Skip to content

Commit

Permalink
Issue steemit#1751 Improved error messaging, eliminated crashes found…
Browse files Browse the repository at this point in the history
… while testing, added example inputs.
  • Loading branch information
vogel76 committed Jan 8, 2018
1 parent 051c941 commit 2553cc3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
37 changes: 29 additions & 8 deletions programs/util/sign_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ int main(int argc, char** argv, char** envp)

if(*strChainId != '\0')
{
std::cerr << "Using explicit chain-id: `" << strChainId << "'" << std::endl;
fc::sha256 parsedId(strChainId);
chainId = parsedId;
try
{
fc::sha256 parsedId(strChainId);
chainId = parsedId;
std::cerr << "Using explicit chain-id: `" << strChainId << "'" << std::endl;
}
catch(const fc::exception& e)
{
std::cerr << "Specified explicit chain-id : `" << strChainId << "' is invalid. Option ignored, default chain-id used." << std::endl;
auto error = e.to_detail_string();
std::cerr << error << std::endl;
}
}
}

Expand All @@ -105,16 +114,28 @@ int main(int argc, char** argv, char** envp)
fc::variant v = fc::json::from_string( line, fc::json::strict_parser );
tx_signing_request sreq;
fc::from_variant( v, sreq );

tx_signing_result sres;
sres.tx = sreq.tx;
sres.digest = sreq.tx.digest();
sres.sig_digest = sreq.tx.sig_digest(chainId);

fc::ecc::private_key priv_key = *steem::utilities::wif_to_key( sreq.wif );
sres.sig = priv_key.sign_compact( sres.sig_digest );
sres.key = steem::protocol::public_key_type( priv_key.get_public_key() );
std::string sres_str = fc::json::to_string( sres );
std::cout << "{\"result\":" << sres_str << "}" << std::endl;
auto priv_key = steem::utilities::wif_to_key( sreq.wif );

if(priv_key)
{
sres.sig = priv_key->sign_compact( sres.sig_digest );
sres.key = steem::protocol::public_key_type( priv_key->get_public_key() );
std::string sres_str = fc::json::to_string( sres );
std::cout << "{\"result\":" << sres_str << "}" << std::endl;
}
else
{
if(sreq.wif.empty())
std::cerr << "Missing Wallet Import Format in the input JSON structure" << std::endl;
else
std::cerr << "Passed JSON points to invalid data according to Wallet Import Format specification: `" << sreq.wif << "'" << std::endl;
}
}
catch( const fc::exception& e )
{
Expand Down
1 change: 1 addition & 0 deletions programs/util/sign_transaction_broken_wif.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tx":{"ref_block_num":42396,"ref_block_prefix":4237248169,"expiration":"2018-01-03T13:14:57","operations":[["vote"{"voter":"the4th","author":"amliv08","permlink":"rfca2-photography-flower","weight":10000}]],"extensions":[],"signatures":["1f411b451090e328941fe2f9154de1fe6983a783ff62391af36d71fb31fcd278cc4cfffec2d56def297b149016320649b0c9c13f8ea36f23d65d3bfae9417229af"]},"wif": "5HueCGU8rMjxEXxi_INVALID_PuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"}
1 change: 1 addition & 0 deletions programs/util/sign_transaction_missing_wif.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tx":{"ref_block_num":42396,"ref_block_prefix":4237248169,"expiration":"2018-01-03T13:14:57","operations":[["vote"{"voter":"the4th","author":"amliv08","permlink":"rfca2-photography-flower","weight":10000}]],"extensions":[],"signatures":["1f411b451090e328941fe2f9154de1fe6983a783ff62391af36d71fb31fcd278cc4cfffec2d56def297b149016320649b0c9c13f8ea36f23d65d3bfae9417229af"]}}
1 change: 1 addition & 0 deletions programs/util/sign_transaction_valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tx":{"ref_block_num":42396,"ref_block_prefix":4237248169,"expiration":"2018-01-03T13:14:57","operations":[["vote"{"voter":"the4th","author":"amliv08","permlink":"rfca2-photography-flower","weight":10000}]],"extensions":[],"signatures":["1f411b451090e328941fe2f9154de1fe6983a783ff62391af36d71fb31fcd278cc4cfffec2d56def297b149016320649b0c9c13f8ea36f23d65d3bfae9417229af"]},"wif": "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"}

0 comments on commit 2553cc3

Please sign in to comment.