diff --git a/CHANGELOG.md b/CHANGELOG.md index 44764f42a..96106b661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ A breaking change will get clearly marked in this log. ## Unreleased +### Added +* Support for the new, optional `diagnosticEventsXdr` field on the `SorobanRpc.Server.sendTransaction` method. The raw field will be present when using the `_sendTransaction` method, while the normal method will have an already-parsed `diagnosticEvents: xdr.DiagnosticEvent[]` field, instead ([]()). +* A new exported interface `SorobanRpc.Api.EventResponse` so that developers can type-check individual events ([#904](https://github.com/stellar/js-stellar-sdk/pull/904)). + ## [v11.1.0](https://github.com/stellar/js-stellar-sdk/compare/v11.0.1...v11.1.0) diff --git a/src/soroban/api.ts b/src/soroban/api.ts index 5b3236fea..7d6050377 100644 --- a/src/soroban/api.ts +++ b/src/soroban/api.ts @@ -186,6 +186,7 @@ export namespace Api { export interface SendTransactionResponse extends BaseSendTransactionResponse { errorResult?: xdr.TransactionResult; + diagnosticEvents?: xdr.DiagnosticEvent[]; } export interface RawSendTransactionResponse @@ -197,6 +198,12 @@ export namespace Api { * It contains details on why the network rejected the transaction. */ errorResultXdr?: string; + /** + * This is a base64-encoded instance of an array of + * {@link xdr.DiagnosticEvent}s, set only when `status` is `"ERROR"` and + * diagnostic events are enabled on the server. + */ + diagnosticEventsXdr?: string[]; } export interface BaseSendTransactionResponse { diff --git a/src/soroban/parsers.ts b/src/soroban/parsers.ts index d20ec14a0..8ff1d1c6d 100644 --- a/src/soroban/parsers.ts +++ b/src/soroban/parsers.ts @@ -4,13 +4,22 @@ import { Api } from './api'; export function parseRawSendTransaction( r: Api.RawSendTransactionResponse ): Api.SendTransactionResponse { - const errResult = r.errorResultXdr; + const { errorResultXdr, diagnosticEventsXdr } = r; delete r.errorResultXdr; + delete r.diagnosticEventsXdr; - if (!!errResult) { + if (!!errorResultXdr) { return { ...r, - errorResult: xdr.TransactionResult.fromXDR(errResult, 'base64') + ...( + diagnosticEventsXdr !== undefined && + diagnosticEventsXdr.length > 0 && { + diagnosticEvents: diagnosticEventsXdr.map( + evt => xdr.DiagnosticEvent.fromXDR(evt, 'base64') + ) + } + ), + errorResult: xdr.TransactionResult.fromXDR(errorResultXdr, 'base64'), }; } diff --git a/test/unit/server/soroban/send_transaction_test.js b/test/unit/server/soroban/send_transaction_test.js index a7e390202..901fcc7c5 100644 --- a/test/unit/server/soroban/send_transaction_test.js +++ b/test/unit/server/soroban/send_transaction_test.js @@ -52,7 +52,12 @@ describe("Server#sendTransaction", function () { this.server .sendTransaction(this.transaction) - .then(function () { + .then(function (r) { + expect(r.status).to.eql("PENDING"); + expect(r.errorResult).to.be.undefined; + expect(r.errorResultXdr).to.be.undefined; + expect(r.diagnosticEvents).to.be.undefined; + expect(r.diagnosticEventsXdr).to.be.undefined; done(); }) .catch(function (err) { @@ -83,6 +88,9 @@ describe("Server#sendTransaction", function () { id: this.hash, status: "ERROR", errorResultXdr: txResult.toXDR("base64"), + diagnosticEventsXdr: [ + "AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgr/p6gt6h8MrmSw+WNJnu3+sCP9dHXx7jR8IH0sG6Cy0AAAAPAAAABWhlbGxvAAAAAAAADwAAAAVBbG9oYQAAAA==", + ], }, }, }), @@ -94,6 +102,9 @@ describe("Server#sendTransaction", function () { expect(r.errorResult).to.be.instanceOf(xdr.TransactionResult); expect(r.errorResult).to.eql(txResult); expect(r.errorResultXdr).to.be.undefined; + expect(r.diagnosticEventsXdr).to.be.undefined; + expect(r.diagnosticEvents).to.have.lengthOf(1); + expect(r.diagnosticEvents[0]).to.be.instanceOf(xdr.DiagnosticEvent); done(); })