From 57beb903974ec49eef89989a973d4f1da51aed79 Mon Sep 17 00:00:00 2001 From: tj327 Date: Tue, 12 Sep 2023 11:31:43 +1000 Subject: [PATCH 1/2] implementing custom denom & addr prefixes --- RELEASE.md | 4 +- common/gateway.go | 2 +- config/constants.go | 2 +- config/load.go | 187 +++++++++++++++++++++++++++++++++----------- gateway/main.go | 1 + go.mod | 2 +- go.sum | 4 +- 7 files changed, 151 insertions(+), 51 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 05b9a6c..4a99608 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,5 @@ Features: -* Fix staking-pool endpoint and valoper endpoint issues -* Fix identity record querying issues +* Implement custom denom and bech32 prefix +* Bump sekai version to v0.3.29 diff --git a/common/gateway.go b/common/gateway.go index e730462..69c7155 100644 --- a/common/gateway.go +++ b/common/gateway.go @@ -304,7 +304,7 @@ func WrapResponse(w http.ResponseWriter, request types.InterxRequest, response t } } -// ServeGRPC is a function to server GRPC +// ServeGRPC is a function to serve GRPC func ServeGRPC(r *http.Request, gwCosmosmux *runtime.ServeMux) (interface{}, interface{}, int) { recorder := httptest.NewRecorder() gwCosmosmux.ServeHTTP(recorder, r) diff --git a/config/constants.go b/config/constants.go index ba33dbb..bb4fdcf 100755 --- a/config/constants.go +++ b/config/constants.go @@ -2,7 +2,7 @@ package config const ( InterxVersion = "v0.4.38" - SekaiVersion = "v0.3.27" + SekaiVersion = "v0.3.29" CosmosVersion = "v0.45.10" QueryDashboard = "/api/dashboard" diff --git a/config/load.go b/config/load.go index 4c35e90..bcd7be5 100644 --- a/config/load.go +++ b/config/load.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "io/ioutil" + "net/http" + "net/http/httptest" "os" "strings" @@ -13,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" bytesize "github.com/inhies/go-bytesize" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/sr25519" @@ -59,12 +62,54 @@ func LoadMnemonic(mnemonic string) string { return TrimMnemonic(mnemonicFromFile(mnemonic)) } -// LoadConfig is a function to load interx configurations from a given file -func LoadConfig(configFilePath string) { - sekaiappparams.SetConfig() +// serveGRPC is a function to serve GRPC +func serveGRPC(r *http.Request, gwCosmosmux *runtime.ServeMux) (interface{}, interface{}, int) { + recorder := httptest.NewRecorder() + gwCosmosmux.ServeHTTP(recorder, r) + resp := recorder.Result() - Config = InterxConfig{} + result := new(interface{}) + if json.NewDecoder(resp.Body).Decode(result) == nil { + if resp.StatusCode == http.StatusOK { + return result, nil, resp.StatusCode + } + + return nil, result, resp.StatusCode + } + + return nil, nil, resp.StatusCode +} + +// LoadAddressAndDenom is a function to load addresses and migrate config using custom bech32 and denom prefixes +func LoadAddressAndDenom(configFilePath string, gwCosmosmux *runtime.ServeMux, rpcAddr string, gatewayAddr string) { + request, _ := http.NewRequest("GET", "http://"+gatewayAddr+"/kira/gov/custom_prefixes", nil) + response, failure, _ := serveGRPC(request, gwCosmosmux) + + if response == nil { + panic(failure) + } + + byteData, err := json.Marshal(response) + if err != nil { + panic(err) + } + result := map[string]string{} + err = json.Unmarshal(byteData, &result) + if err != nil { + panic(err) + } + + bech32Prefix := result["bech32Prefix"] + defaultDenom := result["defaultDenom"] + sekaiappparams.DefaultDenom = defaultDenom + sekaiappparams.AccountAddressPrefix = bech32Prefix + sekaiappparams.AccountPubKeyPrefix = bech32Prefix + "pub" + sekaiappparams.ValidatorAddressPrefix = bech32Prefix + "valoper" + sekaiappparams.ValidatorPubKeyPrefix = bech32Prefix + "valoperpub" + sekaiappparams.ConsNodeAddressPrefix = bech32Prefix + "valcons" + sekaiappparams.ConsNodePubKeyPrefix = bech32Prefix + "valconspub" + sekaiappparams.SetConfig() file, err := ioutil.ReadFile(configFilePath) if err != nil { fmt.Println("Invalid configuration: {}", err) @@ -79,21 +124,8 @@ func LoadConfig(configFilePath string) { panic(err) } - // Interx Main Configuration - Config.InterxVersion = InterxVersion - Config.ServeHTTPS = configFromFile.ServeHTTPS - Config.GRPC = configFromFile.GRPC - Config.RPC = configFromFile.RPC - Config.PORT = configFromFile.PORT + //=============== interx address =============== Config.Mnemonic = LoadMnemonic(configFromFile.MnemonicFile) - - Config.Node = configFromFile.Node - - fmt.Println("Interx Version: ", Config.InterxVersion) - fmt.Println("Interx GRPC: ", Config.GRPC) - fmt.Println("Interx RPC : ", Config.RPC) - fmt.Println("Interx PORT: ", Config.PORT) - if !bip39.IsMnemonicValid(Config.Mnemonic) { fmt.Println("Invalid Interx Mnemonic: ", Config.Mnemonic) panic("Invalid Interx Mnemonic") @@ -113,40 +145,33 @@ func LoadConfig(configFilePath string) { Config.PubKey = Config.PrivKey.PubKey() Config.Address = sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), Config.PubKey.Address()) - Config.AddrBooks = strings.Split(configFromFile.AddrBooks, ",") - Config.NodeKey, err = p2p.LoadOrGenNodeKey(configFromFile.NodeKey) - if err != nil { - panic(err) - } - - Config.TxModes = strings.Split(configFromFile.TxModes, ",") - if len(Config.TxModes) == 0 { - Config.TxModes = strings.Split("sync,async,block", ",") - } - // Display mnemonic and keys - // fmt.Println("Interx Mnemonic : ", Config.Mnemonic) fmt.Println("Interx Address : ", Config.Address) fmt.Println("Interx Public Key: ", Config.PubKey.String()) - Config.NodeDiscovery = configFromFile.NodeDiscovery + //=============== faucet address =============== - Config.Block.StatusSync = configFromFile.Block.StatusSync - Config.Block.HaltedAvgBlockTimes = configFromFile.Block.HaltedAvgBlockTimes + amount, found := configFromFile.Faucet.FaucetAmounts["ukex"] + if found { + configFromFile.Faucet.FaucetAmounts[defaultDenom] = amount + delete(configFromFile.Faucet.FaucetAmounts, "ukex") + } - Config.Cache.CacheDir = configFromFile.Cache.CacheDir - Config.Cache.MaxCacheSize = parseSizeString(configFromFile.Cache.MaxCacheSize) - Config.Cache.CachingDuration = configFromFile.Cache.CachingDuration - Config.Cache.DownloadFileSizeLimitation = parseSizeString(configFromFile.Cache.DownloadFileSizeLimitation) + amount, found = configFromFile.Faucet.FaucetMinimumAmounts["ukex"] + if found { + configFromFile.Faucet.FaucetMinimumAmounts[defaultDenom] = amount + delete(configFromFile.Faucet.FaucetMinimumAmounts, "ukex") + } - // Display cache configurations - fmt.Println("Interx Block StatusSync : ", Config.Block.StatusSync) - fmt.Println("Halted Avg Block Times : ", Config.Block.HaltedAvgBlockTimes) + amount, found = configFromFile.Faucet.FeeAmounts["ukex"] + if found { + configFromFile.Faucet.FeeAmounts[defaultDenom] = amount + delete(configFromFile.Faucet.FeeAmounts, "ukex") + } - fmt.Println("Interx Cache CacheDir : ", Config.Cache.CacheDir) - fmt.Println("Interx Cache MaxCacheSize : ", Config.Cache.MaxCacheSize) - fmt.Println("Interx Cache CachingDuration : ", Config.Cache.CachingDuration) - fmt.Println("Interx Cache DownloadFileSizeLimitation: ", Config.Cache.DownloadFileSizeLimitation) + for denom, coinStr := range configFromFile.Faucet.FeeAmounts { + configFromFile.Faucet.FeeAmounts[denom] = strings.ReplaceAll(coinStr, "ukex", defaultDenom) + } // Faucet Configuration Config.Faucet = FaucetConfig{ @@ -186,6 +211,80 @@ func LoadConfig(configFilePath string) { fmt.Println("Interx Faucet FeeAmounts : ", Config.Faucet.FeeAmounts) fmt.Println("Interx Faucet TimeLimit : ", Config.Faucet.TimeLimit) + // save denom changes to config + bytes, err := json.MarshalIndent(&configFromFile, "", " ") + if err != nil { + panic(err) + } + + err = ioutil.WriteFile(configFilePath, bytes, 0644) + if err != nil { + panic(err) + } +} + +// LoadConfig is a function to load interx configurations from a given file +func LoadConfig(configFilePath string) { + Config = InterxConfig{} + + file, err := ioutil.ReadFile(configFilePath) + if err != nil { + fmt.Println("Invalid configuration: {}", err) + panic(err) + } + + configFromFile := InterxConfigFromFile{} + + err = json.Unmarshal([]byte(file), &configFromFile) + if err != nil { + fmt.Println("Invalid configuration: {}", err) + panic(err) + } + + // Interx Main Configuration + Config.InterxVersion = InterxVersion + Config.ServeHTTPS = configFromFile.ServeHTTPS + Config.GRPC = configFromFile.GRPC + Config.RPC = configFromFile.RPC + Config.PORT = configFromFile.PORT + + Config.Node = configFromFile.Node + + fmt.Println("Interx Version: ", Config.InterxVersion) + fmt.Println("Interx GRPC: ", Config.GRPC) + fmt.Println("Interx RPC : ", Config.RPC) + fmt.Println("Interx PORT: ", Config.PORT) + + Config.AddrBooks = strings.Split(configFromFile.AddrBooks, ",") + Config.NodeKey, err = p2p.LoadOrGenNodeKey(configFromFile.NodeKey) + if err != nil { + panic(err) + } + + Config.TxModes = strings.Split(configFromFile.TxModes, ",") + if len(Config.TxModes) == 0 { + Config.TxModes = strings.Split("sync,async,block", ",") + } + + Config.NodeDiscovery = configFromFile.NodeDiscovery + + Config.Block.StatusSync = configFromFile.Block.StatusSync + Config.Block.HaltedAvgBlockTimes = configFromFile.Block.HaltedAvgBlockTimes + + Config.Cache.CacheDir = configFromFile.Cache.CacheDir + Config.Cache.MaxCacheSize = parseSizeString(configFromFile.Cache.MaxCacheSize) + Config.Cache.CachingDuration = configFromFile.Cache.CachingDuration + Config.Cache.DownloadFileSizeLimitation = parseSizeString(configFromFile.Cache.DownloadFileSizeLimitation) + + // Display cache configurations + fmt.Println("Interx Block StatusSync : ", Config.Block.StatusSync) + fmt.Println("Halted Avg Block Times : ", Config.Block.HaltedAvgBlockTimes) + + fmt.Println("Interx Cache CacheDir : ", Config.Cache.CacheDir) + fmt.Println("Interx Cache MaxCacheSize : ", Config.Cache.MaxCacheSize) + fmt.Println("Interx Cache CachingDuration : ", Config.Cache.CachingDuration) + fmt.Println("Interx Cache DownloadFileSizeLimitation: ", Config.Cache.DownloadFileSizeLimitation) + // RPC Configuration Config.RPCMethods = getRPCSettings() diff --git a/gateway/main.go b/gateway/main.go index 2d299de..f9449b0 100644 --- a/gateway/main.go +++ b/gateway/main.go @@ -166,6 +166,7 @@ func Run(configFilePath string, log grpclog.LoggerV2) error { Handler: c.Handler(router), } + config.LoadAddressAndDenom(configFilePath, gwCosmosmux, rpcAddr, gatewayAddr) tasks.RunTasks(gwCosmosmux, rpcAddr, gatewayAddr) if serveHTTPS { diff --git a/go.mod b/go.mod index f223d71..4daa7a5 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/KeisukeYamashita/go-jsonrpc v1.0.1 - github.com/KiraCore/sekai v0.3.27 + github.com/KiraCore/sekai v0.3.29 github.com/btcsuite/btcd v0.22.1 github.com/cosmos/cosmos-sdk v0.45.10 github.com/cosmos/go-bip39 v1.0.0 diff --git a/go.sum b/go.sum index d55707b..9b4134f 100644 --- a/go.sum +++ b/go.sum @@ -172,8 +172,8 @@ github.com/HdrHistogram/hdrhistogram-go v1.1.0/go.mod h1:yDgFjdqOqDEKOvasDdhWNXY github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= github.com/KeisukeYamashita/go-jsonrpc v1.0.1 h1:mkg8th2I7C1y3tnAsxroQbmQcXEZ22AkQ5pazRd/KDM= github.com/KeisukeYamashita/go-jsonrpc v1.0.1/go.mod h1:NyiYd1oDwaSsIflCju5dKRvLdG5rZ/I4E07ygRYYmgc= -github.com/KiraCore/sekai v0.3.27 h1:5rdlMrl4ZFNab8F+U5rJADYy5R598ustnx85AHthlpw= -github.com/KiraCore/sekai v0.3.27/go.mod h1:qQG8mK2ybhKqa6DW+btiUni4qN8OQTa5eoL49HZcNHg= +github.com/KiraCore/sekai v0.3.29 h1:m08pcagGw7vFHOP7VfF+elBu632Z8/jItp1IznOQpaw= +github.com/KiraCore/sekai v0.3.29/go.mod h1:qQG8mK2ybhKqa6DW+btiUni4qN8OQTa5eoL49HZcNHg= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= From 4a76503f60c3602a98c36814856783fd8e521810 Mon Sep 17 00:00:00 2001 From: tj327 Date: Tue, 12 Sep 2023 11:33:35 +1000 Subject: [PATCH 2/2] update interx version --- config/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/constants.go b/config/constants.go index bb4fdcf..979cf13 100755 --- a/config/constants.go +++ b/config/constants.go @@ -1,7 +1,7 @@ package config const ( - InterxVersion = "v0.4.38" + InterxVersion = "v0.4.39" SekaiVersion = "v0.3.29" CosmosVersion = "v0.45.10"