Skip to content

Commit

Permalink
Merge pull request #218 fix relay uncommited tx
Browse files Browse the repository at this point in the history
  • Loading branch information
aivve committed May 27, 2023
2 parents a8e30bd + 323ff2f commit f26efda
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Wallet/WalletGreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ uint64_t WalletGreen::getBlockTimestamp(const uint32_t blockHeight) {
auto getBlockTimestampCompleted = std::promise<std::error_code>();
auto getBlockTimestampWaitFuture = getBlockTimestampCompleted.get_future();

m_node.getBlockTimestamp(std::move(blockHeight), std::ref(timestamp),
m_node.getBlockTimestamp(blockHeight, std::ref(timestamp),
[&getBlockTimestampCompleted](std::error_code ec) {
auto detachedPromise = std::move(getBlockTimestampCompleted);
detachedPromise.set_value(ec);
Expand Down Expand Up @@ -1901,14 +1901,21 @@ void WalletGreen::commitTransaction(size_t transactionId) {
throw std::system_error(make_error_code(error::TX_TRANSFER_IMPOSSIBLE));
}

System::Event completion(m_dispatcher);
std::error_code ec;

m_node.relayTransaction(m_uncommitedTransactions[transactionId], [&ec, &completion, this](std::error_code error) {
ec = error;
this->m_dispatcher.remoteSpawn(std::bind(asyncRequestCompletion, std::ref(completion)));
});
completion.wait();
try {
auto relayTransactionCompleted = std::promise<std::error_code>();
auto relayTransactionWaitFuture = relayTransactionCompleted.get_future();

m_node.relayTransaction(m_uncommitedTransactions[transactionId], [&ec, &relayTransactionCompleted, this](std::error_code error) {
auto detachedPromise = std::move(relayTransactionCompleted);
detachedPromise.set_value(ec);
});
ec = relayTransactionWaitFuture.get();
}
catch (const std::exception& e) {
m_logger(ERROR, BRIGHT_RED) << "Failed to relay uncommited transaction: " << e.what();
}

if (!ec) {
updateTransactionStateAndPushEvent(transactionId, WalletTransactionState::SUCCEEDED);
Expand Down

0 comments on commit f26efda

Please sign in to comment.