Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions blockcypher/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ def broadcast_signed_transaction(unsigned_tx, signatures, pubkeys, coin_symbol='


def simple_spend(from_privkey, to_address, to_satoshis, change_address=None,
privkey_is_compressed=True, min_confirmations=0, api_key=None, coin_symbol='btc'):
privkey_is_compressed=True, min_confirmations=0, api_key=None, coin_symbol='btc', preference: str = 'high'):
'''
Simple method to spend from one single-key address to another.

Expand All @@ -1641,6 +1641,9 @@ def simple_spend(from_privkey, to_address, to_satoshis, change_address=None,
Compressed public keys (and their corresponding addresses) have been the standard since v0.6,
set privkey_is_compressed=False if using uncompressed addresses.

Fee preferences can be passed as strings with the values 'low', 'medium', or 'high'.
Transaction with zero fees are unlikely to be added to a block and hence removed from choices.

Note that this currently only supports spending from single key addresses.
'''
assert is_valid_coin_symbol(coin_symbol), coin_symbol
Expand Down Expand Up @@ -1674,6 +1677,7 @@ def simple_spend(from_privkey, to_address, to_satoshis, change_address=None,
verify_tosigntx=False, # will verify in next step
include_tosigntx=True,
api_key=api_key,
preference=preference if preference in ('high', 'medium', 'low') else 'high'
)
logger.info('unsigned_tx: %s' % unsigned_tx)

Expand Down Expand Up @@ -1739,7 +1743,7 @@ def simple_spend(from_privkey, to_address, to_satoshis, change_address=None,


def simple_spend_p2sh(all_from_pubkeys, from_privkeys_to_use, to_address, to_satoshis,
change_address=None, min_confirmations=0, api_key=None, coin_symbol='btc'):
change_address=None, min_confirmations=0, api_key=None, coin_symbol='btc', preference: str = 'high'):
'''
Simple method to spend from a p2sh address.

Expand All @@ -1748,6 +1752,9 @@ def simple_spend_p2sh(all_from_pubkeys, from_privkeys_to_use, to_address, to_sat
from_privkeys_to_use is a list of all privkeys that will be used to sign the tx (and no more).
If the address is a 2-of-3 multisig and you supply 1 (or 3) from_privkeys_to_use this will break.

Fee preferences can be passed as strings with the values 'low', 'medium', or 'high'.
Transaction with zero fees are unlikely to be added to a block and hence removed from choices.

Signature takes place locally (client-side) after unsigned transaction is verified.

Returns the tx_hash of the newly broadcast tx.
Expand Down Expand Up @@ -1810,6 +1817,7 @@ def simple_spend_p2sh(all_from_pubkeys, from_privkeys_to_use, to_address, to_sat
verify_tosigntx=False, # will verify in next step
include_tosigntx=True,
api_key=api_key,
preference=preference if preference in ('high', 'medium', 'low') else 'high'
)
logger.info('unsigned_tx: %s' % unsigned_tx)

Expand Down
Loading