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

Fix how failed getTransaction responses are parsed #872

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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<

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why this type is calculated each time in method rather than a non-exported const at top of server.ts or exported as a static Type from api.ts? i.e. TransactionFoundResponse = Omit<...>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't happen each time, it'll just happen once at "compile time" when the TypeScript is turned into JavaScript. It's not part of the API because this is specifying "the subset of the 'success/failure' schema that does not contain the 'missing' schema," which isn't like a well-defined API concept, it's just useful here because we're trying to create a partially-(but well-)defined subset of an object.

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
Loading