Skip to content

Commit

Permalink
Parse address types with nested with contract phrases. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
saeed-zil authored Dec 2, 2024
1 parent 6368fe4 commit 6a3368b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/simplified_representation/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,17 @@ impl AstConverting for SrEmitter {
};
self.stack.push(StackObject::TypeDefinition(map));
}
NodeTypeMapValue::MapValueAddressType(_value) => unimplemented!(),
NodeTypeMapValue::MapValueAddressType(value) => {
value.visit(self)?;
let value = self.pop_type_definition()?;
let key = self.pop_ir_identifier()?;
let map = SrType {
main_type: "Map".to_string(),
sub_types: vec![key.into(), value],
address_type: None,
};
self.stack.push(StackObject::TypeDefinition(map));
}
};
}
TreeTraversalMode::Exit => {}
Expand Down
8 changes: 7 additions & 1 deletion tests/contracts/ByStr.scilla
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ contract AllByStrVariants
field allowances : Map ByStr20 (Map ByStr20 Uint128),
field balances : Map ByStr20 Uint128,
field total_supply : Uint128
end
end,
complex_contract_address: ByStr20 with contract
field implementation: ByStr20 with contract
field services: Map String ByStr20,
field utility: Map String Uint128 end,
field dns: Map String ByStr20,
field guardians: Map String ByStr20 with contract field verification_methods: Map String ByStr33 end end
)

transition ArbitrageFromXCAD
Expand Down
50 changes: 50 additions & 0 deletions tests/full_contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,56 @@ fn test_bystr_contract_parse() {
Field::new("total_supply", Type::Uint128)
])
}
),
Field::new(
"complex_contract_address",
Type::ByStr20With {
type_name: "contract".to_string(),
fields: FieldList(vec![
Field::new(
"implementation",
Type::ByStr20With {
type_name: "contract".to_string(),
fields: FieldList(vec![
Field::new(
"services",
Type::Map(
Box::new(Type::String),
Box::new(Type::ByStr20)
)
),
Field::new(
"utility",
Type::Map(
Box::new(Type::String),
Box::new(Type::Uint128)
)
),
])
}
),
Field::new(
"dns",
Type::Map(Box::new(Type::String), Box::new(Type::ByStr20))
),
Field::new(
"guardians",
Type::Map(
Box::new(Type::String),
Box::new(Type::ByStr20With {
type_name: "contract".to_string(),
fields: FieldList(vec![Field::new(
"verification_methods",
Type::Map(
Box::new(Type::String),
Box::new(Type::ByStrX(33))
)
),])
}),
)
)
])
}
)
]),
fields: FieldList::default(),
Expand Down

0 comments on commit 6a3368b

Please sign in to comment.