Skip to content

Commit a818f5a

Browse files
committed
refactor code words into dictionary to improve extensibility
1 parent 177f46a commit a818f5a

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

contracts/LinearCodeAddressGenerator.cdc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@
33
access(all)
44
contract LinearCodeAddressGenerator {
55

6-
/// The code word for addresses on Flow Mainnet.
76
access(all)
8-
let codeWordMainnet: UInt64
9-
10-
/// The code word for addresses on Flow Testnet.
11-
access(all)
12-
let codeWordTestnet: UInt64
13-
14-
/// The code word for addresses on transient networks, like the Flow Emulator.
15-
access(all)
16-
let codeWordTransient: UInt64
7+
let codeWords: {String: UInt64}
178

189
/// Rows of the generator matrix G of the [64,45]-code used for Flow addresses.
1910
/// G is a (k x n) matrix with coefficients in GF(2), each row is converted into
@@ -30,9 +21,11 @@ contract LinearCodeAddressGenerator {
3021
let parityCheckMatrixColumns: [UInt64; 64]
3122

3223
init() {
33-
self.codeWordMainnet = 0
34-
self.codeWordTestnet = 0x6834ba37b3980209
35-
self.codeWordTransient = 0x1cb159857af02018
24+
self.codeWords = {
25+
"mainnet": 0,
26+
"testnet": 0x6834ba37b3980209,
27+
"transient": 0x1cb159857af02018
28+
}
3629

3730
self.generatorMatrixRows = [
3831
0xe467b9dd11fa00df, 0xf233dcee88fe0abe, 0xf919ee77447b7497, 0xfc8cf73ba23a260d,

tests/LinearCodeAddressGenerator_test.cdc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ access(all)
5555
fun testMainnet() {
5656
checkAddresses(
5757
count: 10,
58-
chainCodeWord: LinearCodeAddressGenerator.codeWordMainnet,
58+
chainCodeWord: LinearCodeAddressGenerator.codeWords["mainnet"]!,
5959
expected: [
6060
0xe467b9dd11fa00df,
6161
0xf233dcee88fe0abe,
@@ -75,7 +75,7 @@ access(all)
7575
fun testTestnet() {
7676
checkAddresses(
7777
count: 10,
78-
chainCodeWord: LinearCodeAddressGenerator.codeWordTestnet,
78+
chainCodeWord: LinearCodeAddressGenerator.codeWords["testnet"]!,
7979
expected: [
8080
0x8c5303eaa26202d6,
8181
0x9a0766d93b6608b7,
@@ -95,7 +95,7 @@ access(all)
9595
fun testTransient() {
9696
checkAddresses(
9797
count: 10,
98-
chainCodeWord: LinearCodeAddressGenerator.codeWordTransient,
98+
chainCodeWord: LinearCodeAddressGenerator.codeWords["transient"]!,
9999
expected: [
100100
0xf8d6e0586b0a20c7,
101101
0xee82856bf20e2aa6,

0 commit comments

Comments
 (0)