Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new sendTransaction response field #905

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions src/soroban/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export namespace Api {

export interface SendTransactionResponse extends BaseSendTransactionResponse {
errorResult?: xdr.TransactionResult;
diagnosticEvents?: xdr.DiagnosticEvent[];
}

export interface RawSendTransactionResponse
Expand All @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions src/soroban/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
};
}

Expand Down
13 changes: 12 additions & 1 deletion test/unit/server/soroban/send_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -83,6 +88,9 @@ describe("Server#sendTransaction", function () {
id: this.hash,
status: "ERROR",
errorResultXdr: txResult.toXDR("base64"),
diagnosticEventsXdr: [
"AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgr/p6gt6h8MrmSw+WNJnu3+sCP9dHXx7jR8IH0sG6Cy0AAAAPAAAABWhlbGxvAAAAAAAADwAAAAVBbG9oYQAAAA==",
],
},
},
}),
Expand All @@ -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();
})
Expand Down
Loading