mirror of
https://github.com/XRPLF/rippled.git
synced 2026-02-07 15:32:34 +00:00
Merge remote-tracking branch 'upstream/ripple/se/fees' into ripple/smart-escrow
This commit is contained in:
@@ -117,16 +117,6 @@ struct HostFuncImpl_test : public beast::unit_test::suite
|
||||
if (BEAST_EXPECT(result.has_value()))
|
||||
BEAST_EXPECT(result.value() == env.current()->parentCloseTime().time_since_epoch().count());
|
||||
}
|
||||
|
||||
env.close(env.now() + std::chrono::seconds(std::numeric_limits<int32_t>::max() - 1));
|
||||
{
|
||||
OpenView ov{*env.current()};
|
||||
ApplyContext ac = createApplyContext(env, ov);
|
||||
WasmHostFunctionsImpl hfs(ac, dummyEscrow);
|
||||
auto const result = hfs.getParentLedgerTime();
|
||||
if (BEAST_EXPECTS(!result.has_value(), std::to_string(result.value())))
|
||||
BEAST_EXPECT(result.error() == HostFunctionError::INTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -163,28 +153,6 @@ struct HostFuncImpl_test : public beast::unit_test::suite
|
||||
auto const result = hfs.getBaseFee();
|
||||
if (BEAST_EXPECT(result.has_value()))
|
||||
BEAST_EXPECT(result.value() == env.current()->fees().base.drops());
|
||||
|
||||
{
|
||||
Env env2(
|
||||
*this,
|
||||
envconfig([](std::unique_ptr<Config> cfg) {
|
||||
cfg->FEES.reference_fee = static_cast<int64_t>(std::numeric_limits<int32_t>::max()) + 1;
|
||||
return cfg;
|
||||
}),
|
||||
testable_amendments());
|
||||
// Run past the flag ledger so that a Fee change vote occurs and
|
||||
// updates FeeSettings. (It also activates all supported
|
||||
// amendments.)
|
||||
for (auto i = env.current()->seq(); i <= 257; ++i)
|
||||
env.close();
|
||||
|
||||
OpenView ov2{*env2.current()};
|
||||
ApplyContext ac2 = createApplyContext(env2, ov2);
|
||||
WasmHostFunctionsImpl hfs2(ac2, dummyEscrow);
|
||||
auto const result2 = hfs2.getBaseFee();
|
||||
if (BEAST_EXPECT(!result2.has_value()))
|
||||
BEAST_EXPECT(result2.error() == HostFunctionError::INTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
return rt_;
|
||||
}
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getLedgerSqn() override
|
||||
{
|
||||
return env_.current()->seq();
|
||||
@@ -70,13 +70,13 @@ public:
|
||||
return rt_;
|
||||
}
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getLedgerSqn() override
|
||||
{
|
||||
return 12345;
|
||||
}
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getParentLedgerTime() override
|
||||
{
|
||||
return 67890;
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
return env_.current()->header().parentHash;
|
||||
}
|
||||
|
||||
Expected<int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getBaseFee() override
|
||||
{
|
||||
return 10;
|
||||
@@ -298,6 +298,15 @@ public:
|
||||
return Bytes{keylet.key.begin(), keylet.key.end()};
|
||||
}
|
||||
|
||||
Expected<Bytes, HostFunctionError>
|
||||
checkKeylet(AccountID const& account, std::uint32_t seq) override
|
||||
{
|
||||
if (!account)
|
||||
return Unexpected(HostFunctionError::INVALID_ACCOUNT);
|
||||
auto const keylet = keylet::check(account, seq);
|
||||
return Bytes{keylet.key.begin(), keylet.key.end()};
|
||||
}
|
||||
|
||||
Expected<Bytes, HostFunctionError>
|
||||
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) override
|
||||
{
|
||||
@@ -538,22 +547,16 @@ struct PerfHostFunctions : public TestHostFunctions
|
||||
{
|
||||
}
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getLedgerSqn() override
|
||||
{
|
||||
auto seq = env_.current()->seq();
|
||||
if (seq > std::numeric_limits<int32_t>::max())
|
||||
return Unexpected(HostFunctionError::INTERNAL); // LCOV_EXCL_LINE
|
||||
return static_cast<int32_t>(seq);
|
||||
return env_.current()->seq();
|
||||
}
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getParentLedgerTime() override
|
||||
{
|
||||
auto time = env_.current()->parentCloseTime().time_since_epoch().count();
|
||||
if (time > std::numeric_limits<int32_t>::max())
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
return static_cast<int32_t>(time);
|
||||
return env_.current()->parentCloseTime().time_since_epoch().count();
|
||||
}
|
||||
|
||||
Expected<Hash, HostFunctionError>
|
||||
@@ -562,13 +565,10 @@ struct PerfHostFunctions : public TestHostFunctions
|
||||
return env_.current()->header().parentHash;
|
||||
}
|
||||
|
||||
Expected<int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getBaseFee() override
|
||||
{
|
||||
auto fee = env_.current()->fees().base.drops();
|
||||
if (fee > std::numeric_limits<int32_t>::max())
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
return static_cast<int32_t>(fee);
|
||||
return env_.current()->fees().base.drops();
|
||||
}
|
||||
|
||||
Expected<int32_t, HostFunctionError>
|
||||
|
||||
@@ -182,7 +182,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
|
||||
auto re = engine.run(ledgerSqnWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal);
|
||||
|
||||
checkResult(re, 0, 151);
|
||||
checkResult(re, 0, 440);
|
||||
|
||||
env.close();
|
||||
env.close();
|
||||
@@ -190,7 +190,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
// empty module - run the same instance
|
||||
re = engine.run({}, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal);
|
||||
|
||||
checkResult(re, 5, 190);
|
||||
checkResult(re, 5, 488);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -257,7 +257,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
|
||||
auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 1'000'000, env.journal);
|
||||
|
||||
checkResult(re, 1, 25'503);
|
||||
checkResult(re, 1, 27'080);
|
||||
|
||||
env.close();
|
||||
}
|
||||
@@ -278,7 +278,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
|
||||
auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 1'000'000, env.journal);
|
||||
|
||||
checkResult(re, 1, 64'263);
|
||||
checkResult(re, 1, 65'840);
|
||||
|
||||
env.close();
|
||||
}
|
||||
@@ -315,14 +315,14 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
{
|
||||
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
|
||||
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
|
||||
checkResult(re, 1, 64'263);
|
||||
checkResult(re, 1, 65'840);
|
||||
}
|
||||
|
||||
{
|
||||
// max<int64_t>() gas
|
||||
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
|
||||
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, -1);
|
||||
checkResult(re, 1, 64'263);
|
||||
checkResult(re, 1, 65'840);
|
||||
}
|
||||
|
||||
{ // fail because trying to access nonexistent field
|
||||
@@ -340,7 +340,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
|
||||
std::shared_ptr<HostFunctions> hfs(new BadTestHostFunctions(env));
|
||||
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
|
||||
checkResult(re, -201, 28'148);
|
||||
checkResult(re, -201, 28'965);
|
||||
}
|
||||
|
||||
{ // fail because trying to allocate more than MAX_PAGES memory
|
||||
@@ -358,7 +358,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
|
||||
std::shared_ptr<HostFunctions> hfs(new BadTestHostFunctions(env));
|
||||
auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000);
|
||||
checkResult(re, -201, 28'148);
|
||||
checkResult(re, -201, 28'965);
|
||||
}
|
||||
|
||||
{ // fail because recursion too deep
|
||||
@@ -574,7 +574,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
auto const codecovWasm = hexToBytes(codecovTestsWasmHex);
|
||||
std::shared_ptr<HostFunctions> hfs(new TestHostFunctions(env, 0));
|
||||
|
||||
auto const allowance = 324'931;
|
||||
auto const allowance = 339'303;
|
||||
auto re = runEscrowWasm(codecovWasm, hfs, ESCROW_FUNCTION_NAME, {}, allowance);
|
||||
|
||||
checkResult(re, 1, allowance);
|
||||
@@ -794,7 +794,7 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
testcase("Wasm Bad Align");
|
||||
|
||||
// bad_align.c
|
||||
auto const badAlignWasm = hexToBytes(badAlignHex);
|
||||
auto const badAlignWasm = hexToBytes(badAlignWasmHex);
|
||||
|
||||
using namespace test::jtx;
|
||||
|
||||
@@ -807,7 +807,10 @@ struct Wasm_test : public beast::unit_test::suite
|
||||
auto& engine = WasmEngine::instance();
|
||||
|
||||
auto re = engine.run(badAlignWasm, "test", {}, imports, hfs, 1'000'000, env.journal);
|
||||
BEAST_EXPECT(re && re->result == 0xbab88d46);
|
||||
if (BEAST_EXPECTS(re, transToken(re.error())))
|
||||
{
|
||||
BEAST_EXPECTS(re->result == 0x684f7941, std::to_string(re->result));
|
||||
}
|
||||
}
|
||||
|
||||
env.close();
|
||||
|
||||
@@ -154,7 +154,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
[[package]]
|
||||
name = "xrpl-address-macro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"bs58",
|
||||
"quote",
|
||||
@@ -165,7 +165,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "xrpl-wasm-stdlib"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"xrpl-address-macro",
|
||||
]
|
||||
|
||||
@@ -10,7 +10,7 @@ edition = "2024"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib" }
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib", branch = "u32-buffer" }
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
@@ -97,22 +97,27 @@ fn test_ledger_header_functions() -> i32 {
|
||||
let _ = trace("--- Category 1: Ledger Header Functions ---");
|
||||
|
||||
// Test 1.1: get_ledger_sqn() - should return current ledger sequence number
|
||||
let sqn_result = unsafe { host::get_ledger_sqn() };
|
||||
let mut sqn_buffer = [0u8; 4];
|
||||
let sqn_result = unsafe { host::get_ledger_sqn(sqn_buffer.as_mut_ptr(), sqn_buffer.len()) };
|
||||
|
||||
if sqn_result <= 0 {
|
||||
let _ = trace_num("ERROR: get_ledger_sqn failed:", sqn_result as i64);
|
||||
return -101; // Ledger sequence number test failed
|
||||
}
|
||||
let _ = trace_num("Ledger sequence number:", sqn_result as i64);
|
||||
let ledger_sqn = u32::from_be_bytes(sqn_buffer);
|
||||
let _ = trace_num("Ledger sequence number:", ledger_sqn as i64);
|
||||
|
||||
// Test 1.2: get_parent_ledger_time() - should return parent ledger timestamp
|
||||
let time_result = unsafe { host::get_parent_ledger_time() };
|
||||
let mut time_buffer = [0u8; 4];
|
||||
let time_result =
|
||||
unsafe { host::get_parent_ledger_time(time_buffer.as_mut_ptr(), time_buffer.len()) };
|
||||
|
||||
if time_result <= 0 {
|
||||
let _ = trace_num("ERROR: get_parent_ledger_time failed:", time_result as i64);
|
||||
return -102; // Parent ledger time test failed
|
||||
}
|
||||
let _ = trace_num("Parent ledger time:", time_result as i64);
|
||||
let parent_ledger_time = u32::from_be_bytes(time_buffer);
|
||||
let _ = trace_num("Parent ledger time:", parent_ledger_time as i64);
|
||||
|
||||
// Test 1.3: get_parent_ledger_hash() - should return parent ledger hash (32 bytes)
|
||||
let mut hash_buffer = [0u8; 32];
|
||||
@@ -616,11 +621,14 @@ fn test_keylet_generation_functions() -> i32 {
|
||||
|
||||
// Test 5.3: escrow_keylet() - Generate keylet for escrow
|
||||
let mut escrow_keylet_buffer = [0u8; 32];
|
||||
let sequence_number: i32 = 1000;
|
||||
let sequence_number_bytes = sequence_number.to_be_bytes();
|
||||
let escrow_keylet_result = unsafe {
|
||||
host::escrow_keylet(
|
||||
account_id.0.as_ptr(),
|
||||
account_id.0.len(),
|
||||
1000, // Sequence number
|
||||
sequence_number_bytes.as_ptr(),
|
||||
sequence_number_bytes.len(),
|
||||
escrow_keylet_buffer.as_mut_ptr(),
|
||||
escrow_keylet_buffer.len(),
|
||||
)
|
||||
@@ -634,11 +642,14 @@ fn test_keylet_generation_functions() -> i32 {
|
||||
|
||||
// Test 5.4: oracle_keylet() - Generate keylet for oracle
|
||||
let mut oracle_keylet_buffer = [0u8; 32];
|
||||
let document_id: i32 = 42;
|
||||
let document_id_bytes = document_id.to_be_bytes();
|
||||
let oracle_keylet_result = unsafe {
|
||||
host::oracle_keylet(
|
||||
account_id.0.as_ptr(),
|
||||
account_id.0.len(),
|
||||
42, // Document ID
|
||||
document_id_bytes.as_ptr(),
|
||||
document_id_bytes.len(),
|
||||
oracle_keylet_buffer.as_mut_ptr(),
|
||||
oracle_keylet_buffer.len(),
|
||||
)
|
||||
|
||||
@@ -154,7 +154,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
[[package]]
|
||||
name = "xrpl-address-macro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"bs58",
|
||||
"quote",
|
||||
@@ -165,7 +165,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "xrpl-wasm-stdlib"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"xrpl-address-macro",
|
||||
]
|
||||
|
||||
@@ -15,7 +15,7 @@ opt-level = 's'
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib" }
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib", branch = "u32-buffer" }
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
@@ -3,21 +3,45 @@
|
||||
int32_t
|
||||
float_from_uint(uint8_t const*, int32_t, uint8_t*, int32_t, int32_t);
|
||||
int32_t
|
||||
get_tx_nested_field(uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
check_keylet(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
|
||||
uint8_t e_data[32 * 1024];
|
||||
uint8_t e_data1[32 * 1024];
|
||||
uint8_t e_data2[32 * 1024];
|
||||
|
||||
int32_t
|
||||
test1()
|
||||
{
|
||||
e_data1[1] = 0xFF;
|
||||
e_data1[2] = 0xFF;
|
||||
e_data1[3] = 0xFF;
|
||||
e_data1[4] = 0xFF;
|
||||
e_data1[5] = 0xFF;
|
||||
e_data1[6] = 0xFF;
|
||||
e_data1[7] = 0xFF;
|
||||
e_data1[8] = 0xFF;
|
||||
int32_t result = float_from_uint(&e_data1[1], 8, &e_data1[35], 12, 0);
|
||||
return result >= 0 ? *((int32_t*)(&e_data1[36])) : result;
|
||||
}
|
||||
|
||||
int32_t
|
||||
test2()
|
||||
{
|
||||
// Set up misaligned uint32 (seq) at offset 1
|
||||
e_data2[1] = 0xFF;
|
||||
e_data2[2] = 0xFF;
|
||||
e_data2[3] = 0xFF;
|
||||
e_data2[4] = 0xFF;
|
||||
// Set up valid non-zero AccountID (20 bytes) at offset 10
|
||||
for (int i = 0; i < 20; i++)
|
||||
e_data2[10 + i] = i + 1;
|
||||
// Call check_keylet with misaligned uint32 at &e_data2[1] to hit line 72 in HostFuncWrapper.cpp
|
||||
int32_t result = check_keylet(&e_data2[10], 20, &e_data2[1], 4, &e_data2[35], 32);
|
||||
// Return the misaligned value directly to validate it was read correctly (-1 if all 0xFF)
|
||||
return result >= 0 ? *((int32_t*)(&e_data2[36])) : result;
|
||||
}
|
||||
|
||||
int32_t
|
||||
test()
|
||||
{
|
||||
e_data[1] = 0xFF;
|
||||
e_data[2] = 0xFF;
|
||||
e_data[3] = 0xFF;
|
||||
e_data[4] = 0xFF;
|
||||
e_data[5] = 0xFF;
|
||||
e_data[6] = 0xFF;
|
||||
e_data[7] = 0xFF;
|
||||
e_data[8] = 0xFF;
|
||||
float_from_uint(&e_data[1], 8, &e_data[35], 12, 0);
|
||||
return *((int32_t*)(&e_data[36]));
|
||||
return test1() + test2();
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
[[package]]
|
||||
name = "xrpl-address-macro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"bs58",
|
||||
"quote",
|
||||
@@ -165,7 +165,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "xrpl-wasm-stdlib"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"xrpl-address-macro",
|
||||
]
|
||||
|
||||
@@ -15,4 +15,4 @@ opt-level = 's'
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib" }
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib", branch = "u32-buffer" }
|
||||
|
||||
@@ -55,12 +55,20 @@ pub extern "C" fn finish() -> i32 {
|
||||
// that's in a separate test file (all_keylets).
|
||||
// The float tests are also in a separate file (float_tests).
|
||||
// ########################################
|
||||
check_result(unsafe { host::get_ledger_sqn() }, 12345, "get_ledger_sqn");
|
||||
check_result(
|
||||
unsafe { host::get_parent_ledger_time() },
|
||||
67890,
|
||||
"get_parent_ledger_time",
|
||||
);
|
||||
with_buffer::<4, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::get_ledger_sqn(ptr, len) },
|
||||
4,
|
||||
"get_ledger_sqn",
|
||||
);
|
||||
});
|
||||
with_buffer::<4, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::get_parent_ledger_time(ptr, len) },
|
||||
4,
|
||||
"get_parent_ledger_time",
|
||||
);
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::get_parent_ledger_hash(ptr, len) },
|
||||
@@ -68,7 +76,9 @@ pub extern "C" fn finish() -> i32 {
|
||||
"get_parent_ledger_hash",
|
||||
);
|
||||
});
|
||||
check_result(unsafe { host::get_base_fee() }, 10, "get_base_fee");
|
||||
with_buffer::<4, _, _>(|ptr, len| {
|
||||
check_result(unsafe { host::get_base_fee(ptr, len) }, 4, "get_base_fee");
|
||||
});
|
||||
let amendment_name: &[u8] = b"test_amendment";
|
||||
let amendment_id: [u8; 32] = [1; 32];
|
||||
check_result(
|
||||
@@ -312,38 +322,6 @@ pub extern "C" fn finish() -> i32 {
|
||||
// Step #3: Test getData[Type] edge cases
|
||||
// ########################################
|
||||
|
||||
// uint64
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::float_from_uint(
|
||||
locator.as_ptr().wrapping_add(1_000_000_000),
|
||||
8,
|
||||
ptr,
|
||||
len,
|
||||
FLOAT_ROUNDING_MODES_TO_NEAREST,
|
||||
)
|
||||
},
|
||||
error_codes::POINTER_OUT_OF_BOUNDS,
|
||||
"float_from_uint_len_oob",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::float_from_uint(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
ptr,
|
||||
len,
|
||||
FLOAT_ROUNDING_MODES_TO_NEAREST,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"float_from_uint_wrong_len",
|
||||
)
|
||||
});
|
||||
|
||||
// SField
|
||||
check_result(
|
||||
unsafe { host::get_tx_array_len(2) }, // not a valid SField value
|
||||
@@ -381,6 +359,72 @@ pub extern "C" fn finish() -> i32 {
|
||||
"get_tx_nested_array_len_ptr_oob",
|
||||
);
|
||||
|
||||
// uint32
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::check_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
locator.as_ptr().wrapping_add(1_000_000_000),
|
||||
8,
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::POINTER_OUT_OF_BOUNDS,
|
||||
"check_keylet_oob_len_u32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::check_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"check_keylet_wrong_len_u32",
|
||||
)
|
||||
});
|
||||
|
||||
// uint64
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::float_from_uint(
|
||||
locator.as_ptr().wrapping_add(1_000_000_000),
|
||||
8,
|
||||
ptr,
|
||||
len,
|
||||
FLOAT_ROUNDING_MODES_TO_NEAREST,
|
||||
)
|
||||
},
|
||||
error_codes::POINTER_OUT_OF_BOUNDS,
|
||||
"float_from_uint_len_oob",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::float_from_uint(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
ptr,
|
||||
len,
|
||||
FLOAT_ROUNDING_MODES_TO_NEAREST,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"float_from_uint_wrong_len_uint64",
|
||||
)
|
||||
});
|
||||
|
||||
// uint256
|
||||
check_result(
|
||||
unsafe {
|
||||
@@ -1011,6 +1055,155 @@ pub extern "C" fn finish() -> i32 {
|
||||
)
|
||||
});
|
||||
|
||||
// invalid UInt32
|
||||
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::escrow_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"escrow_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::mpt_issuance_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"mpt_issuance_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::nft_offer_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"nft_offer_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::offer_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"offer_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::oracle_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"oracle_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::paychan_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"paychan_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::permissioned_domain_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"permissioned_domain_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::ticket_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"ticket_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
with_buffer::<32, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::vault_keylet(
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"vault_keylet_wrong_size_uint32",
|
||||
)
|
||||
});
|
||||
|
||||
// invalid UInt256
|
||||
|
||||
check_result(
|
||||
@@ -1075,9 +1268,20 @@ pub extern "C" fn finish() -> i32 {
|
||||
"account_keylet_wrong_size_accountid",
|
||||
)
|
||||
});
|
||||
let seq: i32 = 1;
|
||||
let seq_bytes = seq.to_be_bytes();
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::check_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::check_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"check_keylet_wrong_size_accountid",
|
||||
)
|
||||
@@ -1191,7 +1395,16 @@ pub extern "C" fn finish() -> i32 {
|
||||
});
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::escrow_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::escrow_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"escrow_keylet_wrong_size_accountid",
|
||||
)
|
||||
@@ -1234,7 +1447,16 @@ pub extern "C" fn finish() -> i32 {
|
||||
});
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::mpt_issuance_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::mpt_issuance_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"mpt_issuance_keylet_wrong_size_accountid",
|
||||
)
|
||||
@@ -1257,21 +1479,48 @@ pub extern "C" fn finish() -> i32 {
|
||||
});
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::nft_offer_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::nft_offer_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"nft_offer_keylet_wrong_size_accountid",
|
||||
)
|
||||
});
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::offer_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::offer_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"offer_keylet_wrong_size_accountid",
|
||||
)
|
||||
});
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::oracle_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::oracle_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"oracle_keylet_wrong_size_accountid",
|
||||
)
|
||||
@@ -1284,7 +1533,8 @@ pub extern "C" fn finish() -> i32 {
|
||||
locator.len(),
|
||||
account.0.as_ptr(),
|
||||
account.0.len(),
|
||||
1,
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
@@ -1301,7 +1551,8 @@ pub extern "C" fn finish() -> i32 {
|
||||
account.0.len(),
|
||||
locator.as_ptr(), // invalid AccountID size
|
||||
locator.len(),
|
||||
1,
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
@@ -1313,7 +1564,14 @@ pub extern "C" fn finish() -> i32 {
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe {
|
||||
host::permissioned_domain_keylet(locator.as_ptr(), locator.len(), 1, ptr, len)
|
||||
host::permissioned_domain_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"permissioned_domain_keylet_wrong_size_accountid",
|
||||
@@ -1328,14 +1586,32 @@ pub extern "C" fn finish() -> i32 {
|
||||
});
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::ticket_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::ticket_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"ticket_keylet_wrong_size_accountid",
|
||||
)
|
||||
});
|
||||
with_buffer::<2, _, _>(|ptr, len| {
|
||||
check_result(
|
||||
unsafe { host::vault_keylet(locator.as_ptr(), locator.len(), 1, ptr, len) },
|
||||
unsafe {
|
||||
host::vault_keylet(
|
||||
locator.as_ptr(),
|
||||
locator.len(),
|
||||
seq_bytes.as_ptr(),
|
||||
seq_bytes.len(),
|
||||
ptr,
|
||||
len,
|
||||
)
|
||||
},
|
||||
error_codes::INVALID_PARAMS,
|
||||
"vault_keylet_wrong_size_accountid",
|
||||
)
|
||||
|
||||
@@ -54,12 +54,7 @@ def process_rust(project_name):
|
||||
")"
|
||||
)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
build_cmd, shell=True, check=True, capture_output=True, text=True
|
||||
)
|
||||
print(f"stdout: {result.stdout}")
|
||||
if result.stderr:
|
||||
print(f"stderr: {result.stderr}")
|
||||
subprocess.run(build_cmd, shell=True, check=True)
|
||||
print(f"WASM file for {project_name} has been built and optimized.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"exec error: {e}")
|
||||
@@ -91,12 +86,7 @@ def process_c(project_name):
|
||||
f"&& wasm-opt {wasm_path} {OPT} -o {wasm_path}"
|
||||
)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
build_cmd, shell=True, check=True, capture_output=True, text=True
|
||||
)
|
||||
print(f"stdout: {result.stdout}")
|
||||
if result.stderr:
|
||||
print(f"stderr: {result.stderr}")
|
||||
subprocess.run(build_cmd, shell=True, check=True)
|
||||
print(
|
||||
f"WASM file for {project_name} has been built with WASI support using clang."
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -138,6 +138,6 @@ extern std::string const infiniteLoopWasmHex;
|
||||
extern std::string const startLoopHex;
|
||||
|
||||
extern std::string const badAllocHex;
|
||||
extern std::string const badAlignHex;
|
||||
extern std::string const badAlignWasmHex;
|
||||
|
||||
extern std::string const updateDataWasmHex;
|
||||
|
||||
@@ -154,7 +154,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
[[package]]
|
||||
name = "xrpl-address-macro"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"bs58",
|
||||
"quote",
|
||||
@@ -165,7 +165,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "xrpl-wasm-stdlib"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git#d27d3e0b4abf3c0215aade729d89053805efe48e"
|
||||
source = "git+https://github.com/ripple/xrpl-wasm-stdlib.git?branch=u32-buffer#1e5d096f46742ef7fcf1cb6f28a2526a72ed59d8"
|
||||
dependencies = [
|
||||
"xrpl-address-macro",
|
||||
]
|
||||
|
||||
@@ -15,7 +15,7 @@ opt-level = 's'
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib" }
|
||||
xrpl-std = { git = "https://github.com/ripple/xrpl-wasm-stdlib.git", package = "xrpl-wasm-stdlib", branch = "u32-buffer" }
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
@@ -1,27 +1,16 @@
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t
|
||||
get_ledger_sqn();
|
||||
// int32_t trace(uint8_t const*, int32_t, uint8_t const*, int32_t, int32_t);
|
||||
// int32_t trace_num(uint8_t const*, int32_t, int64_t);
|
||||
|
||||
// uint8_t buf[1024];
|
||||
|
||||
// char const test_res[] = "sqn: ";
|
||||
// char const test_name[] = "TEST get_ledger_sqn";
|
||||
get_ledger_sqn(uint8_t*, int32_t);
|
||||
|
||||
int
|
||||
finish()
|
||||
{
|
||||
// trace((uint8_t const *)test_name, sizeof(test_name) - 1, 0, 0, 0);
|
||||
uint32_t sqn;
|
||||
int32_t result = get_ledger_sqn((uint8_t*)&sqn, sizeof(sqn));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// for(int i = 0; i < sizeof(buf); ++i) buf[i] = 0;
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
int x = get_ledger_sqn();
|
||||
// if (x >= 0)
|
||||
// x = *((int32_t*)buf);
|
||||
// trace_num((uint8_t const *)test`_res, sizeof(test_res) - 1, x);
|
||||
|
||||
return x < 0 ? x : (x >= 5 ? x : 0);
|
||||
return sqn >= 5 ? 5 : 0;
|
||||
}
|
||||
|
||||
@@ -122,13 +122,13 @@ struct HostFunctions
|
||||
return j_;
|
||||
}
|
||||
|
||||
virtual Expected<std::int32_t, HostFunctionError>
|
||||
virtual Expected<std::uint32_t, HostFunctionError>
|
||||
getLedgerSqn()
|
||||
{
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
}
|
||||
|
||||
virtual Expected<std::int32_t, HostFunctionError>
|
||||
virtual Expected<std::uint32_t, HostFunctionError>
|
||||
getParentLedgerTime()
|
||||
{
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
@@ -140,7 +140,7 @@ struct HostFunctions
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
}
|
||||
|
||||
virtual Expected<int32_t, HostFunctionError>
|
||||
virtual Expected<uint32_t, HostFunctionError>
|
||||
getBaseFee()
|
||||
{
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
|
||||
@@ -82,16 +82,16 @@ public:
|
||||
return data_;
|
||||
}
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getLedgerSqn() override;
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getParentLedgerTime() override;
|
||||
|
||||
Expected<Hash, HostFunctionError>
|
||||
getParentLedgerHash() override;
|
||||
|
||||
Expected<int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
getBaseFee() override;
|
||||
|
||||
Expected<int32_t, HostFunctionError>
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
using getLedgerSqn_proto = int32_t();
|
||||
using getLedgerSqn_proto = int32_t(uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
getLedgerSqn_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using getParentLedgerTime_proto = int32_t();
|
||||
using getParentLedgerTime_proto = int32_t(uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
getParentLedgerTime_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
@@ -16,7 +16,7 @@ using getParentLedgerHash_proto = int32_t(uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
getParentLedgerHash_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using getBaseFee_proto = int32_t();
|
||||
using getBaseFee_proto = int32_t(uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
getBaseFee_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
@@ -96,7 +96,7 @@ using ammKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t
|
||||
wasm_trap_t*
|
||||
ammKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using checkKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using checkKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
checkKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
@@ -117,7 +117,7 @@ using didKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
didKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using escrowKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using escrowKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
escrowKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
@@ -126,7 +126,7 @@ using lineKeylet_proto =
|
||||
wasm_trap_t*
|
||||
lineKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using mptIssuanceKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using mptIssuanceKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
mptIssuanceKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
@@ -134,23 +134,24 @@ using mptokenKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int
|
||||
wasm_trap_t*
|
||||
mptokenKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using nftOfferKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using nftOfferKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
nftOfferKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using offerKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using offerKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
offerKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using oracleKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using oracleKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
oracleKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using paychanKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using paychanKeylet_proto =
|
||||
int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
paychanKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using permissionedDomainKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using permissionedDomainKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
permissionedDomainKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
@@ -158,11 +159,11 @@ using signersKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
signersKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using ticketKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using ticketKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
ticketKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
using vaultKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t);
|
||||
using vaultKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t);
|
||||
wasm_trap_t*
|
||||
vaultKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results);
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
makeNumber(int64_t mantissa, int32_t exponent)
|
||||
{
|
||||
if (mantissa < 0)
|
||||
return Number(true, -mantissa, exponent, Number::normalized());
|
||||
return Number(true, -static_cast<uint64_t>(mantissa), exponent, Number::normalized());
|
||||
return Number(false, mantissa, exponent, Number::normalized());
|
||||
}
|
||||
|
||||
|
||||
@@ -9,22 +9,16 @@ namespace xrpl {
|
||||
// SECTION: LEDGER HEADER FUNCTIONS
|
||||
// =========================================================
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
WasmHostFunctionsImpl::getLedgerSqn()
|
||||
{
|
||||
auto seq = ctx.view().seq();
|
||||
if (seq > std::numeric_limits<int32_t>::max())
|
||||
return Unexpected(HostFunctionError::INTERNAL); // LCOV_EXCL_LINE
|
||||
return static_cast<int32_t>(seq);
|
||||
return ctx.view().seq();
|
||||
}
|
||||
|
||||
Expected<std::int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
WasmHostFunctionsImpl::getParentLedgerTime()
|
||||
{
|
||||
auto time = ctx.view().parentCloseTime().time_since_epoch().count();
|
||||
if (time > std::numeric_limits<int32_t>::max())
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
return static_cast<int32_t>(time);
|
||||
return ctx.view().parentCloseTime().time_since_epoch().count();
|
||||
}
|
||||
|
||||
Expected<Hash, HostFunctionError>
|
||||
@@ -33,13 +27,10 @@ WasmHostFunctionsImpl::getParentLedgerHash()
|
||||
return ctx.view().header().parentHash;
|
||||
}
|
||||
|
||||
Expected<int32_t, HostFunctionError>
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
WasmHostFunctionsImpl::getBaseFee()
|
||||
{
|
||||
auto fee = ctx.view().fees().base.drops();
|
||||
if (fee > std::numeric_limits<int32_t>::max())
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
return static_cast<int32_t>(fee);
|
||||
return ctx.view().fees().base.drops();
|
||||
}
|
||||
|
||||
Expected<int32_t, HostFunctionError>
|
||||
|
||||
@@ -56,25 +56,40 @@ getDataInt64(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i)
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T, class IW>
|
||||
Expected<T, HostFunctionError>
|
||||
getDataUnsigned(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
|
||||
{
|
||||
static_assert(std::is_unsigned_v<T>);
|
||||
auto const r = getDataSlice(runtime, params, i);
|
||||
if (!r)
|
||||
return Unexpected(r.error());
|
||||
if (r->size() != sizeof(T))
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
T x;
|
||||
uintptr_t p = reinterpret_cast<uintptr_t>(r->data());
|
||||
if (p & (alignof(T) - 1)) // unaligned
|
||||
memcpy(&x, r->data(), sizeof(T));
|
||||
else
|
||||
x = *reinterpret_cast<T const*>(r->data());
|
||||
x = adjustWasmEndianess(x);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class IW>
|
||||
Expected<uint32_t, HostFunctionError>
|
||||
getDataUInt32(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
|
||||
{
|
||||
return getDataUnsigned<uint32_t>(runtime, params, i);
|
||||
}
|
||||
|
||||
template <class IW>
|
||||
Expected<uint64_t, HostFunctionError>
|
||||
getDataUInt64(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
|
||||
{
|
||||
auto const r = getDataSlice(runtime, params, i);
|
||||
if (!r)
|
||||
return Unexpected(r.error());
|
||||
if (r->size() != sizeof(uint64_t))
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
uint64_t x;
|
||||
uintptr_t p = reinterpret_cast<uintptr_t>(r->data());
|
||||
if (p & (alignof(uint64_t) - 1)) // unaligned
|
||||
memcpy(&x, r->data(), sizeof(uint64_t));
|
||||
else
|
||||
x = *reinterpret_cast<uint64_t const*>(r->data());
|
||||
x = adjustWasmEndianess(x);
|
||||
|
||||
return x;
|
||||
return getDataUnsigned<uint64_t>(runtime, params, i);
|
||||
}
|
||||
|
||||
template <class IW>
|
||||
@@ -791,10 +806,10 @@ checkKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->checkKeylet(acc.value(), *seq), index);
|
||||
@@ -911,10 +926,10 @@ escrowKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->escrowKeylet(*acc, *seq), index);
|
||||
@@ -965,10 +980,10 @@ mptIssuanceKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->mptIssuanceKeylet(acc.value(), seq.value()), index);
|
||||
@@ -1019,10 +1034,10 @@ nftOfferKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* res
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->nftOfferKeylet(acc.value(), seq.value()), index);
|
||||
@@ -1043,10 +1058,10 @@ offerKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->offerKeylet(acc.value(), seq.value()), index);
|
||||
@@ -1067,10 +1082,10 @@ oracleKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const documentId = getDataInt32(runtime, params, index);
|
||||
auto const documentId = getDataUInt32(runtime, params, index);
|
||||
if (!documentId)
|
||||
{
|
||||
return hfResult(results, documentId.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, documentId.error());
|
||||
}
|
||||
return returnResult(runtime, params, results, hf->oracleKeylet(*acc, *documentId), index);
|
||||
}
|
||||
@@ -1096,10 +1111,10 @@ paychanKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
|
||||
return hfResult(results, dest.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->paychanKeylet(acc.value(), dest.value(), seq.value()), index);
|
||||
@@ -1120,10 +1135,10 @@ permissionedDomainKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->permissionedDomainKeylet(acc.value(), seq.value()), index);
|
||||
@@ -1162,10 +1177,10 @@ ticketKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->ticketKeylet(acc.value(), seq.value()), index);
|
||||
@@ -1186,10 +1201,10 @@ vaultKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
|
||||
return hfResult(results, acc.error());
|
||||
}
|
||||
|
||||
auto const seq = getDataInt32(runtime, params, index);
|
||||
auto const seq = getDataUInt32(runtime, params, index);
|
||||
if (!seq)
|
||||
{
|
||||
return hfResult(results, seq.error()); // LCOV_EXCL_LINE
|
||||
return hfResult(results, seq.error());
|
||||
}
|
||||
|
||||
return returnResult(runtime, params, results, hf->vaultKeylet(acc.value(), seq.value()), index);
|
||||
|
||||
Reference in New Issue
Block a user