Skip to content

feat!: contract interfaces and better function calls#5687

Merged
Thunkar merged 216 commits into
masterfrom
gj/better_fn_calls
Apr 17, 2024
Merged

feat!: contract interfaces and better function calls#5687
Thunkar merged 216 commits into
masterfrom
gj/better_fn_calls

Conversation

@Thunkar

@Thunkar Thunkar commented Apr 11, 2024

Copy link
Copy Markdown
Collaborator

Closes #5081

This PR introduces autogenerated contract interfaces for easy intra and inter contract interactions. The aztec-macro crate is used to stub every non-internal private and public function and inject them into a ghost struct which has the same name as the contract that generated them. After that, they can be called like this:

contract ImportTest {

  use dep::my_imported_contract::MyImportedContract;

  #[aztec(private)]
  fn a_private_fn() {
    let deserialized_return = MyImportedContract::at(some_address).another_private_fn(arg1, arg2).call(&mut context);
    MyImportedContract::at(some_address).a_public_fn(arg1).enqueue(&mut context);
  }

  #[aztec(public)]
  fn a_public_fn() {
    let deserialized_return = MyImportedContract::at(some_address).a_public_fn(arg1).call(&mut context);
  }

  #[aztec(private)]
  fn calling_my_own_fns() {
    ImportTest::at(context.this_address).a_private_fn().call(&mut context);
    ImportTest::at(context.this_address).a_public_fn().enqueue(&mut context);
  }
  
}

Return values are deserialized_into() automatically, providing "real" return values thanks to #5633

Also, some general cleanup was required to allow importing contracts in another contracts. Main changes:

  • HirContext.fully_qualified_struct_path now uses BFS to avoid returning the longest path when looking for a struct in a crate. This is required to avoid pulling structs usually imported in top-level dependencies (usually notes from our main contract) from other imported contracts.
  • pack_args_oracle now has a slice mode in addition to its usual array mode.

PENDING:

AvmContext. The AVM team is discussing supporting args as slices. In case it's decided not to do that, a workaround could possibly be implemented using the macro, but it would be fairly complex.

Thanks to @fcarreiro and the amazing AVM team, this is now supported for the AvmContext!

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(AztecMacro): Calling Functions

7 participants