/
info.cairo
133 lines (119 loc) · 4.46 KB
/
info.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use starknet::{
SyscallResultTrait, SyscallResult, syscalls::get_execution_info_syscall,
contract_address::ContractAddress
};
use core::box::BoxTrait;
#[derive(Copy, Drop)]
struct ExecutionInfo {
block_info: Box<BlockInfo>,
tx_info: Box<TxInfo>,
caller_address: ContractAddress,
contract_address: ContractAddress,
entry_point_selector: felt252,
}
#[derive(Copy, Drop, Serde)]
struct BlockInfo {
block_number: u64,
block_timestamp: u64,
sequencer_address: ContractAddress,
}
#[derive(Copy, Drop, Serde)]
struct TxInfo {
// The version of the transaction. It is fixed (currently, 1) in the OS, and should be
// signed by the account contract.
// This field allows invalidating old transactions, whenever the meaning of the other
// transaction fields is changed (in the OS).
version: felt252,
// The account contract from which this transaction originates.
account_contract_address: ContractAddress,
// The max_fee field of the transaction.
max_fee: u128,
// The signature of the transaction.
signature: Span<felt252>,
// The hash of the transaction.
transaction_hash: felt252,
// The identifier of the chain.
// This field can be used to prevent replay of testnet transactions on mainnet.
chain_id: felt252,
// The transaction's nonce.
nonce: felt252,
}
fn get_execution_info() -> Box<v2::ExecutionInfo> {
starknet::syscalls::get_execution_info_v2_syscall().unwrap_syscall()
}
fn get_caller_address() -> ContractAddress {
get_execution_info().unbox().caller_address
}
fn get_contract_address() -> ContractAddress {
get_execution_info().unbox().contract_address
}
fn get_block_info() -> Box<BlockInfo> {
get_execution_info().unbox().block_info
}
fn get_tx_info() -> Box<v2::TxInfo> {
get_execution_info().unbox().tx_info
}
fn get_block_timestamp() -> u64 {
get_block_info().unbox().block_timestamp
}
fn get_block_number() -> u64 {
get_block_info().unbox().block_number
}
/// The extended version of the `get_execution_info` syscall result.
mod v2 {
use starknet::contract_address::ContractAddress;
use super::BlockInfo;
#[derive(Copy, Drop)]
struct ExecutionInfo {
block_info: Box<BlockInfo>,
tx_info: Box<TxInfo>,
caller_address: ContractAddress,
contract_address: ContractAddress,
entry_point_selector: felt252,
}
#[derive(Copy, Drop, Serde)]
struct TxInfo {
// The version of the transaction. It is fixed (currently, 1) in the OS, and should be
// signed by the account contract.
// This field allows invalidating old transactions, whenever the meaning of the other
// transaction fields is changed (in the OS).
version: felt252,
// The account contract from which this transaction originates.
account_contract_address: ContractAddress,
// The max_fee field of the transaction.
max_fee: u128,
// The signature of the transaction.
signature: Span<felt252>,
// The hash of the transaction.
transaction_hash: felt252,
// The identifier of the chain.
// This field can be used to prevent replay of testnet transactions on mainnet.
chain_id: felt252,
// The transaction's nonce.
nonce: felt252,
// A span of ResourceBounds structs.
resource_bounds: Span<ResourceBounds>,
// The tip.
tip: u128,
// If specified, the paymaster should pay for the execution of the tx.
// The data includes the address of the paymaster sponsoring the transaction, followed by
// extra data to send to the paymaster.
paymaster_data: Span<felt252>,
// The data availability mode for the nonce.
nonce_data_availability_mode: u32,
// The data availability mode for the account balance from which fee will be taken.
fee_data_availability_mode: u32,
// If nonempty, will contain the required data for deploying and initializing an account
// contract: its class hash, address salt and constructor calldata.
account_deployment_data: Span<felt252>,
}
#[derive(Copy, Drop, Serde)]
struct ResourceBounds {
// The name of the resource.
resource: felt252,
// The maximum amount of the resource allowed for usage during the execution.
max_amount: u64,
// The maximum price the user is willing to pay for the resource unit.
max_price_per_unit: u128,
}
}