create coinbase transaction
This commit is contained in:
parent
7d37477aff
commit
ed76d9be46
@ -617,9 +617,6 @@ class Block():
|
|||||||
|
|
||||||
def calculate_commitment(self, witness = None):
|
def calculate_commitment(self, witness = None):
|
||||||
wtxid_list = [b"\x00" * 32,]
|
wtxid_list = [b"\x00" * 32,]
|
||||||
print(self.transactions)
|
|
||||||
print(self.transactions[0].witness[0].witness[0])
|
|
||||||
# print("len ", len(self.transactions))
|
|
||||||
if not (len(self.transactions) == 1 and self.transactions[0].coinbase):
|
if not (len(self.transactions) == 1 and self.transactions[0].coinbase):
|
||||||
for tx in self.transactions[0 if not self.transactions[0].coinbase else 1:]:
|
for tx in self.transactions[0 if not self.transactions[0].coinbase else 1:]:
|
||||||
wtxid_list.append(tx.whash)
|
wtxid_list.append(tx.whash)
|
||||||
@ -636,7 +633,6 @@ class Block():
|
|||||||
coinbase_input = Input((b'\x00'*32 ,0xffffffff), coinbase, 0xffffffff)
|
coinbase_input = Input((b'\x00'*32 ,0xffffffff), coinbase, 0xffffffff)
|
||||||
tx.tx_in = [coinbase_input]
|
tx.tx_in = [coinbase_input]
|
||||||
tx.witness = [Witness([b'\x00'*32])]
|
tx.witness = [Witness([b'\x00'*32])]
|
||||||
print(tx.witness[0].witness[0])
|
|
||||||
commitment = self.calculate_commitment(tx.witness[0].witness[0])
|
commitment = self.calculate_commitment(tx.witness[0].witness[0])
|
||||||
for o in outputs:
|
for o in outputs:
|
||||||
if type(o[1]) == str:
|
if type(o[1]) == str:
|
||||||
@ -659,8 +655,6 @@ class Block():
|
|||||||
extranonce_start = len_coinbase + extranonce_start
|
extranonce_start = len_coinbase + extranonce_start
|
||||||
return tx[:44 + extranonce_start], tx[44+ len_coinbase:]
|
return tx[:44 + extranonce_start], tx[44+ len_coinbase:]
|
||||||
|
|
||||||
result = version + marke_flag + ninputs + b''.join(inputs) +\
|
|
||||||
nouts + b''.join(outputs) + witness + self.lock_time.to_bytes(4,'little')
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def deserialize(cls, stream):
|
def deserialize(cls, stream):
|
||||||
@ -669,12 +663,12 @@ class Block():
|
|||||||
stream.seek(-80, 1)
|
stream.seek(-80, 1)
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'hash': double_sha256(header),
|
'hash': double_sha256(header),
|
||||||
'version': int.from_bytes(stream.read(4), 'little'),
|
'version': stream.read(4),
|
||||||
'prev_block': stream.read(32),
|
'prev_block': stream.read(32),
|
||||||
'merkle_root': stream.read(32),
|
'merkle_root': stream.read(32),
|
||||||
'timestamp': int.from_bytes(stream.read(4), 'little'),
|
'timestamp': int.from_bytes(stream.read(4), 'little'),
|
||||||
'bits': int.from_bytes(stream.read(4), 'little'),
|
'bits': stream.read(4),
|
||||||
'nonce': int.from_bytes(stream.read(4), 'little'),
|
'nonce': stream.read(4),
|
||||||
'txs': read_var_list(stream, Transaction),
|
'txs': read_var_list(stream, Transaction),
|
||||||
'block_size': stream.tell(),
|
'block_size': stream.tell(),
|
||||||
'header': header
|
'header': header
|
||||||
@ -682,19 +676,17 @@ class Block():
|
|||||||
return cls(**kwargs)
|
return cls(**kwargs)
|
||||||
|
|
||||||
def serialize(self, hex = False):
|
def serialize(self, hex = False):
|
||||||
block = self.version.to_bytes(4,'little') + \
|
block = self.version + \
|
||||||
self.prev_block + \
|
self.prev_block + \
|
||||||
self.merkle_root + \
|
self.merkle_root + \
|
||||||
self.timestamp.to_bytes(4,'little') + \
|
self.timestamp.to_bytes(4,'little') + \
|
||||||
self.bits.to_bytes(4,'little') + \
|
self.bits + \
|
||||||
self.nonce.to_bytes(4,'little') + \
|
self.nonce + \
|
||||||
to_var_int(len (self.transactions))
|
to_var_int(len (self.transactions))
|
||||||
for t in self.transactions:
|
for t in self.transactions:
|
||||||
if t.hash == t.whash:
|
if t.hash == t.whash:
|
||||||
print("l")
|
|
||||||
block += t.serialize(segwit = 0)
|
block += t.serialize(segwit = 0)
|
||||||
else:
|
else:
|
||||||
print("s")
|
|
||||||
block += t.serialize(segwit = 1)
|
block += t.serialize(segwit = 1)
|
||||||
|
|
||||||
if hex:
|
if hex:
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user