From 96f39d0f28943f7b13929fa60e0122dc8abca711 Mon Sep 17 00:00:00 2001 From: Dusan Sekulic Date: Fri, 22 Oct 2021 12:01:14 +0200 Subject: [PATCH] Testnet support (#179) * added factory method FromPublicKeys for creating multiscript payment * testnet support --- address/address.go | 11 +++++++++++ network/network.go | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/address/address.go b/address/address.go index 9ec70e3..345e299 100644 --- a/address/address.go +++ b/address/address.go @@ -392,6 +392,11 @@ func NetworkForAddress(address string) (*network.Network, error) { return &network.Regtest, nil } + if strings.HasPrefix(address, network.Testnet.Bech32) || + strings.HasPrefix(address, network.Testnet.Blech32) { + return &network.Testnet, nil + } + _, prefix, err := base58.CheckDecode(address) if err != nil { return nil, err @@ -409,6 +414,12 @@ func NetworkForAddress(address string) (*network.Network, error) { return &network.Regtest, nil } + if prefix == network.Testnet.Confidential || + prefix == network.Testnet.PubKeyHash || + prefix == network.Testnet.ScriptHash { + return &network.Testnet, nil + } + return nil, errors.New("unknown prefix for address") } diff --git a/network/network.go b/network/network.go index 70517ee..af94871 100644 --- a/network/network.go +++ b/network/network.go @@ -38,7 +38,7 @@ var Liquid = Network{ AssetID: "6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d", } -// Regtest defines the network parameters for the regression test network. +// Regtest defines the network parameters for the regression regtest network. var Regtest = Network{ Name: "regtest", Bech32: "ert", @@ -51,3 +51,17 @@ var Regtest = Network{ Confidential: 4, AssetID: "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225", } + +// Testnet defines the network parameters for the regression testnet network. +var Testnet = Network{ + Name: "testnet", + Bech32: "tex", + Blech32: "tlq", + HDPublicKey: [4]byte{0x04, 0x35, 0x87, 0xcf}, + HDPrivateKey: [4]byte{0x04, 0x35, 0x83, 0x94}, + PubKeyHash: 36, + ScriptHash: 19, + Wif: 0xef, + Confidential: 23, + AssetID: "144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49", +}