Gauss Docs
  • 🌐Getting Started
    • Welcome to Gauss
    • Whitepaper
      • Blockchain Providers Need to Do Better
        • Solving a Lack of Token Adoption
          • An Evolving Space With Untapped Potential
        • Security & Reliability
          • Curation & Vetting
            • Important Note For Brands
        • Token Creation
      • WHY BUILD WITH GAUSS?
      • Use Cases
        • Use Cases (Chart)
      • Roadmap
      • Technical Background and Blockchain Development
        • Why Another Blockchain?
        • Gauss 1.0: Built With Efficiency and a Strong Infrastructure to Launch Rapidly
        • Gauss 2.0: Added Functionality For a Better User Experiance
          • Noble Swap 2.0
          • NFTs in Gauss 2.0
          • Token Development Kit (TDK)
          • Gaming DAO
          • Omnipool
      • Token Economics
        • Gang Token Economics: Designed to Ensure Trust and Transparency
        • Token Locking Schedule
        • Reflections: Rewarding the Gauss Community
        • Charitable Allocations: Grants, Scholarships, & Financial Assistance
      • The Gauss Team
      • Important Definitions
      • DISCLAIMER
        • PURCHASER WARNING
        • PROMINENT STATEMENTS
        • FUTURE STATEMENTS
        • VALUE RISKS
        • NOT A SECURITY
    • How To Connect
      • Create Metamask Wallet
    • Links
  • ⚡Launching with Gauss
    • Benefits of Building with Gauss
      • Fostering an Environment for Success
      • Gauss Growth Grant Program
      • Gauss Liquidity Program
      • Ecosystem Integrity Fund
      • Client Referral Program
    • A Guide to Curation
      • Core Principles and Curation Guidelines
      • Curation Stages and Processing Fees
    • Building on Gauss
  • 🖥️Gauss Ecosystem
    • Gauss Chain
      • Polygon-Edge Overview
      • Architecture
      • Consensus
      • Client Modules
        • Blockchain
        • Minimal
        • Networking
        • State
        • TxPool
        • JSON RPC
        • Consensus
        • Storage
        • Types
        • Syncer
        • Sealer
        • Other Modules
      • Polygon-Edge Performance Reports
      • For Developers
        • Operate a Node
          • Local Install
          • Genesis Contract
          • Server Config
          • CLI Commands
          • Key Management
        • Run a Validator
          • Validator FAQ
        • Smart Contract Deployment Permissioning
        • Deploying Contracts
          • Remix
          • Truffle
          • Hardhat
          • Replit
    • Gauss Explorer
      • Features
      • Navigating the Explorer
        • Menus
        • Blocks
        • Transactions
      • Verifying a Smart Contract
        • Hardhat Plugin
        • Sourcify Plugin
        • OpenZeppelin Plugin
      • Interacting With Smart Contracts
      • Exporting Transactions
      • FAQ
      • For Developers
        • Gauss Explorer Dependencies
        • Deployment Guide
          • Smart Contract Verification
          • Cleaning an instance from the previous deployment
          • ENV Variables
          • Testing
        • APIs
          • Requests & Limits
          • GraphQL
          • ETH RPC
    • Noble Swap
      • Liquidity Boost Program
    • Tokens
    • Gauss NFTs
      • Ferro Cards
      • F.E.R.R.E.T. NFTs
    • Contests & Giveaways
    • Gauss Faucet
      • For Developers
    • Address List
  • 💡Additional Resources
    • Partnerships & Affiliates
    • Discord Channel
    • Contact Us
    • Learning Materials
      • Web3 Glossary
    • Media Kit
Powered by GitBook
On this page
  • Overview​
  • Blockchain Interface​
  • ETH Endpoints​
  • Filter Manager​
  • 📜 Resources​
  1. Gauss Ecosystem
  2. Gauss Chain
  3. Client Modules

JSON RPC

PreviousTxPoolNextConsensus

Last updated 2 years ago

Overview

The JSON RPC module implements the JSON RPC API layer, something that dApp developers use to interact with the blockchain.

It includes support for standard , as well as websocket endpoints.

Blockchain Interface

The Polygon Edge uses the blockchain interface to define all the methods that the JSON RPC module needs to use, in order to deliver its endpoints.

The blockchain interface is implemented by the server. It is the base implementation that's passed into the JSON RPC layer.

jsonrpc/blockchain.go

type blockchainInterface interface {
    // Header returns the current header of the chain (genesis if empty)
    Header() *types.Header

    // GetReceiptsByHash returns the receipts for a hash
    GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, error)

    // Subscribe subscribes for chain head events
    SubscribeEvents() blockchain.Subscription

    // GetHeaderByNumber returns the header by number
    GetHeaderByNumber(block uint64) (*types.Header, bool)

    // GetAvgGasPrice returns the average gas price
    GetAvgGasPrice() *big.Int

    // AddTx adds a new transaction to the tx pool
    AddTx(tx *types.Transaction) error

    // State returns a reference to the state
    State() state.State

    // BeginTxn starts a transition object
    BeginTxn(parentRoot types.Hash, header *types.Header) (*state.Transition, error)

    // GetBlockByHash gets a block using the provided hash
    GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool)

    // ApplyTxn applies a transaction object to the blockchain
    ApplyTxn(header *types.Header, txn *types.Transaction) ([]byte, bool, error)

    stateHelperInterface
}

All the standard JSON RPC endpoints are implemented in:

jsonrpc/eth_endpoint.go

The Filter Manager is a service that runs alongside the JSON RPC server.

It provides support for filtering blocks on the blockchain. Specifically, it includes both a log and a block level filter.

jsonrpc/filter_manager.go

type Filter struct {
    id string

    // block filter
    block *headElem

    // log cache
    logs []*Log

    // log filter
    logFilter *LogFilter

    // index of the filter in the timer array
    index int

    // next time to timeout
    timestamp time.Time

    // websocket connection
    ws wsConn
}


type FilterManager struct {
    logger hclog.Logger

    store   blockchainInterface
    closeCh chan struct{}

    subscription blockchain.Subscription

    filters map[string]*Filter
    lock    sync.Mutex

    updateCh chan struct{}
    timer    timeHeapImpl
    timeout  time.Duration

    blockStream *blockStream
}

Filter Manager events get dispatched in the Run method:

jsonrpc/filter_manager.go

func (f *FilterManager) Run() {

    // watch for new events in the blockchain
    watchCh := make(chan *blockchain.Event)
    go func() {
        for {
            evnt := f.subscription.GetEvent()
            if evnt == nil {
                return
            }
            watchCh <- evnt
        }
    }()

    var timeoutCh <-chan time.Time
    for {
        // check for the next filter to be removed
        filter := f.nextTimeoutFilter()
        if filter == nil {
            timeoutCh = nil
        } else {
            timeoutCh = time.After(filter.timestamp.Sub(time.Now()))
        }

        select {
        case evnt := <-watchCh:
            // new blockchain event
            if err := f.dispatchEvent(evnt); err != nil {
                f.logger.Error("failed to dispatch event", "err", err)
            }

        case <-timeoutCh:
            // timeout for filter
            if !f.Uninstall(filter.id) {
                f.logger.Error("failed to uninstall filter", "id", filter.id)
            }

        case <-f.updateCh:
            // there is a new filter, reset the loop to start the timeout timer

        case <-f.closeCh:
            // stop the filter manager
            return
        }
    }
}

ETH Endpoints

Filter Manager

The Filter Manager relies heavily on Subscription Events, mentioned in the section

📜 Resources

🖥️
​
json-rpc endpoints
​
Minimal
​
​
Blockchain
​
Ethereum JSON-RPC