From c634c75aeecb67ee023267e44dd92552f0c7280c Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Mon, 20 Jul 2026 18:07:42 -0400 Subject: [PATCH] fix build issues --- include/xrpl/basics/Number.h | 2 +- include/xrpl/tx/wasm/HostFunc.h | 307 +++++++++--------- include/xrpl/tx/wasm/HostFuncImpl.h | 154 ++++----- include/xrpl/tx/wasm/HostFuncWrapper.h | 24 +- include/xrpl/tx/wasm/README.md | 10 +- include/xrpl/tx/wasm/WasmVM.h | 4 +- include/xrpl/tx/wasm/WasmiVM.h | 4 +- src/libxrpl/tx/wasm/HostFuncImpl.cpp | 11 +- src/libxrpl/tx/wasm/HostFuncImplFloat.cpp | 159 +++++---- src/libxrpl/tx/wasm/HostFuncImplGetter.cpp | 103 +++--- src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp | 115 ++++--- .../tx/wasm/HostFuncImplLedgerHeader.cpp | 13 +- src/libxrpl/tx/wasm/HostFuncImplNFT.cpp | 27 +- src/libxrpl/tx/wasm/HostFuncImplTrace.cpp | 11 +- src/libxrpl/tx/wasm/HostFuncWrapper.cpp | 121 +++---- src/libxrpl/tx/wasm/WasmVM.cpp | 19 +- src/libxrpl/tx/wasm/WasmiVM.cpp | 13 +- src/test/app/HostFuncImpl_test.cpp | 48 +-- src/test/app/TestHostFunctions.h | 130 ++++---- src/test/app/Wasm_test.cpp | 9 +- 20 files changed, 639 insertions(+), 645 deletions(-) diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index f90800c715..c64ad027f4 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -347,7 +347,7 @@ concept Integral64 = std::is_same_v || std::is_same_v #include #include #include @@ -20,46 +19,46 @@ namespace wasm_float { std::string floatToString(Slice const& data); -Expected +std::expected floatFromIntImpl(int64_t x, int32_t mode); -Expected +std::expected floatFromUintImpl(uint64_t x, int32_t mode); -Expected +std::expected floatFromSTAmountImpl(STAmount const& x, int32_t mode); -Expected +std::expected floatFromSTNumberImpl(STNumber const& x, int32_t mode); -Expected +std::expected floatToIntImpl(Slice const& x, int32_t mode); -Expected +std::expected floatToMantExpImpl(Slice const& x); -Expected +std::expected floatFromMantExpImpl(int64_t mantissa, int32_t exponent, int32_t mode); -Expected +std::expected floatCompareImpl(Slice const& x, Slice const& y); -Expected +std::expected floatAddImpl(Slice const& x, Slice const& y, int32_t mode); -Expected +std::expected floatSubtractImpl(Slice const& x, Slice const& y, int32_t mode); -Expected +std::expected floatMultiplyImpl(Slice const& x, Slice const& y, int32_t mode); -Expected +std::expected floatDivideImpl(Slice const& x, Slice const& y, int32_t mode); -Expected +std::expected floatRootImpl(Slice const& x, int32_t n, int32_t mode); -Expected +std::expected floatPowerImpl(Slice const& x, int32_t n, int32_t mode); } // namespace wasm_float @@ -110,401 +109,403 @@ public: return true; } - virtual Expected + virtual std::expected getLedgerSqn() const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getParentLedgerTime() const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getParentLedgerHash() const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getBaseFee() const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected isAmendmentEnabled(uint256 const& amendmentId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected isAmendmentEnabled(std::string_view const& amendmentName) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getTxField(SField const& fname) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getCurrentLedgerObjField(SField const& fname) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getLedgerObjField(int32_t cacheIdx, SField const& fname) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getTxNestedField(FieldLocator const& locator) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getCurrentLedgerObjNestedField(FieldLocator const& locator) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getLedgerObjNestedField(int32_t cacheIdx, FieldLocator const& locator) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getTxArrayLen(SField const& fname) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getCurrentLedgerObjArrayLen(SField const& fname) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getTxNestedArrayLen(FieldLocator const& locator) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getCurrentLedgerObjNestedArrayLen(FieldLocator const& locator) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getLedgerObjNestedArrayLen(int32_t cacheIdx, FieldLocator const& locator) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected updateData(Slice const& data) { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected computeSha512HalfHash(Slice const& data) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected accountKeylet(AccountID const& account) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected ammKeylet(Asset const& issue1, Asset const& issue2) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected checkKeylet(AccountID const& account, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected didKeylet(AccountID const& account) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected delegateKeylet(AccountID const& account, AccountID const& authorize) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected escrowKeylet(AccountID const& account, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected - lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) const + virtual std::expected + trustLineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) + const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected - mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const + virtual std::expected + mptokenIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected mptokenKeylet(MPTID const& mptid, AccountID const& holder) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected - nftOfferKeylet(AccountID const& account, std::uint32_t seq) const + virtual std::expected + nftokenOfferKeylet(AccountID const& account, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected offerKeylet(AccountID const& account, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected oracleKeylet(AccountID const& account, std::uint32_t docId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected - paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) const + virtual std::expected + paychannelKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) + const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected - signersKeylet(AccountID const& account) const + virtual std::expected + signerListKeylet(AccountID const& account) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected ticketKeylet(AccountID const& account, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected vaultKeylet(AccountID const& account, std::uint32_t seq) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getNFT(AccountID const& account, uint256 const& nftId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getNFTIssuer(uint256 const& nftId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getNFTTaxon(uint256 const& nftId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getNFTFlags(uint256 const& nftId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected getNFTTransferFee(uint256 const& nftId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected - getNFTSerial(uint256 const& nftId) const + virtual std::expected + getNFTSequence(uint256 const& nftId) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected trace(std::string_view const& msg, Slice const& data, bool asHex) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected traceNum(std::string_view const& msg, int64_t data) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected traceAccount(std::string_view const& msg, AccountID const& account) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected traceFloat(std::string_view const& msg, Slice const& data) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected traceAmount(std::string_view const& msg, STAmount const& amount) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatFromInt(int64_t x, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatFromUint(uint64_t x, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatFromSTAmount(STAmount const& x, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatFromSTNumber(STNumber const& x, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatToInt(Slice const& x, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatToMantExp(Slice const& x) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatCompare(Slice const& x, Slice const& y) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatAdd(Slice const& x, Slice const& y, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatSubtract(Slice const& x, Slice const& y, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatMultiply(Slice const& x, Slice const& y, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatDivide(Slice const& x, Slice const& y, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatRoot(Slice const& x, int32_t n, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - virtual Expected + virtual std::expected floatPower(Slice const& x, int32_t n, int32_t mode) const { - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } virtual ~HostFunctions() = default; diff --git a/include/xrpl/tx/wasm/HostFuncImpl.h b/include/xrpl/tx/wasm/HostFuncImpl.h index 950856e828..b32023039b 100644 --- a/include/xrpl/tx/wasm/HostFuncImpl.h +++ b/include/xrpl/tx/wasm/HostFuncImpl.h @@ -19,24 +19,24 @@ class WasmHostFunctionsImpl : public HostFunctions std::optional data_; public: - Expected, HostFunctionError> + std::expected, HostFunctionError> getCurrentLedgerObj() const { if (!currentLedgerObj_) currentLedgerObj_ = ctx_.view().read(leKey_); if (*currentLedgerObj_) return *currentLedgerObj_; - return Unexpected(HostFunctionError::LedgerObjNotFound); + return std::unexpected(HostFunctionError::LedgerObjNotFound); } - Expected + std::expected normalizeCacheIndex(int32_t cacheIdx) const { --cacheIdx; if (cacheIdx < 0 || cacheIdx >= maxCache) - return Unexpected(HostFunctionError::SlotOutRange); + return std::unexpected(HostFunctionError::SlotOutRange); if (!cache_[cacheIdx]) - return Unexpected(HostFunctionError::EmptySlot); + return std::unexpected(HostFunctionError::EmptySlot); return cacheIdx; } @@ -77,206 +77,206 @@ public: return data_; } - Expected + std::expected getLedgerSqn() const override; - Expected + std::expected getParentLedgerTime() const override; - Expected + std::expected getParentLedgerHash() const override; - Expected + std::expected getBaseFee() const override; - Expected + std::expected isAmendmentEnabled(uint256 const& amendmentId) const override; - Expected + std::expected isAmendmentEnabled(std::string_view const& amendmentName) const override; - Expected + std::expected cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) override; - Expected + std::expected getTxField(SField const& fname) const override; - Expected + std::expected getCurrentLedgerObjField(SField const& fname) const override; - Expected + std::expected getLedgerObjField(int32_t cacheIdx, SField const& fname) const override; - Expected + std::expected getTxNestedField(FieldLocator const& locator) const override; - Expected + std::expected getCurrentLedgerObjNestedField(FieldLocator const& locator) const override; - Expected + std::expected getLedgerObjNestedField(int32_t cacheIdx, FieldLocator const& locator) const override; - Expected + std::expected getTxArrayLen(SField const& fname) const override; - Expected + std::expected getCurrentLedgerObjArrayLen(SField const& fname) const override; - Expected + std::expected getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const override; - Expected + std::expected getTxNestedArrayLen(FieldLocator const& locator) const override; - Expected + std::expected getCurrentLedgerObjNestedArrayLen(FieldLocator const& locator) const override; - Expected + std::expected getLedgerObjNestedArrayLen(int32_t cacheIdx, FieldLocator const& locator) const override; - Expected + std::expected updateData(Slice const& data) override; - Expected + std::expected checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const override; - Expected + std::expected computeSha512HalfHash(Slice const& data) const override; - Expected + std::expected accountKeylet(AccountID const& account) const override; - Expected + std::expected ammKeylet(Asset const& issue1, Asset const& issue2) const override; - Expected + std::expected checkKeylet(AccountID const& account, std::uint32_t seq) const override; - Expected + std::expected credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const override; - Expected + std::expected didKeylet(AccountID const& account) const override; - Expected + std::expected delegateKeylet(AccountID const& account, AccountID const& authorize) const override; - Expected + std::expected depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const override; - Expected + std::expected escrowKeylet(AccountID const& account, std::uint32_t seq) const override; - Expected - lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) + std::expected + trustLineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) const override; - Expected - mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const override; + std::expected + mptokenIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const override; - Expected + std::expected mptokenKeylet(MPTID const& mptid, AccountID const& holder) const override; - Expected - nftOfferKeylet(AccountID const& account, std::uint32_t seq) const override; + std::expected + nftokenOfferKeylet(AccountID const& account, std::uint32_t seq) const override; - Expected + std::expected offerKeylet(AccountID const& account, std::uint32_t seq) const override; - Expected + std::expected oracleKeylet(AccountID const& account, std::uint32_t docId) const override; - Expected - paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) + std::expected + paychannelKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) const override; - Expected + std::expected permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const override; - Expected - signersKeylet(AccountID const& account) const override; + std::expected + signerListKeylet(AccountID const& account) const override; - Expected + std::expected ticketKeylet(AccountID const& account, std::uint32_t seq) const override; - Expected + std::expected vaultKeylet(AccountID const& account, std::uint32_t seq) const override; - Expected + std::expected getNFT(AccountID const& account, uint256 const& nftId) const override; - Expected + std::expected getNFTIssuer(uint256 const& nftId) const override; - Expected + std::expected getNFTTaxon(uint256 const& nftId) const override; - Expected + std::expected getNFTFlags(uint256 const& nftId) const override; - Expected + std::expected getNFTTransferFee(uint256 const& nftId) const override; - Expected - getNFTSerial(uint256 const& nftId) const override; + std::expected + getNFTSequence(uint256 const& nftId) const override; - Expected + std::expected trace(std::string_view const& msg, Slice const& data, bool asHex) const override; - Expected + std::expected traceNum(std::string_view const& msg, int64_t data) const override; - Expected + std::expected traceAccount(std::string_view const& msg, AccountID const& account) const override; - Expected + std::expected traceFloat(std::string_view const& msg, Slice const& data) const override; - Expected + std::expected traceAmount(std::string_view const& msg, STAmount const& amount) const override; - Expected + std::expected floatFromInt(int64_t x, int32_t mode) const override; - Expected + std::expected floatFromUint(uint64_t x, int32_t mode) const override; - Expected + std::expected floatFromSTAmount(STAmount const& x, int32_t mode) const override; - Expected + std::expected floatFromSTNumber(STNumber const& x, int32_t mode) const override; - Expected + std::expected floatToInt(Slice const& x, int32_t mode) const override; - Expected + std::expected floatToMantExp(Slice const& x) const override; - Expected + std::expected floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const override; - Expected + std::expected floatCompare(Slice const& x, Slice const& y) const override; - Expected + std::expected floatAdd(Slice const& x, Slice const& y, int32_t mode) const override; - Expected + std::expected floatSubtract(Slice const& x, Slice const& y, int32_t mode) const override; - Expected + std::expected floatMultiply(Slice const& x, Slice const& y, int32_t mode) const override; - Expected + std::expected floatDivide(Slice const& x, Slice const& y, int32_t mode) const override; - Expected + std::expected floatRoot(Slice const& x, int32_t n, int32_t mode) const override; - Expected + std::expected floatPower(Slice const& x, int32_t n, int32_t mode) const override; }; diff --git a/include/xrpl/tx/wasm/HostFuncWrapper.h b/include/xrpl/tx/wasm/HostFuncWrapper.h index 825f5344ad..2954c8f423 100644 --- a/include/xrpl/tx/wasm/HostFuncWrapper.h +++ b/include/xrpl/tx/wasm/HostFuncWrapper.h @@ -115,7 +115,7 @@ using escrowKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* escrowKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); -using lineKeylet_proto = int32_t( +using trustLineKeylet_proto = int32_t( uint8_t const*, int32_t, uint8_t const*, @@ -124,19 +124,19 @@ using lineKeylet_proto = int32_t( int32_t, uint8_t*, int32_t); -wasm_trap_t* lineKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); +wasm_trap_t* trustLineKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); -using mptIssuanceKeylet_proto = +using mptokenIssuanceKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); -wasm_trap_t* mptIssuanceKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); +wasm_trap_t* mptokenIssuanceKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); using mptokenKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* mptokenKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); -using nftOfferKeylet_proto = +using nftokenOfferKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); -wasm_trap_t* nftOfferKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); +wasm_trap_t* nftokenOfferKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); using offerKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); @@ -146,7 +146,7 @@ using oracleKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* oracleKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); -using paychanKeylet_proto = int32_t( +using paychannelKeylet_proto = int32_t( uint8_t const*, int32_t, uint8_t const*, @@ -155,14 +155,14 @@ using paychanKeylet_proto = int32_t( int32_t, uint8_t*, int32_t); -wasm_trap_t* paychanKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); +wasm_trap_t* paychannelKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); using permissionedDomainKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* permissionedDomainKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); -using signersKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); -wasm_trap_t* signersKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); +using signerListKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); +wasm_trap_t* signerListKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST); using ticketKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); @@ -187,8 +187,8 @@ wasm_trap_t* getNFTFlags_wrap(WASM_SECONDARY_CB_PARAMS_LIST); using getNFTTransferFee_proto = int32_t(uint8_t const*, int32_t); wasm_trap_t* getNFTTransferFee_wrap(WASM_SECONDARY_CB_PARAMS_LIST); -using getNFTSerial_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); -wasm_trap_t* getNFTSerial_wrap(WASM_SECONDARY_CB_PARAMS_LIST); +using getNFTSequence_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); +wasm_trap_t* getNFTSequence_wrap(WASM_SECONDARY_CB_PARAMS_LIST); using trace_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, int32_t); wasm_trap_t* trace_wrap(WASM_SECONDARY_CB_PARAMS_LIST); diff --git a/include/xrpl/tx/wasm/README.md b/include/xrpl/tx/wasm/README.md index 3275011b49..5b276d3aed 100644 --- a/include/xrpl/tx/wasm/README.md +++ b/include/xrpl/tx/wasm/README.md @@ -45,7 +45,7 @@ The module follows a layered architecture: - **`HostFunc.h`** - Abstract `HostFunctions` base class defining the interface for all callable host functions. Each method returns - `Expected`. + `std::expected`. - **`HostFuncImpl.h` / `detail/HostFuncImpl*.cpp`** - Concrete `WasmHostFunctionsImpl` class that implements host functions with access to @@ -120,10 +120,10 @@ Add a virtual method declaration with a default implementation that returns an error: ```cpp -virtual Expected +virtual std::expected myNewFunction(ParamType1 param1, ParamType2 param2) { - return Unexpected(HostFunctionError::INTERNAL); + return std::unexpected(HostFunctionError::INTERNAL); } ``` @@ -132,7 +132,7 @@ myNewFunction(ParamType1 param1, ParamType2 param2) Add the method override declaration in `WasmHostFunctionsImpl`: ```cpp -Expected +std::expected myNewFunction(ParamType1 param1, ParamType2 param2) override; ``` @@ -141,7 +141,7 @@ myNewFunction(ParamType1 param1, ParamType2 param2) override; Add the implementation in the appropriate file: ```cpp -Expected +std::expected WasmHostFunctionsImpl::myNewFunction(ParamType1 param1, ParamType2 param2) { // Implementation using ctx (ApplyContext) for ledger access diff --git a/include/xrpl/tx/wasm/WasmVM.h b/include/xrpl/tx/wasm/WasmVM.h index 48b0438654..3e200eca17 100644 --- a/include/xrpl/tx/wasm/WasmVM.h +++ b/include/xrpl/tx/wasm/WasmVM.h @@ -40,7 +40,7 @@ public: static WasmEngine& instance(); - Expected, WasmTER> + std::expected, WasmTER> run(Bytes const& wasmCode, HostFunctions& hfs, int64_t gasLimit, @@ -71,7 +71,7 @@ public: ImportVec createWasmImport(HostFunctions& hfs); -Expected +std::expected runEscrowWasm( Bytes const& wasmCode, HostFunctions& hfs, diff --git a/include/xrpl/tx/wasm/WasmiVM.h b/include/xrpl/tx/wasm/WasmiVM.h index 45ef703e91..9c41b05d7c 100644 --- a/include/xrpl/tx/wasm/WasmiVM.h +++ b/include/xrpl/tx/wasm/WasmiVM.h @@ -309,7 +309,7 @@ public: static EnginePtr init(); - Expected, WasmTER> + std::expected, WasmTER> run(Bytes const& wasmCode, HostFunctions& hfs, int64_t gas, @@ -360,7 +360,7 @@ private: return moduleWrap_ ? moduleWrap_->getMem() : Wmem(); } - Expected, WasmTER> + std::expected, WasmTER> runHlp( Bytes const& wasmCode, HostFunctions& hfs, diff --git a/src/libxrpl/tx/wasm/HostFuncImpl.cpp b/src/libxrpl/tx/wasm/HostFuncImpl.cpp index 15ffeba68b..fa2b0153d8 100644 --- a/src/libxrpl/tx/wasm/HostFuncImpl.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImpl.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -15,11 +14,11 @@ namespace xrpl { // SECTION: WRITE FUNCTION // ========================================================= -Expected +std::expected WasmHostFunctionsImpl::updateData(Slice const& data) { if (data.size() > kMaxWasmDataLength) - return Unexpected(HostFunctionError::DataFieldTooLarge); + return std::unexpected(HostFunctionError::DataFieldTooLarge); data_ = Bytes(data.begin(), data.end()); return data_->size(); @@ -29,20 +28,20 @@ WasmHostFunctionsImpl::updateData(Slice const& data) // SECTION: UTILS // ========================================================= -Expected +std::expected WasmHostFunctionsImpl::checkSignature( Slice const& message, Slice const& signature, Slice const& pubkey) const { if (!publicKeyType(pubkey)) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); PublicKey const pk(pubkey); return verify(pk, message, signature); } -Expected +std::expected WasmHostFunctionsImpl::computeSha512HalfHash(Slice const& data) const { auto const hash = sha512Half(data); diff --git a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp index dda1a09296..57e24dd4b7 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -92,7 +91,7 @@ public: return Number::operator int64_t(); } - Expected + std::expected toBytes() const { Serializer msg; @@ -107,7 +106,7 @@ public: std::cout << std::setw(2) << (unsigned)c << " "; std::cout << std::dec << std::setfill(' ') << std::endl; #endif - return Expected(std::move(data)); + return std::expected(std::move(data)); } }; @@ -155,164 +154,164 @@ floatToString(Slice const& data) return s; } -Expected +std::expected floatFromIntImpl(int64_t x, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE + return std::unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatFromUintImpl(uint64_t x, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE + return std::unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatFromSTAmountImpl(STAmount const& x, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(static_cast(x)); if (!num) - return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE + return std::unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatFromSTNumberImpl(STNumber const& x, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x.value()); if (!num) - return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE + return std::unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatToIntImpl(Slice const& x, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE + return std::unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE int64_t const r(num); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatToMantExpImpl(Slice const& x) { try { detail::FloatState const rm(static_cast(Number::RoundingMode::ToNearest)); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE + return std::unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE return FloatPair(num.mantissa(), num.exponent()); } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatFromMantExpImpl(int64_t mantissa, int32_t exponent, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(mantissa, exponent); if (!num) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); return num.toBytes(); } catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } } -Expected +std::expected floatCompareImpl(Slice const& x, Slice const& y) { try @@ -322,10 +321,10 @@ floatCompareImpl(Slice const& x, Slice const& y) detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); if (xx < yy) return 2; if (xx == yy) @@ -335,26 +334,26 @@ floatCompareImpl(Slice const& x, Slice const& y) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatAddImpl(Slice const& x, Slice const& y, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx + yy; return res.toBytes(); @@ -362,25 +361,25 @@ floatAddImpl(Slice const& x, Slice const& y, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatSubtractImpl(Slice const& x, Slice const& y, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx - yy; return res.toBytes(); @@ -388,25 +387,25 @@ floatSubtractImpl(Slice const& x, Slice const& y, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatMultiplyImpl(Slice const& x, Slice const& y, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx * yy; return res.toBytes(); @@ -414,50 +413,50 @@ floatMultiplyImpl(Slice const& x, Slice const& y, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatDivideImpl(Slice const& x, Slice const& y, int32_t mode) { try { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx / yy; return res.toBytes(); } catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } } -Expected +std::expected floatRootImpl(Slice const& x, int32_t n, int32_t mode) { try { if (n < 1) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res(root(xx, n)); @@ -466,28 +465,28 @@ floatRootImpl(Slice const& x, int32_t n, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } -Expected +std::expected floatPowerImpl(Slice const& x, int32_t n, int32_t mode) { try { if ((n < 0) || (n > Number::kMaxExponent)) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FloatInputMalformed); + return std::unexpected(HostFunctionError::FloatInputMalformed); if (xx == Number() && (n == 0)) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); detail::WasmNumber const res(power(xx, n, 1)); @@ -496,7 +495,7 @@ floatPowerImpl(Slice const& x, int32_t n, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FloatComputationError); + return std::unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -507,85 +506,85 @@ floatPowerImpl(Slice const& x, int32_t n, int32_t mode) // ACTUAL HOST FUNCTIONS // ========================================================= -Expected +std::expected WasmHostFunctionsImpl::floatFromInt(int64_t x, int32_t mode) const { return wasm_float::floatFromIntImpl(x, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatFromUint(uint64_t x, int32_t mode) const { return wasm_float::floatFromUintImpl(x, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatFromSTAmount(STAmount const& x, int32_t mode) const { return wasm_float::floatFromSTAmountImpl(x, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatFromSTNumber(STNumber const& x, int32_t mode) const { return wasm_float::floatFromSTNumberImpl(x, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatToInt(Slice const& x, int32_t mode) const { return wasm_float::floatToIntImpl(x, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatToMantExp(Slice const& x) const { return wasm_float::floatToMantExpImpl(x); } -Expected +std::expected WasmHostFunctionsImpl::floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const { return wasm_float::floatFromMantExpImpl(mantissa, exponent, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatCompare(Slice const& x, Slice const& y) const { return wasm_float::floatCompareImpl(x, y); } -Expected +std::expected WasmHostFunctionsImpl::floatAdd(Slice const& x, Slice const& y, int32_t mode) const { return wasm_float::floatAddImpl(x, y, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatSubtract(Slice const& x, Slice const& y, int32_t mode) const { return wasm_float::floatSubtractImpl(x, y, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatMultiply(Slice const& x, Slice const& y, int32_t mode) const { return wasm_float::floatMultiplyImpl(x, y, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatDivide(Slice const& x, Slice const& y, int32_t mode) const { return wasm_float::floatDivideImpl(x, y, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatRoot(Slice const& x, int32_t n, int32_t mode) const { return wasm_float::floatRootImpl(x, n, mode); } -Expected +std::expected WasmHostFunctionsImpl::floatPower(Slice const& x, int32_t n, int32_t mode) const { return wasm_float::floatPowerImpl(x, n, mode); diff --git a/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp b/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp index 344c1f038a..a4cb37a30e 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -36,11 +35,11 @@ getIntBytes(STBase const* obj) return Bytes{b, b + sizeof(T)}; } -static Expected +static std::expected getAnyFieldData(STBase const* obj) { if (obj == nullptr) - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); auto const stype = obj->getSType(); switch (stype) @@ -48,13 +47,13 @@ getAnyFieldData(STBase const* obj) // LCOV_EXCL_START case STI_UNKNOWN: case STI_NOTPRESENT: - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); // LCOV_EXCL_STOP case STI_OBJECT: case STI_ARRAY: case STI_VECTOR256: - return Unexpected(HostFunctionError::NotLeafField); + return std::unexpected(HostFunctionError::NotLeafField); case STI_ACCOUNT: { auto const* account(static_cast(obj)); // NOLINT @@ -115,7 +114,7 @@ getAnyFieldData(STBase const* obj) return msg.getData(); } -static Expected +static std::expected getAnyFieldData(FieldValue const& variantObj) { if (STBase const* const* obj = std::get_if(&variantObj)) @@ -136,7 +135,7 @@ noField(STBase const* field) (STI_UNKNOWN == field->getSType()); } -static Expected +static std::expected locateField(STObject const& obj, FieldLocator const& locator) { STBase const* field = nullptr; @@ -146,12 +145,12 @@ locateField(STObject const& obj, FieldLocator const& locator) int32_t const sfieldCode = adjustWasmEndianess(locator[0]); auto const it = knownSFields.find(sfieldCode); if (it == knownSFields.end()) - return Unexpected(HostFunctionError::InvalidField); + return std::unexpected(HostFunctionError::InvalidField); auto const& fname(*it->second); field = obj.peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); } for (unsigned i = 1; i < locator.size(); ++i) @@ -162,7 +161,7 @@ locateField(STObject const& obj, FieldLocator const& locator) { auto const* arr = static_cast(field); // NOLINT if (sfieldCode < 0 || std::cmp_greater_equal(sfieldCode, arr->size())) - return Unexpected(HostFunctionError::IndexOutOfBounds); + return std::unexpected(HostFunctionError::IndexOutOfBounds); field = &(arr->operator[](sfieldCode)); } else if (STI_OBJECT == field->getSType()) @@ -171,7 +170,7 @@ locateField(STObject const& obj, FieldLocator const& locator) auto const it = knownSFields.find(sfieldCode); if (it == knownSFields.end()) - return Unexpected(HostFunctionError::InvalidField); + return std::unexpected(HostFunctionError::InvalidField); auto const& fname(*it->second); field = o->peekAtPField(fname); @@ -180,22 +179,22 @@ locateField(STObject const& obj, FieldLocator const& locator) { auto const* v = static_cast(field); // NOLINT if (sfieldCode < 0 || std::cmp_greater_equal(sfieldCode, v->size())) - return Unexpected(HostFunctionError::IndexOutOfBounds); + return std::unexpected(HostFunctionError::IndexOutOfBounds); return FieldValue(&(v->operator[](sfieldCode))); } else // simple field must be the last one { - return Unexpected(HostFunctionError::LocatorMalformed); + return std::unexpected(HostFunctionError::LocatorMalformed); } if (noField(field)) - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); } return FieldValue(field); } -static inline Expected +static inline std::expected getArrayLen(FieldValue const& variantField) { if (STBase const* const* field = std::get_if(&variantField)) @@ -207,15 +206,15 @@ getArrayLen(FieldValue const& variantField) } // uint256 is not an array so that variant should still return NO_ARRAY - return Unexpected(HostFunctionError::NoArray); // LCOV_EXCL_LINE + return std::unexpected(HostFunctionError::NoArray); // LCOV_EXCL_LINE } -Expected +std::expected WasmHostFunctionsImpl::cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) { auto const& keylet = keylet::unchecked(objId); if (cacheIdx < 0 || cacheIdx > maxCache) - return Unexpected(HostFunctionError::SlotOutRange); + return std::unexpected(HostFunctionError::SlotOutRange); if (cacheIdx == 0) { @@ -231,167 +230,167 @@ WasmHostFunctionsImpl::cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) } if (cacheIdx >= maxCache) - return Unexpected(HostFunctionError::SlotsFull); + return std::unexpected(HostFunctionError::SlotsFull); cache_[cacheIdx] = ctx_.view().read(keylet); if (!cache_[cacheIdx]) - return Unexpected(HostFunctionError::LedgerObjNotFound); + return std::unexpected(HostFunctionError::LedgerObjNotFound); return cacheIdx + 1; // return 1-based index } // Subsection: top level getters -Expected +std::expected WasmHostFunctionsImpl::getTxField(SField const& fname) const { return getAnyFieldData(ctx_.tx.peekAtPField(fname)); } -Expected +std::expected WasmHostFunctionsImpl::getCurrentLedgerObjField(SField const& fname) const { auto const sle = getCurrentLedgerObj(); if (!sle.has_value()) - return Unexpected(sle.error()); + return std::unexpected(sle.error()); return getAnyFieldData(sle.value()->peekAtPField(fname)); } -Expected +std::expected WasmHostFunctionsImpl::getLedgerObjField(int32_t cacheIdx, SField const& fname) const { auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) - return Unexpected(normalizedIdx.error()); + return std::unexpected(normalizedIdx.error()); return getAnyFieldData(cache_[normalizedIdx.value()]->peekAtPField(fname)); } // Subsection: nested getters -Expected +std::expected WasmHostFunctionsImpl::getTxNestedField(FieldLocator const& locator) const { auto const r = locateField(ctx_.tx, locator); if (!r) - return Unexpected(r.error()); + return std::unexpected(r.error()); return getAnyFieldData(r.value()); } -Expected +std::expected WasmHostFunctionsImpl::getCurrentLedgerObjNestedField(FieldLocator const& locator) const { auto const sle = getCurrentLedgerObj(); if (!sle.has_value()) - return Unexpected(sle.error()); + return std::unexpected(sle.error()); auto const r = locateField(*sle.value(), locator); if (!r) - return Unexpected(r.error()); + return std::unexpected(r.error()); return getAnyFieldData(r.value()); } -Expected +std::expected WasmHostFunctionsImpl::getLedgerObjNestedField(int32_t cacheIdx, FieldLocator const& locator) const { auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) - return Unexpected(normalizedIdx.error()); + return std::unexpected(normalizedIdx.error()); auto const r = locateField(*cache_[normalizedIdx.value()], locator); if (!r) - return Unexpected(r.error()); + return std::unexpected(r.error()); return getAnyFieldData(r.value()); } // Subsection: array length getters -Expected +std::expected WasmHostFunctionsImpl::getTxArrayLen(SField const& fname) const { if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256) - return Unexpected(HostFunctionError::NoArray); + return std::unexpected(HostFunctionError::NoArray); auto const* field = ctx_.tx.peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); return getArrayLen(field); } -Expected +std::expected WasmHostFunctionsImpl::getCurrentLedgerObjArrayLen(SField const& fname) const { if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256) - return Unexpected(HostFunctionError::NoArray); + return std::unexpected(HostFunctionError::NoArray); auto const sle = getCurrentLedgerObj(); if (!sle.has_value()) - return Unexpected(sle.error()); + return std::unexpected(sle.error()); auto const* field = sle.value()->peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); return getArrayLen(field); } -Expected +std::expected WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const { if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256) - return Unexpected(HostFunctionError::NoArray); + return std::unexpected(HostFunctionError::NoArray); auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) - return Unexpected(normalizedIdx.error()); + return std::unexpected(normalizedIdx.error()); auto const* field = cache_[normalizedIdx.value()]->peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); return getArrayLen(field); } // Subsection: nested array length getters -Expected +std::expected WasmHostFunctionsImpl::getTxNestedArrayLen(FieldLocator const& locator) const { auto const r = locateField(ctx_.tx, locator); if (!r) - return Unexpected(r.error()); + return std::unexpected(r.error()); auto const& field = r.value(); return getArrayLen(field); } -Expected +std::expected WasmHostFunctionsImpl::getCurrentLedgerObjNestedArrayLen(FieldLocator const& locator) const { auto const sle = getCurrentLedgerObj(); if (!sle.has_value()) - return Unexpected(sle.error()); + return std::unexpected(sle.error()); auto const r = locateField(*sle.value(), locator); if (!r) - return Unexpected(r.error()); + return std::unexpected(r.error()); auto const& field = r.value(); return getArrayLen(field); } -Expected +std::expected WasmHostFunctionsImpl::getLedgerObjNestedArrayLen(int32_t cacheIdx, FieldLocator const& locator) const { auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) - return Unexpected(normalizedIdx.error()); + return std::unexpected(normalizedIdx.error()); auto const r = locateField(*cache_[normalizedIdx.value()], locator); if (!r) - return Unexpected(r.error()); + return std::unexpected(r.error()); auto const& field = r.value(); return getArrayLen(field); diff --git a/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp b/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp index 5d1d14bfac..66d96381c8 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -13,208 +12,208 @@ namespace xrpl { -Expected +std::expected WasmHostFunctionsImpl::accountKeylet(AccountID const& account) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::account(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::ammKeylet(Asset const& issue1, Asset const& issue2) const { if (issue1 == issue2) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); // note: this should be removed with the MPT DEX amendment if (issue1.holds() || issue2.holds()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::amm(issue1, issue2); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::checkKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::check(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::credentialKeylet( AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const { if (!subject || !issuer) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); if (credentialType.empty() || credentialType.size() > kMaxCredentialTypeLength) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::credential(subject, issuer, credentialType); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::didKeylet(AccountID const& account) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::did(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::delegateKeylet(AccountID const& account, AccountID const& authorize) const { if (!account || !authorize) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); if (account == authorize) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::delegate(account, authorize); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const { if (!account || !authorize) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); if (account == authorize) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::depositPreauth(account, authorize); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::escrowKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::escrow(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected -WasmHostFunctionsImpl::lineKeylet( +std::expected +WasmHostFunctionsImpl::trustLineKeylet( AccountID const& account1, AccountID const& account2, Currency const& currency) const { if (!account1 || !account2) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); if (account1 == account2) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); if (currency.isZero()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); - auto const keylet = keylet::line(account1, account2, currency); + auto const keylet = keylet::trustLine(account1, account2, currency); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected -WasmHostFunctionsImpl::mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const +std::expected +WasmHostFunctionsImpl::mptokenIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const { if (!issuer) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); - auto const keylet = keylet::mptIssuance(seq, issuer); + auto const keylet = keylet::mptokenIssuance(seq, issuer); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::mptokenKeylet(MPTID const& mptid, AccountID const& holder) const { if (!mptid) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); if (!holder) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::mptoken(mptid, holder); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected -WasmHostFunctionsImpl::nftOfferKeylet(AccountID const& account, std::uint32_t seq) const +std::expected +WasmHostFunctionsImpl::nftokenOfferKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); - auto const keylet = keylet::nftoffer(account, seq); + return std::unexpected(HostFunctionError::InvalidAccount); + auto const keylet = keylet::nftokenOffer(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::offerKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::offer(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::oracleKeylet(AccountID const& account, std::uint32_t documentId) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::oracle(account, documentId); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected -WasmHostFunctionsImpl::paychanKeylet( +std::expected +WasmHostFunctionsImpl::paychannelKeylet( AccountID const& account, AccountID const& destination, std::uint32_t seq) const { if (!account || !destination) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); if (account == destination) - return Unexpected(HostFunctionError::InvalidParams); - auto const keylet = keylet::payChan(account, destination, seq); + return std::unexpected(HostFunctionError::InvalidParams); + auto const keylet = keylet::payChannel(account, destination, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::permissionedDomain(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected -WasmHostFunctionsImpl::signersKeylet(AccountID const& account) const +std::expected +WasmHostFunctionsImpl::signerListKeylet(AccountID const& account) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); - auto const keylet = keylet::signers(account); + return std::unexpected(HostFunctionError::InvalidAccount); + auto const keylet = keylet::signerList(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::ticketKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); - auto const keylet = keylet::kTicket(account, seq); + return std::unexpected(HostFunctionError::InvalidAccount); + auto const keylet = keylet::ticket(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } -Expected +std::expected WasmHostFunctionsImpl::vaultKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::vault(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } diff --git a/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp b/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp index 837112389a..49a4c3cdf0 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -14,37 +13,37 @@ namespace xrpl { // SECTION: LEDGER HEADER FUNCTIONS // ========================================================= -Expected +std::expected WasmHostFunctionsImpl::getLedgerSqn() const { return ctx_.view().seq(); } -Expected +std::expected WasmHostFunctionsImpl::getParentLedgerTime() const { return ctx_.view().parentCloseTime().time_since_epoch().count(); } -Expected +std::expected WasmHostFunctionsImpl::getParentLedgerHash() const { return ctx_.view().header().parentHash; } -Expected +std::expected WasmHostFunctionsImpl::getBaseFee() const { return ctx_.view().fees().base.drops(); } -Expected +std::expected WasmHostFunctionsImpl::isAmendmentEnabled(uint256 const& amendmentId) const { return ctx_.view().rules().enabled(amendmentId); } -Expected +std::expected WasmHostFunctionsImpl::isAmendmentEnabled(std::string_view const& amendmentName) const { auto const& table = ctx_.registry.get().getAmendmentTable(); diff --git a/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp b/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp index 30d6dd5eff..118172c247 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -16,59 +15,59 @@ namespace xrpl { // SECTION: NFT UTILS // ========================================================= -Expected +std::expected WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId) const { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); if (!nftId) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); auto obj = nft::findToken(ctx_.view(), account, nftId); if (!obj) - return Unexpected(HostFunctionError::LedgerObjNotFound); + return std::unexpected(HostFunctionError::LedgerObjNotFound); auto objUri = obj->at(~sfURI); if (!objUri) - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); Slice const s = objUri->value(); return Bytes(s.begin(), s.end()); } -Expected +std::expected WasmHostFunctionsImpl::getNFTIssuer(uint256 const& nftId) const { auto const issuer = nft::getIssuer(nftId); if (!issuer) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); return Bytes{issuer.begin(), issuer.end()}; } -Expected +std::expected WasmHostFunctionsImpl::getNFTTaxon(uint256 const& nftId) const { return nft::toUInt32(nft::getTaxon(nftId)); } -Expected +std::expected WasmHostFunctionsImpl::getNFTFlags(uint256 const& nftId) const { return nft::getFlags(nftId); } -Expected +std::expected WasmHostFunctionsImpl::getNFTTransferFee(uint256 const& nftId) const { return nft::getTransferFee(nftId); } -Expected -WasmHostFunctionsImpl::getNFTSerial(uint256 const& nftId) const +std::expected +WasmHostFunctionsImpl::getNFTSequence(uint256 const& nftId) const { - return nft::getSerial(nftId); + return nft::getSequence(nftId); } } // namespace xrpl diff --git a/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp b/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp index 0f9ee2e64c..fea608aa77 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -18,7 +17,7 @@ namespace xrpl { -Expected +std::expected WasmHostFunctionsImpl::trace(std::string_view const& msg, Slice const& data, bool asHex) const { if (!asHex) @@ -40,28 +39,28 @@ WasmHostFunctionsImpl::trace(std::string_view const& msg, Slice const& data, boo return 0; } -Expected +std::expected WasmHostFunctionsImpl::traceNum(std::string_view const& msg, int64_t data) const { log(msg, [data] { return data; }); return 0; } -Expected +std::expected WasmHostFunctionsImpl::traceAccount(std::string_view const& msg, AccountID const& account) const { log(msg, [&account] { return toBase58(account); }); return 0; } -Expected +std::expected WasmHostFunctionsImpl::traceFloat(std::string_view const& msg, Slice const& data) const { log(msg, [&data] { return wasm_float::floatToString(data); }); return 0; } -Expected +std::expected WasmHostFunctionsImpl::traceAmount(std::string_view const& msg, STAmount const& amount) const { log(msg, [&amount] { return amount.getFullText(); }); diff --git a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp index af8bb637d4..9788bce345 100644 --- a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp +++ b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -69,7 +68,7 @@ checkGas(WasmRuntimeWrapper& rt, int64_t delta) // Transfer limit is a separate soft budget: exceeding it is a normal guest-facing // return code, not a trap. Only a failed setTransferLimit (an xrpld bug) throws. -static inline Expected +static inline std::expected checkTransfer(WasmRuntimeWrapper& rt, int64_t delta) { auto const transLimit = rt.getTransferLimit(); @@ -79,7 +78,7 @@ checkTransfer(WasmRuntimeWrapper& rt, int64_t delta) Throw(std::string(hfErrInternal)); // LCOV_EXCL_LINE if (transLimit < delta) - return Unexpected(HostFunctionError::OutOfTransferLimit); + return std::unexpected(HostFunctionError::OutOfTransferLimit); return x; } @@ -147,35 +146,35 @@ setData( return srcSize; } -static Expected +static std::expected getDataSlice(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { int64_t const ptr = params->data[i].of.i32; int64_t const size = params->data[i + 1].of.i32; i += 2; if (ptr < 0 || size < 0) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); if (size == 0) return Slice(); if (size > kMaxWasmDataLength) - return Unexpected(HostFunctionError::DataFieldTooLarge); + return std::unexpected(HostFunctionError::DataFieldTooLarge); auto const memory = runtime.getMem(); // LCOV_EXCL_START if (memory.s == 0u) - return Unexpected(HostFunctionError::NoMemExported); + return std::unexpected(HostFunctionError::NoMemExported); // LCOV_EXCL_STOP if (std::cmp_greater(ptr + size, memory.s)) - return Unexpected(HostFunctionError::PointerOutOfBounds); + return std::unexpected(HostFunctionError::PointerOutOfBounds); Slice data(memory.p + ptr, size); return data; } -static Expected +static std::expected getDataInt32(WasmRuntimeWrapper const&, wasm_val_vec_t const* params, int32_t& i) { auto const result = params->data[i].of.i32; @@ -183,7 +182,7 @@ getDataInt32(WasmRuntimeWrapper const&, wasm_val_vec_t const* params, int32_t& i return result; } -static Expected +static std::expected getDataInt64(WasmRuntimeWrapper const&, wasm_val_vec_t const* params, int32_t& i) { auto const result = params->data[i].of.i64; @@ -192,15 +191,15 @@ getDataInt64(WasmRuntimeWrapper const&, wasm_val_vec_t const* params, int32_t& i } template -static Expected +static std::expected getDataUnsigned(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { static_assert(std::is_unsigned_v); auto const r = getDataSlice(runtime, params, i); if (!r) - return Unexpected(r.error()); + return std::unexpected(r.error()); if (r->size() != sizeof(T)) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); T x; uintptr_t const p = reinterpret_cast(r->data()); @@ -217,89 +216,89 @@ getDataUnsigned(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32 return x; } -static Expected +static std::expected getDataUInt32(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { return getDataUnsigned(runtime, params, i); } -static Expected +static std::expected getDataUInt64(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { return getDataUnsigned(runtime, params, i); } -static Expected +static std::expected getDataSField(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { auto const& m = SField::getKnownCodeToField(); auto const it = m.find(params->data[i].of.i32); i++; if (it == m.end()) - return Unexpected(HostFunctionError::InvalidField); + return std::unexpected(HostFunctionError::InvalidField); return *it->second; } -static Expected +static std::expected getDataUInt256(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { auto const slice = getDataSlice(runtime, params, i); if (!slice) - return Unexpected(slice.error()); + return std::unexpected(slice.error()); if (slice->size() != uint256::size()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); if (auto t = checkTransfer(runtime, uint256::size()); !t) - return Unexpected(t.error()); + return std::unexpected(t.error()); return uint256::fromVoid(slice->data()); } -static Expected +static std::expected getDataAccountID(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { auto const slice = getDataSlice(runtime, params, i); if (!slice) - return Unexpected(slice.error()); + return std::unexpected(slice.error()); if (slice->size() != AccountID::size()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); if (auto t = checkTransfer(runtime, AccountID::size()); !t) - return Unexpected(t.error()); + return std::unexpected(t.error()); return AccountID::fromVoid(slice->data()); } -static Expected +static std::expected getDataCurrency(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { auto const slice = getDataSlice(runtime, params, i); if (!slice) - return Unexpected(slice.error()); + return std::unexpected(slice.error()); if (slice->size() != Currency::size()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); if (auto t = checkTransfer(runtime, Currency::size()); !t) - return Unexpected(t.error()); + return std::unexpected(t.error()); return Currency::fromVoid(slice->data()); } -static Expected +static std::expected getDataAsset(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { auto const slice = getDataSlice(runtime, params, i); if (!slice) - return Unexpected(slice.error()); + return std::unexpected(slice.error()); if (slice->size() == MPTID::size()) { if (auto t = checkTransfer(runtime, slice->size()); !t) - return Unexpected(t.error()); + return std::unexpected(t.error()); auto const mptid = MPTID::fromVoid(slice->data()); return Asset{mptid}; @@ -308,12 +307,12 @@ getDataAsset(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& if (slice->size() == Currency::size()) { if (auto t = checkTransfer(runtime, slice->size()); !t) - return Unexpected(t.error()); + return std::unexpected(t.error()); auto const currency = Currency::fromVoid(slice->data()); auto const issue = Issue{currency, xrpAccount()}; if (!issue.native()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); return Asset{issue}; } @@ -321,41 +320,41 @@ getDataAsset(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& if (slice->size() == (Currency::size() + AccountID::size())) { if (auto t = checkTransfer(runtime, slice->size()); !t) - return Unexpected(t.error()); + return std::unexpected(t.error()); auto const issue = Issue( Currency::fromVoid(slice->data()), AccountID::fromVoid(slice->data() + Currency::size())); if (issue.native()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); return Asset{issue}; } - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); } -static Expected +static std::expected getDataString(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { auto const slice = getDataSlice(runtime, params, i); if (!slice) - return Unexpected(slice.error()); + return std::unexpected(slice.error()); return std::string_view(reinterpret_cast(slice->data()), slice->size()); } -static Expected +static std::expected getDataLocator(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i) { static_assert(kMaxWasmDataLength % sizeof(int32_t) == 0); auto const slice = getDataSlice(runtime, params, i); if (!slice) - return Unexpected(slice.error()); + return std::unexpected(slice.error()); if (slice->empty() || ((slice->size() & 3) != 0u)) // must be multiple of 4 - return Unexpected(HostFunctionError::LocatorMalformed); + return std::unexpected(HostFunctionError::LocatorMalformed); uint32_t const locSize = slice->size() / sizeof(int32_t); uintptr_t const p = reinterpret_cast(slice->data()); @@ -368,7 +367,7 @@ getDataLocator(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_ // guest-facing code when the transfer limit is exceeded. checkGas(runtime, unalignedGas); if (auto t = checkTransfer(runtime, slice->size()); !t) - return Unexpected(t.error()); + return std::unexpected(t.error()); std::vector locBuf(locSize); memcpy(&locBuf[0], slice->data(), slice->size()); @@ -403,7 +402,7 @@ returnResult( WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, wasm_val_vec_t* results, - Expected const& res, + std::expected const& res, int32_t index) { if (!res) @@ -979,7 +978,7 @@ escrowKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) } wasm_trap_t* -lineKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) +trustLineKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) { int index = 0; WasmRuntimeWrapper& runtime = hf.getRT(); @@ -1000,12 +999,12 @@ lineKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) runtime, params, results, - hf.lineKeylet(acc1.value(), acc2.value(), currency.value()), + hf.trustLineKeylet(acc1.value(), acc2.value(), currency.value()), index); } wasm_trap_t* -mptIssuanceKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) +mptokenIssuanceKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) { int index = 0; WasmRuntimeWrapper& runtime = hf.getRT(); @@ -1019,7 +1018,7 @@ mptIssuanceKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) return hfResult(results, seq.error()); return returnResult( - runtime, params, results, hf.mptIssuanceKeylet(acc.value(), seq.value()), index); + runtime, params, results, hf.mptokenIssuanceKeylet(acc.value(), seq.value()), index); } wasm_trap_t* @@ -1044,7 +1043,7 @@ mptokenKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) } wasm_trap_t* -nftOfferKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) +nftokenOfferKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) { int index = 0; WasmRuntimeWrapper& runtime = hf.getRT(); @@ -1058,7 +1057,7 @@ nftOfferKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) return hfResult(results, seq.error()); return returnResult( - runtime, params, results, hf.nftOfferKeylet(acc.value(), seq.value()), index); + runtime, params, results, hf.nftokenOfferKeylet(acc.value(), seq.value()), index); } wasm_trap_t* @@ -1096,7 +1095,7 @@ oracleKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) } wasm_trap_t* -paychanKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) +paychannelKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) { int index = 0; WasmRuntimeWrapper& runtime = hf.getRT(); @@ -1114,7 +1113,11 @@ paychanKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) return hfResult(results, seq.error()); return returnResult( - runtime, params, results, hf.paychanKeylet(acc.value(), dest.value(), seq.value()), index); + runtime, + params, + results, + hf.paychannelKeylet(acc.value(), dest.value(), seq.value()), + index); } wasm_trap_t* @@ -1136,7 +1139,7 @@ permissionedDomainKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) } wasm_trap_t* -signersKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) +signerListKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) { int index = 0; WasmRuntimeWrapper& runtime = hf.getRT(); @@ -1145,7 +1148,7 @@ signersKeylet_wrap(WASM_SECONDARY_CB_PARAMS_LIST) if (!acc) return hfResult(results, acc.error()); - return returnResult(runtime, params, results, hf.signersKeylet(acc.value()), index); + return returnResult(runtime, params, results, hf.signerListKeylet(acc.value()), index); } wasm_trap_t* @@ -1252,7 +1255,7 @@ getNFTTransferFee_wrap(WASM_SECONDARY_CB_PARAMS_LIST) } wasm_trap_t* -getNFTSerial_wrap(WASM_SECONDARY_CB_PARAMS_LIST) +getNFTSequence_wrap(WASM_SECONDARY_CB_PARAMS_LIST) { int index = 0; WasmRuntimeWrapper& runtime = hf.getRT(); @@ -1261,7 +1264,7 @@ getNFTSerial_wrap(WASM_SECONDARY_CB_PARAMS_LIST) if (!nftId) return hfResult(results, nftId.error()); - return returnResult(runtime, params, results, hf.getNFTSerial(*nftId), index); + return returnResult(runtime, params, results, hf.getNFTSequence(*nftId), index); } wasm_trap_t* @@ -1362,7 +1365,7 @@ traceAmount_wrap(WASM_SECONDARY_CB_PARAMS_LIST) std::optional amount; try { - amount = STAmount(serialIter, kSfGeneric); + amount = STAmount(serialIter, sfGeneric); } catch (std::exception const&) { @@ -1429,7 +1432,7 @@ floatFromSTAmount_wrap(WASM_SECONDARY_CB_PARAMS_LIST) std::optional amount; try { - amount = STAmount(serialIter, kSfGeneric); + amount = STAmount(serialIter, sfGeneric); } catch (std::exception const&) { @@ -1461,7 +1464,7 @@ floatFromSTNumber_wrap(WASM_SECONDARY_CB_PARAMS_LIST) std::optional num; try { - num = STNumber(serialIter, kSfGeneric); + num = STNumber(serialIter, sfGeneric); } catch (std::exception const&) { diff --git a/src/libxrpl/tx/wasm/WasmVM.cpp b/src/libxrpl/tx/wasm/WasmVM.cpp index 0a2dcbde65..141da2dc81 100644 --- a/src/libxrpl/tx/wasm/WasmVM.cpp +++ b/src/libxrpl/tx/wasm/WasmVM.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include // IWYU pragma: keep @@ -62,15 +61,15 @@ setCommonHostFunctions(HostFunctions& hfs, ImportVec& i) WASM_IMPORT_FUNC2(i, depositPreauthKeylet, "deposit_preauth_id", hfs, 350); WASM_IMPORT_FUNC2(i, didKeylet, "did_id", hfs, 350); WASM_IMPORT_FUNC2(i, escrowKeylet, "escrow_id", hfs, 350); - WASM_IMPORT_FUNC2(i, lineKeylet, "trustline_id", hfs, 400); - WASM_IMPORT_FUNC2(i, mptIssuanceKeylet, "mpt_issuance_id", hfs, 350); + WASM_IMPORT_FUNC2(i, trustLineKeylet, "trustline_id", hfs, 400); + WASM_IMPORT_FUNC2(i, mptokenIssuanceKeylet, "mptoken_issuance_id", hfs, 350); WASM_IMPORT_FUNC2(i, mptokenKeylet, "mptoken_id", hfs, 500); - WASM_IMPORT_FUNC2(i, nftOfferKeylet, "nft_offer_id", hfs, 350); + WASM_IMPORT_FUNC2(i, nftokenOfferKeylet, "nft_offer_id", hfs, 350); WASM_IMPORT_FUNC2(i, offerKeylet, "offer_id", hfs, 350); WASM_IMPORT_FUNC2(i, oracleKeylet, "oracle_id", hfs, 350); - WASM_IMPORT_FUNC2(i, paychanKeylet, "paychan_id", hfs, 350); + WASM_IMPORT_FUNC2(i, paychannelKeylet, "paychannel_id", hfs, 350); WASM_IMPORT_FUNC2(i, permissionedDomainKeylet, "permissioned_domain_id", hfs, 350); - WASM_IMPORT_FUNC2(i, signersKeylet, "signers_id", hfs, 350); + WASM_IMPORT_FUNC2(i, signerListKeylet, "signer_list_id", hfs, 350); WASM_IMPORT_FUNC2(i, ticketKeylet, "ticket_id", hfs, 350); WASM_IMPORT_FUNC2(i, vaultKeylet, "vault_id", hfs, 350); @@ -79,7 +78,7 @@ setCommonHostFunctions(HostFunctions& hfs, ImportVec& i) WASM_IMPORT_FUNC2(i, getNFTTaxon, "nft_taxon", hfs, 60); WASM_IMPORT_FUNC2(i, getNFTFlags, "nft_flags", hfs, 60); WASM_IMPORT_FUNC2(i, getNFTTransferFee, "nft_xfer_fee", hfs, 60); - WASM_IMPORT_FUNC2(i, getNFTSerial, "nft_serial", hfs, 60); + WASM_IMPORT_FUNC2(i, getNFTSequence, "nft_seq", hfs, 60); WASM_IMPORT_FUNC (i, trace, hfs, 500); WASM_IMPORT_FUNC2(i, traceNum, "trace_num", hfs, 500); @@ -115,7 +114,7 @@ createWasmImport(HostFunctions& hfs) return i; } -Expected +std::expected runEscrowWasm( Bytes const& wasmCode, HostFunctions& hfs, @@ -138,7 +137,7 @@ runEscrowWasm( // Carries the TER (tecOUT_OF_GAS / tecFAILED_PROCESSING / tecINTERNAL / // temBAD_AMOUNT) and, when meaningful, the gas consumed. The caller is // responsible for writing that gas to tx metadata. - return Unexpected(ret.error()); + return std::unexpected(ret.error()); } #ifdef DEBUG_OUTPUT @@ -177,7 +176,7 @@ WasmEngine::instance() return e; } -Expected, WasmTER> +std::expected, WasmTER> WasmEngine::run( Bytes const& wasmCode, HostFunctions& hfs, diff --git a/src/libxrpl/tx/wasm/WasmiVM.cpp b/src/libxrpl/tx/wasm/WasmiVM.cpp index 57968d311e..a1e3a0aee8 100644 --- a/src/libxrpl/tx/wasm/WasmiVM.cpp +++ b/src/libxrpl/tx/wasm/WasmiVM.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -757,7 +756,7 @@ checkImports(ImportVec const& imports, HostFunctions* hfs) } } -Expected, WasmTER> +std::expected, WasmTER> WasmiEngine::run( Bytes const& wasmCode, HostFunctions& hfs, @@ -768,7 +767,7 @@ WasmiEngine::run( beast::Journal j) { if (gas <= 0) - return Unexpected(WasmTER{.ter = temBAD_AMOUNT, .cost = std::nullopt}); + return std::unexpected(WasmTER{.ter = temBAD_AMOUNT, .cost = std::nullopt}); try { @@ -787,10 +786,10 @@ WasmiEngine::run( // LCOV_EXCL_STOP // An exception escaping the engine is an xrpld-side fault -> tecINTERNAL, // no gas. Genuine wasm faults don't throw; they surface as traps in runHlp. - return Unexpected(WasmTER{.ter = tecINTERNAL, .cost = std::nullopt}); + return std::unexpected(WasmTER{.ter = tecINTERNAL, .cost = std::nullopt}); } -Expected, WasmTER> +std::expected, WasmTER> WasmiEngine::runHlp( Bytes const& wasmCode, HostFunctions& hfs, @@ -841,7 +840,7 @@ WasmiEngine::runHlp( // call() already classified the trap (see WasmiEngine::call). // tecINTERNAL is an xrpld-side bug: report no gas. if (*res.ter == tecINTERNAL) - return Unexpected(WasmTER{.ter = tecINTERNAL, .cost = std::nullopt}); + return std::unexpected(WasmTER{.ter = tecINTERNAL, .cost = std::nullopt}); // Out-of-gas / wasm faults report gas (caller writes it to metadata). // Force fuel to 0 on out-of-gas so cost is the full limit (wasmi leaves @@ -849,7 +848,7 @@ WasmiEngine::runHlp( if (*res.ter == tecOUT_OF_GAS) iw.setGas(0); - return Unexpected(WasmTER{.ter = *res.ter, .cost = gas - moduleWrap_->getGas()}); + return std::unexpected(WasmTER{.ter = *res.ter, .cost = gas - moduleWrap_->getGas()}); } if (res.r.empty()) diff --git a/src/test/app/HostFuncImpl_test.cpp b/src/test/app/HostFuncImpl_test.cpp index 377a7c652a..40718943ad 100644 --- a/src/test/app/HostFuncImpl_test.cpp +++ b/src/test/app/HostFuncImpl_test.cpp @@ -796,22 +796,22 @@ struct HostFuncImpl_test : public beast::unit_test::Suite std::to_string(result[0].of.i32)); } - // hfs.getTxField(kSfInvalid); + // hfs.getTxField(sfInvalid); { WasmValVec params(3), result(1); auto* trap = - ww(&import.at("tx_field"), params, result, kSfInvalid.getCode(), 0, 256); + ww(&import.at("tx_field"), params, result, sfInvalid.getCode(), 0, 256); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } - // hfs.getTxField(kSfGeneric); + // hfs.getTxField(sfGeneric); { WasmValVec params(3), result(1); auto* trap = - ww(&import.at("tx_field"), params, result, kSfGeneric.getCode(), 0, 256); + ww(&import.at("tx_field"), params, result, sfGeneric.getCode(), 0, 256); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( @@ -1355,17 +1355,17 @@ struct HostFuncImpl_test : public beast::unit_test::Suite HostFunctionError::InvalidField); // hfs.getTxNestedField(locator); - // Locator for negative base sfield code (-1 = kSfInvalid, exists in map but not in tx) + // Locator for negative base sfield code (-1 = sfInvalid, exists in map but not in tx) expectError( - {-1, // kSfInvalid's field code + {-1, // sfInvalid's field code 0, sfAccount.getCode()}, HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); - // Locator for zero base sfield code (0 = kSfGeneric, exists in map but not in tx) + // Locator for zero base sfield code (0 = sfGeneric, exists in map but not in tx) expectError( - {0, // kSfGeneric's field code + {0, // sfGeneric's field code 0, sfAccount.getCode()}, HostFunctionError::FieldNotFound); @@ -1380,7 +1380,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Locator for negative nested sfield code in STObject context // (sfMemos[0] is an STObject, then -1 is looked up as SField) expectError( - {sfMemos.getCode(), 0, -1}, // -1 = kSfInvalid, exists in map but not in memo object + {sfMemos.getCode(), 0, -1}, // -1 = sfInvalid, exists in map but not in memo object HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); @@ -1434,7 +1434,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite ApplyContext ac = createApplyContext(env, ov); // Find the signer ledger object - auto const signerKeylet = keylet::signers(env.master.id()); + auto const signerKeylet = keylet::signerList(env.master.id()); BEAST_EXPECT(env.le(signerKeylet)); VirtualRuntime vrt; @@ -1581,7 +1581,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite hfs.setRT(vrt); // Cache the SignerList ledger object in slot 1 - auto const signerListKeylet = keylet::signers(env.master.id()); + auto const signerListKeylet = keylet::signerList(env.master.id()); // hfs.cacheLedgerObj(signerListKeylet.key, 1); { WasmValVec params(3), result(1); @@ -1884,7 +1884,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const signerKeylet = keylet::signers(env.master.id()); + auto const signerKeylet = keylet::signerList(env.master.id()); VirtualRuntime vrt; WasmHostFunctionsImpl hfs(ac, signerKeylet); @@ -1963,7 +1963,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite auto import = xrpl::createWasmImport(hfs); hfs.setRT(vrt); - auto const signerListKeylet = keylet::signers(env.master.id()); + auto const signerListKeylet = keylet::signerList(env.master.id()); // hfs.cacheLedgerObj(signerListKeylet.key, 1); { WasmValVec params(3), result(1); @@ -2109,7 +2109,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const signerKeylet = keylet::signers(env.master.id()); + auto const signerKeylet = keylet::signerList(env.master.id()); VirtualRuntime vrt; WasmHostFunctionsImpl hfs(ac, signerKeylet); @@ -2205,7 +2205,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite auto import = xrpl::createWasmImport(hfs); hfs.setRT(vrt); - auto const signerListKeylet = keylet::signers(env.master.id()); + auto const signerListKeylet = keylet::signerList(env.master.id()); // hfs.cacheLedgerObj(signerListKeylet.key, 1); { WasmValVec params(3), result(1); @@ -2760,7 +2760,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite Currency const usd = toCurrency("USD"); { - auto const expected = keylet::line(masterID, alice.id(), usd); + auto const expected = keylet::trustLine(masterID, alice.id(), usd); WasmValVec params(8), result(1); auto* trap = ww(&imp.at("trustline_id"), params, result, masterID, alice.id(), usd, 1024, 32); @@ -2803,7 +2803,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - auto const expected = keylet::mptIssuance(1u, masterID); + auto const expected = keylet::mptokenIssuance(1u, masterID); WasmValVec params(6), result(1); auto* trap = ww(&imp.at("mpt_issuance_id"), params, result, masterID, toBytes(1u), 1024, 32); @@ -2843,7 +2843,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - auto const expected = keylet::nftoffer(masterID, 1u); + auto const expected = keylet::nftokenOffer(masterID, 1u); WasmValVec params(6), result(1); auto* trap = ww(&imp.at("nft_offer_id"), params, result, masterID, toBytes(1u), 1024, 32); @@ -2895,7 +2895,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - auto const expected = keylet::payChan(masterID, alice.id(), 1u); + auto const expected = keylet::payChannel(masterID, alice.id(), 1u); WasmValVec params(8), result(1); auto* trap = ww( &imp.at("paychan_id"), params, result, masterID, alice.id(), toBytes(1u), 1024, 32); @@ -2963,7 +2963,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - auto const expected = keylet::signers(masterID); + auto const expected = keylet::signerList(masterID); WasmValVec params(4), result(1); auto* trap = ww(&imp.at("signers_id"), params, result, masterID, 1024, 32); if (BEAST_EXPECT(!trap && result[0].kind == WASM_I32 && result[0].of.i32 == 32)) @@ -2979,7 +2979,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - auto const expected = keylet::kTicket(masterID, 1u); + auto const expected = keylet::ticket(masterID, 1u); WasmValVec params(6), result(1); auto* trap = ww(&imp.at("ticket_id"), params, result, masterID, toBytes(1u), 1024, 32); if (BEAST_EXPECT(!trap && result[0].kind == WASM_I32 && result[0].of.i32 == 32)) @@ -3352,7 +3352,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite void testGetNFTSerial() { - testcase("getNFTSerial"); + testcase("getNFTSequence"); using namespace test::jtx; Env env{*this}; @@ -3374,7 +3374,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite hfs.setRT(vrt); { - // hfs.getNFTSerial(nftId); + // hfs.getNFTSequence(nftId); vrt.setBytes(0, nftId.data(), uint256::size()); WasmValVec params(4), result(1); auto* trap = @@ -3395,7 +3395,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Should return 0 for zero NFT id { - // hfs.getNFTSerial(uint256()); + // hfs.getNFTSequence(uint256()); uint256 zeroId; vrt.setBytes(0, zeroId.data(), uint256::size()); WasmValVec params(4), result(1); diff --git a/src/test/app/TestHostFunctions.h b/src/test/app/TestHostFunctions.h index 9d8bc94231..bc24c26932 100644 --- a/src/test/app/TestHostFunctions.h +++ b/src/test/app/TestHostFunctions.h @@ -29,7 +29,7 @@ public: { } - Expected + std::expected getLedgerSqn() const override { return env_.current()->seq(); @@ -51,49 +51,49 @@ public: data_ = Bytes{t.begin(), t.end()}; } - Expected + std::expected getLedgerSqn() const override { return 12345; } - Expected + std::expected getParentLedgerTime() const override { return 67890; } - Expected + std::expected getParentLedgerHash() const override { return env_.current()->header().parentHash; } - Expected + std::expected getBaseFee() const override { return 10; } - Expected + std::expected isAmendmentEnabled(uint256 const& amendmentId) const override { return 1; } - Expected + std::expected isAmendmentEnabled(std::string_view const& amendmentName) const override { return 1; } - Expected + std::expected cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) override { return 1; } - Expected + std::expected getTxField(SField const& fname) const override { if (fname == sfAccount) @@ -110,7 +110,7 @@ public: { auto const x = getLedgerSqn(); if (!x) - return Unexpected(x.error()); + return std::unexpected(x.error()); std::uint32_t const data = x.value(); auto const* b = reinterpret_cast(&data); auto const* e = reinterpret_cast(&data + 1); @@ -120,7 +120,7 @@ public: return Bytes(); } - Expected + std::expected getCurrentLedgerObjField(SField const& fname) const override { auto const& sn = fname.getName(); @@ -135,10 +135,10 @@ public: return Bytes{s.begin(), s.end()}; } - return Unexpected(HostFunctionError::Unimplemented); + return std::unexpected(HostFunctionError::Unimplemented); } - Expected + std::expected getLedgerObjField(int32_t, SField const& fname) const override { if (fname == sfBalance) @@ -154,7 +154,7 @@ public: return data_; } - Expected + std::expected getTxNestedField(FieldLocator const& locator) const override { if (locator.size() == 1) @@ -171,7 +171,7 @@ public: return Bytes(&a[0], &a[sizeof(a)]); } - Expected + std::expected getCurrentLedgerObjNestedField(FieldLocator const& locator) const override { if (locator.size() == 1) @@ -188,7 +188,7 @@ public: return Bytes(&a[0], &a[sizeof(a)]); } - Expected + std::expected getLedgerObjNestedField(int32_t cacheIdx, FieldLocator const& locator) const override { if (locator.size() == 1) @@ -205,154 +205,154 @@ public: return Bytes(&a[0], &a[sizeof(a)]); } - Expected + std::expected getTxArrayLen(SField const& fname) const override { return 32; } - Expected + std::expected getCurrentLedgerObjArrayLen(SField const& fname) const override { return 32; } - Expected + std::expected getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const override { return 32; } - Expected + std::expected getTxNestedArrayLen(FieldLocator const& locator) const override { return 32; } - Expected + std::expected getCurrentLedgerObjNestedArrayLen(FieldLocator const& locator) const override { return 32; } - Expected + std::expected getLedgerObjNestedArrayLen(int32_t cacheIdx, FieldLocator const& locator) const override { return 32; } - Expected + std::expected updateData(Slice const& data) override { return data.size(); } - Expected + std::expected checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const override { return 1; } - Expected + std::expected computeSha512HalfHash(Slice const& data) const override { return env_.current()->header().parentHash; } - Expected + std::expected accountKeylet(AccountID const& account) const override { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::account(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } - Expected + std::expected ammKeylet(Asset const& issue1, Asset const& issue2) const override { if (issue1 == issue2) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); if (issue1.holds() || issue2.holds()) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::amm(issue1, issue2); return Bytes{keylet.key.begin(), keylet.key.end()}; } - Expected + std::expected checkKeylet(AccountID const& account, std::uint32_t seq) const override { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::check(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } - Expected + std::expected credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) const override { if (!subject || !issuer || credentialType.empty() || credentialType.size() > kMaxCredentialTypeLength) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::credential(subject, issuer, credentialType); return Bytes{keylet.key.begin(), keylet.key.end()}; } - Expected + std::expected escrowKeylet(AccountID const& account, std::uint32_t seq) const override { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::escrow(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } - Expected + std::expected oracleKeylet(AccountID const& account, std::uint32_t documentId) const override { if (!account) - return Unexpected(HostFunctionError::InvalidAccount); + return std::unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::oracle(account, documentId); return Bytes{keylet.key.begin(), keylet.key.end()}; } - Expected + std::expected getNFT(AccountID const& account, uint256 const& nftId) const override { if (!account || !nftId) - return Unexpected(HostFunctionError::InvalidParams); + return std::unexpected(HostFunctionError::InvalidParams); std::string s = "https://ripple.com"; return Bytes(s.begin(), s.end()); } - Expected + std::expected getNFTIssuer(uint256 const& nftId) const override { return Bytes(accountID_.begin(), accountID_.end()); } - Expected + std::expected getNFTTaxon(uint256 const& nftId) const override { return 4; } - Expected + std::expected getNFTFlags(uint256 const& nftId) const override { return 8; } - Expected + std::expected getNFTTransferFee(uint256 const& nftId) const override { return 10; } - Expected - getNFTSerial(uint256 const& nftId) const override + std::expected + getNFTSequence(uint256 const& nftId) const override { return 4; } @@ -375,7 +375,7 @@ public: #endif } - Expected + std::expected trace(std::string_view const& msg, Slice const& data, bool asHex) const override { if (!asHex) @@ -397,113 +397,113 @@ public: return 0; } - Expected + std::expected traceNum(std::string_view const& msg, int64_t data) const override { log(msg, [data] { return data; }); return 0; } - Expected + std::expected traceAccount(std::string_view const& msg, AccountID const& account) const override { log(msg, [&account] { return toBase58(account); }); return 0; } - Expected + std::expected traceFloat(std::string_view const& msg, Slice const& data) const override { log(msg, [&data] { return wasm_float::floatToString(data); }); return 0; } - Expected + std::expected traceAmount(std::string_view const& msg, STAmount const& amount) const override { log(msg, [&amount] { return amount.getFullText(); }); return 0; } - Expected + std::expected floatFromInt(int64_t x, int32_t mode) const override { return wasm_float::floatFromIntImpl(x, mode); } - Expected + std::expected floatFromUint(uint64_t x, int32_t mode) const override { return wasm_float::floatFromUintImpl(x, mode); } - Expected + std::expected floatFromSTAmount(STAmount const& x, int32_t mode) const override { return wasm_float::floatFromSTAmountImpl(x, mode); } - Expected + std::expected floatFromSTNumber(STNumber const& x, int32_t mode) const override { return wasm_float::floatFromSTNumberImpl(x, mode); } - Expected + std::expected floatToInt(Slice const& x, int32_t mode) const override { return wasm_float::floatToIntImpl(x, mode); } - Expected + std::expected floatToMantExp(Slice const& x) const override { return wasm_float::floatToMantExpImpl(x); } - Expected + std::expected floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const override { return wasm_float::floatFromMantExpImpl(mantissa, exponent, mode); } - Expected + std::expected floatCompare(Slice const& x, Slice const& y) const override { return wasm_float::floatCompareImpl(x, y); } - Expected + std::expected floatAdd(Slice const& x, Slice const& y, int32_t mode) const override { return wasm_float::floatAddImpl(x, y, mode); } - Expected + std::expected floatSubtract(Slice const& x, Slice const& y, int32_t mode) const override { return wasm_float::floatSubtractImpl(x, y, mode); } - Expected + std::expected floatMultiply(Slice const& x, Slice const& y, int32_t mode) const override { return wasm_float::floatMultiplyImpl(x, y, mode); } - Expected + std::expected floatDivide(Slice const& x, Slice const& y, int32_t mode) const override { return wasm_float::floatDivideImpl(x, y, mode); } - Expected + std::expected floatRoot(Slice const& x, int32_t n, int32_t mode) const override { return wasm_float::floatRootImpl(x, n, mode); } - Expected + std::expected floatPower(Slice const& x, int32_t n, int32_t mode) const override { return wasm_float::floatPowerImpl(x, n, mode); diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 230494f498..48da0597f4 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -53,7 +52,7 @@ struct Wasm_test : public beast::unit_test::Suite { void checkResult( - Expected, WasmTER> re, + std::expected, WasmTER> re, int32_t expectedResult, int64_t expectedCost, std::source_location const location = std::source_location::current()) @@ -313,10 +312,10 @@ struct Wasm_test : public beast::unit_test::Suite explicit FieldNotFoundHostFunctions(Env& env) : TestHostFunctions(env) { } - Expected + std::expected getTxField(SField const& fname) const override { - return Unexpected(HostFunctionError::FieldNotFound); + return std::unexpected(HostFunctionError::FieldNotFound); } }; @@ -331,7 +330,7 @@ struct Wasm_test : public beast::unit_test::Suite explicit OversizedFieldHostFunctions(Env& env) : TestHostFunctions(env) { } - Expected + std::expected getTxField(SField const& fname) const override { return Bytes((128 + 1) * 64 * 1024, 1);