rpc: fix wrongly formatted JSON for pruned tx
Fix for #4399. Also unifies code for serializing pruned tx to binary/json into one.
This commit is contained in:
parent
2287fb9fb4
commit
e51c978770
@ -212,23 +212,15 @@ namespace cryptonote
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
static cryptonote::blobdata get_pruned_tx_blob(cryptonote::transaction &tx)
|
class pruned_transaction {
|
||||||
{
|
transaction& tx;
|
||||||
std::stringstream ss;
|
public:
|
||||||
binary_archive<true> ba(ss);
|
pruned_transaction(transaction& tx) : tx(tx) {}
|
||||||
bool r = tx.serialize_base(ba);
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
CHECK_AND_ASSERT_MES(r, cryptonote::blobdata(), "Failed to serialize rct signatures base");
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
static cryptonote::blobdata get_pruned_tx_json(cryptonote::transaction &tx)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
json_archive<true> ar(ss);
|
|
||||||
bool r = tx.serialize_base(ar);
|
bool r = tx.serialize_base(ar);
|
||||||
CHECK_AND_ASSERT_MES(r, cryptonote::blobdata(), "Failed to serialize rct signatures base");
|
if (!r) return false;
|
||||||
return ss.str();
|
END_SERIALIZE()
|
||||||
}
|
};
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res)
|
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res)
|
||||||
{
|
{
|
||||||
@ -564,10 +556,11 @@ namespace cryptonote
|
|||||||
|
|
||||||
crypto::hash tx_hash = *vhi++;
|
crypto::hash tx_hash = *vhi++;
|
||||||
e.tx_hash = *txhi++;
|
e.tx_hash = *txhi++;
|
||||||
blobdata blob = req.prune ? get_pruned_tx_blob(tx) : t_serializable_object_to_blob(tx);
|
pruned_transaction pruned_tx{tx};
|
||||||
|
blobdata blob = req.prune ? t_serializable_object_to_blob(pruned_tx) : t_serializable_object_to_blob(tx);
|
||||||
e.as_hex = string_tools::buff_to_hex_nodelimer(blob);
|
e.as_hex = string_tools::buff_to_hex_nodelimer(blob);
|
||||||
if (req.decode_as_json)
|
if (req.decode_as_json)
|
||||||
e.as_json = req.prune ? get_pruned_tx_json(tx) : obj_to_json_str(tx);
|
e.as_json = req.prune ? obj_to_json_str(pruned_tx) : obj_to_json_str(tx);
|
||||||
e.in_pool = pool_tx_hashes.find(tx_hash) != pool_tx_hashes.end();
|
e.in_pool = pool_tx_hashes.find(tx_hash) != pool_tx_hashes.end();
|
||||||
if (e.in_pool)
|
if (e.in_pool)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user