Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 13, 2023
1 parent ab042ef commit dc4482c
Showing 1 changed file with 68 additions and 18 deletions.
86 changes: 68 additions & 18 deletions docs/docs/dev_docs/contracts/compiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,37 +149,87 @@ You can also generate these interfaces from prebuilt artifacts using the `genera
aztec-cli generate-noir-interface ./path/to/my_aztec_contract_project
```

Example code generated from the [PrivateToken](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr) contract:
Example code snippet generated from the [Token](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr) contract:

```rust
impl PrivateTokenPrivateContextInterface {
fn at(address: Field) -> Self {
Self { address }
impl TokenPrivateContextInterface {
pub fn at(address: Field) -> Self {
Self {
address,
}
}

fn mint(
self, context: &mut PrivateContext, amount: Field, owner: Field

pub fn burn(
self,
context: &mut PrivateContext,
from: FromBurnStruct,
amount: Field,
nonce: Field
) -> [Field; RETURN_VALUES_LENGTH] {
let mut serialized_args = [0; 2];
serialized_args[0] = amount;
serialized_args[1] = owner;
let mut serialized_args = [0; 3];
serialized_args[0] = from.address;
serialized_args[1] = amount;
serialized_args[2] = nonce;

// 0x1dc9c3c0 is the function selector for `mint(field,field)`
context.call_private_function(self.address, 0x1dc9c3c0, serialized_args)
context.call_private_function(self.address, 0xd4fcc96e, serialized_args)
}


pub fn burn_public(
self,
context: &mut PrivateContext,
from: FromBurnPublicStruct,
amount: Field,
nonce: Field
) {
let mut serialized_args = [0; 3];
serialized_args[0] = from.address;
serialized_args[1] = amount;
serialized_args[2] = nonce;

context.call_public_function(self.address, 0xb0e964d5, serialized_args)
}
...

}

fn transfer(
self, context: &mut PrivateContext, amount: Field, sender: Field, recipient: Field
impl TokenPublicContextInterface {
pub fn at(address: Field) -> Self {
Self {
address,
}
}

pub fn burn_public(
self,
context: PublicContext,
from: FromBurnPublicStruct,
amount: Field,
nonce: Field
) -> [Field; RETURN_VALUES_LENGTH] {
let mut serialized_args = [0; 3];
serialized_args[0] = from.address;
serialized_args[1] = amount;
serialized_args[2] = nonce;

context.call_public_function(self.address, 0xb0e964d5, serialized_args)
}


pub fn mint_private(
self,
context: PublicContext,
amount: Field,
secret_hash: Field
) -> [Field; RETURN_VALUES_LENGTH] {
let mut serialized_args = [0; 2];
serialized_args[0] = amount;
serialized_args[1] = sender;
serialized_args[2] = recipient;
serialized_args[1] = secret_hash;

// 0xdcd4c318 is the function selector for `transfer(field,field,field)`
context.call_private_function(self.address, 0xdcd4c318, serialized_args)
context.call_public_function(self.address, 0x10763932, serialized_args)
}


}
```

Expand Down

0 comments on commit dc4482c

Please sign in to comment.