From ed317bed05fc3c35e4e526bd117c723f3320fdfd Mon Sep 17 00:00:00 2001 From: kevin <35275952+kaladinlight@users.noreply.github.com> Date: Fri, 19 Jul 2024 13:39:59 -0600 Subject: [PATCH] fix: upgrade globalfee module -> feemarket module (#1010) --- go/cmd/cosmos/main.go | 1 + go/coinstacks/cosmos/api/swagger.json | 259 -------------------------- go/pkg/cosmos/cosmos.go | 3 + go/pkg/cosmos/fees.go | 39 +--- 4 files changed, 13 insertions(+), 289 deletions(-) diff --git a/go/cmd/cosmos/main.go b/go/cmd/cosmos/main.go index 144cc998b..16449d90d 100644 --- a/go/cmd/cosmos/main.go +++ b/go/cmd/cosmos/main.go @@ -54,6 +54,7 @@ func main() { Bech32PkPrefix: "cosmospub", Bech32ValPrefix: "cosmosvaloper", Bech32PkValPrefix: "cosmosvalpub", + Denom: "uatom", Encoding: encoding, APIKEY: conf.APIKEY, GRPCURL: conf.GRPCURL, diff --git a/go/coinstacks/cosmos/api/swagger.json b/go/coinstacks/cosmos/api/swagger.json index 8fb9424e8..29417898e 100644 --- a/go/coinstacks/cosmos/api/swagger.json +++ b/go/coinstacks/cosmos/api/swagger.json @@ -15,161 +15,6 @@ } }, "paths": { - "/": { - "get": { - "tags": [ - "Websocket" - ], - "summary": "Subscribe to pending and confirmed transactions.", - "operationId": "Websocket", - "responses": { - "200": { - "description": "" - } - } - } - }, - "/api/v1/account/{pubkey}": { - "get": { - "tags": [ - "v1" - ], - "summary": "Get account details.", - "operationId": "GetAccount", - "parameters": [ - { - "type": "string", - "x-go-name": "Pubkey", - "description": "Account address or xpub", - "name": "pubkey", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Account", - "schema": { - "$ref": "#/definitions/Account" - } - }, - "400": { - "description": "BadRequestError", - "schema": { - "$ref": "#/definitions/BadRequestError" - } - }, - "500": { - "description": "InternalServerError", - "schema": { - "$ref": "#/definitions/InternalServerError" - } - } - } - } - }, - "/api/v1/account/{pubkey}/txs": { - "get": { - "tags": [ - "v1" - ], - "summary": "Get paginated transaction history.", - "operationId": "GetTxHistory", - "parameters": [ - { - "type": "string", - "x-go-name": "Pubkey", - "description": "Account address or xpub", - "name": "pubkey", - "in": "path", - "required": true - }, - { - "type": "string", - "x-go-name": "Cursor", - "description": "Pagination cursor from previous response or empty string for first page fetch", - "name": "cursor", - "in": "query" - }, - { - "type": "integer", - "format": "int64", - "x-go-name": "PageSize", - "description": "Page size", - "name": "pageSize", - "in": "query" - } - ], - "responses": { - "200": { - "description": "TxHistory", - "schema": { - "$ref": "#/definitions/TxHistory" - } - }, - "400": { - "description": "BadRequestError", - "schema": { - "$ref": "#/definitions/BadRequestError" - } - }, - "500": { - "description": "InternalServerError", - "schema": { - "$ref": "#/definitions/InternalServerError" - } - } - } - } - }, - "/api/v1/gas/estimate": { - "post": { - "tags": [ - "v1" - ], - "summary": "Get the estimated gas cost for a transaction.", - "operationId": "EstimateGas", - "parameters": [ - { - "name": "Body", - "in": "body", - "schema": { - "type": "object", - "required": [ - "rawTx" - ], - "properties": { - "rawTx": { - "description": "Raw transaction", - "type": "string", - "x-go-name": "RawTx" - } - } - } - } - ], - "responses": { - "200": { - "description": "GasAmount", - "schema": { - "$ref": "#/definitions/GasAmount" - } - }, - "400": { - "description": "BadRequestError", - "schema": { - "$ref": "#/definitions/BadRequestError" - } - }, - "500": { - "description": "InternalServerError", - "schema": { - "$ref": "#/definitions/InternalServerError" - } - } - } - } - }, "/api/v1/gas/fees": { "get": { "tags": [ @@ -199,110 +44,6 @@ } } }, - "/api/v1/info": { - "get": { - "tags": [ - "v1" - ], - "summary": "Get information about the running coinstack.", - "operationId": "GetInfo", - "responses": { - "200": { - "description": "Info", - "schema": { - "$ref": "#/definitions/Info" - } - } - } - } - }, - "/api/v1/send": { - "post": { - "tags": [ - "v1" - ], - "summary": "Sends raw transaction to be broadcast to the node.", - "operationId": "SendTx", - "parameters": [ - { - "name": "Body", - "in": "body", - "schema": { - "type": "object", - "required": [ - "rawTx" - ], - "properties": { - "rawTx": { - "description": "Raw transaction", - "type": "string", - "x-go-name": "RawTx" - } - } - } - } - ], - "responses": { - "200": { - "description": "TransactionHash", - "schema": { - "$ref": "#/definitions/TransactionHash" - } - }, - "400": { - "description": "BadRequestError", - "schema": { - "$ref": "#/definitions/BadRequestError" - } - }, - "500": { - "description": "InternalServerError", - "schema": { - "$ref": "#/definitions/InternalServerError" - } - } - } - } - }, - "/api/v1/tx/{txid}": { - "get": { - "tags": [ - "v1" - ], - "summary": "Get transaction details", - "operationId": "GetTx", - "parameters": [ - { - "type": "string", - "x-go-name": "TxID", - "description": "Transaction hash", - "name": "txid", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Tx", - "schema": { - "$ref": "#/definitions/Tx" - } - }, - "400": { - "description": "BadRequestError", - "schema": { - "$ref": "#/definitions/BadRequestError" - } - }, - "500": { - "description": "InternalServerError", - "schema": { - "$ref": "#/definitions/InternalServerError" - } - } - } - } - }, "/api/v1/validators": { "get": { "tags": [ diff --git a/go/pkg/cosmos/cosmos.go b/go/pkg/cosmos/cosmos.go index 3ee81c621..25b860ded 100644 --- a/go/pkg/cosmos/cosmos.go +++ b/go/pkg/cosmos/cosmos.go @@ -42,6 +42,7 @@ type Config struct { Bech32ValPrefix string Bech32PkPrefix string Bech32PkValPrefix string + Denom string Encoding *params.EncodingConfig APIKEY string GRPCURL string @@ -53,6 +54,7 @@ type Config struct { // HTTPClient allows communicating over http type HTTPClient struct { ctx context.Context + denom string encoding *params.EncodingConfig LCD *resty.Client RPC *resty.Client @@ -84,6 +86,7 @@ func NewHTTPClient(conf Config) (*HTTPClient, error) { c := &HTTPClient{ ctx: context.Background(), + denom: conf.Denom, encoding: conf.Encoding, LCD: lcd, RPC: rpc, diff --git a/go/pkg/cosmos/fees.go b/go/pkg/cosmos/fees.go index 51aa2d52b..74475f67e 100644 --- a/go/pkg/cosmos/fees.go +++ b/go/pkg/cosmos/fees.go @@ -1,7 +1,6 @@ package cosmos import ( - "encoding/json" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,21 +11,16 @@ func (c *HTTPClient) GetGlobalMinimumGasPrices() (map[string]sdk.Dec, error) { gasPrices := make(map[string]sdk.Dec) var res struct { - Param struct { - Amount string `json:"subspace"` - Key string `json:"key"` - Value string `json:"value"` - } `json:"param"` + Price struct { + Amount string `json:"amount"` + Denom string `json:"denom"` + } `json:"price"` } e := &ErrorResponse{} - queryParams := map[string]string{ - "subspace": "globalfee", - "key": "MinimumGasPricesParam", - } - - r, err := c.LCD.R().SetResult(&res).SetError(e).SetQueryParams(queryParams).Get("/cosmos/params/v1beta1/params") + url := fmt.Sprintf("/feemarket/v1/gas_price/%s", c.denom) + r, err := c.LCD.R().SetResult(&res).SetError(e).Get(url) if err != nil { return gasPrices, errors.Wrap(err, "failed to get globalfee params") } @@ -35,27 +29,12 @@ func (c *HTTPClient) GetGlobalMinimumGasPrices() (map[string]sdk.Dec, error) { return gasPrices, errors.Errorf("failed to get globalfee params: %s", e.Msg) } - values := []struct { - Denom string `json:"denom"` - Amount string `json:"amount"` - }{} - - err = json.Unmarshal([]byte(res.Param.Value), &values) + amount, err := sdk.NewDecFromStr(res.Price.Amount) if err != nil { - return gasPrices, errors.Wrapf(err, "failed to unmarshal value: %s", res.Param.Value) + return gasPrices, errors.Errorf("failed to handle amount: %s", err) } - for _, value := range values { - coinStr := fmt.Sprintf("%s%s", value.Amount, value.Denom) - - coin, err := sdk.ParseDecCoin(coinStr) - if err != nil { - logger.Errorf("failed to parse dec coin: %s: %v", coinStr, err) - continue - } - - gasPrices[coin.GetDenom()] = coin.Amount - } + gasPrices[res.Price.Denom] = amount return gasPrices, nil }