API¶
clove.block_explorer.base¶
clove.block_explorer.blockcypher¶
-
class
clove.block_explorer.blockcypher.
BlockcypherAPI
[source]¶ Bases:
clove.block_explorer.base.BaseAPI
Adapter class for blockcypher.com
-
api_url
= 'https://api.blockcypher.com'¶ Base url for block explorer API.
-
classmethod
blockcypher_url
() → str[source]¶ This method returns a full API url for a given network.
Returns: full API url Return type: str
-
classmethod
extract_secret_from_redeem_transaction
(contract_address: str) → Union[str, NoneType][source]¶ Extracting secret from redeem transaction based on contract address.
Parameters: contract_address (str) – address of the contract atomic swap contract Returns: Secret string or None if contract wasn’t redeemed yet. Return type: str, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.extract_secret_from_redeem_transaction('2N7Gxryn4dD1mdyGM3DMxMAwD7k3RBTJ1gP') 90f6b9b9a34acb486654b3e9cdc02cce0b8e40a8845924ffda68453ac2477d20
-
classmethod
get_balance
(wallet_address: str) → Union[float, NoneType][source]¶ Returns wallet balance without unconfirmed transactions.
Parameters: wallet_address (str) – wallet address Returns: account balance converted from base units or None if something went wrong Return type: float, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.get_balance('msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM') 4.22188744
-
classmethod
get_fee
() → Union[float, NoneType][source]¶ Getting actual fee per kb
Returns: actual fee per kb or None if eg. API is not responding Return type: float, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.get_fee() 0.00024538
-
classmethod
get_first_vout_from_tx_json
(tx_json: dict) → bitcoin.core.CTxOut[source]¶ Adapter method for returning first vout.
Parameters: tx_json (dict) – dictionary with transaction details Returns: transaction output Return type: CTxOut
-
classmethod
get_latest_block
() → Union[int, NoneType][source]¶ Returns the number of the latest block.
Returns: number of the latest block or None if API is not working Return type: int, None Example
>>> from clove.network import Bitcoin >>> network = Bitcoin() >>> network.get_latest_block() 544989
-
classmethod
get_transaction
(tx_address: str) → Union[dict, NoneType][source]¶ Getting transaction details.
Parameters: tx_address (str) – transaction address Returns: dictionary with transaction details or None if transaction doesn’t exist Return type: dict, None Example
>>> from clove.network import Bitcoin >>> network = Bitcoin() >>> network.get_transaction('a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64') {'blockhash': '0000000000000000000e2d8d964b4da69f2f30b79aaa58597848719bf0b86a1b', 'blockheight': 544987, 'blocktime': 1539068621, 'confirmations': 3, 'fees': 0.0011, 'locktime': 0, 'size': 192, 'time': 1539068621, 'txid': 'a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64', 'valueIn': 0.60725408, 'valueOut': 0.60615408, 'version': 1, 'vin': [{'addr': '163o7ig87TnUnp1QF1rBrsjU1uhfEW9nNU', 'doubleSpentTxID': None, 'n': 0, 'scriptSig': { 'asm': '3045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae[ALL] 03b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f', # noqa: E50 'hex': '483045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae012103b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f'}, # noqa: E501 'sequence': 4294967295, 'txid': '101cc115cc6882e1fd150c35efd056d18a73c12a3321c406960844561922dfc0', 'value': 0.60725408, 'valueSat': 60725408, 'vout': 0}], 'vout': [{'n': 0, 'scriptPubKey': {'addresses': ['13xMGnw7sTTVXT26YpfZQkk2rvuvJFoMvi'], 'asm': 'OP_DUP OP_HASH160 20680d49e72e1de6af9a0180b3293f2cbd0d0666 OP_EQUALVERIFY OP_CHECKSIG', 'hex': '76a91420680d49e72e1de6af9a0180b3293f2cbd0d066688ac', 'type': 'pubkeyhash'}, 'spentHeight': None, 'spentIndex': None, 'spentTxId': None, 'value': '0.60615408'}]}
-
classmethod
get_transaction_url
(tx_hash: str) → str[source]¶ Returns transaction url for a given transaction hash in block explorer.
Parameters: tx_hash (str) – transaction hash Returns: Url to transaction Return type: str
-
classmethod
get_utxo
(address: str, amount: float) → Union[list, NoneType][source]¶ Getting list of UTXO objects.
Parameters: - address (str) – wallet address to look for UTXO
- amount (float) – minimum value that should be satisfied in UTXO objects
Returns: list of UTXO objects or None it there was not enough UTXO
Return type: list, None
Example
>>> from clove.network import Litecoin >>> network = Litecoin() >>> network.get_utxo(address='LUAn5PWmsPavgz32mGkqsUuAKncftS37Jq', amount=0.01) [ Utxo(tx_id='0cd90567497823097d03464b4b2d08dd659f1c5621dd55e9540bc9bcd3e191ec', vout='0', value='0.00976168', tx_script='76a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac', wallet=None, secret=None, refund=False), # noqa: E501 Utxo(tx_id='a5c027027c695f403fe570850e35ffd44bb28479ecaaee039372015fe0aae7b2', vout='0', value='0.00097114', tx_script='76a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac', wallet=None, secret=None, refund=False) # noqa: E501 ]
-
clove.block_explorer.cryptoid¶
-
class
clove.block_explorer.cryptoid.
CryptoidAPI
[source]¶ Bases:
clove.block_explorer.base.BaseAPI
-
api_url
= 'https://chainz.cryptoid.info'¶ Base url for block explorer API.
-
classmethod
cryptoid_url
()[source]¶ This method returns a full API url for a given network.
Returns: full API url Return type: str
-
classmethod
extract_secret_from_redeem_transaction
(contract_address: str) → Union[str, NoneType][source]¶ Extracting secret from redeem transaction based on contract address.
Parameters: contract_address (str) – address of the contract atomic swap contract Returns: Secret string or None if contract wasn’t redeemed yet. Return type: str, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.extract_secret_from_redeem_transaction('2N7Gxryn4dD1mdyGM3DMxMAwD7k3RBTJ1gP') 90f6b9b9a34acb486654b3e9cdc02cce0b8e40a8845924ffda68453ac2477d20
-
classmethod
get_balance
(wallet_address: str) → Union[float, NoneType][source]¶ Returns wallet balance without unconfirmed transactions.
Parameters: wallet_address (str) – wallet address Returns: account balance converted from base units or None if something went wrong Return type: float, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.get_balance('msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM') 4.22188744
-
classmethod
get_fee
(tx_limit: int = 5) → Union[float, NoneType][source]¶ Getting actual fee per kb
Parameters: tx_limit (int) – counting fee based on given number of last transactions Returns: actual fee per kb or None if eg. API is not responding Return type: float, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.get_fee() 0.00024538
-
classmethod
get_first_vout_from_tx_json
(tx_json: dict) → bitcoin.core.CTxOut[source]¶ Adapter method for returning first vout.
Parameters: tx_json (dict) – dictionary with transaction details Returns: transaction output Return type: CTxOut
-
classmethod
get_latest_block
() → Union[int, NoneType][source]¶ Returns the number of the latest block.
Returns: number of the latest block Return type: int Example
>>> from clove.network import Bitcoin >>> network = Bitcoin() >>> network.get_latest_block() 544989
-
classmethod
get_transaction
(tx_address: str) → Union[dict, NoneType][source]¶ Getting transaction details.
Parameters: tx_address (str) – transaction address Returns: dictionary with transaction details or None if transaction doesn’t exist Return type: dict, None Example
>>> from clove.network import Bitcoin >>> network = Bitcoin() >>> network.get_transaction('a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64') {'blockhash': '0000000000000000000e2d8d964b4da69f2f30b79aaa58597848719bf0b86a1b', 'blockheight': 544987, 'blocktime': 1539068621, 'confirmations': 3, 'fees': 0.0011, 'locktime': 0, 'size': 192, 'time': 1539068621, 'txid': 'a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64', 'valueIn': 0.60725408, 'valueOut': 0.60615408, 'version': 1, 'vin': [{'addr': '163o7ig87TnUnp1QF1rBrsjU1uhfEW9nNU', 'doubleSpentTxID': None, 'n': 0, 'scriptSig': { 'asm': '3045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae[ALL] 03b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f', # noqa: E50 'hex': '483045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae012103b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f'}, # noqa: E501 'sequence': 4294967295, 'txid': '101cc115cc6882e1fd150c35efd056d18a73c12a3321c406960844561922dfc0', 'value': 0.60725408, 'valueSat': 60725408, 'vout': 0}], 'vout': [{'n': 0, 'scriptPubKey': {'addresses': ['13xMGnw7sTTVXT26YpfZQkk2rvuvJFoMvi'], 'asm': 'OP_DUP OP_HASH160 20680d49e72e1de6af9a0180b3293f2cbd0d0666 OP_EQUALVERIFY OP_CHECKSIG', 'hex': '76a91420680d49e72e1de6af9a0180b3293f2cbd0d066688ac', 'type': 'pubkeyhash'}, 'spentHeight': None, 'spentIndex': None, 'spentTxId': None, 'value': '0.60615408'}]}
-
classmethod
get_transaction_url
(tx_hash: str) → Union[str, NoneType][source]¶ Returns transaction url for a given transaction hash in block explorer.
Parameters: tx_hash (str) – transaction hash Returns: Url to transaction Return type: str
-
classmethod
get_utxo
(address: str, amount: float) → Union[list, NoneType][source]¶ Getting list of UTXO objects.
Parameters: - address (str) – wallet address to look for UTXO
- amount (float) – minimum value that should be satisfied in UTXO objects
Returns: list of UTXO objects or None it there was not enough UTXO
Return type: list, None
Example
>>> from clove.network import Litecoin >>> network = Litecoin() >>> network.get_utxo(address='LUAn5PWmsPavgz32mGkqsUuAKncftS37Jq', amount=0.01) [ Utxo(tx_id='0cd90567497823097d03464b4b2d08dd659f1c5621dd55e9540bc9bcd3e191ec', vout='0', value='0.00976168', tx_script='76a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac', wallet=None, secret=None, refund=False), # noqa: E501 Utxo(tx_id='a5c027027c695f403fe570850e35ffd44bb28479ecaaee039372015fe0aae7b2', vout='0', value='0.00097114', tx_script='76a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac', wallet=None, secret=None, refund=False) # noqa: E501 ]
-
clove.block_explorer.etherscan¶
-
class
clove.block_explorer.etherscan.
EtherscanAPI
[source]¶
clove.block_explorer.insight¶
-
class
clove.block_explorer.insight.
InsightAPIv4
[source]¶ Bases:
clove.block_explorer.base.BaseAPI
Wrapper for block explorers that runs on Insight API engine.
Docs: https://github.com/bitpay/insight-api/
-
api_url
= None¶ URL for Insight API
-
classmethod
extract_secret_from_redeem_transaction
(contract_address: str) → Union[str, NoneType][source]¶ Extracting secret from redeem transaction based on contract address.
Parameters: contract_address (str) – address of the contract atomic swap contract Returns: Secret string or None if contract wasn’t redeemed yet. Return type: str, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.extract_secret_from_redeem_transaction('2N7Gxryn4dD1mdyGM3DMxMAwD7k3RBTJ1gP') 90f6b9b9a34acb486654b3e9cdc02cce0b8e40a8845924ffda68453ac2477d20
-
classmethod
get_balance
(wallet_address: str) → Union[float, NoneType][source]¶ Returns wallet balance without unconfirmed transactions.
Parameters: wallet_address (str) – wallet address Returns: amount converted from base units or None if something went wrong Return type: float, None Example
>>> from clove.network import Ravencoin >>> r = Ravencoin() >>> r.get_balance('RM7w75BcC21LzxRe62jy8JhFYykRedqu8k') >>> 18.99
-
classmethod
get_fee
() → Union[float, NoneType][source]¶ Getting actual fee per kb
Returns: actual fee per kb or None if eg. API is not responding Return type: float, None Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.get_fee() 0.00024538
-
classmethod
get_first_vout_from_tx_json
(tx_json: dict) → bitcoin.core.CTxOut[source]¶ Adapter method for returning first vout.
Parameters: tx_json (dict) – dictionary with transaction details Returns: transaction output Return type: CTxOut
-
classmethod
get_latest_block
() → Union[int, NoneType][source]¶ Returns the number of the latest block.
Returns: number of the latest block or None if API is not working Return type: int, None Example
>>> from clove.network import Bitcoin >>> network = Bitcoin() >>> network.get_latest_block() 544989
-
classmethod
get_transaction
(tx_address: str) → Union[dict, NoneType][source]¶ Getting transaction details.
Parameters: tx_address (str) – transaction address Returns: dictionary with transaction details or None if transaction doesn’t exist Return type: dict, None Example
>>> from clove.network import Bitcoin >>> network = Bitcoin() >>> network.get_transaction('a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64') {'blockhash': '0000000000000000000e2d8d964b4da69f2f30b79aaa58597848719bf0b86a1b', 'blockheight': 544987, 'blocktime': 1539068621, 'confirmations': 3, 'fees': 0.0011, 'locktime': 0, 'size': 192, 'time': 1539068621, 'txid': 'a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64', 'valueIn': 0.60725408, 'valueOut': 0.60615408, 'version': 1, 'vin': [{'addr': '163o7ig87TnUnp1QF1rBrsjU1uhfEW9nNU', 'doubleSpentTxID': None, 'n': 0, 'scriptSig': { 'asm': '3045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae[ALL] 03b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f', # noqa: E50 'hex': '483045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae012103b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f'}, # noqa: E501 'sequence': 4294967295, 'txid': '101cc115cc6882e1fd150c35efd056d18a73c12a3321c406960844561922dfc0', 'value': 0.60725408, 'valueSat': 60725408, 'vout': 0}], 'vout': [{'n': 0, 'scriptPubKey': {'addresses': ['13xMGnw7sTTVXT26YpfZQkk2rvuvJFoMvi'], 'asm': 'OP_DUP OP_HASH160 20680d49e72e1de6af9a0180b3293f2cbd0d0666 OP_EQUALVERIFY OP_CHECKSIG', 'hex': '76a91420680d49e72e1de6af9a0180b3293f2cbd0d066688ac', 'type': 'pubkeyhash'}, 'spentHeight': None, 'spentIndex': None, 'spentTxId': None, 'value': '0.60615408'}]}
-
classmethod
get_transaction_url
(tx_hash: str) → Union[str, NoneType][source]¶ Returns URL for a given transaction in block explorer.
Parameters: tx_hash (str) – transaction hash Returns: URL for transaction in block explorer or None if there is no block explorer Return type: str, None Example
>>> from clove.network import Ravencoin >>> r = Ravencoin() >>> r.get_transaction_url('8a673e9fcf5ea469e7c4180846834905e8d4c0f16c6e6ab9531efbb9112bc5e1') 'https://ravencoin.network/tx/8a673e9fcf5ea469e7c4180846834905e8d4c0f16c6e6ab9531efbb9112bc5e1'
-
classmethod
get_utxo
(address, amount) → Union[list, NoneType][source]¶ Getting list of UTXO objects.
Parameters: - address (str) – wallet address to look for UTXO
- amount (float) – minimum value that should be satisfied in UTXO objects
Returns: list of UTXO objects or None it there was not enough UTXO
Return type: list, None
Example
>>> from clove.network import Litecoin >>> network = Litecoin() >>> network.get_utxo(address='LUAn5PWmsPavgz32mGkqsUuAKncftS37Jq', amount=0.01) [ Utxo(tx_id='0cd90567497823097d03464b4b2d08dd659f1c5621dd55e9540bc9bcd3e191ec', vout='0', value='0.00976168', tx_script='76a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac', wallet=None, secret=None, refund=False), # noqa: E501 Utxo(tx_id='a5c027027c695f403fe570850e35ffd44bb28479ecaaee039372015fe0aae7b2', vout='0', value='0.00097114', tx_script='76a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac', wallet=None, secret=None, refund=False) # noqa: E501 ]
-
classmethod
publish
(raw_transaction: str) → str[source]¶ Publish signed transaction via block explorer API.
Parameters: raw_transaction (str) – signed transaction Returns: transaction address if transaction was published Return type: str Raises: ValueError
– if something went wrong
-
ui_url
= None¶ URL for Insight UI
-
clove.network.base¶
-
class
clove.network.base.
BaseNetwork
[source]¶ Bases:
object
Class for shared properties and methods for Bitcoin and Ethereum network.
-
bitcoin_based
= None¶ Flag for Bitcoin-based networks.
-
blockexplorer_tx
= None¶ Url of the transaction in block explorer (format string)
-
default_symbol
¶ Returns default (first) symbol for networks with multiple symbols.
Returns: network symbol Return type: str Example
>>> from clove.network import Bitcoin >>> bitcoin_network = Bitcoin() >>> bitcoin_network.default_symbol 'BTC'
Note
This property can return None if symbols are not declared in the network definition.
-
ethereum_based
= None¶ Flag for Ethereum-based networks.
-
classmethod
get_network_by_symbol
(symbol: str)[source]¶ Returns network instance by its symbol.
Parameters: symbol (str) – network symbol Returns: Network object Raises: RuntimeError
– if there is no network with given symbol.Example
>>> from clove.network.base import BaseNetwork >>> BaseNetwork.get_network_by_symbol('BTC') <clove.network.bitcoin.Bitcoin at 0x7f5a84b233c8>
-
name
= None¶ Network name.
-
networks
= {}¶ Placeholder for symbol-network mapping.
-
symbols
= ()¶ Tuple with network symbols (some networks may have multiple symbols, eg. Bitcoin).
-
testnet
= False¶ Flag for test networks.
-
clove.network.bitcoin.base¶
-
class
clove.network.bitcoin.base.
BitcoinBaseNetwork
[source]¶ Bases:
clove.network.base.BaseNetwork
-
atomic_swap
(sender_address: str, recipient_address: str, value: float, solvable_utxo: list = None, secret_hash: str = None) → Union[clove.network.bitcoin.transaction.BitcoinAtomicSwapTransaction, NoneType][source]¶ Creates atomic swap unsigned transaction object.
Parameters: - 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: unsigned Atomic Swap transaction object or None if something went wrong
Return type: Example
>>> from clove.network import BitcoinTestNet >>> network = BitcoinTestNet() >>> network.atomic_swap('msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM', 'mmJtKA92Mxqfi3XdyGReza69GjhkwAcBN1', 2.4) <clove.network.bitcoin.transaction.BitcoinAtomicSwapTransaction at 0x7f989439d630>
-
audit_contract
(contract: str, raw_transaction: Union[str, NoneType] = None, transaction_address: Union[str, NoneType] = None) → clove.network.bitcoin.contract.BitcoinContract[source]¶ Getting details about an Atomic Swap contract.
Parameters: - contract (str) – contract definition (hex string)
- raw_transaction (str) – hex string with raw transaction
- transaction_address (str) – hex string with transaction address which created an Atomic Swap
Returns: contract object
Return type: Example
>>> from clove.network import Litecoin >>> network = Litecoin() >>> network.audit_contract( contract='63a61450314a793bf317665ecdc54c2e843bb106aeee158876a91485c0522f6e23beb11cc3d066cd20ed732648a4e66704926db75bb17576a914621f617c765c3caa5ce1bb67f6a3e51382b8da296888ac', # noqa: E501 transaction_address='09a60dc3fafe6ba058b2a140457df1c3b446602595d47deed641cb635ffd25aa' ) <clove.network.bitcoin.contract.BitcoinContract at 0x7f98870db978>
-
base58_prefixes
= {}¶ Dictionary of different prefixes
-
bitcoin_based
= True¶ Flag for bitcoin-based networks
-
blacklist_nodes
= {}¶ List of dead nodes
-
broadcast_transaction
(raw_transaction: str) → Union[str, NoneType][source]¶ Sends given transaction to connected node.
Parameters: raw_transaction (str) – hex string containing signed transaction Returns: transaction address if transaction was sent, None otherwise. Return type: str, None
-
capture_messages
(expected_message_types: list, timeout: int = 20, buf_size: int = 1024, ignore_empty: bool = False) → list[source]¶ Method for receiving messages from network nodes.
Parameters: - expected_message_types (list) – list of message types to search for
- timeout (int) – timeout for waiting for messages
- buf_size (int) – buffer size that is going to be used for receiving messages
- ignore_empty (bool) – flag for ignoring errors if the message that we’re looking for wasn’t found. Eg. this flag can be set to True when looking for reject messages because the absence of the reject message is not an error.
Returns: list of received messages or None if none or not all expected message types were found
Return type: list, None
Example
>>> from bitcoin.messages import msg_verack, msg_version >>> network.capture_messages([msg_version, msg_verack])
-
connect
() → Union[str, NoneType][source]¶ Connects to some node from the network.
Returns: node IP address or domain, None if doesn’t connect to any node Return type: str, None Example
>>> network.connect() '198.251.83.19' >>> network.connection <socket.socket fd=12, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=('10.93.5.21', 54300), raddr=('198.251.83.19', 18333)> # noqa: E501
-
connection
= None¶ Connection object
-
create_connection
(node: str, timeout=2) → Union[socket.socket, NoneType][source]¶ Establish connection to a given node.
Parameters: - node (str) – node domain or IP address
- timeout (int) – number of seconds to wait before raising timeout
Returns: socket connection
Return type: socket.socket
Example
>>> network.create_connection('104.248.185.143') <socket.socket fd=11, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=('10.93.5.21', 36086), raddr=('104.248.185.143', 18333)> # noqa: E501
-
static
deserialize_raw_transaction
(raw_transaction: str) → bitcoin.core.CTransaction[source]¶ Checking if transaction can be deserialized (is not corrupted).
Parameters: raw_transaction (str) – transaction to check Returns: transaction object Return type: CTransaction Raises: ImpossibleDeserialization
– when transaction is corruptedExample
>>> from clove.network import Litecoin >>> network = Litecoin() >>> network.deserialize_raw_transaction('0100000001aa25fd5f63cb41d6ee7dd495256046b4c3f17d4540a1b258a06bfefac30da60900000000fdff0047304402201c8869d359b5599ecffd51a96f0a8799392c98c4e15242762ba455e37b1f5d6302203f2974e9afc8d641f9363167df48e5a845a8deba1381bf5a1b549ac04718a1ac01410459cdb91eb7298bc2578dc4e7ac2109ac3cfd9dc9818795c5583e720d2114d540724bf26b4541f683ff51968db627a04eecd1f5cff615b6350dad5fb595f8adf420c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9514c5163a61450314a793bf317665ecdc54c2e843bb106aeee158876a91485c0522f6e23beb11cc3d066cd20ed732648a4e66704926db75bb17576a914621f617c765c3caa5ce1bb67f6a3e51382b8da296888ac00000000015a7b0100000000001976a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac00000000') # noqa: E501 CTransaction((CTxIn(COutPoint(lx('09a60dc3fafe6ba058b2a140457df1c3b446602595d47deed641cb635ffd25aa'), 0), CScript([x('304402201c8869d359b5599ecffd51a96f0a8799392c98c4e15242762ba455e37b1f5d6302203f2974e9afc8d641f9363167df48e5a845a8deba1381bf5a1b549ac04718a1ac01'), x('0459cdb91eb7298bc2578dc4e7ac2109ac3cfd9dc9818795c5583e720d2114d540724bf26b4541f683ff51968db627a04eecd1f5cff615b6350dad5fb595f8adf4'), x('c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9'), 1, x('63a61450314a793bf317665ecdc54c2e843bb106aeee158876a91485c0522f6e23beb11cc3d066cd20ed732648a4e66704926db75bb17576a914621f617c765c3caa5ce1bb67f6a3e51382b8da296888ac')]), 0x0),), (CTxOut(0.00097114*COIN, CScript([OP_DUP, OP_HASH160, x('85c0522f6e23beb11cc3d066cd20ed732648a4e6'), OP_EQUALVERIFY, OP_CHECKSIG])),), 0, 1, CTxWitness()) # noqa: E501
-
classmethod
extract_secret
(raw_transaction: str = None, scriptsig: str = None) → str[source]¶ Extracting secret from Alice redeem transaction (first redeem in the Atomic Swao).
Parameters: - raw_transaction (str) – raw transaction to extract secret from
- scriptSig (str) – value of the scriptSig field from the first vin
Returns: transaction secret
Return type: str
Raises: ValueError
– if something goes wrongExample
>>> from clove.network import Litecoin >>> network = Litecoin() >>> network.extract_secret(raw_transaction='0100000001aa25fd5f63cb41d6ee7dd495256046b4c3f17d4540a1b258a06bfefac30da60900000000fdff0047304402201c8869d359b5599ecffd51a96f0a8799392c98c4e15242762ba455e37b1f5d6302203f2974e9afc8d641f9363167df48e5a845a8deba1381bf5a1b549ac04718a1ac01410459cdb91eb7298bc2578dc4e7ac2109ac3cfd9dc9818795c5583e720d2114d540724bf26b4541f683ff51968db627a04eecd1f5cff615b6350dad5fb595f8adf420c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9514c5163a61450314a793bf317665ecdc54c2e843bb106aeee158876a91485c0522f6e23beb11cc3d066cd20ed732648a4e66704926db75bb17576a914621f617c765c3caa5ce1bb67f6a3e51382b8da296888ac00000000015a7b0100000000001976a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac00000000') # noqa: E501 'c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9'
>>> network.extract_secret(scriptsig='0c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9514c5163a61450314a793bf317665ecdc54c2e843bb106aeee158876a91485c0522f6e23beb11cc3d066cd20') # noqa: E501 'c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9'
-
filter_blacklisted_nodes
(nodes: list, max_tries_number=3) → list[source]¶ Filtering out dead nodes.
Parameters: - nodes (list) – list of nodes to filter
- max_tries_number (int) – maximum number of attempts to connect to a node (above this value node is being filtered out)
Returns: list of nodes without dead nodes
Return type: list
-
classmethod
get_current_fee_per_kb
() → Union[float, NoneType][source]¶ Getting current network fee from Clove API
Returns: current fee per kb or None if something went wrong Return type: float, None Example
>>> network.get_current_fee_per_kb() 0.01006814
-
get_current_node
() → Union[str, NoneType][source]¶ Getting address of connected node.
Returns: IP for connected node or None if there is no connection established. Return type: str, None Example
>>> network.get_current_node() '157.97.106.250'
-
classmethod
get_new_wallet
() → clove.network.bitcoin.wallet.BitcoinWallet[source]¶ Generates a new wallet.
Example
>>> wallet = network.get_new_wallet() >>> wallet.address 'mrkLKxgzfQk4dgFrfaoVYjeTkXxCfKyz1q'
-
static
get_nodes
(seed: str) → list[source]¶ Extracting nodes from seed node.
Parameters: seed (str) – seed node address Returns: list of IPs of network nodes Return type: list Example
>>> network.get_nodes('seed.testnet.bitcoin.sprovoost.nl') ['46.101.230.222', '47.97.79.7', '159.89.205.190', '163.44.175.226', '13.57.215.93', '18.191.17.25', '46.4.61.78', '104.248.185.143', '149.28.176.234', '71.13.92.62', '114.215.66.15', '178.128.244.253', '46.23.46.139', '54.37.192.136', '167.114.64.228', '159.89.128.32', '144.76.136.19', '18.212.60.14', '54.149.194.238', '52.53.159.115', '18.218.226.83']
-
classmethod
get_wallet
(private_key: str = None, encrypted_private_key: bytes = None, password: str = None) → clove.network.bitcoin.wallet.BitcoinWallet[source]¶ Returns wallet object.
Parameters: - 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: wallet object
Return type: 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().
-
classmethod
is_valid_address
(address: str) → bool[source]¶ Checks if wallet address is valid for this network.
Parameters: address (str) – wallet address to check Returns: True if address is valued, False otherwise Return type: bool Example
>>> from clove.network import Bitcoin >>> network = Bitcoin() >>> network.is_valid_address('13iNsKgMfVJQaYVFqp5ojuudxKkVCMtkoa') True >>> network.is_valid_address('msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM') False
-
message_start
= b''¶ Message prefix
-
name
= None¶ Network name
-
nodes
= ()¶ Tuple with nodes addresses or IPs
-
port
= None¶ Port number used by network nodes
-
protocol_version
= None¶ Protocol version number used by network nodes
-
publish
(raw_transaction: str) → Union[str, NoneType][source]¶ Method for publishing transactions.
Parameters: raw_transaction (str) – hex string containing signed transaction Returns: transaction address or None if transaction wasn’t published Return type: str, None Example
>>> raw_transaction = '010000000184a38a4e8743964249665fb241fbd3...35b' >>> network.publish(raw_transaction) 70eefae0106b787e592e12914e4040efd8181dd299fa314d8f66da6a95cd1cfe
-
reset_connection
()[source]¶ Disconnection from node if connected and clearing the blacklisted nodes.
-
seeds
= ()¶ Tuple with seed nodes addresses
-
send_inventory
(serialized_transaction) → Union[bitcoin.messages.msg_getdata, NoneType][source]¶ Sends inventory message with given serialized transaction to connected node.
Returns: get data request or None if something went wrong Return type: msg_getdata, None Note
This method is used by broadcast_transaction to inform connected node about existence of the new transaction.
-
send_message
(msg: object, timeout: int = 2) → bool[source]¶ Sends given message to the connected node.
Parameters: - msg (obj) – bitcoin message object eg bitcoin.messages.msg_version or bitcoin.messages.msg_tx
- timeout (int) – timeout for communication with connected node
Returns: True if the message was sent, False otherwise.
Return type: bool
Example
>>> from bitcoin.messages import msg_ping >>> network.send_message(msg_ping()) True
-
send_ping
(timeout: int = 1) → bool[source]¶ Sends ping message and tries to capture pong message.
Parameters: timeout (int) – timeout for communication with connected node Returns: True if the message was sent, False otherwise. Return type: bool Example
>>> network.send_ping() True
-
send_pong
(ping: bitcoin.messages.msg_ping, timeout: int = 1) → bool[source]¶ Sends pong message in response to ping message.
Parameters: - ping (bitcoin.messages.msg_ping) – ping message that where received
- timeout (int) – timeout for communication with connected node
Returns: True if the message was sent, False otherwise.
Return type: bool
Example
>>> network.send_pong(ping_message) True
-
send_verack
(timeout: int = 2) → bool[source]¶ Sending version acknowledge message.
Parameters: timeout (int) – timeout for communication with connected node Returns: True if the message was sent, False otherwise. Return type: bool Example
>>> network.send_verack() True
-
send_version
(timeout: int = 2) → bool[source]¶ Sending version message.
Parameters: timeout (int) – timeout for communication with connected node Returns: True if the message was sent, False otherwise. Return type: bool Example
>>> network.send_version() True
-
classmethod
split_message
(received_data: bytes) → list[source]¶ Splits received data based on start message prefix.
Parameters: received_data (bytes) – portion of received data Returns: list of messages that were found Return type: list
-
classmethod
switch_params
()[source]¶ Method for changing network parameteres.
Note
This method is used by the auto_switch_params decorator.
-
symbols
= ()¶ Tuple with network symbols
-
terminate
(node: str = None)[source]¶ Closing connection to a given node and increasing number of failed connection attempts to this node.
Parameters: node (str) – node’s IP address or domain. If the node was not given then this method will just close the existing connection. Returns: None
-
clove.network.bitcoin.contract¶
-
class
clove.network.bitcoin.contract.
BitcoinContract
(network, contract: str, raw_transaction: Union[str, NoneType] = None, transaction_address: Union[str, NoneType] = None)[source]¶ Bases:
object
Atomic Swap contract.
-
get_contract_utxo
(wallet=None, secret: str = None, refund: bool = False, contract: str = None) → clove.network.bitcoin.utxo.Utxo[source]¶ Creating UTXO object from contract.
Parameters: - wallet (obj) – wallet object
- secret (str) – tranaction secret (used to redeem contract)
- refund (bool) – flag used for refund transactions
- contract (str) – hex string with contract definition
Returns: Unspent transaction output object
Return type:
-
static
is_valid_contract_script
(script_ops) → bool[source]¶ Checking if contract script is an Atomic Swap contract.
-
participate
(symbol: str, sender_address: str, recipient_address: str, value: float, utxo: list = None, token_address: str = None)[source]¶ Method for creating a second Atomic Swap transaction based on the secret hash from the current contract.
Parameters: - symbol (str) – network symbol
- sender_address (str) – wallet address of the transaction creator
- recipient_address (str) – wallet address of the transaction recipient
- value (float) – amount to be send
- utxo (list) – list of UTXO objects. In None UTXO will be gathered automatically if needed (for bitcoin-based networks)
- token_address (str) – address of the token contract if we want to use a token
Returns: - Atomic Swap transaction object
or None if something went wrong.
Return type: BitcoinAtomicSwapTransaction, EthereumAtomicSwapTransaction, None
-
redeem
(wallet, secret: str) → clove.network.bitcoin.transaction.BitcoinTransaction[source]¶ Creates transaction that can redeem a contract.
Parameters: - wallet (obj) – wallet object of the Atomic Swap contract recipient
- secret (str) – transaction secret that should match the contract secret hash (after hashing)
Returns: unsigned transaction object with redeem transaction
Return type: Raises: ValueError
– if contract balance is 0
-
refund
(wallet)[source]¶ Creates transaction that can refund a contract.
Parameters: wallet (obj) – wallet object of the Atomic Swap contract creator
Returns: unsigned transaction object with refund transaction
Return type: Raises: RuntimeError
– if contract is still validValueError
– if contract balance is 0
-
transaction_address
¶ Returns transaction address.
-
clove.network.bitcoin.transaction¶
-
class
clove.network.bitcoin.transaction.
BitcoinAtomicSwapTransaction
(network, sender_address: str, recipient_address: str, value: float, solvable_utxo: list, secret_hash: str = None, tx_locktime: int = 0)[source]¶ Bases:
clove.network.bitcoin.transaction.BitcoinTransaction
Bitcoin atomic swap object.
-
init_hours
= 48¶
-
participate_hours
= 24¶
-
-
class
clove.network.bitcoin.transaction.
BitcoinTransaction
(network, recipient_address: str, value: float, solvable_utxo: list, tx_locktime: int = 0)[source]¶ Bases:
object
Bitcoin transaction object.
-
address
¶
-
calculate_fee
(add_sig_size=False)[source]¶ Calculating fee for given transaction based on transaction size and estimated fee per kb.
-
get_transaction_url
() → Union[str, NoneType][source]¶ Wrapper around the get_transaction_url method from base network.
-
raw_transaction
¶
-
sign
(default_wallet: clove.network.bitcoin.wallet.BitcoinWallet = None)[source]¶ Signing transaction using the wallet object.
-
size
¶ Returns the size of a transaction represented in bytes.
-
clove.network.bitcoin.utxo¶
clove.network.bitcoin.wallet¶
-
class
clove.network.bitcoin.wallet.
BitcoinWallet
(private_key=None, encrypted_private_key=None, password=None)[source]¶ Bases:
object
Wallet object.
-
static
decrypt_private_key
(encrypted_private_key: bytes, password: str) → str[source]¶ Decrypt private key with the password.
Parameters: - encrypted_private_key (bytes) – encrypted private key
- password (str) – password to decrypt private key with
Returns: decrypted private key
Return type: str
-
static
clove.network.ethereum.base¶
-
class
clove.network.ethereum.base.
EthereumBaseNetwork
[source]¶ Bases:
clove.network.base.BaseNetwork
Class with all the necessary ETH network information and transaction building.
-
API
= True¶ This value tells us that a given network have a block explorer API support.
-
abi
= [{'constant': False, 'inputs': [{'name': '_expiration', 'type': 'uint256'}, {'name': '_hash', 'type': 'bytes20'}, {'name': '_participant', 'type': 'address'}, {'name': '_token', 'type': 'address'}, {'name': '_isToken', 'type': 'bool'}, {'name': '_value', 'type': 'uint256'}], 'name': 'initiate', 'outputs': [], 'payable': True, 'stateMutability': 'payable', 'type': 'function'}, {'constant': True, 'inputs': [{'name': '', 'type': 'address'}, {'name': '', 'type': 'bytes20'}], 'name': 'swaps', 'outputs': [{'name': 'expiration', 'type': 'uint256'}, {'name': 'initiator', 'type': 'address'}, {'name': 'participant', 'type': 'address'}, {'name': 'value', 'type': 'uint256'}, {'name': 'isToken', 'type': 'bool'}, {'name': 'token', 'type': 'address'}, {'name': 'exists', 'type': 'bool'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [{'name': '_secret', 'type': 'bytes32'}], 'name': 'redeem', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'name': '_hash', 'type': 'bytes20'}, {'name': '_participant', 'type': 'address'}], 'name': 'refund', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'anonymous': False, 'inputs': [{'indexed': False, 'name': '_initiator', 'type': 'address'}, {'indexed': False, 'name': '_participant', 'type': 'address'}, {'indexed': False, 'name': '_expiration', 'type': 'uint256'}, {'indexed': False, 'name': '_hash', 'type': 'bytes20'}, {'indexed': False, 'name': '_token', 'type': 'address'}, {'indexed': False, 'name': '_isToken', 'type': 'bool'}, {'indexed': False, 'name': '_value', 'type': 'uint256'}], 'name': 'InitiateSwap', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': False, 'name': '_participant', 'type': 'address'}, {'indexed': False, 'name': '_hash', 'type': 'bytes20'}, {'indexed': False, 'name': '_secret', 'type': 'bytes32'}], 'name': 'RedeemSwap', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': False, 'name': '_initiator', 'type': 'address'}, {'indexed': False, 'name': '_participant', 'type': 'address'}, {'indexed': False, 'name': '_hash', 'type': 'bytes20'}], 'name': 'RefundSwap', 'type': 'event'}]¶ Application Binary Interface definition for Ethereum Atomic Swap contract.
-
approve_token
(sender_address: str, value: Union[str, decimal.Decimal], token_address: str = None) → clove.network.ethereum.transaction.EthereumTokenApprovalTransaction[source]¶ Create unsigned token approve transaction.
Parameters: - sender_address (str) – wallet address of the sender
- value (str, Decimal) – amount to swap
- token_address – address of the ERC20 token contract to swap
Returns: unsigned token approve transaction
Return type: Raises: ValueError
– if you use an incorrect token addressExample
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.approve_token('0x999F348959E611F1E9eab2927c21E88E48e6Ef45', '0.05', '0x53E546387A0d054e7FF127923254c0a679DA6DBf') # noqa: E501 <clove.network.ethereum.transaction.EthereumTokenApprovalTransaction at 0x7f286d14bc50>
-
atomic_swap
(sender_address: str, recipient_address: str, value: Union[str, decimal.Decimal], secret_hash: str = None, token_address: str = None) → clove.network.ethereum.transaction.EthereumAtomicSwapTransaction[source]¶ Return EthereumAtomicSwapTransaction object, which initiate and build transaction between sender and recipient.
Parameters: - sender_address (str) – wallet address of the sender
- recipient_address (str) – wallet address of the recipient
- value (str, Decimal) – amount to swap
- secret_hash (str) – optional secret hash to be used in transaction. If None then the new hash will be generated.
- token_address – address of the ERC20 token contract to swap
Returns: atomic swap unsigned transaction for Ethereum
Return type: Raises: ValueError
– if you use an incorrect token addressExample
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.atomic_swap('0x999F348959E611F1E9eab2927c21E88E48e6Ef45', '0xd867f293Ba129629a9f9355fa285B8D3711a9092', '0.05') # noqa: E501 <clove.network.ethereum.transaction.EthereumAtomicSwapTransaction at 0x7f286d16dba8>
-
audit_contract
(tx_address: str) → clove.network.ethereum.contract.EthereumContract[source]¶ Getting details about an Atomic Swap contract.
Parameters: transaction_address (str) – hex string with transaction address which created an Atomic Swap Returns: contract object Return type: EthereumContract Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.audit_contract('0xfe4bcc1b522923ca6f8dc2721134c7d8636b34737aeafb2d6d0868d73e226891') <clove.network.ethereum.contract.EthereumContract at 0x7f7b3fec3e80>
-
blockexplorer_tx
= None¶ Template string for the transaction address
-
contract_address
= None¶ Placeholder for a contract address
-
static
deserialize_raw_transaction
(raw_transaction: str) → ethereum.transactions.Transaction[source]¶ Deserializing raw transaction and returning Transaction object
Parameters: raw_transaction (str) – raw transaction hex string Returns: Ethereum transaction object Return type: ethereum.transactions.Transaction Raises: ImpossibleDeserialization
– if the raw transaction was not deserializableExample
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> transaction = network.deserialize_raw_transaction('0xf8f28201f4843b9aca008302251694ce07ab9477bc20790b88b398a2a9e0f626c7d26387b1a2bc2ec50000b8c47337c993000000000000000000000000000000000000000000000000000000005bd564819d3e84874c199ca4656d434060ec1a393750ab74000000000000000000000000000000000000000000000000d867f293ba129629a9f9355fa285b8d3711a9092000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808080') # noqa: E501 <Transaction(821b)>
-
ethereum_based
= True¶ Flag for ethereum-based networks
-
static
extract_method_id
(tx_input: str) → str[source]¶ Extract Atomic Swap method identifier from transaction input (hash string).
Parameters: tx_inpit – hash string with transaction input Returns: method identifier Return type: str Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.extract_method_id('0x7337c993000000000000000000000000000000000000000000000000000000005bd1e24b6603102c4aad175d1d719326d32127d55593f986000000000000000000000000000000000000000000000000d867f293ba129629a9f9355fa285b8d3711a90920000000000000000000000004fd13283a6b9e26c4833d7b9ee7557f1d008371d0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002386f26fc10000') # noqa: E501 '7337c993'
-
extract_secret_from_redeem_transaction
(tx_address: str) → str[source]¶ Extracting secret from redeem transaction.
Parameters: tx_address (str) – address of the redeem transaction Returns: Secret string Return type: str, Raises: ValueError
– When given transaction was not a redeem type transactionExample
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.extract_secret_from_redeem_transaction('0x9e41847c3cc780e4cb59902cf55657f0ee92642d9dee4145e090cbf206d4748f') # noqa: E501 b2eefaadbbefeb9d9467092b612464db7c6724f71b5c1d70c85853845728f0e9
-
filtering_supported
= False¶ Support for filtering events
-
find_redeem_token_transaction
(recipient_address: str, token_address: str, value: int)[source]¶ Placeholder
-
find_redeem_transaction
(recipient_address: str, contract_address: str, value: int)[source]¶ Placeholder
-
find_transaction_details_in_redeem_event
(recipient_address: str, secret_hash: str, block_number: int) → Union[dict, NoneType][source]¶ Searching for transaction details of redeem transaction in Atomic Swap contract events.
Parameters: - recipient_address (str) – recipient address
- secret_hash (str) – hash of the secret
- block_number (int) – number of the block from which filtering should be started
Returns: dictionary with secret and transaction hash, None if no redeem transaction where found
Return type: dict, None
Raises: NotImplementedError
– if the network doesn’t support event filtering
-
get_latest_block
¶ Returns the number of the latest block.
Returns: number of the latest block Return type: int Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_latest_block 9188959
-
get_method_name
(method_id: str) → str[source]¶ Returning Atomic Swap method name based on method identifier.
Parameters: method_id (str) – method identifier Returns: method name Return type: str Raises: UnsupportedTransactionType
– if method identifier is not recognizedExample
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_method_name('7337c993') 'initiate'
-
classmethod
get_new_wallet
() → clove.network.ethereum.wallet.EthereumWallet[source]¶ Returns new Ethereum wallet object, which allows to keep address and private key.
Returns: Ethereum wallet object Return type: EthereumWallet Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> method.get_new_wallet() <clove.network.ethereum.wallet.EthereumWallet at 0x7f7b3fdff898>
-
static
get_raw_transaction
(transaction: ethereum.transactions.Transaction) → str[source]¶ Get raw_transaction by encoding Transaction object
Parameters: transaction (ethereum.transactions.Transaction) – Ethereum transaction object Returns: raw transaction hex string Return type: str Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> transaction = network.deserialize_raw_transaction('0xf8f28201f4843b9aca008302251694ce07ab9477bc20790b88b398a2a9e0f626c7d26387b1a2bc2ec50000b8c47337c993000000000000000000000000000000000000000000000000000000005bd564819d3e84874c199ca4656d434060ec1a393750ab74000000000000000000000000000000000000000000000000d867f293ba129629a9f9355fa285b8d3711a9092000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808080') # noqa: E501 >>> network.get_raw_transaction(transaction) '0xf8f28201f4843b9aca008302251694ce07ab9477bc20790b88b398a2a9e0f626c7d26387b1a2bc2ec50000b8c47337c993000000000000000000000000000000000000000000000000000000005bd564819d3e84874c199ca4656d434060ec1a393750ab74000000000000000000000000000000000000000000000000d867f293ba129629a9f9355fa285b8d3711a9092000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808080' # noqa: E501
-
get_token_by_address
(address: str) → Union[clove.network.ethereum.token.EthToken, NoneType][source]¶ Get token by its address.
Parameters: address (str) – token address Returns: Ethereum Token namedtuple Return type: EthToken, None Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_token_by_address('0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6') <clove.network.ethereum.token.EthToken at 0x7f7b3fed1eb8>
-
classmethod
get_token_by_attribute
(name: str, value: str) → Union[clove.network.ethereum_based.Token, NoneType][source]¶ Get a known token (from clove) by provided attribute and its value.
Parameters: - name (str) – attribute name
- value (str) – attribute value
Returns: Ethereum Token namedtuple or None if there is no matching token
Return type: Token, None
Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_token_by_attribute('symbol', 'PGT') Token(name='PrettyGoodToken', symbol='PGT', address='0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6', decimals=18) # noqa: E501
-
classmethod
get_token_by_symbol
(symbol: str) → Union[clove.network.ethereum.token.EthToken, NoneType][source]¶ Get a known token (from clove) by its symbol.
Parameters: symbol (str) – token symbol Returns: Ethereum Token namedtuple or None if there is no matching token Return type: EthToken, None Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_token_by_symbol('PGT') <clove.network.ethereum.token.EthToken at 0x7f7b3fdffe48>
-
get_token_from_token_contract
(token_address: str) → Union[clove.network.ethereum_based.Token, NoneType][source]¶ Getting information from token contract (remote)
Parameters: token_address (str) – address of the token contract Returns: Ethereum Token namedtuple or None if there is something goes wrong Return type: Token, None Raises: RuntimeError
– if name or symbol of the token is not defined.Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_token_from_token_contract('0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6') Token(name='PrettyGoodToken', symbol='PGT', address='0x2c76B98079Bb5520FF4BDBC1bf5012AC3E87ddF6', decimals=18) # noqa: E501
-
get_transaction
(tx_address: str) → web3.utils.datastructures.AttributeDict[source]¶ Getting transaction details.
Parameters: tx_address (str) – transaction address Returns: dictionary with transaction details or None if transaction doesn’t exist Return type: dict, None Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_transaction('0x9e41847c3cc780e4cb59902cf55657f0ee92642d9dee4145e090cbf206d4748f') AttributeDict({'blockHash': HexBytes('0x676df82b6cc2dcf34311bc21c5989452a5ef88c2ddf356991db15e1ee5ede159'), 'blockNumber': 9181891, 'chainId': None, 'condition': None, 'creates': None, 'from': '0x999F348959E611F1E9eab2927c21E88E48e6Ef45', 'gas': 100000, 'gasPrice': 1000000000, 'hash': HexBytes('0x9e41847c3cc780e4cb59902cf55657f0ee92642d9dee4145e090cbf206d4748f'), 'input': '0xeda1122cb2eefaadbbefeb9d9467092b612464db7c6724f71b5c1d70c85853845728f0e9', 'nonce': 499, 'publicKey': HexBytes('0x76c4f5810736d1d9b9964863abc339dce70ace058db5c820e5fdec26e0840f36f9adcb150e5216213bc301f3a6b71a178c81ddd34a361d696c8cb03970590d4f'), # noqa: E501 'r': HexBytes('0xb5c8d879d9f85e6454f69cdf1c16ac2342999608d0366fa495b51ec61d33b9b7'), 'raw': HexBytes('0xf88a8201f3843b9aca00830186a094ce07ab9477bc20790b88b398a2a9e0f626c7d26380a4eda1122cb2eefaadbbefeb9d9467092b612464db7c6724f71b5c1d70c85853845728f0e91ca0b5c8d879d9f85e6454f69cdf1c16ac2342999608d0366fa495b51ec61d33b9b7a01c35cc6de96f61543d92c21c572407481c05a3509af57fa3979d30258571b05a'), # noqa: E501 's': HexBytes('0x1c35cc6de96f61543d92c21c572407481c05a3509af57fa3979d30258571b05a'), 'standardV': 1, 'to': '0xce07aB9477BC20790B88B398A2A9e0F626c7D263', 'transactionIndex': 2, 'v': 28, 'value': 0})
-
classmethod
get_transaction_url
(tx_hash: str) → Union[str, NoneType][source]¶ Returns transaction url for a given transaction hash in block explorer.
Parameters: tx_hash (str) – transaction hash Returns: Url to transaction, None if blockexplorer_tx was not set for this network. Return type: str, None Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> network.get_transaction_url('0x9e41847c3cc780e4cb59902cf55657f0ee92642d9dee4145e090cbf206d4748f') 'https://kovan.etherscan.io/tx/0x9e41847c3cc780e4cb59902cf55657f0ee92642d9dee4145e090cbf206d4748f'
-
classmethod
get_wallet
(private_key=None) → clove.network.ethereum.wallet.EthereumWallet[source]¶ Returns Ethereum wallet object, which allows to keep address and private.
Parameters: private_key (str, None) – private key Returns: Ethereum wallet object Return type: EthereumWallet Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> method.get_wallet(private_key=MY_PRIVATE_KEY) <clove.network.ethereum.wallet.EthereumWallet at 0x7f7b3febd518>
-
static
is_valid_address
(adddress: str) → bool[source]¶ Checking if given address is valid (with checksum or not).
Parameters: str – Ethereum address Returns: True if address is valid, False otherwise Return type: bool Example
>>> from clove.network import Ethereum >>> network = Ethereum() >>> network.is_valid_address('foobar') False >>> network.is_valid_address('0x999f348959e611f1e9eab2927c21e88e48e6ef45') True
-
static
method_id
(method: str) → str[source]¶ Returns Atomic Swap methods identifiers.
Parameters: method (str) – method name with arguments Returns: method identifier Return type: str Example
>>> from clove.network import Ethereum >>> network = Ethereum() >>> network.method_id('redeem(bytes32)') 'eda1122c'
-
name
= None¶ Network name
-
publish
(transaction: Union[str, ethereum.transactions.Transaction]) → Union[str, NoneType][source]¶ Method to publish transaction
Parameters: transaction (str, ethereum.transactions.Transaction) – signed transaction Returns: transaction hash or None if something goes wrong Return type: str, None Example
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> signed_transaction = '0xf901318201f4843b9aca008302251694ce07ab9477bc20790b88b398a2a9e0f626c7d26387b1a2bc2ec50000b8c47337c993000000000000000000000000000000000000000000000000000000005bd564819d3e84874c199ca4656d434060ec1a393750ab74000000000000000000000000000000000000000000000000d867f293ba129629a9f9355fa285b8d3711a90920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ca0d1c5b984ef2629eeb7c96f48a645566b2caf4130b0f3d7060ad5225946eee9e99f9928c5dfe868b45efbb9f8ae7d64d6162591c78961439c49e836947842e178' # noqa: E501 >>> network.publish(signed_transaction) '0x4fd41289b816f6122e59a0759bd10441ead75d550562f4b3aad2fddc56eb3274'
-
static
sign
(transaction: ethereum.transactions.Transaction, private_key: str) → ethereum.transactions.Transaction[source]¶ Signing the transaction.
Parameters: - transaction (Transaction) – Ethereum unsigned transaction object
- private_key (str) – private key
Returns: Ethereum signed transaction object
Return type: Transaction
-
classmethod
sign_raw_transaction
(raw_transaction: str, private_key: str) → str[source]¶ Method to sign raw transactions.
Parameters: - raw_transaction (str) – raw transaction hex string
- private_key (str) – private key hex string
Returns: signed transaction hex string
Return type: str
Raises: ValueError
– if given private key is invalidExample
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> raw_transaction = '0xf8f28201f4843b9aca008302251694ce07ab9477bc20790b88b398a2a9e0f626c7d26387b1a2bc2ec50000b8c47337c993000000000000000000000000000000000000000000000000000000005bd564819d3e84874c199ca4656d434060ec1a393750ab74000000000000000000000000000000000000000000000000d867f293ba129629a9f9355fa285b8d3711a9092000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808080' # noqa: E501 >>> network.sign_raw_transaction(raw_transaction, MY_PRIVATE_KEY) '0xf901318201f4843b9aca008302251694ce07ab9477bc20790b88b398a2a9e0f626c7d26387b1a2bc2ec50000b8c47337c993000000000000000000000000000000000000000000000000000000005bd564819d3e84874c199ca4656d434060ec1a393750ab74000000000000000000000000000000000000000000000000d867f293ba129629a9f9355fa285b8d3711a90920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ca0d1c5b984ef2629eeb7c96f48a645566b2caf4130b0f3d7060ad5225946eee9e99f9928c5dfe868b45efbb9f8ae7d64d6162591c78961439c49e836947842e178' # noqa: E501
-
symbols
= ()¶ Tuple with network symbols
-
tokens
= []¶ Placeholder for a list of tokens
-
static
unify_address
(address: str) → str[source]¶ Returns Ethereum address with checksum.
Parameters: str – Ethereum address Returns: address with checksum Return type: str Raises: AssertionError
– if the address length is incorrectExample
>>> from clove.network import Ethereum >>> network = Ethereum() >>> network.unify_address('0x999f348959e611f1e9eab2927c21e88e48e6ef45') '0x999F348959E611F1E9eab2927c21E88E48e6Ef45'
-
static
value_from_base_units
(value: int) → decimal.Decimal[source]¶ Converting value from base units.
Parameters: value (int) – value in base units (Wei) Returns: value in main coins (Ethereum) Return type: Decimal Example
>>> from clove.network import Ethereum >>> network = Ethereum() >>> network.value_from_base_units(10000000000000) Decimal('0.00001')
-
static
value_to_base_units
(value: float) → int[source]¶ Converting value to base units.
Parameters: value (int) – value in main coins (Ethereum) Returns: value in base units (Wei) Return type: float Example
>>> from clove.network import Ethereum >>> network = Ethereum() >>> network.value_to_base_units(0.00000001) 10000000000
-
web3_provider_address
= None¶ Address to a web3 provider
-
clove.network.ethereum.contract¶
-
class
clove.network.ethereum.contract.
EthereumContract
(network, tx_dict)[source]¶ Bases:
object
Atomic Swap contract.
-
contract
¶ Returns a contract object.
-
find_redeem_transaction
() → Union[str, NoneType][source]¶ Getting details of redeem transaction.
Returns: Redeem transaction hash, None if redeem transaction was not found Return type: str, None Raises: ValueError
– if the network is not supportedExample
>>> from clove.network import EthereumTestnet >>> network = EthereumTestnet() >>> contract = network.audit_contract('0xfe4bcc1b522923ca6f8dc2721134c7d8636b34737aeafb2d6d0868d73e226891') >>> contract.find_redeem_transaction() '0x9879c8e9866fed8f9a2abdefff72c0dacb9e683ffcbd68cb966b5b8358421f39'
-
find_secret
() → Union[str, NoneType][source]¶ Searching for the secret in the redeem transaction details.
Returns: secret or None if the redeem transaction was not found Return type: str, None Raises: ValueError
– if the network doesn’t support event filtering
-
get_balance
() → float[source]¶ Checking contract balance.
Returns: contract balance Return type: float
-
is_token_contract
¶ Checking if contract is a token contract.
Returns: True is contract is a token contract, False otherwise Return type: bool
-
participate
(symbol: str, sender_address: str, recipient_address: str, value: float, utxo: list = None, token_address: str = None)[source]¶ Method for creating a second Atomic Swap transaction based on the secret hash from the current contract.
Parameters: - symbol (str) – network symbol
- sender_address (str) – wallet address of the transaction creator
- recipient_address (str) – wallet address of the transaction recipient
- value (float) – amount to be send
- utxo (list) – list of UTXO objects. In None UTXO will be gathered automatically if needed (for bitcoin-based networks)
- token_address (str) – address of the token contract if we want to use a token
Returns: - Atomic Swap transaction object
or None if something went wrong.
Return type: BitcoinAtomicSwapTransaction, EthereumAtomicSwapTransaction, None
-
redeem
(secret: str) → clove.network.ethereum.transaction.EthereumTokenTransaction[source]¶ Creates transaction that can redeem a contract.
Parameters: secret (str) – transaction secret that should match the contract secret hash (after hashing) Returns: unsigned transaction object with redeem transaction Return type: EthereumTokenTransaction Raises: ValueError
– if contract balance is 0
-
clove.network.ethereum.transaction¶
-
class
clove.network.ethereum.transaction.
EthereumAtomicSwapTransaction
(network, sender_address: str, recipient_address: str, value: decimal.Decimal, secret_hash: str = None, token=None)[source]¶ Bases:
clove.network.ethereum.transaction.EthereumTokenTransaction
-
init_hours
= 48¶
-
participate_hours
= 24¶
-
-
class
clove.network.ethereum.transaction.
EthereumTokenApprovalTransaction
(network, sender_address: str, value: decimal.Decimal, token=None)[source]¶ Bases:
clove.network.ethereum.transaction.EthereumTokenTransaction
-
class
clove.network.ethereum.transaction.
EthereumTokenTransaction
(network)[source]¶ Bases:
clove.network.ethereum.transaction.EthereumTransaction
Ethereum token transaction object.
-
class
clove.network.ethereum.transaction.
EthereumTransaction
(network)[source]¶ Bases:
object
Ethereum transaction object.
-
get_transaction_url
() → Union[str, NoneType][source]¶ Wrapper around the get_transaction_url method from base network.
-
raw_transaction
¶ Returns raw transaction serialized to hex.
-
clove.network.ethereum.wallet¶
clove.utils.bitcoin¶
-
clove.utils.bitcoin.
auto_switch_params
(args_index: int = 0)[source]¶ Decorator for changing network parameters before running some method.
Parameters: args_index (int) – if network object was passed as an argument we can provide an index number of this argument. Example
>>> @auto_switch_params() >>> def connect(self) -> str:
clove.utils.external_source¶
-
clove.utils.external_source.
clove_req_json
(url: str)[source]¶ Make a request with Clove user-agent header and return json response
Parameters: url (str) – url to get data from Returns: response data Return type: dict Raises: ExternalApiRequestLimitExceeded
– if response status code is 429Example
>>> from clove.utils.external_source import clove_req_json >>> clove_req_json('https://testnet.blockexplorer.com/api/status?q=getInfo') {'info': { 'blocks': 1414831, 'connections': 23, 'difficulty': 1, 'errors': 'Warning: unknown new rules activated (versionbit 28)', 'network': 'testnet', 'protocolversion': 70012, 'proxy': '', 'relayfee': 1e-05, 'testnet': True, 'timeoffset': 0, 'version': 120100}}
clove.utils.hashing¶
-
clove.utils.hashing.
generate_secret_with_hash
() -> (<class 'bytes'>, <class 'bytes'>)[source]¶ Generating secret and related ripemd160 hash.
Returns: secret, secret hash Return type: tuple Example
>>> from clove.utils.hashing import generate_secret_with_hash >>> secret, secret_hash = generate_secret_with_hash() >>> secret.hex() '95a968aa18866ffe6ed9ad39a06e27a90e55699734007173bfdd3daa4bab661d'
clove.utils.logging¶
-
clove.utils.logging.
logger
= <RootLogger root (DEBUG)>¶ Common logger for all the clove methods.
clove.utils.network¶
-
clove.utils.network.
generate_params_object
(message_start=b'', default_port=None, rpc_port=None, dns_seeds=(), base58_prefixes={}, max_money=None, genesis_block=None, proof_of_work_limit=None, subsidy_halving_interval=None, name=None) → bitcoin.GenericParams[source]¶ Method that returns GenericParams objects filled with given values.
Returns: modified object with network parameters. Return type: GenericParams
clove.utils.search¶
-
clove.utils.search.
get_network_by_symbol
(symbol: str)[source]¶ Returns network instance by its symbol.
Parameters: symbol (str) – network symbol Returns: Network object Raises: RuntimeError
– if there is no network with given symbol.Example
>>> from clove.utils.search import get_network_by_symbol >>> get_network_by_symbol('BTC') <clove.network.bitcoin.Bitcoin at 0x7f5a84b233c8>