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

Correct all breaking changes in RPC for Protocol 22 #1084

Merged
merged 10 commits into from
Nov 8, 2024
Prev Previous commit
Next Next commit
Revert "Change createdAt type to string"
This reverts commit 78779ec.
  • Loading branch information
Shaptic committed Oct 28, 2024
commit d00c9699005f39c494346986292b2b2ad5614439
10 changes: 5 additions & 5 deletions src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export namespace Api {
status: GetTransactionStatus.FAILED;

ledger: number;
createdAt: string;
createdAt: number;
applicationOrder: number;
feeBump: boolean;
envelopeXdr: xdr.TransactionEnvelope;
Expand All @@ -96,7 +96,7 @@ export namespace Api {
status: GetTransactionStatus.SUCCESS;

ledger: number;
createdAt: string;
createdAt: number;
applicationOrder: number;
feeBump: boolean;
envelopeXdr: xdr.TransactionEnvelope;
Expand All @@ -118,7 +118,7 @@ export namespace Api {
applicationOrder?: number;
feeBump?: boolean;
ledger?: number;
createdAt?: string;
createdAt?: number;
txHash: string;

envelopeXdr?: string;
Expand All @@ -136,7 +136,7 @@ export namespace Api {
export interface RawTransactionInfo {
status: GetTransactionStatus;
ledger: number;
createdAt: string;
createdAt: number;
applicationOrder: number;
feeBump: boolean;
txHash: string;
Expand All @@ -150,7 +150,7 @@ export namespace Api {
export interface TransactionInfo {
status: GetTransactionStatus;
ledger: number;
createdAt: string;
createdAt: number;
applicationOrder: number;
feeBump: boolean;
txHash: string;
Expand Down
61 changes: 17 additions & 44 deletions src/rpc/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import { xdr, Contract, SorobanDataBuilder } from '@stellar/stellar-base';
import { Api } from './api';

/**
* Parse the response from invoking the `submitTransaction` method of a Soroban
* RPC server.
* Parse the response from invoking the `submitTransaction` method of a Soroban RPC server.
* @memberof module:rpc
* @private
*
* @param {Api.RawSendTransactionResponse} raw the raw `submitTransaction`
* response from the Soroban RPC server to parse
*
* @returns {Api.SendTransactionResponse} transaction response parsed from the
* Soroban RPC server's response
* @param {Api.RawSendTransactionResponse} raw the raw `submitTransaction` response from the Soroban RPC server to parse
* @returns {Api.SendTransactionResponse} transaction response parsed from the Soroban RPC server's response
*/
export function parseRawSendTransaction(
raw: Api.RawSendTransactionResponse
Expand Down Expand Up @@ -74,15 +70,11 @@ export function parseRawTransactions(
}

/**
* Parse and return the retrieved events, if any, from a raw response from a
* Soroban RPC server.
* Parse and return the retrieved events, if any, from a raw response from a Soroban RPC server.
* @memberof module:rpc
*
* @param {Api.RawGetEventsResponse} raw the raw `getEvents` response from the
* Soroban RPC server to parse
*
* @returns {Api.GetEventsResponse} events parsed from the Soroban RPC server's
* response
* @param {Api.RawGetEventsResponse} raw the raw `getEvents` response from the Soroban RPC server to parse
* @returns {Api.GetEventsResponse} events parsed from the Soroban RPC server's response
*/
export function parseRawEvents(
raw: Api.RawGetEventsResponse
Expand All @@ -105,16 +97,12 @@ export function parseRawEvents(
}

/**
* Parse and return the retrieved ledger entries, if any, from a raw response
* from a Soroban RPC server.
* Parse and return the retrieved ledger entries, if any, from a raw response from a Soroban RPC server.
* @memberof module:rpc
* @private
*
* @param {Api.RawGetLedgerEntriesResponse} raw the raw `getLedgerEntries`
* response from the Soroban RPC server to parse
*
* @returns {Api.GetLedgerEntriesResponse} ledger entries parsed from the
* Soroban RPC server's response
* @param {Api.RawGetLedgerEntriesResponse} raw he raw `getLedgerEntries` response from the Soroban RPC server to parse
* @returns {Api.GetLedgerEntriesResponse} ledger entries parsed from the Soroban RPC server's response
*/
export function parseRawLedgerEntries(
raw: Api.RawGetLedgerEntriesResponse
Expand All @@ -141,21 +129,13 @@ export function parseRawLedgerEntries(
}

/**
* Parse whether or not the transaction simulation was successful, returning the
* relevant response.
* Parse whether or not the transaction simulation was successful, returning the relevant response.
* @memberof module:rpc
* @private
*
* @param {Api.RawSimulateTransactionResponse} sim a raw response from the
* `simulateTransaction` method of the Soroban RPC server to parse
* @param {Api.BaseSimulateTransactionResponse} partial a partially built
* simulate transaction response that will be used to build the return
* response
*
* @returns {Api.SimulateTransactionRestoreResponse |
* Api.SimulateTransactionSuccessResponse} Either a simulation response
* indicating what ledger entries should be restored, or if the simulation
* was successful.
* @param {Api.RawSimulateTransactionResponse} sim a raw response from the `simulateTransaction` method of the Soroban RPC server to parse
* @param {Api.BaseSimulateTransactionResponse} partial a partially built simulate transaction response that will be used to build the return response
* @returns {Api.SimulateTransactionRestoreResponse | Api.SimulateTransactionSuccessResponse} Either a simulation response indicating what ledger entries should be restored, or if the simulation was successful.
*/
function parseSuccessful(
sim: Api.RawSimulateTransactionResponse,
Expand Down Expand Up @@ -212,20 +192,13 @@ function parseSuccessful(
}

/**
* Converts a raw response schema into one with parsed XDR fields and a
* simplified interface.
* Converts a raw response schema into one with parsed XDR fields and a simplified interface.
* @warning This API is only exported for testing purposes and should not be relied on or considered "stable".
* @memberof module:rpc
* @private
*
* @param {Api.SimulateTransactionResponse | Api.RawSimulateTransactionResponse}
* sim the raw response schema (parsed ones are allowed, best-effort
* @param {Api.SimulateTransactionResponse | Api.RawSimulateTransactionResponse} sim the raw response schema (parsed ones are allowed, best-effort
* detected, and returned untouched)
*
* @returns {Api.SimulateTransactionResponse} the original parameter (if already
* parsed), parsed otherwise
*
* @warning This API is only exported for testing purposes and should not be
* relied on or considered "stable".
* @returns {Api.SimulateTransactionResponse} the original parameter (if already parsed), parsed otherwise
*/
export function parseRawSimulation(
sim:
Expand Down
2 changes: 1 addition & 1 deletion test/unit/server/soroban/get_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function makeTxResult(status, addSoroban = true) {
// aa6a8e198abe53c7e852e4870413b29fe9ef04da1415a97a5de1a4ae489e11e2
const successInfo = {
ledger: 1234,
createdAt: "123456789010",
createdAt: 123456789010,
applicationOrder: 2,
feeBump: false,
envelopeXdr:
Expand Down
2 changes: 1 addition & 1 deletion test/unit/server/soroban/get_transactions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function makeTxResult(ledger, applicationOrder, status) {
return {
status: status,
ledger: ledger,
createdAt: (ledger * 25 + 100).toString(),
createdAt: ledger * 25 + 100,
applicationOrder: applicationOrder,
feeBump: false,
envelopeXdr:
Expand Down