Skip to content

Instantly share code, notes, and snippets.

@conr2d
Last active February 4, 2023 17:38
Show Gist options
  • Save conr2d/82a4de1b45a4538aadd684af6610156f to your computer and use it in GitHub Desktop.
Save conr2d/82a4de1b45a4538aadd684af6610156f to your computer and use it in GitHub Desktop.
EOSIO GET_CODE_HASH example
#pragma once
#include <eosio/fixed_bytes.hpp>
#include <eosio/name.hpp>
#include <eosio/varint.hpp>
#include <array>
namespace eosio {
namespace internal_use_do_not_use {
extern "C" {
__attribute__((eosio_wasm_import))
uint32_t get_code_hash(uint64_t account, uint32_t struct_version, char* data, uint32_t maxlen);
}
}
// 43 bytes
struct code_hash_result {
unsigned_int struct_version; // 1
uint64_t code_sequence; // 8
checksum256 code_hash; // 32
uint8_t vm_type; // 1
uint8_t vm_version; // 1
EOSLIB_SERIALIZE(code_hash_result, (struct_version)(code_sequence)(code_hash)(vm_type)(vm_version))
};
code_hash_result get_code_hash(name account) {
std::array<char, 64> buffer;
auto size = internal_use_do_not_use::get_code_hash(account.value, 0, buffer.data(), buffer.size());
code_hash_result result{};
datastream<char*> ds(buffer.begin(), size);
ds >> result;
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment