Skip to content

Commit 537a187

Browse files
authored
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
1 parent 36fa2af commit 537a187

7 files changed

+38
-36
lines changed

src/rpc/api.ts

+20-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ import { Contract, SorobanDataBuilder, xdr } from '@stellar/stellar-base';
22

33
/* tslint:disable-next-line:no-namespace */
44
export namespace Api {
5-
6-
export interface Cost {
7-
cpuInsns: string;
8-
memBytes: string;
9-
}
10-
115
export interface GetHealthResponse {
126
status: 'healthy';
137
}
@@ -72,6 +66,7 @@ export namespace Api {
7266

7367
interface GetAnyTransactionResponse {
7468
status: GetTransactionStatus;
69+
txHash: string;
7570
latestLedger: number;
7671
latestLedgerCloseTime: number;
7772
oldestLedger: number;
@@ -119,15 +114,17 @@ export namespace Api {
119114
latestLedgerCloseTime: number;
120115
oldestLedger: number;
121116
oldestLedgerCloseTime: number;
117+
txHash: string;
122118

123119
// the fields below are set if status is SUCCESS
124120
applicationOrder?: number;
125121
feeBump?: boolean;
122+
ledger?: number;
123+
createdAt?: number;
124+
126125
envelopeXdr?: string;
127126
resultXdr?: string;
128127
resultMetaXdr?: string;
129-
ledger?: number;
130-
createdAt?: number;
131128
diagnosticEventsXdr?: string[];
132129
}
133130

@@ -143,6 +140,8 @@ export namespace Api {
143140
createdAt: number;
144141
applicationOrder: number;
145142
feeBump: boolean;
143+
txHash: string;
144+
146145
envelopeXdr?: string;
147146
resultXdr?: string;
148147
resultMetaXdr?: string;
@@ -155,6 +154,8 @@ export namespace Api {
155154
createdAt: number;
156155
applicationOrder: number;
157156
feeBump: boolean;
157+
txHash: string;
158+
158159
envelopeXdr: xdr.TransactionEnvelope;
159160
resultXdr: xdr.TransactionResult;
160161
resultMetaXdr: xdr.TransactionMeta;
@@ -209,6 +210,7 @@ export namespace Api {
209210
type: EventType;
210211
ledger: number;
211212
ledgerClosedAt: string;
213+
cursor: string;
212214
pagingToken: string;
213215
inSuccessfulContractCall: boolean;
214216
txHash: string;
@@ -317,7 +319,6 @@ export namespace Api {
317319
extends BaseSimulateTransactionResponse {
318320
transactionData: SorobanDataBuilder;
319321
minResourceFee: string;
320-
cost: Cost;
321322

322323
/** present only for invocation simulation */
323324
result?: SimulateHostFunctionResult;
@@ -403,7 +404,6 @@ export namespace Api {
403404
* invokeHostFunctionOperation is supported per transaction.
404405
* */
405406
results?: RawSimulateHostFunctionResult[];
406-
cost?: Cost;
407407
/** Present if succeeded but has expired ledger entries */
408408
restorePreamble?: {
409409
minResourceFee: string;
@@ -416,9 +416,18 @@ export namespace Api {
416416

417417
export interface GetVersionInfoResponse {
418418
version: string;
419+
commitHash: string;
420+
buildTimestamp: string;
421+
captiveCoreVersion: string;
422+
protocolVersion: number; // uint32
423+
424+
/// @deprecated
419425
commit_hash: string;
420-
build_time_stamp: string;
426+
/// @deprecated
427+
build_timestamp: string;
428+
/// @deprecated
421429
captive_core_version: string;
430+
/// @deprecated
422431
protocol_version: number; // uint32
423432
}
424433

src/rpc/parsers.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ export function parseRawSendTransaction(
3434
return { ...raw } as Api.BaseSendTransactionResponse;
3535
}
3636

37-
export function parseTransactionInfo(raw: Api.RawTransactionInfo | Api.RawGetTransactionResponse): Omit<Api.TransactionInfo, 'status'> {
37+
export function parseTransactionInfo(
38+
raw: Api.RawTransactionInfo | Api.RawGetTransactionResponse
39+
): Omit<Api.TransactionInfo, 'status' | 'txHash'> {
3840
const meta = xdr.TransactionMeta.fromXDR(raw.resultMetaXdr!, 'base64');
39-
const info: Omit<Api.TransactionInfo, 'status'> = {
41+
const info: Omit<Api.TransactionInfo, 'status' | 'txHash'> = {
4042
ledger: raw.ledger!,
4143
createdAt: raw.createdAt!,
4244
applicationOrder: raw.applicationOrder!,
@@ -64,6 +66,7 @@ export function parseRawTransactions(
6466
): Api.TransactionInfo {
6567
return {
6668
status: r.status,
69+
txHash: r.txHash,
6770
...parseTransactionInfo(r),
6871
};
6972
}
@@ -147,11 +150,10 @@ function parseSuccessful(
147150
...partial,
148151
transactionData: new SorobanDataBuilder(sim.transactionData!),
149152
minResourceFee: sim.minResourceFee!,
150-
cost: sim.cost!,
151-
...// coalesce 0-or-1-element results[] list into a single result struct
153+
// coalesce 0-or-1-element results[] list into a single result struct
152154
// with decoded fields if present
153155
// eslint-disable-next-line no-self-compare
154-
((sim.results?.length ?? 0 > 0) && {
156+
...((sim.results?.length ?? 0 > 0) && {
155157
result: sim.results!.map((row) => ({
156158
auth: (row.auth ?? []).map((entry) =>
157159
xdr.SorobanAuthorizationEntry.fromXDR(entry, 'base64')

src/rpc/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ export class RpcServer {
562562

563563
const result: Api.GetTransactionResponse = {
564564
status: raw.status,
565+
txHash: hash,
565566
latestLedger: raw.latestLedger,
566567
latestLedgerCloseTime: raw.latestLedgerCloseTime,
567568
oldestLedger: raw.oldestLedger,

test/unit/server/soroban/get_events_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ let getEventsResponseFixture = [
242242
ledgerClosedAt: "2022-11-16T16:10:41Z",
243243
contractId: "",
244244
id: "0164090849041387521-0000000003",
245-
pagingToken: "164090849041387521-3",
245+
cursor: "164090849041387521-3",
246246
inSuccessfulContractCall: true,
247247
topic: topicVals.slice(0, 2),
248248
value: eventVal,
@@ -254,7 +254,7 @@ let getEventsResponseFixture = [
254254
ledgerClosedAt: "2022-11-16T16:10:41Z",
255255
contractId,
256256
id: "0164090849041387521-0000000003",
257-
pagingToken: "164090849041387521-3",
257+
cursor: "164090849041387521-3",
258258
inSuccessfulContractCall: true,
259259
topic: topicVals.slice(0, 2),
260260
value: eventVal,
@@ -266,7 +266,7 @@ let getEventsResponseFixture = [
266266
ledgerClosedAt: "2022-11-16T16:10:41Z",
267267
contractId,
268268
id: "0164090849041387521-0000000003",
269-
pagingToken: "164090849041387521-3",
269+
cursor: "164090849041387521-3",
270270
inSuccessfulContractCall: true,
271271
topic: [topicVals[0]],
272272
value: eventVal,
@@ -278,7 +278,7 @@ let getEventsResponseFixture = [
278278
ledgerClosedAt: "2022-12-14T01:01:20Z",
279279
contractId,
280280
id: "0000000171798695936-0000000001",
281-
pagingToken: "0000000171798695936-0000000001",
281+
cursor: "0000000171798695936-0000000001",
282282
inSuccessfulContractCall: true,
283283
topic: topicVals,
284284
value: eventVal,

test/unit/server/soroban/get_transaction_test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ describe("Server#getTransaction", function () {
3333
transaction.sign(keypair);
3434

3535
this.transaction = transaction;
36-
this.hash = this.transaction.hash().toString("hex");
3736
this.blob = transaction.toEnvelope().toXDR().toString("base64");
3837
this.prepareAxios = (result) => {
3938
this.axiosMock
@@ -42,7 +41,7 @@ describe("Server#getTransaction", function () {
4241
jsonrpc: "2.0",
4342
id: 1,
4443
method: "getTransaction",
45-
params: { hash: this.hash },
44+
params: { hash: result.txHash },
4645
})
4746
.returns(Promise.resolve({ data: { id: 1, result } }));
4847
};
@@ -58,7 +57,7 @@ describe("Server#getTransaction", function () {
5857
this.prepareAxios(result);
5958

6059
this.server
61-
.getTransaction(this.hash)
60+
.getTransaction(result.txHash)
6261
.then(function (response) {
6362
expect(response).to.be.deep.equal(result);
6463
done();
@@ -84,7 +83,7 @@ describe("Server#getTransaction", function () {
8483
.returnValue();
8584

8685
this.server
87-
.getTransaction(this.hash)
86+
.getTransaction(result.txHash)
8887
.then((resp) => {
8988
expect(Object.keys(resp)).to.eql(Object.keys(expected));
9089
expect(resp).to.eql(expected);
@@ -99,7 +98,7 @@ describe("Server#getTransaction", function () {
9998
this.prepareAxios(result);
10099

101100
this.server
102-
.getTransaction(this.hash)
101+
.getTransaction(result.txHash)
103102
.then((resp) => {
104103
expect(resp).to.be.deep.equal(result);
105104
done();
@@ -152,6 +151,7 @@ function makeTxResult(status, addSoroban = true) {
152151

153152
return {
154153
status,
154+
txHash: "ae9f315c048d87a5f853bc15bf284a2c3c89eb0e1cb38c10409b77a877b830a8",
155155
latestLedger: 100,
156156
latestLedgerCloseTime: 12345,
157157
oldestLedger: 50,

test/unit/server/soroban/get_transactions_test.js

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function makeTxResult(ledger, applicationOrder, status) {
162162
return {
163163
status: status,
164164
ledger: ledger,
165+
txHash: "ae9f315c048d87a5f853bc15bf284a2c3c89eb0e1cb38c10409b77a877b830a8",
165166
createdAt: ledger * 25 + 100,
166167
applicationOrder: applicationOrder,
167168
feeBump: false,

test/unit/server/soroban/simulate_transaction_test.js

-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe("Server#simulateTransaction", async function (done) {
3838
),
3939
retval: xdr.ScVal.fromXDR(simulationResponse.results[0].xdr, "base64"),
4040
},
41-
cost: simulationResponse.cost,
4241
stateChanges: [
4342
{
4443
type: 2,
@@ -242,7 +241,6 @@ describe("Server#simulateTransaction", async function (done) {
242241
const expected = cloneSimulation(parsedSimulationResponse);
243242
// drop fields that go away with errors
244243
delete expected.result;
245-
delete expected.cost;
246244
delete expected.transactionData;
247245
delete expected.minResourceFee;
248246
delete expected.stateChanges;
@@ -270,7 +268,6 @@ function cloneSimulation(sim) {
270268
),
271269
retval: xdr.ScVal.fromXDR(sim.result.retval.toXDR()),
272270
},
273-
cost: sim.cost,
274271
stateChanges: sim.stateChanges,
275272
_parsed: sim._parsed,
276273
};
@@ -332,10 +329,6 @@ function baseSimulationResponse(results) {
332329
minResourceFee: "15",
333330
transactionData: new SorobanDataBuilder().build().toXDR("base64"),
334331
...(results !== undefined && { results }),
335-
cost: {
336-
cpuInsns: "1",
337-
memBytes: "2",
338-
},
339332
stateChanges: [
340333
{
341334
type: 2,
@@ -440,10 +433,6 @@ describe("works with real responses", function () {
440433
xdr: "AAAAEAAAAAEAAAACAAAADwAAAAVIZWxsbwAAAAAAAA8AAAAFQWxvaGEAAAA=",
441434
},
442435
],
443-
cost: {
444-
cpuInsns: "1322134",
445-
memBytes: "1207047",
446-
},
447436
restorePreamble: {
448437
transactionData: "",
449438
minResourceFee: "0",

0 commit comments

Comments
 (0)