From 86d04c408a2eff1823fef13c69582100163e1173 Mon Sep 17 00:00:00 2001 From: blaineheffron Date: Wed, 29 May 2024 17:20:25 -0400 Subject: [PATCH] extract getAccount to utils --- src/contract/assembled_transaction.ts | 20 ++++---------------- src/contract/utils.ts | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/contract/assembled_transaction.ts b/src/contract/assembled_transaction.ts index 67d0ae0f6..42506a82a 100644 --- a/src/contract/assembled_transaction.ts +++ b/src/contract/assembled_transaction.ts @@ -27,6 +27,7 @@ import { DEFAULT_TIMEOUT, contractErrorPattern, implementsToString, + getAccount } from "./utils"; import { SentTransaction } from "./sent_transaction"; @@ -373,20 +374,7 @@ export class AssembledTransaction { }); } - private static async getAccount( - options: AssembledTransactionOptions, - server?: Server - ): Promise { - if (!server) { - server = new Server(options.rpcUrl, { - allowHttp: options.allowHttp ?? false, - }); - } - const account = options.publicKey - ? await server.getAccount(options.publicKey) - : new Account(NULL_ACCOUNT, "0"); - return account; - } + /** * Construct a new AssembledTransaction. This is the only way to create a new @@ -412,7 +400,7 @@ export class AssembledTransaction { const tx = new AssembledTransaction(options); const contract = new Contract(options.contractId); - const account = await AssembledTransaction.getAccount( + const account = await getAccount( options, tx.server ); @@ -460,7 +448,7 @@ export class AssembledTransaction { this.simulation = await this.server.simulateTransaction(this.built); if (Api.isSimulationRestore(this.simulation) && restore) { - const account = await AssembledTransaction.getAccount(this.options, this.server); + const account = await getAccount(this.options, this.server); const result = await this.restoreFootprint( this.simulation.restorePreamble, account diff --git a/src/contract/utils.ts b/src/contract/utils.ts index 44e7b8b02..db99d7cbb 100644 --- a/src/contract/utils.ts +++ b/src/contract/utils.ts @@ -1,5 +1,8 @@ -import { xdr, cereal } from "@stellar/stellar-base"; -import type { AssembledTransaction } from "./assembled_transaction"; +import { xdr, cereal, Account } from "@stellar/stellar-base"; +import { Server } from "../rpc/server"; +import { NULL_ACCOUNT, type AssembledTransaction } from "./assembled_transaction"; +import { AssembledTransactionOptions } from "./types"; + /** * The default timeout for waiting for a transaction to be included in a block. @@ -107,3 +110,12 @@ export function processSpecEntryStream(buffer: Buffer) { } return res; } + +export async function getAccount( + options: AssembledTransactionOptions, + server: Server +): Promise { + return options.publicKey + ? await server.getAccount(options.publicKey) + : new Account(NULL_ACCOUNT, "0"); +}