Skip to content

Commit

Permalink
Merge pull request #2049 from MichelSantos/2048
Browse files Browse the repository at this point in the history
CLI: Specify signing keys
  • Loading branch information
jmjatlanta committed Nov 19, 2019
2 parents dee35ee + 927bb3c commit 70500fd
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 15 deletions.
30 changes: 30 additions & 0 deletions libraries/wallet/include/graphene/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,19 @@ class wallet_api
*/
signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true);

/**
* @ingroup Transaction Builder API
*
* Sign the transaction in a transaction builder and optionally broadcast to the network.
* @param transaction_handle handle of the transaction builder
* @param signing_keys Keys that must be used when signing the transaction
* @param broadcast whether to broadcast the signed transaction to the network
* @return a signed transaction
*/
signed_transaction sign_builder_transaction2(transaction_handle_type transaction_handle,
const vector<public_key_type>& signing_keys = vector<public_key_type>(),
bool broadcast = true);

/** Broadcast signed transaction
* @param tx signed transaction
* @returns the transaction ID along with the signed transaction.
Expand Down Expand Up @@ -1588,6 +1601,21 @@ class wallet_api
*/
signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false);

/** Signs a transaction.
*
* Given a fully-formed transaction that is only lacking signatures, this signs
* the transaction with the inferred necessary keys and the explicitly provided keys,
* and optionally broadcasts the transaction
* @param tx the unsigned transaction
* @param signing_keys Keys that must be used when signing the transaction
* @param broadcast true if you wish to broadcast the transaction
* @return the signed version of the transaction
*/
signed_transaction sign_transaction2(signed_transaction tx,
const vector<public_key_type>& signing_keys = vector<public_key_type>(),
bool broadcast = true);


/** Get transaction signers.
*
* Returns information about who signed the transaction, specifically,
Expand Down Expand Up @@ -1769,6 +1797,7 @@ FC_API( graphene::wallet::wallet_api,
(set_fees_on_builder_transaction)
(preview_builder_transaction)
(sign_builder_transaction)
(sign_builder_transaction2)
(broadcast_transaction)
(propose_builder_transaction)
(propose_builder_transaction2)
Expand Down Expand Up @@ -1857,6 +1886,7 @@ FC_API( graphene::wallet::wallet_api,
(save_wallet_file)
(serialize_transaction)
(sign_transaction)
(sign_transaction2)
(add_transaction_signature)
(get_transaction_signers)
(get_key_references)
Expand Down
13 changes: 13 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ signed_transaction wallet_api::sign_builder_transaction(transaction_handle_type
return my->sign_builder_transaction(transaction_handle, broadcast);
}

signed_transaction wallet_api::sign_builder_transaction2(transaction_handle_type transaction_handle,
const vector<public_key_type>& explicit_keys,
bool broadcast)
{
return my->sign_builder_transaction2(transaction_handle, explicit_keys, broadcast);
}

pair<transaction_id_type,signed_transaction> wallet_api::broadcast_transaction(signed_transaction tx)
{
return my->broadcast_transaction(tx);
Expand Down Expand Up @@ -999,6 +1006,12 @@ signed_transaction wallet_api::sign_transaction(signed_transaction tx, bool broa
return my->sign_transaction( tx, broadcast);
} FC_CAPTURE_AND_RETHROW( (tx) ) }

signed_transaction wallet_api::sign_transaction2(signed_transaction tx, const vector<public_key_type>& signing_keys,
bool broadcast /* = false */)
{ try {
return my->sign_transaction2( tx, signing_keys, broadcast);
} FC_CAPTURE_AND_RETHROW( (tx) ) }

flat_set<public_key_type> wallet_api::get_transaction_signers(const signed_transaction &tx) const
{ try {
return my->get_transaction_signers(tx);
Expand Down
6 changes: 6 additions & 0 deletions libraries/wallet/wallet_api_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ class wallet_api_impl
asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL);
transaction preview_builder_transaction(transaction_handle_type handle);
signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true);
signed_transaction sign_builder_transaction2(transaction_handle_type transaction_handle,
const vector<public_key_type>& signing_keys = vector<public_key_type>(),
bool broadcast = true);

pair<transaction_id_type,signed_transaction> broadcast_transaction(signed_transaction tx);

Expand Down Expand Up @@ -325,6 +328,9 @@ class wallet_api_impl
bool broadcast );

signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false);
signed_transaction sign_transaction2(signed_transaction tx,
const vector<public_key_type>& signing_keys = vector<public_key_type>(),
bool broadcast = false);

flat_set<public_key_type> get_transaction_signers(const signed_transaction &tx) const;

Expand Down
9 changes: 9 additions & 0 deletions libraries/wallet/wallet_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ namespace graphene { namespace wallet { namespace detail {
sign_transaction(_builder_transactions[transaction_handle], broadcast);
}

signed_transaction wallet_api_impl::sign_builder_transaction2(transaction_handle_type
transaction_handle, const vector<public_key_type>& signing_keys, bool broadcast)
{
FC_ASSERT(_builder_transactions.count(transaction_handle));

return _builder_transactions[transaction_handle] =
sign_transaction2(_builder_transactions[transaction_handle], signing_keys, broadcast);
}

signed_transaction wallet_api_impl::propose_builder_transaction( transaction_handle_type handle,
time_point_sec expiration, uint32_t review_period_seconds, bool broadcast)
{
Expand Down
11 changes: 11 additions & 0 deletions libraries/wallet/wallet_sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,20 @@ namespace graphene { namespace wallet { namespace detail {
}

signed_transaction wallet_api_impl::sign_transaction( signed_transaction tx, bool broadcast )
{
return sign_transaction2(tx, {}, broadcast);
}

signed_transaction wallet_api_impl::sign_transaction2( signed_transaction tx,
const vector<public_key_type>& signing_keys, bool broadcast)
{
set<public_key_type> approving_key_set = get_owned_required_keys(tx);

// Add any explicit keys to the approving_key_set
for (const public_key_type& explicit_key : signing_keys) {
approving_key_set.insert(explicit_key);
}

auto dyn_props = get_dynamic_global_properties();
tx.set_reference_block( dyn_props.head_block_id );

Expand Down
Loading

0 comments on commit 70500fd

Please sign in to comment.