Function decodeGenesisData

  • Function to decode genesis data used to launch a new blockchain. The different values are deserialized using protobuffers. One of the arguments is the dictionary which contains the relevant information for the deserialization. By default the function contains the dictionary for the following keys:

    • "object_key::head_block"
    • "object_key::chain_id"
    • "object_key::genesis_key"
    • "object_key::resource_limit_data"
    • "object_key::max_account_resources"
    • "object_key::protocol_descriptor"
    • "object_key::compute_bandwidth_registry"
    • "object_key::block_hash_code"

    Example

    const genesisData = {
    entries: [
    {
    space: { system: true },
    key: "EiC3nO+XbeKg4C8ugW7M7XdfmJKY4i3l91KoJWxosQPImA==",
    value: "AMpASH7CjUHBpl2QR8E5lGKVjVLAvJRg5g==",
    },
    ],
    }

    const genesisDataDecoded = await decodeGenesisData(genesisData);
    console.log(genesisDataDecoded);

    // {
    // entries: [
    // {
    // space: { system: true },
    // key: "EiC3nO+XbeKg4C8ugW7M7XdfmJKY4i3l91KoJWxosQPImA==",
    // alias: "object_key::genesis_key",
    // value: "1KSQWDyUnFZ48Pf2hsW8Akh1b5fKUWc8Z3",
    // },
    // ],
    // };

    Example

    adding a custom dictionary

    const genesisData = {
    entries: [
    {
    key: "difficulty_metadata_key",
    space: {
    id: 1,
    system: true,
    zone: "AMpASH7CjUHBpl2QR8E5lGKVjVLAvJRg5g==",
    },
    value:
    "CiD//////////////////////////////////////////xCAlIus4S8aIBERERERERERERERERERERERERERERERERERERERERERIAo=",
    },
    ],
    };

    const powJson = {
    nested: {
    mypackage: {
    nested: {
    difficulty_metadata: {
    "fields": {
    "target": { "type": "bytes", "id": 1 },
    "last_block_time": { "type": "uint64", "id": 2,
    "options": { "jstype": "JS_STRING" }
    },
    "difficulty": { "type": "bytes", "id": 3 },
    "target_block_interval": { "type": "uint64", "id": 4,
    "options": { "jstype": "JS_STRING" }
    }
    }
    },
    }
    }
    }
    }

    const dic = {
    difficulty_metadata_key: {
    serializer: new Serializer(powJson),
    typeName: "difficulty_metadata",
    },
    };

    const genesisDataDecoded = await decodeGenesisData(genesisData, dic);
    console.log(genesisData);

    // {
    // entries: [
    // {
    // space: { system: true, zone, id: 1 },
    // key: "difficulty_metadata_key",
    // value: {
    // target: "__________________________________________8=",
    // last_block_time: "1641038400000",
    // difficulty: "ERERERERERERERERERERERERERERERERERERERERERE=",
    // target_block_interval: "10",
    // },
    // },
    // ],
    // };

    Parameters

    Returns Promise<GenesisDataDecoded>

Generated using TypeDoc