From 0aebc32b9f64c7ea7ca3e01d823e127590bdb858 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Mon, 30 Oct 2023 17:53:08 -0400 Subject: [PATCH] fix: state var --- proto/core/identity/state.cosmos_orm.go | 385 ------------------------ 1 file changed, 385 deletions(-) delete mode 100644 proto/core/identity/state.cosmos_orm.go diff --git a/proto/core/identity/state.cosmos_orm.go b/proto/core/identity/state.cosmos_orm.go deleted file mode 100644 index a7cc5d030..000000000 --- a/proto/core/identity/state.cosmos_orm.go +++ /dev/null @@ -1,385 +0,0 @@ -// Code generated by protoc-gen-go-cosmos-orm. DO NOT EDIT. - -package identity - -import ( - context "context" - ormlist "cosmossdk.io/orm/model/ormlist" - ormtable "cosmossdk.io/orm/model/ormtable" - ormerrors "cosmossdk.io/orm/types/ormerrors" -) - -type BalanceTable interface { - Insert(ctx context.Context, balance *Balance) error - Update(ctx context.Context, balance *Balance) error - Save(ctx context.Context, balance *Balance) error - Delete(ctx context.Context, balance *Balance) error - Has(ctx context.Context, account []byte, denom 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, account []byte, denom string) (*Balance, error) - List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) - ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) - DeleteBy(ctx context.Context, prefixKey BalanceIndexKey) error - DeleteRange(ctx context.Context, from, to BalanceIndexKey) error - - doNotImplement() -} - -type BalanceIterator struct { - ormtable.Iterator -} - -func (i BalanceIterator) Value() (*Balance, error) { - var balance Balance - err := i.UnmarshalMessage(&balance) - return &balance, err -} - -type BalanceIndexKey interface { - id() uint32 - values() []interface{} - balanceIndexKey() -} - -// primary key starting index.. -type BalancePrimaryKey = BalanceAccountDenomIndexKey - -type BalanceAccountDenomIndexKey struct { - vs []interface{} -} - -func (x BalanceAccountDenomIndexKey) id() uint32 { return 0 } -func (x BalanceAccountDenomIndexKey) values() []interface{} { return x.vs } -func (x BalanceAccountDenomIndexKey) balanceIndexKey() {} - -func (this BalanceAccountDenomIndexKey) WithAccount(account []byte) BalanceAccountDenomIndexKey { - this.vs = []interface{}{account} - return this -} - -func (this BalanceAccountDenomIndexKey) WithAccountDenom(account []byte, denom string) BalanceAccountDenomIndexKey { - this.vs = []interface{}{account, denom} - return this -} - -type BalanceDenomIndexKey struct { - vs []interface{} -} - -func (x BalanceDenomIndexKey) id() uint32 { return 1 } -func (x BalanceDenomIndexKey) values() []interface{} { return x.vs } -func (x BalanceDenomIndexKey) balanceIndexKey() {} - -func (this BalanceDenomIndexKey) WithDenom(denom string) BalanceDenomIndexKey { - this.vs = []interface{}{denom} - return this -} - -type balanceTable struct { - table ormtable.Table -} - -func (this balanceTable) Insert(ctx context.Context, balance *Balance) error { - return this.table.Insert(ctx, balance) -} - -func (this balanceTable) Update(ctx context.Context, balance *Balance) error { - return this.table.Update(ctx, balance) -} - -func (this balanceTable) Save(ctx context.Context, balance *Balance) error { - return this.table.Save(ctx, balance) -} - -func (this balanceTable) Delete(ctx context.Context, balance *Balance) error { - return this.table.Delete(ctx, balance) -} - -func (this balanceTable) Has(ctx context.Context, account []byte, denom string) (found bool, err error) { - return this.table.PrimaryKey().Has(ctx, account, denom) -} - -func (this balanceTable) Get(ctx context.Context, account []byte, denom string) (*Balance, error) { - var balance Balance - found, err := this.table.PrimaryKey().Get(ctx, &balance, account, denom) - if err != nil { - return nil, err - } - if !found { - return nil, ormerrors.NotFound - } - return &balance, nil -} - -func (this balanceTable) List(ctx context.Context, prefixKey BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) { - it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...) - return BalanceIterator{it}, err -} - -func (this balanceTable) ListRange(ctx context.Context, from, to BalanceIndexKey, opts ...ormlist.Option) (BalanceIterator, error) { - it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...) - return BalanceIterator{it}, err -} - -func (this balanceTable) DeleteBy(ctx context.Context, prefixKey BalanceIndexKey) error { - return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...) -} - -func (this balanceTable) DeleteRange(ctx context.Context, from, to BalanceIndexKey) error { - return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values()) -} - -func (this balanceTable) doNotImplement() {} - -var _ BalanceTable = balanceTable{} - -func NewBalanceTable(db ormtable.Schema) (BalanceTable, error) { - table := db.GetTable(&Balance{}) - if table == nil { - return nil, ormerrors.TableNotFound.Wrap(string((&Balance{}).ProtoReflect().Descriptor().FullName())) - } - return balanceTable{table}, nil -} - -type AccountTable interface { - Insert(ctx context.Context, account *Account) error - InsertReturningId(ctx context.Context, account *Account) (uint64, error) - LastInsertedSequence(ctx context.Context) (uint64, error) - Update(ctx context.Context, account *Account) error - Save(ctx context.Context, account *Account) error - Delete(ctx context.Context, account *Account) error - Has(ctx context.Context, id uint64) (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 uint64) (*Account, error) - HasByAddress(ctx context.Context, address []byte) (found bool, err error) - // GetByAddress returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found. - GetByAddress(ctx context.Context, address []byte) (*Account, error) - List(ctx context.Context, prefixKey AccountIndexKey, opts ...ormlist.Option) (AccountIterator, error) - ListRange(ctx context.Context, from, to AccountIndexKey, opts ...ormlist.Option) (AccountIterator, error) - DeleteBy(ctx context.Context, prefixKey AccountIndexKey) error - DeleteRange(ctx context.Context, from, to AccountIndexKey) error - - doNotImplement() -} - -type AccountIterator struct { - ormtable.Iterator -} - -func (i AccountIterator) Value() (*Account, error) { - var account Account - err := i.UnmarshalMessage(&account) - return &account, err -} - -type AccountIndexKey interface { - id() uint32 - values() []interface{} - accountIndexKey() -} - -// primary key starting index.. -type AccountPrimaryKey = AccountIdIndexKey - -type AccountIdIndexKey struct { - vs []interface{} -} - -func (x AccountIdIndexKey) id() uint32 { return 0 } -func (x AccountIdIndexKey) values() []interface{} { return x.vs } -func (x AccountIdIndexKey) accountIndexKey() {} - -func (this AccountIdIndexKey) WithId(id uint64) AccountIdIndexKey { - this.vs = []interface{}{id} - return this -} - -type AccountAddressIndexKey struct { - vs []interface{} -} - -func (x AccountAddressIndexKey) id() uint32 { return 1 } -func (x AccountAddressIndexKey) values() []interface{} { return x.vs } -func (x AccountAddressIndexKey) accountIndexKey() {} - -func (this AccountAddressIndexKey) WithAddress(address []byte) AccountAddressIndexKey { - this.vs = []interface{}{address} - return this -} - -type accountTable struct { - table ormtable.AutoIncrementTable -} - -func (this accountTable) Insert(ctx context.Context, account *Account) error { - return this.table.Insert(ctx, account) -} - -func (this accountTable) Update(ctx context.Context, account *Account) error { - return this.table.Update(ctx, account) -} - -func (this accountTable) Save(ctx context.Context, account *Account) error { - return this.table.Save(ctx, account) -} - -func (this accountTable) Delete(ctx context.Context, account *Account) error { - return this.table.Delete(ctx, account) -} - -func (this accountTable) InsertReturningId(ctx context.Context, account *Account) (uint64, error) { - return this.table.InsertReturningPKey(ctx, account) -} - -func (this accountTable) LastInsertedSequence(ctx context.Context) (uint64, error) { - return this.table.LastInsertedSequence(ctx) -} - -func (this accountTable) Has(ctx context.Context, id uint64) (found bool, err error) { - return this.table.PrimaryKey().Has(ctx, id) -} - -func (this accountTable) Get(ctx context.Context, id uint64) (*Account, error) { - var account Account - found, err := this.table.PrimaryKey().Get(ctx, &account, id) - if err != nil { - return nil, err - } - if !found { - return nil, ormerrors.NotFound - } - return &account, nil -} - -func (this accountTable) HasByAddress(ctx context.Context, address []byte) (found bool, err error) { - return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx, - address, - ) -} - -func (this accountTable) GetByAddress(ctx context.Context, address []byte) (*Account, error) { - var account Account - found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &account, - address, - ) - if err != nil { - return nil, err - } - if !found { - return nil, ormerrors.NotFound - } - return &account, nil -} - -func (this accountTable) List(ctx context.Context, prefixKey AccountIndexKey, opts ...ormlist.Option) (AccountIterator, error) { - it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...) - return AccountIterator{it}, err -} - -func (this accountTable) ListRange(ctx context.Context, from, to AccountIndexKey, opts ...ormlist.Option) (AccountIterator, error) { - it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...) - return AccountIterator{it}, err -} - -func (this accountTable) DeleteBy(ctx context.Context, prefixKey AccountIndexKey) error { - return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...) -} - -func (this accountTable) DeleteRange(ctx context.Context, from, to AccountIndexKey) error { - return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values()) -} - -func (this accountTable) doNotImplement() {} - -var _ AccountTable = accountTable{} - -func NewAccountTable(db ormtable.Schema) (AccountTable, error) { - table := db.GetTable(&Account{}) - if table == nil { - return nil, ormerrors.TableNotFound.Wrap(string((&Account{}).ProtoReflect().Descriptor().FullName())) - } - return accountTable{table.(ormtable.AutoIncrementTable)}, nil -} - -// singleton store -type ConfigTable interface { - Get(ctx context.Context) (*Config, error) - Save(ctx context.Context, config *Config) error -} - -type configTable struct { - table ormtable.Table -} - -var _ ConfigTable = configTable{} - -func (x configTable) Get(ctx context.Context) (*Config, error) { - config := &Config{} - _, err := x.table.Get(ctx, config) - return config, err -} - -func (x configTable) Save(ctx context.Context, config *Config) error { - return x.table.Save(ctx, config) -} - -func NewConfigTable(db ormtable.Schema) (ConfigTable, error) { - table := db.GetTable(&Config{}) - if table == nil { - return nil, ormerrors.TableNotFound.Wrap(string((&Config{}).ProtoReflect().Descriptor().FullName())) - } - return &configTable{table}, nil -} - -type StateStore interface { - BalanceTable() BalanceTable - AccountTable() AccountTable - ConfigTable() ConfigTable - - doNotImplement() -} - -type stateStore struct { - balance BalanceTable - account AccountTable - config ConfigTable -} - -func (x stateStore) BalanceTable() BalanceTable { - return x.balance -} - -func (x stateStore) AccountTable() AccountTable { - return x.account -} - -func (x stateStore) ConfigTable() ConfigTable { - return x.config -} - -func (stateStore) doNotImplement() {} - -var _ StateStore = stateStore{} - -func NewStateStore(db ormtable.Schema) (StateStore, error) { - balanceTable, err := NewBalanceTable(db) - if err != nil { - return nil, err - } - - accountTable, err := NewAccountTable(db) - if err != nil { - return nil, err - } - - configTable, err := NewConfigTable(db) - if err != nil { - return nil, err - } - - return stateStore{ - balanceTable, - accountTable, - configTable, - }, nil -}