mirror of
https://github.com/logos-storage/nim-nitro.git
synced 2026-01-02 13:43:06 +00:00
Return updated signed state after payment
This commit is contained in:
parent
40cfe54144
commit
40b4782f9d
@ -108,24 +108,24 @@ func pay*(wallet: var Wallet,
|
||||
channel: ChannelId,
|
||||
asset: EthAddress,
|
||||
receiver: Destination,
|
||||
amount: UInt256): ?!void =
|
||||
amount: UInt256): ?!SignedState =
|
||||
if var state =? wallet.state(channel):
|
||||
if var balances =? state.outcome.balances(asset):
|
||||
?balances.move(wallet.destination, receiver, amount)
|
||||
try:
|
||||
state.outcome.update(asset, balances)
|
||||
wallet.updateChannel(SignedState(state: state))
|
||||
ok()
|
||||
ok(wallet.channels[channel])
|
||||
except KeyError as error:
|
||||
void.failure error
|
||||
SignedState.failure error
|
||||
else:
|
||||
void.failure "asset not found"
|
||||
SignedState.failure "asset not found"
|
||||
else:
|
||||
void.failure "channel not found"
|
||||
SignedState.failure "channel not found"
|
||||
|
||||
func pay*(wallet: var Wallet,
|
||||
channel: ChannelId,
|
||||
asset: EthAddress,
|
||||
receiver: EthAddress,
|
||||
amount: UInt256): ?!void =
|
||||
amount: UInt256): ?!SignedState =
|
||||
wallet.pay(channel, asset, receiver.toDestination, amount)
|
||||
|
||||
@ -106,6 +106,13 @@ suite "wallet: making payments":
|
||||
let expectedSignature = key.sign(wallet.state(channel).get)
|
||||
check wallet.signature(channel, wallet.address) == expectedSignature.some
|
||||
|
||||
test "pay returns the updated signed state":
|
||||
wallet = Wallet.init(key)
|
||||
channel = wallet.openLedgerChannel(hub, chainId, nonce, asset, 42.u256)
|
||||
let updated = wallet.pay(channel, asset, hub, 1.u256).option
|
||||
check updated?.state == wallet.state(channel)
|
||||
check updated?.signatures == wallet.signatures(channel)
|
||||
|
||||
test "payment fails when channel not found":
|
||||
wallet = Wallet.init(key)
|
||||
check wallet.pay(channel, asset, hub, 1.u256).isErr
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user