diff --git a/src/contract/assembled_transaction.ts b/src/contract/assembled_transaction.ts index 1aac05e39..55e5ff3e6 100644 --- a/src/contract/assembled_transaction.ts +++ b/src/contract/assembled_transaction.ts @@ -304,7 +304,7 @@ export class AssembledTransaction { /** * The signed transaction. */ - private signed?: Tx; + public signed?: Tx; /** * A list of the most important errors that various AssembledTransaction @@ -629,7 +629,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 sent = await SentTransaction.init(this.options, this.signed); + const sent = await SentTransaction.init(undefined, this); return sent; } diff --git a/src/contract/sent_transaction.ts b/src/contract/sent_transaction.ts index 98bbb56b6..0a449ab3e 100644 --- a/src/contract/sent_transaction.ts +++ b/src/contract/sent_transaction.ts @@ -1,9 +1,10 @@ /* disable max-classes rule, because extending error shouldn't count! */ /* eslint max-classes-per-file: 0 */ -import type { MethodOptions, SentTransactionOptions, Tx } from "./types"; +import type { MethodOptions } 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: @@ -49,11 +50,11 @@ export class SentTransaction { }; constructor( - public options: SentTransactionOptions, - public signed: Tx, + _: any, // deprecated: used to take sentTransaction, need to wait for major release for breaking change + public assembled: AssembledTransaction, ) { - this.server = new Server(this.options.rpcUrl, { - allowHttp: this.options.allowHttp ?? false, + this.server = new Server(this.assembled.options.rpcUrl, { + allowHttp: this.assembled.options.allowHttp ?? false, }); } @@ -62,27 +63,19 @@ export class SentTransaction { * AssembledTransaction. This will also send the transaction to the network. */ static init = async ( - /** - * Configuration options for initializing the SentTransaction. - * - * @typedef {Object} SentTransactionOptions - * @property {number} [timeoutInSeconds] - Optional timeout duration in seconds for the transaction. - * @property {string} rpcUrl - The RPC URL of the network to which the transaction will be sent. - * @property {boolean} [allowHttp] - Optional flag to allow HTTP connections (default is false, HTTPS is preferred). - * @property {(xdr: xdr.ScVal) => U} parseResultXdr - Function to parse the XDR result returned by the network. - */ - options: SentTransactionOptions, - /** The signed transaction to send to the network */ - signed: Tx, + /** @deprecated variable is ignored. Now handled by AssembledTransaction. */ + _: any, // eslint-disable-line @typescript-eslint/no-unused-vars + /** {@link AssembledTransaction} from which this SentTransaction was initialized */ + assembled: AssembledTransaction, ): Promise> => { - const tx = new SentTransaction(options, signed); + const tx = new SentTransaction(undefined, assembled); const sent = await tx.send(); return sent; }; private send = async (): Promise => { this.sendTransactionResponse = await this.server.sendTransaction( - this.signed, + this.assembled.signed!, ); if (this.sendTransactionResponse.status !== "PENDING") { @@ -98,7 +91,7 @@ export class SentTransaction { const { hash } = this.sendTransactionResponse; const timeoutInSeconds = - this.options.timeoutInSeconds ?? DEFAULT_TIMEOUT; + this.assembled.options.timeoutInSeconds ?? DEFAULT_TIMEOUT; this.getTransactionResponseAll = await withExponentialBackoff( () => this.server.getTransaction(hash), (resp) => resp.status === Api.GetTransactionStatus.NOT_FOUND, @@ -135,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.options.parseResultXdr( + return this.assembled.options.parseResultXdr( this.getTransactionResponse.returnValue!, ); } @@ -160,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.signed)}`, + `Sending transaction failed: ${JSON.stringify(this.assembled.signed)}`, ); } } diff --git a/src/contract/types.ts b/src/contract/types.ts index 461880d1b..8b92276c2 100644 --- a/src/contract/types.ts +++ b/src/contract/types.ts @@ -117,10 +117,3 @@ 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, -};