本文整理匯總了Python中bitcoin.wallet方法的典型用法代碼示例。如果您正苦於以下問題:Python bitcoin.wallet方法的具體用法?Python bitcoin.wallet怎麽用?Python bitcoin.wallet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bitcoin
的用法示例。
在下文中一共展示了bitcoin.wallet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getreceivedbyaddress
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def getreceivedbyaddress(self, addr, minconf=1):
"""Return total amount received by given a (wallet) address
Get the amount received by <address> in transactions with at least
[minconf] confirmations.
Works only for addresses in the local wallet; other addresses will
always show zero.
addr - The address. (CBitcoinAddress instance)
minconf - Only include transactions confirmed at least this many times.
(default=1)
"""
r = self._call('getreceivedbyaddress', str(addr), minconf)
return int(r * COIN)
示例2: listunspent
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def listunspent(self, minconf=0, maxconf=9999999, addrs=None):
"""Return unspent transaction outputs in wallet
Outputs will have between minconf and maxconf (inclusive)
confirmations, optionally filtered to only include txouts paid to
addresses in addrs.
"""
r = None
if addrs is None:
r = self._call('listunspent', minconf, maxconf)
else:
addrs = [str(addr) for addr in addrs]
r = self._call('listunspent', minconf, maxconf, addrs)
r2 = []
for unspent in r:
unspent['outpoint'] = COutPoint(lx(unspent['txid']), unspent['vout'])
del unspent['txid']
del unspent['vout']
unspent['address'] = CBitcoinAddress(unspent['address'])
unspent['scriptPubKey'] = CScript(unhexlify(unspent['scriptPubKey']))
unspent['amount'] = int(unspent['amount'] * COIN)
r2.append(unspent)
return r2
示例3: get_wallet
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def get_wallet(cls, private_key: str=None, encrypted_private_key: bytes=None, password: str=None) ->BitcoinWallet:
'''
Returns wallet object.
Args:
private_key (str): hex string with wallet's secret key
encrypted_private_key (bytes): private key encrypted with password
password (str): password for decrypting an encrypted private key
Returns:
BitcoinWallet: wallet object
Example:
>>> from clove.network import BitcoinTestNet
>>> network = BitcoinTestNet()
>>> wallet = network.get_wallet('cV8FDJu3JhLED2D7q5L7FwLCus69TajYGEnTWEbNqhzzV9WxMBE7')
>>> wallet.address
'mtUXc6UJTiwb5FdoEJ2hzR8R1yUrcj3hcn'
Note:
If private_key has not been provided then a new wallet will be generated just like via `get_new_wallet()`.
'''
return BitcoinWallet(private_key, encrypted_private_key, password)
示例4: is_valid_address
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def is_valid_address(cls, address: str) -> bool:
'''
Checks if wallet address is valid for this network.
Args:
address (str): wallet address to check
Returns:
bool: True if address is valued, False otherwise
Example:
>>> from clove.network import Bitcoin
>>> network = Bitcoin()
>>> network.is_valid_address('13iNsKgMfVJQaYVFqp5ojuudxKkVCMtkoa')
True
>>> network.is_valid_address('msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM')
False
'''
try:
CBitcoinAddress(address)
except (CBitcoinAddressError, Base58ChecksumError, InvalidBase58Error):
return False
return True
示例5: getbalance
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def getbalance(self, account='*', minconf=1):
"""Get the balance
account - The selected account. Defaults to "*" for entire wallet. It
may be the default account using "".
minconf - Only include transactions confirmed at least this many times.
(default=1)
"""
r = self._call('getbalance', account, minconf)
return int(r*COIN)
示例6: gettransaction
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def gettransaction(self, txid):
"""Get detailed information about in-wallet transaction txid
Raises IndexError if transaction not found in the wallet.
FIXME: Returned data types are not yet converted.
"""
try:
r = self._call('gettransaction', b2lx(txid))
except JSONRPCError as ex:
raise IndexError('%s.getrawtransaction(): %s (%d)' %
(self.__class__.__name__, ex.error['message'], ex.error['code']))
return r
示例7: importaddress
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def importaddress(self, addr, label='', rescan=True):
"""Adds an address or pubkey to wallet without the associated privkey."""
addr = str(addr)
r = self._call('importaddress', addr, label, rescan)
return r
示例8: get_new_wallet
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def get_new_wallet(cls) -> BitcoinWallet:
'''
Generates a new wallet.
Example:
>>> wallet = network.get_new_wallet()
>>> wallet.address
'mrkLKxgzfQk4dgFrfaoVYjeTkXxCfKyz1q'
'''
return cls.get_wallet()
示例9: atomic_swap
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def atomic_swap(
self,
sender_address: str,
recipient_address: str,
value: float,
solvable_utxo: list=None,
secret_hash: str=None,
) -> Optional[BitcoinAtomicSwapTransaction]:
'''
Creates atomic swap unsigned transaction object.
Args:
sender_address (str): wallet address of the sender
recipient_address (str): wallet address of the recipient
value (float): amount to swap
solvable_utxo (list): optional list of UTXO objects. If None then it will try to find UTXO automatically
by using the `get_utxo` method.
secret_hash (str): optional secret hash to be used in transaction. If None then the new hash
will be generated.
Returns:
BitcoinAtomicSwapTransaction, None: unsigned Atomic Swap transaction object or None if something went wrong
Example:
>>> from clove.network import BitcoinTestNet
>>> network = BitcoinTestNet()
>>> network.atomic_swap('msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM', 'mmJtKA92Mxqfi3XdyGReza69GjhkwAcBN1', 2.4)
<clove.network.bitcoin.transaction.BitcoinAtomicSwapTransaction at 0x7f989439d630>
'''
if not solvable_utxo:
solvable_utxo = self.get_utxo(sender_address, value)
if not solvable_utxo:
logger.error(f'Cannot get UTXO for address {sender_address}')
return
transaction = BitcoinAtomicSwapTransaction(
self, sender_address, recipient_address, value, solvable_utxo, secret_hash
)
transaction.create_unsigned_transaction()
return transaction
示例10: _as_any_address
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def _as_any_address(address):
try:
result = colorcore.addresses.Base58Address.from_string(address)
return result.address
except (bitcoin.wallet.CBitcoinAddressError, bitcoin.base58.Base58ChecksumError):
raise colorcore.routing.ControllerError("The address {} is an invalid address.".format(address))
示例11: _as_openassets_address
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def _as_openassets_address(self, address):
try:
result = colorcore.addresses.Base58Address.from_string(address)
if result.namespace != self.configuration.namespace:
raise colorcore.routing.ControllerError("The address {} is not an asset address.".format(address))
return result.address
except (bitcoin.wallet.CBitcoinAddressError, bitcoin.base58.Base58ChecksumError):
raise colorcore.routing.ControllerError("The address {} is an invalid address.".format(address))
示例12: script_to_address
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def script_to_address(script):
"""
Converts an output script to an address if possible, or None otherwise.
:param bytes script: The script to convert.
:return: The converted value.
:rtype: CBitcoinAddress | None
"""
try:
return bitcoin.wallet.CBitcoinAddress.from_scriptPubKey(bitcoin.core.CScript(script))
except bitcoin.wallet.CBitcoinAddressError:
return None
示例13: getbalance
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def getbalance(self, account='*', minconf=1, include_watchonly=False):
"""Get the balance
account - The selected account. Defaults to "*" for entire wallet. It
may be the default account using "".
minconf - Only include transactions confirmed at least this many times.
(default=1)
include_watchonly - Also include balance in watch-only addresses (see 'importaddress')
(default=False)
"""
r = self._call('getbalance', account, minconf, include_watchonly)
return int(r*COIN)
示例14: gettransaction
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def gettransaction(self, txid):
"""Get detailed information about in-wallet transaction txid
Raises IndexError if transaction not found in the wallet.
FIXME: Returned data types are not yet converted.
"""
try:
r = self._call('gettransaction', b2lx(txid))
except InvalidAddressOrKeyError as ex:
raise IndexError('%s.getrawtransaction(): %s (%d)' %
(self.__class__.__name__, ex.error['message'], ex.error['code']))
return r
示例15: do_mesh_sendtoaddress
# 需要導入模塊: import bitcoin [as 別名]
# 或者: from bitcoin import wallet [as 別名]
def do_mesh_sendtoaddress(self, rem) :
"""
Create a signed transaction and broadcast it over the connected mesh device. The transaction
spends some amount of satoshis to the specified address from the local bitcoind wallet and selected network.
Usage: mesh_sendtoaddress ADDRESS SATS NETWORK(m|t)
eg. txTenna> mesh_sendtoaddress 2N4BtwKZBU3kXkWT7ZBEcQLQ451AuDWiau2 13371337 t
"""
try:
proxy = bitcoin.rpc.Proxy()
(addr, sats, network) = rem.split()
# Create the txout. This time we create the scriptPubKey from a Bitcoin
# address.
txout = CMutableTxOut(sats, CBitcoinAddress(addr).to_scriptPubKey())
# Create the unsigned transaction.
unfunded_transaction = CMutableTransaction([], [txout])
funded_transaction = proxy.fundrawtransaction(unfunded_transaction)
signed_transaction = proxy.signrawtransaction(funded_transaction["tx"])
txhex = b2x(signed_transaction["tx"].serialize())
txid = b2lx(signed_transaction["tx"].GetTxid())
print("sendtoaddress_mesh (tx, txid, network): " + txhex + ", " + txid, ", " + network)
# broadcast over mesh
self.do_mesh_broadcast_rawtx( txhex + " " + txid + " " + network)
except Exception: # pylint: disable=broad-except
traceback.print_exc()
try :
# lock UTXOs used to fund the tx if broadcast successful
vin_outpoints = set()
for txin in funded_transaction["tx"].vin:
vin_outpoints.add(txin.prevout)
## json_outpoints = [{'txid':b2lx(outpoint.hash), 'vout':outpoint.n}
## for outpoint in vin_outpoints]
## print(str(json_outpoints))
proxy.lockunspent(False, vin_outpoints)
except Exception: # pylint: disable=broad-except
## TODO: figure out why this is happening
print("RPC timeout after calling lockunspent")