Skip to content

Commit 6d48edf

Browse files
Fix: add smart rollup address checking
1 parent f789138 commit 6d48edf

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

tools/literal.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func IsLiteral(prim string) bool {
2222
}
2323

2424
// IsContract -
25-
func IsContract(address string) bool {
25+
func IsContractLazy(address string) bool {
2626
return len(address) == 36 && strings.HasPrefix(address, "KT")
2727
}
2828

@@ -31,29 +31,51 @@ func IsAddressLazy(address string) bool {
3131
return len(address) == 36 && (strings.HasPrefix(address, "KT") || strings.HasPrefix(address, "tz"))
3232
}
3333

34+
// IsRollupAddressLazy -
35+
func IsRollupAddressLazy(address string) bool {
36+
return len(address) == 37 && strings.HasPrefix(address, "txr")
37+
}
38+
39+
// IsRollupAddressLazy -
40+
func IsSmartRollupAddressLazy(address string) bool {
41+
return len(address) == 36 && strings.HasPrefix(address, "sr1")
42+
}
43+
3444
var (
35-
addressRegex = regexp.MustCompile("(tz|KT)[0-9A-Za-z]{34}")
36-
operationHashRegex = regexp.MustCompile("(o)[0-9A-Za-z]{50}")
37-
bigMapKeyHashRegex = regexp.MustCompile("(expr)[0-9A-Za-z]{50}")
45+
addressRegex = regexp.MustCompile("(tz|KT|txr|sr)[0-9A-Za-z]{34}")
46+
contractRegex = regexp.MustCompile("(KT1)[0-9A-Za-z]{33}")
3847
bakerHashRegex = regexp.MustCompile("(SG1)[0-9A-Za-z]{33}")
48+
operationRegex = regexp.MustCompile("^o[1-9A-HJ-NP-Za-km-z]{50}$")
49+
smartRollupRegex = regexp.MustCompile("(sr)[0-9A-Za-z]{34}")
50+
bigMapKeyHashRegex = regexp.MustCompile("(expr)[0-9A-Za-z]{50}")
3951
)
4052

4153
// IsAddress -
4254
func IsAddress(str string) bool {
4355
return addressRegex.MatchString(str)
4456
}
4557

58+
// IsContract -
59+
func IsContract(str string) bool {
60+
return contractRegex.MatchString(str)
61+
}
62+
63+
// IsBakerHash -
64+
func IsBakerHash(str string) bool {
65+
return bakerHashRegex.MatchString(str)
66+
}
67+
4668
// IsOperationHash -
4769
func IsOperationHash(str string) bool {
48-
return operationHashRegex.MatchString(str)
70+
return operationRegex.MatchString(str)
71+
}
72+
73+
// IsSmartRollupHash -
74+
func IsSmartRollupHash(str string) bool {
75+
return smartRollupRegex.MatchString(str)
4976
}
5077

5178
// IsBigMapKeyHash -
5279
func IsBigMapKeyHash(str string) bool {
5380
return bigMapKeyHashRegex.MatchString(str)
5481
}
55-
56-
// IsBakerHash -
57-
func IsBakerHash(str string) bool {
58-
return bakerHashRegex.MatchString(str)
59-
}

tools/literal_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ func TestIsAddress(t *testing.T) {
125125
name: "tz1PUnJ3m435ZK4RTqhTEiSYF22YAUx5rEU1",
126126
str: "tz1PUnJ3m435ZK4RTqhTEiSYF22YAUx5rEU1",
127127
want: true,
128+
}, {
129+
name: "sr1J1ECygUgzE7urU3Ayr5HZaty83hpjbs28",
130+
str: "sr1J1ECygUgzE7urU3Ayr5HZaty83hpjbs28",
131+
want: true,
132+
}, {
133+
name: "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UA",
134+
str: "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UA",
135+
want: false,
128136
},
129137
}
130138
for _, tt := range tests {

0 commit comments

Comments
 (0)