示例#1
0
    def test_transaction_to_dict(self):
        wallet = Wallet()
        transaction = Transaction(wallet.pubkey, "CityU", 1)
        content = transaction.to_dict()

        self.assertIsInstance(content, dict)
        self.assertEqual(list(content.keys()), ["sender", "recipient", "value", "fee"])
示例#2
0
 def sign_transaction(self, transaction: Transaction) -> str:
     '''
     method to return the signature that is coming from the actual owner in a transaction
     implemented in the Wallet class instead of Transaction class to protect the private key from illegal access
     '''
     signer = PKCS1_v1_5.new(self._private_key)
     payload = str(transaction.to_dict()).encode('utf-8')
     h = SHA.new(payload)
     return binascii.hexlify(signer.sign(h)).decode('ascii')