From 72ef525ddbe90ed6834d5b874ca87aecc3160a66 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 9 Feb 2018 15:38:54 +0800 Subject: [PATCH 1/3] Add broadcast_transaction method for broadcast transaction signed by cold wallet --- .../wallet/include/graphene/wallet/wallet.hpp | 7 +++++++ libraries/wallet/wallet.cpp | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 4290d2b172..fd9fb03175 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -507,6 +507,12 @@ class wallet_api * @ingroup Transaction Builder API */ signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true); + + /** + * @ingroup broadcast signed transaction + */ + pair broadcast_transaction(signed_transaction tx); + /** * @ingroup Transaction Builder API */ @@ -1628,6 +1634,7 @@ FC_API( graphene::wallet::wallet_api, (set_fees_on_builder_transaction) (preview_builder_transaction) (sign_builder_transaction) + (broadcast_transaction) (propose_builder_transaction) (propose_builder_transaction2) (remove_builder_transaction) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index dec7813b30..7c8a6025f3 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -851,6 +851,19 @@ class wallet_api_impl return _builder_transactions[transaction_handle] = sign_transaction(_builder_transactions[transaction_handle], broadcast); } + + pair broadcast_transaction(signed_transaction tx) + { + try { + _remote_net_broadcast->broadcast_transaction(tx); + } + catch (const fc::exception& e) { + elog("Caught exception while broadcasting tx ${id}: ${e}", ("id", tx.id().str())("e", e.to_detail_string())); + throw; + } + return std::make_pair(tx.id(),tx); + } + signed_transaction propose_builder_transaction( transaction_handle_type handle, time_point_sec expiration = time_point::now() + fc::minutes(1), @@ -3028,6 +3041,11 @@ signed_transaction wallet_api::sign_builder_transaction(transaction_handle_type return my->sign_builder_transaction(transaction_handle, broadcast); } +pair wallet_api::broadcast_transaction(signed_transaction tx) +{ + return my->broadcast_transaction(tx); +} + signed_transaction wallet_api::propose_builder_transaction( transaction_handle_type handle, time_point_sec expiration, From bf27fb801026c5f5fdb8c2517cab115367ba5db1 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 9 Feb 2018 19:42:47 +0800 Subject: [PATCH 2/3] Update document for broadcast_transaction --- libraries/wallet/include/graphene/wallet/wallet.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index fd9fb03175..5bfc0f15f5 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -508,8 +508,9 @@ class wallet_api */ signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true); - /** - * @ingroup broadcast signed transaction + /** Broadcast signed transaction + * @param tx signed transaction + * @returns the transaction ID along with the signed transaction. */ pair broadcast_transaction(signed_transaction tx); From cdb4307ee7271815eb9f7b75419e5cf2db98e296 Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 10 Feb 2018 09:04:03 +0800 Subject: [PATCH 3/3] removed TODO of broadcast_transaction function --- libraries/wallet/include/graphene/wallet/wallet.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 5bfc0f15f5..ec7ad00825 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -667,8 +667,6 @@ class wallet_api bool is_public_key_registered(string public_key) const; /** Converts a signed_transaction in JSON form to its binary representation. - * - * TODO: I don't see a broadcast_transaction() function, do we need one? * * @param tx the transaction to serialize * @returns the binary form of the transaction. It will not be hex encoded,