mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 02:54:20 +01:00
fix: cashu send --lock (#570)
This commit is contained in:
@@ -135,16 +135,24 @@ async def send(
|
|||||||
sig_all=True,
|
sig_all=True,
|
||||||
n_sigs=1,
|
n_sigs=1,
|
||||||
)
|
)
|
||||||
print(f"Secret lock: {secret_lock}")
|
logger.debug(f"Secret lock: {secret_lock}")
|
||||||
|
|
||||||
await wallet.load_proofs()
|
await wallet.load_proofs()
|
||||||
|
|
||||||
await wallet.load_mint()
|
await wallet.load_mint()
|
||||||
# get a proof with specific amount
|
if secret_lock:
|
||||||
|
_, send_proofs = await wallet.split_to_send(
|
||||||
|
wallet.proofs,
|
||||||
|
amount,
|
||||||
|
set_reserved=False, # we set reserved later
|
||||||
|
secret_lock=secret_lock,
|
||||||
|
include_fees=include_fees,
|
||||||
|
)
|
||||||
|
else:
|
||||||
send_proofs, fees = await wallet.select_to_send(
|
send_proofs, fees = await wallet.select_to_send(
|
||||||
wallet.proofs,
|
wallet.proofs,
|
||||||
amount,
|
amount,
|
||||||
set_reserved=False,
|
set_reserved=False, # we set reserved later
|
||||||
offline=offline,
|
offline=offline,
|
||||||
include_fees=include_fees,
|
include_fees=include_fees,
|
||||||
)
|
)
|
||||||
@@ -152,7 +160,8 @@ async def send(
|
|||||||
token = await wallet.serialize_proofs(
|
token = await wallet.serialize_proofs(
|
||||||
send_proofs, include_dleq=include_dleq, legacy=legacy, memo=memo
|
send_proofs, include_dleq=include_dleq, legacy=legacy, memo=memo
|
||||||
)
|
)
|
||||||
print(token)
|
|
||||||
await wallet.set_reserved(send_proofs, reserved=True)
|
|
||||||
|
|
||||||
|
print(token)
|
||||||
|
|
||||||
|
await wallet.set_reserved(send_proofs, reserved=True)
|
||||||
return wallet.available_balance, token
|
return wallet.available_balance, token
|
||||||
|
|||||||
@@ -483,3 +483,37 @@ def test_selfpay(cli_prefix):
|
|||||||
assert result.exception is None
|
assert result.exception is None
|
||||||
print(result.output)
|
print(result.output)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_with_lock(mint, cli_prefix):
|
||||||
|
# call "cashu locks" first and get the lock
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(
|
||||||
|
cli,
|
||||||
|
[*cli_prefix, "locks"],
|
||||||
|
)
|
||||||
|
assert result.exception is None
|
||||||
|
print("test_send_with_lock", result.output)
|
||||||
|
# iterate through all words and get the word that starts with "P2PK:"
|
||||||
|
lock = None
|
||||||
|
for word in result.output.split(" "):
|
||||||
|
# strip the word
|
||||||
|
word = word.strip()
|
||||||
|
if word.startswith("P2PK:"):
|
||||||
|
lock = word
|
||||||
|
break
|
||||||
|
assert lock is not None, "no lock found"
|
||||||
|
pubkey = lock.split(":")[1]
|
||||||
|
|
||||||
|
# now lock the token
|
||||||
|
runner = CliRunner()
|
||||||
|
result = runner.invoke(
|
||||||
|
cli,
|
||||||
|
[*cli_prefix, "send", "10", "--lock", lock],
|
||||||
|
)
|
||||||
|
assert result.exception is None
|
||||||
|
print("test_send_with_lock", result.output)
|
||||||
|
token_str = result.output.split("\n")[0]
|
||||||
|
assert "cashuB" in token_str, "output does not have a token"
|
||||||
|
token = TokenV4.deserialize(token_str).to_tokenv3()
|
||||||
|
assert pubkey in token.token[0].proofs[0].secret
|
||||||
|
|||||||
Reference in New Issue
Block a user