Skip to content

Commit d8e7c0a

Browse files
Merge pull request #311 from elmato/push-transaction-sync
Implement network_broadcast_api::broadcast_transaction_synchronous
2 parents 38ac7cb + ea8f896 commit d8e7c0a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

libraries/app/api.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include <fc/crypto/hex.hpp>
4141
#include <fc/smart_ref_impl.hpp>
42+
#include <fc/thread/future.hpp>
4243

4344
namespace graphene { namespace app {
4445

@@ -159,6 +160,16 @@ namespace graphene { namespace app {
159160
_app.p2p_node()->broadcast_transaction(trx);
160161
}
161162

163+
fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction& trx)
164+
{
165+
fc::promise<fc::variant>::ptr prom( new fc::promise<fc::variant>() );
166+
broadcast_transaction_with_callback( [=]( const fc::variant& v ){
167+
prom->set_value(v);
168+
}, trx );
169+
170+
return fc::future<fc::variant>(prom).wait();
171+
}
172+
162173
void network_broadcast_api::broadcast_block( const signed_block& b )
163174
{
164175
_app.chain_database()->push_block(b);

libraries/app/include/graphene/app/api.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ namespace graphene { namespace app {
195195
*/
196196
void broadcast_transaction_with_callback( confirmation_callback cb, const signed_transaction& trx);
197197

198+
/** this version of broadcast transaction registers a callback method that will be called when the transaction is
199+
* included into a block. The callback method includes the transaction id, block number, and transaction number in the
200+
* block.
201+
*/
202+
fc::variant broadcast_transaction_synchronous(const signed_transaction& trx);
203+
198204
void broadcast_block( const signed_block& block );
199205

200206
/**
@@ -394,6 +400,7 @@ FC_API(graphene::app::block_api,
394400
FC_API(graphene::app::network_broadcast_api,
395401
(broadcast_transaction)
396402
(broadcast_transaction_with_callback)
403+
(broadcast_transaction_synchronous)
397404
(broadcast_block)
398405
)
399406
FC_API(graphene::app::network_node_api,

0 commit comments

Comments
 (0)