Example #1
0
def generate_transaction():
    public_key = request.form['public_key']
    private_key = request.form['private_key']
    amount = request.form['amount']
    fees = request.form['fees']

    transaction = Transaction(private_key, public_key, amount, fees)
    transaction.sign()

    response = {'signature' : transaction.signature}
    return jsonify(response), 200
Example #2
0
 def generate_transaction(self, amount):
     self.signature_dict['signature_type'] = self.signature_type
     self.receiver_signature_dict['signature_type'] = self.signature_type
     new_transaction = Transaction(
         debit_user_public_key=blockchain.get_user_public_key(
             self.signature_dict),
         credit_user_public_key=blockchain.get_user_public_key(
             self.receiver_signature_dict),
         transaction_value=amount)
     new_transaction.sign(self.signature_dict, self.signature_type)
     return new_transaction.serialize()
Example #3
0
def add_transaction(to, amount, addr, public: PublicKey, private: PrivateKey):
    t = Transaction(addr, to, amount, '', public)
    print(t.message())
    t.sign = sign(t.message(), private)
    data = t.to_dict()
    resp = requests.post(b_url + '/add_transaction', json=data)
    return resp.text
Example #4
0
def new_transaction() -> Response:
    """Add a new transaction to the blockchain."""
    values = request.form
    required = ('sender_address', 'sender_private_key', 'recipient_address',
                'stock', 'quantity')

    for r in required:
        if r not in values:
            print(values)
            return Response('Missing form value', 400)

    transaction = Transaction(values['sender_address'],
                              values['sender_private_key'],
                              values['recipient_address'], values['stock'],
                              values['quantity'])

    signature = transaction.sign()

    try:
        blockchain.submit_transaction(values['sender_address'],
                                      values['recipient_address'],
                                      values['stock'], values['quantity'],
                                      signature)
    except Exception as error:
        print("[!] Error: ", error)

    return Response('Successfully added', 200)
Example #5
0
def prepare_chain_for_tests():
    pub, prv = cryptutil.fake_new_keys(2048)
    pub2, prv2 = cryptutil.fake_new_keys(2048)

    pub_txt = pub.exportKey("PEM").decode('ascii')
    pub2_txt = pub2.exportKey("PEM").decode('ascii')

    block_chain.mine_block(pub_txt)
    block_chain.mine_block(pub2_txt)
    block_chain.mine_block(pub_txt)

    trx = Transaction(pub_txt, pub2_txt, 10)
    trx.sign(prv)
    block_chain.add_transaction(trx)

    trx = Transaction(pub_txt, pub2_txt, 10)
    trx.sign(prv)
    block_chain.add_transaction(trx)

    block_chain.mine_block(pub_txt)