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

    sender_address = request.form['sender_address']
    sender_private_key = request.form['sender_private_key']
    recipient_address = request.form['recipient_address']
    value = request.form['amount']

    transaction = Transaction(sender_address, sender_private_key,
                              recipient_address, value)

    array = {}
    array['address'] = sender_address
    array['public_key'] = ''
    array['private_key'] = sender_private_key
    array['timestamp'] = 1
    check_wallet_out = Wallet(array)
    check_wallet_out = check_wallet_out.ischeck_address()

    array['address'] = recipient_address
    check_wallet_in = Wallet(array)
    check_wallet_in = check_wallet_in.ischeck_address()
    try:
        response = {
            'transaction': transaction.to_dict(),
            'signature': transaction.sign_transaction()
        }
        if (check_wallet_out and check_wallet_in):
            return jsonify(response), 200
        else:
            return "Not address or private key", 500
    except:
        return "Not address or private key", 500
 def generate_tx(self, outputs, utxo):
     utxo.sign(self.sk)
     tx = Transaction(peer_data=self.peer_data,
                      inputs=[utxo],
                      outputs=outputs,
                      witnesses_included=True)
     msg = str(tx.to_dict())
     signature = sign(msg, self.sk)
     tx.sign_transaction(signature)
     return tx
Пример #3
0
 def test_transaction_dumping(self):
     u1 = Client()
     u2 = Client()
     outputs = [(u2.public_key, 5)]
     tx = Transaction(u1.public_key, u1.get_sk(), [], outputs, False)
     dictionary = tx.to_dict()
     self.assertEqual(dictionary['witnesses_included'], False)
     self.assertEqual(dictionary['originator'], u1.public_key)
     self.assertEqual(dictionary['witnesses'], [])
     self.assertEqual(dictionary['ip_counter'], 0)
     self.assertEqual(dictionary['inputs'], [])
     self.assertEqual(dictionary['op_counter'], 1)
     self.assertEqual(dictionary['outputs'], tx.get_outputs())
     self.assertEqual(dictionary['time'], tx.get_timestamp())