Skip to content

Commit

Permalink
register on first call
Browse files Browse the repository at this point in the history
  • Loading branch information
ermvrs committed Dec 18, 2024
1 parent 8db9b51 commit a4241a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/accounts/base.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ pub mod RosettaAccount {
}
#[abi(embed_v0)]
impl AccountImpl of super::IRosettaAccount<ContractState> {
// Instead of Array<Call> we use Array<felt252> since we pass different values to the
// parameter
// It is EOA execution so multiple calls are not possible right now. We will add Multicalls in a different way in beta
// calls params can include raw signed tx or can include the abi parsing bit locations for calldata
fn __execute__(self: @ContractState, call: RosettanetCall) -> Array<Span<felt252>> {
let sender = get_caller_address();
assert(sender.is_zero(), Errors::INVALID_CALLER);

self.register_account(); // Register this contract if not registered on registry

let eth_target: EthAddress = call.to;
let sn_target: ContractAddress = IRosettanetDispatcher { contract_address: self.registry.read() }.get_starknet_address(eth_target);
assert(sn_target != starknet::contract_address_const::<0>(), 'target not registered');
Expand Down Expand Up @@ -290,5 +288,13 @@ pub mod RosettaAccount {

array![array![].span()]
}

fn register_account(self: @ContractState) {
let rosettanet = IRosettanetDispatcher { contract_address: self.registry.read() };
let eth_address: EthAddress = self.ethereum_address.read();
if(rosettanet.get_starknet_address(eth_address) == starknet::contract_address_const::<0>()) {
rosettanet.register_deployed_account(eth_address);
}
}
}
}
2 changes: 1 addition & 1 deletion src/rosettanet.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub mod Rosettanet {
/// * `eth_address` - Ethereum Address for already deployed account
fn register_deployed_account(ref self: ContractState, eth_address: EthAddress) {
let precalculated_address: ContractAddress = self.precalculate_starknet_account(eth_address);
assert(IRosettaAccountDispatcher { contract_address: precalculated_address}.rosettanet() == get_contract_address(), 'wrong deployment');
assert(IRosettaAccountDispatcher { contract_address: precalculated_address }.rosettanet() == get_contract_address(), 'wrong deployment');
// TODO: Add tests for this function
self.update_registry(precalculated_address, eth_address);

Expand Down

0 comments on commit a4241a1

Please sign in to comment.