Module 0xb::chain_ids
- Struct
BridgeRoute
- Constants
- Function
iota_mainnet
- Function
iota_testnet
- Function
iota_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
Fields
source: u8
destination: u8
Constants
const EInvalidBridgeRoute: u64 = 0;
const EthCustom: u8 = 12;
const EthMainnet: u8 = 10;
const EthSepolia: u8 = 11;
const IotaCustom: u8 = 2;
const IotaMainnet: u8 = 0;
const IotaTestnet: u8 = 1;
Function iota_mainnet
public fun iota_mainnet(): u8
Implementation
public fun iota_mainnet(): u8 { IotaMainnet }
Function iota_testnet
public fun iota_testnet(): u8
Implementation
public fun iota_testnet(): u8 { IotaTestnet }
Function iota_custom
public fun iota_custom(): u8
Implementation
public fun iota_custom(): u8 { IotaCustom }
Function eth_mainnet
public fun eth_mainnet(): u8
Implementation
public fun eth_mainnet(): u8 { EthMainnet }
Function eth_sepolia
public fun eth_sepolia(): u8
Implementation
public fun eth_sepolia(): u8 { EthSepolia }
Function eth_custom
public fun eth_custom(): u8
Implementation
public fun eth_custom(): u8 { EthCustom }
Function route_source
public fun route_source(route: &chain_ids::BridgeRoute): &u8
Implementation
public fun route_source(route: &BridgeRoute): &u8 {
&route.source
}
Function route_destination
public fun route_destination(route: &chain_ids::BridgeRoute): &u8
Implementation
public fun route_destination(route: &BridgeRoute): &u8 {
&route.destination
}
Function assert_valid_chain_id
public fun assert_valid_chain_id(id: u8)
Implementation
public fun assert_valid_chain_id(id: u8) {
assert!(
id == IotaMainnet ||
id == IotaTestnet ||
id == IotaCustom ||
id == EthMainnet ||
id == EthSepolia ||
id == EthCustom,
EInvalidBridgeRoute
)
}
Function valid_routes
public fun valid_routes(): vector<chain_ids::BridgeRoute>
Implementation
public fun valid_routes(): vector<BridgeRoute> {
vector[
BridgeRoute { source: IotaMainnet, destination: EthMainnet },
BridgeRoute { source: EthMainnet, destination: IotaMainnet },
BridgeRoute { source: IotaTestnet, destination: EthSepolia },
BridgeRoute { source: IotaTestnet, destination: EthCustom },
BridgeRoute { source: IotaCustom, destination: EthCustom },
BridgeRoute { source: IotaCustom, destination: EthSepolia },
BridgeRoute { source: EthSepolia, destination: IotaTestnet },
BridgeRoute { source: EthSepolia, destination: IotaCustom },
BridgeRoute { source: EthCustom, destination: IotaTestnet },
BridgeRoute { source: EthCustom, destination: IotaCustom }
]
}
Function is_valid_route
public fun is_valid_route(source: u8, destination: u8): bool
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
Implementation
public fun get_route(source: u8, destination: u8): BridgeRoute {
let route = BridgeRoute { source, destination };
assert!(valid_routes().contains(&route), EInvalidBridgeRoute);
route
}