Skip to content

Commit

Permalink
fix: upgrade globalfee module -> feemarket module (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight committed Dec 13, 2024
1 parent d717ae1 commit ed317be
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 289 deletions.
1 change: 1 addition & 0 deletions go/cmd/cosmos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func main() {
Bech32PkPrefix: "cosmospub",
Bech32ValPrefix: "cosmosvaloper",
Bech32PkValPrefix: "cosmosvalpub",
Denom: "uatom",
Encoding: encoding,
APIKEY: conf.APIKEY,
GRPCURL: conf.GRPCURL,
Expand Down
259 changes: 0 additions & 259 deletions go/coinstacks/cosmos/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions go/pkg/cosmos/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Config struct {
Bech32ValPrefix string
Bech32PkPrefix string
Bech32PkValPrefix string
Denom string
Encoding *params.EncodingConfig
APIKEY string
GRPCURL string
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
39 changes: 9 additions & 30 deletions go/pkg/cosmos/fees.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cosmos

import (
"encoding/json"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -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")
}
Expand All @@ -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
}
Expand Down

0 comments on commit ed317be

Please sign in to comment.