Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepark327 committed Nov 13, 2020
1 parent 226601f commit b43624b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def valid_block(self, block, prev_block):
if block.header.index == 0:
pass # TODO: re-calculate genesis' tx sign.
else:
self.valid_transaction(tx)
if not self.valid_transaction(tx):
return True

# TODO: Valid timestamp

Expand All @@ -218,14 +219,14 @@ def valid_block(self, block, prev_block):
def valid_transaction(self, tx):
if tx.sender == '':
# mint
pass # TODO: minting addr.
return True # TODO: minting addr.
else:
raw_tx = Transaction(tx.sender, tx.receiver, tx.amount, tx.data)
raw_tx_string = json.dumps(raw_tx.toDict(), sort_keys=True).encode()
raw_tx_digest = sha256(raw_tx_string).digest()

vk = VerifyingKey.from_string(bytearray.fromhex(tx.sender), curve=SECP256k1)
return vk.verify(bytes(bytearray.fromhex(tx.sign)), raw_tx_digest)
return vk.verify(bytearray.fromhex(tx.sign), raw_tx_digest)


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


global sk
global vk
# global vk
global Addr


Expand Down Expand Up @@ -111,7 +111,7 @@ def transaction_new():
return jsonify({'res': index}), 201


# Curl http://127.0.0.1:8327/pool
# Curl http://127.0.0.1:8327/transaction/pool
@app.route('/transaction/pool')
def transaction_pool():
return jsonify({'res': [tx.toDict() for tx in bc.transaction_pool]}), 200
Expand Down Expand Up @@ -169,9 +169,9 @@ def parser():
Addr = wallet.public_key.decode()
print(Addr)

# Generate sk & vk
# Generate sk # & vk
private_key = bytearray.fromhex(wallet.private_key)
sk = SigningKey.from_string(private_key, curve=SECP256k1)
vk = sk.verifying_key # wallet.public_key == vk.to_string("compressed").hex()
# vk = sk.verifying_key # wallet.public_key == vk.to_string("compressed").hex()

app.run(host='0.0.0.0', port=port)

0 comments on commit b43624b

Please sign in to comment.