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

Account Balance Tracking #17

Closed
ejfitzgerald opened this issue Jul 28, 2022 · 2 comments · Fixed by #88 or #105
Closed

Account Balance Tracking #17

ejfitzgerald opened this issue Jul 28, 2022 · 2 comments · Fixed by #88 or #105
Milestone

Comments

@ejfitzgerald
Copy link
Member

ejfitzgerald commented Jul 28, 2022

Acceptance Criteria

To add the ability for a user to query a specific address account balance. For the first version of this task only native balances should be captured.

Below is an illustrative schema for the problem

type NativeBalance {
  amount: BigInt!
  denom: String!
}

type Account @entity {
  address: ID! # might be also String!
  nativeBalances: [NativeBalance!]!
}

Potential strategy

Create updateNativeBalance function:

  1. Function queries database for existing instances of 'Account' with the relevant native transfer address
  2. If no existing entity returned, create new one
  3. Update the balance of the 'Account'
  4. Insert this function to all cases where balances may change in handlers for coin_spent and coin_received events
  5. Iterate to increase coverage of balance changes

Blocked on

@ejfitzgerald ejfitzgerald mentioned this issue Jul 28, 2022
5 tasks
@Jonathansumner Jonathansumner self-assigned this Aug 11, 2022
@bryanchriswhite
Copy link

bryanchriswhite commented Aug 20, 2022

I think we might be able to listen for the coin_spent and coin_received events from the bank module for this.

I did some brief querying to see what kinds of messages correspond to these events and there seems to be a variety. Here's the query I used:

query coinReceivedEvents {
  events(
    first: 10
    filter: {
      type: { equalTo: "coin_received" }
      transaction: {
        messages: {
          some: {
            typeUrl: {
              notIn: [
                "/cosmos.bank.v1beta1.MsgSend"
                "/cosmos.bank.v1beta1.MsgMultiSend"
              ]
            }
          }
        }
      }
    }
  ) {
    nodes {
      #id
      type
      #attributes
      transaction {
        messages {
          nodes {
            typeUrl
            json
          }
        }
      }
    }
  }
}

query coinSpentEvents {
  events(
    first: 10
    filter: {
      type: { equalTo: "coin_spent" }
      transaction: {
        messages: {
          some: {
            typeUrl: {
              notIn: [
                "/cosmos.bank.v1beta1.MsgSend"
                "/cosmos.bank.v1beta1.MsgMultiSend"
              ]
            }
          }
        }
      }
    }
  ) {
    nodes {
      #id
      type
      #attributes
      transaction {
        messages {
          nodes {
            typeUrl
            json
          }
        }
      }
    }
  }
}

@bryanchriswhite bryanchriswhite linked a pull request Aug 29, 2022 that will close this issue
@bryanchriswhite
Copy link

I think we will need to process the genesis for the respective network to get the starting point which we can use together with the accumulated offset to calculate current balances.

@bryanchriswhite bryanchriswhite added this to the v0.2 milestone Sep 8, 2022
@bryanchriswhite bryanchriswhite linked a pull request Sep 12, 2022 that will close this issue
@bryanchriswhite bryanchriswhite linked a pull request Sep 24, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants