From f81ad99750544a97f2d1d96f4f6ccc246a0dc790 Mon Sep 17 00:00:00 2001 From: Liquid369 Date: Fri, 25 Oct 2024 09:52:23 -0500 Subject: [PATCH] Blah --- src/pivx_parser.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pivx_parser.py b/src/pivx_parser.py index 6bf6af1..ec06dd9 100644 --- a/src/pivx_parser.py +++ b/src/pivx_parser.py @@ -4,18 +4,25 @@ # Distributed under the MIT software license, see the accompanying # file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php. -from typing import Dict, Tuple +from typing import Dict, Tuple, TypedDict +from typing import Any from misc import getCallerName, getFunctionName, printException import utils from pivx_hashlib import pubkeyhash_to_address +class VinType(TypedDict, total=False): + txid: str + vout: int + scriptSig: Dict[str, str] + sequence: int + coinbase: str class HexParser: def __init__(self, hex_str: str): self.cursor = 0 self.hex_str = hex_str - def readInt(self, nbytes: int, byteorder: str = 'big', signed: bool = False) -> int: + def readInt(self, nbytes: int, byteorder: str = "big", signed: bool = False) -> int: if self.cursor + nbytes * 2 > len(self.hex_str): raise Exception("HexParser range error") b = bytes.fromhex(self.hex_str[self.cursor:self.cursor + nbytes * 2]) @@ -44,12 +51,12 @@ def readString(self, nbytes: int, byteorder: str = "big") -> str: return res -def IsCoinBase(vin: Dict[str, any]) -> bool: +def IsCoinBase(vin: Dict[str, Any]) -> bool: return vin["txid"] == "0" * 64 and vin["vout"] == 4294967295 and vin["scriptSig"]["hex"][:2] != "c2" -def ParseTxInput(p: HexParser) -> Dict[str, any]: - vin = { +def ParseTxInput(p: HexParser) -> Dict[str, Any]: + vin = VinType { "txid": p.readString(32, "little"), "vout": p.readInt(4, "little"), "scriptSig": { @@ -66,7 +73,7 @@ def ParseTxInput(p: HexParser) -> Dict[str, any]: return vin -def ParseTxOutput(p: HexParser, isTestnet: bool = False) -> Dict[str, any]: +def ParseTxOutput(p: HexParser, isTestnet: bool = False) -> Dict[str, Any]: vout = { "value": p.readInt(8, "little"), "scriptPubKey": { @@ -86,7 +93,7 @@ def ParseTxOutput(p: HexParser, isTestnet: bool = False) -> Dict[str, any]: return vout -def ParseTx(hex_string: str, isTestnet: bool = False) -> Dict[str, any]: +def ParseTx(hex_string: str, isTestnet: bool = False) -> Dict[str, Any]: p = HexParser(hex_string) tx = { "version": p.readInt(4, "little"), @@ -103,7 +110,7 @@ def IsPayToColdStaking(rawtx: str, out_n: int) -> Tuple[bool, bool]: return utils.IsPayToColdStaking(bytes.fromhex(script)), IsCoinStake(tx) -def IsCoinStake(json_tx: Dict[str, any]) -> bool: +def IsCoinStake(json_tx: Dict[str, Any]) -> bool: return json_tx['vout'][0]["scriptPubKey"]["hex"] == ""