add trust anchor type to machine module

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2023-09-05 14:19:59 +02:00
parent 5763bd6a7c
commit 51dfde22e1
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
7 changed files with 242 additions and 26 deletions

View File

@ -533,6 +533,7 @@ func New(
keys[machinemoduletypes.TAIndexKey],
keys[machinemoduletypes.IssuerPlanetmintIndexKey],
keys[machinemoduletypes.IssuerLiquidIndexKey],
keys[machinemoduletypes.TrustAnchorKey],
keys[machinemoduletypes.MemStoreKey],
app.GetSubspace(machinemoduletypes.ModuleName),
)

View File

@ -31,3 +31,7 @@ message MachineIndex {
string issuerPlanetmint = 2;
string issuerLiquid = 3;
}
message TrustAnchor {
string pubkey = 1;
}

View File

@ -23,6 +23,7 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
taIndexStoreKey := sdk.NewKVStoreKey(types.TAIndexKey)
issuerPlanetmintIndexStoreKey := sdk.NewKVStoreKey(types.IssuerPlanetmintIndexKey)
issuerLiquidIndexStoreKey := sdk.NewKVStoreKey(types.IssuerLiquidIndexKey)
trustAnchorStoreKey := sdk.NewKVStoreKey(types.TrustAnchorKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
db := tmdb.NewMemDB()
@ -31,6 +32,7 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
stateStore.MountStoreWithDB(taIndexStoreKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(issuerPlanetmintIndexStoreKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(issuerLiquidIndexStoreKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(trustAnchorStoreKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())
@ -50,6 +52,7 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
taIndexStoreKey,
issuerPlanetmintIndexStoreKey,
issuerLiquidIndexStoreKey,
trustAnchorStoreKey,
memStoreKey,
paramsSubspace,
)

View File

@ -19,6 +19,7 @@ type (
taIndexStoreKey storetypes.StoreKey
issuerPlanetmintIndexStoreKey storetypes.StoreKey
issuerLiquidIndexStoreKey storetypes.StoreKey
taStoreKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
}
@ -30,6 +31,7 @@ func NewKeeper(
indexStoreKey,
issuerPlanetmintIndexStoreKey,
issuerLiquidIndexStoreKey,
taStoreKey,
memKey storetypes.StoreKey,
ps paramtypes.Subspace,
) *Keeper {
@ -44,6 +46,7 @@ func NewKeeper(
taIndexStoreKey: indexStoreKey,
issuerPlanetmintIndexStoreKey: issuerPlanetmintIndexStoreKey,
issuerLiquidIndexStoreKey: issuerLiquidIndexStoreKey,
taStoreKey: taStoreKey,
memKey: memKey,
paramstore: ps,
}

View File

@ -0,0 +1,31 @@
package keeper
import (
"planetmint-go/x/machine/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k Keeper) StoreTrustAnchor(ctx sdk.Context, ta types.TrustAnchor) {
store := prefix.NewStore(ctx.KVStore(k.taStoreKey), types.KeyPrefix(types.TrustAnchorKey))
appendValue := k.cdc.MustMarshal(&ta)
store.Set(GetTrustAnchorBytes(ta.Pubkey), appendValue)
}
func (k Keeper) GetTrustAnchor(ctx sdk.Context, pubKey string) (val types.TrustAnchor, found bool) {
store := prefix.NewStore(ctx.KVStore(k.taStoreKey), types.KeyPrefix(types.TrustAnchorKey))
trustAnchor := store.Get(GetTrustAnchorBytes(pubKey))
if trustAnchor == nil {
return val, false
}
if err := k.cdc.Unmarshal(trustAnchor, &val); err != nil {
return val, false
}
return val, true
}
func GetTrustAnchorBytes(pubKey string) []byte {
return []byte(pubKey)
}

View File

@ -20,6 +20,8 @@ const (
IssuerPlanetmintIndexKey = "Machine/IssuerPlanetmintIndex/"
IssuerLiquidIndexKey = "Machine/IssuerLiquidIndex/"
TrustAnchorKey = "Machine/trustAnchor/"
)
func KeyPrefix(p string) []byte {

View File

@ -274,10 +274,55 @@ func (m *MachineIndex) GetIssuerLiquid() string {
return ""
}
type TrustAnchor struct {
Pubkey string `protobuf:"bytes,1,opt,name=pubkey,proto3" json:"pubkey,omitempty"`
}
func (m *TrustAnchor) Reset() { *m = TrustAnchor{} }
func (m *TrustAnchor) String() string { return proto.CompactTextString(m) }
func (*TrustAnchor) ProtoMessage() {}
func (*TrustAnchor) Descriptor() ([]byte, []int) {
return fileDescriptor_1bb279745bef7c4b, []int{3}
}
func (m *TrustAnchor) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TrustAnchor) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_TrustAnchor.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 *TrustAnchor) XXX_Merge(src proto.Message) {
xxx_messageInfo_TrustAnchor.Merge(m, src)
}
func (m *TrustAnchor) XXX_Size() int {
return m.Size()
}
func (m *TrustAnchor) XXX_DiscardUnknown() {
xxx_messageInfo_TrustAnchor.DiscardUnknown(m)
}
var xxx_messageInfo_TrustAnchor proto.InternalMessageInfo
func (m *TrustAnchor) GetPubkey() string {
if m != nil {
return m.Pubkey
}
return ""
}
func init() {
proto.RegisterType((*Machine)(nil), "planetmintgo.machine.Machine")
proto.RegisterType((*Metadata)(nil), "planetmintgo.machine.Metadata")
proto.RegisterType((*MachineIndex)(nil), "planetmintgo.machine.MachineIndex")
proto.RegisterType((*TrustAnchor)(nil), "planetmintgo.machine.TrustAnchor")
}
func init() {
@ -285,32 +330,34 @@ func init() {
}
var fileDescriptor_1bb279745bef7c4b = []byte{
// 394 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0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cc, 0xee, 0x1a, 0x6a, 0x81, 0xcf, 0x7e, 0x02, 0x00, 0x00,
0xff, 0xff, 0xb9, 0x18, 0x24, 0xb2, 0xe6, 0x02, 0x00, 0x00,
// 417 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x0b, 0xd3, 0x30,
0x18, 0xc6, 0x97, 0x6d, 0x6e, 0xed, 0xbb, 0x89, 0x33, 0x88, 0xe4, 0xa0, 0xa5, 0x14, 0x84, 0x22,
0xda, 0x81, 0x1e, 0x04, 0x6f, 0xea, 0x2e, 0x03, 0x07, 0x52, 0x3c, 0x79, 0xcb, 0xda, 0xb8, 0x85,
0xad, 0x49, 0x6d, 0x52, 0xd9, 0xc0, 0x8f, 0xe0, 0xc1, 0x8f, 0xe5, 0x71, 0x47, 0xc1, 0x8b, 0x6c,
0x5f, 0x44, 0x9a, 0xa6, 0x9b, 0xfb, 0x73, 0xf0, 0xd4, 0xf7, 0x79, 0xde, 0x27, 0xbc, 0xcd, 0x2f,
0x2f, 0x04, 0xf9, 0x9a, 0x0a, 0xa6, 0x33, 0x2e, 0xf4, 0x42, 0x8e, 0x33, 0x9a, 0x2c, 0xb9, 0x60,
0xcd, 0x37, 0xca, 0x0b, 0xa9, 0x25, 0x7e, 0xf0, 0x6f, 0x26, 0xb2, 0xbd, 0xe0, 0x77, 0x1b, 0xfa,
0xb3, 0xba, 0xc6, 0x18, 0xba, 0x82, 0x66, 0x8c, 0x20, 0x1f, 0x85, 0x6e, 0x6c, 0x6a, 0xfc, 0x10,
0x7a, 0x9a, 0x27, 0x2b, 0x56, 0x90, 0xb6, 0x71, 0xad, 0xaa, 0xfc, 0x54, 0x66, 0x94, 0x0b, 0xd2,
0xa9, 0xfd, 0x5a, 0x61, 0x02, 0xfd, 0x82, 0x71, 0xa5, 0x4a, 0x46, 0xba, 0x3e, 0x0a, 0x9d, 0xb8,
0x91, 0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16, 0xa5, 0xd2, 0x6f, 0x44, 0xb2, 0x94,
0x66, 0x83, 0xf2, 0x72, 0xbe, 0x62, 0x5b, 0x3b, 0xd9, 0xaa, 0xb7, 0xaf, 0x7e, 0xee, 0x3d, 0xb4,
0xdb, 0x7b, 0xe8, 0xcf, 0xde, 0x43, 0x3f, 0x0e, 0x5e, 0x6b, 0x77, 0xf0, 0x5a, 0xbf, 0x0e, 0x5e,
0xeb, 0xd3, 0xe3, 0xd3, 0x53, 0x3c, 0x5f, 0xc8, 0xf1, 0xe6, 0xb8, 0xe8, 0x15, 0x6b, 0x35, 0xef,
0x99, 0x3d, 0x7f, 0xf9, 0x37, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x0c, 0xb1, 0x11, 0x0d, 0x03, 0x00,
0x00,
}
func (m *Machine) Marshal() (dAtA []byte, err error) {
@ -510,6 +557,36 @@ func (m *MachineIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *TrustAnchor) 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 *TrustAnchor) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TrustAnchor) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Pubkey) > 0 {
i -= len(m.Pubkey)
copy(dAtA[i:], m.Pubkey)
i = encodeVarintMachine(dAtA, i, uint64(len(m.Pubkey)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintMachine(dAtA []byte, offset int, v uint64) int {
offset -= sovMachine(v)
base := offset
@ -616,6 +693,19 @@ func (m *MachineIndex) Size() (n int) {
return n
}
func (m *TrustAnchor) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Pubkey)
if l > 0 {
n += 1 + l + sovMachine(uint64(l))
}
return n
}
func sovMachine(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@ -1301,6 +1391,88 @@ func (m *MachineIndex) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *TrustAnchor) 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 ErrIntOverflowMachine
}
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: TrustAnchor: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TrustAnchor: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Pubkey", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowMachine
}
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 ErrInvalidLengthMachine
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthMachine
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Pubkey = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipMachine(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthMachine
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipMachine(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0