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