Пример #1
0
def generate_genesis_block(WalletA):

    coinbase = Wallet()

    genesis = Transaction("0", coinbase.publicKey, WalletA.publicKey, 100,
                          None)
    genesis.generate_signature(coinbase.privateKey)
    genesis.outputs.append(
        TransactionOutput(genesis.transaction_id, genesis.reciepient,
                          genesis.value))
    main_utxo[genesis.outputs[0].id] = genesis.outputs[0]

    print("Creating and Mining Genesis block... ")
    block = Block("Hi I am a block 0", "0")
    block.add_transaction(genesis, main_utxo)
    add_block(block)
Пример #2
0
    def send_funds(self, reciepient, value_sent , main_utxo):
        if(self.get_balance(main_utxo) < value_sent):
            print("#Not Enough funds to send transaction. Transaction Discarded.")
            return None

        total = 0
        inputs = []
        for key , value in self.utxo.items():
            utxo = value
            total += utxo.value 
            inputs.append(TransactionInput(utxo.id , utxo))
            if(total > value_sent):
                break

        #Pass "0" as default argument
        new_transaction = Transaction("0", self.publicKey, reciepient, value_sent, inputs)
        new_transaction.generate_signature(self.privateKey)  

        for obj in inputs:
            self.utxo.pop(obj.transaction_output_id)

        return new_transaction