1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +00:00

decred: Return tree and version in insight api (#319)

This commit is contained in:
Matheus Degiovani 2018-10-10 07:44:54 -03:00 committed by Pavol Rusnak
parent 4f18d53219
commit 6d9157c4a5
2 changed files with 15 additions and 2 deletions

View File

@ -40,8 +40,11 @@ def _insight_for_coin(coin):
return None
zcash = coin["coin_name"].lower().startswith("zcash")
bip115 = coin["bip115"]
decred = coin["decred"]
network = "insight_{}".format(coin["coin_name"].lower().replace(" ", "_"))
return TxApiInsight(network=network, url=url, zcash=zcash, bip115=bip115)
return TxApiInsight(
network=network, url=url, zcash=zcash, bip115=bip115, decred=decred
)
# exported variables

View File

@ -68,10 +68,11 @@ class TxApi(object):
class TxApiInsight(TxApi):
def __init__(self, network, url=None, zcash=None, bip115=False):
def __init__(self, network, url=None, zcash=None, bip115=False, decred=False):
super().__init__(network, url)
self.zcash = zcash
self.bip115 = bip115
self.decred = decred
if url:
self.pushtx_url = self.url + "/tx/send"
@ -93,6 +94,9 @@ class TxApiInsight(TxApi):
t.version = data["version"]
t.lock_time = data["locktime"]
if self.decred:
t.expiry = data["expiry"]
for vin in data["vin"]:
i = t._add_inputs()
if "coinbase" in vin.keys():
@ -107,6 +111,10 @@ class TxApiInsight(TxApi):
i.script_sig = bytes.fromhex(vin["scriptSig"]["hex"])
i.sequence = vin["sequence"]
if self.decred:
i.decred_tree = vin["tree"]
# TODO: support amountIn, blockHeight, blockIndex
for vout in data["vout"]:
o = t._add_bin_outputs()
o.amount = int(Decimal(vout["value"]) * 100000000)
@ -119,6 +127,8 @@ class TxApiInsight(TxApi):
o.block_height = int.from_bytes(
tail[34:37], byteorder="little"
) # <3-byte block height>
if self.decred:
o.decred_script_version = vout["version"]
if self.zcash:
t.overwintered = data.get("fOverwintered", False)