Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement insertunsafely command #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions walletclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,43 @@ def insertmany(webcash):
save_webcash_wallet(webcash_wallet)
print(f"Done! Saved e{merged_webcash.amount} in the wallet.")

@cli.command("insertunsafely")
Copy link

@jokpine jokpine May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@cli.command("insertunsafely")
@cli.command("insertunsafely", short_help="Directly insert the given webcash into the wallet. WARNING: This is unsafe: webcash status is not checked on insertion and the deterministic wallet is not used (recovery will not catch any webcash inserted in this manner).", hidden=True)

@click.argument("webcash", nargs=-1)
@lock_wallet
def insertunsafely(webcash):
"""
Directly insert the given webcash into the wallet.

WARNING: This is insecure and does not check the status of any of the
webcash. You probably don't want to use this.

WARNING: This will not use the deterministic wallet. Recovery will not
catch any webcash inserted in this manner.
"""

webcash_wallet = load_webcash_wallet()

acks = check_legal_agreements(webcash_wallet)
if not acks:
print("User must acknowledge and agree to the terms first.")
return

webcashes = list(set(webcash))

# use set to filter out duplicates by total string value
webcashes = list(set(webcash))

# deserialize
webcashes = [SecretWebcash.deserialize(wc) for wc in webcash]

# further filter out duplicates by secret_value
wc_secrets = [wc.secret_value for wc in webcashes]
deduped = list(set([(wc_secrets.count(wc.secret_value), str(wc)) for wc in webcashes]))
webcashes = [x[1] for x in deduped]

webcash_wallet["webcash"].extend(webcashes)

print(f"Inserted {len(webcashes)} webcash" + ("es" if len(webcashes) > 1 else "") + " into the wallet.")

@cli.command("pay")
@click.argument('amount')
Expand Down