Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquid369 committed Oct 25, 2024
1 parent 3b1539d commit 60e21e3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/pivx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# 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, Literal, Any
from misc import getCallerName, getFunctionName, printException
import utils
from pivx_hashlib import pubkeyhash_to_address
Expand All @@ -15,7 +15,7 @@ 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: Literal['little', 'big'] = '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])
Expand Down Expand Up @@ -44,11 +44,11 @@ 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]:
def ParseTxInput(p: HexParser) -> Dict[str, Any]:
vin = {
"txid": p.readString(32, "little"),
"vout": p.readInt(4, "little"),
Expand All @@ -66,7 +66,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": {
Expand All @@ -86,7 +86,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"),
Expand All @@ -103,7 +103,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"] == ""


Expand Down

0 comments on commit 60e21e3

Please sign in to comment.