Add derive support for actions
romac opened this issue · 0 comments
romac commented
type Balance = HashMap<String, BigInt>;
type Balances = HashMap<String, Balance>;
#[derive(Copy, Clone, Debug, DecodeItfValue)]
enum Outcome {
#[itf(rename = "")]
None,
#[itf(rename = "SUCCESS")]
Success,
#[itf(rename = "DUPLICATE_DENOM")]
DuplicateDenom,
#[itf(rename = "INSUFFICIENT_FUNDS")]
InsufficientFunds,
}
#[derive(Clone, Debug, DecodeItfValue)]
#[allow(dead_code)]
struct Coin {
amount: BigInt,
denom: String,
}
#[derive(Clone, Debug, DecodeItfValue)]
#[allow(dead_code)]
#[itf(tag = "tag")]
enum Action {
#[itf(rename = "init")]
Init { balances: Balances },
#[itf(rename = "send")]
Send {
receiver: String,
sender: String,
coins: Vec<Coin>,
},
}
#[derive(Clone, Debug, TryFromRawState)]
#[allow(dead_code)]
struct State {
action: Action,
outcome: Outcome,
balances: Balances,
step: i64,
}
let data = include_str!("../tests/fixtures/TestInsufficientSuccess9.itf.json");
let raw_trace: raw::Trace = serde_json::from_str(data).unwrap();
let trace = parse_raw_trace::<State>(raw_trace).unwrap();
dbg!(trace);