diff --git a/nitro/outcome.nim b/nitro/outcome.nim index c55227d..8be7d54 100644 --- a/nitro/outcome.nim +++ b/nitro/outcome.nim @@ -6,7 +6,7 @@ export types export abi type - Outcome* = seq[AssetOutcome] + Outcome* = distinct seq[AssetOutcome] AssetOutcomeType* = enum allocationType = 0 guaranteeType = 1 @@ -56,5 +56,10 @@ proc write*(writer: var AbiWriter, assetOutcome: AssetOutcome) = writer.write(content.finish()) writer.finishTuple() +proc write*(writer: var AbiWriter, outcome: Outcome) = + writer.startTuple() + writer.write(seq[AssetOutcome](outcome)) + writer.finishTuple() + proc hashOutcome*(outcome: Outcome): array[32, byte] = keccak256.digest(Abi.encode(outcome)).data diff --git a/tests/nitro/examples.nim b/tests/nitro/examples.nim index 3becd48..1e436e1 100644 --- a/tests/nitro/examples.nim +++ b/tests/nitro/examples.nim @@ -62,6 +62,9 @@ proc example*(_: type AssetOutcome): AssetOutcome = guarantee: Guarantee.example ) +proc example*(_: type Outcome): Outcome = + Outcome(seq[AssetOutcome].example) + proc example*(_: type State): State = State( turnNum: UInt48.example, diff --git a/tests/nitro/testOutcome.nim b/tests/nitro/testOutcome.nim index aa02931..fed7a51 100644 --- a/tests/nitro/testOutcome.nim +++ b/tests/nitro/testOutcome.nim @@ -59,6 +59,14 @@ suite "outcome": writer.finishTuple() check Abi.encode(assetOutcome) == writer.finish() + test "encodes outcomes": + let outcome = Outcome.example() + var writer: AbiWriter + writer.startTuple() + writer.write(seq[AssetOutcome](outcome)) + writer.finishTuple() + check Abi.encode(outcome) == writer.finish() + test "hashes outcomes": let outcome = Outcome.example let encoded = Abi.encode(outcome)