add hso w/ api version

This commit is contained in:
Denis Angell
2024-05-22 02:27:02 +02:00
committed by RichardAH
parent 6c3da46a1b
commit 59ecbd9932
2 changed files with 25 additions and 0 deletions

View File

@@ -37,6 +37,10 @@ hook(
Json::Value
hso(std::vector<uint8_t> const& wasmBytes, void (*f)(Json::Value& jv) = 0);
Json::Value
hso(std::vector<uint8_t> const& wasmBytes, uint16_t apiVersion, void (*f)(Json::Value& jv) = 0);
Json::Value
hso(std::string const& wasmHex, void (*f)(Json::Value& jv) = 0);

View File

@@ -81,6 +81,27 @@ hso(std::vector<uint8_t> const& wasmBytes, void (*f)(Json::Value& jv))
return jv;
}
Json::Value
hso(std::vector<uint8_t> const& wasmBytes, uint16_t apiVersion = 0, void (*f)(Json::Value& jv))
{
if (wasmBytes.size() == 0)
throw std::runtime_error("empty hook wasm passed to hso()");
Json::Value jv;
jv[jss::CreateCode] = strHex(wasmBytes);
{
jv[jss::HookOn] =
"0000000000000000000000000000000000000000000000000000000000000000";
jv[jss::HookNamespace] = to_string(uint256{beast::zero});
jv[jss::HookApiVersion] = Json::Value{apiVersion};
}
if (f)
f(jv);
return jv;
}
Json::Value
hso(std::string const& wasmHex, void (*f)(Json::Value& jv))
{