sandbox

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const BucketSeperator = "/"

BucketSeperator separator between bucket and raw key

View Source
const DelFlag = "\x00"

DelFlag delete flag

View Source
const (
	// TransientBucket is the name of bucket that only appears in tx output set
	// but does't persists in xmodel
	TransientBucket = "$transient"
)

Variables

View Source
var (
	// ErrHasDel is returned when key was marked as del
	ErrHasDel = errors.New("Key has been mark as del")
	// ErrNotFound is returned when key is not found
	ErrNotFound = errors.New("Key not found")
)

Functions

func IsDelFlag

func IsDelFlag(value []byte) bool

func IsEmptyVersionedData

func IsEmptyVersionedData(vd *ledger.VersionedData) bool

IsEmptyVersionedData check if VersionedData is empty

func NewUTXOReaderFromInput

func NewUTXOReaderFromInput(input []*protos.TxInput) contract.UtxoReader

func ParseContractEvents

func ParseContractEvents(tx *lpb.Transaction) ([]*protos.ContractEvent, error)

ParseContractEvents parse contract events from tx

func XMReaderFromRWSet

func XMReaderFromRWSet(rwset *contract.RWSet) ledger.XMReader

Types

type ContractIterator

type ContractIterator struct {
	ledger.XMIterator
}

ContractIterator 把contract.XMIterator转换成contract.Iterator

func (*ContractIterator) Value

func (c *ContractIterator) Value() []byte

type MemXModel

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

func NewMemXModel

func NewMemXModel() *MemXModel

func (*MemXModel) Get

func (m *MemXModel) Get(bucket string, key []byte) (*ledger.VersionedData, error)

读取一个key的值,返回的value就是有版本的data

func (*MemXModel) NewIterator

func (m *MemXModel) NewIterator() ledger.XMIterator

func (*MemXModel) Put

func (m *MemXModel) Put(bucket string, key []byte, value *ledger.VersionedData) error

func (*MemXModel) Select

func (m *MemXModel) Select(bucket string, startKey []byte, endKey []byte) (ledger.XMIterator, error)

Select 扫描一个bucket中所有的kv, 调用者可以设置key区间[startKey, endKey) start为nil意味着从bucket的第一个元素开始,end为空意味着遍历到bucket的最后一个元素

type UTXOReader

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

func (*UTXOReader) SelectUtxo

func (r *UTXOReader) SelectUtxo(from string, amount *big.Int, lock bool, excludeUnconfirmed bool) ([]*protos.TxInput, [][]byte, *big.Int, error)

type UtxoReader

type UtxoReader interface {
	SelectUtxo(string, *big.Int, bool, bool) ([]*protos.TxInput, [][]byte, *big.Int, error)
}

UtxoReader manages utxos

type XMCache

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

XMCache data structure for XModel Cache

func NewXModelCache

func NewXModelCache(cfg *contract.SandboxConfig) *XMCache

NewXModelCache new an instance of XModel Cache

func (*XMCache) AddEvent

func (xc *XMCache) AddEvent(events ...*protos.ContractEvent)

AddEvent add contract event to xmodel cache

func (*XMCache) Del

func (xc *XMCache) Del(bucket string, key []byte) error

Del delete one key from outPutCache, marked its value as `DelFlag`

func (*XMCache) Flush

func (xc *XMCache) Flush() error

WriteTransientBucket write transient bucket data. transient bucket is a special bucket used to store some data generated during the execution of the contract, but will not be referenced by other txs.

func (*XMCache) Get

func (xc *XMCache) Get(bucket string, key []byte) ([]byte, error)

Get 读取一个key的值,返回的value就是有版本的data

func (*XMCache) Put

func (xc *XMCache) Put(bucket string, key []byte, value []byte) error

Put put a pair of <key, value> into XModel Cache

func (*XMCache) RWSet

func (xc *XMCache) RWSet() *contract.RWSet

GetRWSets get read/write sets

func (*XMCache) Select

func (xc *XMCache) Select(bucket string, startKey []byte, endKey []byte) (contract.Iterator, error)

Select select all kv from a bucket, can set key range, left closed, right opend When xc.isPenetrate equals true, three-way merge, When xc.isPenetrate equals false, two-way merge

func (*XMCache) Transfer

func (xc *XMCache) Transfer(from, to string, amount *big.Int) error

// Transfer transfer tokens using utxo

func (*XMCache) UTXORWSet

func (xc *XMCache) UTXORWSet() *contract.UTXORWSet

UTXORWSet returns the inputs and outputs of utxo

Jump to

Keyboard shortcuts

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