Skip to content

Commit

Permalink
extract getAccount to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed May 29, 2024
1 parent 00e2f3c commit 86d04c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
20 changes: 4 additions & 16 deletions src/contract/assembled_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
DEFAULT_TIMEOUT,
contractErrorPattern,
implementsToString,
getAccount
} from "./utils";
import { SentTransaction } from "./sent_transaction";

Expand Down Expand Up @@ -373,20 +374,7 @@ export class AssembledTransaction<T> {
});
}

private static async getAccount<T>(
options: AssembledTransactionOptions<T>,
server?: Server
): Promise<Account> {
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
Expand All @@ -412,7 +400,7 @@ export class AssembledTransaction<T> {
const tx = new AssembledTransaction(options);
const contract = new Contract(options.contractId);

const account = await AssembledTransaction.getAccount(
const account = await getAccount(
options,
tx.server
);
Expand Down Expand Up @@ -460,7 +448,7 @@ export class AssembledTransaction<T> {
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
Expand Down
16 changes: 14 additions & 2 deletions src/contract/utils.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -107,3 +110,12 @@ export function processSpecEntryStream(buffer: Buffer) {
}
return res;
}

export async function getAccount<T>(
options: AssembledTransactionOptions<T>,
server: Server
): Promise<Account> {
return options.publicKey
? await server.getAccount(options.publicKey)
: new Account(NULL_ACCOUNT, "0");
}

0 comments on commit 86d04c4

Please sign in to comment.