Skip to content

Commit

Permalink
Add get_env mwe
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter committed Sep 13, 2024
1 parent 3b80394 commit 8e396b1
Show file tree
Hide file tree
Showing 2 changed files with 647 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cairo_programs/get_env.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from starkware.cairo.common.uint256 import Uint256
from starkware.cairo.common.alloc import alloc

// @notice Store all environment data relevant to the current execution context.
// @param origin The origin of the transaction.
// @param gas_price The gas price for the call.
// @param chain_id The chain id of the current block.
// @param prev_randao The previous RANDAO value.
// @param block_number The block number of the current block.
// @param block_gas_limit The gas limit for the current block.
// @param block_timestamp The timestamp of the current block.
// @param coinbase The address of the miner of the current block.
// @param base_fee The basefee of the current block.
struct Environment {
origin: felt,
gas_price: felt,
chain_id: felt,
prev_randao: Uint256,
block_number: felt,
block_gas_limit: felt,
block_timestamp: felt,
coinbase: felt,
base_fee: felt,
}

// @notice Populate an Environment with hint
func get_env() -> Environment* {
let (env: Environment*) = alloc();
%{ get_env %}

return env;
}

func main() {
let env = get_env();
%{
print(f"{ids.origin=}")
print(f"{ids.gas_price=}")
print(f"{ids.chain_id=}")
print(f"{ids.prev_randao=}")
print(f"{ids.block_number=}")
print(f"{ids.block_gas_limit=}")
print(f"{ids.block_timestamp=}")
print(f"{ids.coinbase=}")
print(f"{ids.base_fee=}")
%}

return ();
}
Loading

0 comments on commit 8e396b1

Please sign in to comment.