nervosnetwork / ckb-light-client

CKB light client reference implementation
MIT License
14 stars 16 forks source link

[Question] Given a Block Number, how to retrieve its Header? #164

Closed phroi closed 8 months ago

phroi commented 8 months ago

As per title, I'm wondering: within a DApp that relies on a CKB Light Client as back-end, what's the most idiomatic way to retrieve a Block Header given its Block Number?

For example, let's say a DApp has to support Nervos DAO, at the second withdrawal step the withdrawal request cell in input contains the deposit Block Number. What's the most idiomatic way for this DApp to retrieve the corresponding deposit Header?

As usual I'm asking here since GitHub issues are SEO friendly and very likely in the future there will be other L1 developers wondering the same 😉

Keep up the great work :muscle: Phroi

quake commented 8 months ago

you may use get_transaction rpc to retrieve the deposit transaction, it will return the corresponding header hash together with tx, then use the get_header rpc to retrieve the header.

phroi commented 8 months ago

Yup yup! On the other side there is another way that is trying the headerDeps of the withdrawal request transaction. This seems a bit more general as likely it's applicable to other protocols outside NervosDAO. Depending one the transaction this means one less get_transaction call and possibly some more calls to get_header.

Thanks for your advice :pray: