mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-23 19:31:00 +08:00
include min_confirmations in the UTXO service drivers
This commit is contained in:
@@ -42,12 +42,13 @@ def create_bitcoind_service_proxy(
|
||||
|
||||
class BitcoindClient(BlockchainClient):
|
||||
def __init__(self, rpc_username, rpc_password, use_https=False,
|
||||
server='127.0.0.1', port=8332, version_byte=0):
|
||||
server='127.0.0.1', port=8332, version_byte=0, min_confirmations=None):
|
||||
self.type = 'bitcoind'
|
||||
self.auth = (rpc_username, rpc_password)
|
||||
self.bitcoind = create_bitcoind_service_proxy(rpc_username,
|
||||
rpc_password, use_https=use_https, server=server, port=port)
|
||||
self.version_byte = version_byte
|
||||
self.min_confirmations = min_confirmations
|
||||
|
||||
|
||||
def format_unspents(unspents):
|
||||
|
||||
@@ -26,8 +26,10 @@ class BlockchainClient(object):
|
||||
'blockcypher.com', etc.
|
||||
Auth object is a two item tuple.
|
||||
"""
|
||||
|
||||
def __init__(self, type, auth=None, timeout=None):
|
||||
self.type = type
|
||||
|
||||
if isinstance(auth, tuple) and len(auth) == 2:
|
||||
self.auth = auth
|
||||
else:
|
||||
|
||||
@@ -28,14 +28,15 @@ BLOCKCHAIN_API_BASE_URL = "https://blockchain.info"
|
||||
from .blockchain_client import BlockchainClient
|
||||
|
||||
class BlockchainInfoClient(BlockchainClient):
|
||||
def __init__(self, api_key=None, timeout=30):
|
||||
def __init__(self, api_key=None, timeout=30, min_confirmations=None):
|
||||
self.type = 'blockchain.info'
|
||||
self.timeout = timeout
|
||||
if api_key:
|
||||
self.auth = (api_key, '')
|
||||
else:
|
||||
self.auth = None
|
||||
|
||||
|
||||
self.min_confirmations = min_confirmations
|
||||
|
||||
def reverse_hash(hash, hex_format=True):
|
||||
""" hash is in hex or binary format
|
||||
|
||||
@@ -30,7 +30,7 @@ from .blockchain_client import BlockchainClient
|
||||
|
||||
|
||||
class BlockcypherClient(BlockchainClient):
|
||||
def __init__(self, api_key=None, timeout=30):
|
||||
def __init__(self, api_key=None, timeout=30, min_confirmations=None):
|
||||
self.type = 'blockcypher.com'
|
||||
if api_key:
|
||||
self.auth = (api_key, '')
|
||||
@@ -38,7 +38,7 @@ class BlockcypherClient(BlockchainClient):
|
||||
self.auth = None
|
||||
|
||||
self.timeout = timeout
|
||||
|
||||
self.min_confirmations = min_confirmations
|
||||
|
||||
def format_unspents(unspents):
|
||||
|
||||
|
||||
@@ -88,10 +88,11 @@ class BlockstackCoreRPCClient(object):
|
||||
"""
|
||||
RPC client for the blockstack server
|
||||
"""
|
||||
def __init__(self, server, port, timeout=30 ):
|
||||
def __init__(self, server, port, timeout=30, min_confirmations=None ):
|
||||
self.srv = TimeoutServerProxy( "http://%s:%s" % (server, port), timeout=timeout, allow_none=True )
|
||||
self.server = server
|
||||
self.port = port
|
||||
self.min_confirmations = min_confirmations
|
||||
|
||||
def __getattr__(self, key):
|
||||
try:
|
||||
|
||||
@@ -26,8 +26,8 @@ from .insight_api import InsightClient, _get_unspents, _broadcast_transaction
|
||||
BLOCKSTACK_EXPLORER_URL = "https://explorer.blockstack.org"
|
||||
|
||||
class BlockstackExplorerClient(InsightClient):
|
||||
def __init__(self, url=BLOCKSTACK_EXPLORER_URL):
|
||||
super(BlockstackExplorerClient, self).__init__(url)
|
||||
def __init__(self, url=BLOCKSTACK_EXPLORER_URL, min_confirmations=None):
|
||||
super(BlockstackExplorerClient, self).__init__(url, min_confirmations=min_confirmations)
|
||||
|
||||
|
||||
get_unspents = _get_unspents
|
||||
|
||||
@@ -26,8 +26,8 @@ from .insight_api import InsightClient, _get_unspents, _broadcast_transaction
|
||||
BLOCKSTACK_UTXO_URL = "https://utxo.blockstack.org"
|
||||
|
||||
class BlockstackUTXOClient(InsightClient):
|
||||
def __init__(self, url=BLOCKSTACK_UTXO_URL):
|
||||
super(BlockstackUTXOClient, self).__init__(url)
|
||||
def __init__(self, url=BLOCKSTACK_UTXO_URL, min_confirmations=None):
|
||||
super(BlockstackUTXOClient, self).__init__(url, min_confirmations=min_confirmations)
|
||||
|
||||
get_unspents = _get_unspents
|
||||
broadcast_transaction = _broadcast_transaction
|
||||
|
||||
@@ -30,9 +30,10 @@ from ...logger import get_logger
|
||||
log = get_logger("insight-api")
|
||||
|
||||
class InsightClient(object):
|
||||
def __init__(self, url):
|
||||
def __init__(self, url, min_confirmations=None):
|
||||
assert url
|
||||
self.url = url
|
||||
self.min_confirmations = min_confirmations
|
||||
|
||||
def get_unspents(self, address):
|
||||
url = self.url + '/insight-api/addr/{}/utxo'.format(address)
|
||||
@@ -47,7 +48,9 @@ class InsightClient(object):
|
||||
|
||||
# format...
|
||||
try:
|
||||
return format_unspents(resp)
|
||||
unspents = format_unspents(resp)
|
||||
log.debug("{} has {} UTXOs".format(address, len(unspents)))
|
||||
return unspents
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise ValueError("Invalid UTXO response")
|
||||
|
||||
Reference in New Issue
Block a user