PEP8 formating

This commit is contained in:
4tochka 2018-05-29 18:19:52 +04:00
parent a0a7c8ed08
commit 3d381807b2
6 changed files with 619 additions and 592 deletions

View File

@ -1,5 +1,6 @@
from .tools import *
class PrivateKey():
def __init__(self, key=None, compressed=True, testnet=False):
if key is None:
@ -34,7 +35,7 @@ class PrivateKey():
def hex(self):
return hexlify(self.raw_key).decode()
def WIF(self, compressed=None, testnet=None):
def wif(self, compressed=None, testnet=None):
if compressed is None:
compressed = self.compressed
if testnet is None:
@ -60,18 +61,16 @@ class PublicKey():
self.compressed = False
self.raw_key = key
def hex(self):
return hexlify(self.raw_key).decode()
class Address():
def __init__(self, key = None,
address_type="P2WPKH", testnet=False, compressed = True):
address_type="P2WPKH", testnet=False, compressed=True):
if key is None:
self.private_key = PrivateKey(testnet = testnet,
compressed = compressed)
self.private_key = PrivateKey(testnet=testnet,
compressed=compressed)
self.public_key = PublicKey(self.private_key)
elif type(key) == PrivateKey:
self.private_key = key
@ -92,7 +91,6 @@ class Address():
else:
self.witness_version = None
self.compressed = compressed
if address_type == "P2SH_P2WPKH":
self.script_hash = True
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.hash = hash160(self.public_key.raw_key)
self.address = hash_to_address(self.hash,
script_hash = self.script_hash,
witness_version = self.witness_version)
script_hash=self.script_hash,
witness_version=self.witness_version)

View File

@ -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

View File

@ -502,7 +502,6 @@ class OLDBlock():
extranonce_start = len_coinbase + extranonce_start
return tx[:44 + extranonce_start], tx[44 + extranonce_start + extranonce_size:]
@classmethod
def deserialize(cls, stream):
stream = get_stream(stream)

View File

@ -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)
if len(tx_hash_list) == 1:
return tx_hash_list[0]

View File

@ -76,8 +76,8 @@ class Transaction(dict):
self["weight"] = self["bSize"] * 3 + self["size"]
self["vSize"] = math.ceil(self["weight"] / 4)
if ic == 1 and \
self["vIn"][0]["txId"] == b'\x00' * 32 and \
self["vIn"][0]["vOut"] == 0xffffffff:
self["vIn"][0]["txId"] == b'\x00' * 32 and \
self["vIn"][0]["vOut"] == 0xffffffff:
self["coinbase"] = True
if sw:
self["segwit"] = True

File diff suppressed because one or more lines are too long