Add convenience initializer to Outcome

This commit is contained in:
Mark Spanbroek 2021-03-09 16:48:47 +01:00
parent a8b2cfab5a
commit a945698ec6
3 changed files with 15 additions and 8 deletions

View File

@ -19,13 +19,23 @@ type
of guaranteeType:
guarantee*: Guarantee
Allocation* = distinct seq[AllocationItem]
AllocationItem* = object
destination*: Destination
amount*: UInt256
AllocationItem* = tuple
destination: Destination
amount: UInt256
Guarantee* = object
targetChannelId*: Destination
destinations*: seq[Destination]
proc init*(_: type Outcome,
asset: EthAddress,
allocation: openArray[AllocationItem]): Outcome =
let assetOutcome = AssetOutcome(
kind: allocationType,
assetHolder: asset,
allocation: Allocation(@allocation)
)
Outcome(@[assetOutcome])
proc encode*(encoder: var AbiEncoder, guarantee: Guarantee) =
encoder.startTuple()
encoder.startTuple()

View File

@ -38,10 +38,7 @@ proc example*(_: type ChannelDefinition): ChannelDefinition =
)
proc example*(_: type AllocationItem): AllocationItem =
AllocationItem(
destination: Destination.example,
amount: UInt256.example
)
(Destination.example, UInt256.example)
proc example*(_: type Guarantee): Guarantee =
Guarantee(

View File

@ -94,7 +94,7 @@ suite "outcome":
"1E90B49563da16D2537CA1Ddd9b1285279103D93"
).get(),
allocation: Allocation(@[
AllocationItem(
(
destination: Destination.parse(
"f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3"
).get(),