Make the wallet backwards-compatible
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import base64, socket, sys, time
|
import base64, socket, sys, time
|
||||||
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
|
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
|
||||||
|
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, PublicFormat, NoEncryption
|
||||||
|
|
||||||
def format_address(raw_address):
|
def format_address(raw_address):
|
||||||
return base64.b64encode(raw_address).decode()
|
return base64.b64encode(raw_address).decode()
|
||||||
@@ -23,7 +24,7 @@ def write_transaction(timestamp, message, amount):
|
|||||||
print(f"{formatted_time} {message:<44} {format_amount(amount):>14}")
|
print(f"{formatted_time} {message:<44} {format_amount(amount):>14}")
|
||||||
|
|
||||||
def show_balance(public_key):
|
def show_balance(public_key):
|
||||||
public_key_raw = public_key.public_bytes_raw()
|
public_key_raw = public_key.public_bytes(Encoding.Raw, PublicFormat.Raw)
|
||||||
with open("blockchain", "rb") as f:
|
with open("blockchain", "rb") as f:
|
||||||
total_amount = 0
|
total_amount = 0
|
||||||
while True:
|
while True:
|
||||||
@@ -101,7 +102,7 @@ def send_payment(private_key, target, amount, fee):
|
|||||||
if amount == 0:
|
if amount == 0:
|
||||||
raise Exception("Amount must not be zero")
|
raise Exception("Amount must not be zero")
|
||||||
fee = parse_amount_checked(fee)
|
fee = parse_amount_checked(fee)
|
||||||
public_key_raw = private_key.public_key().public_bytes_raw()
|
public_key_raw = private_key.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw)
|
||||||
transaction_id = find_free_id(public_key_raw)
|
transaction_id = find_free_id(public_key_raw)
|
||||||
transaction_prefix = transaction_id.to_bytes(4, "big") + \
|
transaction_prefix = transaction_id.to_bytes(4, "big") + \
|
||||||
public_key_raw + \
|
public_key_raw + \
|
||||||
@@ -141,12 +142,12 @@ def main():
|
|||||||
private_key = Ed25519PrivateKey.from_private_bytes(private_key_raw)
|
private_key = Ed25519PrivateKey.from_private_bytes(private_key_raw)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
private_key = Ed25519PrivateKey.generate()
|
private_key = Ed25519PrivateKey.generate()
|
||||||
private_key_raw = private_key.private_bytes_raw()
|
private_key_raw = private_key.private_bytes(Encoding.Raw, PrivateFormat.Raw, NoEncryption())
|
||||||
with open("wallet-key", "wb") as f:
|
with open("wallet-key", "wb") as f:
|
||||||
f.write(private_key_raw)
|
f.write(private_key_raw)
|
||||||
|
|
||||||
public_key = private_key.public_key()
|
public_key = private_key.public_key()
|
||||||
wallet_addr = format_address(public_key.public_bytes_raw())
|
wallet_addr = format_address(public_key.public_bytes(Encoding.Raw, PublicFormat.Raw))
|
||||||
print(f"Your wallet address: {wallet_addr}\n")
|
print(f"Your wallet address: {wallet_addr}\n")
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user