wharfkit / antelope

Core types, client interfaces, and other tools for working with Antelope-based blockchains.
Other
44 stars 23 forks source link

Want to deserialize SHIP data, cannot import ABI #60

Closed cc32d9 closed 1 year ago

cc32d9 commented 1 year ago

I've got a copy of this JSON locally: https://github.com/AntelopeIO/leap/blob/main/libraries/state_history/abi.cpp

I want to create an ABI object in order to deserialize the state history data, but this JSON doesn't have actions and ricardian clauses:

error TS2739: Type '{ version: string; structs: ({ name: string; fields: { name: string; type: string; }[]; base?: undefined; } | { name: string; base: string; fields: { name: string; type: string; }[]; })[]; types: { new_type_name: string; type: string; }[]; variants: { ...; }[]; tables: { ...; }[]; }' is missing the following properties from type 'Def': actions, ricardian_clauses
cc32d9 commented 1 year ago

here's the code I'm trying to work with:

import eosio from '@greymass/eosio';
import shipABIJSON from '../state_history_plugin_abi.json';

export class ChronosClient {
    shipABI: eosio.ABI.Def;

    constructor(options: cassandra.ClientOptions) {
        this.shipABI = shipABIJSON;
    }
}

after adding "actions": [], "ricardian_clauses": [] it now complains that Struct is missing the "base" field.

cc32d9 commented 1 year ago

did a dirty hack, but it will be great to have a better solution:

        this.shipABI =  {
            version: '',
            types: [],
            variants: [],
            structs: [],
            actions: [],
            tables: [],
            ricardian_clauses: [],
        };

        ['version', 'types', 'structs', 'tables', 'variants'].forEach((element) => {
            this.shipABI[element] = shipABIJSON[element];
        });
cc32d9 commented 1 year ago

ended up in this hack, but it needs to be more beautiful https://github.com/EOSChronicleProject/chronos-client-npm/blob/b42154ebbd01a074bc8c87e66cd6ef129841f5db/src/chronos-client.ts

cc32d9 commented 1 year ago

this way it works well: https://github.com/EOSChronicleProject/chronos-client-npm/blob/abb109e10094c7ae4d5062753b2cf767793c3d71/src/chronos-client.ts#L27

jnordberg commented 1 year ago

Glad you got it working! (Another solution could be to use the ABIDef type that allows partial fields in the ABI, or just keeping a reference to a eosio-core ABI object created by ABI.from(abiJson)) In the future though please use the forums or telegram for support, we want to try to keep the noise at a minimum in our bug tracker. Thanks!