feat(x/tx): support bytes field as signer (port: #21850) (#24503)

Co-authored-by: yihuang <huang@crypto.com>
Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
This commit is contained in:
mmsqe 2025-05-13 21:52:56 +08:00 committed by GitHub
parent a2d6d1f6ac
commit 151f7d8767
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1676 additions and 95 deletions

View File

@ -33,6 +33,10 @@ Since v0.13.0, x/tx follows Cosmos SDK semver: https://github.com/cosmos/cosmos-
## [Unreleased]
### Improvements
* [#21850](https://github.com/cosmos/cosmos-sdk/pull/21850) Support bytes field as signer.
## [v0.14.0](https://github.com/cosmos/cosmos-sdk/releases/tag/x/tx/v0.14.0) - 2025-04-24
* SDK v0.53.x support.

View File

@ -92,7 +92,7 @@ message DeeplyNestedRepeatedSigner {
message BadSigner {
option (cosmos.msg.v1.signer) = "signer";
bytes signer = 1;
int32 signer = 1;
}
message NoSignerOption {
@ -104,7 +104,22 @@ message ValidatorSigner {
string signer = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}
message ValidatorSigners {
option (cosmos.msg.v1.signer) = "signers";
repeated string signers = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}
message ValidatorByteSigner {
option (cosmos.msg.v1.signer) = "signer";
bytes signer = 1;
}
message ValidatorByteSigners {
option (cosmos.msg.v1.signer) = "signers";
repeated bytes signers = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}
service TestSimpleSigner {
option (cosmos.msg.v1.service) = true;
rpc TestSimpleSigner(SimpleSigner) returns (SimpleSigner) {}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -301,6 +301,23 @@ func (c *Context) makeGetSignersFunc(descriptor protoreflect.MessageDescriptor)
}
return arr, nil
}
case protoreflect.BytesKind:
if field.IsList() {
fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) {
list := msg.ProtoReflect().Get(field).List()
n := list.Len()
for i := 0; i < n; i++ {
addrBz := list.Get(i).Bytes()
arr = append(arr, addrBz)
}
return arr, nil
}
} else {
fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) {
addrBz := msg.ProtoReflect().Get(field).Bytes()
return append(arr, addrBz), nil
}
}
default:
return nil, fmt.Errorf("unexpected field type %s for field %s in message %s", field.Kind(), fieldName, descriptor.FullName())
}

View File

@ -199,6 +199,27 @@ func TestGetSigners(t *testing.T) {
},
want: [][]byte{[]byte("foo")},
},
{
name: "validator signers",
msg: &testpb.ValidatorSigners{
Signers: []string{"val" + hex.EncodeToString([]byte("foo"))},
},
want: [][]byte{[]byte("foo")},
},
{
name: "validator bytes signer",
msg: &testpb.ValidatorByteSigner{
Signer: []byte("foo"),
},
want: [][]byte{[]byte("foo")},
},
{
name: "validator bytes signers",
msg: &testpb.ValidatorByteSigners{
Signers: [][]byte{[]byte("foo")},
},
want: [][]byte{[]byte("foo")},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {