fix build issues

This commit is contained in:
Mayukha Vadari
2026-07-20 18:07:42 -04:00
parent 9801c23bad
commit c634c75aee
20 changed files with 639 additions and 645 deletions

View File

@@ -347,7 +347,7 @@ concept Integral64 = std::is_same_v<T, std::int64_t> || std::is_same_v<T, std::u
* (SingleAssetVault and LendingProtocol), and/or check if either of those
* amendments are enabled to determine which result to expect.
*/
class Number final
class Number
{
using rep = std::int64_t;
using internalrep = MantissaRange::rep;

View File

@@ -1,6 +1,5 @@
#pragma once
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/protocol/AccountID.h>
@@ -20,46 +19,46 @@ namespace wasm_float {
std::string
floatToString(Slice const& data);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromIntImpl(int64_t x, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromUintImpl(uint64_t x, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromSTAmountImpl(STAmount const& x, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromSTNumberImpl(STNumber const& x, int32_t mode);
Expected<int64_t, HostFunctionError>
std::expected<int64_t, HostFunctionError>
floatToIntImpl(Slice const& x, int32_t mode);
Expected<FloatPair, HostFunctionError>
std::expected<FloatPair, HostFunctionError>
floatToMantExpImpl(Slice const& x);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromMantExpImpl(int64_t mantissa, int32_t exponent, int32_t mode);
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
floatCompareImpl(Slice const& x, Slice const& y);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatAddImpl(Slice const& x, Slice const& y, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatSubtractImpl(Slice const& x, Slice const& y, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatMultiplyImpl(Slice const& x, Slice const& y, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatDivideImpl(Slice const& x, Slice const& y, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatRootImpl(Slice const& x, int32_t n, int32_t mode);
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatPowerImpl(Slice const& x, int32_t n, int32_t mode);
} // namespace wasm_float
@@ -110,401 +109,403 @@ public:
return true;
}
virtual Expected<std::uint32_t, HostFunctionError>
virtual std::expected<std::uint32_t, HostFunctionError>
getLedgerSqn() const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<std::uint32_t, HostFunctionError>
virtual std::expected<std::uint32_t, HostFunctionError>
getParentLedgerTime() const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Hash, HostFunctionError>
virtual std::expected<Hash, HostFunctionError>
getParentLedgerHash() const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<uint32_t, HostFunctionError>
virtual std::expected<uint32_t, HostFunctionError>
getBaseFee() const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
isAmendmentEnabled(uint256 const& amendmentId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
isAmendmentEnabled(std::string_view const& amendmentName) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
cacheLedgerObj(uint256 const& objId, int32_t cacheIdx)
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getTxField(SField const& fname) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getCurrentLedgerObjField(SField const& fname) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getLedgerObjField(int32_t cacheIdx, SField const& fname) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getTxNestedField(FieldLocator const& locator) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getCurrentLedgerObjNestedField(FieldLocator const& locator) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getLedgerObjNestedField(int32_t cacheIdx, FieldLocator const& locator) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getTxArrayLen(SField const& fname) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getCurrentLedgerObjArrayLen(SField const& fname) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getTxNestedArrayLen(FieldLocator const& locator) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getCurrentLedgerObjNestedArrayLen(FieldLocator const& locator) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getLedgerObjNestedArrayLen(int32_t cacheIdx, FieldLocator const& locator) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
updateData(Slice const& data)
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Hash, HostFunctionError>
virtual std::expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
accountKeylet(AccountID const& account) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
ammKeylet(Asset const& issue1, Asset const& issue2) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
checkKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType)
const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
didKeylet(AccountID const& account) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
delegateKeylet(AccountID const& account, AccountID const& authorize) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
escrowKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) const
virtual std::expected<Bytes, HostFunctionError>
trustLineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency)
const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const
virtual std::expected<Bytes, HostFunctionError>
mptokenIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
mptokenKeylet(MPTID const& mptid, AccountID const& holder) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
nftOfferKeylet(AccountID const& account, std::uint32_t seq) const
virtual std::expected<Bytes, HostFunctionError>
nftokenOfferKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
offerKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
oracleKeylet(AccountID const& account, std::uint32_t docId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) const
virtual std::expected<Bytes, HostFunctionError>
paychannelKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq)
const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
signersKeylet(AccountID const& account) const
virtual std::expected<Bytes, HostFunctionError>
signerListKeylet(AccountID const& account) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
ticketKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
vaultKeylet(AccountID const& account, std::uint32_t seq) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getNFT(AccountID const& account, uint256 const& nftId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<std::uint32_t, HostFunctionError>
virtual std::expected<std::uint32_t, HostFunctionError>
getNFTTaxon(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getNFTFlags(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
getNFTTransferFee(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<std::uint32_t, HostFunctionError>
getNFTSerial(uint256 const& nftId) const
virtual std::expected<std::uint32_t, HostFunctionError>
getNFTSequence(uint256 const& nftId) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
trace(std::string_view const& msg, Slice const& data, bool asHex) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
traceNum(std::string_view const& msg, int64_t data) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
traceAccount(std::string_view const& msg, AccountID const& account) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
traceFloat(std::string_view const& msg, Slice const& data) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
traceAmount(std::string_view const& msg, STAmount const& amount) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatFromInt(int64_t x, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatFromUint(uint64_t x, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatFromSTAmount(STAmount const& x, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatFromSTNumber(STNumber const& x, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int64_t, HostFunctionError>
virtual std::expected<int64_t, HostFunctionError>
floatToInt(Slice const& x, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<FloatPair, HostFunctionError>
virtual std::expected<FloatPair, HostFunctionError>
floatToMantExp(Slice const& x) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<int32_t, HostFunctionError>
virtual std::expected<int32_t, HostFunctionError>
floatCompare(Slice const& x, Slice const& y) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatAdd(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatSubtract(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatMultiply(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatDivide(Slice const& x, Slice const& y, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatRoot(Slice const& x, int32_t n, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual Expected<Bytes, HostFunctionError>
virtual std::expected<Bytes, HostFunctionError>
floatPower(Slice const& x, int32_t n, int32_t mode) const
{
return Unexpected(HostFunctionError::Unimplemented);
return std::unexpected(HostFunctionError::Unimplemented);
}
virtual ~HostFunctions() = default;

View File

@@ -19,24 +19,24 @@ class WasmHostFunctionsImpl : public HostFunctions
std::optional<Bytes> data_;
public:
Expected<std::shared_ptr<SLE const>, HostFunctionError>
std::expected<std::shared_ptr<SLE const>, HostFunctionError>
getCurrentLedgerObj() const
{
if (!currentLedgerObj_)
currentLedgerObj_ = ctx_.view().read(leKey_);
if (*currentLedgerObj_)
return *currentLedgerObj_;
return Unexpected(HostFunctionError::LedgerObjNotFound);
return std::unexpected(HostFunctionError::LedgerObjNotFound);
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getLedgerSqn() const override;
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getParentLedgerTime() const override;
Expected<Hash, HostFunctionError>
std::expected<Hash, HostFunctionError>
getParentLedgerHash() const override;
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getBaseFee() const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
isAmendmentEnabled(uint256 const& amendmentId) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
isAmendmentEnabled(std::string_view const& amendmentName) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getTxField(SField const& fname) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getCurrentLedgerObjField(SField const& fname) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getLedgerObjField(int32_t cacheIdx, SField const& fname) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getTxNestedField(FieldLocator const& locator) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getCurrentLedgerObjNestedField(FieldLocator const& locator) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getLedgerObjNestedField(int32_t cacheIdx, FieldLocator const& locator) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getTxArrayLen(SField const& fname) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getCurrentLedgerObjArrayLen(SField const& fname) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getTxNestedArrayLen(FieldLocator const& locator) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getCurrentLedgerObjNestedArrayLen(FieldLocator const& locator) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getLedgerObjNestedArrayLen(int32_t cacheIdx, FieldLocator const& locator) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
updateData(Slice const& data) override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey)
const override;
Expected<Hash, HostFunctionError>
std::expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
accountKeylet(AccountID const& account) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
ammKeylet(Asset const& issue1, Asset const& issue2) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
checkKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType)
const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
didKeylet(AccountID const& account) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
delegateKeylet(AccountID const& account, AccountID const& authorize) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
depositPreauthKeylet(AccountID const& account, AccountID const& authorize) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
escrowKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency)
std::expected<Bytes, HostFunctionError>
trustLineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency)
const override;
Expected<Bytes, HostFunctionError>
mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const override;
std::expected<Bytes, HostFunctionError>
mptokenIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
mptokenKeylet(MPTID const& mptid, AccountID const& holder) const override;
Expected<Bytes, HostFunctionError>
nftOfferKeylet(AccountID const& account, std::uint32_t seq) const override;
std::expected<Bytes, HostFunctionError>
nftokenOfferKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
offerKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
oracleKeylet(AccountID const& account, std::uint32_t docId) const override;
Expected<Bytes, HostFunctionError>
paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq)
std::expected<Bytes, HostFunctionError>
paychannelKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq)
const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
signersKeylet(AccountID const& account) const override;
std::expected<Bytes, HostFunctionError>
signerListKeylet(AccountID const& account) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
ticketKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
vaultKeylet(AccountID const& account, std::uint32_t seq) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getNFT(AccountID const& account, uint256 const& nftId) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId) const override;
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getNFTTaxon(uint256 const& nftId) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getNFTFlags(uint256 const& nftId) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getNFTTransferFee(uint256 const& nftId) const override;
Expected<std::uint32_t, HostFunctionError>
getNFTSerial(uint256 const& nftId) const override;
std::expected<std::uint32_t, HostFunctionError>
getNFTSequence(uint256 const& nftId) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
trace(std::string_view const& msg, Slice const& data, bool asHex) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceNum(std::string_view const& msg, int64_t data) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceAccount(std::string_view const& msg, AccountID const& account) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceFloat(std::string_view const& msg, Slice const& data) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceAmount(std::string_view const& msg, STAmount const& amount) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromInt(int64_t x, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromUint(uint64_t x, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromSTAmount(STAmount const& x, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromSTNumber(STNumber const& x, int32_t mode) const override;
Expected<int64_t, HostFunctionError>
std::expected<int64_t, HostFunctionError>
floatToInt(Slice const& x, int32_t mode) const override;
Expected<FloatPair, HostFunctionError>
std::expected<FloatPair, HostFunctionError>
floatToMantExp(Slice const& x) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const override;
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
floatCompare(Slice const& x, Slice const& y) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatAdd(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatSubtract(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatMultiply(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatDivide(Slice const& x, Slice const& y, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatRoot(Slice const& x, int32_t n, int32_t mode) const override;
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatPower(Slice const& x, int32_t n, int32_t mode) const override;
};

View File

@@ -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);

View File

@@ -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<T, HostFunctionError>`.
`std::expected<T, HostFunctionError>`.
- **`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<ReturnType, HostFunctionError>
virtual std::expected<ReturnType, HostFunctionError>
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<ReturnType, HostFunctionError>
std::expected<ReturnType, HostFunctionError>
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<ReturnType, HostFunctionError>
std::expected<ReturnType, HostFunctionError>
WasmHostFunctionsImpl::myNewFunction(ParamType1 param1, ParamType2 param2)
{
// Implementation using ctx (ApplyContext) for ledger access

View File

@@ -40,7 +40,7 @@ public:
static WasmEngine&
instance();
Expected<WasmResult<int32_t>, WasmTER>
std::expected<WasmResult<int32_t>, WasmTER>
run(Bytes const& wasmCode,
HostFunctions& hfs,
int64_t gasLimit,
@@ -71,7 +71,7 @@ public:
ImportVec
createWasmImport(HostFunctions& hfs);
Expected<EscrowResult, WasmTER>
std::expected<EscrowResult, WasmTER>
runEscrowWasm(
Bytes const& wasmCode,
HostFunctions& hfs,

View File

@@ -309,7 +309,7 @@ public:
static EnginePtr
init();
Expected<WasmResult<int32_t>, WasmTER>
std::expected<WasmResult<int32_t>, WasmTER>
run(Bytes const& wasmCode,
HostFunctions& hfs,
int64_t gas,
@@ -360,7 +360,7 @@ private:
return moduleWrap_ ? moduleWrap_->getMem() : Wmem();
}
Expected<WasmResult<int32_t>, WasmTER>
std::expected<WasmResult<int32_t>, WasmTER>
runHlp(
Bytes const& wasmCode,
HostFunctions& hfs,

View File

@@ -1,6 +1,5 @@
#include <xrpl/tx/wasm/HostFuncImpl.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/PublicKey.h>
@@ -15,11 +14,11 @@ namespace xrpl {
// SECTION: WRITE FUNCTION
// =========================================================
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<Hash, HostFunctionError>
std::expected<Hash, HostFunctionError>
WasmHostFunctionsImpl::computeSha512HalfHash(Slice const& data) const
{
auto const hash = sha512Half(data);

View File

@@ -1,4 +1,3 @@
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Number.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/protocol/SField.h>
@@ -92,7 +91,7 @@ public:
return Number::operator int64_t();
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>(std::move(data));
return std::expected<Bytes, HostFunctionError>(std::move(data));
}
};
@@ -155,164 +154,164 @@ floatToString(Slice const& data)
return s;
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Number>(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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<int64_t, HostFunctionError>
std::expected<int64_t, HostFunctionError>
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<FloatPair, HostFunctionError>
std::expected<FloatPair, HostFunctionError>
floatToMantExpImpl(Slice const& x)
{
try
{
detail::FloatState const rm(static_cast<int32_t>(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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatFromInt(int64_t x, int32_t mode) const
{
return wasm_float::floatFromIntImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatFromUint(uint64_t x, int32_t mode) const
{
return wasm_float::floatFromUintImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatFromSTAmount(STAmount const& x, int32_t mode) const
{
return wasm_float::floatFromSTAmountImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatFromSTNumber(STNumber const& x, int32_t mode) const
{
return wasm_float::floatFromSTNumberImpl(x, mode);
}
Expected<int64_t, HostFunctionError>
std::expected<int64_t, HostFunctionError>
WasmHostFunctionsImpl::floatToInt(Slice const& x, int32_t mode) const
{
return wasm_float::floatToIntImpl(x, mode);
}
Expected<FloatPair, HostFunctionError>
std::expected<FloatPair, HostFunctionError>
WasmHostFunctionsImpl::floatToMantExp(Slice const& x) const
{
return wasm_float::floatToMantExpImpl(x);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const
{
return wasm_float::floatFromMantExpImpl(mantissa, exponent, mode);
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::floatCompare(Slice const& x, Slice const& y) const
{
return wasm_float::floatCompareImpl(x, y);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatAdd(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatAddImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatSubtract(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatSubtractImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatMultiply(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatMultiplyImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatDivide(Slice const& x, Slice const& y, int32_t mode) const
{
return wasm_float::floatDivideImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatRoot(Slice const& x, int32_t n, int32_t mode) const
{
return wasm_float::floatRootImpl(x, n, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::floatPower(Slice const& x, int32_t n, int32_t mode) const
{
return wasm_float::floatPowerImpl(x, n, mode);

View File

@@ -1,4 +1,3 @@
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/basics/contract.h>
#include <xrpl/beast/utility/instrumentation.h>
@@ -36,11 +35,11 @@ getIntBytes(STBase const* obj)
return Bytes{b, b + sizeof(T)};
}
static Expected<Bytes, HostFunctionError>
static std::expected<Bytes, HostFunctionError>
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<STAccount const*>(obj)); // NOLINT
@@ -115,7 +114,7 @@ getAnyFieldData(STBase const* obj)
return msg.getData();
}
static Expected<Bytes, HostFunctionError>
static std::expected<Bytes, HostFunctionError>
getAnyFieldData(FieldValue const& variantObj)
{
if (STBase const* const* obj = std::get_if<STBase const*>(&variantObj))
@@ -136,7 +135,7 @@ noField(STBase const* field)
(STI_UNKNOWN == field->getSType());
}
static Expected<FieldValue, HostFunctionError>
static std::expected<FieldValue, HostFunctionError>
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<STArray const*>(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<STVector256 const*>(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<int32_t, HostFunctionError>
static inline std::expected<int32_t, HostFunctionError>
getArrayLen(FieldValue const& variantField)
{
if (STBase const* const* field = std::get_if<STBase const*>(&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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
WasmHostFunctionsImpl::getTxField(SField const& fname) const
{
return getAnyFieldData(ctx_.tx.peekAtPField(fname));
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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);

View File

@@ -1,4 +1,3 @@
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
@@ -13,208 +12,208 @@
namespace xrpl {
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<MPTIssue>() || issue2.holds<MPTIssue>())
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
WasmHostFunctionsImpl::lineKeylet(
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
WasmHostFunctionsImpl::mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
WasmHostFunctionsImpl::nftOfferKeylet(AccountID const& account, std::uint32_t seq) const
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
WasmHostFunctionsImpl::paychanKeylet(
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
WasmHostFunctionsImpl::signersKeylet(AccountID const& account) const
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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()};
}

View File

@@ -1,4 +1,3 @@
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/ledger/AmendmentTable.h>
#include <xrpl/tx/wasm/HostFuncImpl.h>
@@ -14,37 +13,37 @@ namespace xrpl {
// SECTION: LEDGER HEADER FUNCTIONS
// =========================================================
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getLedgerSqn() const
{
return ctx_.view().seq();
}
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getParentLedgerTime() const
{
return ctx_.view().parentCloseTime().time_since_epoch().count();
}
Expected<Hash, HostFunctionError>
std::expected<Hash, HostFunctionError>
WasmHostFunctionsImpl::getParentLedgerHash() const
{
return ctx_.view().header().parentHash;
}
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getBaseFee() const
{
return ctx_.view().fees().base.drops();
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::isAmendmentEnabled(uint256 const& amendmentId) const
{
return ctx_.view().rules().enabled(amendmentId);
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::isAmendmentEnabled(std::string_view const& amendmentName) const
{
auto const& table = ctx_.registry.get().getAmendmentTable();

View File

@@ -1,4 +1,3 @@
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/ledger/helpers/NFTokenHelpers.h>
@@ -16,59 +15,59 @@ namespace xrpl {
// SECTION: NFT UTILS
// =========================================================
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTTaxon(uint256 const& nftId) const
{
return nft::toUInt32(nft::getTaxon(nftId));
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTFlags(uint256 const& nftId) const
{
return nft::getFlags(nftId);
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTTransferFee(uint256 const& nftId) const
{
return nft::getTransferFee(nftId);
}
Expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTSerial(uint256 const& nftId) const
std::expected<std::uint32_t, HostFunctionError>
WasmHostFunctionsImpl::getNFTSequence(uint256 const& nftId) const
{
return nft::getSerial(nftId);
return nft::getSequence(nftId);
}
} // namespace xrpl

View File

@@ -1,4 +1,3 @@
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/STAmount.h>
@@ -18,7 +17,7 @@
namespace xrpl {
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceNum(std::string_view const& msg, int64_t data) const
{
log(msg, [data] { return data; });
return 0;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceAccount(std::string_view const& msg, AccountID const& account) const
{
log(msg, [&account] { return toBase58(account); });
return 0;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceFloat(std::string_view const& msg, Slice const& data) const
{
log(msg, [&data] { return wasm_float::floatToString(data); });
return 0;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
WasmHostFunctionsImpl::traceAmount(std::string_view const& msg, STAmount const& amount) const
{
log(msg, [&amount] { return amount.getFullText(); });

View File

@@ -1,6 +1,5 @@
#include <xrpl/tx/wasm/HostFuncWrapper.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Slice.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/basics/contract.h>
@@ -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<std::int64_t, HostFunctionError>
static inline std::expected<std::int64_t, HostFunctionError>
checkTransfer(WasmRuntimeWrapper& rt, int64_t delta)
{
auto const transLimit = rt.getTransferLimit();
@@ -79,7 +78,7 @@ checkTransfer(WasmRuntimeWrapper& rt, int64_t delta)
Throw<std::runtime_error>(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<Slice, HostFunctionError>
static std::expected<Slice, HostFunctionError>
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<int32_t, HostFunctionError>
static std::expected<int32_t, HostFunctionError>
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<int64_t, HostFunctionError>
static std::expected<int64_t, HostFunctionError>
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 <class T>
static Expected<T, HostFunctionError>
static std::expected<T, HostFunctionError>
getDataUnsigned(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i)
{
static_assert(std::is_unsigned_v<T>);
auto const r = getDataSlice(runtime, params, i);
if (!r)
return Unexpected(r.error());
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<uintptr_t>(r->data());
@@ -217,89 +216,89 @@ getDataUnsigned(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32
return x;
}
static Expected<uint32_t, HostFunctionError>
static std::expected<uint32_t, HostFunctionError>
getDataUInt32(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i)
{
return getDataUnsigned<uint32_t>(runtime, params, i);
}
static Expected<uint64_t, HostFunctionError>
static std::expected<uint64_t, HostFunctionError>
getDataUInt64(WasmRuntimeWrapper& runtime, wasm_val_vec_t const* params, int32_t& i)
{
return getDataUnsigned<uint64_t>(runtime, params, i);
}
static Expected<SFieldCRef, HostFunctionError>
static std::expected<SFieldCRef, HostFunctionError>
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<uint256, HostFunctionError>
static std::expected<uint256, HostFunctionError>
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<AccountID, HostFunctionError>
static std::expected<AccountID, HostFunctionError>
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<Currency, HostFunctionError>
static std::expected<Currency, HostFunctionError>
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<Asset, HostFunctionError>
static std::expected<Asset, HostFunctionError>
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<std::string_view, HostFunctionError>
static std::expected<std::string_view, HostFunctionError>
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<char const*>(slice->data()), slice->size());
}
static Expected<FieldLocator, HostFunctionError>
static std::expected<FieldLocator, HostFunctionError>
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<uintptr_t>(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<int32_t> 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<T, HostFunctionError> const& res,
std::expected<T, HostFunctionError> 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<STAmount> 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<STAmount> 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<STNumber> num;
try
{
num = STNumber(serialIter, kSfGeneric);
num = STNumber(serialIter, sfGeneric);
}
catch (std::exception const&)
{

View File

@@ -1,6 +1,5 @@
#include <xrpl/tx/wasm/WasmVM.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/tx/wasm/HostFuncWrapper.h> // 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<EscrowResult, WasmTER>
std::expected<EscrowResult, WasmTER>
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<WasmResult<int32_t>, WasmTER>
std::expected<WasmResult<int32_t>, WasmTER>
WasmEngine::run(
Bytes const& wasmCode,
HostFunctions& hfs,

View File

@@ -1,6 +1,5 @@
#include <xrpl/tx/wasm/WasmiVM.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/contract.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/protocol/TER.h>
@@ -757,7 +756,7 @@ checkImports(ImportVec const& imports, HostFunctions* hfs)
}
}
Expected<WasmResult<int32_t>, WasmTER>
std::expected<WasmResult<int32_t>, 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<WasmResult<int32_t>, WasmTER>
std::expected<WasmResult<int32_t>, 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())

View File

@@ -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<int32_t>(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);

View File

@@ -29,7 +29,7 @@ public:
{
}
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getLedgerSqn() const override
{
return env_.current()->seq();
@@ -51,49 +51,49 @@ public:
data_ = Bytes{t.begin(), t.end()};
}
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getLedgerSqn() const override
{
return 12345;
}
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getParentLedgerTime() const override
{
return 67890;
}
Expected<Hash, HostFunctionError>
std::expected<Hash, HostFunctionError>
getParentLedgerHash() const override
{
return env_.current()->header().parentHash;
}
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getBaseFee() const override
{
return 10;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
isAmendmentEnabled(uint256 const& amendmentId) const override
{
return 1;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
isAmendmentEnabled(std::string_view const& amendmentName) const override
{
return 1;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) override
{
return 1;
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<uint8_t const*>(&data);
auto const* e = reinterpret_cast<uint8_t const*>(&data + 1);
@@ -120,7 +120,7 @@ public:
return Bytes();
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getLedgerObjField(int32_t, SField const& fname) const override
{
if (fname == sfBalance)
@@ -154,7 +154,7 @@ public:
return data_;
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getTxNestedField(FieldLocator const& locator) const override
{
if (locator.size() == 1)
@@ -171,7 +171,7 @@ public:
return Bytes(&a[0], &a[sizeof(a)]);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getCurrentLedgerObjNestedField(FieldLocator const& locator) const override
{
if (locator.size() == 1)
@@ -188,7 +188,7 @@ public:
return Bytes(&a[0], &a[sizeof(a)]);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getTxArrayLen(SField const& fname) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getCurrentLedgerObjArrayLen(SField const& fname) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getTxNestedArrayLen(FieldLocator const& locator) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getCurrentLedgerObjNestedArrayLen(FieldLocator const& locator) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getLedgerObjNestedArrayLen(int32_t cacheIdx, FieldLocator const& locator) const override
{
return 32;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
updateData(Slice const& data) override
{
return data.size();
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) const override
{
return 1;
}
Expected<Hash, HostFunctionError>
std::expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data) const override
{
return env_.current()->header().parentHash;
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
ammKeylet(Asset const& issue1, Asset const& issue2) const override
{
if (issue1 == issue2)
return Unexpected(HostFunctionError::InvalidParams);
return std::unexpected(HostFunctionError::InvalidParams);
if (issue1.holds<MPTIssue>() || issue2.holds<MPTIssue>())
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId) const override
{
return Bytes(accountID_.begin(), accountID_.end());
}
Expected<std::uint32_t, HostFunctionError>
std::expected<std::uint32_t, HostFunctionError>
getNFTTaxon(uint256 const& nftId) const override
{
return 4;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getNFTFlags(uint256 const& nftId) const override
{
return 8;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
getNFTTransferFee(uint256 const& nftId) const override
{
return 10;
}
Expected<std::uint32_t, HostFunctionError>
getNFTSerial(uint256 const& nftId) const override
std::expected<std::uint32_t, HostFunctionError>
getNFTSequence(uint256 const& nftId) const override
{
return 4;
}
@@ -375,7 +375,7 @@ public:
#endif
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
trace(std::string_view const& msg, Slice const& data, bool asHex) const override
{
if (!asHex)
@@ -397,113 +397,113 @@ public:
return 0;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceNum(std::string_view const& msg, int64_t data) const override
{
log(msg, [data] { return data; });
return 0;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceAccount(std::string_view const& msg, AccountID const& account) const override
{
log(msg, [&account] { return toBase58(account); });
return 0;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceFloat(std::string_view const& msg, Slice const& data) const override
{
log(msg, [&data] { return wasm_float::floatToString(data); });
return 0;
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
traceAmount(std::string_view const& msg, STAmount const& amount) const override
{
log(msg, [&amount] { return amount.getFullText(); });
return 0;
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromInt(int64_t x, int32_t mode) const override
{
return wasm_float::floatFromIntImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromUint(uint64_t x, int32_t mode) const override
{
return wasm_float::floatFromUintImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromSTAmount(STAmount const& x, int32_t mode) const override
{
return wasm_float::floatFromSTAmountImpl(x, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromSTNumber(STNumber const& x, int32_t mode) const override
{
return wasm_float::floatFromSTNumberImpl(x, mode);
}
Expected<int64_t, HostFunctionError>
std::expected<int64_t, HostFunctionError>
floatToInt(Slice const& x, int32_t mode) const override
{
return wasm_float::floatToIntImpl(x, mode);
}
Expected<FloatPair, HostFunctionError>
std::expected<FloatPair, HostFunctionError>
floatToMantExp(Slice const& x) const override
{
return wasm_float::floatToMantExpImpl(x);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatFromMantExp(int64_t mantissa, int32_t exponent, int32_t mode) const override
{
return wasm_float::floatFromMantExpImpl(mantissa, exponent, mode);
}
Expected<int32_t, HostFunctionError>
std::expected<int32_t, HostFunctionError>
floatCompare(Slice const& x, Slice const& y) const override
{
return wasm_float::floatCompareImpl(x, y);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatAdd(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatAddImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatSubtract(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatSubtractImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatMultiply(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatMultiplyImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatDivide(Slice const& x, Slice const& y, int32_t mode) const override
{
return wasm_float::floatDivideImpl(x, y, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatRoot(Slice const& x, int32_t n, int32_t mode) const override
{
return wasm_float::floatRootImpl(x, n, mode);
}
Expected<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
floatPower(Slice const& x, int32_t n, int32_t mode) const override
{
return wasm_float::floatPowerImpl(x, n, mode);

View File

@@ -6,7 +6,6 @@
#include <test/app/wasm_fixtures/fixtures.h>
#include <test/jtx/Env.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/beast/unit_test/suite.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/TER.h>
@@ -53,7 +52,7 @@ struct Wasm_test : public beast::unit_test::Suite
{
void
checkResult(
Expected<WasmResult<int32_t>, WasmTER> re,
std::expected<WasmResult<int32_t>, 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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
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<Bytes, HostFunctionError>
std::expected<Bytes, HostFunctionError>
getTxField(SField const& fname) const override
{
return Bytes((128 + 1) * 64 * 1024, 1);