pubHash := crypto.Ripemd160(derivedPK)
// TODO: pass different params due to config
- address, err := common.NewAddressWitnessPubKeyHash(pubHash, consensus.ActiveNetParams)
+ address, err := common.NewAddressWitnessPubKeyHash(pubHash, &consensus.ActiveNetParams)
if err != nil {
return nil, err
}
scriptHash := crypto.Sha256(signScript)
// TODO: pass different params due to config
- address, err := common.NewAddressWitnessScriptHash(scriptHash, consensus.ActiveNetParams)
+ address, err := common.NewAddressWitnessScriptHash(scriptHash, &consensus.ActiveNetParams)
if err != nil {
return nil, err
}
return txInput, sigInst, nil
}
- address, err := common.DecodeAddress(u.Address, consensus.ActiveNetParams)
+ address, err := common.DecodeAddress(u.Address, &consensus.ActiveNetParams)
if err != nil {
return nil, nil, err
}
Vaild: false,
IsLocal: false,
}
- address, err := common.DecodeAddress(ins.Address, consensus.ActiveNetParams)
+ address, err := common.DecodeAddress(ins.Address, &consensus.ActiveNetParams)
if err != nil {
return NewSuccessResponse(resp)
}
return MissingFieldsError(missing...)
}
- address, err := common.DecodeAddress(a.Address, consensus.ActiveNetParams)
+ address, err := common.DecodeAddress(a.Address, &consensus.ActiveNetParams)
if err != nil {
return err
}
Bech32HRPSegwit string
}
-var ActiveNetParams = &MainNetParams
+var ActiveNetParams = MainNetParams
+
+// NetParams is the correspondence between chain_id and Params
+var NetParams = map[string]Params{
+ "mainnet": MainNetParams,
+ "testnet": TestNetParams,
+}
// MainNetParams is the config for production
var MainNetParams = Params{
func NewNode(config *cfg.Config) *Node {
ctx := context.Background()
- if config.ChainID == "testnet" {
- consensus.ActiveNetParams = &consensus.TestNetParams
- }
+ initActiveNetParams(config)
// Get store
txDB := dbm.NewDB("txdb", config.DBBackend, config.DBDir())
store := leveldb.NewStore(txDB)
return node
}
+func initActiveNetParams(config *cfg.Config) {
+ var exist bool
+ consensus.ActiveNetParams, exist = consensus.NetParams[config.ChainID]
+ if !exist {
+ cmn.Exit(cmn.Fmt("chain_id[%v] don't exist", config.ChainID))
+ }
+}
+
func initOrRecoverAccount(hsm *pseudohsm.HSM, wallet *w.Wallet) error {
xpubs := hsm.ListKeys()
}
func buildP2PKHAddress(pubHash []byte) string {
- address, err := common.NewAddressWitnessPubKeyHash(pubHash, consensus.ActiveNetParams)
+ address, err := common.NewAddressWitnessPubKeyHash(pubHash, &consensus.ActiveNetParams)
if err != nil {
return ""
}
}
func buildP2SHAddress(scriptHash []byte) string {
- address, err := common.NewAddressWitnessScriptHash(scriptHash, consensus.ActiveNetParams)
+ address, err := common.NewAddressWitnessScriptHash(scriptHash, &consensus.ActiveNetParams)
if err != nil {
return ""
}