def test_get_transaction(self): tx = Transaction() input = TransactionInput() input.address = "" tx.add_input(input) tx.generate_hash() mp = Mempool() mp.flush_mempool() mp.add_transaction(tx) self.assertEqual(mp.get_transaction().to_json(), tx.to_json()) mp.close()
def add_transaction(self, val: Transaction) -> bool: """ This function add transaction to the mempool for further processing Parameters: val(Any): The transaction object to add to the mempool. Returns: boolean: A boolean result to show if the transaction is added successfully or not. """ print("adding") self.redis_client.rpush("mempool", json.dumps(val.to_json())) print("added tx") return True
def create_tx(addr): add_data = { "address": "1d3f347aada53547142da8edea5e0019e6ef31bb15", "vk": "-----BEGIN PUBLIC KEY-----\nMEkwEwYHKoZIzj0CAQYIKoZIzj0DAQEDMgAEHxzkpgh/lqgd1/rb7d+D+srhlhzG\ncOAveBQafVnHkffNR2aCiFHVQZKzhyO7iC/p\n-----END PUBLIC KEY-----\n", "sk": "-----BEGIN EC PRIVATE KEY-----\nMF8CAQEEGKtkXJ8xlejSSOl4mzNTYiXmb70wRByW1aAKBggqhkjOPQMBAaE0AzIA\nBB8c5KYIf5aoHdf62+3fg/rK4ZYcxnDgL3gUGn1Zx5H3zUdmgohR1UGSs4cju4gv\n6Q==\n-----END EC PRIVATE KEY-----\n" } tx = Transaction() add = Address() add.load(add_data["sk"], add_data["vk"]) # print(addr) tx.inputs = [] tx.inputs.append( TransactionInput.from_json({ 'previous_tx': "16e8dab3a9185d5329fac9cfdc0a81c7817826f701e747cb3751878061e4dc8c", 'index': 0, 'scriptSig': [ add.sign_message( json.dumps({ 'previous_tx': "16e8dab3a9185d5329fac9cfdc0a81c7817826f701e747cb3751878061e4dc8c", 'index': 0 }).encode("utf-8")).hex() ], 'address': addr, 'verifying_key': [add_data["vk"]] })) tx.outputs.append( TransactionOutput.from_json({ 'address': "yikgyyf67rr68t887tfc", 'value': 25, 'n': 0 })) tx.generate_hash() txf = tx.to_json() # print(txf['inputs'][0]['address']) return txf