提交 a0409fd4 编写于 作者: M Matt Witherspoon

Get ride of functor passing for transaction signing

Just embed the logic needed right in to wallet implementations. This will cause a little bit of code duplication but avoids the complexity of the functor
上级 57decaba
......@@ -76,8 +76,6 @@ namespace eosio { namespace chain {
struct signed_transaction : public transaction
{
using sign_digest_functor = std::function<signature_type(digest_type)>;
signed_transaction() = default;
// signed_transaction( const signed_transaction& ) = default;
// signed_transaction( signed_transaction&& ) = default;
......@@ -92,7 +90,6 @@ namespace eosio { namespace chain {
vector<bytes> context_free_data; ///< for each context-free action, there is an entry here
const signature_type& sign(const private_key_type& key, const chain_id_type& chain_id);
const signature_type& sign(sign_digest_functor signature_request, const chain_id_type& chain_id);
signature_type sign(const private_key_type& key, const chain_id_type& chain_id)const;
flat_set<public_key_type> get_signature_keys( const chain_id_type& chain_id, bool allow_duplicate_keys = false )const;
};
......
......@@ -119,11 +119,6 @@ const signature_type& signed_transaction::sign(const private_key_type& key, cons
return signatures.back();
}
const signature_type& signed_transaction::sign(sign_digest_functor signature_request, const chain_id_type& chain_id) {
signatures.push_back(signature_request(sig_digest(chain_id, context_free_data)));
return signatures.back();
}
signature_type signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const {
return key.sign(sig_digest(chain_id, context_free_data));
}
......
......@@ -171,9 +171,9 @@ class soft_wallet final : public wallet_api
*/
string create_key( string key_type ) override;
/* Returns a fuctor to sign a digest via the given public_key
/* Attempts to sign a digest via the given public_key
*/
optional<signed_transaction::sign_digest_functor> sign_digest( public_key_type public_key ) override;
optional<signature_type> try_sign_digest( const digest_type digest, const public_key_type public_key ) override;
std::shared_ptr<detail::soft_wallet_impl> my;
void encrypt_keys();
......
......@@ -91,12 +91,9 @@ class wallet_api
*/
virtual string create_key( string key_type ) = 0;
/** Returns a functor that can be used to sign a digest based on the given public key (provided the
*
* wallet can sign with that key)
* @param public_key the key type to create. May be empty to allow wallet to pick appropriate/"best" key type
/** Returns a signature given the digest and public_key, if this wallet can sign via that public key
*/
virtual optional<signed_transaction::sign_digest_functor> sign_digest( public_key_type public_key ) = 0;
virtual optional<signature_type> try_sign_digest( const digest_type digest, const public_key_type public_key ) = 0;
};
}}
\ No newline at end of file
......@@ -128,13 +128,11 @@ public:
return optional<private_key_type>();
}
optional<signed_transaction::sign_digest_functor> sign_digest( public_key_type public_key ) {
optional<signature_type> try_sign_digest( const digest_type digest, const public_key_type public_key ) {
auto it = _keys.find(public_key);
if( it == _keys.end() )
return optional<signed_transaction::sign_digest_functor>{};
return [priv_key = it->second](digest_type d) {
return priv_key.sign(d);
};
return optional<signature_type>{};
return it->second.sign(digest);
}
private_key_type get_private_key(const public_key_type& id)const
......@@ -377,8 +375,8 @@ private_key_type soft_wallet::get_private_key( public_key_type pubkey )const
return my->get_private_key( pubkey );
}
optional<signed_transaction::sign_digest_functor> soft_wallet::sign_digest( public_key_type public_key ) {
return my->sign_digest(public_key);
optional<signature_type> soft_wallet::try_sign_digest( const digest_type digest, const public_key_type public_key ) {
return my->try_sign_digest(digest, public_key);
}
pair<public_key_type,private_key_type> soft_wallet::get_private_key_from_password( string account, string role, string password )const {
......
......@@ -204,9 +204,9 @@ wallet_manager::sign_transaction(const chain::signed_transaction& txn, const fla
bool found = false;
for (const auto& i : wallets) {
if (!i.second->is_locked()) {
auto f = i.second->sign_digest(pk);
if (f) {
stxn.sign(*f, id);
optional<signature_type> sig = i.second->try_sign_digest(stxn.sig_digest(id, stxn.context_free_data), pk);
if (sig) {
stxn.signatures.push_back(*sig);
found = true;
break; // inner for
}
......@@ -227,10 +227,9 @@ wallet_manager::sign_digest(const chain::digest_type& digest, const public_key_t
try {
for (const auto& i : wallets) {
if (!i.second->is_locked()) {
auto f = i.second->sign_digest(key);
if (f) {
return (*f)(digest);
}
optional<signature_type> sig = i.second->try_sign_digest(digest, key);
if (sig)
return *sig;
}
}
} FC_LOG_AND_RETHROW();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册