From 6bde0f74163da65de484f7636a92772d7f272292 Mon Sep 17 00:00:00 2001 From: PhilippeR26 Date: Fri, 19 Jan 2024 10:36:39 +0100 Subject: [PATCH] docs: add interface for contract 1 --- cairo/merkleTreeVerify.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cairo/merkleTreeVerify.md b/cairo/merkleTreeVerify.md index 6f4b68d..e6fe3f2 100644 --- a/cairo/merkleTreeVerify.md +++ b/cairo/merkleTreeVerify.md @@ -119,11 +119,39 @@ fn constructor( ref self: ContractState, erc20_address: ContractAddress, merkle_address: ContractAddress, // address of Contract 1 + erc20_owner: ContractAddress, start_time: u64, ) ``` This value has to be stored in the contract. +In your contract 2, you will call contract 1 functions. You can proceed this two ways : +- low level call, with `call_contract_syscall`. All example above are using this function. +- high level call, using the `IMerkleVerify` interface. Add this code at the beginning of your contract : +```rust +#[starknet::interface] +trait IMerkleVerify { + fn get_root(self: @TContractState) -> felt252; + fn verify_from_leaf_hash( + self: @TContractState, leaf_hash: felt252, proof: Array + ) -> bool; + fn verify_from_leaf_array( + self: @TContractState, leaf_array: Array, proof: Array + ) -> bool; + fn verify_from_leaf_airdrop( + self: @TContractState, address: ContractAddress, amount: u256, proof: Array + ) -> bool; + fn hash_leaf_array(self: @TContractState, leaf: Array) -> felt252; +} +``` +and an example of use +```rust +let is_request_valid: bool = IMerkleVerifyDispatcher { + contract_address: self.merkle_address.read() + } + .verify_from_leaf_airdrop( address, amount, proof); +``` + ### hash_leaf_array() : Calculate the Pedersen/Poseidon hash of a Merkle tree leaf.