db

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SeqTypeAdd = 1
	SeqTypeDel = 2
)

SeqType

View Source
const (
	OpAdd    = 1
	OpDel    = 2
	OpUpdate = 3
)

DB operator

View Source
const (
	DatabaseTypeEs        = 1
	DatabaseTypeChainJRPC = 2
	DatabaseTypeChainGRPC = 3
)

DB Type

View Source
const (
	//修改Mapping去掉了Type
	SeqMapping = `` /* 128-byte string literal not displayed */

	LastSeqDB   = "last_seq"
	DefaultType = "_doc"
)

convert seq

View Source
const (
	NormalAddressID = 0
	EthAddressID    = 2
)

Variables

View Source
var (
	ErrDBNotFound         = errors.New("DB Not Found")
	ErrDBBadParam         = errors.New("DB Bad Param")
	ErrDBInvalidOperation = errors.New("DB invalid operation")
)

ErrDBNotFound DB Not Found

View Source
var (
	DefaultAddrID int32
)

Functions

func CalcParaTitle

func CalcParaTitle(title string) string

CalcParaTitle 计算exec的前缀

func ExecAddress

func ExecAddress(name string) string

ExecAddress 获得执行器地址

func Hash160AddressToString

func Hash160AddressToString(addr pcom.Hash160Address) string

Hash160AddressToString 将Hash160格式的地址转换为string格式

func HeightIndex

func HeightIndex(height, index int64) int64

HeightIndex HeightIndex

func SetAddrID

func SetAddrID(addrDriver string)

func SetVersion

func SetVersion(v int32)

Types

type Block

type Block struct {
	Height      int64  `json:"height"`
	Ts          int64  `json:"ts"`
	BlockHash   string `json:"block_hash"`
	Index       int64  `json:"index"`
	Send        string `json:"send"`
	TxHash      string `json:"tx_hash"`
	HeightIndex int64  `json:"height_index"`
}

Block info

func NewBlock

func NewBlock(env *TxEnv) *Block

NewBlock New

func NewBlockByTxDetail

func NewBlockByTxDetail(txd *rpctypes.TransactionDetail) *Block

NewBlockByTxDetail New

func NewBlockByTxDetail2

func NewBlockByTxDetail2(txd *types.TransactionDetail) *Block

NewBlockByTxDetail2 New

func SetupBlock

func SetupBlock(env *TxEnv, from, txHash string) *Block

SetupBlock set into to block

type Convert

type Convert interface {
	ConvertTx(env *TxEnv, op int) ([]Record, error)
}

Convert for tx convert

type DBCreator

type DBCreator interface {
	Exists(name string) (bool, error)
	Create(name string, table, definition string) (bool, error)
	Delete(name string) (bool, error)
	GetVersion() int32
}

DBCreator DBCreator nolint

type DBSaver

type DBSaver interface {
	InitDB(DBCreator) error
}

DBSaver DBSaver nolint

type ExecConvert

type ExecConvert interface {
	Convert
	DBSaver
}

ExecConvert with db part 下阶段再分开, 可以配置不同的存储

type IKey

type IKey struct {
	// contains filtered or unexported fields
}

IKey impl Key

func NewIKey

func NewIKey(index, typ, id string) *IKey

NewIKey create key

func (*IKey) ID

func (d *IKey) ID() string

ID impl Key

func (*IKey) Index

func (d *IKey) Index() string

Index impl Key

func (*IKey) Key

func (d *IKey) Key() string

Key impl Key

func (*IKey) Type

func (d *IKey) Type() string

Type impl Key

type Key

type Key interface {
	Index() string
	Type() string
	ID() string
	Key() string
}

Key 获得相关的key

type ListKV

type ListKV struct {
	Key   string
	Value interface{}
}

ListKV ListKV

type NeedWrapDB

type NeedWrapDB interface {
	SetDB(w WrapDB) error
}

NeedWrapDB 看插件是否需要数据库

type Op

type Op struct {
	// contains filtered or unexported fields
}

Op impl Op

func NewOp

func NewOp(t int) *Op

NewOp create Op

func (*Op) OpType

func (d *Op) OpType() int

Op impl Op

type Operator

type Operator interface {
	OpType() int
}

Operator for db Operator

type Record

type Record interface {
	Key
	Operator
	Value() []byte
}

Record 要保存到外部数据的数据结构都要满足这个接口

type SourceAbleRecord

type SourceAbleRecord interface {
	Record
	Source() interface{}
}

type TxEnv

type TxEnv struct {
	Block     *types.BlockDetail
	TxIndex   int64
	BlockHash string
}

TxEnv record block info

type WrapDB

type WrapDB interface {
	Get(k1, k2, id string) (*json.RawMessage, error)
	List(k1, k2 string, keyValue []*ListKV) ([]*json.RawMessage, error)
	Set(k1, k2, id string, r Record) error
	Search(idx, typ string, query *querypara.Query, decode func(x *json.RawMessage) (interface{}, error)) ([]interface{}, error)
}

WrapDB 满足虚拟合约执行时访问数据库的要求. 虚拟合约 由于不在链上执行, 插件需要有一定的业务逻辑, 对业务逻辑的处理需要依赖于现有数据 所以需要插件能访问数据库, 目前的逻辑可以通过 Set/Get 来完成. 如果需要更复杂的方式可以扩展这个接口

Jump to

Keyboard shortcuts

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