vacuumlabs / adalite-backend-service

Icarus, a reference implementation for a lightweight wallet developed by the IOHK Engineering Team.
Apache License 2.0
2 stars 7 forks source link

getting delegation and rewards info given an address #93

Open roccomuso opened 4 years ago

roccomuso commented 4 years ago

Is there any endpoint that does something similar to api/account/info/:account :

https://github.com/vacuumlabs/adalite-backend-service/blob/shelley-hard-fork/src/legacy-routes.js#L345

Using address instead of accountDbId?

SebastienGllmt commented 4 years ago

Getting the rewards info for an address isn't supported by cardano-node or cardano-db-sync yet

roccomuso commented 4 years ago

How do I get it then? publicKey?

xdzurman commented 4 years ago

@roccomuso Rewards themselves will just start flowing on 23.8. 21:44 UTC. However, the rewards table is defined for now as follows: image

For your original question though, the endpoint api/account/info/:account requires the staking address on the input, e.g. api/account/info/e1f8c68b4297984c00049791b2db7b949982fcdc255ecb681abdf0b211, if that's what you're asking. We extract its database ID at the start of the function https://github.com/vacuumlabs/adalite-backend-service/blob/shelley-hard-fork/src/legacy-routes.js#L293 for faster lookups - and basically all tables are inter-referenced by their ids.

roccomuso commented 4 years ago

@xdzurman e1f8c68b4297984c00049791b2db7b949982fcdc255ecb681abdf0b211 is this a staking address? I thought was an accountDbId. How do you get the staking address given an address like addr1q8zk0a8p0darg2m4whzve5fry595tmahqd6jgzt9chr2ay79vl6wz7m6xs4h2awyengjxfgtghhmwqm4ysykt3wx46fs2wwd4g ?

PeterBenc commented 4 years ago

@roccomuso, yes that is hex representation of staking address, (rewards account address). Check out the implementation here, https://github.com/vacuumlabs/cardano-crypto.js/blob/492c0a5fa47bd7f257c593275d49b7149e6ffd56/address.js#L111, if you bech32 decode the given address, the last 28 bytes should be blake2b encoded staking public key, add a header to it and convert it to hex. That should be it but I've might have missed something. Anyways, I guess you can reverse-engineer it from here https://github.com/vacuumlabs/cardano-crypto.js/blob/492c0a5fa47bd7f257c593275d49b7149e6ffd56/address.js#L157

roccomuso commented 4 years ago

And what about from staking hex address getting back to the orginal 32 bytes pubKey? not clear why 4 bytes are dropped.

PeterBenc commented 4 years ago

blake2b encoding the public key to 28 bytes is a one-way operation, so you cant get the public key back from the address. Why would you need something like that anyway when you have access to those public keys when creating the address?