From c02e00616f898afef8eac2c1067710c6f1471c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Thu, 5 Oct 2023 17:08:22 +0200 Subject: [PATCH] ignite scaffold type reissuance proposer rawtx tx-id block-height:uint --module dao MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- proto/planetmintgo/dao/reissuance.proto | 12 + .../msg_server_reissue_rddl_proposal.go | 8 +- x/dao/keeper/reissuance.go | 30 ++ x/dao/types/keys.go | 2 + x/dao/types/reissuance.pb.go | 455 ++++++++++++++++++ 5 files changed, 506 insertions(+), 1 deletion(-) create mode 100644 proto/planetmintgo/dao/reissuance.proto create mode 100644 x/dao/keeper/reissuance.go create mode 100644 x/dao/types/reissuance.pb.go diff --git a/proto/planetmintgo/dao/reissuance.proto b/proto/planetmintgo/dao/reissuance.proto new file mode 100644 index 0000000..9a83f77 --- /dev/null +++ b/proto/planetmintgo/dao/reissuance.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package planetmintgo.dao; + +option go_package = "github.com/planetmint/planetmint-go/x/dao/types"; + +message Reissuance { + + string proposer = 1; + string rawtx = 2; + string txId = 3; + uint64 blockHeight = 4; +} diff --git a/x/dao/keeper/msg_server_reissue_rddl_proposal.go b/x/dao/keeper/msg_server_reissue_rddl_proposal.go index 7301f21..59623df 100644 --- a/x/dao/keeper/msg_server_reissue_rddl_proposal.go +++ b/x/dao/keeper/msg_server_reissue_rddl_proposal.go @@ -10,13 +10,19 @@ import ( func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReissueRDDLProposal) (*types.MsgReissueRDDLProposalResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + validator_identity, valid_result := util.GetValidatorCometBFTIdentity(ctx) if valid_result && msg.Proposer == validator_identity { // 1. sign tx // 2. broadcast tx // 3. notarize result by notarizing the liquid tx-id } - // 4. notarize msg in any case + + var reissuance types.Reissuance + reissuance.BlockHeight = msg.GetBlockheight() + reissuance.Proposer = msg.GetProposer() + reissuance.Rawtx = msg.GetTx() + k.StoreReissuance(ctx, reissuance) return &types.MsgReissueRDDLProposalResponse{}, nil } diff --git a/x/dao/keeper/reissuance.go b/x/dao/keeper/reissuance.go new file mode 100644 index 0000000..fedcb06 --- /dev/null +++ b/x/dao/keeper/reissuance.go @@ -0,0 +1,30 @@ +package keeper + +import ( + "math/big" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/planetmint/planetmint-go/x/dao/types" +) + +func (k Keeper) StoreReissuance(ctx sdk.Context, reissuance types.Reissuance) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey)) + appendValue := k.cdc.MustMarshal(&reissuance) + store.Set(getReissuanceBytes(reissuance.BlockHeight), appendValue) +} + +func (k Keeper) GetReissuance(ctx sdk.Context, height uint64) (val types.Challenge, found bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey)) + reissuance := store.Get(getReissuanceBytes(height)) + if reissuance == nil { + return val, false + } + k.cdc.MustUnmarshal(reissuance, &val) + return val, true +} + +func getReissuanceBytes(height uint64) []byte { + // Adding 1 because 0 will be interpreted as nil, which is an invalid key + return big.NewInt(int64(height + 1)).Bytes() +} diff --git a/x/dao/types/keys.go b/x/dao/types/keys.go index 876d29c..55d6706 100644 --- a/x/dao/types/keys.go +++ b/x/dao/types/keys.go @@ -18,6 +18,8 @@ const ( MintRequestAddressKey = "Dao/MintRequestAddress" MintRequestHashKey = "Dao/MintRequestHash" + + ReissuanceBlockHeightKey = "Dao/ReissuanceBlockHeight" ) func KeyPrefix(p string) []byte { diff --git a/x/dao/types/reissuance.pb.go b/x/dao/types/reissuance.pb.go new file mode 100644 index 0000000..b4eca29 --- /dev/null +++ b/x/dao/types/reissuance.pb.go @@ -0,0 +1,455 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: planetmintgo/dao/reissuance.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Reissuance struct { + Proposer string `protobuf:"bytes,1,opt,name=proposer,proto3" json:"proposer,omitempty"` + Rawtx string `protobuf:"bytes,2,opt,name=rawtx,proto3" json:"rawtx,omitempty"` + TxId string `protobuf:"bytes,3,opt,name=txId,proto3" json:"txId,omitempty"` + BlockHeight uint64 `protobuf:"varint,4,opt,name=blockHeight,proto3" json:"blockHeight,omitempty"` +} + +func (m *Reissuance) Reset() { *m = Reissuance{} } +func (m *Reissuance) String() string { return proto.CompactTextString(m) } +func (*Reissuance) ProtoMessage() {} +func (*Reissuance) Descriptor() ([]byte, []int) { + return fileDescriptor_35cf062bd4436e27, []int{0} +} +func (m *Reissuance) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Reissuance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Reissuance.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 *Reissuance) XXX_Merge(src proto.Message) { + xxx_messageInfo_Reissuance.Merge(m, src) +} +func (m *Reissuance) XXX_Size() int { + return m.Size() +} +func (m *Reissuance) XXX_DiscardUnknown() { + xxx_messageInfo_Reissuance.DiscardUnknown(m) +} + +var xxx_messageInfo_Reissuance proto.InternalMessageInfo + +func (m *Reissuance) GetProposer() string { + if m != nil { + return m.Proposer + } + return "" +} + +func (m *Reissuance) GetRawtx() string { + if m != nil { + return m.Rawtx + } + return "" +} + +func (m *Reissuance) GetTxId() string { + if m != nil { + return m.TxId + } + return "" +} + +func (m *Reissuance) GetBlockHeight() uint64 { + if m != nil { + return m.BlockHeight + } + return 0 +} + +func init() { + proto.RegisterType((*Reissuance)(nil), "planetmintgo.dao.Reissuance") +} + +func init() { proto.RegisterFile("planetmintgo/dao/reissuance.proto", fileDescriptor_35cf062bd4436e27) } + +var fileDescriptor_35cf062bd4436e27 = []byte{ + // 209 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2c, 0xc8, 0x49, 0xcc, + 0x4b, 0x2d, 0xc9, 0xcd, 0xcc, 0x2b, 0x49, 0xcf, 0xd7, 0x4f, 0x49, 0xcc, 0xd7, 0x2f, 0x4a, 0xcd, + 0x2c, 0x2e, 0x2e, 0x4d, 0xcc, 0x4b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x40, + 0x56, 0xa2, 0x97, 0x92, 0x98, 0xaf, 0x54, 0xc2, 0xc5, 0x15, 0x04, 0x57, 0x25, 0x24, 0xc5, 0xc5, + 0x51, 0x50, 0x94, 0x5f, 0x90, 0x5f, 0x9c, 0x5a, 0x24, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0x04, + 0xe7, 0x0b, 0x89, 0x70, 0xb1, 0x16, 0x25, 0x96, 0x97, 0x54, 0x48, 0x30, 0x81, 0x25, 0x20, 0x1c, + 0x21, 0x21, 0x2e, 0x96, 0x92, 0x0a, 0xcf, 0x14, 0x09, 0x66, 0xb0, 0x20, 0x98, 0x2d, 0xa4, 0xc0, + 0xc5, 0x9d, 0x94, 0x93, 0x9f, 0x9c, 0xed, 0x91, 0x9a, 0x99, 0x9e, 0x51, 0x22, 0xc1, 0xa2, 0xc0, + 0xa8, 0xc1, 0x12, 0x84, 0x2c, 0xe4, 0xe4, 0x79, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, + 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, + 0x0c, 0x51, 0xfa, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x08, 0xc7, + 0x22, 0x31, 0x75, 0xd3, 0xf3, 0xf5, 0x2b, 0xc0, 0xbe, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, + 0x03, 0xfb, 0xcc, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x81, 0xd2, 0xf6, 0x5d, 0xfe, 0x00, 0x00, + 0x00, +} + +func (m *Reissuance) 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 *Reissuance) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Reissuance) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeight != 0 { + i = encodeVarintReissuance(dAtA, i, uint64(m.BlockHeight)) + i-- + dAtA[i] = 0x20 + } + if len(m.TxId) > 0 { + i -= len(m.TxId) + copy(dAtA[i:], m.TxId) + i = encodeVarintReissuance(dAtA, i, uint64(len(m.TxId))) + i-- + dAtA[i] = 0x1a + } + if len(m.Rawtx) > 0 { + i -= len(m.Rawtx) + copy(dAtA[i:], m.Rawtx) + i = encodeVarintReissuance(dAtA, i, uint64(len(m.Rawtx))) + i-- + dAtA[i] = 0x12 + } + if len(m.Proposer) > 0 { + i -= len(m.Proposer) + copy(dAtA[i:], m.Proposer) + i = encodeVarintReissuance(dAtA, i, uint64(len(m.Proposer))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintReissuance(dAtA []byte, offset int, v uint64) int { + offset -= sovReissuance(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Reissuance) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Proposer) + if l > 0 { + n += 1 + l + sovReissuance(uint64(l)) + } + l = len(m.Rawtx) + if l > 0 { + n += 1 + l + sovReissuance(uint64(l)) + } + l = len(m.TxId) + if l > 0 { + n += 1 + l + sovReissuance(uint64(l)) + } + if m.BlockHeight != 0 { + n += 1 + sovReissuance(uint64(m.BlockHeight)) + } + return n +} + +func sovReissuance(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozReissuance(x uint64) (n int) { + return sovReissuance(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Reissuance) 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 ErrIntOverflowReissuance + } + 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: Reissuance: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Reissuance: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proposer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReissuance + } + 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 ErrInvalidLengthReissuance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReissuance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proposer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rawtx", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReissuance + } + 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 ErrInvalidLengthReissuance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReissuance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Rawtx = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReissuance + } + 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 ErrInvalidLengthReissuance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReissuance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeight", wireType) + } + m.BlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReissuance + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipReissuance(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthReissuance + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipReissuance(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowReissuance + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowReissuance + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowReissuance + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthReissuance + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupReissuance + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthReissuance + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthReissuance = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowReissuance = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupReissuance = fmt.Errorf("proto: unexpected end of group") +)