void json_rpc_database_fixture::review_answer( fc::variant& answer, int64_t code, bool is_warning, bool is_fail, fc::optional< fc::variant > id ) { fc::variant_object error; int64_t answer_code; if( is_fail ) { if( id.valid() && code != JSON_RPC_INVALID_REQUEST ) { BOOST_REQUIRE( answer.get_object().contains( "id" ) ); check_id_equal( answer[ "id" ], *id ); } BOOST_REQUIRE( answer.get_object().contains( "error" ) ); BOOST_REQUIRE( answer["error"].is_object() ); error = answer["error"].get_object(); BOOST_REQUIRE( error.contains( "code" ) ); BOOST_REQUIRE( error["code"].is_int64() ); answer_code = error["code"].as_int64(); BOOST_REQUIRE( answer_code == code ); if( is_warning ) BOOST_TEST_MESSAGE( error["message"].as_string() ); } else { BOOST_REQUIRE( answer.get_object().contains( "result" ) ); BOOST_REQUIRE( answer.get_object().contains( "id" ) ); if( id.valid() ) check_id_equal( answer[ "id" ], *id ); } }
int run( int64_t index, fc::optional<string> seed, fc::optional<fc::path> json_outfile ) { fc::ecc::private_key key; if( seed.valid() ) { string effective_seed; if( index >= 0 ) effective_seed = (*seed)+std::to_string(index); else effective_seed = (*seed); fc::sha256 hash_effective_seed = fc::sha256::hash( effective_seed.c_str(), effective_seed.length() ); key = fc::ecc::private_key::regenerate( hash_effective_seed ); } else key = fc::ecc::private_key::generate(); if( !json_outfile.valid() ) { auto obj = fc::mutable_variant_object(); obj["public_key"] = public_key_type(key.get_public_key()); obj["private_key"] = key.get_secret(); obj["wif_private_key"] = bts::utilities::key_to_wif(key); obj["native_address"] = bts::blockchain::address(key.get_public_key()); obj["pts_address"] = bts::blockchain::pts_address(key.get_public_key()); std::cout << fc::json::to_pretty_string(obj) << '\n'; return 0; } else { std::cout << "writing new private key to JSON file " << (*json_outfile).string() << "\n"; fc::json::save_to_file(key, (*json_outfile)); std::cout << "bts address: " << std::string(bts::blockchain::address(key.get_public_key())) << "\n"; return 0; } }