Skip to content

Commit

Permalink
Merge pull request #90 from gfusee/fix/tuple_in_structs
Browse files Browse the repository at this point in the history
Fixed a compilation issue when a struct in the abi has a tuple field
  • Loading branch information
gfusee authored Jul 17, 2024
2 parents 8eb6db8 + 35f69ad commit 5100a96
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 22 deletions.
36 changes: 30 additions & 6 deletions .novax/abis/tester-contract.abi.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"buildInfo": {
"rustc": {
"version": "1.78.0",
"commitHash": "9b00956e56009bab2aa15d7bff10916599e3d6d6",
"commitDate": "2024-04-29",
"version": "1.79.0",
"commitHash": "129f3b9964af4d4a709d1383930ade12dfe7c081",
"commitDate": "2024-06-10",
"channel": "Stable",
"short": "rustc 1.78.0 (9b00956e5 2024-04-29)"
"short": "rustc 1.79.0 (129f3b996 2024-06-10)"
},
"contractCrate": {
"name": "tester-contract",
"version": "0.0.0",
"gitVersion": "0.1.6-17-gaeef5de"
"version": "0.1.7-beta.1",
"gitVersion": "0.1.7-beta.1-1-g8eb6db8"
},
"framework": {
"name": "multiversx-sc",
Expand Down Expand Up @@ -593,6 +593,21 @@
}
]
},
{
"name": "returnStructWithTupleField",
"mutability": "mutable",
"inputs": [
{
"name": "arg",
"type": "CustomStructWithTupleField"
}
],
"outputs": [
{
"type": "CustomStructWithTupleField"
}
]
},
{
"name": "callAnotherContractReturnTwoU64",
"mutability": "mutable",
Expand Down Expand Up @@ -781,6 +796,15 @@
}
]
},
"CustomStructWithTupleField": {
"type": "struct",
"fields": [
{
"name": "tuple",
"type": "tuple<BigUint,bytes>"
}
]
},
"TestEnumProperties": {
"type": "enum",
"variants": [
Expand Down
4 changes: 4 additions & 0 deletions abi-build/src/generator/impl_abi_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ fn is_enum_fieldless(variants: &AbiTypeVariants) -> bool {

fn should_struct_derive_managed_vec_item(abi_fields: &AbiTypeFields, all_abi_types: &AbiTypes) -> bool {
for field in abi_fields {
if field.r#type.0.starts_with("tuple<") {
return false
}

let Some(abi_type) = all_abi_types.get(&field.r#type.0) else { continue };
let should_derive = match abi_type.r#type {
AbiPossibleType::Enum => {
Expand Down
36 changes: 30 additions & 6 deletions tester/contract/output/tester-contract.abi.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"buildInfo": {
"rustc": {
"version": "1.78.0",
"commitHash": "9b00956e56009bab2aa15d7bff10916599e3d6d6",
"commitDate": "2024-04-29",
"version": "1.79.0",
"commitHash": "129f3b9964af4d4a709d1383930ade12dfe7c081",
"commitDate": "2024-06-10",
"channel": "Stable",
"short": "rustc 1.78.0 (9b00956e5 2024-04-29)"
"short": "rustc 1.79.0 (129f3b996 2024-06-10)"
},
"contractCrate": {
"name": "tester-contract",
"version": "0.0.0",
"gitVersion": "0.1.6-17-gaeef5de"
"version": "0.1.7-beta.1",
"gitVersion": "0.1.7-beta.1-1-g8eb6db8"
},
"framework": {
"name": "multiversx-sc",
Expand Down Expand Up @@ -593,6 +593,21 @@
}
]
},
{
"name": "returnStructWithTupleField",
"mutability": "mutable",
"inputs": [
{
"name": "arg",
"type": "CustomStructWithTupleField"
}
],
"outputs": [
{
"type": "CustomStructWithTupleField"
}
]
},
{
"name": "callAnotherContractReturnTwoU64",
"mutability": "mutable",
Expand Down Expand Up @@ -781,6 +796,15 @@
}
]
},
"CustomStructWithTupleField": {
"type": "struct",
"fields": [
{
"name": "tuple",
"type": "tuple<BigUint,bytes>"
}
]
},
"TestEnumProperties": {
"type": "enum",
"variants": [
Expand Down
38 changes: 31 additions & 7 deletions tester/contract/output/tester-contract.mxsc.json

Large diffs are not rendered by default.

Binary file modified tester/contract/output/tester-contract.wasm
Binary file not shown.
13 changes: 13 additions & 0 deletions tester/contract/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub enum CustomEnumWithFields<M: ManagedTypeApi> {
Second { second_first: ManagedVec<M, u64>, second_second: ManagedVec<M, ManagedBuffer<M>>, second_third: CustomStruct<M> }
}

#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi)]
struct CustomStructWithTupleField<M: ManagedTypeApi> {
pub tuple: (BigUint<M>, ManagedBuffer<M>)
}

#[multiversx_sc::module]
pub trait PrinterModule: ContractBase {
#[endpoint(returnNftProperties)]
Expand Down Expand Up @@ -402,4 +407,12 @@ pub trait PrinterModule: ContractBase {
fn return_bigint_arg(&self, value: BigInt<Self::Api>) -> BigInt<Self::Api> {
value
}

#[endpoint(returnStructWithTupleField)]
fn return_struct_with_tuple_field(
&self,
arg: CustomStructWithTupleField<Self::Api>
) -> CustomStructWithTupleField<Self::Api> {
arg
}
}
2 changes: 1 addition & 1 deletion tester/contract/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tester/contract/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 50
// Endpoints: 51
// Async Callback: 1
// Total number of exported functions: 53
// Total number of exported functions: 54

#![no_std]

Expand Down Expand Up @@ -66,6 +66,7 @@ multiversx_sc_wasm_adapter::endpoints! {
returnOptionalValueBoolArg => return_optional_value_bool_arg
returnMultiValueTwo => return_optional_multi_value_three_arg
returnBigIntArg => return_bigint_arg
returnStructWithTupleField => return_struct_with_tuple_field
callAnotherContractReturnTwoU64 => call_another_contract_return_u64
asyncCallAnotherContractReturnTwoU64NoCallback => async_call_another_contract_return_u64_no_callback
asyncCallAnotherContractReturnTwoU64WithReturningCallback => async_call_another_contract_return_u64_with_returning_callback
Expand Down

0 comments on commit 5100a96

Please sign in to comment.