Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def transaction_import_raw(self, raw_tx, network=None):
"""
Import a raw transaction. Link inputs to wallet keys if possible and return HDWalletTransaction object
:param raw_tx: Raw transaction
:type raw_tx: str, bytes
:param network: Network name. Leave empty for default network
:type network: str
:return HDWalletTransaction:
"""
if network is None:
network = self.network.network_name
t_import = Transaction.import_raw(raw_tx, network=network)
rt = self.transaction_create(t_import.outputs, t_import.inputs, network=network)
rt.verify()
return rt
def gettransaction(self, txid):
tx = self.proxy.getrawtransaction(txid, 1)
t = Transaction.import_raw(tx['hex'], network='dash')
t.confirmations = tx['confirmations']
if t.confirmations:
t.status = 'confirmed'
t.verified = True
for i in t.inputs:
txi = self.proxy.getrawtransaction(to_hexstring(i.prev_hash), 1)
value = int(float(txi['vout'][i.output_n_int]['value']) / self.network.denominator)
i.value = value
t.block_hash = tx['blockhash']
t.version = tx['version']
t.date = datetime.fromtimestamp(tx['blocktime'])
t.update_totals()
return t
def gettransaction(self, tx_id):
tx = self.compose_request('rawtx', tx_id)
raw_tx = self.getrawtransaction(tx_id)
t = Transaction.import_raw(raw_tx, self.network)
input_total = 0
for n, i in enumerate(t.inputs):
if 'prev_out' in tx['inputs'][n]:
i.value = tx['inputs'][n]['prev_out']['value']
input_total += i.value
for n, o in enumerate(t.outputs):
o.spent = tx['out'][n]['spent']
if 'block_height' in tx and tx['block_height']:
t.status = 'confirmed'
else:
t.status = 'unconfirmed'
t.hash = tx_id
t.date = datetime.fromtimestamp(tx['time'])
t.block_height = 0 if 'block_height' not in tx else tx['block_height']
t.rawtx = raw_tx
t.size = tx['size']
def getrawtransaction(self, txid):
tx = self.compose_request('tx', txid)
t = Transaction.import_raw(tx['hex'], network=self.network)
for i in t.inputs:
if not i.address:
raise ClientError("Address missing in input. Provider might not support segwit transactions")
return tx['hex']
def gettransaction(self, txid):
tx = self.proxy.getrawtransaction(txid, 1)
t = Transaction.import_raw(tx['hex'], network=self.network)
t.confirmations = tx['confirmations']
if t.confirmations:
t.status = 'confirmed'
t.verified = True
for i in t.inputs:
if i.prev_hash == b'\x00' * 32:
i.value = t.output_total
i.script_type = 'coinbase'
continue
txi = self.proxy.getrawtransaction(to_hexstring(i.prev_hash), 1)
i.value = int(round(float(txi['vout'][i.output_n_int]['value']) / self.network.denominator))
for o in t.outputs:
o.spent = None
t.block_hash = tx['blockhash']
t.version = struct.pack('>L', tx['version'])
t.date = datetime.fromtimestamp(tx['blocktime'])
def gettransaction(self, tx_id):
res = self.compose_request('get_tx', tx_id)
tx = res['data']
raw_tx = tx['tx_hex']
t = Transaction.import_raw(raw_tx, network=self.network)
input_total = 0
output_total = 0
for n, i in enumerate(t.inputs):
i.value = int(round(float(tx['inputs'][n]['value']) * self.units, 0))
input_total += i.value
for o in t.outputs:
o.spent = None
output_total += o.value
t.hash = tx_id
t.block_hash = tx['blockhash']
t.date = datetime.fromtimestamp(tx['time'])
t.rawtx = raw_tx
t.size = tx['size']
t.network = self.network
t.locktime = tx['locktime']
t.input_total = input_total
def _parse_transaction(self, tx):
t = Transaction.import_raw(tx['rawTx'], network=self.network)
t.status = 'unconfirmed'
if tx['confirmations']:
t.status = 'confirmed'
t.hash = tx['txId']
if 'timestamp' in tx and tx['timestamp']:
t.date = datetime.fromtimestamp(tx['timestamp'])
elif 'blockTime' in tx and tx['blockTime']:
t.date = datetime.fromtimestamp(tx['blockTime'])
t.confirmations = tx['confirmations']
if 'blockHeight' in tx:
t.block_height = tx['blockHeight']
t.block_hash = tx['blockHash']
t.fee = tx['fee']
t.rawtx = tx['rawTx']
t.size = tx['size']
t.network = self.network
def gettransaction(self, tx_id):
variables = {'id': tx_id, 'hex': None}
tx = self.compose_request(path_type='explorer', variables=variables)
t = Transaction.import_raw(tx['hex'], self.network)
variables = {'t': tx_id}
tx_api = self.compose_request('txinfo', path_type='api', variables=variables)
for n, i in enumerate(t.inputs):
i.value = int(round(tx_api['inputs'][n]['amount'] * self.units, 0))
for n, o in enumerate(t.outputs):
o.spent = None
if tx['confirmations']:
t.status = 'confirmed'
else:
t.status = 'unconfirmed'
t.hash = tx_id
t.date = datetime.fromtimestamp(tx['time'])
t.block_height = tx_api['block']
t.block_hash = tx['blockhash']
t.confirmations = tx['confirmations']
t.rawtx = tx['hex']