mirror of
https://github.com/logos-storage/nim-nitro.git
synced 2026-01-02 13:43:06 +00:00
There's a new byteutils in newer versions of stew - also, remove upraises and disable windows testing which requires SSL library install
62 lines
1.4 KiB
Nim
62 lines
1.4 KiB
Nim
import pkg/nimcrypto
|
|
import ../basics
|
|
import ./channel
|
|
import ./outcome
|
|
import ./abi
|
|
|
|
{.push raises: [].}
|
|
|
|
export basics
|
|
export channel
|
|
export outcome
|
|
|
|
type
|
|
State* = object
|
|
turnNum*: UInt48
|
|
isFinal*: bool
|
|
channel*: ChannelDefinition
|
|
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]
|
|
|
|
func fixedPart*(state: State): FixedPart =
|
|
FixedPart(
|
|
chainId: state.channel.chainId,
|
|
participants: state.channel.participants,
|
|
channelNonce: state.channel.nonce,
|
|
appDefinition: state.appDefinition,
|
|
challengeDuration: state.challengeDuration
|
|
)
|
|
|
|
func variablePart*(state: State): VariablePart =
|
|
VariablePart(
|
|
outcome: AbiEncoder.encode(state.outcome),
|
|
appData: state.appData
|
|
)
|
|
|
|
func hashAppPart*(state: State): array[32, byte] =
|
|
let encoding = AbiEncoder.encode:
|
|
(state.challengeDuration, state.appDefinition, state.appData)
|
|
keccak256.digest(encoding).data
|
|
|
|
func hashState*(state: State): array[32, byte] =
|
|
let encoding = AbiEncoder.encode:
|
|
(
|
|
state.turnNum,
|
|
state.isFinal,
|
|
getChannelId(state.channel),
|
|
hashAppPart(state),
|
|
hashOutcome(state.outcome)
|
|
)
|
|
keccak256.digest(encoding).data
|