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

Update API definitions to conform to the new Soroban RPC schemas #173

Merged
merged 2 commits into from
Dec 1, 2023
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
2 changes: 1 addition & 1 deletion src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function parseRawEvents(
...evt,
contractId: new Contract(evt.contractId),
topic: evt.topic.map((topic) => xdr.ScVal.fromXDR(topic, 'base64')),
value: xdr.DiagnosticEvent.fromXDR(evt.value.xdr, 'base64')
value: xdr.ScVal.fromXDR(evt.value, 'base64')
};
})
};
Expand Down
41 changes: 17 additions & 24 deletions src/soroban_rpc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { AssetType, Contract, SorobanDataBuilder, xdr } from 'stellar-base';

// TODO: Better parsing for hashes

/* tslint:disable-next-line:no-namespace */
/**
* @namespace SorobanRpc
*/
/** @namespace SorobanRpc */
export namespace SorobanRpc {
export interface Balance {
asset_type: AssetType.credit4 | AssetType.credit12;
Expand Down Expand Up @@ -55,20 +51,18 @@ export namespace SorobanRpc {
latestLedger: number;
}

/* Response for jsonrpc method `getNetwork`
*/
/** @see https://soroban.stellar.org/api/methods/getNetwork */
export interface GetNetworkResponse {
friendbotUrl?: string;
passphrase: string;
protocolVersion: string;
protocolVersion: number;
}

/* Response for jsonrpc method `getLatestLedger`
*/
/** @see https://soroban.stellar.org/api/methods/getLatestLedger */
export interface GetLatestLedgerResponse {
id: string;
sequence: number;
protocolVersion: string;
protocolVersion: number;
}

export enum GetTransactionStatus {
Expand All @@ -77,16 +71,17 @@ export namespace SorobanRpc {
FAILED = 'FAILED'
}

/** @see https://soroban.stellar.org/api/methods/getTransaction */
export type GetTransactionResponse =
| GetSuccessfulTransactionResponse
| GetFailedTransactionResponse
| GetMissingTransactionResponse;

interface GetAnyTransactionResponse {
status: GetTransactionStatus;
latestLedger: string;
latestLedger: number;
latestLedgerCloseTime: number;
oldestLedger: string;
oldestLedger: number;
oldestLedgerCloseTime: number;
}

Expand Down Expand Up @@ -117,9 +112,9 @@ export namespace SorobanRpc {

export interface RawGetTransactionResponse {
status: GetTransactionStatus;
latestLedger: string;
latestLedger: number;
latestLedgerCloseTime: number;
oldestLedger: string;
oldestLedger: number;
oldestLedgerCloseTime: number;

// the fields below are set if status is SUCCESS
Expand All @@ -141,25 +136,25 @@ export namespace SorobanRpc {
}

export interface GetEventsResponse {
latestLedger: string;
latestLedger: number;
events: EventResponse[];
}

interface EventResponse extends BaseEventResponse {
contractId: Contract;
topic: xdr.ScVal[];
value: xdr.DiagnosticEvent;
value: xdr.ScVal;
}

export interface RawGetEventsResponse {
latestLedger: string;
latestLedger: number;
events: RawEventResponse[];
}

interface BaseEventResponse {
id: string;
type: EventType;
ledger: string;
ledger: number;
ledgerClosedAt: string;
pagingToken: string;
inSuccessfulContractCall: boolean;
Expand All @@ -168,9 +163,7 @@ export namespace SorobanRpc {
interface RawEventResponse extends BaseEventResponse {
contractId: string;
topic: string[];
value: {
xdr: string;
};
value: string;
}

export interface RequestAirdropResponse {
Expand Down Expand Up @@ -232,7 +225,7 @@ export namespace SorobanRpc {
id: string;

/** always present: the LCL known to the server when responding */
latestLedger: string;
latestLedger: number;

/**
* The field is always present, but may be empty in cases where:
Expand Down Expand Up @@ -322,7 +315,7 @@ export namespace SorobanRpc {
/** @see https://soroban.stellar.org/api/methods/simulateTransaction#returns */
export interface RawSimulateTransactionResponse {
id: string;
latestLedger: string;
latestLedger: number;
error?: string;
// this is an xdr.SorobanTransactionData in base64
transactionData?: string;
Expand Down