diff --git a/rai/core_test/interface.cpp b/rai/core_test/interface.cpp index cf64a673..1c5a0386 100644 --- a/rai/core_test/interface.cpp +++ b/rai/core_test/interface.cpp @@ -100,6 +100,12 @@ TEST (interface, sign_transaction) free (transaction); } +TEST (interface, fail_sign_transaction) +{ + rai::uint256_union data (0); + xrb_sign_transaction ("", data.bytes.data ()); +} + TEST (interface, work_transaction) { rai::raw_key key; @@ -117,3 +123,9 @@ TEST (interface, work_transaction) ASSERT_FALSE (rai::work_validate (*block)); free (transaction); } + +TEST (interface, fail_work_transaction) +{ + rai::uint256_union data (0); + xrb_work_transaction (""); +} diff --git a/rai/lib/interface.cpp b/rai/lib/interface.cpp index cb2c802c..40f24e3a 100644 --- a/rai/lib/interface.cpp +++ b/rai/lib/interface.cpp @@ -78,21 +78,27 @@ void xrb_key_account (const xrb_uint256 key, xrb_uint256 pub) char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private_key) { char * result (nullptr); - boost::property_tree::ptree block_l; - std::string transaction_l (transaction); - std::stringstream block_stream (transaction_l); - boost::property_tree::read_json (block_stream, block_l); - auto block (rai::deserialize_block_json (block_l)); - if (block != nullptr) + try + { + boost::property_tree::ptree block_l; + std::string transaction_l (transaction); + std::stringstream block_stream (transaction_l); + boost::property_tree::read_json (block_stream, block_l); + auto block (rai::deserialize_block_json (block_l)); + if (block != nullptr) + { + rai::uint256_union pub; + ed25519_publickey (private_key, pub.bytes.data ()); + rai::raw_key prv; + prv.data = *reinterpret_cast (private_key); + block->signature_set (rai::sign_message (prv, pub, block->hash ())); + auto json (block->to_json ()); + result = reinterpret_cast (malloc (json.size () + 1)); + strncpy (result, json.c_str (), json.size () + 1); + } + } + catch (std::runtime_error const & err) { - rai::uint256_union pub; - ed25519_publickey (private_key, pub.bytes.data ()); - rai::raw_key prv; - prv.data = *reinterpret_cast (private_key); - block->signature_set (rai::sign_message (prv, pub, block->hash ())); - auto json (block->to_json ()); - result = reinterpret_cast (malloc (json.size () + 1)); - strncpy (result, json.c_str (), json.size () + 1); } return result; } @@ -100,19 +106,25 @@ char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private char * xrb_work_transaction (const char * transaction) { char * result (nullptr); - boost::property_tree::ptree block_l; - std::string transaction_l (transaction); - std::stringstream block_stream (transaction_l); - boost::property_tree::read_json (block_stream, block_l); - auto block (rai::deserialize_block_json (block_l)); - if (block != nullptr) + try + { + boost::property_tree::ptree block_l; + std::string transaction_l (transaction); + std::stringstream block_stream (transaction_l); + boost::property_tree::read_json (block_stream, block_l); + auto block (rai::deserialize_block_json (block_l)); + if (block != nullptr) + { + rai::work_pool pool (std::thread::hardware_concurrency ()); + auto work (pool.generate (block->root ())); + block->block_work_set (work); + auto json (block->to_json ()); + result = reinterpret_cast (malloc (json.size () + 1)); + strncpy (result, json.c_str (), json.size () + 1); + } + } + catch (std::runtime_error const & err) { - rai::work_pool pool (std::thread::hardware_concurrency ()); - auto work (pool.generate (block->root ())); - block->block_work_set (work); - auto json (block->to_json ()); - result = reinterpret_cast (malloc (json.size () + 1)); - strncpy (result, json.c_str (), json.size () + 1); } return result; }