PEP8 formating
This commit is contained in:
parent
a0a7c8ed08
commit
3d381807b2
@ -1,5 +1,6 @@
|
|||||||
from .tools import *
|
from .tools import *
|
||||||
|
|
||||||
|
|
||||||
class PrivateKey():
|
class PrivateKey():
|
||||||
def __init__(self, key=None, compressed=True, testnet=False):
|
def __init__(self, key=None, compressed=True, testnet=False):
|
||||||
if key is None:
|
if key is None:
|
||||||
@ -34,7 +35,7 @@ class PrivateKey():
|
|||||||
def hex(self):
|
def hex(self):
|
||||||
return hexlify(self.raw_key).decode()
|
return hexlify(self.raw_key).decode()
|
||||||
|
|
||||||
def WIF(self, compressed=None, testnet=None):
|
def wif(self, compressed=None, testnet=None):
|
||||||
if compressed is None:
|
if compressed is None:
|
||||||
compressed = self.compressed
|
compressed = self.compressed
|
||||||
if testnet is None:
|
if testnet is None:
|
||||||
@ -60,18 +61,16 @@ class PublicKey():
|
|||||||
self.compressed = False
|
self.compressed = False
|
||||||
self.raw_key = key
|
self.raw_key = key
|
||||||
|
|
||||||
|
|
||||||
def hex(self):
|
def hex(self):
|
||||||
return hexlify(self.raw_key).decode()
|
return hexlify(self.raw_key).decode()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Address():
|
class Address():
|
||||||
def __init__(self, key = None,
|
def __init__(self, key = None,
|
||||||
address_type="P2WPKH", testnet=False, compressed = True):
|
address_type="P2WPKH", testnet=False, compressed=True):
|
||||||
if key is None:
|
if key is None:
|
||||||
self.private_key = PrivateKey(testnet = testnet,
|
self.private_key = PrivateKey(testnet=testnet,
|
||||||
compressed = compressed)
|
compressed=compressed)
|
||||||
self.public_key = PublicKey(self.private_key)
|
self.public_key = PublicKey(self.private_key)
|
||||||
elif type(key) == PrivateKey:
|
elif type(key) == PrivateKey:
|
||||||
self.private_key = key
|
self.private_key = key
|
||||||
@ -92,7 +91,6 @@ class Address():
|
|||||||
else:
|
else:
|
||||||
self.witness_version = None
|
self.witness_version = None
|
||||||
self.compressed = compressed
|
self.compressed = compressed
|
||||||
|
|
||||||
if address_type == "P2SH_P2WPKH":
|
if address_type == "P2SH_P2WPKH":
|
||||||
self.script_hash = True
|
self.script_hash = True
|
||||||
self.redeem_script = public_key_to_p2sh_p2wpkh_script(self.public_key.raw_key)
|
self.redeem_script = public_key_to_p2sh_p2wpkh_script(self.public_key.raw_key)
|
||||||
@ -102,5 +100,5 @@ class Address():
|
|||||||
self.script_hash = False
|
self.script_hash = False
|
||||||
self.hash = hash160(self.public_key.raw_key)
|
self.hash = hash160(self.public_key.raw_key)
|
||||||
self.address = hash_to_address(self.hash,
|
self.address = hash_to_address(self.hash,
|
||||||
script_hash = self.script_hash,
|
script_hash=self.script_hash,
|
||||||
witness_version = self.witness_version)
|
witness_version=self.witness_version)
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
from .tools import *
|
||||||
|
from .transaction import Transaction
|
||||||
|
from struct import pack, unpack
|
||||||
|
|
||||||
|
|
||||||
|
class Block(dict):
|
||||||
|
def __init__(self, block):
|
||||||
|
s = get_stream(block)
|
||||||
|
self["header"] = s.read(80)
|
||||||
|
self["hash"] = double_sha256(self["header"])
|
||||||
|
self["version"] = unpack("<L", s.read(4))
|
||||||
|
self["previousBlockHash"] = s.read(32)
|
||||||
|
self["merkleRoot"] = s.read(32)
|
||||||
|
self["time"] = unpack("<L", s.read(4))
|
||||||
|
self["bits"] = s.read(4),
|
||||||
|
self["nonce"] = unpack("<L", s.read(4))
|
||||||
|
s.seek(-80, 1)
|
||||||
|
self["tx"] = {i: Transaction(s)
|
||||||
|
for i in range(var_int_to_int(read_var_int(s)))}
|
||||||
|
self["weight"] = 0
|
||||||
|
self["size"] = 0
|
||||||
|
self["strippedSize"] = 0
|
||||||
|
self["height"] = 0
|
||||||
|
self["difficulty"] = 0
|
||||||
|
self["targetDifficulty"] = 0
|
||||||
|
self["target"] = 0
|
||||||
|
|
||||||
|
|
||||||
@ -502,7 +502,6 @@ class OLDBlock():
|
|||||||
extranonce_start = len_coinbase + extranonce_start
|
extranonce_start = len_coinbase + extranonce_start
|
||||||
return tx[:44 + extranonce_start], tx[44 + extranonce_start + extranonce_size:]
|
return tx[:44 + extranonce_start], tx[44 + extranonce_start + extranonce_size:]
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def deserialize(cls, stream):
|
def deserialize(cls, stream):
|
||||||
stream = get_stream(stream)
|
stream = get_stream(stream)
|
||||||
|
|||||||
@ -589,7 +589,7 @@ def reverse_hash(h):
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
def merkleroot(tx_hash_list):
|
def merkle_root(tx_hash_list):
|
||||||
tx_hash_list = list(tx_hash_list)
|
tx_hash_list = list(tx_hash_list)
|
||||||
if len(tx_hash_list) == 1:
|
if len(tx_hash_list) == 1:
|
||||||
return tx_hash_list[0]
|
return tx_hash_list[0]
|
||||||
|
|||||||
@ -76,8 +76,8 @@ class Transaction(dict):
|
|||||||
self["weight"] = self["bSize"] * 3 + self["size"]
|
self["weight"] = self["bSize"] * 3 + self["size"]
|
||||||
self["vSize"] = math.ceil(self["weight"] / 4)
|
self["vSize"] = math.ceil(self["weight"] / 4)
|
||||||
if ic == 1 and \
|
if ic == 1 and \
|
||||||
self["vIn"][0]["txId"] == b'\x00' * 32 and \
|
self["vIn"][0]["txId"] == b'\x00' * 32 and \
|
||||||
self["vIn"][0]["vOut"] == 0xffffffff:
|
self["vIn"][0]["vOut"] == 0xffffffff:
|
||||||
self["coinbase"] = True
|
self["coinbase"] = True
|
||||||
if sw:
|
if sw:
|
||||||
self["segwit"] = True
|
self["segwit"] = True
|
||||||
|
|||||||
1160
tests/test/block.py
1160
tests/test/block.py
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user