Skip to content

Commit 6c48cb5

Browse files
committed
update address generator to match the flow-go
1 parent 6920f8f commit 6c48cb5

2 files changed

Lines changed: 38 additions & 12 deletions

File tree

address.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ func chainCustomizer(chain ChainID) uint64 {
107107
case Mainnet:
108108
return 0
109109
case Testnet:
110-
return invalidCodeTestnet
111-
case Emulator:
112-
return invalidCodeEmulator
110+
return invalidCodeTestNetwork
111+
case Stagingnet:
112+
return invalidCodeStagingNetwork
113+
case Emulator, Localnet, Benchnet, BftTestnet:
114+
return invalidCodeTransientNetwork
113115
default:
114-
panic("chain ID is invalid")
116+
panic(fmt.Sprintf("chain ID [%s] is invalid or does not support linear code address generation", chain))
115117
}
116118
}
117119

@@ -261,8 +263,14 @@ func (a *Address) IsValid(chain ChainID) bool {
261263
// invalid code-words in the [64,45] code
262264
// these constants are used to generate non-Flow-Mainnet addresses
263265
const (
264-
invalidCodeTestnet = uint64(0x6834ba37b3980209)
265-
invalidCodeEmulator = uint64(0x1cb159857af02018)
266+
// invalidCodeTestNetwork is the invalid codeword used for long-lived test networks.
267+
invalidCodeTestNetwork = uint64(0x6834ba37b3980209)
268+
269+
// invalidCodeTransientNetwork is the invalid codeword used for transient test networks.
270+
invalidCodeTransientNetwork = uint64(0x1cb159857af02018)
271+
272+
// invalidCodeStagingNetwork is the invalid codeword used for Staging network.
273+
invalidCodeStagingNetwork = uint64(0x1035ce4eff92ae01)
266274
)
267275

268276
// Rows of the generator matrix G of the [64,45]-code used for Flow addresses.

flow.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,32 @@ func HashToStateCommitment(hash []byte) StateCommitment {
9595
// Chain IDs are used used to prevent replay attacks and to support network-specific address generation.
9696
type ChainID string
9797

98-
// Mainnet is the chain ID for the mainnet node chain.
99-
const Mainnet ChainID = "flow-mainnet"
98+
const (
99+
// Mainnet is the chain ID for the mainnet chain.
100+
Mainnet ChainID = "flow-mainnet"
100101

101-
// Testnet is the chain ID for the testnet node chain.
102-
const Testnet ChainID = "flow-testnet"
102+
// Long-lived test networks
103103

104-
// Emulator is the chain ID for the emulated node chain.
105-
const Emulator ChainID = "flow-emulator"
104+
// Testnet is the chain ID for the testnet chain.
105+
Testnet ChainID = "flow-testnet"
106+
107+
// Stagingnet is the chain ID for internal stagingnet chain.
108+
Stagingnet ChainID = "flow-stagingnet"
109+
110+
// Transient test networks
111+
112+
// Benchnet is the chain ID for the transient benchmarking chain.
113+
Benchnet ChainID = "flow-benchnet"
114+
// Localnet is the chain ID for the local development chain.
115+
Localnet ChainID = "flow-localnet"
116+
// Emulator is the chain ID for the emulated chain.
117+
Emulator ChainID = "flow-emulator"
118+
// BftTestnet is the chain ID for testing attack vector scenarios.
119+
BftTestnet ChainID = "flow-bft-test-net"
120+
121+
// MonotonicEmulator is the chain ID for the emulated node chain with monotonic address generation.
122+
MonotonicEmulator ChainID = "flow-emulator-monotonic"
123+
)
106124

107125
func (id ChainID) String() string {
108126
return string(id)

0 commit comments

Comments
 (0)