version 2.0 draft
This commit is contained in:
parent
a4050459d9
commit
fa00b7ff21
@ -1,6 +1,6 @@
|
|||||||
# from .tools import *
|
from .tools import *
|
||||||
# from .opcodes import *
|
from .opcodes import *
|
||||||
from .consensus import *
|
from .consensus import *
|
||||||
from .blockchain import *
|
from .transaction import *
|
||||||
|
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
|||||||
@ -12,7 +12,7 @@ k = 0
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Transaction():
|
class OLDTransaction():
|
||||||
def __init__(self, version = 1, tx_in = [], tx_out = [] , lock_time = 0,
|
def __init__(self, version = 1, tx_in = [], tx_out = [] , lock_time = 0,
|
||||||
hash=None, size = 0, timestamp = None,
|
hash=None, size = 0, timestamp = None,
|
||||||
marker = None, flag = None, witness = [],
|
marker = None, flag = None, witness = [],
|
||||||
@ -410,7 +410,7 @@ class Transaction():
|
|||||||
witness = witness, whash = wtx_id, vsize = vsize)
|
witness = witness, whash = wtx_id, vsize = vsize)
|
||||||
|
|
||||||
|
|
||||||
class Block():
|
class OLDBlock():
|
||||||
def __init__(self, version, prev_block, merkle_root,
|
def __init__(self, version, prev_block, merkle_root,
|
||||||
timestamp, bits, nonce, txs, block_size, hash = None, header = None):
|
timestamp, bits, nonce, txs, block_size, hash = None, header = None):
|
||||||
qt = time.time()
|
qt = time.time()
|
||||||
|
|||||||
@ -42,13 +42,13 @@ class Transaction(dict):
|
|||||||
for k in range(ic):
|
for k in range(ic):
|
||||||
self["vIn"][k] = dict()
|
self["vIn"][k] = dict()
|
||||||
self["vIn"][k]["txId"] = stream.read(32)
|
self["vIn"][k]["txId"] = stream.read(32)
|
||||||
(self["vIn"][k]["vOut"],) = unpack('<L', stream.read(4))
|
self["vIn"][k]["vOut"] = unpack('<L', stream.read(4))[0]
|
||||||
n = var_int_to_int(read_var_int(stream))
|
n = var_int_to_int(read_var_int(stream))
|
||||||
self["vIn"][k]["scriptSig"] = stream.read(n)
|
self["vIn"][k]["scriptSig"] = stream.read(n)
|
||||||
(self["vIn"][k]["sequence"],) = unpack('<L', stream.read(4))
|
(self["vIn"][k]["sequence"],) = unpack('<L', stream.read(4))
|
||||||
for k in range(var_int_to_int(read_var_int(stream))):
|
for k in range(var_int_to_int(read_var_int(stream))):
|
||||||
self["vOut"][k] = dict()
|
self["vOut"][k] = dict()
|
||||||
(self["vOut"][k]["value"],) = unpack('<Q', stream.read(8))
|
self["vOut"][k]["value"] = unpack('<Q', stream.read(8))[0]
|
||||||
self["amount"] += self["vOut"][k]["value"]
|
self["amount"] += self["vOut"][k]["value"]
|
||||||
self["vOut"][k]["scriptPubKey"] = stream.read(var_int_to_int(read_var_int(stream)))
|
self["vOut"][k]["scriptPubKey"] = stream.read(var_int_to_int(read_var_int(stream)))
|
||||||
s = parse_script(self["vOut"][k]["scriptPubKey"], sw)
|
s = parse_script(self["vOut"][k]["scriptPubKey"], sw)
|
||||||
@ -66,7 +66,7 @@ class Transaction(dict):
|
|||||||
self["vIn"][k]["txInWitness"] = [stream.read(var_int_to_int(read_var_int(stream))) \
|
self["vIn"][k]["txInWitness"] = [stream.read(var_int_to_int(read_var_int(stream))) \
|
||||||
for c in range(var_int_to_int(read_var_int(stream)))]
|
for c in range(var_int_to_int(read_var_int(stream)))]
|
||||||
sw_len = stream.tell() - sw + 2
|
sw_len = stream.tell() - sw + 2
|
||||||
(self["lockTime"],) = unpack('<L', stream.read(4))
|
self["lockTime"] = unpack('<L', stream.read(4))[0]
|
||||||
end = stream.tell()
|
end = stream.tell()
|
||||||
stream.seek(start)
|
stream.seek(start)
|
||||||
b = stream.read(end - start)
|
b = stream.read(end - start)
|
||||||
@ -221,5 +221,4 @@ class Transaction(dict):
|
|||||||
return json.dumps(self)
|
return json.dumps(self)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
print(self)
|
|
||||||
return json.dumps(self.decode())
|
return json.dumps(self.decode())
|
||||||
@ -10,14 +10,11 @@ from pybtc.transaction import *
|
|||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from pybtc import address_to_hash as address2hash160
|
from pybtc import address_to_hash as address2hash160
|
||||||
|
|
||||||
|
|
||||||
def decode_block_tx(block):
|
def decode_block_tx(block):
|
||||||
stream = get_stream(block)
|
stream = get_stream(block)
|
||||||
tx = dict()
|
|
||||||
stream.seek(80)
|
stream.seek(80)
|
||||||
count = var_int_to_int(read_var_int(stream))
|
return {i: Transaction(stream) for i in range(var_int_to_int(read_var_int(stream)))}
|
||||||
for i in range(count):
|
|
||||||
tx[i] = Transaction(stream)
|
|
||||||
return tx
|
|
||||||
|
|
||||||
|
|
||||||
class TransactionDeserializeTests(unittest.TestCase):
|
class TransactionDeserializeTests(unittest.TestCase):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user