DigiOracle Docs v1.0.1
  • 📔KlayOracle Documentation
  • Fundamentals
    • Introduction
    • Architecture
    • Aggregation Mechanism
    • Node & data provider communication
    • Installing KlayOracle
  • Smart Contract Developers
    • Price Feeds
      • Quick Start: Code Samples
      • How to Use KlayOracle Price Feeds
    • Random Number Generator
      • Quick Start: Code Samples
      • How to Use KlayOracle Random Number Generator
  • Data Providers
    • Introduction
    • Install & run data providers locally
    • How It Works
      • Configuring Data Feeds
      • Reducers
      • Data provider utilities
      • Configuration Files & Environmental Variables
      • OracleProvider Contract
      • Bootstrap Data Providers
    • Best Practices
  • Nodes
    • Introduction
    • Install & run node locally
  • Community
    • DigiOracle Champion Program
      • About the DigiOracle Champion Program
      • How to create content & become a DigiOracle Champion
      • Contribution Guidelines
      • FAQs
    • Bounties
Powered by GitBook
On this page
  1. Data Providers
  2. How It Works

Reducers

In functional programming, a reducer takes your previous state object and an action and returns the updated state.

In KlayOracle, when data sources return responses to the data provider, the data could be returned in different formats: an array, an object, or an array of objects. The reducer is a function that is run on this data, manipulates it, and which in itself returns a response.

In KlayOracle’s data provider feeds, reducers are written as an array of objects, where each defined reducer acts on the response returned by the previous reducer. For example, where we have:

"reducers":[
    {
      "function":"PARSE",
      "args":["$.RAW.KLAY.USD.PRICE"]
    },
    {
      "function":"FLOAT64_MUL_UINT64",
      "args":[
        "1000000000"
      ]
    }
  ],

The PARSE function is run on the data source’s JSON response, returns a response, and then the FLOAT64_MUL_UINT64 is then run on PARSE’s response.

<aside> 💡 For price feeds, PARSE must be the first reducer run on the JSON response from the data source. Its output must be a single value of type: integer, float, string of float, string of integer

</aside>

There are 6 defined reducers in KlayOracle’s data providers:

  • PARSE:

  • FLOAT64_MUL_UINT64

  • …

<aside> 💡 It is highly recommended that the final reducer object returns an unsigned integer, since this data is sent to the blockchain via the oracle contract, and the EVM only accepts positive integer values.

</aside>

<aside> 💡 The data subscriber should be informed of the data type that will be returned, so they know how to convert the data before passing it to their smart contract.

</aside>

PreviousConfiguring Data FeedsNextData provider utilities

Last updated 2 years ago