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:
Mayukha Vadari
2025-06-05 14:24:13 -04:00
committed by GitHub
parent 8a33702f26
commit 6e8a5f0f4e
3 changed files with 27 additions and 14 deletions

View File

@@ -93,11 +93,17 @@ wamr_log_to_rippled(
{
beast::Journal j = WasmEngine::instance().getJournal();
// Format the variadic args
char const* safeFile = file ? file : "<null>";
std::ostringstream oss;
oss << "WAMR (" << safeFile << ":" << line << "): ";
// Format the variadic args
if (file)
{
oss << "WAMR (" << file << ":" << line << "): ";
}
else
{
oss << "WAMR: ";
}
va_list args;
va_start(args, fmt);
@@ -114,7 +120,6 @@ wamr_log_to_rippled(
#ifdef DEBUG_OUTPUT_WAMR
std::cerr << oss.str() << std::endl;
#endif
//
}
void
@@ -544,9 +549,8 @@ ModuleWrapper::buildImports(
if (impCnt != importTypes.num_elems)
{
print_wasm_error(
std::string("Imports not finished: ") +
std::to_string(wimports.num_elems) + "/" +
std::to_string(importTypes.num_elems),
std::string("Imports not finished: ") + std::to_string(impCnt) +
"/" + std::to_string(importTypes.num_elems),
nullptr,
j_);
}

View File

@@ -455,11 +455,17 @@ Expected<Bytes, int32_t>
WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId)
{
if (!account || !nftId)
{
getJournal().trace() << "WAMR getNFT: Invalid account or NFT ID";
return Unexpected(HF_ERR_INVALID_PARAMS);
}
auto obj = nft::findToken(ctx.view(), account, nftId);
if (!obj)
{
getJournal().trace() << "WAMR getNFT: NFT not found";
return Unexpected(HF_ERR_LEDGER_OBJ_NOT_FOUND);
}
Slice const s = obj->at(sfURI);
return Bytes(s.begin(), s.end());
@@ -476,15 +482,15 @@ WasmHostFunctionsImpl::trace(
#else
auto j = ctx.journal.trace();
#endif
j << msg;
if (!asHex)
j << std::string_view(
reinterpret_cast<char const*>(data.data()), data.size());
j << "WAMR TRACE (" << leKey.key << "): " << msg << " - "
<< std::string_view(
reinterpret_cast<char const*>(data.data()), data.size());
else
{
auto const hex =
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);
@@ -499,7 +505,7 @@ WasmHostFunctionsImpl::traceNum(std::string const& msg, int64_t data)
auto j = ctx.journal.trace();
#endif
j << msg << data;
j << "WAMR DEV TRACE (" << leKey.key << "): " << msg << " - " << data;
return msg.size() + sizeof(data);
}

View File

@@ -685,8 +685,11 @@ getNFT_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
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);
}