Module 0xb::chain_ids
- Struct
BridgeRoute
- Constants
- Function
sui_mainnet
- Function
sui_testnet
- Function
sui_custom
- Function
eth_mainnet
- Function
eth_sepolia
- Function
eth_custom
- Function
route_source
- Function
route_destination
- Function
assert_valid_chain_id
- Function
valid_routes
- Function
is_valid_route
- Function
get_route
use 0x1::vector;
Struct BridgeRoute
struct BridgeRoute has copy, drop, store
Click to open
Fields
- source: u8
- destination: u8
Constants
const EInvalidBridgeRoute: u64 = 0;
const EthCustom: u8 = 12;
const EthMainnet: u8 = 10;
const EthSepolia: u8 = 11;
const SuiCustom: u8 = 2;
const SuiMainnet: u8 = 0;
const SuiTestnet: u8 = 1;
Function sui_mainnet
public fun sui_mainnet(): u8
Click to open
Implementation
public fun sui_mainnet(): u8 { SuiMainnet }
Function sui_testnet
public fun sui_testnet(): u8
Click to open
Implementation
public fun sui_testnet(): u8 { SuiTestnet }
Function sui_custom
public fun sui_custom(): u8
Click to open
Implementation
public fun sui_custom(): u8 { SuiCustom }
Function eth_mainnet
public fun eth_mainnet(): u8
Click to open
Implementation
public fun eth_mainnet(): u8 { EthMainnet }
Function eth_sepolia
public fun eth_sepolia(): u8
Click to open
Implementation
public fun eth_sepolia(): u8 { EthSepolia }
Function eth_custom
public fun eth_custom(): u8
Click to open
Implementation
public fun eth_custom(): u8 { EthCustom }
Function route_source
public fun route_source(route: &chain_ids::BridgeRoute): &u8
Click to open
Implementation
public fun route_source(route: &BridgeRoute): &u8 {
&route.source
}
Function route_destination
public fun route_destination(route: &chain_ids::BridgeRoute): &u8
Click to open
Implementation
public fun route_destination(route: &BridgeRoute): &u8 {
&route.destination
}
Function assert_valid_chain_id
public fun assert_valid_chain_id(id: u8)
Click to open
Implementation
public fun assert_valid_chain_id(id: u8) {
assert!(
id == SuiMainnet ||
id == SuiTestnet ||
id == SuiCustom ||
id == EthMainnet ||
id == EthSepolia ||
id == EthCustom,
EInvalidBridgeRoute
)
}
Function valid_routes
public fun valid_routes(): vector<chain_ids::BridgeRoute>
Click to open
Implementation
public fun valid_routes(): vector<BridgeRoute> {
vector[
BridgeRoute { source: SuiMainnet, destination: EthMainnet },
BridgeRoute { source: EthMainnet, destination: SuiMainnet },
BridgeRoute { source: SuiTestnet, destination: EthSepolia },
BridgeRoute { source: SuiTestnet, destination: EthCustom },
BridgeRoute { source: SuiCustom, destination: EthCustom },
BridgeRoute { source: SuiCustom, destination: EthSepolia },
BridgeRoute { source: EthSepolia, destination: SuiTestnet },
BridgeRoute { source: EthSepolia, destination: SuiCustom },
BridgeRoute { source: EthCustom, destination: SuiTestnet },
BridgeRoute { source: EthCustom, destination: SuiCustom }
]
}
Function is_valid_route
public fun is_valid_route(source: u8, destination: u8): bool
Click to open
Implementation
public fun is_valid_route(source: u8, destination: u8): bool {
let route = BridgeRoute { source, destination };
valid_routes().contains(&route)
}
Function get_route
public fun get_route(source: u8, destination: u8): chain_ids::BridgeRoute
Click to open
Implementation
public fun get_route(source: u8, destination: u8): BridgeRoute {
let route = BridgeRoute { source, destination };
assert!(valid_routes().contains(&route), EInvalidBridgeRoute);
route
}