@greymass/eosio
Advanced tools
Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "@greymass/eosio", | ||
"description": "Library for working with EOSIO blockchains", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"homepage": "https://github.com/greymass/eosio-core", | ||
@@ -31,3 +31,3 @@ "license": "BSD-3-Clause-No-Military-License", | ||
"@rollup/plugin-alias": "^3.1.4", | ||
"@rollup/plugin-commonjs": "^20.0.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-json": "^4.1.0", | ||
@@ -42,8 +42,8 @@ "@rollup/plugin-node-resolve": "^13.0.2", | ||
"@types/node": "^16.4.0", | ||
"@typescript-eslint/eslint-plugin": "^4.9.0", | ||
"@typescript-eslint/parser": "^4.9.0", | ||
"@typescript-eslint/eslint-plugin": "^5.4.0", | ||
"@typescript-eslint/parser": "^5.4.0", | ||
"chai": "^4.3.4", | ||
"eslint": "^7.19.0", | ||
"eslint": "^8.2.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-prettier": "^3.2.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"gh-pages": "^3.2.3", | ||
@@ -55,9 +55,9 @@ "mocha": "^9.0.2", | ||
"rollup": "^2.38.2", | ||
"rollup-plugin-dts": "^3.0.1", | ||
"rollup-plugin-dts": "^4.0.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"ts-node": "^10.0.0", | ||
"tsconfig-paths": "^3.10.1", | ||
"typedoc": "^0.21.4", | ||
"typedoc": "^0.22.9", | ||
"typescript": "^4.1.2" | ||
} | ||
} |
import {isInstanceOf} from '../utils' | ||
import type {ABISerializableObject} from '../serializer/serializable' | ||
import type {ABIDecoder} from '../serializer/decoder' | ||
import {abiEncode, ABIEncoder} from '../serializer/encoder' | ||
@@ -7,4 +10,4 @@ import {Name, NameType} from '../' | ||
export class ABI { | ||
static __className = 'ABI' | ||
export class ABI implements ABISerializableObject { | ||
static abiName = 'abi' | ||
static version = 'eosio::abi/1.1' | ||
@@ -46,2 +49,145 @@ | ||
static fromABI(decoder: ABIDecoder) { | ||
const version = decoder.readString() | ||
const types: ABI.TypeDef[] = [] | ||
const numTypes = decoder.readVaruint32() | ||
for (let i = 0; i < numTypes; i++) { | ||
types.push({new_type_name: decoder.readString(), type: decoder.readString()}) | ||
} | ||
const structs: ABI.Struct[] = [] | ||
const numStructs = decoder.readVaruint32() | ||
for (let i = 0; i < numStructs; i++) { | ||
const name = decoder.readString() | ||
const base = decoder.readString() | ||
const numFields = decoder.readVaruint32() | ||
const fields: ABI.Field[] = [] | ||
for (let j = 0; j < numFields; j++) { | ||
fields.push({name: decoder.readString(), type: decoder.readString()}) | ||
} | ||
structs.push({base, name, fields}) | ||
} | ||
const actions: ABI.Action[] = [] | ||
const numActions = decoder.readVaruint32() | ||
for (let i = 0; i < numActions; i++) { | ||
const name = Name.fromABI(decoder) | ||
const type = decoder.readString() | ||
const ricardian_contract = decoder.readString() | ||
actions.push({name, type, ricardian_contract}) | ||
} | ||
const tables: ABI.Table[] = [] | ||
const numTables = decoder.readVaruint32() | ||
for (let i = 0; i < numTables; i++) { | ||
const name = Name.fromABI(decoder) | ||
const index_type = decoder.readString() | ||
const key_names: string[] = [] | ||
const numKeyNames = decoder.readVaruint32() | ||
for (let j = 0; j < numKeyNames; j++) { | ||
key_names.push(decoder.readString()) | ||
} | ||
const key_types: string[] = [] | ||
const numKeyTypes = decoder.readVaruint32() | ||
for (let j = 0; j < numKeyTypes; j++) { | ||
key_types.push(decoder.readString()) | ||
} | ||
const type = decoder.readString() | ||
tables.push({name, index_type, key_names, key_types, type}) | ||
} | ||
const ricardian_clauses: ABI.Clause[] = [] | ||
const numClauses = decoder.readVaruint32() | ||
for (let i = 0; i < numClauses; i++) { | ||
const id = decoder.readString() | ||
const body = decoder.readString() | ||
ricardian_clauses.push({id, body}) | ||
} | ||
// error_messages, never used? | ||
const numErrors = decoder.readVaruint32() | ||
for (let i = 0; i < numErrors; i++) { | ||
decoder.advance(8) // uint64 error_code | ||
decoder.advance(decoder.readVaruint32()) // string error_msgr | ||
} | ||
// extensions, not used | ||
const numExtensions = decoder.readVaruint32() | ||
for (let i = 0; i < numExtensions; i++) { | ||
decoder.advance(2) // uint16 type | ||
decoder.advance(decoder.readVaruint32()) // bytes data | ||
} | ||
// variants is a binary extension for some reason even though extensions are defined on the type | ||
const variants: ABI.Variant[] = [] | ||
if (decoder.canRead()) { | ||
const numVariants = decoder.readVaruint32() | ||
for (let i = 0; i < numVariants; i++) { | ||
const name = decoder.readString() | ||
const types: string[] = [] | ||
const numTypes = decoder.readVaruint32() | ||
for (let j = 0; j < numTypes; j++) { | ||
types.push(decoder.readString()) | ||
} | ||
variants.push({name, types}) | ||
} | ||
} | ||
return new ABI({ | ||
version, | ||
types, | ||
structs, | ||
actions, | ||
tables, | ||
ricardian_clauses, | ||
variants, | ||
}) | ||
} | ||
toABI(encoder: ABIEncoder) { | ||
encoder.writeString(this.version) | ||
encoder.writeVaruint32(this.types.length) | ||
for (const type of this.types) { | ||
encoder.writeString(type.new_type_name) | ||
encoder.writeString(type.type) | ||
} | ||
encoder.writeVaruint32(this.structs.length) | ||
for (const struct of this.structs) { | ||
encoder.writeString(struct.name) | ||
encoder.writeString(struct.base) | ||
encoder.writeVaruint32(struct.fields.length) | ||
for (const field of struct.fields) { | ||
encoder.writeString(field.name) | ||
encoder.writeString(field.type) | ||
} | ||
} | ||
encoder.writeVaruint32(this.actions.length) | ||
for (const action of this.actions) { | ||
Name.from(action.name).toABI(encoder) | ||
encoder.writeString(action.type) | ||
encoder.writeString(action.ricardian_contract) | ||
} | ||
encoder.writeVaruint32(this.tables.length) | ||
for (const table of this.tables) { | ||
Name.from(table.name).toABI(encoder) | ||
encoder.writeString(table.index_type) | ||
encoder.writeVaruint32(table.key_names.length) | ||
for (const key of table.key_names) { | ||
encoder.writeString(key) | ||
} | ||
encoder.writeVaruint32(table.key_types.length) | ||
for (const key of table.key_types) { | ||
encoder.writeString(key) | ||
} | ||
encoder.writeString(table.type) | ||
} | ||
encoder.writeVaruint32(this.ricardian_clauses.length) | ||
for (const clause of this.ricardian_clauses) { | ||
encoder.writeString(clause.id) | ||
encoder.writeString(clause.body) | ||
} | ||
encoder.writeVaruint32(0) // error_messages | ||
encoder.writeVaruint32(0) // extensions | ||
encoder.writeVaruint32(this.variants.length) | ||
for (const variant of this.variants) { | ||
encoder.writeString(variant.name) | ||
encoder.writeVaruint32(variant.types.length) | ||
for (const type of variant.types) { | ||
encoder.writeString(type) | ||
} | ||
} | ||
} | ||
resolveType(name: string): ABI.ResolvedType { | ||
@@ -115,2 +261,32 @@ const types: {[name: string]: ABI.ResolvedType} = {} | ||
} | ||
equals(other: ABIDef): boolean { | ||
const o = ABI.from(other) | ||
if ( | ||
this.version != o.version || | ||
this.types.length != o.types.length || | ||
this.structs.length != o.structs.length || | ||
this.actions.length != o.actions.length || | ||
this.tables.length != o.tables.length || | ||
this.ricardian_clauses.length != o.ricardian_clauses.length || | ||
this.variants.length != o.variants.length | ||
) { | ||
return false | ||
} | ||
return abiEncode({object: this}).equals(abiEncode({object: o})) | ||
} | ||
toJSON() { | ||
return { | ||
version: this.version, | ||
types: this.types, | ||
structs: this.structs, | ||
actions: this.actions, | ||
tables: this.tables, | ||
ricardian_clauses: this.ricardian_clauses, | ||
error_messages: [], | ||
abi_extensions: [], | ||
variants: this.variants, | ||
} | ||
} | ||
} | ||
@@ -117,0 +293,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
844983
16694