Skip to content

Commit

Permalink
Merge pull request #450 from evoskuil/master
Browse files Browse the repository at this point in the history
Fix missing handling of return codes and watch-address calls.
  • Loading branch information
evoskuil authored Mar 7, 2017
2 parents 027ca31 + 5a0f5ba commit cd50ac6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/commands/send-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ console_result send_tx::invoke(std::ostream& output, std::ostream& error)

auto on_done = [&state](const code& error)
{
state.output(BX_SEND_TX_OUTPUT);
if (state.succeeded(error))
state.output(BX_SEND_TX_OUTPUT);
};

auto on_error = [&state](const code& error)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/validate-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ console_result validate_tx::invoke(std::ostream& output,

auto on_done = [&state](const code& error)
{
if (error)
state.output(format(BX_VALIDATE_TX_INVALID) % error.message());
else
if (state.succeeded(error))
state.output(BX_VALIDATE_TX_VALID);
else
state.output(format(BX_VALIDATE_TX_INVALID) % error.message());
};

auto on_error = [&state](const code& error)
Expand Down
30 changes: 18 additions & 12 deletions src/commands/watch-address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,38 @@ console_result watch_address::invoke(std::ostream& output, std::ostream& error)

auto on_subscribed = [&state, &address](const code& error)
{
state.output(format(BX_WATCH_ADDRESS_WAITING) % address);
++state;
if (state.succeeded(error))
{
state.output(format(BX_WATCH_ADDRESS_WAITING) % address);
++state;
}
};

auto on_error = [&state](const code& error)
{
state.succeeded(error);
};

client.address_subscribe(on_error, on_subscribed, address);
client.wait();

if (state.stopped())
return state.get_result();

// This enables json-style array formatting.
const auto json = encoding == encoding_engine::json;

auto on_update = [&output, &state, json](const payment_address& address,
size_t, const hash_digest& block_hash, const tx_type& tx)
auto on_update = [&output, &state, &address, json](const code& error,
uint16_t /*sequence*/, size_t /*height*/,
const hash_digest& block_hash, const tx_type& tx)
{
state.output(prop_tree(tx, block_hash, address, json));
output << std::endl;
if (state.succeeded(error))
{
state.output(prop_tree(tx, block_hash, address, json));
output << std::endl;
}
};

client.set_on_update(on_update);
client.address_subscribe(on_error, on_subscribed, address);
client.wait();

if (state.stopped())
return state.get_result();

// Catch C signals for stopping the program before monitoring timeout.
signal(SIGTERM, handle_signal);
Expand Down
20 changes: 10 additions & 10 deletions test/commands/send-tx-p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ BX_USING_NAMESPACES()
BOOST_AUTO_TEST_SUITE(network)
BOOST_AUTO_TEST_SUITE(send_tx_p2p__invoke)

#define SEND_TX_P2P_A \
"0100000001b3807042c92f449bbf79b33ca59d7dfec7f4cc71096704a9c526dddf496ee097010000006a473044022039a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c202201035fe810e283bcf394485c6a9dfd117ad9f684cdd83d36453718f5d0491b9dd012103c40cbd64c9c608df2c9730f49b0888c4db1c436e8b2b74aead6c6afbd10428c0ffffffff01905f0100000000001976a91418c0bd8d1818f1bf99cb1df2269c645318ef7b7388ac00000000"

BOOST_AUTO_TEST_CASE(send_tx_p2p__invoke__nodes_3__okay)
{
BX_DECLARE_PEER_COMMAND(send_tx_p2p);
command.set_nodes_option(3);
command.set_transaction_argument({ SEND_TX_P2P_A });
BX_REQUIRE_OKAY(command.invoke(output, error));
}
////#define SEND_TX_P2P_A \
////"0100000001b3807042c92f449bbf79b33ca59d7dfec7f4cc71096704a9c526dddf496ee097010000006a473044022039a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c202201035fe810e283bcf394485c6a9dfd117ad9f684cdd83d36453718f5d0491b9dd012103c40cbd64c9c608df2c9730f49b0888c4db1c436e8b2b74aead6c6afbd10428c0ffffffff01905f0100000000001976a91418c0bd8d1818f1bf99cb1df2269c645318ef7b7388ac00000000"
////
////BOOST_AUTO_TEST_CASE(send_tx_p2p__invoke__nodes_3__okay)
////{
//// BX_DECLARE_PEER_COMMAND(send_tx_p2p);
//// command.set_nodes_option(3);
//// command.set_transaction_argument({ SEND_TX_P2P_A });
//// BX_REQUIRE_OKAY(command.invoke(output, error));
////}

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit cd50ac6

Please sign in to comment.