cardano-foundation / cardano-graphql

GraphQL API for Cardano
Apache License 2.0
263 stars 104 forks source link

How to watch for staking rewards event? #829

Open jasoncsli opened 1 year ago

jasoncsli commented 1 year ago

Ask a question

I would like to index all rewards into my database. From my previous experience in Solana, staking rewards have been sent in the block. So I just listen to block-creation and loop through all rewards in this block, and then save them in my database. How could I do by cardano-graphql? I can't find the staking rewards of a block by block query. I do find rewards fields in slot leader field and epoch field of block query, but I think they have rewards are not in current epochs (or not in current block).

  1. How could I get reward event in real time ? Once the staking reward has been sent to address in the new block, I need to save it in my db too.

  2. query {
    rewards(where: { receivedIn: { number: {_eq: 142}} } ) {
        address
        amount
        type
        earnedIn {
            number
        }
        receivedIn {
            number
        }
    }
    }

This is a way to find all rewards in the epoch. For example, if current epoch is 142, when is the accounts receives the staking rewards in epoch 142? In Solana, it is first block(slot) in the epoch.