From 7384a407d6a1e5b5d13ae2a16dff622b47f9efee Mon Sep 17 00:00:00 2001 From: Saeed Dadkhah Date: Wed, 13 Nov 2024 13:59:27 +0330 Subject: [PATCH] Support parsing all variants of ByStr including ByStr20 with (#12) --- README.md | 8 +- src/simplified_representation/emitter.rs | 32 +- src/simplified_representation/primitives.rs | 10 + src/type.rs | 50 ++- tests/contracts/ByStr.scilla | 15 + tests/full_contract_tests.rs | 445 +++++++++++++++----- 6 files changed, 430 insertions(+), 130 deletions(-) create mode 100644 tests/contracts/ByStr.scilla diff --git a/README.md b/README.md index 1c36d09..806c66d 100644 --- a/README.md +++ b/README.md @@ -52,28 +52,28 @@ Here is the code to parse [SendZil.scilla](./tests/contracts/SendZil.scilla) con Transition::new( "fundUserWithTag", FieldList(vec![ - Field::new("user", Type::ByStr(20)), + Field::new("user", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "fundUser", FieldList(vec![ - Field::new("user", Type::ByStr(20)), + Field::new("user", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "fundContract", FieldList(vec![ - Field::new("contract_address", Type::ByStr(20)), + Field::new("contract_address", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "callOtherContract", FieldList(vec![ - Field::new("contract_address", Type::ByStr(20)), + Field::new("contract_address", Type::ByStr20), Field::new("tag", Type::String), Field::new("value", Type::Uint256) ]) diff --git a/src/simplified_representation/emitter.rs b/src/simplified_representation/emitter.rs index bf0a8c4..f74f59f 100644 --- a/src/simplified_representation/emitter.rs +++ b/src/simplified_representation/emitter.rs @@ -177,6 +177,7 @@ impl AstConverting for SrEmitter { let map = SrType { main_type: "Map".to_string(), sub_types: vec![key.into(), value.into()], + address_type: None, }; self.stack.push(StackObject::TypeDefinition(map)); } @@ -190,6 +191,7 @@ impl AstConverting for SrEmitter { let map = SrType { main_type: "Map".to_string(), sub_types: vec![key.into(), value], + address_type: None, }; self.stack.push(StackObject::TypeDefinition(map)); } @@ -282,16 +284,38 @@ impl AstConverting for SrEmitter { fn emit_address_type_field( &mut self, _mode: TreeTraversalMode, - _node: &NodeAddressTypeField, + node: &NodeAddressTypeField, ) -> Result { - Ok(TraversalResult::Continue) + if let NodeVariableIdentifier::VariableName(n) = &node.identifier.node { + node.type_name.visit(self)?; + let typename = self.pop_type_definition()?; + let s = StackObject::VariableDeclaration(Field::new(&n.node, typename.into())); + self.stack.push(s); + } + Ok(TraversalResult::SkipChildren) } fn emit_address_type( &mut self, _mode: TreeTraversalMode, - _node: &NodeAddressType, + node: &NodeAddressType, ) -> Result { - Ok(TraversalResult::Continue) + node.identifier.visit(self)?; + let identifier = self.pop_ir_identifier()?; + self.stack + .push(StackObject::TypeDefinition(identifier.into())); + let mut main_type = self.pop_type_definition()?; + let mut fields = vec![]; + for field in &node.address_fields { + field.visit(self)?; + let field = self.pop_variable_declaration()?; + fields.push(field); + } + main_type.address_type = Some(AddressType { + type_name: node.type_name.node.clone(), + fields: FieldList(fields), + }); + self.stack.push(StackObject::TypeDefinition(main_type)); + Ok(TraversalResult::SkipChildren) } fn emit_full_expression( diff --git a/src/simplified_representation/primitives.rs b/src/simplified_representation/primitives.rs index 67b16e2..0aa1620 100644 --- a/src/simplified_representation/primitives.rs +++ b/src/simplified_representation/primitives.rs @@ -1,3 +1,5 @@ +use crate::FieldList; + /// Enum representing the different kinds of identifiers in the simplified representation. #[derive(Debug, Clone, PartialEq)] pub enum SrIdentifierKind { @@ -36,10 +38,17 @@ pub struct SrIdentifier { pub is_definition: bool, } +#[derive(Debug, Clone)] +pub struct AddressType { + pub type_name: String, + pub fields: FieldList, +} + #[derive(Debug, Clone)] pub struct SrType { pub main_type: String, pub sub_types: Vec, + pub address_type: Option, // For types like `ByStr20 with contract field f1 : t1, field f2 : t2, ... end` } impl SrType { @@ -53,6 +62,7 @@ impl From for SrType { Self { main_type: value.unresolved, sub_types: vec![], + address_type: None, } } } diff --git a/src/type.rs b/src/type.rs index 83fe7f3..f4a556a 100644 --- a/src/type.rs +++ b/src/type.rs @@ -1,6 +1,6 @@ use std::fmt::Display; -use crate::simplified_representation::primitives::SrType; +use crate::{simplified_representation::primitives::SrType, FieldList}; /// Represents all different scilla types. #[derive(Debug, PartialEq, Clone)] @@ -20,7 +20,14 @@ pub enum Type { BNum, Map(Box, Box), - ByStr(usize), + ByStr, + ByStrX(usize), + ByStr20, + /// See https://scilla.readthedocs.io/en/latest/scilla-in-depth.html#addresses-1 + ByStr20With { + type_name: String, // contract, library, ... + fields: FieldList, + }, // ADT Bool, @@ -49,7 +56,17 @@ impl Display for Type { Type::Option(ref k) => write!(f, "(Option {})", k), Type::List(ref k) => write!(f, "(List {})", k), Type::Pair(ref k, ref v) => write!(f, "(Pair {} {})", k, v), - Type::ByStr(n) => write!(f, "ByStr{}", n), + Type::ByStr => write!(f, "ByStr"), + Type::ByStrX(n) => write!(f, "ByStr{}", n), + Type::ByStr20 => write!(f, "ByStr20"), + Type::ByStr20With { type_name, fields } => { + let fields = fields + .iter() + .map(|field| format!("field {}: {}", field.name, field.r#type)) + .collect::>() + .join(", "); + write!(f, "ByStr20 with {type_name}{fields} end") + } Type::Other(ref s) => write!(f, "{}", s), } } @@ -67,7 +84,8 @@ impl From for Type { "Uint128" => Type::Uint128, "Uint256" => Type::Uint256, "String" => Type::String, - "ByStr20" => Type::ByStr(20), + "ByStr" => Type::ByStr, + "ByStrX" => todo!(), "BNum" => Type::BNum, "Bool" => Type::Bool, // TODO: Remove unwrap @@ -83,6 +101,22 @@ impl From for Type { let key = type_definition.sub_types.pop().unwrap(); Type::Map(Box::new(key.into()), Box::new(value.into())) } + "ByStr20" => type_definition + .address_type + .map_or(Type::ByStr20, |address_type| Type::ByStr20With { + type_name: address_type.type_name, + fields: address_type.fields, + }), + t if t.starts_with("ByStr") => { + if let Some(number) = t + .strip_prefix("ByStr") + .and_then(|s| s.parse::().ok()) + { + Type::ByStrX(number) + } else { + Type::Other(type_definition.main_type) + } + } _ => Type::Other(type_definition.main_type), } } @@ -96,9 +130,9 @@ mod tests { fn test_type_to_string() { //(List (Pair ByStr20 (List (Pair ByStr20 Uint32)))) let list_type = Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStrX(20)), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStrX(20)), Box::new(Type::Uint32), )))), ))); @@ -110,9 +144,9 @@ mod tests { // (List (Pair ByStr20 (List (Pair ByStr20 (List (Pair Uint32 Uint128)))))) let list_type = Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStrX(20)), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStrX(20)), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::Uint32), Box::new(Type::Uint128), diff --git a/tests/contracts/ByStr.scilla b/tests/contracts/ByStr.scilla new file mode 100644 index 0000000..31090e3 --- /dev/null +++ b/tests/contracts/ByStr.scilla @@ -0,0 +1,15 @@ +scilla_version 0 + +contract AllByStrVariants + ( + bystr32 : ByStr32, + raw_address: ByStr20, + library_address : ByStr20 with library end, + contract_address : ByStr20 with contract end, + detailed_contract_address : + ByStr20 with contract + field allowances : Map ByStr20 (Map ByStr20 Uint128), + field balances : Map ByStr20 Uint128, + field total_supply : Uint128 + end + ) \ No newline at end of file diff --git a/tests/full_contract_tests.rs b/tests/full_contract_tests.rs index ab40367..350294b 100644 --- a/tests/full_contract_tests.rs +++ b/tests/full_contract_tests.rs @@ -16,6 +16,62 @@ fn test_parse() -> Result<(), Box> { Ok(()) } +#[test] +fn test_bystr_contract_parse() { + let contract_path = PathBuf::from("tests/contracts/ByStr.scilla"); + let contract = Contract::parse(&contract_path).unwrap(); + + assert_eq!( + contract, + Contract { + name: "AllByStrVariants".to_string(), + init_params: FieldList(vec![ + Field::new("bystr32", Type::ByStrX(32)), + Field::new("raw_address", Type::ByStr20), + Field::new( + "library_address", + Type::ByStr20With { + type_name: "library".to_string(), + fields: FieldList::default() + } + ), + Field::new( + "contract_address", + Type::ByStr20With { + type_name: "contract".to_string(), + fields: FieldList::default() + } + ), + Field::new( + "detailed_contract_address", + Type::ByStr20With { + type_name: "contract".to_string(), + fields: FieldList(vec![ + Field::new( + "allowances", + Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::Uint128) + )) + ) + ), + Field::new( + "balances", + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128)) + ), + Field::new("total_supply", Type::Uint128) + ]) + } + ) + ]), + fields: FieldList::default(), + transitions: TransitionList::default(), + } + ); +} + #[test] fn test_timestamp_contract_parse() { let contract_path = PathBuf::from("tests/contracts/Timestamp.scilla"); @@ -38,7 +94,174 @@ fn test_timestamp_contract_parse() { #[test] fn test_staking_contract_parse() { let contract_path = PathBuf::from("tests/contracts/StakingContract.scilla"); - Contract::parse(&contract_path).unwrap(); + let contract = Contract::parse(&contract_path).unwrap(); + + assert_eq!( + contract, + Contract { + name: "StakingContract".to_string(), + init_params: FieldList(vec![ + Field::new("initial_owner", Type::ByStr20), + Field::new( + "initial_staking_token_address", + Type::ByStr20With { + type_name: "contract".to_string(), + fields: FieldList(vec![ + Field::new( + "allowances", + Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::Uint128) + )) + ) + ), + Field::new( + "balances", + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128)) + ), + Field::new("total_supply", Type::Uint128) + ]) + } + ) + ]), + fields: FieldList(vec![ + Field::new("owner", Type::ByStr20), + Field::new("staking_token_address", Type::ByStr20), + Field::new("pending_owner", Type::ByStr20), + Field::new("paused", Type::Bool), + Field::new( + "reward_pairs", + Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::List(Box::new(Type::Other("RewardParam".to_string())))) + ) + ), + Field::new( + "stakes", + Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::Other("Stake".to_string())) + ) + ), + Field::new( + "rewards", + Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128))) + ) + ), + Field::new( + "administrators", + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Bool)) + ), + Field::new( + "treasury_balances", + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128)) + ), + Field::new("treasury_fees_address", Type::ByStr20), + Field::new("penalty_fee_balances", Type::Uint128), + Field::new("total_staked_amount", Type::Uint128), + ]), + transitions: TransitionList(vec![ + Transition::new( + "AddStake", + FieldList(vec![ + Field::new("amount", Type::Uint128), + Field::new("expiration_time", Type::Uint64), + Field::new("penalty_fee_bps", Type::Uint128) + ]) + ), + Transition::new( + "RemoveStake", + FieldList(vec![Field::new("amount", Type::Uint128,),],) + ), + Transition::new("ClaimRewards", FieldList::default()), + Transition::new( + "AddRewardToken", + FieldList(vec![ + Field::new("reward_token_address", Type::ByStr20), + Field::new("apr", Type::Uint128,), + Field::new("treasury_fee", Type::Uint128) + ]), + ), + Transition::new( + "RemoveRewardToken", + FieldList(vec![Field::new("reward_token_address", Type::ByStr20)]), + ), + Transition::new("RemoveAllRewardTokens", FieldList::default()), + Transition::new("Pause", FieldList::default()), + Transition::new("UnPause", FieldList::default()), + Transition::new( + "AddAdmin", + FieldList(vec![Field::new("address", Type::ByStr20)]) + ), + Transition::new( + "RemoveAdmin", + FieldList(vec![Field::new("address", Type::ByStr20)]) + ), + Transition::new( + "TransferOwnership", + FieldList(vec![Field::new("new_owner", Type::ByStr20)]) + ), + Transition::new("AcceptPendingOwnership", FieldList::default()), + Transition::new( + "WithdrawTokens", + FieldList(vec![ + Field::new("token_address", Type::ByStr20), + Field::new("token_amount", Type::Uint128) + ]) + ), + Transition::new( + "WithdrawZils", + FieldList(vec![Field::new("zil_amount", Type::Uint128),]) + ), + Transition::new( + "Deposit", + FieldList(vec![ + Field::new("token_address", Type::ByStr20), + Field::new("token_amount", Type::Uint128) + ]) + ), + Transition::new( + "TransferFromSuccessCallBack", + FieldList(vec![ + Field::new("initiator", Type::ByStr20), + Field::new("sender", Type::ByStr20), + Field::new("recipient", Type::ByStr20), + Field::new("amount", Type::Uint128) + ]) + ), + Transition::new( + "TransferSuccessCallBack", + FieldList(vec![ + Field::new("sender", Type::ByStr20), + Field::new("recipient", Type::ByStr20), + Field::new("amount", Type::Uint128) + ]) + ), + Transition::new( + "RecipientAcceptTransferFrom", + FieldList(vec![ + Field::new("initiator", Type::ByStr20), + Field::new("sender", Type::ByStr20), + Field::new("recipient", Type::ByStr20), + Field::new("amount", Type::Uint128) + ]) + ), + Transition::new("AddFunds", FieldList::default()), + Transition::new( + "RecipientAcceptTransfer", + FieldList(vec![ + Field::new("sender", Type::ByStr20), + Field::new("recipient", Type::ByStr20), + Field::new("amount", Type::Uint128) + ]) + ), + ]) + } + ); } #[test] @@ -69,7 +292,7 @@ fn test_hello_world_contract_parse() { contract, Contract { name: "HelloWorld".to_string(), - init_params: FieldList(vec![Field::new("owner", Type::ByStr(20))]), + init_params: FieldList(vec![Field::new("owner", Type::ByStr20)]), fields: FieldList(vec![Field::new("welcome_msg", Type::String)]), transitions: TransitionList(vec![ Transition::new("setHello", FieldList(vec![Field::new("msg", Type::String)])), @@ -99,16 +322,16 @@ fn test_get_fields_contract_parse() { Field::new("field_int128", Type::Int128), Field::new("field_bnum", Type::BNum), Field::new("field_string", Type::String), - Field::new("field_address", Type::ByStr(20)), + Field::new("field_address", Type::ByStr20), Field::new("field_bool_false", Type::Bool), Field::new("field_bool_true", Type::Bool), Field::new( "field_option_bystr20_none", - Type::Option(Box::new(Type::ByStr(20))) + Type::Option(Box::new(Type::ByStr20)) ), Field::new( "field_option_bystr20_some", - Type::Option(Box::new(Type::ByStr(20))) + Type::Option(Box::new(Type::ByStr20)) ), Field::new( "field_option_int32_some", @@ -121,7 +344,7 @@ fn test_get_fields_contract_parse() { ), Field::new( "balances", - Type::Map(Box::new(Type::ByStr(20)), Box::new(Type::Uint128)) + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128)) ), Field::new("field_list", Type::List(Box::new(Type::Int32))) ]), @@ -169,7 +392,7 @@ fn test_call_transition_contract_parse() { ), Transition::new( "call_address", - FieldList(vec![Field::new("v", Type::ByStr(20))]) + FieldList(vec![Field::new("v", Type::ByStr20)]) ), Transition::new( "call_option_bool", @@ -186,16 +409,16 @@ fn test_call_transition_contract_parse() { ), Transition::new( "call_list", - FieldList(vec![Field::new("v", Type::List(Box::new(Type::ByStr(20))))]) + FieldList(vec![Field::new("v", Type::List(Box::new(Type::ByStr20)))]) ), Transition::new( "call_list_2", FieldList(vec![Field::new( "v", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Uint32) )))) ))) @@ -216,9 +439,9 @@ fn test_call_transition_contract_parse() { FieldList(vec![Field::new( "v", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::Uint32), Box::new(Type::Uint128) @@ -232,7 +455,7 @@ fn test_call_transition_contract_parse() { FieldList(vec![Field::new( "v", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::BNum), Box::new(Type::Uint128) @@ -276,28 +499,28 @@ fn test_send_zil_contract_parse() { Transition::new( "fundUserWithTag", FieldList(vec![ - Field::new("user", Type::ByStr(20)), + Field::new("user", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "fundUser", FieldList(vec![ - Field::new("user", Type::ByStr(20)), + Field::new("user", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "fundContract", FieldList(vec![ - Field::new("contract_address", Type::ByStr(20)), + Field::new("contract_address", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "callOtherContract", FieldList(vec![ - Field::new("contract_address", Type::ByStr(20)), + Field::new("contract_address", Type::ByStr20), Field::new("tag", Type::String), Field::new("value", Type::Uint256) ]) @@ -316,7 +539,7 @@ fn test_fungible_token_parse() { Contract { name: "FungibleToken".to_string(), init_params: FieldList(vec![ - Field::new("contract_owner", Type::ByStr(20)), + Field::new("contract_owner", Type::ByStr20), Field::new("name", Type::String), Field::new("symbol", Type::String), Field::new("decimals", Type::Uint32), @@ -326,16 +549,13 @@ fn test_fungible_token_parse() { Field::new("total_supply", Type::Uint128), Field::new( "balances", - Type::Map(Box::new(Type::ByStr(20)), Box::new(Type::Uint128)) + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128)) ), Field::new( "allowances", Type::Map( - Box::new(Type::ByStr(20)), - Box::new(Type::Map( - Box::new(Type::ByStr(20)), - Box::new(Type::Uint128) - )) + Box::new(Type::ByStr20), + Box::new(Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128))) ) ) ]), @@ -343,36 +563,36 @@ fn test_fungible_token_parse() { Transition::new( "IncreaseAllowance", FieldList(vec![ - Field::new("spender", Type::ByStr(20)), + Field::new("spender", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "DecreaseAllowance", FieldList(vec![ - Field::new("spender", Type::ByStr(20)), + Field::new("spender", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "Transfer", FieldList(vec![ - Field::new("to", Type::ByStr(20)), + Field::new("to", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "TransferFailed", FieldList(vec![ - Field::new("to", Type::ByStr(20)), + Field::new("to", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), Transition::new( "TransferFrom", FieldList(vec![ - Field::new("from", Type::ByStr(20)), - Field::new("to", Type::ByStr(20)), + Field::new("from", Type::ByStr20), + Field::new("to", Type::ByStr20), Field::new("amount", Type::Uint128) ]) ), @@ -390,35 +610,35 @@ fn test_staking_proxy_v2_parse() { Contract { name: "SSNListProxy_V2".to_string(), init_params: FieldList(vec![ - Field::new("init_implementation", Type::ByStr(20)), - Field::new("init_admin", Type::ByStr(20)), + Field::new("init_implementation", Type::ByStr20), + Field::new("init_admin", Type::ByStr20), ]), fields: FieldList(vec![ - Field::new("implementation", Type::ByStr(20)), - Field::new("admin", Type::ByStr(20)), - Field::new("stagingadmin", Type::Option(Box::new(Type::ByStr(20)))), + Field::new("implementation", Type::ByStr20), + Field::new("admin", Type::ByStr20), + Field::new("stagingadmin", Type::Option(Box::new(Type::ByStr20))), ]), transitions: TransitionList(vec![ Transition::new( "UpgradeTo", - FieldList(vec![Field::new("newImplementation", Type::ByStr(20))]) + FieldList(vec![Field::new("newImplementation", Type::ByStr20)]) ), Transition::new( "ChangeProxyAdmin", - FieldList(vec![Field::new("newAdmin", Type::ByStr(20))]) + FieldList(vec![Field::new("newAdmin", Type::ByStr20)]) ), Transition::new_without_param("ClaimProxyAdmin"), Transition::new( "OptInSSNToConsensusPoolAdminOverride", - FieldList(vec![Field::new("ssnaddr", Type::ByStr(20))]) + FieldList(vec![Field::new("ssnaddr", Type::ByStr20)]) ), Transition::new( "OptOutSSNFromConsensusPoolAdminOverride", - FieldList(vec![Field::new("ssnaddr", Type::ByStr(20))]) + FieldList(vec![Field::new("ssnaddr", Type::ByStr20)]) ), Transition::new( "RemoveFromConsensusPoolAdminOverride", - FieldList(vec![Field::new("ssnaddr", Type::ByStr(20))]) + FieldList(vec![Field::new("ssnaddr", Type::ByStr20)]) ), Transition::new( "ChangeMinCommissionRate", @@ -427,7 +647,7 @@ fn test_staking_proxy_v2_parse() { Transition::new( "AddSSNNonStaking", FieldList(vec![ - Field::new("ssnaddr", Type::ByStr(20)), + Field::new("ssnaddr", Type::ByStr20), Field::new("name", Type::String), Field::new("urlraw", Type::String), Field::new("urlapi", Type::String), @@ -439,18 +659,18 @@ fn test_staking_proxy_v2_parse() { Transition::new( "WithdrawStakeRewardsForCycles", FieldList(vec![ - Field::new("ssnaddr", Type::ByStr(20)), + Field::new("ssnaddr", Type::ByStr20), Field::new("cycles", Type::Uint32) ]) ), Transition::new( "CopySSNDelegAmt", FieldList(vec![ - Field::new("ssn", Type::ByStr(20)), + Field::new("ssn", Type::ByStr20), Field::new( "keys", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Uint128) ))) ) @@ -459,7 +679,7 @@ fn test_staking_proxy_v2_parse() { Transition::new( "MigrateStakeSSNPerCycle", FieldList(vec![ - Field::new("ssn", Type::ByStr(20)), + Field::new("ssn", Type::ByStr20), Field::new( "keys", Type::List(Box::new(Type::Pair( @@ -475,11 +695,11 @@ fn test_staking_proxy_v2_parse() { Transition::new( "CopyBuffDepositDeleg", FieldList(vec![ - Field::new("deleg", Type::ByStr(20)), + Field::new("deleg", Type::ByStr20), Field::new( "keys", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::Uint32), Box::new(Type::Uint128) @@ -493,9 +713,9 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "last_buf_deposit_cycle_deleg_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Uint32), )))) ))) @@ -506,9 +726,9 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "last_withdraw_cycle_deleg_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Uint32), )))) ))) @@ -519,9 +739,9 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "deleg_stake_per_cycle_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::Uint32), Box::new(Type::Uint128) @@ -535,9 +755,9 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "direct_deposit_deleg_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::Uint32), Box::new(Type::Uint128) @@ -551,9 +771,9 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "buff_deposit_deleg_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::Uint32), Box::new(Type::Uint128) @@ -567,9 +787,9 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "deposit_amt_deleg_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Uint128) )))) ))) @@ -580,7 +800,7 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "withdrawal_pending_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::BNum), Box::new(Type::Uint128) @@ -593,7 +813,7 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "comm_for_ssn_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::List(Box::new(Type::Pair( Box::new(Type::Uint32), Box::new(Type::Uint128) @@ -606,8 +826,8 @@ fn test_staking_proxy_v2_parse() { FieldList(vec![Field::new( "deleg_swap_request_list", Type::List(Box::new(Type::Pair( - Box::new(Type::ByStr(20)), - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), + Box::new(Type::ByStr20), ))) )]) ), @@ -628,25 +848,25 @@ fn test_staking_proxy_v2_parse() { ), Transition::new( "ChangeCurrentDeleg", - FieldList(vec![Field::new("input_current_deleg", Type::ByStr(20))]) + FieldList(vec![Field::new("input_current_deleg", Type::ByStr20)]) ), Transition::new( "ChangeCurrentSSN", - FieldList(vec![Field::new("input_current_ssn", Type::ByStr(20))]) + FieldList(vec![Field::new("input_current_ssn", Type::ByStr20)]) ), Transition::new( "ChangeNewDeleg", - FieldList(vec![Field::new("input_new_deleg", Type::ByStr(20))]) + FieldList(vec![Field::new("input_new_deleg", Type::ByStr20)]) ), Transition::new( "ChangeVerifier", - FieldList(vec![Field::new("input_verifier", Type::ByStr(20))]) + FieldList(vec![Field::new("input_verifier", Type::ByStr20)]) ), Transition::new( "ChangeVerifierReceivingAddr", FieldList(vec![Field::new( "input_verifier_receiving_addr", - Type::ByStr(20) + Type::ByStr20 )]) ), Transition::new( @@ -688,26 +908,26 @@ fn test_stzil_contract_parse() { Contract { name: "StZIL".to_string(), init_params: FieldList(vec![ - Field::new("contract_owner", Type::ByStr(20)), - Field::new("init_admin_address", Type::ByStr(20)), - Field::new("init_zimpl_address", Type::ByStr(20)), + Field::new("contract_owner", Type::ByStr20), + Field::new("init_admin_address", Type::ByStr20), + Field::new("init_zimpl_address", Type::ByStr20), Field::new("name", Type::String), Field::new("symbol", Type::String), Field::new("decimals", Type::Uint32), Field::new("init_supply", Type::Uint128) ]), fields: FieldList(vec![ - Field::new("owner_address", Type::ByStr(20)), - Field::new("admin_address", Type::ByStr(20)), - Field::new("treasury_address", Type::ByStr(20)), - Field::new("withdrawal_fee_address", Type::ByStr(20)), - Field::new("zimpl_address", Type::ByStr(20)), - Field::new("holder_address", Type::ByStr(20)), - Field::new("buffers_addresses", Type::List(Box::new(Type::ByStr(20)))), - Field::new("ssn_addresses", Type::List(Box::new(Type::ByStr(20)))), + Field::new("owner_address", Type::ByStr20), + Field::new("admin_address", Type::ByStr20), + Field::new("treasury_address", Type::ByStr20), + Field::new("withdrawal_fee_address", Type::ByStr20), + Field::new("zimpl_address", Type::ByStr20), + Field::new("holder_address", Type::ByStr20), + Field::new("buffers_addresses", Type::List(Box::new(Type::ByStr20))), + Field::new("ssn_addresses", Type::List(Box::new(Type::ByStr20))), Field::new( "staging_owner_address", - Type::Option(Box::new(Type::ByStr(20))) + Type::Option(Box::new(Type::ByStr20)) ), Field::new("is_paused_in", Type::Bool), Field::new("is_paused_out", Type::Bool), @@ -720,16 +940,13 @@ fn test_stzil_contract_parse() { Field::new("total_supply", Type::Uint128), Field::new( "balances", - Type::Map(Box::new(Type::ByStr(20)), Box::new(Type::Uint128)) + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128)) ), Field::new( "allowances", Type::Map( - Box::new(Type::ByStr(20)), - Box::new(Type::Map( - Box::new(Type::ByStr(20)), - Box::new(Type::Uint128) - )) + Box::new(Type::ByStr20), + Box::new(Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128))) ) ), Field::new( @@ -737,7 +954,7 @@ fn test_stzil_contract_parse() { Type::Map( Box::new(Type::BNum), Box::new(Type::Map( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Other("Withdrawal".to_string())) )) ) @@ -745,7 +962,7 @@ fn test_stzil_contract_parse() { Field::new( "withdrawal_pending_of_delegator", Type::Map( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Map( Box::new(Type::BNum), Box::new(Type::Other("Withdrawal".to_string())) @@ -755,20 +972,20 @@ fn test_stzil_contract_parse() { Field::new( "withdrawal_unbonded", Type::Map( - Box::new(Type::ByStr(20)), + Box::new(Type::ByStr20), Box::new(Type::Other("Withdrawal".to_string())) ) ), Field::new( "buffer_drained_cycle", - Type::Map(Box::new(Type::ByStr(20)), Box::new(Type::Uint32)) + Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint32)) ), Field::new("ssn_index", Type::Uint128), - Field::new("tmp_delegator", Type::Option(Box::new(Type::ByStr(20)))), + Field::new("tmp_delegator", Type::Option(Box::new(Type::ByStr20))), Field::new("tmp_stake_delegate_amount", Type::Uint128), Field::new("tmp_complete_withdrawal_available", Type::Uint128), - Field::new("tmp_ssn_addr_in", Type::ByStr(20)), - Field::new("tmp_ssn_addr_out", Type::ByStr(20)), + Field::new("tmp_ssn_addr_in", Type::ByStr20), + Field::new("tmp_ssn_addr_out", Type::ByStr20), Field::new("tmp_bnum", Type::BNum), Field::new("tmp_deleg_exists", Type::Bool), Field::new("local_bnum_req", Type::Uint128), @@ -783,54 +1000,54 @@ fn test_stzil_contract_parse() { Transition::new_without_param("UnPauseZrc2"), Transition::new( "ChangeAdmin", - FieldList(vec![Field::new("new_admin", Type::ByStr(20))]) + FieldList(vec![Field::new("new_admin", Type::ByStr20)]) ), Transition::new( "ChangeOwner", - FieldList(vec![Field::new("new_owner", Type::ByStr(20))]) + FieldList(vec![Field::new("new_owner", Type::ByStr20)]) ), Transition::new_without_param("ClaimOwner"), Transition::new( "ChangeTreasuryAddress", - FieldList(vec![Field::new("address", Type::ByStr(20))]) + FieldList(vec![Field::new("address", Type::ByStr20)]) ), Transition::new( "ChangeWithdrawalFeeAddress", - FieldList(vec![Field::new("address", Type::ByStr(20))]) + FieldList(vec![Field::new("address", Type::ByStr20)]) ), Transition::new( "SetHolderAddress", - FieldList(vec![Field::new("address", Type::ByStr(20))]), + FieldList(vec![Field::new("address", Type::ByStr20)]), ), Transition::new( "ChangeZimplAddress", - FieldList(vec![Field::new("address", Type::ByStr(20))]), + FieldList(vec![Field::new("address", Type::ByStr20)]), ), Transition::new( "ChangeBuffers", FieldList(vec![Field::new( "new_buffers", - Type::List(Box::new(Type::ByStr(20))) + Type::List(Box::new(Type::ByStr20)) )]) ), Transition::new( "AddSSN", - FieldList(vec![Field::new("ssnaddr", Type::ByStr(20))]) + FieldList(vec![Field::new("ssnaddr", Type::ByStr20)]) ), Transition::new( "RemoveSSN", - FieldList(vec![Field::new("ssnaddr", Type::ByStr(20))]) + FieldList(vec![Field::new("ssnaddr", Type::ByStr20)]) ), Transition::new( "ClaimRewards", FieldList(vec![ - Field::new("buffer_or_holder", Type::ByStr(20)), - Field::new("ssn", Type::ByStr(20)) + Field::new("buffer_or_holder", Type::ByStr20), + Field::new("ssn", Type::ByStr20) ]) ), Transition::new( "ConsolidateInHolder", - FieldList(vec![Field::new("buffer_addr", Type::ByStr(20))]) + FieldList(vec![Field::new("buffer_addr", Type::ByStr20)]) ), Transition::new_without_param("ClaimRewardsSuccessCallBack"), Transition::new_without_param("PerformAutoRestake"), @@ -846,7 +1063,7 @@ fn test_stzil_contract_parse() { Transition::new_without_param("DelegateStake"), Transition::new( "DelegateStakeWithReferral", - FieldList(vec![Field::new("referral", Type::ByStr(20)),],) + FieldList(vec![Field::new("referral", Type::ByStr20),],) ), Transition::new( "DelegateStakeSuccessCallBack", @@ -867,48 +1084,48 @@ fn test_stzil_contract_parse() { "SlashSSN", FieldList(vec![ Field::new("withdraw_stake_amt", Type::Uint128), - Field::new("ssnaddr", Type::ByStr(20)) + Field::new("ssnaddr", Type::ByStr20) ],) ), Transition::new_without_param("CompleteWithdrawal"), Transition::new_without_param("CompleteWithdrawalSuccessCallBack"), Transition::new( "ChownStakeConfirmSwap", - FieldList(vec![Field::new("delegator", Type::ByStr(20)),],) + FieldList(vec![Field::new("delegator", Type::ByStr20),],) ), Transition::new( "ChownStakeReDelegate", FieldList(vec![ - Field::new("from_ssn", Type::ByStr(20)), + Field::new("from_ssn", Type::ByStr20), Field::new("amount", Type::Uint128), ],) ), Transition::new( "IncreaseAllowance", FieldList(vec![ - Field::new("spender", Type::ByStr(20)), + Field::new("spender", Type::ByStr20), Field::new("amount", Type::Uint128), ],) ), Transition::new( "DecreaseAllowance", FieldList(vec![ - Field::new("spender", Type::ByStr(20)), + Field::new("spender", Type::ByStr20), Field::new("amount", Type::Uint128), ],) ), Transition::new( "Transfer", FieldList(vec![ - Field::new("to", Type::ByStr(20)), + Field::new("to", Type::ByStr20), Field::new("amount", Type::Uint128,), ],) ), Transition::new( "TransferFrom", FieldList(vec![ - Field::new("from", Type::ByStr(20)), - Field::new("to", Type::ByStr(20)), + Field::new("from", Type::ByStr20), + Field::new("to", Type::ByStr20), Field::new("amount", Type::Uint128) ],) ),