def add_transaction(self, recipient, sender, signature, amount=1.0): """ Append a new value as well as the last blockchain value to the blockchain. Arguments: :sender: The sender of the coins. :recipient: The recipient of the coins. :amount: The amount of coins sent with the transaction (default = 1.0) """ if self._is_hosting_node_none(): return False transaction = Transaction(sender, recipient, signature, amount) if Verification.verify_transaction(transaction, self.get_balance): signature = Wallet.verify_signature(transaction) if signature: self._open_transactions.append(transaction) self.save_data() return True return False self._delete_invalid_transaction_block() return False
def createTrans(self, sequance_number, signature, fromUser, toUser, transaction_fee, data, amount, transaction_time, transaction_sender=None): # Printing the info of tx dprint("\nCreating the transaction") dprint("***") dprint(sequance_number) dprint(signature) dprint(fromUser) dprint(toUser) dprint(data) dprint(amount) dprint("***\n") # End # Some data signature_class = Signature.fromBase64(signature) temp_signature = signature_class.toBase64() already_got = self.tx_already_got(temp_signature) # End # Validation dprint("\nValidation") if Ecdsa.verify((str(sequance_number)+str(fromUser)+str(toUser)+str(data)+str(amount)+str(transaction_fee)+str(transaction_time)), signature_class, PublicKey.fromPem(fromUser)) and not amount < self.minumum_transfer_amount and not transaction_fee < self.transaction_fee and not already_got and not (int(time.time()) - transaction_time) > 60: dprint("Signature is valid") dprint("Getsequancenumber: "+str(GetSequanceNumber(fromUser, self)+1)) if sequance_number == (GetSequanceNumber(fromUser, self)+1): dprint("Sequance number is valid") balance = GetBalance(fromUser, self) if balance >= (float(amount)+float(transaction_fee)) and (balance - (float(amount)+float(transaction_fee))) > 2: dprint("Amount is valid") # Local saving the_tx = Transaction( sequance_number= sequance_number, signature=temp_signature, fromUser= fromUser, toUser=toUser, data = data, amount = amount, transaction_fee= transaction_fee, time_of_transaction = transaction_time ) self.pendingTransaction.append(the_tx) self.change_transaction_fee() self.save_block() # End self.propagating_the_tx(the_tx) return True dprint(" Validation end")
def _update_current_open_transactions(self, open_transactions): """""" # We need to convert the loaded data because Transactions should use OrderedDict updated_transactions = [] for trans in open_transactions: updated_transaction = Transaction(trans['sender'], trans['recipient'], trans['signature'], trans['amount']) updated_transactions.append(updated_transaction) self._open_transactions = updated_transactions
def _update_current_block_chain(self, blockchain): """""" updated_blockchain = [] for block in blockchain: trans_block = [ Transaction(trans['sender'], trans['recipient'], trans['signature'], trans['amount']) for trans in block['transactions'] ] block = Block(block['index'], block['previous_hash'], trans_block, block['proof'], block['timestamp']) updated_blockchain.append(block) self.chain = updated_blockchain
def get_reward(hosting_node_id): MINING_REWARD = 10 OWNER = "" return Transaction("MINING", hosting_node_id, MINING_REWARD)
def get_mine_reward(cls, host_name): return Transaction("MINING", host_name, amount=cls.MINING_REWARD)