starcoin-framework

Module 0x1::ChainId

The module provides chain id information.

use 0x1::CoreAddresses;
use 0x1::Timestamp;

Resource ChainId

chain id data structure.

struct ChainId has key
Fields
id: u8
real id.

Constants

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;

Function initialize

Publish the chain ID under the genesis account

public fun initialize(account: &signer, id: u8)
Implementation
public fun initialize(account: &signer, id: u8) {
    Timestamp::assert_genesis();
    CoreAddresses::assert_genesis_address(account);
    move_to(account, ChainId { id });
}
Specification
aborts_if !Timestamp::is_genesis();
aborts_if Signer::address_of(account) != CoreAddresses::SPEC_GENESIS_ADDRESS();
aborts_if exists<ChainId>(Signer::address_of(account));
ensures exists<ChainId>(Signer::address_of(account));

Function get

Return the chain ID of this chain

public fun get(): u8
Implementation
public fun get(): u8 acquires ChainId {
    borrow_global<ChainId>(CoreAddresses::GENESIS_ADDRESS()).id
}
Specification
aborts_if !exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());

Function is_dev

public fun is_dev(): bool
Implementation
public fun is_dev(): bool acquires ChainId {
    get() == DEV_CHAIN_ID
}
Specification
aborts_if !exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());

Function is_test

public fun is_test(): bool
Implementation
public fun is_test(): bool acquires ChainId {
    get() == TEST_CHAIN_ID
}
Specification
aborts_if !exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());

Function is_halley

public fun is_halley(): bool
Implementation
public fun is_halley(): bool acquires ChainId {
    get() == HALLEY_CHAIN_ID
}
Specification
aborts_if !exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());

Function is_proxima

public fun is_proxima(): bool
Implementation
public fun is_proxima(): bool acquires ChainId {
    get() == PROXIMA_CHAIN_ID
}
Specification
aborts_if !exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());

Function is_barnard

public fun is_barnard(): bool
Implementation
public fun is_barnard(): bool acquires ChainId {
    get() == BARNARD_CHAIN_ID
}
Specification
aborts_if !exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());

Function is_main

public fun is_main(): bool
Implementation
public fun is_main(): bool acquires ChainId {
    get() == MAIN_CHAIN_ID
}
Specification
aborts_if !exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());
ensures exists<ChainId>(CoreAddresses::SPEC_GENESIS_ADDRESS());

Module Specification

pragma verify;
pragma aborts_if_is_strict;