Skip to content

Instantly share code, notes, and snippets.

@TrevorBenson
Last active January 15, 2021 14:49
Show Gist options
  • Save TrevorBenson/575206f357fab9f2a58c337856c40db3 to your computer and use it in GitHub Desktop.
Save TrevorBenson/575206f357fab9f2a58c337856c40db3 to your computer and use it in GitHub Desktop.
What db-sync queries I would like to see.
Quantity of current valid pools
Get the stake distribution for a specified pool, for [a given epoch | any epoch | >= or <= epoch]
Get the number of blocks created by a specified pool, for [a given epoch | any epoch | <= or >= epoch]
Get the number of blocks created by a specified pool for every epoch
Get the delegation history for a specified wallet
Get the reward history for a specified wallet
@rcmorano
Copy link

rcmorano commented Dec 28, 2020

I've put some functions in place on my deploys so these can be easily retrieved (just used the well known for you cardano-db-sync queries as reference :)

# If you perform a plain GET instead of the HEAD, it returns some info about the pools
curl -sI -H 'Prefer: count=estimate' "https://postgrest-api.mainnet.dandelion.link/rpc/get_valid_pools" | \
  grep -i ^content-range | \
  sed 's|\(content-range: .*\)-\(.*\)/\(.*\)|\2|'
# If no params are provided, returns latest epoch stake distribution for every pool
POOL_ID=4c16a640f689a29dcf427934aa0951d34f8cacb2d08187aef34b1f9b
POOL_BECH32=$(echo ${POOL_ID} | bech32 pool)
EPOCH=104
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_stake_distribution \
  -d pool_bech32=${POOL_BECH32} \
  -d epoch=${EPOCH}
  1. This is an approach returning blocks for an array instead of playing with ranges:
# If no epochs array is provided, count for every epoch is returned
POOL_ID=cf46fd8eb598742bd889d72f80717552a480921379f6b811b2825eaf
POOL_BECH32=$(echo ${POOL_ID} | bech32 pool)
EPOCHS_ARRAY={92,99,101}
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_blockcount_for_poolbech32 \
     -d pool_bech32=${POOL_BECH32} \
     -d epochs=${EPOCHS_ARRAY}
  1. Same than 3 but without any epoch filtering:
POOL_ID=cf46fd8eb598742bd889d72f80717552a480921379f6b811b2825eaf
POOL_BECH32=$(echo ${POOL_ID} | bech32 pool)
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_blockcount_for_poolbech32 \
     -d pool_bech32=${POOL_BECH32}
# If no epochs are provided, returns delegation for every epoch
STAKE_ADDRESS=stake_test1uzxpncx82vfkl5ml00ws44hzfdh64r22kr93e79jqsumv0q8g8cy0
EPOCHS_ARRAY={94}
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_delegation_history_for_stake_address \
     -d address=${STAKE_ADDRESS} \
     -d epochs=${EPOCHS_ARRAY}
# If no epochs are provided, returns delegation for every epoch
STAKE_ADDRESS=stake_test1uzxpncx82vfkl5ml00ws44hzfdh64r22kr93e79jqsumv0q8g8cy0
EPOCHS_ARRAY={94}
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_rewards_history_for_stake_address \
     -d address=${STAKE_ADDRESS} \
     -d epochs=${EPOCHS_ARRAY}

Also added some extra functions:

  • Get block numbers [for given pool_bech32 in epochs]:
POOL_ID=00cd5fd9cbf0b9535f804f59da4666859afa38e5ca7729a3172efe36
POOL_BECH32=$(echo ${POOL_ID} | bech32 pool)
EPOCHS_ARRAY={100,104}
# for every epoch and pool
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_blocknumbers
# for any pool and specific epochs
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_blocknumbers \
     -d epochs=${EPOCHS_ARRAY}
# for specific pool and epochs
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_blocknumbers \
     -d pool_bech32=${POOL_BECH32} \
     -d epochs=${EPOCHS_ARRAY}
# for specific pool and any epoch
curl -s https://postgrest-api.testnet.dandelion.link/rpc/get_blocknumbers \
     -d pool_bech32=${POOL_BECH32}

@TrevorBenson
Copy link
Author

@rcmorano Thanks for the content contribution to this gist.

This is the first time I have looked at dandelion.link, I had not realized it was a free API backend for Cardano which tied into GimbaLabs, which I also hadn't had a chance to check out yet. I'm already loving seeing new content about token transactions and using asciinema "asciicasts" as video demo's.

These provide options which remove the requirement for db-sync. I will have to review the API's, most likely I will build a postman collection to compare the datasets between the db-sync query and the dandelion.link output to see if we can construct the same table datasets.

If your interested in contributing thoughts we are starting a discussion under the cardano-community which I invite your input on. Your mentioned in the initial discussion so will know of it momentarily.

Thanks!

@rcmorano
Copy link

You are welcome @TrevorBenson, glad you are liking our open stuff :)))

I'll be working on updating the postgREST doco on gimbalabs.com this week to include all the examples in this gist and some others, and I was also thinking on adding, not a postman collection, but a hopsscotch (former postwoman) one :D
As I commented on cntool's related issue, feel free to use dandelion endpoints, my aiming is to keep them open/standard so no one is locked in, and eventually maybe democratize such service so it becomes something greater than a playground for people prototyping things :)

@TrevorBenson
Copy link
Author

TrevorBenson commented Jan 12, 2021

@rcmorano

I'll be working on updating the postgREST doco on gimbalabs.com this week to include all the examples in this gist and some others, and I was also thinking on adding, not a postman collection, but a hopsscotch (former postwoman) one :D

I'm not stuck on postman by any means. Any tool to help build a swagger/openapi like spec/def is acceptable to me.

Also interested in your thoughts on democratization. My goals are to support the testnet(s) and mainnet in various ways and that includes collaborative efforts. One thing I'm (slowly very very slowly) working on is providing something like minimum pooltool.io for the testnets. Feel free to DM me for further discussion if you have interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment