This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transaction_metadata create_signing_keys_future method
- Loading branch information
Showing
6 changed files
with
82 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @file | ||
* @copyright defined in eos/LICENSE.txt | ||
*/ | ||
#pragma once | ||
|
||
#include <boost/asio/thread_pool.hpp> | ||
#include <boost/asio/post.hpp> | ||
#include <future> | ||
#include <memory> | ||
|
||
namespace eosio { namespace chain { | ||
|
||
// async on thread_pool and return future | ||
template<typename F> | ||
auto async_thread_pool( boost::asio::thread_pool& thread_pool, F&& f ) { | ||
auto task = std::make_shared<std::packaged_task<decltype( f() )()>>( std::forward<F>( f ) ); | ||
boost::asio::post( thread_pool, [task]() { (*task)(); } ); | ||
return task->get_future(); | ||
} | ||
|
||
} } // eosio::chain | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <eosio/chain/transaction_metadata.hpp> | ||
#include <eosio/chain/thread_utils.hpp> | ||
#include <boost/asio/thread_pool.hpp> | ||
|
||
namespace eosio { namespace chain { | ||
|
||
|
||
const flat_set<public_key_type>& transaction_metadata::recover_keys( const chain_id_type& chain_id ) { | ||
// Unlikely for more than one chain_id to be used in one nodeos instance | ||
if( !signing_keys || signing_keys->first != chain_id ) { | ||
if( signing_keys_future.valid() ) { | ||
signing_keys = signing_keys_future.get(); | ||
if( signing_keys->first == chain_id ) { | ||
return signing_keys->second; | ||
} | ||
} | ||
signing_keys = std::make_pair( chain_id, trx.get_signature_keys( chain_id )); | ||
} | ||
return signing_keys->second; | ||
} | ||
|
||
void transaction_metadata::create_signing_keys_future( transaction_metadata_ptr& mtrx, | ||
boost::asio::thread_pool& thread_pool, const chain_id_type& chain_id ) { | ||
std::weak_ptr<transaction_metadata> mtrx_wp = mtrx; | ||
mtrx->signing_keys_future = async_thread_pool( thread_pool, [chain_id, mtrx_wp]() { | ||
auto mtrx = mtrx_wp.lock(); | ||
return mtrx ? | ||
std::make_pair( chain_id, mtrx->trx.get_signature_keys( chain_id ) ) : | ||
std::make_pair( chain_id, decltype( mtrx->trx.get_signature_keys( chain_id ) ){} ); | ||
} ); | ||
} | ||
|
||
|
||
} } // eosio::chain |