Skip to content

Commit

Permalink
Fix: add smart rollup address checking
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Aug 17, 2023
1 parent f789138 commit 6d48edf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
42 changes: 32 additions & 10 deletions tools/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func IsLiteral(prim string) bool {
}

// IsContract -
func IsContract(address string) bool {
func IsContractLazy(address string) bool {
return len(address) == 36 && strings.HasPrefix(address, "KT")
}

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

// IsRollupAddressLazy -
func IsRollupAddressLazy(address string) bool {
return len(address) == 37 && strings.HasPrefix(address, "txr")
}

// IsRollupAddressLazy -
func IsSmartRollupAddressLazy(address string) bool {
return len(address) == 36 && strings.HasPrefix(address, "sr1")
}

var (
addressRegex = regexp.MustCompile("(tz|KT)[0-9A-Za-z]{34}")
operationHashRegex = regexp.MustCompile("(o)[0-9A-Za-z]{50}")
bigMapKeyHashRegex = regexp.MustCompile("(expr)[0-9A-Za-z]{50}")
addressRegex = regexp.MustCompile("(tz|KT|txr|sr)[0-9A-Za-z]{34}")
contractRegex = regexp.MustCompile("(KT1)[0-9A-Za-z]{33}")
bakerHashRegex = regexp.MustCompile("(SG1)[0-9A-Za-z]{33}")
operationRegex = regexp.MustCompile("^o[1-9A-HJ-NP-Za-km-z]{50}$")
smartRollupRegex = regexp.MustCompile("(sr)[0-9A-Za-z]{34}")
bigMapKeyHashRegex = regexp.MustCompile("(expr)[0-9A-Za-z]{50}")
)

// IsAddress -
func IsAddress(str string) bool {
return addressRegex.MatchString(str)
}

// IsContract -
func IsContract(str string) bool {
return contractRegex.MatchString(str)
}

// IsBakerHash -
func IsBakerHash(str string) bool {
return bakerHashRegex.MatchString(str)
}

// IsOperationHash -
func IsOperationHash(str string) bool {
return operationHashRegex.MatchString(str)
return operationRegex.MatchString(str)
}

// IsSmartRollupHash -
func IsSmartRollupHash(str string) bool {
return smartRollupRegex.MatchString(str)
}

// IsBigMapKeyHash -
func IsBigMapKeyHash(str string) bool {
return bigMapKeyHashRegex.MatchString(str)
}

// IsBakerHash -
func IsBakerHash(str string) bool {
return bakerHashRegex.MatchString(str)
}
8 changes: 8 additions & 0 deletions tools/literal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func TestIsAddress(t *testing.T) {
name: "tz1PUnJ3m435ZK4RTqhTEiSYF22YAUx5rEU1",
str: "tz1PUnJ3m435ZK4RTqhTEiSYF22YAUx5rEU1",
want: true,
}, {
name: "sr1J1ECygUgzE7urU3Ayr5HZaty83hpjbs28",
str: "sr1J1ECygUgzE7urU3Ayr5HZaty83hpjbs28",
want: true,
}, {
name: "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UA",
str: "txr1YNMEtkj5Vkqsbdmt7xaxBTMRZjzS96UA",
want: false,
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 6d48edf

Please sign in to comment.