Support Cron in util_keylet Hook API (#612)

This commit is contained in:
tequ
2025-10-27 13:35:01 +09:00
committed by GitHub
parent 2a10013dfc
commit 79fdafe638
5 changed files with 729 additions and 632 deletions

View File

@@ -37,6 +37,7 @@
#define KEYLET_NFT_OFFER 23
#define KEYLET_HOOK_DEFINITION 24
#define KEYLET_HOOK_STATE_DIR 25
#define KEYLET_CRON 26
#define COMPARE_EQUAL 1U
#define COMPARE_LESS 2U

View File

@@ -278,8 +278,7 @@ enum keylet_code : uint32_t {
NFT_OFFER = 23,
HOOK_DEFINITION = 24,
HOOK_STATE_DIR = 25,
LAST_KLTYPE_V0 = HOOK_DEFINITION,
LAST_KLTYPE_V1 = HOOK_STATE_DIR,
CRON = 26
};
}

View File

@@ -2903,17 +2903,6 @@ DEFINE_HOOK_FUNCTION(
if (write_len < 34)
return TOO_SMALL;
bool const v1 = applyCtx.view().rules().enabled(featureHooksUpdate1);
if (keylet_type == 0)
return INVALID_ARGUMENT;
auto const last =
v1 ? keylet_code::LAST_KLTYPE_V1 : keylet_code::LAST_KLTYPE_V0;
if (keylet_type > last)
return INVALID_ARGUMENT;
try
{
switch (keylet_type)
@@ -3015,7 +3004,8 @@ DEFINE_HOOK_FUNCTION(
return serialize_keylet(kl, memory, write_ptr, write_len);
}
// keylets that take 20 byte account id, and 4 byte uint
// keylets that take 20 byte account id, and (4 byte uint for 32
// byte hash)
case keylet_code::OFFER:
case keylet_code::CHECK:
case keylet_code::ESCROW:
@@ -3058,6 +3048,33 @@ DEFINE_HOOK_FUNCTION(
return serialize_keylet(kl, memory, write_ptr, write_len);
}
// keylets that take 20 byte account id, and 4 byte uint
case keylet_code::CRON: {
if (!applyCtx.view().rules().enabled(featureCron))
return INVALID_ARGUMENT;
if (a == 0 || b == 0)
return INVALID_ARGUMENT;
if (e != 0 || f != 0 || d != 0)
return INVALID_ARGUMENT;
uint32_t read_ptr = a, read_len = b;
if (NOT_IN_BOUNDS(read_ptr, read_len, memory_length))
return OUT_OF_BOUNDS;
if (read_len != 20)
return INVALID_ARGUMENT;
ripple::AccountID id = AccountID::fromVoid(memory + read_ptr);
uint32_t seq = c;
ripple::Keylet kl = ripple::keylet::cron(seq, id);
return serialize_keylet(kl, memory, write_ptr, write_len);
}
// keylets that take a 32 byte uint and an 8byte uint64
case keylet_code::PAGE: {
if (a == 0 || b == 0)
@@ -3105,6 +3122,9 @@ DEFINE_HOOK_FUNCTION(
}
case keylet_code::HOOK_STATE_DIR: {
if (!applyCtx.view().rules().enabled(featureHooksUpdate1))
return INVALID_ARGUMENT;
if (a == 0 || b == 0 || c == 0 || d == 0)
return INVALID_ARGUMENT;
@@ -3279,7 +3299,7 @@ DEFINE_HOOK_FUNCTION(
return INTERNAL_ERROR;
}
return NO_SUCH_KEYLET;
return INVALID_ARGUMENT;
HOOK_TEARDOWN();
}

View File

@@ -11147,6 +11147,7 @@ public:
#define KEYLET_PAYCHAN 21
#define KEYLET_EMITTED_TXN 22
#define KEYLET_NFT_OFFER 23
#define KEYLET_CRON 26
#define ASSERT(x)\
if (!(x))\
rollback((uint32_t)#x, sizeof(#x), __LINE__);
@@ -11209,6 +11210,9 @@ public:
// Test min size
ASSERT(util_keylet((uint32_t)buf, 33, KEYLET_SKIP, 0,0,0,0,0,0) == TOO_SMALL);
// Invalid keylet type
ASSERT(util_keylet((uint32_t)buf, 34, 0, 0,0,0,0,0,0) == INVALID_ARGUMENT);
ASSERT(util_keylet((uint32_t)buf, 34, 0x99999999, 0,0,0,0,0,0) == INVALID_ARGUMENT);
// Test one of each type
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_HOOK,
@@ -11651,6 +11655,17 @@ public:
0,0
)));
ASSERT(34 == (e=util_keylet(buf, 34, KEYLET_CRON, SBUF(a), 1, 0, 0, 0)));
{
uint8_t ans[] =
{
0x00U,0x41U,0xF7U,0xB6U,0x45U,0x43U,0x61U,0x87U,0xCCU,0x61U,
0x00U,0x00U,0x00U,0x01U,0x0AU,0x45U,0x80U,0x75U,0x7CU,0xDAU,
0xD9U,0x16U,0x7EU,0xEEU,0xC1U,0x3CU,0x6CU,0x15U,0xD5U,0x17U,
0xE2U,0x72U,0x9EU,0xC8
};
ASSERT_KL_EQ(ans);
}
accept(0,0,0);
}
)[test.hook]"];

File diff suppressed because it is too large Load Diff