fees.go


Overview

The [fees.go](/projects/291/69231) file is part of the `cosmos` package and provides functionality for retrieving minimum gas price information from a Cosmos SDK-based blockchain network. It interacts with the blockchain's REST API (LCD - Light Client Daemon) to fetch two types of gas prices:

This information is crucial for clients constructing transactions to ensure their fees meet the minimum network requirements to be accepted and processed.


Detailed Description of Functions

1. GetGlobalMinimumGasPrices

func (c *HTTPClient) GetGlobalMinimumGasPrices() (map[string]sdkmath.LegacyDec, error)

Purpose

Fetches the global minimum gas prices from the feemarket module of the blockchain by querying the LCD endpoint `/feemarket/v1/gas_price/{denom}`.

Parameters

Returns

Description

Usage Example

client := &cosmos.HTTPClient{denom: "uatom", /* ... other fields ... */}
gasPrices, err := client.GetGlobalMinimumGasPrices()
if err != nil {
    log.Fatalf("Error fetching global gas prices: %v", err)
}
fmt.Println("Global Minimum Gas Prices:", gasPrices)

2. GetLocalMinimumGasPrices

func (c *HTTPClient) GetLocalMinimumGasPrices() (map[string]sdkmath.LegacyDec, error)

Purpose

Retrieves the local node's configured minimum gas prices from the node's base configuration endpoint `/cosmos/base/node/v1beta1/config`.

Parameters

Returns

Description

Usage Example

client := &cosmos.HTTPClient{ /* ... */ }
localGasPrices, err := client.GetLocalMinimumGasPrices()
if err != nil {
    log.Fatalf("Error fetching local gas prices: %v", err)
}
fmt.Println("Local Minimum Gas Prices:", localGasPrices)

Important Implementation Details


Interaction with Other System Components

This file is likely used by higher-level modules responsible for transaction creation, fee estimation, and validation to ensure transactions include appropriate fees.


Mermaid Diagram: Flowchart of Main Functions and Their Relationships

flowchart TD
    A[HTTPClient] --> B[GetGlobalMinimumGasPrices]
    A --> C[GetLocalMinimumGasPrices]

    B --> D{HTTP GET /feemarket/v1/gas_price/{denom}}
    D --> E[Parse JSON response]
    E --> F[Convert amount to LegacyDec]
    F --> G[Return map[denom]LegacyDec]

    C --> H{HTTP GET /cosmos/base/node/v1beta1/config}
    H --> I[Parse JSON response]
    I --> J[Parse minimum_gas_price string to DecCoins]
    J --> K[Build map[denom]LegacyDec]
    K --> L[Return gas prices map]

    subgraph ErrorHandling
        D -- On failure --> M[Return error]
        H -- On failure --> M
        E -- On failure --> M
        I -- On failure --> M
        F -- On failure --> M
        J -- On failure --> M
    end

Summary

The [fees.go](/projects/291/69231) file provides essential utilities for querying minimum gas price information from a Cosmos SDK blockchain's REST API. It exposes two primary methods for retrieving global and local gas price configurations, handling all necessary API interactions, JSON unmarshalling, and error handling internally. This functionality supports fee management in transaction processing workflows, ensuring clients can dynamically adjust to network fee requirements.


If you require further details about the `HTTPClient` struct or `ErrorResponse` type, please refer to their respective source files in the `cosmos` package.