From 537a187fe3b8937943092f26a7fc829f5ae93919 Mon Sep 17 00:00:00 2001 From: George Date: Thu, 7 Nov 2024 18:46:55 -0800 Subject: [PATCH] Correct all breaking changes in RPC for Protocol 22 (#1084) * Change createdAt type to string * Drop simulateTransaction cost field * Rename pagingToken to cursor * Fixup casing, txhash to getTransactions * Add hash to test output --- src/rpc/api.ts | 31 ++++++++++++------- src/rpc/parsers.ts | 12 ++++--- src/rpc/server.ts | 1 + test/unit/server/soroban/get_events_test.js | 8 ++--- .../server/soroban/get_transaction_test.js | 10 +++--- .../server/soroban/get_transactions_test.js | 1 + .../soroban/simulate_transaction_test.js | 11 ------- 7 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/rpc/api.ts b/src/rpc/api.ts index 09a027b9a..097a5d972 100644 --- a/src/rpc/api.ts +++ b/src/rpc/api.ts @@ -2,12 +2,6 @@ import { Contract, SorobanDataBuilder, xdr } from '@stellar/stellar-base'; /* tslint:disable-next-line:no-namespace */ export namespace Api { - - export interface Cost { - cpuInsns: string; - memBytes: string; - } - export interface GetHealthResponse { status: 'healthy'; } @@ -72,6 +66,7 @@ export namespace Api { interface GetAnyTransactionResponse { status: GetTransactionStatus; + txHash: string; latestLedger: number; latestLedgerCloseTime: number; oldestLedger: number; @@ -119,15 +114,17 @@ export namespace Api { latestLedgerCloseTime: number; oldestLedger: number; oldestLedgerCloseTime: number; + txHash: string; // the fields below are set if status is SUCCESS applicationOrder?: number; feeBump?: boolean; + ledger?: number; + createdAt?: number; + envelopeXdr?: string; resultXdr?: string; resultMetaXdr?: string; - ledger?: number; - createdAt?: number; diagnosticEventsXdr?: string[]; } @@ -143,6 +140,8 @@ export namespace Api { createdAt: number; applicationOrder: number; feeBump: boolean; + txHash: string; + envelopeXdr?: string; resultXdr?: string; resultMetaXdr?: string; @@ -155,6 +154,8 @@ export namespace Api { createdAt: number; applicationOrder: number; feeBump: boolean; + txHash: string; + envelopeXdr: xdr.TransactionEnvelope; resultXdr: xdr.TransactionResult; resultMetaXdr: xdr.TransactionMeta; @@ -209,6 +210,7 @@ export namespace Api { type: EventType; ledger: number; ledgerClosedAt: string; + cursor: string; pagingToken: string; inSuccessfulContractCall: boolean; txHash: string; @@ -317,7 +319,6 @@ export namespace Api { extends BaseSimulateTransactionResponse { transactionData: SorobanDataBuilder; minResourceFee: string; - cost: Cost; /** present only for invocation simulation */ result?: SimulateHostFunctionResult; @@ -403,7 +404,6 @@ export namespace Api { * invokeHostFunctionOperation is supported per transaction. * */ results?: RawSimulateHostFunctionResult[]; - cost?: Cost; /** Present if succeeded but has expired ledger entries */ restorePreamble?: { minResourceFee: string; @@ -416,9 +416,18 @@ export namespace Api { export interface GetVersionInfoResponse { version: string; + commitHash: string; + buildTimestamp: string; + captiveCoreVersion: string; + protocolVersion: number; // uint32 + + /// @deprecated commit_hash: string; - build_time_stamp: string; + /// @deprecated + build_timestamp: string; + /// @deprecated captive_core_version: string; + /// @deprecated protocol_version: number; // uint32 } diff --git a/src/rpc/parsers.ts b/src/rpc/parsers.ts index c45a8cec6..a897f52e3 100644 --- a/src/rpc/parsers.ts +++ b/src/rpc/parsers.ts @@ -34,9 +34,11 @@ export function parseRawSendTransaction( return { ...raw } as Api.BaseSendTransactionResponse; } -export function parseTransactionInfo(raw: Api.RawTransactionInfo | Api.RawGetTransactionResponse): Omit { +export function parseTransactionInfo( + raw: Api.RawTransactionInfo | Api.RawGetTransactionResponse +): Omit { const meta = xdr.TransactionMeta.fromXDR(raw.resultMetaXdr!, 'base64'); - const info: Omit = { + const info: Omit = { ledger: raw.ledger!, createdAt: raw.createdAt!, applicationOrder: raw.applicationOrder!, @@ -64,6 +66,7 @@ export function parseRawTransactions( ): Api.TransactionInfo { return { status: r.status, + txHash: r.txHash, ...parseTransactionInfo(r), }; } @@ -147,11 +150,10 @@ function parseSuccessful( ...partial, transactionData: new SorobanDataBuilder(sim.transactionData!), minResourceFee: sim.minResourceFee!, - cost: sim.cost!, - ...// coalesce 0-or-1-element results[] list into a single result struct + // coalesce 0-or-1-element results[] list into a single result struct // with decoded fields if present // eslint-disable-next-line no-self-compare - ((sim.results?.length ?? 0 > 0) && { + ...((sim.results?.length ?? 0 > 0) && { result: sim.results!.map((row) => ({ auth: (row.auth ?? []).map((entry) => xdr.SorobanAuthorizationEntry.fromXDR(entry, 'base64') diff --git a/src/rpc/server.ts b/src/rpc/server.ts index 546d707f8..dfab27efc 100644 --- a/src/rpc/server.ts +++ b/src/rpc/server.ts @@ -562,6 +562,7 @@ export class RpcServer { const result: Api.GetTransactionResponse = { status: raw.status, + txHash: hash, latestLedger: raw.latestLedger, latestLedgerCloseTime: raw.latestLedgerCloseTime, oldestLedger: raw.oldestLedger, diff --git a/test/unit/server/soroban/get_events_test.js b/test/unit/server/soroban/get_events_test.js index c4d759859..41db1984d 100644 --- a/test/unit/server/soroban/get_events_test.js +++ b/test/unit/server/soroban/get_events_test.js @@ -242,7 +242,7 @@ let getEventsResponseFixture = [ ledgerClosedAt: "2022-11-16T16:10:41Z", contractId: "", id: "0164090849041387521-0000000003", - pagingToken: "164090849041387521-3", + cursor: "164090849041387521-3", inSuccessfulContractCall: true, topic: topicVals.slice(0, 2), value: eventVal, @@ -254,7 +254,7 @@ let getEventsResponseFixture = [ ledgerClosedAt: "2022-11-16T16:10:41Z", contractId, id: "0164090849041387521-0000000003", - pagingToken: "164090849041387521-3", + cursor: "164090849041387521-3", inSuccessfulContractCall: true, topic: topicVals.slice(0, 2), value: eventVal, @@ -266,7 +266,7 @@ let getEventsResponseFixture = [ ledgerClosedAt: "2022-11-16T16:10:41Z", contractId, id: "0164090849041387521-0000000003", - pagingToken: "164090849041387521-3", + cursor: "164090849041387521-3", inSuccessfulContractCall: true, topic: [topicVals[0]], value: eventVal, @@ -278,7 +278,7 @@ let getEventsResponseFixture = [ ledgerClosedAt: "2022-12-14T01:01:20Z", contractId, id: "0000000171798695936-0000000001", - pagingToken: "0000000171798695936-0000000001", + cursor: "0000000171798695936-0000000001", inSuccessfulContractCall: true, topic: topicVals, value: eventVal, diff --git a/test/unit/server/soroban/get_transaction_test.js b/test/unit/server/soroban/get_transaction_test.js index 52b6c807a..adcec7552 100644 --- a/test/unit/server/soroban/get_transaction_test.js +++ b/test/unit/server/soroban/get_transaction_test.js @@ -33,7 +33,6 @@ describe("Server#getTransaction", function () { transaction.sign(keypair); this.transaction = transaction; - this.hash = this.transaction.hash().toString("hex"); this.blob = transaction.toEnvelope().toXDR().toString("base64"); this.prepareAxios = (result) => { this.axiosMock @@ -42,7 +41,7 @@ describe("Server#getTransaction", function () { jsonrpc: "2.0", id: 1, method: "getTransaction", - params: { hash: this.hash }, + params: { hash: result.txHash }, }) .returns(Promise.resolve({ data: { id: 1, result } })); }; @@ -58,7 +57,7 @@ describe("Server#getTransaction", function () { this.prepareAxios(result); this.server - .getTransaction(this.hash) + .getTransaction(result.txHash) .then(function (response) { expect(response).to.be.deep.equal(result); done(); @@ -84,7 +83,7 @@ describe("Server#getTransaction", function () { .returnValue(); this.server - .getTransaction(this.hash) + .getTransaction(result.txHash) .then((resp) => { expect(Object.keys(resp)).to.eql(Object.keys(expected)); expect(resp).to.eql(expected); @@ -99,7 +98,7 @@ describe("Server#getTransaction", function () { this.prepareAxios(result); this.server - .getTransaction(this.hash) + .getTransaction(result.txHash) .then((resp) => { expect(resp).to.be.deep.equal(result); done(); @@ -152,6 +151,7 @@ function makeTxResult(status, addSoroban = true) { return { status, + txHash: "ae9f315c048d87a5f853bc15bf284a2c3c89eb0e1cb38c10409b77a877b830a8", latestLedger: 100, latestLedgerCloseTime: 12345, oldestLedger: 50, diff --git a/test/unit/server/soroban/get_transactions_test.js b/test/unit/server/soroban/get_transactions_test.js index 2fc0c8c45..56c8625a5 100644 --- a/test/unit/server/soroban/get_transactions_test.js +++ b/test/unit/server/soroban/get_transactions_test.js @@ -162,6 +162,7 @@ function makeTxResult(ledger, applicationOrder, status) { return { status: status, ledger: ledger, + txHash: "ae9f315c048d87a5f853bc15bf284a2c3c89eb0e1cb38c10409b77a877b830a8", createdAt: ledger * 25 + 100, applicationOrder: applicationOrder, feeBump: false, diff --git a/test/unit/server/soroban/simulate_transaction_test.js b/test/unit/server/soroban/simulate_transaction_test.js index a48817877..385f4ef8f 100644 --- a/test/unit/server/soroban/simulate_transaction_test.js +++ b/test/unit/server/soroban/simulate_transaction_test.js @@ -38,7 +38,6 @@ describe("Server#simulateTransaction", async function (done) { ), retval: xdr.ScVal.fromXDR(simulationResponse.results[0].xdr, "base64"), }, - cost: simulationResponse.cost, stateChanges: [ { type: 2, @@ -242,7 +241,6 @@ describe("Server#simulateTransaction", async function (done) { const expected = cloneSimulation(parsedSimulationResponse); // drop fields that go away with errors delete expected.result; - delete expected.cost; delete expected.transactionData; delete expected.minResourceFee; delete expected.stateChanges; @@ -270,7 +268,6 @@ function cloneSimulation(sim) { ), retval: xdr.ScVal.fromXDR(sim.result.retval.toXDR()), }, - cost: sim.cost, stateChanges: sim.stateChanges, _parsed: sim._parsed, }; @@ -332,10 +329,6 @@ function baseSimulationResponse(results) { minResourceFee: "15", transactionData: new SorobanDataBuilder().build().toXDR("base64"), ...(results !== undefined && { results }), - cost: { - cpuInsns: "1", - memBytes: "2", - }, stateChanges: [ { type: 2, @@ -440,10 +433,6 @@ describe("works with real responses", function () { xdr: "AAAAEAAAAAEAAAACAAAADwAAAAVIZWxsbwAAAAAAAA8AAAAFQWxvaGEAAAA=", }, ], - cost: { - cpuInsns: "1322134", - memBytes: "1207047", - }, restorePreamble: { transactionData: "", minResourceFee: "0",