Skip to content

Option to expand setabi abi #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
heifner opened this issue May 8, 2023 · 0 comments
Open

Option to expand setabi abi #1144

heifner opened this issue May 8, 2023 · 0 comments
Labels
discussion enhancement New feature or request

Comments

@heifner
Copy link
Member

heifner commented May 8, 2023

cleos has the ability to unpack_transaction with --unpack-action-data, for example:
cleos convert unpack_transaction --unpack-action-data t.txt
If the transaction is a eosio::setabi it would be nice to have some way to expand the setabi abi field.

t.txt

{
"compression":
"zlib",
"packed_context_free_data":
"",
"packed_trx":
"78daf314894c79adf665e3b75d0c40c00822185e198482a81dc99b0e010526f024ccdab71a24b0e2ad91d176b8c85a46bed4fce2cc7c2babc4a44c7d433d030666ce92a2c4bce2b4d4a262065696b4a2fc5c96bcc4dc54a6927c30cd51589a9857925952c99a585c9c5ac2929b9a9bcf565c52949997ce9a9c5f9a57c29a99576266c2999c919a9c5d5a9c52c2c0c0016603ad61606066603810ae6b73f62c92250c0c2738b33b429c91b53030ccd0020a21e98402002532487e",
"signatures":
[
"SIG_K1_Kd5ennMQtr25EVpwretDaeqm9gVKZUkkDKX6HHJQ4dMrMjGDKYS4LAF4bs5j7u1Wfc8Y5trZZZwn39Gy3on7ZxWLb43vPX"
]
}

./cleos -u http://mainnet.genereos.io convert unpack_transaction --unpack-action-data t.txt
outputs:

{
  "expiration": "2023-05-08T15:24:57",
  "ref_block_num": 9963,
  "ref_block_prefix": 3136729588,
  "max_net_usage_words": 0,
  "max_cpu_usage_ms": 0,
  "delay_sec": 0,
  "context_free_actions": [],
  "actions": [{
      "account": "eosio",
      "name": "setabi",
      "authorization": [{
          "actor": "pizdos.gm",
          "permission": "active"
        }
      ],
      "data": {
        "account": "pizdos.gm",
        "abi": "0e656f73696f3a3a6162692f312e300003097472616e736665727300050466726f6d046e616d6502746f046e616d65087175616e74697479056173736574046d656d6f06737472696e6705636f756e7405696e74363409636865636b75736474000008636865636b656f730000030000c0572d3ccdcd097472616e7366657273000000c8096b88544309636865636b7573647400000000982a88544308636865636b656f730000000000000000"
      },
      "hex_data": "0000900c609abeabad010e656f73696f3a3a6162692f312e300003097472616e736665727300050466726f6d046e616d6502746f046e616d65087175616e74697479056173736574046d656d6f06737472696e6705636f756e7405696e74363409636865636b75736474000008636865636b656f730000030000c0572d3ccdcd097472616e7366657273000000c8096b88544309636865636b7573647400000000982a88544308636865636b656f730000000000000000"
    }
  ],
  "transaction_extensions": [],
  "signatures": [
    "SIG_K1_Kd5ennMQtr25EVpwretDaeqm9gVKZUkkDKX6HHJQ4dMrMjGDKYS4LAF4bs5j7u1Wfc8Y5trZZZwn39Gy3on7ZxWLb43vPX"
  ],
  "context_free_data": []
}

Would be nice to have an ability to expand that abi hex string.

Here is an example abieos program that will expand the hex string:

#include <eosio/abi.hpp>
#include <eosio/from_bin.hpp>
#include <eosio/from_json.hpp>
#include <fstream>
#include <iostream>

int main(int argc, char** argv) {
    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " abifile.\n";
        return 1;
    }

    std::ifstream in_file(argv[1]);
    std::string abi_hex{std::istreambuf_iterator<char>(in_file), std::istreambuf_iterator<char>()};
    if (abi_hex[0] == '"' && abi_hex.back() == '"')
        abi_hex = abi_hex.substr(1, abi_hex.size() - 2);

    std::vector<char> abi_binary(abi_hex.size() / 2);
    if (eosio::unhex(abi_binary.data(), abi_hex.begin(), abi_hex.end())) {

        eosio::input_stream istrm(abi_binary);
        eosio::abi_def abi;
        eosio::from_bin(abi, istrm);

        std::vector<char> obuf;
        eosio::vector_stream ostrm(obuf);
        eosio::to_json(abi, ostrm);

        std::copy(obuf.begin(), obuf.end(), std::ostream_iterator<char>(std::cout));

        return 0;
    } else {
        std::cerr << "unhex error\n";
        return 1;
    }
}

If done in cleos would want to use abi_serializer with abidef definition to expand the hex string.

Should this be an option to unpack_transaction, unpack_action_data ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants