(no commit message provided)

This commit is contained in:
Prad Nukala
2024-07-06 03:02:45 -04:00
committed by Prad Nukala (aider)
parent 775150830f
commit e127d70584
10 changed files with 3047 additions and 1312 deletions
+126
View File
@@ -9,6 +9,120 @@ import (
ormerrors "cosmossdk.io/orm/types/ormerrors"
)
type AssertionTable interface {
Insert(ctx context.Context, assertion *Assertion) error
Update(ctx context.Context, assertion *Assertion) error
Save(ctx context.Context, assertion *Assertion) error
Delete(ctx context.Context, assertion *Assertion) error
Has(ctx context.Context, id string) (found bool, err error)
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
Get(ctx context.Context, id string) (*Assertion, error)
List(ctx context.Context, prefixKey AssertionIndexKey, opts ...ormlist.Option) (AssertionIterator, error)
ListRange(ctx context.Context, from, to AssertionIndexKey, opts ...ormlist.Option) (AssertionIterator, error)
DeleteBy(ctx context.Context, prefixKey AssertionIndexKey) error
DeleteRange(ctx context.Context, from, to AssertionIndexKey) error
doNotImplement()
}
type AssertionIterator struct {
ormtable.Iterator
}
func (i AssertionIterator) Value() (*Assertion, error) {
var assertion Assertion
err := i.UnmarshalMessage(&assertion)
return &assertion, err
}
type AssertionIndexKey interface {
id() uint32
values() []interface{}
assertionIndexKey()
}
// primary key starting index..
type AssertionPrimaryKey = AssertionIdIndexKey
type AssertionIdIndexKey struct {
vs []interface{}
}
func (x AssertionIdIndexKey) id() uint32 { return 0 }
func (x AssertionIdIndexKey) values() []interface{} { return x.vs }
func (x AssertionIdIndexKey) assertionIndexKey() {}
func (this AssertionIdIndexKey) WithId(id string) AssertionIdIndexKey {
this.vs = []interface{}{id}
return this
}
type assertionTable struct {
table ormtable.Table
}
func (this assertionTable) Insert(ctx context.Context, assertion *Assertion) error {
return this.table.Insert(ctx, assertion)
}
func (this assertionTable) Update(ctx context.Context, assertion *Assertion) error {
return this.table.Update(ctx, assertion)
}
func (this assertionTable) Save(ctx context.Context, assertion *Assertion) error {
return this.table.Save(ctx, assertion)
}
func (this assertionTable) Delete(ctx context.Context, assertion *Assertion) error {
return this.table.Delete(ctx, assertion)
}
func (this assertionTable) Has(ctx context.Context, id string) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, id)
}
func (this assertionTable) Get(ctx context.Context, id string) (*Assertion, error) {
var assertion Assertion
found, err := this.table.PrimaryKey().Get(ctx, &assertion, id)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &assertion, nil
}
func (this assertionTable) List(ctx context.Context, prefixKey AssertionIndexKey, opts ...ormlist.Option) (AssertionIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return AssertionIterator{it}, err
}
func (this assertionTable) ListRange(ctx context.Context, from, to AssertionIndexKey, opts ...ormlist.Option) (AssertionIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return AssertionIterator{it}, err
}
func (this assertionTable) DeleteBy(ctx context.Context, prefixKey AssertionIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this assertionTable) DeleteRange(ctx context.Context, from, to AssertionIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this assertionTable) doNotImplement() {}
var _ AssertionTable = assertionTable{}
func NewAssertionTable(db ormtable.Schema) (AssertionTable, error) {
table := db.GetTable(&Assertion{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&Assertion{}).ProtoReflect().Descriptor().FullName()))
}
return assertionTable{table}, nil
}
type AttestationTable interface {
Insert(ctx context.Context, attestation *Attestation) error
Update(ctx context.Context, attestation *Attestation) error
@@ -466,6 +580,7 @@ func NewServiceTable(db ormtable.Schema) (ServiceTable, error) {
}
type StateStore interface {
AssertionTable() AssertionTable
AttestationTable() AttestationTable
ControllerTable() ControllerTable
DelegationTable() DelegationTable
@@ -475,12 +590,17 @@ type StateStore interface {
}
type stateStore struct {
assertion AssertionTable
attestation AttestationTable
controller ControllerTable
delegation DelegationTable
service ServiceTable
}
func (x stateStore) AssertionTable() AssertionTable {
return x.assertion
}
func (x stateStore) AttestationTable() AttestationTable {
return x.attestation
}
@@ -502,6 +622,11 @@ func (stateStore) doNotImplement() {}
var _ StateStore = stateStore{}
func NewStateStore(db ormtable.Schema) (StateStore, error) {
assertionTable, err := NewAssertionTable(db)
if err != nil {
return nil, err
}
attestationTable, err := NewAttestationTable(db)
if err != nil {
return nil, err
@@ -523,6 +648,7 @@ func NewStateStore(db ormtable.Schema) (StateStore, error) {
}
return stateStore{
assertionTable,
attestationTable,
controllerTable,
delegationTable,