0x1::ChainId
The module provides chain id information.
ChainId
initialize
get
is_dev
is_test
is_halley
is_proxima
is_barnard
is_main
use 0x1::CoreAddresses;
use 0x1::Timestamp;
ChainId
chain id data structure.
struct ChainId has key
id: u8
const BARNARD_CHAIN_ID: u8 = 251;
const DEV_CHAIN_ID: u8 = 254;
const HALLEY_CHAIN_ID: u8 = 253;
const MAIN_CHAIN_ID: u8 = 1;
const PROXIMA_CHAIN_ID: u8 = 252;
const TEST_CHAIN_ID: u8 = 255;
initialize
Publish the chain ID under the genesis account
public fun initialize(account: &signer, id: u8)
public fun initialize(account: &signer, id: u8) {
Timestamp::assert_genesis();
CoreAddresses::assert_genesis_address(account);
move_to(account, ChainId { id });
}
aborts_if !Timestamp::is_genesis();
aborts_if Signer::address_of(account) != CoreAddresses::GENESIS_ADDRESS();
aborts_if exists<ChainId>(Signer::address_of(account));
ensures exists<ChainId>(Signer::address_of(account));
get
Return the chain ID of this chain
public fun get(): u8
public fun get(): u8 acquires ChainId {
borrow_global<ChainId>(CoreAddresses::GENESIS_ADDRESS()).id
}
aborts_if !exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
is_dev
public fun is_dev(): bool
public fun is_dev(): bool acquires ChainId {
get() == DEV_CHAIN_ID
}
aborts_if !exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
is_test
public fun is_test(): bool
public fun is_test(): bool acquires ChainId {
get() == TEST_CHAIN_ID
}
aborts_if !exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
is_halley
public fun is_halley(): bool
public fun is_halley(): bool acquires ChainId {
get() == HALLEY_CHAIN_ID
}
aborts_if !exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
is_proxima
public fun is_proxima(): bool
public fun is_proxima(): bool acquires ChainId {
get() == PROXIMA_CHAIN_ID
}
aborts_if !exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
is_barnard
public fun is_barnard(): bool
public fun is_barnard(): bool acquires ChainId {
get() == BARNARD_CHAIN_ID
}
aborts_if !exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
is_main
public fun is_main(): bool
public fun is_main(): bool acquires ChainId {
get() == MAIN_CHAIN_ID
}
aborts_if !exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::GENESIS_ADDRESS());
pragma verify;
pragma aborts_if_is_strict;