mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-19 21:30:56 +00:00
fix: Merge upstream branch
This commit is contained in:
@@ -394,11 +394,6 @@ host_functions! {
|
||||
#[wasm_name = "trace"]
|
||||
fn trace(&self, msg: &str, data: &[u8], data_type: TraceDataType) -> HostResult<()>;
|
||||
|
||||
/// Writes `msg` and `number` to the trace log.
|
||||
#[gas = 500]
|
||||
#[wasm_name = "trace_num"]
|
||||
fn trace_num(&self, msg: &str, number: i64) -> HostResult<()>;
|
||||
|
||||
/// Stores `data` as the current object's data field, replacing whatever was there,
|
||||
/// and returns the number of bytes stored. Reads the data region; `DataFieldTooLarge`
|
||||
/// if it exceeds the host's limit.
|
||||
|
||||
@@ -785,7 +785,6 @@ fn the_trait_is_implementable() {
|
||||
assert_eq!(host.sha512_half(b"abc", &mut out), Ok(HASH_LEN));
|
||||
assert_eq!(out[0], 3);
|
||||
assert_eq!(host.trace("hello", b"xy", TraceDataType::AsHex), Ok(()));
|
||||
assert_eq!(host.trace_num("count", -1), Ok(()));
|
||||
assert_eq!(host.update_data(b"abcd"), Ok(4));
|
||||
assert_eq!(host.get_nft(&[7; 20], &[9; 32], &mut out), Ok(HASH_LEN));
|
||||
assert_eq!(out[0], 7);
|
||||
@@ -930,7 +929,6 @@ fn the_spec_table_matches_the_declarations() {
|
||||
("vault_id", 350),
|
||||
("sha512_half", 2000),
|
||||
("trace", 30),
|
||||
("trace_num", 500),
|
||||
("set_data", 1000),
|
||||
("nft_uri", 5000),
|
||||
("nft_issuer", 70),
|
||||
|
||||
@@ -1183,28 +1183,11 @@ mod tests {
|
||||
assert_eq!(bytes_written(0), Ok(0));
|
||||
assert_eq!(bytes_written(-3), Err(HostError::BufferTooSmall));
|
||||
assert_eq!(bytes_written(-14), Err(HostError::NoMemExported));
|
||||
assert_eq!(reported(0), Ok(()));
|
||||
assert_eq!(reported(-14), Err(HostError::NoMemExported));
|
||||
assert_eq!(scalar(1), Ok(1));
|
||||
assert_eq!(scalar(0), Ok(0));
|
||||
assert_eq!(scalar(-2), Err(HostError::FieldNotFound));
|
||||
}
|
||||
|
||||
/// An exception caught on the C++ side arrives as `InternalFatal`, the code
|
||||
/// `HostContext` answers with when a body throws. The engine stops the run on it and
|
||||
/// the transaction is `tecINTERNAL`, rather than the contract being handed a code to
|
||||
/// interpret.
|
||||
///
|
||||
/// It arrives through the sign test like any other code, which is the point of
|
||||
/// choosing a negative sentinel: `usize::try_from` rejects it, so this needs no case
|
||||
/// of its own here and a positive length cannot be mistaken for it.
|
||||
#[test]
|
||||
fn a_caught_cxx_exception_arrives_as_internal() {
|
||||
assert_eq!(bytes_written(-1), Err(HostError::Internal));
|
||||
assert_eq!(reported(-1), Err(HostError::Internal));
|
||||
assert_eq!(scalar(-1), Err(HostError::Internal));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_caught_cxx_exception_arrives_as_internal_fatal() {
|
||||
assert_eq!(bytes_written(i32::MIN), Err(HostError::InternalFatal));
|
||||
|
||||
@@ -286,7 +286,7 @@ pub(crate) fn write_mant_exp(
|
||||
mantissa_out: Region,
|
||||
exponent_out: Region,
|
||||
call: impl FnOnce(&dyn HostFunctions, &[u8], &mut [u8], &mut [u8]) -> HostResult<usize>,
|
||||
) -> HostResult<i32> {
|
||||
) -> CallResult<i32> {
|
||||
let mem = memory(caller)?;
|
||||
let (data, state) = mem.data_and_store_mut(&mut *caller);
|
||||
let host: &dyn HostFunctions = state.host;
|
||||
@@ -306,7 +306,7 @@ pub(crate) fn write_mant_exp(
|
||||
.get_mut(mant_range)
|
||||
.ok_or(HostError::PointerOutOfBounds)?;
|
||||
if mant_dst.len() < MANTISSA_BYTES {
|
||||
return Err(HostError::BufferTooSmall);
|
||||
return Err(HostError::BufferTooSmall.into());
|
||||
}
|
||||
mant_dst[..MANTISSA_BYTES].copy_from_slice(&state.out_buffer[..MANTISSA_BYTES]);
|
||||
|
||||
@@ -315,7 +315,7 @@ pub(crate) fn write_mant_exp(
|
||||
.get_mut(exp_range)
|
||||
.ok_or(HostError::PointerOutOfBounds)?;
|
||||
if exp_dst.len() < EXPONENT_BYTES {
|
||||
return Err(HostError::BufferTooSmall);
|
||||
return Err(HostError::BufferTooSmall.into());
|
||||
}
|
||||
exp_dst[..EXPONENT_BYTES]
|
||||
.copy_from_slice(&state.out_buffer[MANTISSA_BYTES..MANTISSA_BYTES + EXPONENT_BYTES]);
|
||||
|
||||
@@ -87,7 +87,7 @@ pub(crate) fn register_host_functions(
|
||||
charged(&mut caller, HostFunctionSpec::IsAmendmentEnabled, |c| {
|
||||
let host = c.data().host;
|
||||
let amendment = read_borrowed(c, Region::new(ptr, len))?;
|
||||
host.is_amendment_enabled(amendment)
|
||||
Ok(host.is_amendment_enabled(amendment)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -102,7 +102,7 @@ pub(crate) fn register_host_functions(
|
||||
charged(&mut caller, HostFunctionSpec::CacheLedgerObj, |c| {
|
||||
let host = c.data().host;
|
||||
let obj_id = read_borrowed(c, Region::new(id_ptr, id_len))?;
|
||||
host.cache_ledger_obj(obj_id, cache_idx)
|
||||
Ok(host.cache_ledger_obj(obj_id, cache_idx)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -229,7 +229,7 @@ pub(crate) fn register_host_functions(
|
||||
op.wasm_name(),
|
||||
|mut caller: Caller<'_, VmState<'_>>, field: i32| -> Result<i32, wasmi::Error> {
|
||||
charged(&mut caller, HostFunctionSpec::GetTxArrayLen, |c| {
|
||||
c.data().host.get_tx_array_len(field)
|
||||
Ok(c.data().host.get_tx_array_len(field)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -240,7 +240,7 @@ pub(crate) fn register_host_functions(
|
||||
charged(
|
||||
&mut caller,
|
||||
HostFunctionSpec::GetCurrentLedgerObjArrayLen,
|
||||
|c| c.data().host.get_current_ledger_obj_array_len(field),
|
||||
|c| Ok(c.data().host.get_current_ledger_obj_array_len(field)?),
|
||||
)
|
||||
},
|
||||
),
|
||||
@@ -252,7 +252,7 @@ pub(crate) fn register_host_functions(
|
||||
field: i32|
|
||||
-> Result<i32, wasmi::Error> {
|
||||
charged(&mut caller, HostFunctionSpec::GetLedgerObjArrayLen, |c| {
|
||||
c.data().host.get_ledger_obj_array_len(cache_idx, field)
|
||||
Ok(c.data().host.get_ledger_obj_array_len(cache_idx, field)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -266,7 +266,7 @@ pub(crate) fn register_host_functions(
|
||||
charged(&mut caller, HostFunctionSpec::GetTxNestedArrayLen, |c| {
|
||||
let host = c.data().host;
|
||||
let locator = read_borrowed(c, Region::new(loc_ptr, loc_len))?;
|
||||
host.get_tx_nested_array_len(locator)
|
||||
Ok(host.get_tx_nested_array_len(locator)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -283,7 +283,7 @@ pub(crate) fn register_host_functions(
|
||||
|c| {
|
||||
let host = c.data().host;
|
||||
let locator = read_borrowed(c, Region::new(loc_ptr, loc_len))?;
|
||||
host.get_current_ledger_obj_nested_array_len(locator)
|
||||
Ok(host.get_current_ledger_obj_nested_array_len(locator)?)
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -302,7 +302,7 @@ pub(crate) fn register_host_functions(
|
||||
|c| {
|
||||
let host = c.data().host;
|
||||
let locator = read_borrowed(c, Region::new(loc_ptr, loc_len))?;
|
||||
host.get_ledger_obj_nested_array_len(cache_idx, locator)
|
||||
Ok(host.get_ledger_obj_nested_array_len(cache_idx, locator)?)
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -323,7 +323,7 @@ pub(crate) fn register_host_functions(
|
||||
let message = read_borrowed(c, Region::new(msg_ptr, msg_len))?;
|
||||
let signature = read_borrowed(c, Region::new(sig_ptr, sig_len))?;
|
||||
let pubkey = read_borrowed(c, Region::new(pk_ptr, pk_len))?;
|
||||
host.check_signature(message, signature, pubkey)
|
||||
Ok(host.check_signature(message, signature, pubkey)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -827,7 +827,7 @@ pub(crate) fn register_host_functions(
|
||||
charged(&mut caller, HostFunctionSpec::UpdateData, |c| {
|
||||
let host = c.data().host;
|
||||
let data = read_borrowed(c, Region::new(ptr, len))?;
|
||||
host.update_data(data)
|
||||
Ok(host.update_data(data)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -898,7 +898,7 @@ pub(crate) fn register_host_functions(
|
||||
charged(&mut caller, HostFunctionSpec::GetNftFlags, |c| {
|
||||
let host = c.data().host;
|
||||
let nft_id = read_borrowed(c, Region::new(nft_ptr, nft_len))?;
|
||||
host.get_nft_flags(nft_id)
|
||||
Ok(host.get_nft_flags(nft_id)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -912,7 +912,7 @@ pub(crate) fn register_host_functions(
|
||||
charged(&mut caller, HostFunctionSpec::GetNftTransferFee, |c| {
|
||||
let host = c.data().host;
|
||||
let nft_id = read_borrowed(c, Region::new(nft_ptr, nft_len))?;
|
||||
host.get_nft_transfer_fee(nft_id)
|
||||
Ok(host.get_nft_transfer_fee(nft_id)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
@@ -1077,7 +1077,7 @@ pub(crate) fn register_host_functions(
|
||||
let host = c.data().host;
|
||||
let x = read_borrowed(c, Region::new(x_ptr, x_len))?;
|
||||
let y = read_borrowed(c, Region::new(y_ptr, y_len))?;
|
||||
host.float_compare(x, y)
|
||||
Ok(host.float_compare(x, y)?)
|
||||
})
|
||||
},
|
||||
),
|
||||
|
||||
@@ -74,8 +74,8 @@ public:
|
||||
* their location in the parsed document. An empty string is returned if no
|
||||
* error occurred during parsing.
|
||||
*/
|
||||
static [[nodiscard]] std::string
|
||||
getFormattedErrorMessages();
|
||||
[[nodiscard]] std::string
|
||||
getFormattedErrorMessages() const;
|
||||
|
||||
static constexpr unsigned kNestLimit{25};
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
namespace json {
|
||||
// Implementation of class Reader
|
||||
@@ -77,7 +78,7 @@ Reader::parse(std::istream& sin, Value& root)
|
||||
|
||||
// Since std::string is reference-counted, this at least does not
|
||||
// create an extra copy.
|
||||
std::string const doc;
|
||||
std::string doc;
|
||||
std::getline(sin, doc, (char)EOF);
|
||||
return parse(doc, root);
|
||||
}
|
||||
@@ -612,7 +613,7 @@ Reader::decodeDouble(Token& token)
|
||||
return addError("Unable to parse token length", token);
|
||||
}
|
||||
|
||||
double const value = 0;
|
||||
double value = 0;
|
||||
auto const [ptr, ec] = fast_float::from_chars(token.start, token.end, value);
|
||||
|
||||
// Reject anything from_chars could not turn into a finite double:
|
||||
@@ -895,7 +896,7 @@ Reader::getLocationLineAndColumn(Location location) const
|
||||
}
|
||||
|
||||
std::string
|
||||
Reader::getFormattedErrorMessages()
|
||||
Reader::getFormattedErrorMessages() const
|
||||
{
|
||||
std::string formattedMessage;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user