sonr/api/oracle/v1/state.cosmos_orm.go

343 lines
10 KiB
Go

// Code generated by protoc-gen-go-cosmos-orm. DO NOT EDIT.
package oraclev1
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 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 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 = BalanceAccountIndexKey
type BalanceAccountIndexKey struct {
vs []interface{}
}
func (x BalanceAccountIndexKey) id() uint32 { return 0 }
func (x BalanceAccountIndexKey) values() []interface{} { return x.vs }
func (x BalanceAccountIndexKey) balanceIndexKey() {}
func (this BalanceAccountIndexKey) WithAccount(account string) BalanceAccountIndexKey {
this.vs = []interface{}{account}
return this
}
type BalanceAmountIndexKey struct {
vs []interface{}
}
func (x BalanceAmountIndexKey) id() uint32 { return 1 }
func (x BalanceAmountIndexKey) values() []interface{} { return x.vs }
func (x BalanceAmountIndexKey) balanceIndexKey() {}
func (this BalanceAmountIndexKey) WithAmount(amount uint64) BalanceAmountIndexKey {
this.vs = []interface{}{amount}
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 string) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, account)
}
func (this balanceTable) Get(ctx context.Context, account string) (*Balance, error) {
var balance Balance
found, err := this.table.PrimaryKey().Get(ctx, &balance, account)
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
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)
HasByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (found bool, err error)
// GetByAddressChainNetwork returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (*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 AccountAddressChainNetworkIndexKey struct {
vs []interface{}
}
func (x AccountAddressChainNetworkIndexKey) id() uint32 { return 1 }
func (x AccountAddressChainNetworkIndexKey) values() []interface{} { return x.vs }
func (x AccountAddressChainNetworkIndexKey) accountIndexKey() {}
func (this AccountAddressChainNetworkIndexKey) WithAddress(address string) AccountAddressChainNetworkIndexKey {
this.vs = []interface{}{address}
return this
}
func (this AccountAddressChainNetworkIndexKey) WithAddressChain(address string, chain string) AccountAddressChainNetworkIndexKey {
this.vs = []interface{}{address, chain}
return this
}
func (this AccountAddressChainNetworkIndexKey) WithAddressChainNetwork(address string, chain string, network string) AccountAddressChainNetworkIndexKey {
this.vs = []interface{}{address, chain, network}
return this
}
type accountTable struct {
table ormtable.Table
}
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) 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) HasByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (found bool, err error) {
return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx,
address,
chain,
network,
)
}
func (this accountTable) GetByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (*Account, error) {
var account Account
found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &account,
address,
chain,
network,
)
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}, nil
}
type StateStore interface {
BalanceTable() BalanceTable
AccountTable() AccountTable
doNotImplement()
}
type stateStore struct {
balance BalanceTable
account AccountTable
}
func (x stateStore) BalanceTable() BalanceTable {
return x.balance
}
func (x stateStore) AccountTable() AccountTable {
return x.account
}
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
}
return stateStore{
balanceTable,
accountTable,
}, nil
}