mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
fix: make host function traces easier to use, fix get_NFT bug (#5466)
Co-authored-by: Olek <115580134+oleks-rip@users.noreply.github.com>
This commit is contained in:
@@ -93,11 +93,17 @@ wamr_log_to_rippled(
|
|||||||
{
|
{
|
||||||
beast::Journal j = WasmEngine::instance().getJournal();
|
beast::Journal j = WasmEngine::instance().getJournal();
|
||||||
|
|
||||||
// Format the variadic args
|
|
||||||
char const* safeFile = file ? file : "<null>";
|
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "WAMR (" << safeFile << ":" << line << "): ";
|
|
||||||
|
// Format the variadic args
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
oss << "WAMR (" << file << ":" << line << "): ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oss << "WAMR: ";
|
||||||
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -114,7 +120,6 @@ wamr_log_to_rippled(
|
|||||||
#ifdef DEBUG_OUTPUT_WAMR
|
#ifdef DEBUG_OUTPUT_WAMR
|
||||||
std::cerr << oss.str() << std::endl;
|
std::cerr << oss.str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -544,9 +549,8 @@ ModuleWrapper::buildImports(
|
|||||||
if (impCnt != importTypes.num_elems)
|
if (impCnt != importTypes.num_elems)
|
||||||
{
|
{
|
||||||
print_wasm_error(
|
print_wasm_error(
|
||||||
std::string("Imports not finished: ") +
|
std::string("Imports not finished: ") + std::to_string(impCnt) +
|
||||||
std::to_string(wimports.num_elems) + "/" +
|
"/" + std::to_string(importTypes.num_elems),
|
||||||
std::to_string(importTypes.num_elems),
|
|
||||||
nullptr,
|
nullptr,
|
||||||
j_);
|
j_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -455,11 +455,17 @@ Expected<Bytes, int32_t>
|
|||||||
WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId)
|
WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId)
|
||||||
{
|
{
|
||||||
if (!account || !nftId)
|
if (!account || !nftId)
|
||||||
|
{
|
||||||
|
getJournal().trace() << "WAMR getNFT: Invalid account or NFT ID";
|
||||||
return Unexpected(HF_ERR_INVALID_PARAMS);
|
return Unexpected(HF_ERR_INVALID_PARAMS);
|
||||||
|
}
|
||||||
|
|
||||||
auto obj = nft::findToken(ctx.view(), account, nftId);
|
auto obj = nft::findToken(ctx.view(), account, nftId);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
|
{
|
||||||
|
getJournal().trace() << "WAMR getNFT: NFT not found";
|
||||||
return Unexpected(HF_ERR_LEDGER_OBJ_NOT_FOUND);
|
return Unexpected(HF_ERR_LEDGER_OBJ_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
Slice const s = obj->at(sfURI);
|
Slice const s = obj->at(sfURI);
|
||||||
return Bytes(s.begin(), s.end());
|
return Bytes(s.begin(), s.end());
|
||||||
@@ -476,15 +482,15 @@ WasmHostFunctionsImpl::trace(
|
|||||||
#else
|
#else
|
||||||
auto j = ctx.journal.trace();
|
auto j = ctx.journal.trace();
|
||||||
#endif
|
#endif
|
||||||
j << msg;
|
|
||||||
if (!asHex)
|
if (!asHex)
|
||||||
j << std::string_view(
|
j << "WAMR TRACE (" << leKey.key << "): " << msg << " - "
|
||||||
reinterpret_cast<char const*>(data.data()), data.size());
|
<< std::string_view(
|
||||||
|
reinterpret_cast<char const*>(data.data()), data.size());
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto const hex =
|
auto const hex =
|
||||||
boost::algorithm::hex(std::string(data.begin(), data.end()));
|
boost::algorithm::hex(std::string(data.begin(), data.end()));
|
||||||
j << hex;
|
j << "WAMR DEV TRACE (" << leKey.key << "): " << msg << " - " << hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return msg.size() + data.size() * (asHex ? 2 : 1);
|
return msg.size() + data.size() * (asHex ? 2 : 1);
|
||||||
@@ -499,7 +505,7 @@ WasmHostFunctionsImpl::traceNum(std::string const& msg, int64_t data)
|
|||||||
auto j = ctx.journal.trace();
|
auto j = ctx.journal.trace();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
j << msg << data;
|
j << "WAMR DEV TRACE (" << leKey.key << "): " << msg << " - " << data;
|
||||||
|
|
||||||
return msg.size() + sizeof(data);
|
return msg.size() + sizeof(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -685,8 +685,11 @@ getNFT_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
|
|||||||
RET(nftRaw.error());
|
RET(nftRaw.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nftRaw->size() < uint256::bytes * 2)
|
if (nftRaw->size() != uint256::bytes)
|
||||||
{
|
{
|
||||||
|
hf->getJournal().trace()
|
||||||
|
<< "WAMR getNFT: Invalid NFT data size: " << nftRaw->size()
|
||||||
|
<< ", expected " << (uint256::bytes);
|
||||||
RET(HF_ERR_INVALID_PARAMS);
|
RET(HF_ERR_INVALID_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user