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

pull/25/head
Matheus Degiovani 6 years ago committed by Pavol Rusnak
parent 4f18d53219
commit 6d9157c4a5

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

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

Loading…
Cancel
Save