Skip to content

Commit

Permalink
chore: remove some commented out code and some unneccesary files
Browse files Browse the repository at this point in the history
  • Loading branch information
15IITian committed Apr 27, 2024
1 parent a8ffaa2 commit 69bf587
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 311 deletions.
45 changes: 6 additions & 39 deletions Block.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def get_mined_tx_data(cls, tx_files):
# sort the tx_included list
tx_included = sorted(tx_included, key=lambda x: x['fee_rate'],reverse=True)


print("tx_count: {}".format(tx_count))
print("fee_collected: {}".format(fee_collected))
print("weight_stored: {}".format(weight_stored))


return (tx_count,tx_included,fee_collected,weight_stored)


Expand Down Expand Up @@ -171,38 +175,13 @@ def create_block(cls, tx_files):
print(serliased)







# print("merkle root : \n {}".format(valid_block.merkle_root.hex()))
# print(serliased)
# serliased_in_bytes= bytes.fromhex(serliased)


# desired_slice = serliased_in_bytes[36:68].hex()
# print(desired_slice)
# print(desired_slice == valid_block.merkle_root.hex())
# print("{} {} {} {} {} {} ".format(valid_block.version,(valid_block.prev_block).hex(),(valid_block.merkle_root).hex(),valid_block.timestamp,(valid_block.bits).hex(),valid_block.nonce))

# print("block hash: {}".format(valid_block.hash()))






# serliased coinbase transaction
print(serliased_coinbase_tx)

# print all txids
for tx_id in tx_ids_list:
print(tx_id)


print(tx_id)





Expand All @@ -217,9 +196,6 @@ def check_pow(cls,serliased_block_header,target,nonce):
proof = little_endian_to_int(h256)
# return whether this integer is less than the target
target= int.from_bytes(bytes.fromhex(target),"big")


# print("{} : {} \n".format(nonce,proof.to_bytes(32,"big").hex()) )
return proof < target

def get_valid_nonce(self,target):
Expand All @@ -233,15 +209,6 @@ def get_valid_nonce(self,target):
else:
print("shit-man")
break
# if flag:
# print("required nonce: {}".format(self.nonce))

return self



# block_header= "0060e92f3f18ee206e1350f1cabe4ff319851d4c3c64b8d2d90e030000000000000000005f73d58ab5be2407065a26a290750250c1ebebc46a280e6f2b1c5032b3397c2ab48c2a66ffff001f00000000"
# target ="0000ffff00000000000000000000000000000000000000000000000000000000"

# print(Block.check_pow(block_header,target))

10 changes: 1 addition & 9 deletions Helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,11 @@ def merkle_root(hashes):


def HASH160(s):
#sha256 followed by ripemd160
# return hashlib.new('ripemd160', hashlib.sha256(s).digest()).digest()
return ripemd160(s)


a= 5
# print(HASH160(a.to_bytes(4,"big")))





# print(ripemd160(a.to_bytes(4,"big")).hex())
# h = RIPEMD160.new()
# h.update(b'Hello')
# print h.hexdigest()
# print(HASH160(a.to_bytes(4,"big")))
41 changes: 1 addition & 40 deletions Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,7 @@
from Helper import *


script_types= {

"p2pkh":{
"scriptpubkey":["OP_DUP","OP_HASH160","OP_PUSHBYTES_20","<20_BYTE_HASH>","OP_EQUALVERIFY","OP_CHECKSIG"],
"script_sig":["<Signature>","<pubkey>"]
},
"p2sh":{
"scriptpubkey":["OP_HASH160", "OP_PUSHBYTES_20", "<20_BYTE_HASH>", "OP_EQUAL"],
"script_sig":"" ## can be anything depending on redeem script but will contain redeem script

},
"bare-multisig":{
"scriptpubkey":["OP_PUSHNUM_M","N(PushBytes + PubKeys)", "OP_PUSHNUM_N", "OP_CHECKMULTISIG"],
"script_sig":[]
},

"v0_p2wpkh":{
"scriptpubkey":["OP_0", "OP_PUSHBYTES_20","<20_BYTE_HASH>"],
"script_sig":""
},
"v0_p2wsh":{
"scriptpubkey":["OP_0" "OP_PUSHBYTES_32" "<32_Byte_Hash>"],
"script_sig":""
},
"v1_p2tr":{
"scriptpubkey":["OP_PUSHNUM_1", "OP_PUSHBYTES_32", "<32_BYTE_HASH>"],
"script_sig":""
},
"v0_p2sh_p2wpkh":{
"scriptpubkey":["OP_HASH160", "OP_PUSHBYTES_20", "<20_BYTE_HASH>", "OP_EQUAL"],
"script_sig":["OP_PUSHBYTES_22","<20 BYTE REDEEM_SCRIPT HASH>"],
"witness":[]
},
"v0_p2sh_p2wsh":{
"scriptpubkey":["OP_HASH160", "OP_PUSHBYTES_20", "<20_BYTE_HASH>", "OP_EQUAL"],
"script_sig":["OP_PUSHBYTES_34","<20 BYTE REDEEM_SCRIPT HASH>"],
"witness":[]
}

}

class Script:
def __init__(self,cmds=None):
if cmds is None:
Expand Down
195 changes: 0 additions & 195 deletions Test.ipynb

This file was deleted.

Binary file modified __pycache__/Block.cpython-311.pyc
Binary file not shown.
28 changes: 1 addition & 27 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from Transacttions import *
from Block import *
all_files = list_all_tx()
# print(len(all_files))

# modify the tx files which contains some additional fields which are important
new_files= Tx.modified_tx_files(all_files)
Expand All @@ -28,33 +27,8 @@
# now segregate the transactions which can be included in our block i.e do not have any locktime constraints

(valid_tx_unlocked,_,zeroes)= Tx.get_unlocked_tx(valid_tx_list)
# print("valid_tx: {}".format(valid_tx))
# print("valid_tx_unlocked: {}".format(len(valid_tx_unlocked)))
# print("zeroes: {}".format(zeroes))







(tx_count,tx_included,fee_collected,weight_stored) =Block.get_mined_tx_data(valid_tx_unlocked)

# print("tx_count:{}".format(tx_count))
# print("tx_included: {}".format(tx_included))
# print("fee_collected:{}".format(fee_collected))
# print("weight_stored:{}".format(weight_stored))
# for tx in new_files:
# print(tx["fee_rate"])

# print(new_files[0])


# now create a block
Block.create_block(tx_included)

# tx_hashes_list= []

# for tx in valid_tx_list:
# tx_hash = Transacttions.Tx.get_tx_hash(tx)
# tx_hashes_list.append(tx_hash)
# print(merkle_root(tx_hashes_list))
Loading

0 comments on commit 69bf587

Please sign in to comment.