2021-02-22 15:32:48 +01:00
|
|
|
import pkg/nimcrypto
|
2021-03-09 11:07:35 +01:00
|
|
|
import ../basics
|
2021-02-22 15:32:48 +01:00
|
|
|
import ./channel
|
|
|
|
|
import ./outcome
|
|
|
|
|
import ./abi
|
|
|
|
|
|
2025-12-10 20:44:01 +01:00
|
|
|
{.push raises: [].}
|
2021-03-03 10:30:07 +01:00
|
|
|
|
2021-03-09 11:07:35 +01:00
|
|
|
export basics
|
2021-02-22 15:32:48 +01:00
|
|
|
export channel
|
|
|
|
|
export outcome
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
State* = object
|
|
|
|
|
turnNum*: UInt48
|
|
|
|
|
isFinal*: bool
|
2021-03-09 12:41:51 +01:00
|
|
|
channel*: ChannelDefinition
|
2021-02-22 15:32:48 +01:00
|
|
|
challengeDuration*: UInt48
|
|
|
|
|
outcome*: Outcome
|
|
|
|
|
appDefinition*: EthAddress
|
|
|
|
|
appData*: seq[byte]
|
|
|
|
|
FixedPart* = object
|
|
|
|
|
chainId*: UInt256
|
|
|
|
|
participants*: seq[EthAddress]
|
|
|
|
|
channelNonce*: UInt48
|
|
|
|
|
appDefinition*: EthAddress
|
|
|
|
|
challengeDuration*: UInt48
|
|
|
|
|
VariablePart* = object
|
|
|
|
|
outcome*: seq[byte]
|
|
|
|
|
appdata*: seq[byte]
|
|
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func fixedPart*(state: State): FixedPart =
|
2021-02-22 15:32:48 +01:00
|
|
|
FixedPart(
|
|
|
|
|
chainId: state.channel.chainId,
|
|
|
|
|
participants: state.channel.participants,
|
|
|
|
|
channelNonce: state.channel.nonce,
|
|
|
|
|
appDefinition: state.appDefinition,
|
|
|
|
|
challengeDuration: state.challengeDuration
|
|
|
|
|
)
|
|
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func variablePart*(state: State): VariablePart =
|
2021-02-22 15:32:48 +01:00
|
|
|
VariablePart(
|
2021-02-25 09:11:46 +01:00
|
|
|
outcome: AbiEncoder.encode(state.outcome),
|
2021-02-22 15:32:48 +01:00
|
|
|
appData: state.appData
|
|
|
|
|
)
|
|
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func hashAppPart*(state: State): array[32, byte] =
|
2021-12-06 15:39:27 +01:00
|
|
|
let encoding = AbiEncoder.encode:
|
|
|
|
|
(state.challengeDuration, state.appDefinition, state.appData)
|
|
|
|
|
keccak256.digest(encoding).data
|
2021-02-22 15:32:48 +01:00
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func hashState*(state: State): array[32, byte] =
|
2021-12-06 15:39:27 +01:00
|
|
|
let encoding = AbiEncoder.encode:
|
|
|
|
|
(
|
|
|
|
|
state.turnNum,
|
|
|
|
|
state.isFinal,
|
|
|
|
|
getChannelId(state.channel),
|
|
|
|
|
hashAppPart(state),
|
|
|
|
|
hashOutcome(state.outcome)
|
|
|
|
|
)
|
|
|
|
|
keccak256.digest(encoding).data
|