-
Notifications
You must be signed in to change notification settings - Fork 170
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
feat: Implement BTCHeaderBytes and BTCHeaderHashBytes types #29
Conversation
Regarding Header Height: While having a type for it would be useful (instead of having
and in another file:
would lead to the |
Would it? At least addition seems to work fine: https://go.dev/play/p/0FZkJKYjlnC |
@@ -42,14 +43,18 @@ message QueryHashesRequest { | |||
|
|||
// QueryHashesResponse is response type for the Query/Hashes RPC method. | |||
message QueryHashesResponse { | |||
repeated bytes hashes = 1; | |||
repeated bytes hashes = 1 [ | |||
(gogoproto.castrepeated) = "github.com/babylonchain/babylon/types.BTCHeaderHashesBytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't it not be a repeated BTCHeaderHashBytes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
castrepeated
expects a slice of the corresponding type. Changed this to customtype
pointing to types.BTCHeaderHashBytes
and works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly used this because it is used extensively in Cosmos, but requires defining a new type.
x/btclightclient/types/msgs.go
Outdated
var headerBytes bbl.BTCHeaderBytes | ||
err := headerBytes.UnmarshalHex(headerHex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would make sense to have a dedicated package for these types, like decimal.go
in the SDK, so you can do this in one line, like headerBytes, err := btc_header.NewFromHex(headerHex)
and similarly for hashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I added these methods under the bbl
namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smashing! I admit I got a bit lost in the many marshalling variants, and perhaps the ergonomics could be improved so a variable declaration doesn't need to be separate from assignment, but otherwise it's a great leap! 👨🚀
762e8e3
to
05bfa41
Compare
Thanks @aakoshh for the comments! Updates and answers have been posted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the changes, looks good 👍
…ry (#29) --------- Co-authored-by: Runchao Han <[email protected]>
After the discussion on #26 , we agreed that there is a need for custom types that wrap Header and Header Hash bytes objects so that we can have control over our input and output formats depending on the context (CLI vs. RPC etc).
The types implementations are put under a global directory (a practice also followed by cosmos) since they are probably going to be needed by other modules (e.g. btccheckpoint) and implement various marshalling and umarshalling operations, most notably from hex strings to bytes and vice versa.