Skip to content

Instantly share code, notes, and snippets.

@m-kus
Created December 27, 2024 12:46
Show Gist options
  • Save m-kus/25a85fe2ba0f4425cc29a1ecf7223ede to your computer and use it in GitHub Desktop.
Save m-kus/25a85fe2ba0f4425cc29a1ecf7223ede to your computer and use it in GitHub Desktop.
NoValidate account contract
#[starknet::interface]
pub trait ValidateDeploy<TContractState> {
fn __validate_deploy__(
self: @TContractState,
class_hash: felt252,
contract_address_salt: felt252,
public_key: felt252
) -> felt252;
}
#[starknet::contract(account)]
mod NoValidate {
use array::{ArrayTrait, SpanTrait};
use box::BoxTrait;
use starknet::account::{Call, AccountContract};
use starknet::{ContractAddress, call_contract_syscall};
use zeroable::Zeroable;
use array::ArraySerde;
#[storage]
struct Storage {
}
#[constructor]
fn constructor(ref self: ContractState, public_key: felt252) {
}
#[abi(embed_v0)]
impl NoValidateDeploy of super::ValidateDeploy<ContractState> {
fn __validate_deploy__(
self: @ContractState,
class_hash: felt252,
contract_address_salt: felt252,
public_key: felt252
) -> felt252 {
starknet::VALIDATED
}
}
#[abi(embed_v0)]
impl NoValidateAccount of AccountContract<ContractState> {
fn __validate_declare__(self: @ContractState, class_hash: felt252) -> felt252 {
starknet::VALIDATED
}
fn __validate__(ref self: ContractState, calls: Array<Call>) -> felt252 {
starknet::VALIDATED
}
fn __execute__(ref self: ContractState, mut calls: Array<Call>) -> Array<Span<felt252>> {
// Validate caller.
assert(starknet::get_caller_address().is_zero(), 'INVALID_CALLER');
// Check the tx version here, since version 0 transaction skip the __validate__ function.
let tx_info = starknet::get_tx_info().unbox();
assert(tx_info.version != 0, 'INVALID_TX_VERSION');
let mut result = ArrayTrait::new();
while let Option::Some(call) = calls.pop_front() {
let mut res = call_contract_syscall(
address: call.to,
entry_point_selector: call.selector,
calldata: call.calldata
)
.unwrap();
result.append(res);
};
result
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment