forked from lthn/blockchain
added json-version for sendrawtransaction (cherry-picked)
This commit is contained in:
parent
68194dc60b
commit
701625d2f0
4 changed files with 42 additions and 6 deletions
|
|
@ -863,11 +863,24 @@ namespace currency
|
|||
CHECK_CORE_READY();
|
||||
|
||||
std::string tx_blob;
|
||||
if(!string_tools::parse_hexstr_to_binbuff(req.tx_as_hex, tx_blob))
|
||||
if (req.tx_as_hex.size())
|
||||
{
|
||||
LOG_PRINT_L0("[on_send_raw_tx]: Failed to parse tx from hexbuff: " << req.tx_as_hex);
|
||||
res.status = "Failed";
|
||||
return true;
|
||||
if (!string_tools::parse_hexstr_to_binbuff(req.tx_as_hex, tx_blob))
|
||||
{
|
||||
LOG_PRINT_L0("[on_send_raw_tx]: Failed to parse tx from hexbuff: " << req.tx_as_hex);
|
||||
res.status = "Failed";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!req.tx_as_base64.size())
|
||||
{
|
||||
LOG_PRINT_L0("[on_send_raw_tx]: Failed to parse tx from hexbuff: " << req.tx_as_hex);
|
||||
res.status = API_RETURN_CODE_BAD_ARG;
|
||||
return true;
|
||||
}
|
||||
tx_blob = req.tx_as_base64;
|
||||
}
|
||||
|
||||
if (!m_ignore_offline_status && !m_p2p.get_payload_object().get_synchronized_connections_count())
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ namespace currency
|
|||
BEGIN_JSON_RPC_MAP("/json_rpc")
|
||||
MAP_JON_RPC ("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
|
||||
MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH)
|
||||
MAP_JON_RPC ("sendrawtransaction", on_send_raw_tx, COMMAND_RPC_SEND_RAW_TX)
|
||||
MAP_JON_RPC_WE("getblocktemplate", on_getblocktemplate, COMMAND_RPC_GETBLOCKTEMPLATE)
|
||||
MAP_JON_RPC_WE("submitblock", on_submitblock, COMMAND_RPC_SUBMITBLOCK)
|
||||
MAP_JON_RPC_WE("submitblock2", on_submitblock2, COMMAND_RPC_SUBMITBLOCK2)
|
||||
|
|
|
|||
|
|
@ -695,12 +695,14 @@ namespace currency
|
|||
struct request
|
||||
{
|
||||
std::string tx_as_hex;
|
||||
std::string tx_as_base64;
|
||||
|
||||
request() {}
|
||||
explicit request(const transaction &);
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(tx_as_hex) DOC_DSCR("The transaction data as a hexadecimal string, ready for network broadcast.") DOC_EXMP("00018ed1535b8b4862e.....368cdc5a86") DOC_END
|
||||
KV_SERIALIZE_BLOB_AS_BASE64_STRING(tx_as_base64) DOC_DSCR("The transaction data as a base64 string, ready for network broadcast. Used only if tx_as_hex is empty") DOC_EXMP("AwElEBr7PxIAAAAAABr......cQAAAAAAABqBJAAAAAAAABo6BQ") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,26 @@ DISABLE_VS_WARNINGS(4244)
|
|||
POP_VS_WARNINGS
|
||||
|
||||
|
||||
|
||||
void test_base64_serialization()
|
||||
{
|
||||
currency::COMMAND_RPC_GET_POOL_TXS_DETAILS::response rsp;
|
||||
rsp.txs.resize(1);
|
||||
rsp.txs.back().blob.resize(4000);
|
||||
crypto::generate_random_bytes(rsp.txs.back().blob.size(), (void*)rsp.txs.back().blob.data());
|
||||
|
||||
std::string str_json;
|
||||
epee::serialization::store_t_to_json(rsp, str_json);
|
||||
|
||||
currency::COMMAND_RPC_GET_POOL_TXS_DETAILS::response rsp2;
|
||||
bool res = epee::serialization::load_t_from_json(rsp2, str_json);
|
||||
if (rsp.txs.back().blob != rsp2.txs.back().blob)
|
||||
{
|
||||
LOG_PRINT_L0("Troubles");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void test_plain_wallet()
|
||||
{
|
||||
//std::string res = plain_wallet::init("195.201.107.230", "33340", "C:\\Users\\roky\\home\\", 0);
|
||||
|
|
@ -158,8 +178,8 @@ int main(int argc, char** argv)
|
|||
//epee::log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
// epee::log_space::log_singletone::get_default_log_file().c_str(),
|
||||
// epee::log_space::log_singletone::get_default_log_folder().c_str());
|
||||
|
||||
test_plain_wallet();
|
||||
test_base64_serialization();
|
||||
//test_plain_wallet();
|
||||
//parse_weird_tx();
|
||||
//thread_pool_tests();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue