From b6d306ffe7f32277c9060284ce5e6b6bc93c33c0 Mon Sep 17 00:00:00 2001 From: Dreamer <745124335@qq.com> Date: Mon, 7 Nov 2022 17:54:59 +0800 Subject: [PATCH 1/4] update protobuf --- .../applications/nft_transfer/v1/packet.proto | 10 +++-- types/codec.go | 29 +++++++++++++ types/packet.go | 2 +- types/packet.pb.go | 42 ++++++++++--------- types/trace_test.go | 30 ++++--------- 5 files changed, 67 insertions(+), 46 deletions(-) diff --git a/proto/ibc/applications/nft_transfer/v1/packet.proto b/proto/ibc/applications/nft_transfer/v1/packet.proto index bbf9439..69e7d1b 100644 --- a/proto/ibc/applications/nft_transfer/v1/packet.proto +++ b/proto/ibc/applications/nft_transfer/v1/packet.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package ibc.applications.nft_transfer.v1; +import "gogoproto/gogo.proto"; + option go_package = "github.com/bianjieai/nft-transfer/types"; // NonFungibleTokenPacketData defines a struct for the packet payload @@ -9,13 +11,13 @@ option go_package = "github.com/bianjieai/nft-transfer/types"; // https://github.com/cosmos/ibc/tree/master/spec/app/ics-721-nft-transfer#data-structures message NonFungibleTokenPacketData { // the class_id of tokens to be transferred - string class_id = 1; + string class_id = 1 [ (gogoproto.customname) = "ClassId" ]; // the class_uri of tokens to be transferred - string class_uri = 2; + string class_uri = 2 [ (gogoproto.customname) = "ClassUri" ]; // the non fungible tokens to be transferred - repeated string token_ids = 3; + repeated string token_ids = 3 [ (gogoproto.customname) = "TokenIds" ]; // the non fungible tokens's uri to be transferred - repeated string token_uris = 4; + repeated string token_uris = 4 [ (gogoproto.customname) = "TokenUris" ]; // the sender address string sender = 5; // the recipient address on the destination chain diff --git a/types/codec.go b/types/codec.go index 3312c30..7b8860f 100644 --- a/types/codec.go +++ b/types/codec.go @@ -1,6 +1,11 @@ package types import ( + "bytes" + + "github.com/gogo/protobuf/jsonpb" + "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -39,3 +44,27 @@ func init() { RegisterLegacyAminoCodec(amino) amino.Seal() } + +func mustProtoMarshalJSON(msg proto.Message) []byte { + anyResolver := codectypes.NewInterfaceRegistry() + + // EmitDefaults is set to false to prevent marshalling of unpopulated fields (memo) + // OrigName and the anyResovler match the fields the original SDK function would expect + // in order to minimize changes. + + // OrigName is true since there is no particular reason to use camel case + // The any resolver is empty, but provided anyways. + jm := &jsonpb.Marshaler{OrigName: false, EmitDefaults: false, AnyResolver: anyResolver} + + err := codectypes.UnpackInterfaces(msg, codectypes.ProtoJSONPacker{JSONPBMarshaler: jm}) + if err != nil { + panic(err) + } + + buf := new(bytes.Buffer) + if err := jm.Marshal(buf, msg); err != nil { + panic(err) + } + + return buf.Bytes() +} diff --git a/types/packet.go b/types/packet.go index 8bd5413..9121157 100644 --- a/types/packet.go +++ b/types/packet.go @@ -75,5 +75,5 @@ func (nftpd NonFungibleTokenPacketData) ValidateBasic() error { // GetBytes is a helper for serializing func (nftpd NonFungibleTokenPacketData) GetBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&nftpd)) + return sdk.MustSortJSON(mustProtoMarshalJSON(&nftpd)) } diff --git a/types/packet.pb.go b/types/packet.pb.go index 523017c..b111617 100644 --- a/types/packet.pb.go +++ b/types/packet.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -124,25 +125,28 @@ func init() { } var fileDescriptor_f82fdc932b824013 = []byte{ - // 281 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x4e, 0xc3, 0x30, - 0x14, 0x45, 0x63, 0x0a, 0xa1, 0xf5, 0xe8, 0x01, 0x99, 0x22, 0xac, 0x88, 0x05, 0x96, 0x26, 0xaa, - 0xf8, 0x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0xbf, 0xbf, 0x7c, 0x7d, 0xf5, 0xd9, 0x32, 0xb4, - 0x6d, 0x19, 0xfa, 0x6e, 0x19, 0x7a, 0xef, 0x58, 0xb4, 0xed, 0x58, 0xf4, 0xd5, 0xb1, 0xe8, 0xe9, - 0x7c, 0x0d, 0xfe, 0xb9, 0x16, 0xa9, 0x34, 0xaf, 0x99, 0x00, 0xae, 0x5f, 0x40, 0x71, 0xe8, 0x57, - 0x9b, 0xfd, 0xaf, 0xe6, 0xdf, 0x2a, 0xe5, 0x44, 0x1c, 0x26, 0xbb, 0xfc, 0x09, 0x00, 0x00, 0xff, - 0xff, 0x8d, 0x61, 0x9e, 0x80, 0x63, 0x01, 0x00, 0x00, + // 329 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0xd1, 0xbd, 0x4e, 0xc3, 0x30, + 0x10, 0x07, 0xf0, 0x86, 0x42, 0x9b, 0x1a, 0x58, 0x22, 0x84, 0xa2, 0x0e, 0x69, 0xc5, 0xc0, 0x87, + 0x44, 0x13, 0x55, 0x3c, 0x01, 0x05, 0x21, 0x75, 0x41, 0x28, 0xa2, 0x0b, 0x4b, 0xe5, 0x38, 0x6e, + 0x38, 0x5a, 0xec, 0xc8, 0x76, 0x2a, 0xf1, 0x16, 0x3c, 0x16, 0x63, 0x47, 0xa6, 0x0a, 0x39, 0xaf, + 0xc1, 0x80, 0x6c, 0x97, 0xaa, 0xdb, 0xff, 0x92, 0x9f, 0xef, 0x2c, 0x1f, 0x1a, 0x40, 0x46, 0x12, + 0x5c, 0x96, 0x0b, 0x20, 0x58, 0x01, 0x67, 0x32, 0x61, 0x33, 0x35, 0x55, 0x02, 0x33, 0x39, 0xa3, + 0x22, 0x59, 0x0e, 0x93, 0x12, 0x93, 0x39, 0x55, 0x71, 0x29, 0xb8, 0xe2, 0x41, 0x1f, 0x32, 0x12, + 0xef, 0xf2, 0x78, 0x97, 0xc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 0xd9, 0x1b, 0x50, 0x0c, 0x66, 0x07, + 0x83, 0xed, 0x0e, 0xd4, 0x47, 0x49, 0x65, 0xd6, 0xb2, 0x0f, 0x79, 0xf3, 0x17, 0x00, 0x00, 0xff, + 0xff, 0x1c, 0xe2, 0xa6, 0x3a, 0xb1, 0x01, 0x00, 0x00, } func (m *NonFungibleTokenPacketData) Marshal() (dAtA []byte, err error) { diff --git a/types/trace_test.go b/types/trace_test.go index c668526..8e58c6b 100644 --- a/types/trace_test.go +++ b/types/trace_test.go @@ -1,7 +1,7 @@ package types import ( - "reflect" + "fmt" "testing" ) @@ -32,27 +32,9 @@ func TestIsAwayFromOrigin(t *testing.T) { } } -func TestParseClassTrace(t *testing.T) { - type args struct { - rawClassID string - } - tests := []struct { - name string - args args - want ClassTrace - }{ - {"native class", args{"kitty"}, ClassTrace{Path: "", BaseClassId: "kitty"}}, - {"transfer to (p2,c2)", args{"p2/c2/kitty"}, ClassTrace{Path: "p2/c2", BaseClassId: "kitty"}}, - {"transfer to (p4,c4)", args{"p4/c4/p2/c2/kitty"}, ClassTrace{Path: "p4/c4/p2/c2", BaseClassId: "kitty"}}, - {"transfer to (p6,c6)", args{"p6/c6/p4/c4/p2/c2/kitty"}, ClassTrace{Path: "p6/c6/p4/c4/p2/c2", BaseClassId: "kitty"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := ParseClassTrace(tt.args.rawClassID); !reflect.DeepEqual(got, tt.want) { - t.Errorf("ParseClassTrace() = %v, want %v", got, tt.want) - } - }) - } +func TestNonFungibleTokenPacketDataGetBytes(t *testing.T) { + n := NewNonFungibleTokenPacketData("cat", "hahha", []string{"xiaopi"}, []string{"baidu.com"}, "", "") + fmt.Println(string(n.GetBytes())) } func TestClassTrace_GetFullClassPath(t *testing.T) { @@ -74,3 +56,7 @@ func TestClassTrace_GetFullClassPath(t *testing.T) { }) } } + +func TestParseClassTrace(t *testing.T) { + +} From f4192097ef3428faadf281c4657dc9f2c037d72e Mon Sep 17 00:00:00 2001 From: Dreamer <745124335@qq.com> Date: Mon, 7 Nov 2022 17:58:21 +0800 Subject: [PATCH 2/4] revert protobuf --- .../applications/nft_transfer/v1/packet.proto | 8 ++-- types/packet.pb.go | 42 +++++++++---------- types/trace_test.go | 6 --- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/proto/ibc/applications/nft_transfer/v1/packet.proto b/proto/ibc/applications/nft_transfer/v1/packet.proto index 69e7d1b..1330046 100644 --- a/proto/ibc/applications/nft_transfer/v1/packet.proto +++ b/proto/ibc/applications/nft_transfer/v1/packet.proto @@ -11,13 +11,13 @@ option go_package = "github.com/bianjieai/nft-transfer/types"; // https://github.com/cosmos/ibc/tree/master/spec/app/ics-721-nft-transfer#data-structures message NonFungibleTokenPacketData { // the class_id of tokens to be transferred - string class_id = 1 [ (gogoproto.customname) = "ClassId" ]; + string class_id = 1; // the class_uri of tokens to be transferred - string class_uri = 2 [ (gogoproto.customname) = "ClassUri" ]; + string class_uri = 2; // the non fungible tokens to be transferred - repeated string token_ids = 3 [ (gogoproto.customname) = "TokenIds" ]; + repeated string token_ids = 3; // the non fungible tokens's uri to be transferred - repeated string token_uris = 4 [ (gogoproto.customname) = "TokenUris" ]; + repeated string token_uris = 4; // the sender address string sender = 5; // the recipient address on the destination chain diff --git a/types/packet.pb.go b/types/packet.pb.go index b111617..5d1f4d0 100644 --- a/types/packet.pb.go +++ b/types/packet.pb.go @@ -125,28 +125,26 @@ func init() { } var fileDescriptor_f82fdc932b824013 = []byte{ - // 329 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0xd1, 0xbd, 0x4e, 0xc3, 0x30, - 0x10, 0x07, 0xf0, 0x86, 0x42, 0x9b, 0x1a, 0x58, 0x22, 0x84, 0xa2, 0x0e, 0x69, 0xc5, 0xc0, 0x87, - 0x44, 0x13, 0x55, 0x3c, 0x01, 0x05, 0x21, 0x75, 0x41, 0x28, 0xa2, 0x0b, 0x4b, 0xe5, 0x38, 0x6e, - 0x38, 0x5a, 0xec, 0xc8, 0x76, 0x2a, 0xf1, 0x16, 0x3c, 0x16, 0x63, 0x47, 0xa6, 0x0a, 0x39, 0xaf, - 0xc1, 0x80, 0x6c, 0x97, 0xaa, 0xdb, 0xff, 0x92, 0x9f, 0xef, 0x2c, 0x1f, 0x1a, 0x40, 0x46, 0x12, - 0x5c, 0x96, 0x0b, 0x20, 0x58, 0x01, 0x67, 0x32, 0x61, 0x33, 0x35, 0x55, 0x02, 0x33, 0x39, 0xa3, - 0x22, 0x59, 0x0e, 0x93, 0x12, 0x93, 0x39, 0x55, 0x71, 0x29, 0xb8, 0xe2, 0x41, 0x1f, 0x32, 0x12, - 0xef, 0xf2, 0x78, 0x97, 0xc7, 0xcb, 0x61, 0xf7, 0xa4, 0xe0, 0x05, 0xb7, 0x38, 0x31, 0xc9, 0x9d, - 0x3b, 0xfb, 0xf5, 0x50, 0xf7, 0x91, 0xb3, 0x87, 0x8a, 0x15, 0x90, 0x2d, 0xe8, 0x33, 0x9f, 0x53, - 0xf6, 0x64, 0x1b, 0xdf, 0x63, 0x85, 0x83, 0x73, 0xe4, 0x93, 0x05, 0x96, 0x72, 0x0a, 0x79, 0xe8, - 0xf5, 0xbd, 0xcb, 0xce, 0xe8, 0x50, 0xaf, 0x7b, 0xed, 0x3b, 0xf3, 0x6d, 0x9c, 0xa7, 0x6d, 0xe2, - 0x42, 0x70, 0x85, 0x3a, 0xce, 0x55, 0x02, 0xc2, 0x3d, 0x0b, 0x8f, 0xf4, 0xba, 0xe7, 0x5b, 0x38, - 0x11, 0x90, 0xba, 0x36, 0x13, 0x01, 0x86, 0x2a, 0x33, 0x65, 0x0a, 0xb9, 0x0c, 0x9b, 0xfd, 0xe6, - 0x3f, 0xb5, 0xa3, 0xc7, 0xb9, 0x4c, 0x7d, 0xb5, 0x49, 0xc1, 0x35, 0x42, 0x8e, 0x56, 0x02, 0x64, - 0xb8, 0x6f, 0xed, 0xb1, 0x5e, 0xf7, 0x3a, 0xd6, 0x4e, 0x04, 0xc8, 0xd4, 0xf5, 0x32, 0x31, 0x38, - 0x45, 0x2d, 0x49, 0x59, 0x4e, 0x45, 0x78, 0x60, 0x2e, 0x90, 0x6e, 0xaa, 0xa0, 0x8b, 0x7c, 0x41, - 0x09, 0x85, 0x25, 0x15, 0x61, 0xcb, 0xfe, 0xd9, 0xd6, 0xa3, 0xdb, 0x2f, 0x1d, 0x79, 0x2b, 0x1d, - 0x79, 0x3f, 0x3a, 0xf2, 0x3e, 0xeb, 0xa8, 0xb1, 0xaa, 0xa3, 0xc6, 0x77, 0x1d, 0x35, 0x5e, 0x2e, - 0x0a, 0x50, 0xaf, 0x55, 0x16, 0x13, 0xfe, 0x9e, 0x64, 0x80, 0xd9, 0x1b, 0x50, 0x0c, 0x66, 0x07, - 0x83, 0xed, 0x0e, 0xd4, 0x47, 0x49, 0x65, 0xd6, 0xb2, 0x0f, 0x79, 0xf3, 0x17, 0x00, 0x00, 0xff, - 0xff, 0x1c, 0xe2, 0xa6, 0x3a, 0xb1, 0x01, 0x00, 0x00, + // 293 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0x2b, 0x31, + 0x18, 0x85, 0x9b, 0xdb, 0x6b, 0x6d, 0xb3, 0x0c, 0x22, 0xb1, 0x62, 0x28, 0x6e, 0x74, 0xd3, 0x09, + 0xc5, 0x27, 0x50, 0x44, 0xe8, 0x46, 0x44, 0xec, 0xc6, 0x4d, 0x49, 0x32, 0xe9, 0xf8, 0xdb, 0x9a, + 0x0c, 0x49, 0x66, 0xc0, 0xb7, 0xf0, 0xa1, 0x5c, 0xb8, 0xec, 0xd2, 0xa5, 0xcc, 0xbc, 0x88, 0x4c, + 0xa2, 0xd2, 0x5d, 0x4e, 0xbe, 0x2f, 0x27, 0x70, 0xf0,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0x20, 0x3c, 0x55, + 0x32, 0x53, 0xf6, 0x85, 0x4b, 0x10, 0xe6, 0x19, 0xb4, 0x80, 0x6e, 0xcb, 0xe9, 0xdf, 0x96, 0xe1, + 0xb5, 0xd4, 0x5e, 0x0e, 0xe2, 0x20, 0x17, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x75, 0xb1, 0xab, + 0x1f, 0x79, 0x01, 0x00, 0x00, } func (m *NonFungibleTokenPacketData) Marshal() (dAtA []byte, err error) { diff --git a/types/trace_test.go b/types/trace_test.go index 8e58c6b..e5f9933 100644 --- a/types/trace_test.go +++ b/types/trace_test.go @@ -1,7 +1,6 @@ package types import ( - "fmt" "testing" ) @@ -32,11 +31,6 @@ func TestIsAwayFromOrigin(t *testing.T) { } } -func TestNonFungibleTokenPacketDataGetBytes(t *testing.T) { - n := NewNonFungibleTokenPacketData("cat", "hahha", []string{"xiaopi"}, []string{"baidu.com"}, "", "") - fmt.Println(string(n.GetBytes())) -} - func TestClassTrace_GetFullClassPath(t *testing.T) { tests := []struct { name string From 93de3f6c9f24b88d95bd538aaa462678608d3630 Mon Sep 17 00:00:00 2001 From: Dreamer <745124335@qq.com> Date: Mon, 7 Nov 2022 18:00:15 +0800 Subject: [PATCH 3/4] clean comments --- types/codec.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/types/codec.go b/types/codec.go index 7b8860f..772fe12 100644 --- a/types/codec.go +++ b/types/codec.go @@ -51,9 +51,6 @@ func mustProtoMarshalJSON(msg proto.Message) []byte { // EmitDefaults is set to false to prevent marshalling of unpopulated fields (memo) // OrigName and the anyResovler match the fields the original SDK function would expect // in order to minimize changes. - - // OrigName is true since there is no particular reason to use camel case - // The any resolver is empty, but provided anyways. jm := &jsonpb.Marshaler{OrigName: false, EmitDefaults: false, AnyResolver: anyResolver} err := codectypes.UnpackInterfaces(msg, codectypes.ProtoJSONPacker{JSONPBMarshaler: jm}) From 90552f0deed37e6c20ef987289844aef3502d774 Mon Sep 17 00:00:00 2001 From: Dreamer <745124335@qq.com> Date: Mon, 7 Nov 2022 18:05:00 +0800 Subject: [PATCH 4/4] remove unused code --- .../applications/nft_transfer/v1/packet.proto | 2 -- types/trace_test.go | 28 ++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/proto/ibc/applications/nft_transfer/v1/packet.proto b/proto/ibc/applications/nft_transfer/v1/packet.proto index 1330046..bbf9439 100644 --- a/proto/ibc/applications/nft_transfer/v1/packet.proto +++ b/proto/ibc/applications/nft_transfer/v1/packet.proto @@ -2,8 +2,6 @@ syntax = "proto3"; package ibc.applications.nft_transfer.v1; -import "gogoproto/gogo.proto"; - option go_package = "github.com/bianjieai/nft-transfer/types"; // NonFungibleTokenPacketData defines a struct for the packet payload diff --git a/types/trace_test.go b/types/trace_test.go index e5f9933..c668526 100644 --- a/types/trace_test.go +++ b/types/trace_test.go @@ -1,6 +1,7 @@ package types import ( + "reflect" "testing" ) @@ -31,6 +32,29 @@ func TestIsAwayFromOrigin(t *testing.T) { } } +func TestParseClassTrace(t *testing.T) { + type args struct { + rawClassID string + } + tests := []struct { + name string + args args + want ClassTrace + }{ + {"native class", args{"kitty"}, ClassTrace{Path: "", BaseClassId: "kitty"}}, + {"transfer to (p2,c2)", args{"p2/c2/kitty"}, ClassTrace{Path: "p2/c2", BaseClassId: "kitty"}}, + {"transfer to (p4,c4)", args{"p4/c4/p2/c2/kitty"}, ClassTrace{Path: "p4/c4/p2/c2", BaseClassId: "kitty"}}, + {"transfer to (p6,c6)", args{"p6/c6/p4/c4/p2/c2/kitty"}, ClassTrace{Path: "p6/c6/p4/c4/p2/c2", BaseClassId: "kitty"}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ParseClassTrace(tt.args.rawClassID); !reflect.DeepEqual(got, tt.want) { + t.Errorf("ParseClassTrace() = %v, want %v", got, tt.want) + } + }) + } +} + func TestClassTrace_GetFullClassPath(t *testing.T) { tests := []struct { name string @@ -50,7 +74,3 @@ func TestClassTrace_GetFullClassPath(t *testing.T) { }) } } - -func TestParseClassTrace(t *testing.T) { - -}