Exemplo n.º 1
0
 def setUp(self):
     self.key = RSA.import_key(open('tests/test_rsa').read())
     self.key_pub = RSA.import_key(open('tests/test_rsa.pub').read())
     self.key_pub = binascii.hexlify(self.key_pub.exportKey(format="DER"))
     self.t = models.Transaction(value=10,
                                 receiver=self.key_pub,
                                 sender=self.key_pub)
Exemplo n.º 2
0
 def setUp(self):
     t = models.Transaction(value=10, receiver="r", sender="s")
     self.keyr = RSA.import_key(open('tests/test_rsa').read())
     t.sign(self.keyr)
     self.transactions = [str(t)]
     self.prev_hash = SHA3_256.new().update(
         str.encode("fake previous block")).hexdigest()
     self.difficulty = 1
     self.block = models.Block(prev_hash=self.prev_hash,
                               transactions=self.transactions,
                               difficulty=self.difficulty)
Exemplo n.º 3
0
def handle_transactions():
    if request.method == "GET":
        return json.jsonify(node.mem_pool)
    if request.method == "POST":
        transaction_json = request.json["transaction"]
        new_transaction = models.Transaction(
            value=transaction_json["value"],
            receiver=transaction_json["receiver"],
            sender=transaction_json["sender"],
            signature=transaction_json["signature"]
        )
        node.accept_transaction(str(new_transaction))

        return f"Added transaction {new_transaction}"
Exemplo n.º 4
0
 def setUp(self):
     self.t = models.Transaction(value=10, receiver="r", sender="s")
     self.keyr = RSA.import_key(open('tests/test_rsa').read())
     self.t.sign(self.keyr)
     self.node = node.Node()
Exemplo n.º 5
0
from pychain import models
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA3_256

keyr = RSA.import_key(open('tests/test_rsa').read())
key_pub = RSA.import_key(open('tests/test_rsa.pub').read())
key_pub = binascii.hexlify(key_pub.exportKey(format="DER"))
t = models.Transaction(value=10, receiver=key_pub, sender=key_pub)
t.sign(keyr)
print(t)