diff --git a/src/server.ts b/src/server.ts index eea4eadc..7e5173c1 100644 --- a/src/server.ts +++ b/src/server.ts @@ -189,34 +189,31 @@ export class Server { } /** - * Fetch the status, result, and/or error of a submitted transaction. + * Fetch the details of a submitted transaction. * * When submitting a transaction, clients should poll this to tell when the * transaction has completed. * * @example * const transactionHash = "c4515e3bdc0897f21cc5dbec8c82cf0a936d4741cb74a8e158eb51b9fb00411a"; - * server.getTransactionStatus(transactionHash).then(transaction => { + * server.getTransaction(transactionHash).then(transaction => { * console.log("status:", transaction.status); - * console.log("envelopeXdr:", transaction.envelopeXdr); - * console.log("resultMetaXdr:", transaction.resultMetaXdr); * console.log("resultXdr:", transaction.resultXdr); - * console.log("error:", transaction.error); * }); * * @param {string} hash - The hash of the transaction to check. Encoded as a * hex string. * - * @returns {Promise} Returns a - * promise to the {@link SorobanRpc.GetTransactionStatusResponse} object - * with the status, results, and error of the transaction. + * @returns {Promise} Returns a + * promise to the {@link SorobanRpc.GetTransactionResponse} object + * with the status, result, and other details about the transaction. */ - public async getTransactionStatus( + public async getTransaction( hash: string, - ): Promise { + ): Promise { return await jsonrpc.post( this.serverURL.toString(), - "getTransactionStatus", + "getTransaction", hash, ); } @@ -389,9 +386,9 @@ export class Server { * preparedTransaction.sign(sourceKeypair); * * server.sendTransaction(transaction).then(result => { - * console.log("id:", result.id); + * console.log("transactionHash:", result.transactionHash); * console.log("status:", result.status); - * console.log("error:", result.error); + * console.log("errorResultXdr:", result.errorResultXdr); * }); * * @param {Transaction | FeeBumpTransaction} transaction - The transaction to @@ -461,8 +458,9 @@ export class Server { * transaction.sign(sourceKeypair); * * server.sendTransaction(transaction).then(result => { - * console.log("id:", result.id); - * console.log("error:", result.error); + * console.log("transactionHash:", result.transactionHash); + * console.log("status:", result.status); + * console.log("errorResultXdr:", result.errorResultXdr); * }); * * @param {Transaction | FeeBumpTransaction} transaction - The transaction to diff --git a/src/soroban_rpc.ts b/src/soroban_rpc.ts index 34687ce1..15cdcb4e 100644 --- a/src/soroban_rpc.ts +++ b/src/soroban_rpc.ts @@ -20,8 +20,6 @@ export namespace SorobanRpc { memBytes: string; } - export type TransactionStatus = "pending" | "success" | "error"; - export interface GetHealthResponse { status: "healthy"; } @@ -43,14 +41,21 @@ export namespace SorobanRpc { protocolVersion: string; } - export interface GetTransactionStatusResponse { - id: string; - status: TransactionStatus; - envelopeXdr?: string; + export type GetTransactionStatus = "SUCCESS" | "NOT_FOUND" | "FAILED"; + + export interface GetTransactionResponse { + status: GetTransactionStatus; + latestLedger: number; + latestLedgerCloseTime: number; + oldestLedger: number; + oldestLedgerCloseTime: number; + + // the fields below are set if status is SUCCESS + applicationOrder?: number; + feeBump?: boolean; resultXdr?: string; - resultMetaXdr?: string; - results?: Array<{ xdr: string }>; - error?: jsonrpc.Error; + ledger?: number; + createdAt?: number; } export interface EventFilter { @@ -79,9 +84,19 @@ export namespace SorobanRpc { transaction_id: string; } + export type SendTransactionStatus = + | "PENDING" + | "DUPLICATE" + | "TRY_AGAIN_LATER" + | "ERROR"; + export interface SendTransactionResponse { - id: string; - error?: jsonrpc.Error; + status: SendTransactionStatus; + // errorResultXdr is only set when status is ERROR + errorResultXdr?: string; + transactionHash: string; + latestLedger: number; + latestLedgerCloseTime: number; } export interface SimulateTransactionResponse { diff --git a/test/unit/server/get_transaction_status_test.js b/test/unit/server/get_transaction_test.js similarity index 74% rename from test/unit/server/get_transaction_status_test.js rename to test/unit/server/get_transaction_test.js index e69ac78d..9eb8c1cf 100644 --- a/test/unit/server/get_transaction_status_test.js +++ b/test/unit/server/get_transaction_test.js @@ -1,4 +1,4 @@ -describe("Server#getTransactionStatus", function() { +describe("Server#getTransaction", function() { let keypair = SorobanClient.Keypair.random(); let account = new SorobanClient.Account( keypair.publicKey(), @@ -39,28 +39,27 @@ describe("Server#getTransactionStatus", function() { }); it("transaction not found", function(done) { + const result = { + status: "NOT_FOUND", + latestLedger: 100, + latestLedgerCloseTime: 12345, + oldestLedger: 50, + oldestLedgerCloseTime: 500, + }; this.axiosMock .expects("post") .withArgs(serverUrl, { jsonrpc: "2.0", id: 1, - method: "getTransactionStatus", + method: "getTransaction", params: [this.hash], }) - .returns(Promise.resolve({ data: { id: 1, error: { code: 404 } } })); + .returns(Promise.resolve({ data: { id: 1, result } })); - this.server - .getTransactionStatus(this.hash) - .then(function(_response) { - done(new Error("Expected error")); - }) - .catch(function(err) { - done( - err.code == 404 - ? null - : new Error("Expected error code 404, got: " + err.code), - ); - }); + this.server.getTransaction(this.hash).then(function(response) { + expect(response).to.be.deep.equal(result); + done(); + }); }); xit("transaction pending", function(done) {}); diff --git a/test/unit/server/send_transaction_test.js b/test/unit/server/send_transaction_test.js index 68461b20..9eac951e 100644 --- a/test/unit/server/send_transaction_test.js +++ b/test/unit/server/send_transaction_test.js @@ -49,7 +49,7 @@ describe("Server#sendTransaction", function() { }) .returns( Promise.resolve({ - data: { id: 1, result: { id: this.hash, status: "pending" } }, + data: { id: 1, result: { id: this.hash, status: "PENDING" } }, }), );