diff --git a/src/contract/assembled_transaction.ts b/src/contract/assembled_transaction.ts index bdf4d8898..557a722ad 100644 --- a/src/contract/assembled_transaction.ts +++ b/src/contract/assembled_transaction.ts @@ -582,8 +582,7 @@ export class AssembledTransaction { if(!this.signed){ throw new Error("The transaction has not yet been signed. Run `sign` first, or use `signAndSend` instead."); } - const typeChecked: AssembledTransaction = this; - const sent = await SentTransaction.init(typeChecked, this.signed); + const sent = await SentTransaction.init(this.options, this.signed); return sent; } diff --git a/src/contract/sent_transaction.ts b/src/contract/sent_transaction.ts index 960f842f7..366e00259 100644 --- a/src/contract/sent_transaction.ts +++ b/src/contract/sent_transaction.ts @@ -1,10 +1,9 @@ /* disable max-classes rule, because extending error shouldn't count! */ /* eslint max-classes-per-file: 0 */ -import type { MethodOptions, Tx } from "./types"; +import type { MethodOptions, SentTransactionOptions, Tx } from "./types"; import { Server } from "../rpc/server" import { Api } from "../rpc/api" import { DEFAULT_TIMEOUT, withExponentialBackoff } from "./utils"; -import type { AssembledTransaction } from "./assembled_transaction"; /** * A transaction that has been sent to the Soroban network. This happens in two steps: @@ -50,12 +49,11 @@ export class SentTransaction { }; constructor( - public assembled: AssembledTransaction, - + public options: SentTransactionOptions, public signed: Tx, ) { - this.server = new Server(this.assembled.options.rpcUrl, { - allowHttp: this.assembled.options.allowHttp ?? false, + this.server = new Server(this.options.rpcUrl, { + allowHttp: this.options.allowHttp ?? false, }); } @@ -65,12 +63,12 @@ export class SentTransaction { * network. */ static init = async ( - /** {@link AssembledTransaction} from which this SentTransaction was initialized */ - assembled: AssembledTransaction, + /** {@link SentTransactionOptions} from which this SentTransaction was initialized */ + options: SentTransactionOptions, /** The signed transaction to send to the network */ signed: Tx, ): Promise> => { - const tx = new SentTransaction(assembled, signed); + const tx = new SentTransaction(options, signed); const sent = await tx.send(); return sent; }; @@ -93,7 +91,7 @@ export class SentTransaction { const { hash } = this.sendTransactionResponse; const timeoutInSeconds = - this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT; + this.options.timeoutInSeconds ?? DEFAULT_TIMEOUT; this.getTransactionResponseAll = await withExponentialBackoff( () => this.server.getTransaction(hash), (resp) => resp.status === Api.GetTransactionStatus.NOT_FOUND, @@ -130,7 +128,7 @@ export class SentTransaction { if ("getTransactionResponse" in this && this.getTransactionResponse) { // getTransactionResponse has a `returnValue` field unless it failed if ("returnValue" in this.getTransactionResponse) { - return this.assembled.options.parseResultXdr( + return this.options.parseResultXdr( this.getTransactionResponse.returnValue!, ); } @@ -155,7 +153,7 @@ export class SentTransaction { // 3. finally, if neither of those are present, throw an error throw new Error( - `Sending transaction failed: ${JSON.stringify(this.assembled)}`, + `Sending transaction failed: ${JSON.stringify(this.signed)}`, ); } } diff --git a/src/contract/types.ts b/src/contract/types.ts index 8b92276c2..461880d1b 100644 --- a/src/contract/types.ts +++ b/src/contract/types.ts @@ -117,3 +117,10 @@ export type AssembledTransactionOptions = MethodOptions & args?: any[]; parseResultXdr: (xdr: xdr.ScVal) => T; }; + +export type SentTransactionOptions = { + timeoutInSeconds?: number, + rpcUrl: string, + allowHttp?: boolean, + parseResultXdr: (xdr: xdr.ScVal) => T, +};