-
Notifications
You must be signed in to change notification settings - Fork 33
[IBC] Clone cosmos/ics23 protobuf definitions into IBC repo
#922
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
672e202
Add cosmos/ics23 proto into local proto with conversion
h5law 513005c
Add makefile auto download and sed on proto
h5law 0ce694a
add missing conversion field
h5law ac50e06
pick: conversion funcs
h5law 06cb90e
unexport methods
h5law 064f69c
remove unused functions
h5law 2cfcbf1
chore: dont download unless file doesnt exist
h5law File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,15 @@ CWD ?= CURRENT_WORKING_DIRECTIONRY_NOT_SUPPLIED | |
| # `VERBOSE_TEST="" make test_persistence` is an easy way to run the same tests without verbose output | ||
| VERBOSE_TEST ?= -v | ||
|
|
||
| # Detect OS using the $(shell uname -s) command | ||
| ifeq ($(shell uname -s),Darwin) | ||
| # Add macOS-specific commands here | ||
| SEDI = sed -i '' | ||
| else ifeq ($(shell uname -s),Linux) | ||
| # Add Linux-specific commands here | ||
| SEDI = sed -i | ||
| endif | ||
|
|
||
| .SILENT: | ||
|
|
||
| .PHONY: list ## List all make targets | ||
|
|
@@ -309,13 +318,26 @@ protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the | |
| $(PROTOC_SHARED) -I=./p2p/types/proto --go_out=./p2p/types ./p2p/types/proto/*.proto | ||
|
|
||
| # IBC | ||
| @if test ! -e "./ibc/types/proto/proofs.proto"; then \ | ||
| make download_ics23_proto; \ | ||
| fi | ||
| $(PROTOC_SHARED) -I=./ibc/types/proto --go_out=./ibc/types ./ibc/types/proto/*.proto | ||
|
|
||
| # echo "View generated proto files by running: make protogen_show" | ||
|
|
||
| # CONSIDERATION: Some proto files contain unused gRPC services so we may need to add the following | ||
| # if/when we decide to include it: `grpc--go-grpc_opt=paths=source_relative --go-grpc_out=./output/path` | ||
|
|
||
| .PHONY: download_ics23_proto | ||
| download_ics23_proto: | ||
| echo "Downloading cosmos/ics23 proto definitions..."; \ | ||
| curl -s -o ./ibc/types/proto/proofs.proto https://raw.githubusercontent.com/cosmos/ics23/master/proto/cosmos/ics23/v1/proofs.proto; \ | ||
| $(SEDI) \ | ||
| -e '/^package/{N;d;}' \ | ||
| -e '[email protected]/.*"@github.com/pokt-network/pocket/ibc/types"@g' \ | ||
| ./ibc/types/proto/proofs.proto && \ | ||
| awk 'BEGIN { print "// ===== !! THIS IS CLONED FROM cosmos/ics23 !! =====\n" } { print }' ./ibc/types/proto/proofs.proto > tmpfile && mv tmpfile ./ibc/types/proto/proofs.proto; \ | ||
|
|
||
| .PHONY: protogen_docker_m1 | ||
| ## TECHDEBT: Test, validate & update. | ||
| protogen_docker_m1: docker_check | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| package types | ||
|
|
||
| import ics23 "github.com/cosmos/ics23/go" | ||
|
|
||
| // Copy of ics23.SmtSpec | ||
| // Ref: https://github.com/cosmos/ics23/blob/daa1760cb80f8607494ecf9e40482e66717a24e0/go/proof.go#L47 | ||
| var SmtSpec = &ProofSpec{ | ||
h5law marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LeafSpec: &LeafOp{ | ||
| Hash: HashOp_SHA256, | ||
| PrehashKey: HashOp_SHA256, | ||
| PrehashValue: HashOp_SHA256, | ||
| Length: LengthOp_NO_PREFIX, | ||
| Prefix: []byte{0}, | ||
| }, | ||
| InnerSpec: &InnerSpec{ | ||
| ChildOrder: []int32{0, 1}, | ||
| ChildSize: 32, | ||
| MinPrefixLength: 1, | ||
| MaxPrefixLength: 1, | ||
| EmptyChild: make([]byte, 32), | ||
| Hash: HashOp_SHA256, | ||
| }, | ||
| MaxDepth: 256, | ||
| PrehashKeyBeforeComparison: true, | ||
| } | ||
|
|
||
| func (p *ProofSpec) ConvertToIcs23ProofSpec() *ics23.ProofSpec { | ||
| if p == nil { | ||
| return nil | ||
| } | ||
| ics := new(ics23.ProofSpec) | ||
| ics.LeafSpec = p.LeafSpec.convertToIcs23LeafOp() | ||
| ics.InnerSpec = p.InnerSpec.convertToIcs23InnerSpec() | ||
| ics.MaxDepth = p.MaxDepth | ||
| ics.MinDepth = p.MinDepth | ||
| ics.PrehashKeyBeforeComparison = p.PrehashKeyBeforeComparison | ||
| return ics | ||
| } | ||
|
|
||
| func ConvertFromIcs23ProofSpec(p *ics23.ProofSpec) *ProofSpec { | ||
| if p == nil { | ||
| return nil | ||
| } | ||
| spc := new(ProofSpec) | ||
| spc.LeafSpec = convertFromIcs23LeafOp(p.LeafSpec) | ||
| spc.InnerSpec = convertFromIcs23InnerSpec(p.InnerSpec) | ||
| spc.MaxDepth = p.MaxDepth | ||
| spc.MinDepth = p.MinDepth | ||
| spc.PrehashKeyBeforeComparison = p.PrehashKeyBeforeComparison | ||
| return spc | ||
| } | ||
|
|
||
| func (l *LeafOp) convertToIcs23LeafOp() *ics23.LeafOp { | ||
| if l == nil { | ||
| return nil | ||
| } | ||
| ics := new(ics23.LeafOp) | ||
| ics.Hash = l.Hash.convertToIcs23HashOp() | ||
| ics.PrehashKey = l.PrehashKey.convertToIcs23HashOp() | ||
| ics.PrehashValue = l.PrehashValue.convertToIcs23HashOp() | ||
| ics.Length = l.Length.convertToIcs23LenthOp() | ||
| ics.Prefix = l.Prefix | ||
| return ics | ||
| } | ||
|
|
||
| func convertFromIcs23LeafOp(l *ics23.LeafOp) *LeafOp { | ||
| if l == nil { | ||
| return nil | ||
| } | ||
| op := new(LeafOp) | ||
| op.Hash = convertFromIcs23HashOp(l.Hash) | ||
| op.PrehashKey = convertFromIcs23HashOp(l.PrehashKey) | ||
| op.PrehashValue = convertFromIcs23HashOp(l.PrehashValue) | ||
| op.Length = convertFromIcs23LengthOp(l.Length) | ||
| op.Prefix = l.Prefix | ||
| return op | ||
| } | ||
|
|
||
| func (i *InnerSpec) convertToIcs23InnerSpec() *ics23.InnerSpec { | ||
| if i == nil { | ||
| return nil | ||
| } | ||
| ics := new(ics23.InnerSpec) | ||
| ics.ChildOrder = i.ChildOrder | ||
| ics.ChildSize = i.ChildSize | ||
| ics.MinPrefixLength = i.MinPrefixLength | ||
| ics.MaxPrefixLength = i.MaxPrefixLength | ||
| ics.EmptyChild = i.EmptyChild | ||
| ics.Hash = i.Hash.convertToIcs23HashOp() | ||
| return ics | ||
| } | ||
|
|
||
| func convertFromIcs23InnerSpec(i *ics23.InnerSpec) *InnerSpec { | ||
| if i == nil { | ||
| return nil | ||
| } | ||
| spec := new(InnerSpec) | ||
| spec.ChildOrder = i.ChildOrder | ||
| spec.ChildSize = i.ChildSize | ||
| spec.MinPrefixLength = i.MinPrefixLength | ||
| spec.MaxPrefixLength = i.MaxPrefixLength | ||
| spec.EmptyChild = i.EmptyChild | ||
| spec.Hash = convertFromIcs23HashOp(i.Hash) | ||
| return spec | ||
| } | ||
|
|
||
| func (h HashOp) convertToIcs23HashOp() ics23.HashOp { | ||
| switch h { | ||
| case HashOp_NO_HASH: | ||
| return ics23.HashOp_NO_HASH | ||
| case HashOp_SHA256: | ||
| return ics23.HashOp_SHA256 | ||
| case HashOp_SHA512: | ||
| return ics23.HashOp_SHA512 | ||
| case HashOp_KECCAK: | ||
| return ics23.HashOp_KECCAK | ||
| case HashOp_RIPEMD160: | ||
| return ics23.HashOp_RIPEMD160 | ||
| case HashOp_BITCOIN: | ||
| return ics23.HashOp_BITCOIN | ||
| case HashOp_SHA512_256: | ||
| return ics23.HashOp_SHA512_256 | ||
| default: | ||
| panic("unknown hash op") | ||
| } | ||
| } | ||
|
|
||
| func convertFromIcs23HashOp(h ics23.HashOp) HashOp { | ||
| switch h { | ||
| case ics23.HashOp_NO_HASH: | ||
| return HashOp_NO_HASH | ||
| case ics23.HashOp_SHA256: | ||
| return HashOp_SHA256 | ||
| case ics23.HashOp_SHA512: | ||
| return HashOp_SHA512 | ||
| case ics23.HashOp_KECCAK: | ||
| return HashOp_KECCAK | ||
| case ics23.HashOp_RIPEMD160: | ||
| return HashOp_RIPEMD160 | ||
| case ics23.HashOp_BITCOIN: | ||
| return HashOp_BITCOIN | ||
| case ics23.HashOp_SHA512_256: | ||
| return HashOp_SHA512_256 | ||
| default: | ||
| panic("unknown hash op") | ||
| } | ||
| } | ||
|
|
||
| func (l LengthOp) convertToIcs23LenthOp() ics23.LengthOp { | ||
| switch l { | ||
| case LengthOp_NO_PREFIX: | ||
| return ics23.LengthOp_NO_PREFIX | ||
| case LengthOp_VAR_PROTO: | ||
| return ics23.LengthOp_VAR_PROTO | ||
| case LengthOp_VAR_RLP: | ||
| return ics23.LengthOp_VAR_RLP | ||
| case LengthOp_FIXED32_BIG: | ||
| return ics23.LengthOp_FIXED32_BIG | ||
| case LengthOp_FIXED32_LITTLE: | ||
| return ics23.LengthOp_FIXED32_LITTLE | ||
| case LengthOp_FIXED64_BIG: | ||
| return ics23.LengthOp_FIXED64_BIG | ||
| case LengthOp_FIXED64_LITTLE: | ||
| return ics23.LengthOp_FIXED64_LITTLE | ||
| case LengthOp_REQUIRE_32_BYTES: | ||
| return ics23.LengthOp_REQUIRE_32_BYTES | ||
| case LengthOp_REQUIRE_64_BYTES: | ||
| return ics23.LengthOp_REQUIRE_64_BYTES | ||
| default: | ||
| panic("unknown length op") | ||
| } | ||
| } | ||
|
|
||
| func convertFromIcs23LengthOp(l ics23.LengthOp) LengthOp { | ||
| switch l { | ||
| case ics23.LengthOp_NO_PREFIX: | ||
| return LengthOp_NO_PREFIX | ||
| case ics23.LengthOp_VAR_PROTO: | ||
| return LengthOp_VAR_PROTO | ||
| case ics23.LengthOp_VAR_RLP: | ||
| return LengthOp_VAR_RLP | ||
| case ics23.LengthOp_FIXED32_BIG: | ||
| return LengthOp_FIXED32_BIG | ||
| case ics23.LengthOp_FIXED32_LITTLE: | ||
| return LengthOp_FIXED32_LITTLE | ||
| case ics23.LengthOp_FIXED64_BIG: | ||
| return LengthOp_FIXED64_BIG | ||
| case ics23.LengthOp_FIXED64_LITTLE: | ||
| return LengthOp_FIXED64_LITTLE | ||
| case ics23.LengthOp_REQUIRE_32_BYTES: | ||
| return LengthOp_REQUIRE_32_BYTES | ||
| case ics23.LengthOp_REQUIRE_64_BYTES: | ||
| return LengthOp_REQUIRE_64_BYTES | ||
| default: | ||
| panic("unknown length op") | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.