Skip to content

Commit

Permalink
Update API in accordance with new RPC schemas (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Dec 1, 2023
1 parent 03cff76 commit 0633a8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
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

0 comments on commit 0633a8b

Please sign in to comment.