darwinia-network / collator-staking-ui-v2

https://collator-staking.ringdao.com/
0 stars 0 forks source link

Graphql Query #1

Open fewensa opened 2 months ago

fewensa commented 2 months ago

hyperindex

Generate key

function genKey(address: string, votes: bigint) {
  const _stdAddr = address.toLowerCase().replace('0x', '');
  const _stdVotes = votes.toString(16).padStart(64, '0');
  return `${_stdVotes}-${_stdAddr}`;
}

Query CollatorSet

query QueryCollatorSet {
  CollatorSet(
    where: {chainId: {_eq: "701"}},
    order_by: {key: desc},
    offset: 0,
    limit: 2
  ) {
    id
    key
  }
}

1st page: {offiset: 0, limit 2} 2nd page: {offset: 2, limit2} 3rd page: {offset: 4, limit 2}

offset = pageNumber * limit - limit

Query previous

query QueryCollatorSet {
  CollatorSet(
    where: {
      chainId: {_eq: "701"}, 
      key: {_gt: "0000000000000000000000000000000000000000000000000000000000000032-f712eea0fc84d94b7f0acc14bb3f248bdb454cf9"}
    }, 
    order_by: {key: asc}, 
    limit: 1) {
    id
    key
  }
}

Query next

query QueryCollatorSet {
  CollatorSet(
    where: {
      chainId: {_eq: "701"}, 
      key: {_lt: "0000000000000000000000000000000000000000000000000000000000000032-f712eea0fc84d94b7f0acc14bb3f248bdb454cf9"}
    }, 
    order_by: {key: desc}, 
    limit: 1) {
    id
    key
  }
}

Query new previous

query QueryCollatorSet {
  CollatorSet(
    limit: 1
    order_by: {key: asc},
    where: {
      chainId: {_eq: "701"}, 
      key: {_gt: "0000000000000000000000000000000000000000000000006124fee993bbfffe-95ec69dd90e4b120c413b209b3a31a5c74a58b76"}, 
      _and: {
        key: {_neq: "000000000000000000000000000000000000000000000007f808e9291e6bffff-95ec69dd90e4b120c413b209b3a31a5c74a58b76"}
      }
    }
  ) {
    id
    key
  }
}

_and.key._neq yourself key key._gt: your new key

Query multiple collatorset

query QueryCollatorSet {
  CollatorSet(order_by: {key: asc}, where: {chainId: {_eq: "701"}, id: {_in: ["0x94F4F04A594FD690e0feA46F2882a5b26153A72F","0x0009388eC547642294Df0656c909f33bfD71d20A","0x0033Bc68281e6E52d7652d884eC207E470DB1d79"]}}) {
    id
    key
  }
}
fewensa commented 2 months ago

thegraph

playground: https://thegraph-g2.darwinia.network/training/subgraphs/name/dip7index-koi-kv/graphql api: https://thegraph-g2.darwinia.network/training/subgraphs/name/dip7index-koi-kv

Generate key

function genKey(address: string, votes: bigint) {
  const _stdAddr = address.toLowerCase().replace('0x', '');
  const _stdVotes = votes.toString(16).padStart(64, '0');
  return `${_stdVotes}-${_stdAddr}`;
}

Query CollatorSet

query QueryCollatorSet {
  collatorSets(orderBy: key, orderDirection: desc, skip: 1, first: 1) {
    address
    assets
    blockNumber
    id
    commission
    inset
    key
    logIndex
    pool
    prev
    reward
    votes
  }
}

1st page: {skip: 0, first: 2} 2nd page: {skip: 2, first: 2} 3rd page: {skip: 4, first: 2}

skip= pageNumber * first- first

Query previous

query QueryuPrevCollator {
  collatorSets(
    orderBy: key
    orderDirection: asc
    first: 1
    where: {key_gt: "0000000000000000000000000000000000000000000000000000000000000032-f712eea0fc84d94b7f0acc14bb3f248bdb454cf9"}
  ) {
    id
    key
  }
}

Query next

query QueryuNextCollator {
  collatorSets(
    orderBy: key
    orderDirection: desc
    first: 1
    where: {key_lt: "0000000000000000000000000000000000000000000000000000000000000032-f712eea0fc84d94b7f0acc14bb3f248bdb454cf9"}
  ) {
    id
    key
  }
}

Query new previous by key

query QueryNewPrevCollator {
  collatorSets(
    orderBy: key
    orderDirection: asc
    first: 1
    where: {
      inset: 1
      key_not: "0000000000000000000000000000000000000000000000000000000000000032-f712eea0fc84d94b7f0acc14bb3f248bdb454cf9"
      key_gt: "0000000000000000000000000000000000000000000000000000000000000032-f712eea0fc84d94b7f0acc14bb3f248bdb454cf9"
  }
  ) {
    id
    key
  }
}

Query new previous by collator

query QueryNewPrevCollator {
  collatorSets(
    orderBy: key
    orderDirection: asc
    first: 1
    where: {
      inset: 1
      id_not: "0xf712eea0fc84d94b7f0acc14bb3f248bdb454cf9"
      key_gt: "0000000000000000000000000000000000000000000000000000000000000032-f712eea0fc84d94b7f0acc14bb3f248bdb454cf9"
  }
  ) {
    id
    key
  }
}

Query multiple collators

query MyQuery {
  collatorSets(where: {id_in: ["0x94f4f04a594fd690e0fea46f2882a5b26153a72f", "0x94f4f04a594fd690e0fea46f2882a5b26153a72f"]}) {
    id
    key
  }
}

Query deployment meta

query MyQuery {
  _meta {
    hasIndexingErrors
    deployment
    block {
      timestamp
      parentHash
      number
      hash
    }
  }
}

Query stakingAccount

query QueryStakingAccounts {
  stakingAccounts(where: {collator: "0x00450cebf0787799dde77daeaffdc317c762e35b"}) {
    pool
    latestChangeTimestamp
    id
    collator
    assets
    account
  }
}

Query stakingAccounts order by change time desc

query MyQuery {
  stakingAccounts(orderBy: latestChangeTimestamp, orderDirection: desc) {
    pool
    latestChangeTimestamp
    id
    collator
    assets
    account
  }
}