From 6d9157c4a5b0b64857cee7b982049a8071706a44 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Wed, 10 Oct 2018 07:44:54 -0300 Subject: [PATCH] decred: Return tree and version in insight api (#319) --- trezorlib/coins.py | 5 ++++- trezorlib/tx_api.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/trezorlib/coins.py b/trezorlib/coins.py index 99d83c19e..72ff2729e 100644 --- a/trezorlib/coins.py +++ b/trezorlib/coins.py @@ -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 diff --git a/trezorlib/tx_api.py b/trezorlib/tx_api.py index 750d172d1..1ef5b45da 100644 --- a/trezorlib/tx_api.py +++ b/trezorlib/tx_api.py @@ -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)