Skip to content

Commit 966fbde

Browse files
committed
Add support to ABI for the calls field in 1.3
1 parent 44c68ac commit 966fbde

File tree

4 files changed

+436
-3
lines changed

4 files changed

+436
-3
lines changed

src/chain/abi.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {ABISerializableObject} from '../serializer/serializable'
33
import {abiDecode, ABIDecoder} from '../serializer/decoder'
44
import {abiEncode, ABIEncoder} from '../serializer/encoder'
55

6-
import {Blob, Name, NameType} from '../'
6+
import {Blob, Name, NameType, UInt64, UInt64Type} from '../'
77

88
export type ABIDef = string | Partial<ABI.Def> | ABI | Blob
99

@@ -26,6 +26,8 @@ export class ABI implements ABISerializableObject {
2626
ricardian_clauses: ABI.Clause[]
2727
/// Action Results
2828
action_results: ABI.ActionResult[]
29+
/// Sync Calls
30+
calls: ABI.Call[]
2931

3032
constructor(args: Partial<ABI.Def>) {
3133
this.version = args.version || ABI.version
@@ -36,6 +38,7 @@ export class ABI implements ABISerializableObject {
3638
this.tables = args.tables || []
3739
this.ricardian_clauses = args.ricardian_clauses || []
3840
this.action_results = args.action_results || []
41+
this.calls = args.calls || []
3942
}
4043

4144
static from(value: ABIDef) {
@@ -141,6 +144,17 @@ export class ABI implements ABISerializableObject {
141144
action_results.push({name, result_type})
142145
}
143146
}
147+
const calls: ABI.Call[] = []
148+
if (decoder.canRead()) {
149+
const numCalls = decoder.readVaruint32()
150+
for (let i = 0; i < numCalls; i++) {
151+
const name = decoder.readString()
152+
const type = decoder.readString()
153+
const id = UInt64.fromABI(decoder)
154+
const result_type = decoder.readString()
155+
calls.push({name, type, id, result_type})
156+
}
157+
}
144158
return new ABI({
145159
version,
146160
types,
@@ -150,6 +164,7 @@ export class ABI implements ABISerializableObject {
150164
ricardian_clauses,
151165
variants,
152166
action_results,
167+
calls,
153168
})
154169
}
155170

@@ -210,6 +225,13 @@ export class ABI implements ABISerializableObject {
210225
Name.from(result.name).toABI(encoder)
211226
encoder.writeString(result.result_type)
212227
}
228+
encoder.writeVaruint32(this.calls.length)
229+
for (const call of this.calls) {
230+
encoder.writeString(call.name)
231+
encoder.writeString(call.type)
232+
UInt64.from(String(call.id)).toABI(encoder)
233+
encoder.writeString(call.result_type)
234+
}
213235
}
214236

215237
resolveType(name: string): ABI.ResolvedType {
@@ -291,7 +313,8 @@ export class ABI implements ABISerializableObject {
291313
this.tables.length != o.tables.length ||
292314
this.ricardian_clauses.length != o.ricardian_clauses.length ||
293315
this.variants.length != o.variants.length ||
294-
this.action_results.length != o.action_results.length
316+
this.action_results.length != o.action_results.length ||
317+
this.calls.length != o.calls.length
295318
) {
296319
return false
297320
}
@@ -310,6 +333,7 @@ export class ABI implements ABISerializableObject {
310333
abi_extensions: [],
311334
variants: this.variants,
312335
action_results: this.action_results,
336+
calls: this.calls,
313337
}
314338
}
315339
}
@@ -357,11 +381,18 @@ export namespace ABI {
357381
tables: Table[]
358382
ricardian_clauses: Clause[]
359383
action_results: ActionResult[]
384+
calls: Call[]
360385
}
361386
export interface ActionResult {
362387
name: NameType
363388
result_type: string
364389
}
390+
export interface Call {
391+
name: string
392+
type: string
393+
id: UInt64Type
394+
result_type: string
395+
}
365396
export class ResolvedType {
366397
name: string
367398
id: number

test/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ suite('api v1', function () {
848848
result_type: 'Result',
849849
},
850850
],
851+
calls: [],
851852
}
852853
const info = await jungle4.v1.chain.get_info()
853854
const header = info.getTransactionHeader()
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"api": "https://jungle4.api.eosnation.io",
3+
"headers": {
4+
"access-control-allow-headers": "Origin, X-Requested-With, Content-Type, Accept",
5+
"access-control-allow-methods": "GET, POST, HEAD, OPTIONS",
6+
"access-control-allow-origin": "*",
7+
"connection": "close",
8+
"content-length": "1683",
9+
"content-type": "application/json",
10+
"date": "Fri, 06 Oct 2023 18:23:19 GMT",
11+
"server": "nginx/1.24.0"
12+
},
13+
"status": 202,
14+
"json": {
15+
"transaction_id": "ac0b580f76914b330294081efca07e320777ae4227261f134fe39d38a7d5536f",
16+
"processed": {
17+
"id": "ac0b580f76914b330294081efca07e320777ae4227261f134fe39d38a7d5536f",
18+
"block_num": 101720398,
19+
"block_time": "2023-10-06T18:23:20.000",
20+
"producer_block_id": null,
21+
"receipt": {
22+
"status": "executed",
23+
"cpu_usage_us": 188,
24+
"net_usage_words": 22
25+
},
26+
"elapsed": 188,
27+
"net_usage": 176,
28+
"scheduled": false,
29+
"action_traces": [
30+
{
31+
"action_ordinal": 1,
32+
"creator_action_ordinal": 0,
33+
"closest_unnotified_ancestor_action_ordinal": 0,
34+
"receipt": {
35+
"receiver": "eosio",
36+
"act_digest": "756984726b93751e921d4d50e0a7ad53e6a56db8f4b0ed617096d712d504336b",
37+
"global_sequence": 134833924,
38+
"recv_sequence": 101790722,
39+
"auth_sequence": [["corecorecore", 1179]],
40+
"code_sequence": 4,
41+
"abi_sequence": 4
42+
},
43+
"receiver": "eosio",
44+
"act": {
45+
"account": "eosio",
46+
"name": "setabi",
47+
"authorization": [
48+
{
49+
"actor": "corecorecore",
50+
"permission": "active"
51+
}
52+
],
53+
"data": {
54+
"account": "corecorecore",
55+
"abi": "0e656f73696f3a3a6162692f312e32000206526573756c7400010269640675696e743332047465737400010b656f735f6163636f756e74046e616d6501000000000090b1ca047465737400000000000001000000000090b1ca06526573756c74"
56+
},
57+
"hex_data": "a02e45ea52a42e45600e656f73696f3a3a6162692f312e32000206526573756c7400010269640675696e743332047465737400010b656f735f6163636f756e74046e616d6501000000000090b1ca047465737400000000000001000000000090b1ca06526573756c74"
58+
},
59+
"context_free": false,
60+
"elapsed": 63,
61+
"console": "",
62+
"trx_id": "ac0b580f76914b330294081efca07e320777ae4227261f134fe39d38a7d5536f",
63+
"block_num": 101720398,
64+
"block_time": "2023-10-06T18:23:20.000",
65+
"producer_block_id": null,
66+
"account_ram_deltas": [],
67+
"except": null,
68+
"error_code": null,
69+
"return_value_hex_data": "",
70+
"inline_traces": []
71+
}
72+
],
73+
"account_ram_delta": null,
74+
"except": null,
75+
"error_code": null
76+
}
77+
},
78+
"text": "{\"transaction_id\":\"ac0b580f76914b330294081efca07e320777ae4227261f134fe39d38a7d5536f\",\"processed\":{\"id\":\"ac0b580f76914b330294081efca07e320777ae4227261f134fe39d38a7d5536f\",\"block_num\":101720398,\"block_time\":\"2023-10-06T18:23:20.000\",\"producer_block_id\":null,\"receipt\":{\"status\":\"executed\",\"cpu_usage_us\":188,\"net_usage_words\":22},\"elapsed\":188,\"net_usage\":176,\"scheduled\":false,\"action_traces\":[{\"action_ordinal\":1,\"creator_action_ordinal\":0,\"closest_unnotified_ancestor_action_ordinal\":0,\"receipt\":{\"receiver\":\"eosio\",\"act_digest\":\"756984726b93751e921d4d50e0a7ad53e6a56db8f4b0ed617096d712d504336b\",\"global_sequence\":134833924,\"recv_sequence\":101790722,\"auth_sequence\":[[\"corecorecore\",1179]],\"code_sequence\":4,\"abi_sequence\":4},\"receiver\":\"eosio\",\"act\":{\"account\":\"eosio\",\"name\":\"setabi\",\"authorization\":[{\"actor\":\"corecorecore\",\"permission\":\"active\"}],\"data\":{\"account\":\"corecorecore\",\"abi\":\"0e656f73696f3a3a6162692f312e32000206526573756c7400010269640675696e743332047465737400010b656f735f6163636f756e74046e616d6501000000000090b1ca047465737400000000000001000000000090b1ca06526573756c74\"},\"hex_data\":\"a02e45ea52a42e45600e656f73696f3a3a6162692f312e32000206526573756c7400010269640675696e743332047465737400010b656f735f6163636f756e74046e616d6501000000000090b1ca047465737400000000000001000000000090b1ca06526573756c74\"},\"context_free\":false,\"elapsed\":63,\"console\":\"\",\"trx_id\":\"ac0b580f76914b330294081efca07e320777ae4227261f134fe39d38a7d5536f\",\"block_num\":101720398,\"block_time\":\"2023-10-06T18:23:20.000\",\"producer_block_id\":null,\"account_ram_deltas\":[],\"except\":null,\"error_code\":null,\"return_value_hex_data\":\"\",\"inline_traces\":[]}],\"account_ram_delta\":null,\"except\":null,\"error_code\":null}}"
79+
}

0 commit comments

Comments
 (0)