client

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GrantWriter = "writer"
	GrantReader = "reader"
	GrantOwner  = "admin"
)
View Source
const DefaultChainEndpoint = "https://api.xian.glitter.link"

Variables

Functions

This section is empty.

Types

type CreateTxOptions

type CreateTxOptions struct {
	Msgs []msg.Msg
	Memo string

	// Optional parameters
	AccountNumber uint64
	Sequence      uint64
	GasLimit      uint64
	FeeAmount     msg.Coins

	SignMode      tx.SignMode
	FeeGranter    msg.AccAddress
	TimeoutHeight uint64
}

CreateTxOptions tx creation options

type EncodingConfig

type EncodingConfig struct {
	InterfaceRegistry types.InterfaceRegistry
	Marshaller        codec.Codec
	TxConfig          client.TxConfig
	Amino             *codec.LegacyAmino
}

func MakeEncodingConfig

func MakeEncodingConfig(mb module.BasicManager) EncodingConfig

MakeEncodingConfig creates an EncodingConfig for testing

type LCDClient

type LCDClient struct {
	URL           string
	ChainID       string
	GasPrice      msg.DecCoin
	GasAdjustment msg.Dec

	PrivKey        key.PrivKey
	EncodingConfig EncodingConfig
	// contains filtered or unexported fields
}

LCDClient outer interface for building & signing & broadcasting tx

func New

func New(chainID string, privateKey key.PrivKey, options ...Option) *LCDClient

New create new Glitter client

func (*LCDClient) BatchInsert

func (lcd *LCDClient) BatchInsert(ctx context.Context, db, table string, columns []string, rowValues [][]interface{}) (*sdk.TxResponse, error)

BatchInsert insert multiple rows into the specified table using the provided column names and row values Args:

  • db: The database name
  • table: The table name
  • rows: A list of rows to insert, each row is a dict of column names to values

Returns: The result of executing the batch INSERT statement

func (*LCDClient) Broadcast

func (lcd *LCDClient) Broadcast(ctx context.Context, txbuilder *tx.Builder) (*sdk.TxResponse, error)

Broadcast transaction

func (*LCDClient) CreateAndSignTx

func (lcd *LCDClient) CreateAndSignTx(ctx context.Context, options CreateTxOptions) (*tx.Builder, error)

CreateAndSignTx build and sign tx

func (*LCDClient) CreateDatabase

func (lcd *LCDClient) CreateDatabase(ctx context.Context, database string) (*sdk.TxResponse, error)

CreateDatabase Create a new database with the specified name Args: - database: The name of the database to create

Returns: The result of executing the SQL CREATE DATABASE statement

func (*LCDClient) CreateTable

func (lcd *LCDClient) CreateTable(ctx context.Context, sql string) (*sdk.TxResponse, error)

CreateTable Creates a new table in the database using the provided SQL DDL statement. table name must be a full path format <database>.<table> Args: - sql: The SQL statement to create a new table

Returns: The result of executing the SQL statement

func (*LCDClient) Delete

func (lcd *LCDClient) Delete(ctx context.Context, db, table string, where map[string]interface{}, orderBy string, asc bool, limit int) (*sdk.TxResponse, error)

Delete rows from the specified table based on the provided conditions Args:

  • db: The database name
  • table: The table name
  • where: Condition to match rows to delete
  • order_by: Column to order deletion
  • asc: Sort order ascending if True
  • limit: Max number of rows to delete

Returns: The result of executing the DELETE statement

func (*LCDClient) DropDatabase

func (lcd *LCDClient) DropDatabase(ctx context.Context, db, table string) (*sdk.TxResponse, error)

DropDatabase Drop (deletes) the specified database Args:

  • database: The database name

Returns: The result of executing the SQL DROP DATABASE statement

func (*LCDClient) DropTable

func (lcd *LCDClient) DropTable(ctx context.Context, db, table string) (*sdk.TxResponse, error)

DropTable Drop (deletes) a table from the specified database Args:

  • database: The database name
  • table: The table name

Returns: The result of executing the SQL DROP TABLE statement

func (*LCDClient) GetAddress

func (lcd *LCDClient) GetAddress() msg.AccAddress

GetAddress get account address

func (*LCDClient) GetMarshaler

func (lcd *LCDClient) GetMarshaler() codec.Codec

func (*LCDClient) GetTxConfig

func (lcd *LCDClient) GetTxConfig() client.TxConfig

func (*LCDClient) GrantAdmin

func (lcd *LCDClient) GrantAdmin(ctx context.Context, onDatabase string, onTable string, toUID string) (*sdk.TxResponse, error)

GrantAdmin (admin) permissions on the specified table to the specified user Args:

  • toUID: Address to grant access
  • onDatabase: SQL database name
  • onTable: SQL table name, optional

Returns: Result of grant transaction

func (*LCDClient) GrantReader

func (lcd *LCDClient) GrantReader(ctx context.Context, onDatabase string, onTable string, toUID string) (*sdk.TxResponse, error)

GrantReader (select) permissions on the specified table to the specified user Args:

  • toUID: Address to grant access
  • onDatabase: SQL database name
  • onTable: SQL table name, optional

Returns: Result of grant transaction

func (*LCDClient) GrantWriter

func (lcd *LCDClient) GrantWriter(ctx context.Context, onDatabase string, onTable string, toUID string) (*sdk.TxResponse, error)

GrantWriter (insert/update/delete) permissions on the specified table to the specified user Args:

  • toUID: Address to grant access
  • onDatabase: SQL database name
  • onTable: SQL table name, optional

Returns: Result of grant transaction

func (*LCDClient) Insert

func (lcd *LCDClient) Insert(ctx context.Context, db, table string, columns map[string]interface{}) (*sdk.TxResponse, error)

Insert a new row into the specified table with the provided column-value pairs Args:

  • db: The database name
  • table: The table name
  • columns: A dictionary of column names and values to insert

Returns: The result of executing the INSERT statement

func (*LCDClient) ListDatabases

func (lcd *LCDClient) ListDatabases(ctx context.Context, creator string) (res *glittertypes.SQLListDatabasesResponse, err error)

ListDatabases List all databases or filter by creator in glitter Args:

  • creator (optional): Only return databases created by this creator

Returns: ListDatabasesResponse containing matching databases

func (*LCDClient) ListTables

func (lcd *LCDClient) ListTables(ctx context.Context, tableKeyword, uid, database string, page, pageSize *int) (res *glittertypes.SQLListTablesResponse, err error)

ListTables List tables in glitter, filtering by various criteria Args:

  • tableKeyword: Filter tables by keyword
  • uid: Filter tables by creator uid
  • database: Filter tables by database name
  • page: Page number for pagination
  • pageSize: Number of results per page

Returns: ListTablesResponse containing matching tables

func (*LCDClient) LoadAccount

func (lcd *LCDClient) LoadAccount(ctx context.Context, address msg.AccAddress) (res authtypes.AccountI, err error)

LoadAccount simulates gas and fee for a transaction

func (*LCDClient) Query

func (lcd *LCDClient) Query(ctx context.Context, sql string, args ...*glittertypes.Argument) (res *glittertypes.SQLQueryResponse, err error)

Query execute a SQL query statement Args:

  • sql: The SQL query string
  • args: Optional list of arguments to substitute into the query

Returns: A list of rows where each row is a dict mapping column name to value

func (*LCDClient) QueryScan

func (lcd *LCDClient) QueryScan(ctx context.Context, target interface{}, sql string, args ...*glittertypes.Argument) error

QueryScan execute a SQL query statement and scan result to target Args:

  • target: Target to scan result values
  • sql: The SQL query string
  • args: Optional list of arguments to substitute into the query

Returns: A list of rows where each row is a dict mapping column name to value

func (*LCDClient) SQLExec

func (lcd *LCDClient) SQLExec(ctx context.Context, sql string, args []*glittertypes.Argument) (*sdk.TxResponse, error)

SQLExec Execute a SQL Args: sql: SQL statement to execute args: Parameters of the SQL statement, default to None Returns: Transaction information of the SQL execution

func (*LCDClient) SQLExecWithOptions

func (lcd *LCDClient) SQLExecWithOptions(ctx context.Context, options CreateTxOptions, sql string, args []*glittertypes.Argument) (*sdk.TxResponse, error)

SQLExecWithOptions Execute a SQL with options Args: sql: SQL statement to execute args: Parameters of the SQL statement, default to None Returns: Transaction information of the SQL execution

func (*LCDClient) SQLGrant

func (lcd *LCDClient) SQLGrant(ctx context.Context, onDatabase string, onTable string, toUID string, role string) (*sdk.TxResponse, error)

SQLGrant Grant database or table access permission Args:

  • toUID: Address to grant access to
  • role: SQL role name
  • onDatabase: SQL database name
  • onTable: SQL table name, optional (Grant authorization to the table if specified, otherwise grant authorization to the database)

Returns: Result of broadcasting grant transaction

func (*LCDClient) ShowCreateTable

func (lcd *LCDClient) ShowCreateTable(ctx context.Context, database string, table string) (res *glittertypes.ShowCreateTableResponse, err error)

ShowCreateTable Show the CREATE TABLE statement for an existing table Args: - database: The database name - table: The table name

Returns: The result containing the CREATE TABLE statement

func (*LCDClient) SignAndBroadcastTX

func (lcd *LCDClient) SignAndBroadcastTX(ctx context.Context, options CreateTxOptions) (*sdk.TxResponse, error)

SignAndBroadcastTX sign and broadcast transaction

func (*LCDClient) Simulate

func (lcd *LCDClient) Simulate(ctx context.Context, txbuilder tx.Builder, options CreateTxOptions) (*sdktx.SimulateResponse, error)

Simulate tx and get response

func (*LCDClient) Update

func (lcd *LCDClient) Update(ctx context.Context, db, table string, columns map[string]interface{}, where map[string]interface{}) (*sdk.TxResponse, error)

Update rows in the specified table with the provided column-value pairs based on the specified conditions Args:

  • db: The database name
  • table: The table name
  • columnsValue: A dictionary of column names and updated values
  • where: A dictionary of column names and values to match

Returns: The result of executing the UPDATE statement

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithChainEndpoint

func WithChainEndpoint(endpoint string) Option

WithChainEndpoint create client with custom chain endpoint

func WithGasFeeConfig

func WithGasFeeConfig(gasPrice msg.DecCoin, gasAdjustment msg.Dec) Option

WithGasFeeConfig create client with custom gas fee config

func WithTimeout

func WithTimeout(duration time.Duration) Option

WithTimeout create client with http timeout

type QueryAccountRes

type QueryAccountRes struct {
	Account QueryAccountResData `json:"account"`
}

QueryAccountRes response

type QueryAccountResData

type QueryAccountResData struct {
	Address       msg.AccAddress `json:"address"`
	AccountNumber msg.Int        `json:"account_number"`
	Sequence      msg.Int        `json:"sequence"`
}

QueryAccountResData response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL