Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wharfkit/antelope",
"description": "Library for working with Antelope powered blockchains.",
"version": "1.1.0",
"version": "1.2.0-rc1",
"homepage": "https://github.com/wharfkit/antelope",
"license": "BSD-3-Clause-No-Military-License",
"main": "lib/antelope.js",
Expand Down
35 changes: 33 additions & 2 deletions src/chain/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {ABISerializableObject} from '../serializer/serializable'
import {abiDecode, ABIDecoder} from '../serializer/decoder'
import {abiEncode, ABIEncoder} from '../serializer/encoder'

import {Blob, Name, NameType} from '../'
import {Blob, Name, NameType, UInt64, UInt64Type} from '../'

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

Expand All @@ -26,6 +26,8 @@ export class ABI implements ABISerializableObject {
ricardian_clauses: ABI.Clause[]
/// Action Results
action_results: ABI.ActionResult[]
/// Sync Calls
calls: ABI.Call[]

constructor(args: Partial<ABI.Def>) {
this.version = args.version || ABI.version
Expand All @@ -36,6 +38,7 @@ export class ABI implements ABISerializableObject {
this.tables = args.tables || []
this.ricardian_clauses = args.ricardian_clauses || []
this.action_results = args.action_results || []
this.calls = args.calls || []
}

static from(value: ABIDef) {
Expand Down Expand Up @@ -141,6 +144,17 @@ export class ABI implements ABISerializableObject {
action_results.push({name, result_type})
}
}
const calls: ABI.Call[] = []
if (decoder.canRead()) {
const numCalls = decoder.readVaruint32()
for (let i = 0; i < numCalls; i++) {
const name = decoder.readString()
const type = decoder.readString()
const id = UInt64.fromABI(decoder)
const result_type = decoder.readString()
calls.push({name, type, id, result_type})
}
}
return new ABI({
version,
types,
Expand All @@ -150,6 +164,7 @@ export class ABI implements ABISerializableObject {
ricardian_clauses,
variants,
action_results,
calls,
})
}

Expand Down Expand Up @@ -210,6 +225,13 @@ export class ABI implements ABISerializableObject {
Name.from(result.name).toABI(encoder)
encoder.writeString(result.result_type)
}
encoder.writeVaruint32(this.calls.length)
for (const call of this.calls) {
encoder.writeString(call.name)
encoder.writeString(call.type)
UInt64.from(String(call.id)).toABI(encoder)
encoder.writeString(call.result_type)
}
}

resolveType(name: string): ABI.ResolvedType {
Expand Down Expand Up @@ -291,7 +313,8 @@ export class ABI implements ABISerializableObject {
this.tables.length != o.tables.length ||
this.ricardian_clauses.length != o.ricardian_clauses.length ||
this.variants.length != o.variants.length ||
this.action_results.length != o.action_results.length
this.action_results.length != o.action_results.length ||
this.calls.length != o.calls.length
) {
return false
}
Expand All @@ -310,6 +333,7 @@ export class ABI implements ABISerializableObject {
abi_extensions: [],
variants: this.variants,
action_results: this.action_results,
calls: this.calls,
}
}
}
Expand Down Expand Up @@ -357,11 +381,18 @@ export namespace ABI {
tables: Table[]
ricardian_clauses: Clause[]
action_results: ActionResult[]
calls: Call[]
}
export interface ActionResult {
name: NameType
result_type: string
}
export interface Call {
name: string
type: string
id: UInt64Type
result_type: string
}
export class ResolvedType {
name: string
id: number
Expand Down
5 changes: 5 additions & 0 deletions src/chain/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export class Action extends Struct {
let type: string | undefined
if (abi) {
type = ABI.from(abi).getActionType(object.name)
if (!type) {
throw new Error(
`The action "${object.name}" does not exist on the ABI provided.`
)
}
} else if (!data.constructor || data.constructor.abiName === undefined) {
throw new Error(
'Missing ABI definition when creating action with untyped action data'
Expand Down
1 change: 1 addition & 0 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ suite('api v1', function () {
result_type: 'Result',
},
],
calls: [],
}
const info = await jungle4.v1.chain.get_info()
const header = info.getTransactionHeader()
Expand Down
14 changes: 14 additions & 0 deletions test/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,18 @@ suite('chain', function () {
Serializer.encode({object: {input: [1, 2, 3, 4]}, abi, type: 'fixed'}).hexString
)
})

test('action does not exist in ABI', function () {
assert.throws(() =>
Action.from(
{
account: 'foo',
name: 'bar',
authorization: [{actor: 'foo', permission: 'bar'}],
data: {},
},
{}
)
)
})
})
79 changes: 79 additions & 0 deletions test/data/6894cf2c141822d1b9d92ee77affc01f4dad75f0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"api": "https://jungle4.api.eosnation.io",
"headers": {
"access-control-allow-headers": "Origin, X-Requested-With, Content-Type, Accept",
"access-control-allow-methods": "GET, POST, HEAD, OPTIONS",
"access-control-allow-origin": "*",
"connection": "close",
"content-length": "1683",
"content-type": "application/json",
"date": "Fri, 06 Oct 2023 18:23:19 GMT",
"server": "nginx/1.24.0"
},
"status": 202,
"json": {
"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
}
},
"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}}"
}
Loading