def validate(self): pc = PublicKey.loads(self.public_key) ok = sha512(str( self.public_key).encode()).hexdigest() == self.from_addr return ok and validate_signature(pc.e, pc.n, self.get_message(), self.sign)
def get_balance(addr): blocks = get_blocks() transactions = sum((x.transactions for x in blocks), []) amount = 0 for transaction in transactions: if transaction.from_addr == addr: amount -= transaction.amount if transaction.to_addr == addr: amount += transaction.amount return amount f = open('wallet.json', 'r') wallet = json.loads(f.read()) f.close() public_key = PublicKey.loads(wallet['public_key']) private_key = PrivateKey.loads(wallet['private_key']) address = wallet['address'] print(add_transaction('0' * 64, 1, address, public_key, private_key)) print(get_transactions()) print(mine()) print(get_transactions()) # get_blocks() print(get_balance(address))
def from_dict(cls, data): return cls(data['from'], data['to'], data['amount'], data['sign'], PublicKey.loads(data['public_key']))