From cdd52a2b63e757722e359d2a3f4746369afb4fe3 Mon Sep 17 00:00:00 2001 From: jagdeep sidhu Date: Wed, 2 Dec 2020 21:36:27 -0800 Subject: [PATCH 1/5] Add default address encodings for Bitcoin This should be here so its easily overridable by other UTXO chains. --- bitcoin/types.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bitcoin/types.go b/bitcoin/types.go index 8942577b..2a01f159 100644 --- a/bitcoin/types.go +++ b/bitcoin/types.go @@ -99,7 +99,12 @@ var ( Symbol: "BTC", Decimals: Decimals, } - + + // Mainnet address encoding magics + MainnetParams.PubKeyHashAddrID = []byte{0} + MainnetParams.ScriptHashAddrID = []byte{5} + MainnetParams.Bech32HRPSegwit = "bc" + // TestnetGenesisBlockIdentifier is the genesis block for testnet. TestnetGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943", @@ -114,6 +119,11 @@ var ( Decimals: Decimals, } + // Testnet address encoding magics + TestnetParams.PubKeyHashAddrID = []byte{111} + TestnetParams.ScriptHashAddrID = []byte{196} + TestnetParams.Bech32HRPSegwit = "tb" + // OperationTypes are all supported operation.Types. OperationTypes = []string{ InputOpType, From b6ff0db14407db0ca4bbbc90fb9c407dc2622881 Mon Sep 17 00:00:00 2001 From: jagdeep sidhu Date: Wed, 2 Dec 2020 22:37:39 -0800 Subject: [PATCH 2/5] create helper functions to override default network settings --- bitcoin/types.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/bitcoin/types.go b/bitcoin/types.go index 2a01f159..690f4cfa 100644 --- a/bitcoin/types.go +++ b/bitcoin/types.go @@ -85,6 +85,22 @@ const ( P2PKHScriptPubkeySize = 25 // P2PKH size ) +func CreateMainNetParams() (*chaincfg.Params) { + params := &chaincfg.MainNetParams + params.PubKeyHashAddrID = 0 + params.ScriptHashAddrID = 5 + params.Bech32HRPSegwit = "bc" + return params +} + +func CreateTestNet3Params() (*chaincfg.Params) { + params := &chaincfg.TestNet3Params + params.PubKeyHashAddrID = 111 + params.ScriptHashAddrID = 196 + params.Bech32HRPSegwit = "tb" + return params +} + var ( // MainnetGenesisBlockIdentifier is the genesis block for mainnet. MainnetGenesisBlockIdentifier = &types.BlockIdentifier{ @@ -92,7 +108,7 @@ var ( } // MainnetParams are the params for mainnet. - MainnetParams = &chaincfg.MainNetParams + MainnetParams = CreateMainNetParams() // MainnetCurrency is the *types.Currency for mainnet. MainnetCurrency = &types.Currency{ @@ -100,29 +116,19 @@ var ( Decimals: Decimals, } - // Mainnet address encoding magics - MainnetParams.PubKeyHashAddrID = []byte{0} - MainnetParams.ScriptHashAddrID = []byte{5} - MainnetParams.Bech32HRPSegwit = "bc" - // TestnetGenesisBlockIdentifier is the genesis block for testnet. TestnetGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943", } // TestnetParams are the params for testnet. - TestnetParams = &chaincfg.TestNet3Params + TestnetParams = CreateTestNet3Params() // TestnetCurrency is the *types.Currency for testnet. TestnetCurrency = &types.Currency{ Symbol: "tBTC", Decimals: Decimals, } - - // Testnet address encoding magics - TestnetParams.PubKeyHashAddrID = []byte{111} - TestnetParams.ScriptHashAddrID = []byte{196} - TestnetParams.Bech32HRPSegwit = "tb" // OperationTypes are all supported operation.Types. OperationTypes = []string{ From acfe2006f58dff54c42735874fcd17b2e35d3537 Mon Sep 17 00:00:00 2001 From: jagdeep sidhu Date: Wed, 2 Dec 2020 22:43:21 -0800 Subject: [PATCH 3/5] Update types.go --- bitcoin/types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bitcoin/types.go b/bitcoin/types.go index 690f4cfa..d791f8ba 100644 --- a/bitcoin/types.go +++ b/bitcoin/types.go @@ -85,6 +85,7 @@ const ( P2PKHScriptPubkeySize = 25 // P2PKH size ) +// override default mainnet settings with address prefixes func CreateMainNetParams() (*chaincfg.Params) { params := &chaincfg.MainNetParams params.PubKeyHashAddrID = 0 @@ -93,6 +94,7 @@ func CreateMainNetParams() (*chaincfg.Params) { return params } +// override default testnet settings with address prefixes func CreateTestNet3Params() (*chaincfg.Params) { params := &chaincfg.TestNet3Params params.PubKeyHashAddrID = 111 From a38f8c28d57fede7abd746f76157bb92188429d9 Mon Sep 17 00:00:00 2001 From: jagdeep sidhu Date: Wed, 2 Dec 2020 22:47:41 -0800 Subject: [PATCH 4/5] lint fixes --- bitcoin/types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitcoin/types.go b/bitcoin/types.go index d791f8ba..83cd0b24 100644 --- a/bitcoin/types.go +++ b/bitcoin/types.go @@ -85,7 +85,7 @@ const ( P2PKHScriptPubkeySize = 25 // P2PKH size ) -// override default mainnet settings with address prefixes +// CreateMainNetParams is a function to override default mainnet settings with address prefixes func CreateMainNetParams() (*chaincfg.Params) { params := &chaincfg.MainNetParams params.PubKeyHashAddrID = 0 @@ -94,7 +94,7 @@ func CreateMainNetParams() (*chaincfg.Params) { return params } -// override default testnet settings with address prefixes +// CreateTestNet3Params is a function to override default mainnet settings with address prefixes func CreateTestNet3Params() (*chaincfg.Params) { params := &chaincfg.TestNet3Params params.PubKeyHashAddrID = 111 From 649ee8bd543bab120684812e87e6edd2caa0add6 Mon Sep 17 00:00:00 2001 From: jagdeep sidhu Date: Wed, 2 Dec 2020 22:58:05 -0800 Subject: [PATCH 5/5] fix testnet network comment --- bitcoin/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin/types.go b/bitcoin/types.go index 83cd0b24..f87e12ee 100644 --- a/bitcoin/types.go +++ b/bitcoin/types.go @@ -94,7 +94,7 @@ func CreateMainNetParams() (*chaincfg.Params) { return params } -// CreateTestNet3Params is a function to override default mainnet settings with address prefixes +// CreateTestNet3Params is a function to override default testnet settings with address prefixes func CreateTestNet3Params() (*chaincfg.Params) { params := &chaincfg.TestNet3Params params.PubKeyHashAddrID = 111