mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
(no commit message provided)
This commit is contained in:
committed by
Prad Nukala (aider)
parent
49b183cf48
commit
c0809ecac6
@@ -9,6 +9,120 @@ import (
|
||||
ormerrors "cosmossdk.io/orm/types/ormerrors"
|
||||
)
|
||||
|
||||
type AliasesTable interface {
|
||||
Insert(ctx context.Context, aliases *Aliases) error
|
||||
Update(ctx context.Context, aliases *Aliases) error
|
||||
Save(ctx context.Context, aliases *Aliases) error
|
||||
Delete(ctx context.Context, aliases *Aliases) 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) (*Aliases, error)
|
||||
List(ctx context.Context, prefixKey AliasesIndexKey, opts ...ormlist.Option) (AliasesIterator, error)
|
||||
ListRange(ctx context.Context, from, to AliasesIndexKey, opts ...ormlist.Option) (AliasesIterator, error)
|
||||
DeleteBy(ctx context.Context, prefixKey AliasesIndexKey) error
|
||||
DeleteRange(ctx context.Context, from, to AliasesIndexKey) error
|
||||
|
||||
doNotImplement()
|
||||
}
|
||||
|
||||
type AliasesIterator struct {
|
||||
ormtable.Iterator
|
||||
}
|
||||
|
||||
func (i AliasesIterator) Value() (*Aliases, error) {
|
||||
var aliases Aliases
|
||||
err := i.UnmarshalMessage(&aliases)
|
||||
return &aliases, err
|
||||
}
|
||||
|
||||
type AliasesIndexKey interface {
|
||||
id() uint32
|
||||
values() []interface{}
|
||||
aliasesIndexKey()
|
||||
}
|
||||
|
||||
// primary key starting index..
|
||||
type AliasesPrimaryKey = AliasesIdIndexKey
|
||||
|
||||
type AliasesIdIndexKey struct {
|
||||
vs []interface{}
|
||||
}
|
||||
|
||||
func (x AliasesIdIndexKey) id() uint32 { return 0 }
|
||||
func (x AliasesIdIndexKey) values() []interface{} { return x.vs }
|
||||
func (x AliasesIdIndexKey) aliasesIndexKey() {}
|
||||
|
||||
func (this AliasesIdIndexKey) WithId(id string) AliasesIdIndexKey {
|
||||
this.vs = []interface{}{id}
|
||||
return this
|
||||
}
|
||||
|
||||
type aliasesTable struct {
|
||||
table ormtable.Table
|
||||
}
|
||||
|
||||
func (this aliasesTable) Insert(ctx context.Context, aliases *Aliases) error {
|
||||
return this.table.Insert(ctx, aliases)
|
||||
}
|
||||
|
||||
func (this aliasesTable) Update(ctx context.Context, aliases *Aliases) error {
|
||||
return this.table.Update(ctx, aliases)
|
||||
}
|
||||
|
||||
func (this aliasesTable) Save(ctx context.Context, aliases *Aliases) error {
|
||||
return this.table.Save(ctx, aliases)
|
||||
}
|
||||
|
||||
func (this aliasesTable) Delete(ctx context.Context, aliases *Aliases) error {
|
||||
return this.table.Delete(ctx, aliases)
|
||||
}
|
||||
|
||||
func (this aliasesTable) Has(ctx context.Context, id string) (found bool, err error) {
|
||||
return this.table.PrimaryKey().Has(ctx, id)
|
||||
}
|
||||
|
||||
func (this aliasesTable) Get(ctx context.Context, id string) (*Aliases, error) {
|
||||
var aliases Aliases
|
||||
found, err := this.table.PrimaryKey().Get(ctx, &aliases, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, ormerrors.NotFound
|
||||
}
|
||||
return &aliases, nil
|
||||
}
|
||||
|
||||
func (this aliasesTable) List(ctx context.Context, prefixKey AliasesIndexKey, opts ...ormlist.Option) (AliasesIterator, error) {
|
||||
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
|
||||
return AliasesIterator{it}, err
|
||||
}
|
||||
|
||||
func (this aliasesTable) ListRange(ctx context.Context, from, to AliasesIndexKey, opts ...ormlist.Option) (AliasesIterator, error) {
|
||||
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
|
||||
return AliasesIterator{it}, err
|
||||
}
|
||||
|
||||
func (this aliasesTable) DeleteBy(ctx context.Context, prefixKey AliasesIndexKey) error {
|
||||
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
|
||||
}
|
||||
|
||||
func (this aliasesTable) DeleteRange(ctx context.Context, from, to AliasesIndexKey) error {
|
||||
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
|
||||
}
|
||||
|
||||
func (this aliasesTable) doNotImplement() {}
|
||||
|
||||
var _ AliasesTable = aliasesTable{}
|
||||
|
||||
func NewAliasesTable(db ormtable.Schema) (AliasesTable, error) {
|
||||
table := db.GetTable(&Aliases{})
|
||||
if table == nil {
|
||||
return nil, ormerrors.TableNotFound.Wrap(string((&Aliases{}).ProtoReflect().Descriptor().FullName()))
|
||||
}
|
||||
return aliasesTable{table}, nil
|
||||
}
|
||||
|
||||
type AssertionTable interface {
|
||||
Insert(ctx context.Context, assertion *Assertion) error
|
||||
Update(ctx context.Context, assertion *Assertion) error
|
||||
@@ -580,6 +694,7 @@ func NewServiceTable(db ormtable.Schema) (ServiceTable, error) {
|
||||
}
|
||||
|
||||
type StateStore interface {
|
||||
AliasesTable() AliasesTable
|
||||
AssertionTable() AssertionTable
|
||||
AttestationTable() AttestationTable
|
||||
ControllerTable() ControllerTable
|
||||
@@ -590,6 +705,7 @@ type StateStore interface {
|
||||
}
|
||||
|
||||
type stateStore struct {
|
||||
aliases AliasesTable
|
||||
assertion AssertionTable
|
||||
attestation AttestationTable
|
||||
controller ControllerTable
|
||||
@@ -597,6 +713,10 @@ type stateStore struct {
|
||||
service ServiceTable
|
||||
}
|
||||
|
||||
func (x stateStore) AliasesTable() AliasesTable {
|
||||
return x.aliases
|
||||
}
|
||||
|
||||
func (x stateStore) AssertionTable() AssertionTable {
|
||||
return x.assertion
|
||||
}
|
||||
@@ -622,6 +742,11 @@ func (stateStore) doNotImplement() {}
|
||||
var _ StateStore = stateStore{}
|
||||
|
||||
func NewStateStore(db ormtable.Schema) (StateStore, error) {
|
||||
aliasesTable, err := NewAliasesTable(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
assertionTable, err := NewAssertionTable(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -648,6 +773,7 @@ func NewStateStore(db ormtable.Schema) (StateStore, error) {
|
||||
}
|
||||
|
||||
return stateStore{
|
||||
aliasesTable,
|
||||
assertionTable,
|
||||
attestationTable,
|
||||
controllerTable,
|
||||
|
||||
Reference in New Issue
Block a user