diff --git a/.vscode/settings.json b/.vscode/settings.json index b8719fde..a4276005 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "locktime", "prevout", "RIPEMD", "secp", diff --git a/Block.py b/Block.py index 9c79c6c7..72d9d18f 100644 --- a/Block.py +++ b/Block.py @@ -6,9 +6,6 @@ -GENESIS_BLOCK = bytes.fromhex('0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c') -TESTNET_GENESIS_BLOCK = bytes.fromhex('0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff001d1aa4ae18') -LOWEST_BITS = bytes.fromhex('ffff001d') MAX_BLOCK_SIZE= 4000000 BLOCK_HEADER_SIZE= 320 diff --git a/Opcodes.py b/Opcodes.py index 5568531a..35f9d1f6 100644 --- a/Opcodes.py +++ b/Opcodes.py @@ -275,7 +275,7 @@ -# this function will give the funciton object from the string +# this function will give the function object from the string def get_function_by_name(func_name): # Check if the function exists in the global namespace if func_name in globals() and callable(globals()[func_name]): @@ -284,7 +284,7 @@ def get_function_by_name(func_name): return None -all_opcodes_used : { 'OP_ELSE', 'OP_ENDIF'} +# all_opcodes_used : { 'OP_ELSE', 'OP_ENDIF'} diff --git a/Transacttions.py b/Transacttions.py index cac1e3e9..2593f656 100644 --- a/Transacttions.py +++ b/Transacttions.py @@ -304,7 +304,6 @@ def verify(cls,file): if not Tx.verify_input(file,i): return False - # verify the signatures provided. return True @@ -539,7 +538,7 @@ def get_unlocked_tx(cls,tx_files): if unlock_flag: tx_unlocked.append(file) - return (tx_unlocked,tx_locked,zeroes) + return tx_unlocked diff --git a/__pycache__/Block.cpython-311.pyc b/__pycache__/Block.cpython-311.pyc index 6fb11dc0..b41f749b 100644 Binary files a/__pycache__/Block.cpython-311.pyc and b/__pycache__/Block.cpython-311.pyc differ diff --git a/__pycache__/Helper.cpython-311.pyc b/__pycache__/Helper.cpython-311.pyc index be826db9..34b0c060 100644 Binary files a/__pycache__/Helper.cpython-311.pyc and b/__pycache__/Helper.cpython-311.pyc differ diff --git a/__pycache__/Opcodes.cpython-311.pyc b/__pycache__/Opcodes.cpython-311.pyc index 51dd83c2..3fc2856e 100644 Binary files a/__pycache__/Opcodes.cpython-311.pyc and b/__pycache__/Opcodes.cpython-311.pyc differ diff --git a/__pycache__/RIPEMD160.cpython-311.pyc b/__pycache__/RIPEMD160.cpython-311.pyc deleted file mode 100644 index 7e0da101..00000000 Binary files a/__pycache__/RIPEMD160.cpython-311.pyc and /dev/null differ diff --git a/__pycache__/Transacttions.cpython-311.pyc b/__pycache__/Transacttions.cpython-311.pyc index d5c7a58a..2b0591d4 100644 Binary files a/__pycache__/Transacttions.cpython-311.pyc and b/__pycache__/Transacttions.cpython-311.pyc differ diff --git a/__pycache__/ecc.cpython-311.pyc b/__pycache__/ecc.cpython-311.pyc index c6eafa70..b4cdd7b6 100644 Binary files a/__pycache__/ecc.cpython-311.pyc and b/__pycache__/ecc.cpython-311.pyc differ diff --git a/ecc.py b/ecc.py index 9741f65b..1d03e1e6 100644 --- a/ecc.py +++ b/ecc.py @@ -329,65 +329,3 @@ def parse(cls, signature_bin): raise SyntaxError("Signature too long") return cls(r, s) - - -# class PrivateKey: - -# def __init__(self, secret): -# self.secret = secret -# self.point = secret * G - -# def hex(self): -# return '{:x}'.format(self.secret).zfill(64) - -# def sign(self, z): -# k = self.deterministic_k(z) -# # r is the x coordinate of the resulting point k*G -# r = (k * G).x.num -# # remember 1/k = pow(k, N-2, N) -# k_inv = pow(k, N - 2, N) -# # s = (z+r*secret) / k -# s = (z + r * self.secret) * k_inv % N -# if s > N / 2: -# s = N - s -# # return an instance of Signature: -# # Signature(r, s) -# return Signature(r, s) - -# def deterministic_k(self, z): -# k = b'\x00' * 32 -# v = b'\x01' * 32 -# if z > N: -# z -= N -# z_bytes = z.to_bytes(32, 'big') -# secret_bytes = self.secret.to_bytes(32, 'big') -# s256 = hashlib.sha256 -# k = hmac.new(k, v + b'\x00' + secret_bytes + z_bytes, s256).digest() -# v = hmac.new(k, v, s256).digest() -# k = hmac.new(k, v + b'\x01' + secret_bytes + z_bytes, s256).digest() -# v = hmac.new(k, v, s256).digest() -# while True: -# v = hmac.new(k, v, s256).digest() -# candidate = int.from_bytes(v, 'big') -# if candidate >= 1 and candidate < N: -# return candidate -# k = hmac.new(k, v + b'\x00', s256).digest() -# v = hmac.new(k, v, s256).digest() - -# def wif(self, compressed=True, testnet=False): -# # convert the secret from integer to a 32-bytes in big endian using num.to_bytes(32, 'big') -# secret_bytes = self.secret.to_bytes(32, 'big') -# # prepend b'\xef' on testnet, b'\x80' on mainnet -# if testnet: -# prefix = b'\xef' -# else: -# prefix = b'\x80' -# # append b'\x01' if compressed -# if compressed: -# suffix = b'\x01' -# else: -# suffix = b'' -# # encode_base58_checksum the whole thing -# return encode_base58_checksum(prefix + secret_bytes + suffix) - - diff --git a/image-1.png b/image-1.png new file mode 100644 index 00000000..6a11b17a Binary files /dev/null and b/image-1.png differ diff --git a/image-2.png b/image-2.png new file mode 100644 index 00000000..0b0282d7 Binary files /dev/null and b/image-2.png differ diff --git a/image-3.png b/image-3.png new file mode 100644 index 00000000..4e3ba76c Binary files /dev/null and b/image-3.png differ diff --git a/image-4.png b/image-4.png new file mode 100644 index 00000000..43f0a84a Binary files /dev/null and b/image-4.png differ diff --git a/image-5.png b/image-5.png new file mode 100644 index 00000000..2ebd0044 Binary files /dev/null and b/image-5.png differ diff --git a/image-6.png b/image-6.png new file mode 100644 index 00000000..1e58aad9 Binary files /dev/null and b/image-6.png differ diff --git a/image-7.png b/image-7.png new file mode 100644 index 00000000..706823a8 Binary files /dev/null and b/image-7.png differ diff --git a/image-8.png b/image-8.png new file mode 100644 index 00000000..7fcc7e2e Binary files /dev/null and b/image-8.png differ diff --git a/image.png b/image.png new file mode 100644 index 00000000..4238dcff Binary files /dev/null and b/image.png differ diff --git a/main.py b/main.py index 2effd493..cfc4d41d 100644 --- a/main.py +++ b/main.py @@ -10,25 +10,33 @@ new_files= sorted(new_files, key=lambda x: x['fee_rate'],reverse=True) -invalid_tx = 0 -valid_tx = 0 + valid_tx_list=[] invalid_tx_list = [] for file in new_files: if Tx.verify(file): - valid_tx+=1 valid_tx_list.append(file) else: - invalid_tx+=1 invalid_tx_list.append(file) # 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) +valid_tx_unlocked= Tx.get_unlocked_tx(valid_tx_list) + + + (tx_count,tx_included,fee_collected,weight_stored) =Block.get_mined_tx_data(valid_tx_unlocked) + + + + # now create a block + + + + Block.create_block(tx_included) diff --git a/output.txt b/output.txt index ce83740a..0172b4aa 100644 --- a/output.txt +++ b/output.txt @@ -1,4 +1,4 @@ -0060e92f3f18ee206e1350f1cabe4ff319851d4c3c64b8d2d90e03000000000000000000664d84331a42280c640a257b7e2223c2774445a448668a242a075add51187f57252f2f66ffff001fc8060000 +0060e92f3f18ee206e1350f1cabe4ff319851d4c3c64b8d2d90e03000000000000000000664d84331a42280c640a257b7e2223c2774445a448668a242a075add51187f57d2343066ffff001fc4780000 010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff11030cd3bf0c004f4345414e2e58595a002effffffff02e412bf13000000001976a9142c30a6aaac6d96687291475d7d52f4b469f665a688ac0000000000000000266a24aa21a9ed68d3d720d695be2c9d1e2f33c3d9d1042bdec1ce26b563afdc471db6a02a12520120000000000000000000000000000000000000000000000000000000000000000000000000 96cb0dce25d42069df3ad24623a1d0c303e32b30412821f25cb7f6619d2e66c5 dcd522b3588c7adb0418454539e1a929fff936f211e5a20383fdcbc3ad8751b9 diff --git a/trial.ipynb b/trial.ipynb new file mode 100644 index 00000000..3a87caca --- /dev/null +++ b/trial.ipynb @@ -0,0 +1,189 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from Helper import *\n", + "from Transacttions import *\n", + "from Block import *" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'version': 2,\n", + " 'locktime': 0,\n", + " 'vin': [{'txid': '64ca1941edef34b690dd6672c7d395c60882067f7f3fc396e64d88e39c1da5b4',\n", + " 'vout': 0,\n", + " 'prevout': {'scriptpubkey': '0014d5bfb7a6d05d44c1e14443919b30d284c0c0a10a',\n", + " 'scriptpubkey_asm': 'OP_0 OP_PUSHBYTES_20 d5bfb7a6d05d44c1e14443919b30d284c0c0a10a',\n", + " 'scriptpubkey_type': 'v0_p2wpkh',\n", + " 'scriptpubkey_address': 'bc1q6klm0fkst4zvrc2ygwgekvxjsnqvpgg2jjfurm',\n", + " 'value': 10740},\n", + " 'scriptsig': '',\n", + " 'scriptsig_asm': '',\n", + " 'witness': ['3044022100884219ecbb54a6ec4d09597ca6aca49692ded3c2ffb13d1858ca5b70e59fabb4021f2de73021471a01d8f03a71a923b662f00120d181d0f7fa8e06faa1bb750e8f01',\n", + " '0271d4e7a84804c075017593271c370e8983f704f123d22aa747cd321268981cba'],\n", + " 'is_coinbase': False,\n", + " 'sequence': 4294967293}],\n", + " 'vout': [{'scriptpubkey': 'a91450feb99697a4901d3fe082eca341204fb6711b9487',\n", + " 'scriptpubkey_asm': 'OP_HASH160 OP_PUSHBYTES_20 50feb99697a4901d3fe082eca341204fb6711b94 OP_EQUAL',\n", + " 'scriptpubkey_type': 'p2sh',\n", + " 'scriptpubkey_address': '395H8VPYPtAoZWa2bx5SRyN2VojXrsb7j3',\n", + " 'value': 9520}]}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "all_files= list_all_tx()\n", + "all_files[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'version': 2,\n", + " 'locktime': 0,\n", + " 'vin': [{'txid': '64ca1941edef34b690dd6672c7d395c60882067f7f3fc396e64d88e39c1da5b4',\n", + " 'vout': 0,\n", + " 'prevout': {'scriptpubkey': '0014d5bfb7a6d05d44c1e14443919b30d284c0c0a10a',\n", + " 'scriptpubkey_asm': 'OP_0 OP_PUSHBYTES_20 d5bfb7a6d05d44c1e14443919b30d284c0c0a10a',\n", + " 'scriptpubkey_type': 'v0_p2wpkh',\n", + " 'scriptpubkey_address': 'bc1q6klm0fkst4zvrc2ygwgekvxjsnqvpgg2jjfurm',\n", + " 'value': 10740},\n", + " 'scriptsig': '',\n", + " 'scriptsig_asm': '',\n", + " 'witness': ['3044022100884219ecbb54a6ec4d09597ca6aca49692ded3c2ffb13d1858ca5b70e59fabb4021f2de73021471a01d8f03a71a923b662f00120d181d0f7fa8e06faa1bb750e8f01',\n", + " '0271d4e7a84804c075017593271c370e8983f704f123d22aa747cd321268981cba'],\n", + " 'is_coinbase': False,\n", + " 'sequence': 4294967293,\n", + " 'sequence_result': {'rbf': True, 'relative_locktime': False}}],\n", + " 'vout': [{'scriptpubkey': 'a91450feb99697a4901d3fe082eca341204fb6711b9487',\n", + " 'scriptpubkey_asm': 'OP_HASH160 OP_PUSHBYTES_20 50feb99697a4901d3fe082eca341204fb6711b94 OP_EQUAL',\n", + " 'scriptpubkey_type': 'p2sh',\n", + " 'scriptpubkey_address': '395H8VPYPtAoZWa2bx5SRyN2VojXrsb7j3',\n", + " 'value': 9520}],\n", + " 'is_segwit': True,\n", + " 'fee': 1220,\n", + " 'fee_rate': 2.766439909297052,\n", + " 'weights': 441}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_files= Tx.modified_tx_files(all_files)\n", + "new_files[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'version': 2,\n", + " 'locktime': 0,\n", + " 'vin': [{'txid': 'e3acb27a9fb6593822a4d8bbb8be9f9516e33123f196a41fc2801a9cae278ba4',\n", + " 'vout': 0,\n", + " 'prevout': {'scriptpubkey': '5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_asm': 'OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_type': 'v1_p2tr',\n", + " 'scriptpubkey_address': 'bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d',\n", + " 'value': 546},\n", + " 'scriptsig': '',\n", + " 'scriptsig_asm': '',\n", + " 'witness': ['265f6c3128efad948b8e1d11e1cd165c457e9e5da32f0e4093d81221aa6ecd6ec9bebbda812f4aa8c2caabf50575d22b551cd95d27ec015031950589869b5d26'],\n", + " 'is_coinbase': False,\n", + " 'sequence': 2147483649,\n", + " 'sequence_result': {'rbf': True, 'relative_locktime': False}},\n", + " {'txid': 'ef575d36c46466f419678345bd0fc17d65cc1a5741a47ac272d9e329dab7c0c9',\n", + " 'vout': 1,\n", + " 'prevout': {'scriptpubkey': '5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_asm': 'OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_type': 'v1_p2tr',\n", + " 'scriptpubkey_address': 'bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d',\n", + " 'value': 1811712},\n", + " 'scriptsig': '',\n", + " 'scriptsig_asm': '',\n", + " 'witness': ['8b8b8a72ac3d38c85fb59b0ba462d6a4ef39b73bd86a3ac8a300e5ab52033729ecd442e2b0eb5aba0ba9111ad0bccbdb4d24483caf482ebe6d2b819825f27731'],\n", + " 'is_coinbase': False,\n", + " 'sequence': 2147483649,\n", + " 'sequence_result': {'rbf': True, 'relative_locktime': False}}],\n", + " 'vout': [{'scriptpubkey': '5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_asm': 'OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_type': 'v1_p2tr',\n", + " 'scriptpubkey_address': 'bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d',\n", + " 'value': 546},\n", + " {'scriptpubkey': '5120d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_asm': 'OP_PUSHNUM_1 OP_PUSHBYTES_32 d7b0161160dc8ce46dfbf55c602ffeef5ed4ebcadebbe077918819b0aa1b73e6',\n", + " 'scriptpubkey_type': 'v1_p2tr',\n", + " 'scriptpubkey_address': 'bc1p67cpvytqmjxwgm0m74wxqtl7aa0df672m6a7qau33qvmp2smw0nqrgxc8d',\n", + " 'value': 1809391}],\n", + " 'is_segwit': True,\n", + " 'fee': 2321,\n", + " 'fee_rate': 2.2231800766283527,\n", + " 'weights': 1044}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_files[4]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}