Skip to content

Commit

Permalink
Fix how failed getTransaction responses are parsed (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Oct 27, 2023
1 parent 2a43e48 commit 2b8af68
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ A breaking change will get clearly marked in this log.

## Unreleased

### Fixed
* The `SorobanRpc.Server.getTransaction` method will now return the full response when encountering a `FAILED` transaction result ([#872](https://github.com/stellar/js-stellar-sdk/pull/872)).


## [v11.0.0-beta.5](https://github.com/stellar/js-stellar-sdk/compare/v11.0.0-beta.4...v11.0.0-beta.5)

Expand Down
8 changes: 8 additions & 0 deletions src/soroban/soroban_rpc.ts → src/soroban/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export namespace Api {
export interface GetFailedTransactionResponse
extends GetAnyTransactionResponse {
status: GetTransactionStatus.FAILED;

ledger: number;
createdAt: number;
applicationOrder: number;
feeBump: boolean;
envelopeXdr: xdr.TransactionEnvelope;
resultXdr: xdr.TransactionResult;
resultMetaXdr: xdr.TransactionMeta;
}

export interface GetSuccessfulTransactionResponse
Expand Down
2 changes: 1 addition & 1 deletion src/soroban/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference path="../../types/dom-monkeypatch.d.ts" />

// Expose all types
export * from './soroban_rpc';
export * from './api';

// soroban-client classes to expose
export { Server, Durability } from './server';
Expand Down
2 changes: 1 addition & 1 deletion src/soroban/parsers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { xdr, Contract, SorobanDataBuilder } from 'stellar-base';
import { Api } from './soroban_rpc';
import { Api } from './api';

export function parseRawSendTransaction(
r: Api.RawSendTransactionResponse
Expand Down
15 changes: 8 additions & 7 deletions src/soroban/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import AxiosClient from './axios';
import { Api as FriendbotApi } from '../friendbot';
import * as jsonrpc from './jsonrpc';
import { Api } from './soroban_rpc';
import { Api } from './api';
import { assembleTransaction } from './transaction';
import {
parseRawSendTransaction,
Expand Down Expand Up @@ -307,14 +307,14 @@ export class Server {
hash: string
): Promise<Api.GetTransactionResponse> {
return this._getTransaction(hash).then((raw) => {
let successInfo: Omit<
let foundInfo: Omit<
Api.GetSuccessfulTransactionResponse,
keyof Api.GetFailedTransactionResponse
keyof Api.GetMissingTransactionResponse
> = {} as any;

if (raw.status === Api.GetTransactionStatus.SUCCESS) {
if (raw.status !== Api.GetTransactionStatus.NOT_FOUND) {
const meta = xdr.TransactionMeta.fromXDR(raw.resultMetaXdr!, 'base64');
successInfo = {
foundInfo = {
ledger: raw.ledger!,
createdAt: raw.createdAt!,
applicationOrder: raw.applicationOrder!,
Expand All @@ -326,7 +326,8 @@ export class Server {
resultXdr: xdr.TransactionResult.fromXDR(raw.resultXdr!, 'base64'),
resultMetaXdr: meta,
...(meta.switch() === 3 &&
meta.v3().sorobanMeta() !== null && {
meta.v3().sorobanMeta() !== null &&
raw.status === Api.GetTransactionStatus.SUCCESS && {
returnValue: meta.v3().sorobanMeta()?.returnValue()
})
};
Expand All @@ -338,7 +339,7 @@ export class Server {
latestLedgerCloseTime: raw.latestLedgerCloseTime,
oldestLedger: raw.oldestLedger,
oldestLedgerCloseTime: raw.oldestLedgerCloseTime,
...successInfo
...foundInfo
};

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/soroban/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TransactionBuilder
} from 'stellar-base';

import { Api } from './soroban_rpc';
import { Api } from './api';
import { parseRawSimulation } from './parsers';

/**
Expand Down

0 comments on commit 2b8af68

Please sign in to comment.