Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gas price RPC methods #120

Merged
merged 14 commits into from
Nov 28, 2024
Merged

Conversation

jinoosss
Copy link
Member

@jinoosss jinoosss commented Nov 26, 2024

Descriptions

Add an RPC endpoints to get the transaction's gas fee based gas price.

The price of gas provides low, average, and high values for each denomination of the coin.

Gas Price Endpoints

getGasPrice

Retrieve gas information by coin for a block range.

  • Params: If empty, it defaults to a range of 1,000 blocks from the latest block.
    • from block height (number)
    • to block height (number)
  • Response: List results for gas prices with low, average, high, and denom.

Example request:

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "getGasPrice",
  "params": [100, 200] // If parameters are empty, the default is latest 1,000 blocks
}

Example response:

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "low": 40000,
            "average": 50000,
            "high": 70000,
            "denom": "ugnot"
        }
    ]
}

subscribe

  • newGasPrice - fires a notification whenever a block with a new transaction is added to the chain.

Example request (over WS):

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "subscribe",
  "params": [
    "newGasPrice"
  ]
}

Example response when a newGasPrice event happens (over WS):

{
    "params": {
        "result": [
            {
                "low": 70000,
                "average": 70000,
                "high": 70000,
                "denom": "ugnot"
            }
        ],
        "subscription": "eb654246-a1c4-4ef2-9d99-42e1308ee68f"
    },
    "jsonrpc": "2.0",
    "method": "subscription"
}

Related Issue

@jinoosss jinoosss marked this pull request as ready for review November 27, 2024 05:33
@Kouteki Kouteki added the in focus Core team is actively working on this label Nov 27, 2024
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 💯

I've left a few comments 🙏

serve/handlers/gas/gas.go Outdated Show resolved Hide resolved
serve/methods/gas.go Outdated Show resolved Hide resolved
serve/methods/gas.go Outdated Show resolved Hide resolved
@zivkovicmilos zivkovicmilos merged commit 652dcd5 into main Nov 28, 2024
4 checks passed
@zivkovicmilos zivkovicmilos deleted the feat/add-gas-price-rpc-methods branch November 28, 2024 10:14
@Kouteki Kouteki removed the in focus Core team is actively working on this label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants