Replace SignedState.participants() with SignedState.hasParticipant()

This commit is contained in:
Mark Spanbroek 2021-03-17 13:21:02 +01:00
parent e798964ba5
commit 92bad679b5
2 changed files with 7 additions and 7 deletions

View File

@ -8,12 +8,12 @@ type
state*: State
signatures*: seq[(EthAddress, Signature)]
func participants*(signed: SignedState): seq[EthAddress] =
signed.state.channel.participants
func hasParticipant*(signed: SignedState, participant: EthAddress): bool =
signed.state.channel.participants.contains(participant)
func verifySignatures*(signed: SignedState): bool =
for (participant, signature) in signed.signatures:
if not signed.participants.contains(participant):
if not signed.hasParticipant(participant):
return false
if not signature.verify(signed.state, participant):
return false

View File

@ -46,11 +46,11 @@ func openLedgerChannel*(wallet: var Wallet,
let state = startLedger(wallet.address, hub, chainId, nonce, asset, amount)
wallet.createChannel(state)
func acceptChannel*(wallet: var Wallet, state: SignedState): ?!ChannelId =
if not state.participants.contains(wallet.address):
func acceptChannel*(wallet: var Wallet, signed: SignedState): ?!ChannelId =
if not signed.hasParticipant(wallet.address):
return ChannelId.failure "wallet owner is not a participant"
if not verifySignatures(state):
if not verifySignatures(signed):
return ChannelId.failure "incorrect signatures"
wallet.createChannel(state).success
wallet.createChannel(signed).success