avoid concurrent write to addressPrefixes
This commit is contained in:
parent
dd814b834b
commit
40f9c3f961
1 changed files with 5 additions and 7 deletions
|
@ -2,6 +2,7 @@ package address
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/lbryio/lbryschema.go/address/base58"
|
"github.com/lbryio/lbryschema.go/address/base58"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,16 +21,13 @@ const lbrycrdMain = "lbrycrd_main"
|
||||||
const lbrycrdTestnet = "lbrycrd_testnet"
|
const lbrycrdTestnet = "lbrycrd_testnet"
|
||||||
const lbrycrdRegtest = "lbrycrd_regtest"
|
const lbrycrdRegtest = "lbrycrd_regtest"
|
||||||
|
|
||||||
var addressPrefixes = map[string][2]byte{}
|
var addressPrefixes = map[string][2]byte{
|
||||||
|
lbrycrdMain: [2]byte{lbrycrdMainPubkeyPrefix, lbrycrdMainScriptPrefix},
|
||||||
func SetPrefixes() {
|
lbrycrdTestnet: [2]byte{lbrycrdTestnetPubkeyPrefix, lbrycrdTestnetScriptPrefix},
|
||||||
addressPrefixes[lbrycrdMain] = [2]byte{lbrycrdMainPubkeyPrefix, lbrycrdMainScriptPrefix}
|
lbrycrdRegtest: [2]byte{lbrycrdRegtestPubkeyPrefix, lbrycrdRegtestScriptPrefix},
|
||||||
addressPrefixes[lbrycrdTestnet] = [2]byte{lbrycrdTestnetPubkeyPrefix, lbrycrdTestnetScriptPrefix}
|
|
||||||
addressPrefixes[lbrycrdRegtest] = [2]byte{lbrycrdRegtestPubkeyPrefix, lbrycrdRegtestScriptPrefix}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrefixIsValid(address [addressLength]byte, blockchainName string) bool {
|
func PrefixIsValid(address [addressLength]byte, blockchainName string) bool {
|
||||||
SetPrefixes()
|
|
||||||
prefix := address[0]
|
prefix := address[0]
|
||||||
for _, addrPrefix := range addressPrefixes[blockchainName] {
|
for _, addrPrefix := range addressPrefixes[blockchainName] {
|
||||||
if addrPrefix == prefix {
|
if addrPrefix == prefix {
|
||||||
|
|
Loading…
Reference in a new issue