From a9039888ab47385a694dffadfd6ac21cd2998193 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 23 Aug 2023 11:28:11 -0600 Subject: [PATCH 01/10] add genesis protos --- docs/proto-docs.md | 18 ++ proto/provenance/marker/v1/genesis.proto | 14 + x/marker/types/genesis.pb.go | 309 +++++++++++++++++++++-- 3 files changed, 324 insertions(+), 17 deletions(-) diff --git a/docs/proto-docs.md b/docs/proto-docs.md index 035a4ff511..41070e728f 100644 --- a/docs/proto-docs.md +++ b/docs/proto-docs.md @@ -82,6 +82,7 @@ - [MarkerType](#provenance.marker.v1.MarkerType) - [provenance/marker/v1/genesis.proto](#provenance/marker/v1/genesis.proto) + - [DenySendAddresses](#provenance.marker.v1.DenySendAddresses) - [GenesisState](#provenance.marker.v1.GenesisState) - [provenance/marker/v1/proposals.proto](#provenance/marker/v1/proposals.proto) @@ -1604,6 +1605,22 @@ MarkerType defines the types of marker + + +### DenySendAddresses +DenySendAddresses defines addresses that are denied sends for marker denom + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `denom` | [string](#string) | | denom is the marker's denom for denied addresses | +| `addresses` | [string](#string) | repeated | addresses defines all wallet addresses that are denied sends for marker denom | + + + + + + ### GenesisState @@ -1614,6 +1631,7 @@ GenesisState defines the account module's genesis state. | ----- | ---- | ----- | ----------- | | `params` | [Params](#provenance.marker.v1.Params) | | params defines all the parameters of the module. | | `markers` | [MarkerAccount](#provenance.marker.v1.MarkerAccount) | repeated | A collection of marker accounts to create on start | +| `deny_send_addresses` | [DenySendAddresses](#provenance.marker.v1.DenySendAddresses) | repeated | list of denom based denied send addresses | diff --git a/proto/provenance/marker/v1/genesis.proto b/proto/provenance/marker/v1/genesis.proto index 6445c288dd..7643c78ce5 100644 --- a/proto/provenance/marker/v1/genesis.proto +++ b/proto/provenance/marker/v1/genesis.proto @@ -19,4 +19,18 @@ message GenesisState { // A collection of marker accounts to create on start repeated MarkerAccount markers = 2 [(gogoproto.nullable) = false]; + + // list of denom based denied send addresses + repeated DenySendAddresses deny_send_addresses = 4 [(gogoproto.nullable) = false]; } + +// DenySendAddresses defines addresses that are denied sends for marker denom +message DenySendAddresses { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // denom is the marker's denom for denied addresses + string denom = 1; + // addresses defines all wallet addresses that are denied sends for marker denom + repeated string addresses = 3; +} \ No newline at end of file diff --git a/x/marker/types/genesis.pb.go b/x/marker/types/genesis.pb.go index 8c34adee37..12b1cb1f98 100644 --- a/x/marker/types/genesis.pb.go +++ b/x/marker/types/genesis.pb.go @@ -29,6 +29,8 @@ type GenesisState struct { Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` // A collection of marker accounts to create on start Markers []MarkerAccount `protobuf:"bytes,2,rep,name=markers,proto3" json:"markers"` + // list of denom based denied send addresses + DenySendAddresses []DenySendAddresses `protobuf:"bytes,4,rep,name=deny_send_addresses,json=denySendAddresses,proto3" json:"deny_send_addresses"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -64,8 +66,50 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +// DenySendAddresses defines addresses that are denied sends for marker denom +type DenySendAddresses struct { + // denom is the marker's denom for denied addresses + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` + // addresses defines all wallet addresses that are denied sends for marker denom + Addresses []string `protobuf:"bytes,3,rep,name=addresses,proto3" json:"addresses,omitempty"` +} + +func (m *DenySendAddresses) Reset() { *m = DenySendAddresses{} } +func (m *DenySendAddresses) String() string { return proto.CompactTextString(m) } +func (*DenySendAddresses) ProtoMessage() {} +func (*DenySendAddresses) Descriptor() ([]byte, []int) { + return fileDescriptor_5dcc4ab7c9d2f78f, []int{1} +} +func (m *DenySendAddresses) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DenySendAddresses) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DenySendAddresses.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DenySendAddresses) XXX_Merge(src proto.Message) { + xxx_messageInfo_DenySendAddresses.Merge(m, src) +} +func (m *DenySendAddresses) XXX_Size() int { + return m.Size() +} +func (m *DenySendAddresses) XXX_DiscardUnknown() { + xxx_messageInfo_DenySendAddresses.DiscardUnknown(m) +} + +var xxx_messageInfo_DenySendAddresses proto.InternalMessageInfo + func init() { proto.RegisterType((*GenesisState)(nil), "provenance.marker.v1.GenesisState") + proto.RegisterType((*DenySendAddresses)(nil), "provenance.marker.v1.DenySendAddresses") } func init() { @@ -73,23 +117,28 @@ func init() { } var fileDescriptor_5dcc4ab7c9d2f78f = []byte{ - // 251 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2a, 0x28, 0xca, 0x2f, - 0x4b, 0xcd, 0x4b, 0xcc, 0x4b, 0x4e, 0xd5, 0xcf, 0x4d, 0x2c, 0xca, 0x4e, 0x2d, 0xd2, 0x2f, 0x33, - 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, - 0x41, 0xa8, 0xd1, 0x83, 0xa8, 0xd1, 0x2b, 0x33, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, - 0xd0, 0x07, 0xb1, 0x20, 0x6a, 0xa5, 0x14, 0xb1, 0x9a, 0x07, 0xd5, 0x05, 0x56, 0xa2, 0x34, 0x93, - 0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x41, 0x70, 0x49, 0x62, 0x49, 0xaa, 0x90, 0x15, 0x17, 0x5b, 0x41, - 0x62, 0x51, 0x62, 0x6e, 0xb1, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x8c, 0x1e, 0x36, 0x0b, - 0xf5, 0x02, 0xc0, 0x6a, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xea, 0x10, 0x72, 0xe6, - 0x62, 0x87, 0xa8, 0x28, 0x96, 0x60, 0x52, 0x60, 0xd6, 0xe0, 0x36, 0x52, 0xc6, 0xae, 0xd9, 0x17, - 0xcc, 0x72, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x81, 0x9a, 0x01, 0xd3, 0x69, 0xc5, 0xd1, 0xb1, - 0x40, 0x9e, 0xe1, 0xc5, 0x02, 0x79, 0x06, 0xa7, 0xf4, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, - 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, - 0x96, 0x63, 0xe0, 0x12, 0xcf, 0xcc, 0xc7, 0x6a, 0x72, 0x00, 0x63, 0x94, 0x51, 0x7a, 0x66, 0x49, - 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x42, 0x89, 0x6e, 0x66, 0x3e, 0x12, 0x4f, 0xbf, - 0x02, 0x16, 0x1c, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0xb0, 0x30, 0x06, 0x04, 0x00, - 0x00, 0xff, 0xff, 0xa8, 0x55, 0x2c, 0xc0, 0x80, 0x01, 0x00, 0x00, + // 335 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x31, 0x4f, 0xc2, 0x40, + 0x14, 0xc7, 0x7b, 0x82, 0x28, 0x87, 0x0b, 0x95, 0x44, 0x42, 0x48, 0x41, 0x1c, 0x64, 0xb1, 0x17, + 0x70, 0x63, 0x03, 0x4d, 0x9c, 0x4c, 0x10, 0x36, 0x13, 0x43, 0x8e, 0xde, 0x4b, 0x6d, 0x4c, 0xef, + 0x9a, 0xbb, 0x83, 0xc8, 0x37, 0x70, 0xf4, 0x23, 0xf0, 0x71, 0x18, 0x19, 0x9d, 0x8c, 0x81, 0xc5, + 0x8f, 0xe0, 0x68, 0xbc, 0x96, 0xd4, 0x68, 0xb7, 0xf7, 0xda, 0xdf, 0xff, 0xf7, 0xde, 0xe5, 0xe1, + 0x56, 0x24, 0xc5, 0x1c, 0x38, 0xe5, 0x1e, 0x90, 0x90, 0xca, 0x27, 0x90, 0x64, 0xde, 0x21, 0x3e, + 0x70, 0x50, 0x81, 0x72, 0x23, 0x29, 0xb4, 0xb0, 0x2b, 0x29, 0xe3, 0xc6, 0x8c, 0x3b, 0xef, 0xd4, + 0x2a, 0xbe, 0xf0, 0x85, 0x01, 0xc8, 0x4f, 0x15, 0xb3, 0xb5, 0xd3, 0x4c, 0x5f, 0x92, 0x32, 0x48, + 0xeb, 0x0b, 0xe1, 0xa3, 0x9b, 0x78, 0xc0, 0x58, 0x53, 0x0d, 0x76, 0x0f, 0x17, 0x22, 0x2a, 0x69, + 0xa8, 0xaa, 0xa8, 0x89, 0xda, 0xa5, 0x6e, 0xdd, 0xcd, 0x1a, 0xe8, 0x0e, 0x0d, 0x33, 0xc8, 0xaf, + 0xde, 0x1b, 0xd6, 0x28, 0x49, 0xd8, 0x57, 0xf8, 0x20, 0x26, 0x54, 0x75, 0xaf, 0x99, 0x6b, 0x97, + 0xba, 0x67, 0xd9, 0xe1, 0x5b, 0x53, 0xf5, 0x3d, 0x4f, 0xcc, 0xb8, 0x4e, 0x1c, 0xbb, 0xa4, 0xfd, + 0x80, 0x8f, 0x19, 0xf0, 0xc5, 0x44, 0x01, 0x67, 0x13, 0xca, 0x98, 0x04, 0xa5, 0x40, 0x55, 0xf3, + 0x46, 0x78, 0x9e, 0x2d, 0xbc, 0x06, 0xbe, 0x18, 0x03, 0x67, 0xfd, 0x1d, 0x9e, 0x48, 0xcb, 0xec, + 0xef, 0x8f, 0xde, 0xe1, 0xcb, 0xb2, 0x61, 0x7d, 0x2e, 0x1b, 0x56, 0xeb, 0x0e, 0x97, 0xff, 0xe5, + 0xec, 0x0a, 0xde, 0x67, 0xc0, 0x45, 0x68, 0x5e, 0x5f, 0x1c, 0xc5, 0x8d, 0x5d, 0xc7, 0xc5, 0x74, + 0x93, 0x5c, 0x33, 0xd7, 0x2e, 0x8e, 0xd2, 0x0f, 0xa9, 0x72, 0xe0, 0xaf, 0x36, 0x0e, 0x5a, 0x6f, + 0x1c, 0xf4, 0xb1, 0x71, 0xd0, 0xeb, 0xd6, 0xb1, 0xd6, 0x5b, 0xc7, 0x7a, 0xdb, 0x3a, 0x16, 0x3e, + 0x09, 0x44, 0xe6, 0xea, 0x43, 0x74, 0xdf, 0xf5, 0x03, 0xfd, 0x38, 0x9b, 0xba, 0x9e, 0x08, 0x49, + 0x8a, 0x5c, 0x04, 0xe2, 0x57, 0x47, 0x9e, 0x77, 0x07, 0xd4, 0x8b, 0x08, 0xd4, 0xb4, 0x60, 0xae, + 0x77, 0xf9, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x86, 0x50, 0xd7, 0x47, 0x32, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -112,6 +161,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.DenySendAddresses) > 0 { + for iNdEx := len(m.DenySendAddresses) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.DenySendAddresses[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } if len(m.Markers) > 0 { for iNdEx := len(m.Markers) - 1; iNdEx >= 0; iNdEx-- { { @@ -139,6 +202,45 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *DenySendAddresses) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DenySendAddresses) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DenySendAddresses) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -164,6 +266,31 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.DenySendAddresses) > 0 { + for _, e := range m.DenySendAddresses { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *DenySendAddresses) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Addresses) > 0 { + for _, s := range m.Addresses { + l = len(s) + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -269,6 +396,154 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DenySendAddresses", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DenySendAddresses = append(m.DenySendAddresses, DenySendAddresses{}) + if err := m.DenySendAddresses[len(m.DenySendAddresses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DenySendAddresses) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DenySendAddresses: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DenySendAddresses: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) From 61ecfd3dd1eb53e5ce7931d255698fc333ccd1a0 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Thu, 24 Aug 2023 10:39:49 -0600 Subject: [PATCH 02/10] add key parsing and tests --- x/marker/types/key.go | 9 +++++++++ x/marker/types/key_test.go | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/x/marker/types/key.go b/x/marker/types/key.go index d09499bbab..93a2d08fed 100644 --- a/x/marker/types/key.go +++ b/x/marker/types/key.go @@ -70,3 +70,12 @@ func DenySendKey(markerAddr sdk.AccAddress, denyAddr sdk.AccAddress) []byte { key = append(key, address.MustLengthPrefix(markerAddr.Bytes())...) return append(key, address.MustLengthPrefix(denyAddr.Bytes())...) } + +// GetDenySendAddresses returns marker and denied send sdk.AccAddress's from DenySendKey +func GetDenySendAddresses(key []byte) (markerAddr sdk.AccAddress, denyAddr sdk.AccAddress) { + markerKeyLen := key[1] + denyKeyLen := key[markerKeyLen+2] + markerAddr = sdk.AccAddress(key[2 : markerKeyLen+2]) + denyAddr = sdk.AccAddress(key[markerKeyLen+3 : markerKeyLen+3+denyKeyLen]) + return +} diff --git a/x/marker/types/key_test.go b/x/marker/types/key_test.go index cd74720838..ac5da0d5b5 100644 --- a/x/marker/types/key_test.go +++ b/x/marker/types/key_test.go @@ -34,3 +34,13 @@ func TestDenySendKey(t *testing.T) { assert.Equal(t, denyAddr.Bytes(), denyKey[denomArrLen+3:denomArrLen+3+denyAddrLen], "should match deny key") assert.Len(t, denyKey, int(3+denomArrLen+denyAddrLen), "should have key of length of sum 1 for prefix 2 length bytes and length of denom and deny address") } + +func TestGetDenySendAddresses(t *testing.T) { + addr, err := MarkerAddress("nhash") + require.NoError(t, err) + denyAddr := sdk.AccAddress("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") + denyKey := DenySendKey(addr, denyAddr) + mAddr, dAddr := GetDenySendAddresses(denyKey) + assert.Equal(t, mAddr, addr) + assert.Equal(t, dAddr, denyAddr) +} From 7182d85f59bc01b08b8504998f8667024a6bf4a4 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Thu, 24 Aug 2023 15:09:41 -0600 Subject: [PATCH 03/10] refactor genesis design, add init and export genesis --- docs/proto-docs.md | 14 +-- proto/provenance/marker/v1/genesis.proto | 14 +-- x/marker/keeper/genesis.go | 17 ++- x/marker/keeper/keeper.go | 15 ++- x/marker/types/genesis.go | 9 +- x/marker/types/genesis.pb.go | 143 +++++++++++------------ 6 files changed, 119 insertions(+), 93 deletions(-) diff --git a/docs/proto-docs.md b/docs/proto-docs.md index 41070e728f..79d4c74384 100644 --- a/docs/proto-docs.md +++ b/docs/proto-docs.md @@ -82,7 +82,7 @@ - [MarkerType](#provenance.marker.v1.MarkerType) - [provenance/marker/v1/genesis.proto](#provenance/marker/v1/genesis.proto) - - [DenySendAddresses](#provenance.marker.v1.DenySendAddresses) + - [DenySendAddress](#provenance.marker.v1.DenySendAddress) - [GenesisState](#provenance.marker.v1.GenesisState) - [provenance/marker/v1/proposals.proto](#provenance/marker/v1/proposals.proto) @@ -1605,16 +1605,16 @@ MarkerType defines the types of marker - + -### DenySendAddresses -DenySendAddresses defines addresses that are denied sends for marker denom +### DenySendAddress +DenySendAddress defines addresses that are denied sends for marker denom | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `denom` | [string](#string) | | denom is the marker's denom for denied addresses | -| `addresses` | [string](#string) | repeated | addresses defines all wallet addresses that are denied sends for marker denom | +| `marker_address` | [string](#string) | | marker_address is the marker's address for denied address | +| `deny_address` | [string](#string) | | deny_address defines all wallet addresses that are denied sends for the marker | @@ -1631,7 +1631,7 @@ GenesisState defines the account module's genesis state. | ----- | ---- | ----- | ----------- | | `params` | [Params](#provenance.marker.v1.Params) | | params defines all the parameters of the module. | | `markers` | [MarkerAccount](#provenance.marker.v1.MarkerAccount) | repeated | A collection of marker accounts to create on start | -| `deny_send_addresses` | [DenySendAddresses](#provenance.marker.v1.DenySendAddresses) | repeated | list of denom based denied send addresses | +| `deny_send_addresses` | [DenySendAddress](#provenance.marker.v1.DenySendAddress) | repeated | list of denom based denied send addresses | diff --git a/proto/provenance/marker/v1/genesis.proto b/proto/provenance/marker/v1/genesis.proto index 7643c78ce5..becd07bb09 100644 --- a/proto/provenance/marker/v1/genesis.proto +++ b/proto/provenance/marker/v1/genesis.proto @@ -21,16 +21,16 @@ message GenesisState { repeated MarkerAccount markers = 2 [(gogoproto.nullable) = false]; // list of denom based denied send addresses - repeated DenySendAddresses deny_send_addresses = 4 [(gogoproto.nullable) = false]; + repeated DenySendAddress deny_send_addresses = 4 [(gogoproto.nullable) = false]; } -// DenySendAddresses defines addresses that are denied sends for marker denom -message DenySendAddresses { +// DenySendAddress defines addresses that are denied sends for marker denom +message DenySendAddress { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - // denom is the marker's denom for denied addresses - string denom = 1; - // addresses defines all wallet addresses that are denied sends for marker denom - repeated string addresses = 3; + // marker_address is the marker's address for denied address + string marker_address = 1; + // deny_address defines all wallet addresses that are denied sends for the marker + string deny_address = 3; } \ No newline at end of file diff --git a/x/marker/keeper/genesis.go b/x/marker/keeper/genesis.go index 6009f39b6c..c09b921397 100644 --- a/x/marker/keeper/genesis.go +++ b/x/marker/keeper/genesis.go @@ -43,6 +43,12 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { k.SetMarker(ctx, &data.Markers[i]) } } + + for _, denyAddress := range data.DenySendAddresses { + markerAddr := sdk.MustAccAddressFromBech32(denyAddress.MarkerAddress) + denyAddress := sdk.MustAccAddressFromBech32(denyAddress.DenyAddress) + k.AddSendDeny(ctx, markerAddr, denyAddress) + } } // ExportGenesis exports the current keeper state of the marker module.ExportGenesis @@ -73,5 +79,14 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) { } k.IterateMarkers(ctx, appendToMarkers) - return types.NewGenesisState(params, markers) + + var denyAddresses []types.DenySendAddress + handleDenyList := func(key []byte) bool { + markerAddr, denyAddr := types.GetDenySendAddresses(key) + denyAddresses = append(denyAddresses, types.DenySendAddress{MarkerAddress: markerAddr.String(), DenyAddress: denyAddr.String()}) + return false + } + k.IterateSendDeny(ctx, handleDenyList) + + return types.NewGenesisState(params, markers, denyAddresses) } diff --git a/x/marker/keeper/keeper.go b/x/marker/keeper/keeper.go index c6e744f3a0..6046232a21 100644 --- a/x/marker/keeper/keeper.go +++ b/x/marker/keeper/keeper.go @@ -174,7 +174,7 @@ func (k Keeper) RemoveMarker(ctx sdk.Context, marker types.MarkerAccountI) { store.Delete(types.MarkerStoreKey(marker.GetAddress())) } -// IterateMarkers iterates all markers with the given handler function. +// IterateMarkers iterates all markers with the given handler function. func (k Keeper) IterateMarkers(ctx sdk.Context, cb func(marker types.MarkerAccountI) (stop bool)) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, types.MarkerStoreKeyPrefix) @@ -217,6 +217,19 @@ func (k Keeper) RemoveSendDeny(ctx sdk.Context, markerAddr, senderAddr sdk.AccAd store.Delete(types.DenySendKey(markerAddr, senderAddr)) } +// IterateMarkers iterates all markers with the given handler function. +func (k Keeper) IterateSendDeny(ctx sdk.Context, handler func(key []byte) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.DenySendKeyPrefix) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + if handler(iterator.Key()) { + break + } + } +} + // GetReqAttrBypassAddrs returns a deep copy of the addresses that bypass the required attributes checking. func (k Keeper) GetReqAttrBypassAddrs() []sdk.AccAddress { return k.reqAttrBypassAddrs.GetSlice() diff --git a/x/marker/types/genesis.go b/x/marker/types/genesis.go index 5cb211b1f7..00799ca2b2 100644 --- a/x/marker/types/genesis.go +++ b/x/marker/types/genesis.go @@ -7,10 +7,11 @@ import ( ) // NewGenesisState creates a new GenesisState object -func NewGenesisState(params Params, markers []MarkerAccount) *GenesisState { +func NewGenesisState(params Params, markers []MarkerAccount, denySendAddress []DenySendAddress) *GenesisState { return &GenesisState{ - Params: params, - Markers: markers, + Params: params, + Markers: markers, + DenySendAddresses: denySendAddress, } } @@ -26,7 +27,7 @@ func (state GenesisState) Validate() error { // DefaultGenesisState returns the initial module genesis state. func DefaultGenesisState() *GenesisState { - return NewGenesisState(DefaultParams(), []MarkerAccount{}) + return NewGenesisState(DefaultParams(), []MarkerAccount{}, []DenySendAddress{}) } // GetGenesisStateFromAppState returns x/marker GenesisState given raw application diff --git a/x/marker/types/genesis.pb.go b/x/marker/types/genesis.pb.go index 12b1cb1f98..084474f09b 100644 --- a/x/marker/types/genesis.pb.go +++ b/x/marker/types/genesis.pb.go @@ -30,7 +30,7 @@ type GenesisState struct { // A collection of marker accounts to create on start Markers []MarkerAccount `protobuf:"bytes,2,rep,name=markers,proto3" json:"markers"` // list of denom based denied send addresses - DenySendAddresses []DenySendAddresses `protobuf:"bytes,4,rep,name=deny_send_addresses,json=denySendAddresses,proto3" json:"deny_send_addresses"` + DenySendAddresses []DenySendAddress `protobuf:"bytes,4,rep,name=deny_send_addresses,json=denySendAddresses,proto3" json:"deny_send_addresses"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -66,26 +66,26 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -// DenySendAddresses defines addresses that are denied sends for marker denom -type DenySendAddresses struct { - // denom is the marker's denom for denied addresses - Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` - // addresses defines all wallet addresses that are denied sends for marker denom - Addresses []string `protobuf:"bytes,3,rep,name=addresses,proto3" json:"addresses,omitempty"` +// DenySendAddress defines addresses that are denied sends for marker denom +type DenySendAddress struct { + // marker_address is the marker's address for denied address + MarkerAddress string `protobuf:"bytes,1,opt,name=marker_address,json=markerAddress,proto3" json:"marker_address,omitempty"` + // deny_address defines all wallet addresses that are denied sends for the marker + DenyAddress string `protobuf:"bytes,3,opt,name=deny_address,json=denyAddress,proto3" json:"deny_address,omitempty"` } -func (m *DenySendAddresses) Reset() { *m = DenySendAddresses{} } -func (m *DenySendAddresses) String() string { return proto.CompactTextString(m) } -func (*DenySendAddresses) ProtoMessage() {} -func (*DenySendAddresses) Descriptor() ([]byte, []int) { +func (m *DenySendAddress) Reset() { *m = DenySendAddress{} } +func (m *DenySendAddress) String() string { return proto.CompactTextString(m) } +func (*DenySendAddress) ProtoMessage() {} +func (*DenySendAddress) Descriptor() ([]byte, []int) { return fileDescriptor_5dcc4ab7c9d2f78f, []int{1} } -func (m *DenySendAddresses) XXX_Unmarshal(b []byte) error { +func (m *DenySendAddress) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *DenySendAddresses) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *DenySendAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_DenySendAddresses.Marshal(b, m, deterministic) + return xxx_messageInfo_DenySendAddress.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -95,21 +95,21 @@ func (m *DenySendAddresses) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *DenySendAddresses) XXX_Merge(src proto.Message) { - xxx_messageInfo_DenySendAddresses.Merge(m, src) +func (m *DenySendAddress) XXX_Merge(src proto.Message) { + xxx_messageInfo_DenySendAddress.Merge(m, src) } -func (m *DenySendAddresses) XXX_Size() int { +func (m *DenySendAddress) XXX_Size() int { return m.Size() } -func (m *DenySendAddresses) XXX_DiscardUnknown() { - xxx_messageInfo_DenySendAddresses.DiscardUnknown(m) +func (m *DenySendAddress) XXX_DiscardUnknown() { + xxx_messageInfo_DenySendAddress.DiscardUnknown(m) } -var xxx_messageInfo_DenySendAddresses proto.InternalMessageInfo +var xxx_messageInfo_DenySendAddress proto.InternalMessageInfo func init() { proto.RegisterType((*GenesisState)(nil), "provenance.marker.v1.GenesisState") - proto.RegisterType((*DenySendAddresses)(nil), "provenance.marker.v1.DenySendAddresses") + proto.RegisterType((*DenySendAddress)(nil), "provenance.marker.v1.DenySendAddress") } func init() { @@ -117,28 +117,29 @@ func init() { } var fileDescriptor_5dcc4ab7c9d2f78f = []byte{ - // 335 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x31, 0x4f, 0xc2, 0x40, - 0x14, 0xc7, 0x7b, 0x82, 0x28, 0x87, 0x0b, 0x95, 0x44, 0x42, 0x48, 0x41, 0x1c, 0x64, 0xb1, 0x17, - 0x70, 0x63, 0x03, 0x4d, 0x9c, 0x4c, 0x10, 0x36, 0x13, 0x43, 0x8e, 0xde, 0x4b, 0x6d, 0x4c, 0xef, - 0x9a, 0xbb, 0x83, 0xc8, 0x37, 0x70, 0xf4, 0x23, 0xf0, 0x71, 0x18, 0x19, 0x9d, 0x8c, 0x81, 0xc5, - 0x8f, 0xe0, 0x68, 0xbc, 0x96, 0xd4, 0x68, 0xb7, 0xf7, 0xda, 0xdf, 0xff, 0xf7, 0xde, 0xe5, 0xe1, - 0x56, 0x24, 0xc5, 0x1c, 0x38, 0xe5, 0x1e, 0x90, 0x90, 0xca, 0x27, 0x90, 0x64, 0xde, 0x21, 0x3e, - 0x70, 0x50, 0x81, 0x72, 0x23, 0x29, 0xb4, 0xb0, 0x2b, 0x29, 0xe3, 0xc6, 0x8c, 0x3b, 0xef, 0xd4, - 0x2a, 0xbe, 0xf0, 0x85, 0x01, 0xc8, 0x4f, 0x15, 0xb3, 0xb5, 0xd3, 0x4c, 0x5f, 0x92, 0x32, 0x48, - 0xeb, 0x0b, 0xe1, 0xa3, 0x9b, 0x78, 0xc0, 0x58, 0x53, 0x0d, 0x76, 0x0f, 0x17, 0x22, 0x2a, 0x69, - 0xa8, 0xaa, 0xa8, 0x89, 0xda, 0xa5, 0x6e, 0xdd, 0xcd, 0x1a, 0xe8, 0x0e, 0x0d, 0x33, 0xc8, 0xaf, - 0xde, 0x1b, 0xd6, 0x28, 0x49, 0xd8, 0x57, 0xf8, 0x20, 0x26, 0x54, 0x75, 0xaf, 0x99, 0x6b, 0x97, - 0xba, 0x67, 0xd9, 0xe1, 0x5b, 0x53, 0xf5, 0x3d, 0x4f, 0xcc, 0xb8, 0x4e, 0x1c, 0xbb, 0xa4, 0xfd, - 0x80, 0x8f, 0x19, 0xf0, 0xc5, 0x44, 0x01, 0x67, 0x13, 0xca, 0x98, 0x04, 0xa5, 0x40, 0x55, 0xf3, - 0x46, 0x78, 0x9e, 0x2d, 0xbc, 0x06, 0xbe, 0x18, 0x03, 0x67, 0xfd, 0x1d, 0x9e, 0x48, 0xcb, 0xec, - 0xef, 0x8f, 0xde, 0xe1, 0xcb, 0xb2, 0x61, 0x7d, 0x2e, 0x1b, 0x56, 0xeb, 0x0e, 0x97, 0xff, 0xe5, - 0xec, 0x0a, 0xde, 0x67, 0xc0, 0x45, 0x68, 0x5e, 0x5f, 0x1c, 0xc5, 0x8d, 0x5d, 0xc7, 0xc5, 0x74, - 0x93, 0x5c, 0x33, 0xd7, 0x2e, 0x8e, 0xd2, 0x0f, 0xa9, 0x72, 0xe0, 0xaf, 0x36, 0x0e, 0x5a, 0x6f, - 0x1c, 0xf4, 0xb1, 0x71, 0xd0, 0xeb, 0xd6, 0xb1, 0xd6, 0x5b, 0xc7, 0x7a, 0xdb, 0x3a, 0x16, 0x3e, - 0x09, 0x44, 0xe6, 0xea, 0x43, 0x74, 0xdf, 0xf5, 0x03, 0xfd, 0x38, 0x9b, 0xba, 0x9e, 0x08, 0x49, - 0x8a, 0x5c, 0x04, 0xe2, 0x57, 0x47, 0x9e, 0x77, 0x07, 0xd4, 0x8b, 0x08, 0xd4, 0xb4, 0x60, 0xae, - 0x77, 0xf9, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x86, 0x50, 0xd7, 0x47, 0x32, 0x02, 0x00, 0x00, + // 340 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x4f, 0x4b, 0x02, 0x41, + 0x18, 0xc6, 0x77, 0x52, 0xac, 0x46, 0x2b, 0xda, 0x84, 0x44, 0x62, 0xfd, 0x13, 0x82, 0x97, 0x76, + 0xd1, 0x6e, 0xde, 0xb4, 0xa0, 0x53, 0x20, 0x7a, 0xab, 0x83, 0x8c, 0x3b, 0x2f, 0xdb, 0x12, 0xce, + 0x2c, 0x33, 0xa3, 0xe4, 0x37, 0xe8, 0xd8, 0x47, 0xf0, 0xe3, 0x78, 0xf4, 0xd8, 0x29, 0x42, 0x2f, + 0x7d, 0x82, 0xce, 0xe1, 0xcc, 0x2e, 0x56, 0xec, 0xed, 0x9d, 0x87, 0xdf, 0xf3, 0x3c, 0x33, 0xf3, + 0xe2, 0x7a, 0x24, 0xf8, 0x0c, 0x18, 0x61, 0x3e, 0x78, 0x13, 0x22, 0x9e, 0x41, 0x78, 0xb3, 0x96, + 0x17, 0x00, 0x03, 0x19, 0x4a, 0x37, 0x12, 0x5c, 0x71, 0xbb, 0xb8, 0x63, 0x5c, 0xc3, 0xb8, 0xb3, + 0x56, 0xb9, 0x18, 0xf0, 0x80, 0x6b, 0xc0, 0xdb, 0x4e, 0x86, 0x2d, 0xd7, 0x52, 0xf3, 0x62, 0x97, + 0x46, 0xea, 0xdf, 0x08, 0x17, 0xee, 0x4c, 0xc1, 0x50, 0x11, 0x05, 0x76, 0x07, 0xe7, 0x22, 0x22, + 0xc8, 0x44, 0x96, 0x50, 0x15, 0x35, 0xf3, 0xed, 0x0b, 0x37, 0xad, 0xd0, 0xed, 0x6b, 0xa6, 0x97, + 0x5d, 0x7e, 0x54, 0xac, 0x41, 0xec, 0xb0, 0x6f, 0xf0, 0xbe, 0x21, 0x64, 0x69, 0xaf, 0x9a, 0x69, + 0xe6, 0xdb, 0x97, 0xe9, 0xe6, 0x7b, 0x3d, 0x75, 0x7d, 0x9f, 0x4f, 0x99, 0x8a, 0x33, 0x12, 0xa7, + 0xfd, 0x88, 0xcf, 0x28, 0xb0, 0xf9, 0x48, 0x02, 0xa3, 0x23, 0x42, 0xa9, 0x00, 0x29, 0x41, 0x96, + 0xb2, 0x3a, 0xb0, 0x91, 0x1e, 0x78, 0x0b, 0x6c, 0x3e, 0x04, 0x46, 0xbb, 0x06, 0x8f, 0x23, 0x4f, + 0xe9, 0x5f, 0x19, 0x64, 0xe7, 0xe0, 0x75, 0x51, 0xb1, 0xbe, 0x16, 0x15, 0xab, 0x0e, 0xf8, 0xe4, + 0x9f, 0xcb, 0x6e, 0xe0, 0x63, 0x13, 0x99, 0xd4, 0xea, 0x2f, 0x38, 0x1c, 0x1c, 0x19, 0x35, 0xc1, + 0x6a, 0xb8, 0xa0, 0x2f, 0x98, 0x40, 0x19, 0x0d, 0xe5, 0xb7, 0x5a, 0x8c, 0xec, 0x6a, 0x7a, 0xc1, + 0x72, 0xed, 0xa0, 0xd5, 0xda, 0x41, 0x9f, 0x6b, 0x07, 0xbd, 0x6d, 0x1c, 0x6b, 0xb5, 0x71, 0xac, + 0xf7, 0x8d, 0x63, 0xe1, 0xf3, 0x90, 0xa7, 0x3e, 0xa6, 0x8f, 0x1e, 0xda, 0x41, 0xa8, 0x9e, 0xa6, + 0x63, 0xd7, 0xe7, 0x13, 0x6f, 0x87, 0x5c, 0x85, 0xfc, 0xd7, 0xc9, 0x7b, 0x49, 0x56, 0xaa, 0xe6, + 0x11, 0xc8, 0x71, 0x4e, 0xef, 0xf3, 0xfa, 0x27, 0x00, 0x00, 0xff, 0xff, 0x9b, 0xdf, 0x5a, 0xb1, + 0x44, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -202,7 +203,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *DenySendAddresses) Marshal() (dAtA []byte, err error) { +func (m *DenySendAddress) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -212,29 +213,27 @@ func (m *DenySendAddresses) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *DenySendAddresses) MarshalTo(dAtA []byte) (int, error) { +func (m *DenySendAddress) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *DenySendAddresses) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *DenySendAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.Addresses) > 0 { - for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Addresses[iNdEx]) - copy(dAtA[i:], m.Addresses[iNdEx]) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Addresses[iNdEx]))) - i-- - dAtA[i] = 0x1a - } + if len(m.DenyAddress) > 0 { + i -= len(m.DenyAddress) + copy(dAtA[i:], m.DenyAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.DenyAddress))) + i-- + dAtA[i] = 0x1a } - if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Denom))) + if len(m.MarkerAddress) > 0 { + i -= len(m.MarkerAddress) + copy(dAtA[i:], m.MarkerAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.MarkerAddress))) i-- dAtA[i] = 0xa } @@ -275,21 +274,19 @@ func (m *GenesisState) Size() (n int) { return n } -func (m *DenySendAddresses) Size() (n int) { +func (m *DenySendAddress) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Denom) + l = len(m.MarkerAddress) if l > 0 { n += 1 + l + sovGenesis(uint64(l)) } - if len(m.Addresses) > 0 { - for _, s := range m.Addresses { - l = len(s) - n += 1 + l + sovGenesis(uint64(l)) - } + l = len(m.DenyAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) } return n } @@ -425,7 +422,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.DenySendAddresses = append(m.DenySendAddresses, DenySendAddresses{}) + m.DenySendAddresses = append(m.DenySendAddresses, DenySendAddress{}) if err := m.DenySendAddresses[len(m.DenySendAddresses)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -451,7 +448,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -func (m *DenySendAddresses) Unmarshal(dAtA []byte) error { +func (m *DenySendAddress) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -474,15 +471,15 @@ func (m *DenySendAddresses) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: DenySendAddresses: wiretype end group for non-group") + return fmt.Errorf("proto: DenySendAddress: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: DenySendAddresses: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: DenySendAddress: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MarkerAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -510,11 +507,11 @@ func (m *DenySendAddresses) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Denom = string(dAtA[iNdEx:postIndex]) + m.MarkerAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field DenyAddress", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -542,7 +539,7 @@ func (m *DenySendAddresses) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Addresses = append(m.Addresses, string(dAtA[iNdEx:postIndex])) + m.DenyAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex From a2d5f35287e7b5e2bd22c0c4bcaf72617edab33d Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Thu, 24 Aug 2023 15:30:38 -0600 Subject: [PATCH 04/10] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ca07ea8c..7441d9262b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ The id info is still included by default, but will be excluded if `exclude_id_info` is `true`. * Removed the quicksilver upgrade handlers [PR 1648](https://github.com/provenance-io/provenance/pull/1648). * Bump cometbft to v0.34.29 (from v0.34.28) [PR 1649](https://github.com/provenance-io/provenance/pull/1649). +* Add genesis/init for Marker module send deny list addresses. [#1660](https://github.com/provenance-io/provenance/issues/1660) ### Bug Fixes From f7e262bffe10761e5cd2847bd3ed83259def5534 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Fri, 25 Aug 2023 09:45:04 -0600 Subject: [PATCH 05/10] add sim tests for deny send list --- app/params/weights.go | 1 + x/marker/simulation/operations.go | 53 ++++++++++++++++++------- x/marker/simulation/operations_test.go | 54 +++++++++++++++++++++++++- 3 files changed, 93 insertions(+), 15 deletions(-) diff --git a/app/params/weights.go b/app/params/weights.go index 76080f289b..5d3b3ded9c 100644 --- a/app/params/weights.go +++ b/app/params/weights.go @@ -26,6 +26,7 @@ const ( DefaultWeightMsgAddAccess int = 10 DefaultWeightMsgAddFinalizeActivateMarker int = 10 DefaultWeightMsgAddMarkerProposal int = 40 + DefaultWeightMsgUpdateDenySendList int = 10 // MsgFees DefaultWeightAddMsgFeeProposalContent int = 75 DefaultWeightRemoveMsgFeeProposalContent int = 25 diff --git a/x/marker/simulation/operations.go b/x/marker/simulation/operations.go index db18224bc2..345a09b35d 100644 --- a/x/marker/simulation/operations.go +++ b/x/marker/simulation/operations.go @@ -38,22 +38,10 @@ const ( OpWeightMsgAddMarkerProposal = "op_weight_msg_add_marker_proposal" //nolint:gosec // not credentials OpWeightMsgSetAccountData = "op_weight_msg_set_account_data" + //nolint:gosec // not credentials + OpWeightMsgUpdateSendDenyList = "op_weight_msg_update_send_deny_list" ) -/* - -AddAccess -DeleteAccess - -Withdraw - -Mint -Burn -Transfer - -SetDenomMetadata -*/ - // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, protoCodec *codec.ProtoCodec, @@ -76,6 +64,7 @@ func WeightedOperations( weightMsgAddFinalizeActivateMarker int weightMsgAddMarkerProposal int weightMsgSetAccountData int + weightMsgUpdateSendDenyList int ) appParams.GetOrGenerate(cdc, OpWeightMsgAddMarker, &weightMsgAddMarker, nil, @@ -114,6 +103,12 @@ func WeightedOperations( }, ) + appParams.GetOrGenerate(cdc, OpWeightMsgUpdateSendDenyList, &weightMsgUpdateSendDenyList, nil, + func(_ *rand.Rand) { + weightMsgUpdateSendDenyList = simappparams.DefaultWeightMsgUpdateDenySendList + }, + ) + return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgAddMarker, @@ -139,6 +134,10 @@ func WeightedOperations( weightMsgSetAccountData, SimulateMsgSetAccountData(k, args), ), + simulation.NewWeightedOperation( + weightMsgUpdateSendDenyList, + SimulateMsgUpdateSendDenyList(k, args), + ), } } @@ -368,6 +367,32 @@ func SimulateMsgSetAccountData(k keeper.Keeper, args *WeightedOpsArgs) simtypes. } } +// SimulateMsgUpdateSendDenyList will update random marker with denied send addresses. +func SimulateMsgUpdateSendDenyList(k keeper.Keeper, args *WeightedOpsArgs) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msg := &types.MsgUpdateSendDenyListRequest{} + + marker, signer := randomMarkerWithAccessSigner(r, ctx, k, accs, types.Access_Transfer) + if marker == nil { + return simtypes.NoOpMsg(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), "unable to find marker with a transfer signer"), nil, nil + } + + rDenyAccounts := simtypes.RandomAccounts(r, 10) + addDenyAddresses := make([]string, len(rDenyAccounts)) + for i := range rDenyAccounts { + addDenyAddresses[i] = rDenyAccounts[i].Address.String() + } + + msg.Denom = marker.GetDenom() + msg.AddDeniedAddresses = addDenyAddresses + msg.Authority = signer.Address.String() + + return Dispatch(r, app, ctx, args.AK, args.BK, signer, chainID, msg, nil) + } +} + // Dispatch sends an operation to the chain using a given account/funds on account for fees. Failures on the server side // are handled as no-op msg operations with the error string as the status/response. func Dispatch( diff --git a/x/marker/simulation/operations_test.go b/x/marker/simulation/operations_test.go index 01692e44a9..9d70782450 100644 --- a/x/marker/simulation/operations_test.go +++ b/x/marker/simulation/operations_test.go @@ -351,7 +351,7 @@ func (s *SimTestSuite) TestSimulateMsgAddMarkerProposal() { } } -func (s *SimTestSuite) TestSSimulateMsgSetAccountData() { +func (s *SimTestSuite) TestSimulateMsgSetAccountData() { // setup 3 accounts src := rand.NewSource(1) r := rand.New(src) @@ -403,6 +403,58 @@ func (s *SimTestSuite) TestSSimulateMsgSetAccountData() { s.Assert().Len(futureOperations, 0, "futureOperations") } +func (s *SimTestSuite) TestSimulateMsgUpdateSendDenyList() { + // setup 3 accounts + src := rand.NewSource(1) + r := rand.New(src) + accounts := s.getTestingAccounts(r, 3) + + // Add a marker with deposit permissions so that it can be found by the sim. + newMarker := &types.MsgAddFinalizeActivateMarkerRequest{ + Amount: sdk.NewInt64Coin("simcoin", 1000), + Manager: accounts[1].Address.String(), + FromAddress: accounts[1].Address.String(), + MarkerType: types.MarkerType_RestrictedCoin, + AccessList: []types.AccessGrant{ + { + Address: accounts[1].Address.String(), + Permissions: types.AccessList{ + types.Access_Mint, types.Access_Burn, types.Access_Deposit, types.Access_Withdraw, + types.Access_Delete, types.Access_Admin, types.Access_Transfer, + }, + }, + }, + SupplyFixed: true, + AllowGovernanceControl: true, + AllowForcedTransfer: false, + RequiredAttributes: nil, + } + markerMsgServer := keeper.NewMsgServerImpl(s.app.MarkerKeeper) + _, err := markerMsgServer.AddFinalizeActivateMarker(s.ctx, newMarker) + s.Require().NoError(err, "AddFinalizeActivateMarker") + + // begin a new block + s.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: s.app.LastBlockHeight() + 1, AppHash: s.app.LastCommitID().Hash}}) + + args := s.getWeightedOpsArgs() + // execute operation + op := simulation.SimulateMsgUpdateSendDenyList(s.app.MarkerKeeper, &args) + operationMsg, futureOperations, err := op(r, s.app.BaseApp, s.ctx, accounts, "") + s.Require().NoError(err, "SimulateMsgUpdateSendDenyList op(...) error") + s.LogOperationMsg(operationMsg) + + var msg types.MsgUpdateSendDenyListRequest + s.Require().NoError(s.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + + s.Assert().True(operationMsg.OK, "operationMsg.OK") + s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name, "operationMsg.Name") + s.Assert().Equal("simcoin", msg.Denom, "msg.Denom") + s.Assert().Len(msg.AddDeniedAddresses, 10, "msg.AddDeniedAddresses") + s.Assert().Equal(accounts[1].Address.String(), msg.Authority, "msg.Authority") + s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Route, "operationMsg.Route") + s.Assert().Len(futureOperations, 0, "futureOperations") +} + func (s *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { accounts := simtypes.RandomAccounts(r, n) From bf5ea0555e8f3ea38496f0504bd83a6f4a0e728f Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Fri, 25 Aug 2023 10:36:11 -0600 Subject: [PATCH 06/10] add missing comments and update incorrect ones --- x/marker/simulation/operations.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x/marker/simulation/operations.go b/x/marker/simulation/operations.go index 345a09b35d..29f3bf4128 100644 --- a/x/marker/simulation/operations.go +++ b/x/marker/simulation/operations.go @@ -141,7 +141,7 @@ func WeightedOperations( } } -// SimulateMsgAddMarker will bind a NAME under an existing name using a 40% probability of restricting it. +// SimulateMsgAddMarker will Add a random marker with random configuration. func SimulateMsgAddMarker(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, @@ -165,6 +165,7 @@ func SimulateMsgAddMarker(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bank } } +// SimulateMsgChangeStatus will randomly change the status of the marker depending on it's current state. func SimulateMsgChangeStatus(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, @@ -214,6 +215,7 @@ func SimulateMsgChangeStatus(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk b } } +// SimulateMsgAddAccess will Add a random access to an account. func SimulateMsgAddAccess(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, @@ -264,6 +266,7 @@ func SimulateMsgAddFinalizeActivateMarker(k keeper.Keeper, ak authkeeper.Account } } +// SimulateMsgAddMarkerProposal will broadcast a Add random Marker Proposal. func SimulateMsgAddMarkerProposal(k keeper.Keeper, args *WeightedOpsArgs) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, @@ -338,6 +341,7 @@ func SimulateMsgAddMarkerProposal(k keeper.Keeper, args *WeightedOpsArgs) simtyp } } +// SimulateMsgSetAccountData will set randomized account data to a marker. func SimulateMsgSetAccountData(k keeper.Keeper, args *WeightedOpsArgs) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, @@ -456,6 +460,7 @@ func Dispatch( return simtypes.NewOperationMsg(msg, true, "", &codec.ProtoCodec{}), futures, nil } +// randomUnrestrictedDenom returns a randomized unrestricted denom string value. func randomUnrestrictedDenom(r *rand.Rand, unrestrictedDenomExp string) string { exp := regexp.MustCompile(`\{(\d+),(\d+)\}`) matches := exp.FindStringSubmatch(unrestrictedDenomExp) @@ -499,6 +504,7 @@ func randomAccessTypes(r *rand.Rand, markerType types.MarkerType) (result []type return } +// randomMarker returns a randomly selected marker from store func randomMarker(r *rand.Rand, ctx sdk.Context, k keeper.Keeper) types.MarkerAccountI { var markers []types.MarkerAccountI k.IterateMarkers(ctx, func(marker types.MarkerAccountI) (stop bool) { @@ -512,6 +518,7 @@ func randomMarker(r *rand.Rand, ctx sdk.Context, k keeper.Keeper) types.MarkerAc return markers[idx] } +// randomMarkerWithAccessSigner returns a randomly selected marker and account that has specified access. func randomMarkerWithAccessSigner(r *rand.Rand, ctx sdk.Context, k keeper.Keeper, accs []simtypes.Account, access types.Access) (types.MarkerAccountI, simtypes.Account) { var markers []types.MarkerAccountI k.IterateMarkers(ctx, func(marker types.MarkerAccountI) (stop bool) { From 58c67992ef5340981a8877ce691180921e3e07b2 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Fri, 25 Aug 2023 10:45:10 -0600 Subject: [PATCH 07/10] add missing expected operation --- x/marker/simulation/operations_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/marker/simulation/operations_test.go b/x/marker/simulation/operations_test.go index 9d70782450..59161361b5 100644 --- a/x/marker/simulation/operations_test.go +++ b/x/marker/simulation/operations_test.go @@ -99,6 +99,7 @@ func (s *SimTestSuite) TestWeightedOperations() { {simappparams.DefaultWeightMsgAddFinalizeActivateMarker, sdk.MsgTypeURL(&types.MsgAddFinalizeActivateMarkerRequest{}), sdk.MsgTypeURL(&types.MsgAddFinalizeActivateMarkerRequest{})}, {simappparams.DefaultWeightMsgAddMarkerProposal, "gov", sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{})}, {simappparams.DefaultWeightMsgSetAccountData, sdk.MsgTypeURL(&types.MsgSetAccountDataRequest{}), sdk.MsgTypeURL(&types.MsgSetAccountDataRequest{})}, + {simappparams.DefaultWeightMsgUpdateDenySendList, sdk.MsgTypeURL(&types.MsgUpdateSendDenyListRequest{}), sdk.MsgTypeURL(&types.MsgUpdateSendDenyListRequest{})}, } expNames := make([]string, len(expected)) From 0eb020a285da9c99164581e0d7ed29091eed460a Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Thu, 31 Aug 2023 10:09:20 -0600 Subject: [PATCH 08/10] fix key test --- x/marker/types/key_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/marker/types/key_test.go b/x/marker/types/key_test.go index ac5da0d5b5..65df062d56 100644 --- a/x/marker/types/key_test.go +++ b/x/marker/types/key_test.go @@ -41,6 +41,6 @@ func TestGetDenySendAddresses(t *testing.T) { denyAddr := sdk.AccAddress("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") denyKey := DenySendKey(addr, denyAddr) mAddr, dAddr := GetDenySendAddresses(denyKey) - assert.Equal(t, mAddr, addr) - assert.Equal(t, dAddr, denyAddr) + assert.Equal(t, addr, mAddr, "module address") + assert.Equal(t, denyAddr, dAddr, "deny address") } From 47dd0c208f8c42392a54d7a6b913fc9bfdca38f8 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Thu, 31 Aug 2023 12:15:30 -0600 Subject: [PATCH 09/10] add msg to test --- x/marker/types/key_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/marker/types/key_test.go b/x/marker/types/key_test.go index 65df062d56..79c3dcc2ee 100644 --- a/x/marker/types/key_test.go +++ b/x/marker/types/key_test.go @@ -37,7 +37,7 @@ func TestDenySendKey(t *testing.T) { func TestGetDenySendAddresses(t *testing.T) { addr, err := MarkerAddress("nhash") - require.NoError(t, err) + require.NoError(t, err, "MarkerAddress(nhash)") denyAddr := sdk.AccAddress("cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h") denyKey := DenySendKey(addr, denyAddr) mAddr, dAddr := GetDenySendAddresses(denyKey) From ebbdd7afa5036a01825b18893d919a6018f27444 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 6 Sep 2023 14:49:47 -0600 Subject: [PATCH 10/10] fix proto numbers --- proto/provenance/marker/v1/genesis.proto | 2 +- x/marker/types/genesis.pb.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/proto/provenance/marker/v1/genesis.proto b/proto/provenance/marker/v1/genesis.proto index baf538e2b0..787b680884 100644 --- a/proto/provenance/marker/v1/genesis.proto +++ b/proto/provenance/marker/v1/genesis.proto @@ -35,7 +35,7 @@ message DenySendAddress { // marker_address is the marker's address for denied address string marker_address = 1; // deny_address defines all wallet addresses that are denied sends for the marker - string deny_address = 3; + string deny_address = 2; } // MarkerNetAssetValues defines the net asset values for a marker diff --git a/x/marker/types/genesis.pb.go b/x/marker/types/genesis.pb.go index 9c1ec8f453..ceb0c27c9f 100644 --- a/x/marker/types/genesis.pb.go +++ b/x/marker/types/genesis.pb.go @@ -73,7 +73,7 @@ type DenySendAddress struct { // marker_address is the marker's address for denied address MarkerAddress string `protobuf:"bytes,1,opt,name=marker_address,json=markerAddress,proto3" json:"marker_address,omitempty"` // deny_address defines all wallet addresses that are denied sends for the marker - DenyAddress string `protobuf:"bytes,3,opt,name=deny_address,json=denyAddress,proto3" json:"deny_address,omitempty"` + DenyAddress string `protobuf:"bytes,2,opt,name=deny_address,json=denyAddress,proto3" json:"deny_address,omitempty"` } func (m *DenySendAddress) Reset() { *m = DenySendAddress{} } @@ -180,14 +180,14 @@ var fileDescriptor_5dcc4ab7c9d2f78f = []byte{ 0xc4, 0xf3, 0x22, 0xe0, 0x1c, 0xb8, 0x51, 0x92, 0xfa, 0x9e, 0x5a, 0xff, 0x09, 0xe8, 0x66, 0x0e, 0xd4, 0x1b, 0x27, 0x78, 0x6a, 0x7e, 0xe9, 0xe5, 0xc7, 0xc0, 0x47, 0x4f, 0xfe, 0x6c, 0x5b, 0xda, 0xfd, 0xb6, 0xa5, 0x75, 0x01, 0x3d, 0x7f, 0x94, 0xc2, 0x3d, 0x54, 0x4f, 0x94, 0x59, 0xad, 0xbc, - 0xde, 0xa7, 0xb3, 0x67, 0xc9, 0x34, 0xc3, 0x3a, 0xa8, 0x26, 0x0f, 0x98, 0x41, 0x45, 0x09, 0x55, + 0xde, 0xa7, 0xb3, 0x67, 0xc9, 0x34, 0xc3, 0x3a, 0xa8, 0x26, 0x0f, 0x98, 0x41, 0x05, 0x09, 0x55, 0x4f, 0xb3, 0x14, 0xb9, 0xa8, 0xf9, 0xab, 0xa3, 0x86, 0xea, 0xe3, 0xb1, 0x81, 0x2a, 0xf9, 0x96, 0x6c, 0x8b, 0xe7, 0x8a, 0xcb, 0xbd, 0xfa, 0xab, 0x72, 0x66, 0xf5, 0xad, 0x9e, 0x4f, 0x34, 0xf1, 0x77, 0x07, 0x53, 0xdf, 0x1f, 0x4c, 0xfd, 0xee, 0x60, 0xea, 0xff, 0x8e, 0xa6, 0xb6, 0x3f, 0x9a, 0xda, 0xcd, 0xd1, 0xd4, 0xd0, 0xeb, 0x80, 0x29, 0x0b, 0xa6, 0xfa, 0x62, 0xe8, 0x07, 0xe2, 0xc7, 0x7a, 0x69, 0xb9, 0x6c, 0x65, 0x9f, 0x91, 0xf7, 0x01, 0xbb, 0xd8, 0xd9, 0xbf, 0xb3, 0x07, 0x2c, - 0x36, 0x21, 0xf0, 0x65, 0x59, 0xbe, 0xde, 0x0f, 0x0f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x78, 0x9f, - 0x1d, 0x5f, 0x32, 0x03, 0x00, 0x00, + 0x36, 0x21, 0xf0, 0x65, 0x59, 0xbe, 0xde, 0x0f, 0x0f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x2d, + 0x05, 0xd5, 0x32, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -290,7 +290,7 @@ func (m *DenySendAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.DenyAddress) i = encodeVarintGenesis(dAtA, i, uint64(len(m.DenyAddress))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } if len(m.MarkerAddress) > 0 { i -= len(m.MarkerAddress) @@ -674,7 +674,7 @@ func (m *DenySendAddress) Unmarshal(dAtA []byte) error { } m.MarkerAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field DenyAddress", wireType) }