Hey guys,
I’m trying to use an algebraic data type (in order to act like enum in solidity),
but I’m lost in the docs and can’t figure out how to make it work.
In solidity I have this:
enum SwapStatus { INVALID, ACTIVE, REFUNDED, WITHDRAWN, EXPIRED }
and I’m using it here:
struct LockContract {
SwapStatus status;
}
I constructed this:
contract Test =
datatype status('a, 'b, 'c, 'd) = Active('a) | Withdrawn('b) | Refunded('c) | Expired('d)
record lock_contract = {
id: int,
status: status(Active()) }
let new_contract : lock_contract = {
id = 6,
status = (Active) }
entrypoint get_active(x : status('a, 'b, 'c, 'd)) : option('a) =
switch(x)
Active(x) => Some(x)
Withdrawn(_) => None
Refunded(_) => None
Expired(_) => None
How am I supposed to initialize the get_active state and then check what the contracts state is
@philipp.chain , any ideas?
Thanks in advance