How to validate BAND Protocol Network address?

Viewed 15

I am trying to write a wallet address validator with golang. I wrote the validator for ATOM (Cosmos). BAND network also using the Cosmos SDK. BAND network and ATOM network are similiar.

This is the code of the Cosmos wallet validator I wrote:

package atom_validator

import (
    "regexp"

    "github.com/btcsuite/btcutil/bech32"
)

const allowed_chars = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
const atomRegex = "^(cosmos)1([" + allowed_chars + "]+)$" // cosmos + bech32 separated by "1"

func IsValidAddress(address string) bool {
    match, _ := regexp.MatchString(atomRegex, address)
    if match {
        return verifyChecksum(address)
    } else {
        return false
    }
}

func verifyChecksum(address string) bool {
    _, decoded, _ := bech32.Decode(address)

    if decoded != nil {
        return len(decoded) == 32
    } else {
        return false
    }
}

I am looking for a way to do the same validation for BAND Protocol using Golang. Thank you.

1 Answers

I solved the problem. Just replaced "atom" with "band" in the regex string.

package band_validator


import (
    "regexp"

    "github.com/btcsuite/btcutil/bech32"
)

const allowed_chars = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
const atomRegex = "^(band)1([" + allowed_chars + "]+)$"

func IsValidAddress(address string) bool {
    match, _ := regexp.MatchString(atomRegex, address)
    if match {
        return verifyChecksum(address)
    } else {
        return false
    }
}

func verifyChecksum(address string) bool {
    _, decoded, _ := bech32.Decode(address)

    if decoded != nil {
        return len(decoded) == 32
    } else {
        return false
    }
}

Related