fix verbose
arg for blockchain.transaction.get
#30
3 changed files with 54 additions and 4 deletions
|
@ -4,6 +4,7 @@ import typing
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from struct import Struct
|
from struct import Struct
|
||||||
from scribe.schema.claim import Claim
|
from scribe.schema.claim import Claim
|
||||||
|
from scribe.common import double_sha256
|
||||||
|
|
||||||
if (sys.version_info.major, sys.version_info.minor) > (3, 7):
|
if (sys.version_info.major, sys.version_info.minor) > (3, 7):
|
||||||
cachedproperty = functools.cached_property
|
cachedproperty = functools.cached_property
|
||||||
|
@ -84,6 +85,51 @@ class Tx(typing.NamedTuple):
|
||||||
flag: typing.Optional[int] = None
|
flag: typing.Optional[int] = None
|
||||||
witness: typing.Optional[typing.List[typing.List[bytes]]] = None
|
witness: typing.Optional[typing.List[typing.List[bytes]]] = None
|
||||||
|
|
||||||
|
def as_dict(self, coin):
|
||||||
|
txid = double_sha256(self.raw)[::-1].hex()
|
||||||
|
result = {
|
||||||
|
"txid": txid,
|
||||||
|
"hash": txid,
|
||||||
|
"version": self.version,
|
||||||
|
"size": len(self.raw),
|
||||||
|
"vsize": len(self.raw),
|
||||||
|
"weight": None, # FIXME: add this
|
||||||
|
"locktime": self.locktime,
|
||||||
|
"vin": [
|
||||||
|
{
|
||||||
|
"txid": txin.prev_hash[::-1].hex(),
|
||||||
|
"vout": txin.prev_idx,
|
||||||
|
"scriptSig": {
|
||||||
|
"asm": None, # FIXME: add this
|
||||||
|
"hex": txin.script.hex()
|
||||||
|
},
|
||||||
|
"sequence": txin.sequence
|
||||||
|
} for txin in self.inputs
|
||||||
|
],
|
||||||
|
"vout": [
|
||||||
|
{
|
||||||
|
"value": txo.value / 1E8,
|
||||||
|
"n": txo.nout,
|
||||||
|
"scriptPubKey": {
|
||||||
|
"asm": None, # FIXME: add this
|
||||||
|
"hex": txo.pk_script.hex(),
|
||||||
|
"reqSigs": 1, # FIXME: what if it isn't 1?
|
||||||
|
"type": "nonstandard" if (txo.is_support or txo.is_claim or txo.is_update) else "pubkeyhash" if txo.pubkey_hash else "scripthash",
|
||||||
|
"addresses": [
|
||||||
|
coin.claim_address_handler(txo)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} for txo in self.outputs
|
||||||
|
],
|
||||||
|
"hex": self.raw.hex()
|
||||||
|
}
|
||||||
|
for n, txo in enumerate(self.outputs):
|
||||||
|
if txo.is_support or txo.is_claim or txo.is_update:
|
||||||
|
result['vout'][n]["scriptPubKey"]["isclaim"] = txo.is_claim or txo.is_update
|
||||||
|
result['vout'][n]["scriptPubKey"]["issupport"] = txo.is_support
|
||||||
|
result['vout'][n]["scriptPubKey"]["subtype"] = "pubkeyhash" if txo.pubkey_hash else "scripthash"
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class TxInput(typing.NamedTuple):
|
class TxInput(typing.NamedTuple):
|
||||||
prev_hash: bytes
|
prev_hash: bytes
|
||||||
|
|
|
@ -284,7 +284,10 @@ class Env:
|
||||||
return self.PD_ON
|
return self.PD_ON
|
||||||
|
|
||||||
def extract_peer_hubs(self):
|
def extract_peer_hubs(self):
|
||||||
return [hub.strip() for hub in self.default('PEER_HUBS', '').split(',')]
|
peer_hubs = self.default('PEER_HUBS', '')
|
||||||
|
if not peer_hubs:
|
||||||
|
return []
|
||||||
|
return [hub.strip() for hub in peer_hubs.split(',')]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def contribute_to_arg_parser(cls, parser):
|
def contribute_to_arg_parser(cls, parser):
|
||||||
|
|
|
@ -1668,13 +1668,14 @@ class LBRYElectrumX(asyncio.Protocol):
|
||||||
verbose: passed on to the daemon
|
verbose: passed on to the daemon
|
||||||
"""
|
"""
|
||||||
assert_tx_hash(txid)
|
assert_tx_hash(txid)
|
||||||
if verbose not in (True, False):
|
verbose = bool(verbose)
|
||||||
raise RPCError(BAD_REQUEST, f'"verbose" must be a boolean')
|
|
||||||
tx_hash_bytes = bytes.fromhex(txid)[::-1]
|
tx_hash_bytes = bytes.fromhex(txid)[::-1]
|
||||||
|
|
||||||
raw_tx = await asyncio.get_event_loop().run_in_executor(None, self.db.get_raw_tx, tx_hash_bytes)
|
raw_tx = await asyncio.get_event_loop().run_in_executor(None, self.db.get_raw_tx, tx_hash_bytes)
|
||||||
if raw_tx:
|
if raw_tx:
|
||||||
return raw_tx.hex()
|
if not verbose:
|
||||||
|
return raw_tx.hex()
|
||||||
|
return self.coin.transaction(raw_tx).as_dict(self.coin)
|
||||||
return RPCError("No such mempool or blockchain transaction.")
|
return RPCError("No such mempool or blockchain transaction.")
|
||||||
|
|
||||||
def _get_merkle_branch(self, tx_hashes, tx_pos):
|
def _get_merkle_branch(self, tx_hashes, tx_pos):
|
||||||
|
|
Loading…
Reference in a new issue