mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-22 10:36:57 +08:00
properly format UTXOs for virtualchain's transaction serializer
This commit is contained in:
@@ -53,9 +53,12 @@ class BitcoindClient(BlockchainClient):
|
||||
def format_unspents(unspents):
|
||||
return [{
|
||||
"transaction_hash": s["txid"],
|
||||
"output_index": s["vout"],
|
||||
"outpoint": {
|
||||
'hash': s['txid'],
|
||||
'index': s["vout"],
|
||||
},
|
||||
"value": int(Decimal(s["amount"]*SATOSHIS_PER_COIN)),
|
||||
"script_hex": s["scriptPubKey"],
|
||||
"out_script": s["scriptPubKey"],
|
||||
"confirmations": s["confirmations"]
|
||||
}
|
||||
for s in unspents
|
||||
|
||||
@@ -48,9 +48,12 @@ def reverse_hash(hash, hex_format=True):
|
||||
def format_unspents(unspents):
|
||||
return [{
|
||||
"transaction_hash": reverse_hash(s["tx_hash"]),
|
||||
"output_index": s["tx_output_n"],
|
||||
"outpoint": {
|
||||
'hash': reverse_hash(s['tx_hash']),
|
||||
'index': s["tx_output_n"],
|
||||
},
|
||||
"value": s["value"],
|
||||
"script_hex": s["script"],
|
||||
"out_script": s["script"],
|
||||
"confirmations": s["confirmations"]
|
||||
}
|
||||
for s in unspents
|
||||
@@ -86,7 +89,7 @@ def broadcast_transaction(hex_tx, blockchain_client=BlockchainInfoClient()):
|
||||
r = requests.post(url, data=payload, auth=blockchain_client.auth, timeout=blockchain_client.timeout)
|
||||
|
||||
if 'submitted' in r.text.lower():
|
||||
return {'success': True, 'tx_hash': virtualchain.tx_get_hash(hex_tx)}
|
||||
return {'success': True, 'tx_hash': virtualchain.btc_tx_get_hash(hex_tx)}
|
||||
else:
|
||||
raise Exception('Invalid response from blockchain.info.')
|
||||
|
||||
|
||||
@@ -47,9 +47,12 @@ def format_unspents(unspents):
|
||||
|
||||
return [{
|
||||
"transaction_hash": s["tx_hash"],
|
||||
"output_index": s["tx_output_n"],
|
||||
"outpoint": {
|
||||
'hash': s['tx_hash'],
|
||||
'index': s["tx_output_n"],
|
||||
},
|
||||
"value": s["value"],
|
||||
"script_hex": s.get("script"),
|
||||
"out_script": s.get("script"),
|
||||
"confirmations": s["confirmations"],
|
||||
}
|
||||
for s in all_unspents
|
||||
|
||||
@@ -75,9 +75,12 @@ class InsightClient(object):
|
||||
def format_unspents(unspents):
|
||||
return [{
|
||||
'transaction_hash': s['txid'],
|
||||
'output_index': s['vout'],
|
||||
'outpoint': {
|
||||
'hash': s['txid'],
|
||||
'index': s['vout'],
|
||||
},
|
||||
'value': s['satoshis'],
|
||||
'script_hex': s['scriptPubKey'],
|
||||
'out_script': s['scriptPubKey'],
|
||||
'confirmations': s['confirmations']
|
||||
} for s in unspents]
|
||||
|
||||
|
||||
@@ -419,9 +419,12 @@ def get_unspents(address, blockchain_client):
|
||||
Gets the unspent outputs for a given address.
|
||||
Returns [{
|
||||
"transaction_hash": str,
|
||||
"output_index": int
|
||||
'outpoint': {
|
||||
'index': index,
|
||||
'hash': txhash
|
||||
},
|
||||
"value": int,
|
||||
"script_hex": str,
|
||||
"out_script": str,
|
||||
"confirmations": int,
|
||||
}]
|
||||
on success.
|
||||
@@ -444,10 +447,8 @@ def get_unspents(address, blockchain_client):
|
||||
# default
|
||||
elif hasattr(blockchain_client, "get_unspents"):
|
||||
return blockchain_client.get_unspents( address )
|
||||
elif isinstance(blockchain_client, BlockchainClient):
|
||||
raise Exception('That blockchain interface is not supported.')
|
||||
else:
|
||||
raise Exception('A BlockchainClient object is required')
|
||||
raise Exception('A blockchain client object is required')
|
||||
|
||||
|
||||
def broadcast_transaction(hex_tx, blockchain_client):
|
||||
@@ -472,9 +473,7 @@ def broadcast_transaction(hex_tx, blockchain_client):
|
||||
# default
|
||||
elif hasattr(blockchain_client, "broadcast_transaction"):
|
||||
return blockchain_client.broadcast_transaction( hex_tx )
|
||||
elif isinstance(blockchain_client, BlockchainClient):
|
||||
raise Exception('That blockchain interface is not supported.')
|
||||
else:
|
||||
raise Exception('A BlockchainClient object is required')
|
||||
raise Exception('A blockchain client object is required')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user