add otxn_param hook api

This commit is contained in:
Richard Holland
2023-01-04 11:36:01 +00:00
parent 75f3b93c78
commit f70ddf9e65
4 changed files with 60 additions and 0 deletions

View File

@@ -545,6 +545,7 @@ namespace hook_api
"otxn_generation",
"otxn_id",
"otxn_type",
"otxn_param",
"rollback",
"slot",
"slot_clear",

View File

@@ -199,6 +199,8 @@ namespace hook_api
DECLARE_HOOK_FUNCTION(int64_t, otxn_id, uint32_t write_ptr, uint32_t write_len, uint32_t flags );
DECLARE_HOOK_FUNCNARG(int64_t, otxn_type );
DECLARE_HOOK_FUNCTION(int64_t, otxn_slot, uint32_t slot_no );
DECLARE_HOOK_FUNCTION(int64_t, otxn_param, uint32_t write_ptr, uint32_t write_len,
uint32_t read_ptr, uint32_t read_len);
DECLARE_HOOK_FUNCTION(int64_t, meta_slot, uint32_t slot_no );
@@ -583,6 +585,8 @@ namespace hook
ADD_HOOK_FUNCTION(otxn_id, ctx);
ADD_HOOK_FUNCTION(otxn_type, ctx);
ADD_HOOK_FUNCTION(otxn_slot, ctx);
ADD_HOOK_FUNCTION(otxn_param, ctx);
ADD_HOOK_FUNCTION(hook_account, ctx);
ADD_HOOK_FUNCTION(hook_hash, ctx);
ADD_HOOK_FUNCTION(hook_again, ctx);

View File

@@ -4869,6 +4869,55 @@ DEFINE_HOOK_FUNCTION(
return double_to_xfl(result);
}
DEFINE_HOOK_FUNCTION(
int64_t,
otxn_param,
uint32_t write_ptr, uint32_t write_len,
uint32_t read_ptr, uint32_t read_len )
{
HOOK_SETUP(); // populates memory_ctx, memory, memory_length, applyCtx, hookCtx on current stack
if (NOT_IN_BOUNDS(read_ptr, read_len, memory_length))
return OUT_OF_BOUNDS;
if (read_len < 1)
return TOO_SMALL;
if (read_len > 32)
return TOO_BIG;
if (!applyCtx.tx.isFieldPresent(sfHookParameters))
return DOESNT_EXIST;
std::vector<uint8_t> paramName { read_ptr + memory, read_ptr + read_len + memory };
auto const& params = applyCtx.tx.getFieldArray(sfHookParameters);
for (auto const& param: params)
{
if (!param.isFieldPresent(sfHookParameterName) ||
param.getFieldVL(sfHookParameterName) != paramName)
continue;
if (!param.isFieldPresent(sfHookParameterValue))
return DOESNT_EXIST;
auto const& val = param.getFieldVL(sfHookParameterValue);
if (val.empty())
return DOESNT_EXIST;
if (val.size() < write_len)
return TOO_SMALL;
WRITE_WASM_MEMORY_AND_RETURN(
write_ptr, write_len,
val.data(), val.size(),
memory, memory_length);
}
return DOESNT_EXIST;
}
DEFINE_HOOK_FUNCTION(
int64_t,
hook_param,

View File

@@ -5146,6 +5146,11 @@ public:
// RH TODO: test behaviour on emit failure
}
void
test_otxn_param()
{
}
void
test_slot()
{
@@ -9703,6 +9708,7 @@ public:
test_otxn_id(); //
test_otxn_slot(); //
test_otxn_type(); //
test_otxn_param();
test_slot(); //
test_slot_clear(); //