mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-19 10:05:48 +00:00
add util_raddr, util_accid
This commit is contained in:
@@ -31,8 +31,11 @@ public:
|
||||
// rollback
|
||||
|
||||
/// util APIs
|
||||
// util_raddr
|
||||
// util_accid
|
||||
Expected<std::string, HookReturnCode>
|
||||
util_raddr(Bytes const& accountID) const;
|
||||
|
||||
Expected<Bytes, HookReturnCode>
|
||||
util_accid(std::string raddress) const;
|
||||
|
||||
Expected<bool, HookReturnCode>
|
||||
util_verify(Slice const& data, Slice const& sig, Slice const& key) const;
|
||||
|
||||
@@ -305,8 +305,24 @@ using namespace hook_float;
|
||||
// rollback
|
||||
|
||||
/// util APIs
|
||||
// util_raddr
|
||||
// util_accid
|
||||
Expected<std::string, HookReturnCode>
|
||||
HookAPI::util_raddr(Bytes const& accountID) const
|
||||
{
|
||||
if (accountID.size() != 20)
|
||||
return Unexpected(INVALID_ARGUMENT);
|
||||
|
||||
return encodeBase58Token(
|
||||
TokenType::AccountID, accountID.data(), accountID.size());
|
||||
}
|
||||
|
||||
Expected<Bytes, HookReturnCode>
|
||||
HookAPI::util_accid(std::string raddress) const
|
||||
{
|
||||
auto const result = decodeBase58Token(raddress, TokenType::AccountID);
|
||||
if (result.empty())
|
||||
return Unexpected(INVALID_ARGUMENT);
|
||||
return Bytes(result.data(), result.data() + result.size());
|
||||
}
|
||||
|
||||
Expected<bool, HookReturnCode>
|
||||
HookAPI::util_verify(Slice const& data, Slice const& sig, Slice const& key)
|
||||
|
||||
@@ -3064,11 +3064,12 @@ DEFINE_HOOK_FUNCTION(
|
||||
if (NOT_IN_BOUNDS(read_ptr, read_len, memory_length))
|
||||
return OUT_OF_BOUNDS;
|
||||
|
||||
if (read_len != 20)
|
||||
return INVALID_ARGUMENT;
|
||||
|
||||
std::string raddr =
|
||||
encodeBase58Token(TokenType::AccountID, memory + read_ptr, read_len);
|
||||
hook::HookAPI api(hookCtx);
|
||||
auto const result =
|
||||
api.util_raddr(Bytes{memory + read_ptr, memory + read_ptr + read_len});
|
||||
if (!result)
|
||||
return result.error();
|
||||
auto const& raddr = result.value();
|
||||
|
||||
if (write_len < raddr.size())
|
||||
return TOO_SMALL;
|
||||
@@ -3119,12 +3120,14 @@ DEFINE_HOOK_FUNCTION(
|
||||
|
||||
std::string raddr{buffer};
|
||||
|
||||
auto const result = decodeBase58Token(raddr, TokenType::AccountID);
|
||||
if (result.empty())
|
||||
return INVALID_ARGUMENT;
|
||||
hook::HookAPI api(hookCtx);
|
||||
auto const result = api.util_accid(raddr);
|
||||
if (!result)
|
||||
return result.error();
|
||||
auto const& accountID = result.value();
|
||||
|
||||
WRITE_WASM_MEMORY_AND_RETURN(
|
||||
write_ptr, write_len, result.data(), 20, memory, memory_length);
|
||||
write_ptr, write_len, accountID.data(), 20, memory, memory_length);
|
||||
|
||||
HOOK_TEARDOWN();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user