common

package
v0.0.0-...-dd0ed3b Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAddressLength = errors.New("unexpected address length")

Functions

func Address20ToBytes

func Address20ToBytes(addr string) ([]byte, error)

func Address32ToBytes

func Address32ToBytes(addr string) ([]byte, error)

func AddressToBytes

func AddressToBytes(addr string) ([]byte, error)

func AddressToString

func AddressToString(addr []byte) string

func AssertLength

func AssertLength(addr []byte, l int) error

func Check

func Check(err error)

func Check2

func Check2(err error)

func CheckResponse

func CheckResponse(resp *http.Response, err error) error

func ConcatBytes

func ConcatBytes(srcs ...[]byte) []byte

func CopyAndSumCode

func CopyAndSumCode(r io.Reader) ([]byte, *bytes.Buffer, error)

func CreateRequestBody

func CreateRequestBody(f io.Reader) (*bytes.Buffer, string, error)

func DecodeBalance

func DecodeBalance(b []byte) uint64

func DownloadCode

func DownloadCode(url string, retry int) (*http.Response, error)

func DownloadCodeIfRequired

func DownloadCodeIfRequired(codeDir string, codeID, data []byte) error

func DumpFile

func DumpFile(data []byte, directory, file string)

func EncodeBalance

func EncodeBalance(value uint64) []byte

func Exists

func Exists(path string) bool

func GetCodeAddr

func GetCodeAddr(key string) []byte

func GetRequestWithRetry

func GetRequestWithRetry(url string) (*http.Response, error)

func RegisterCode

func RegisterCode(key string, addr []byte)

func StoreCode

func StoreCode(codeDir string, r io.Reader) ([]byte, error)

func ValidLength

func ValidLength(addr []byte) error

func WriteCodeFile

func WriteCodeFile(codeDir string, codeID []byte, r io.Reader) error

Types

type CallContext

type CallContext interface {
	Sender() []byte
	BlockHash() []byte
	BlockHeight() uint64
	Input() []byte

	GetState(key []byte) []byte
	SetState(key, value []byte)
}

type CallContextQuery

type CallContextQuery struct {
	StateGetter
	RawInput  []byte
	RawSender []byte
}

func (*CallContextQuery) BlockHash

func (ctx *CallContextQuery) BlockHash() []byte

func (*CallContextQuery) BlockHeight

func (ctx *CallContextQuery) BlockHeight() uint64

func (*CallContextQuery) Input

func (ctx *CallContextQuery) Input() []byte

func (*CallContextQuery) Sender

func (ctx *CallContextQuery) Sender() []byte

func (*CallContextQuery) SetState

func (ctx *CallContextQuery) SetState(key, value []byte)

type CallContextTx

type CallContextTx struct {
	*StateTracker
	Block       *core.Block
	Transaction *core.Transaction
	RawSender   []byte
	RawInput    []byte
}

func (*CallContextTx) BlockHash

func (ctx *CallContextTx) BlockHash() []byte

func (*CallContextTx) BlockHeight

func (ctx *CallContextTx) BlockHeight() uint64

func (*CallContextTx) Input

func (ctx *CallContextTx) Input() []byte

func (*CallContextTx) Sender

func (ctx *CallContextTx) Sender() []byte

type Chaincode

type Chaincode interface {
	// Init is called when chaincode is deployed
	Init(ctx CallContext) error
	Invoke(ctx CallContext) error
	Query(ctx CallContext) ([]byte, error)
	// SetTxTrk is used only for evm runner
	SetTxTrk(txTrk *StateTracker)
}

Chaincode all chaincodes implements this interface

type CodeDriver

type CodeDriver interface {
	// Install is called when code deployment transaction is received
	// Example data field - download url for code binary
	// After successful Install, getInstance should give a Chaincode instance without error
	Install(codeID, data []byte) error
	GetInstance(codeID []byte) (Chaincode, error)
}

type CodeInfo

type CodeInfo struct {
	DriverType DriverType `json:"driverType"`
	CodeID     []byte     `json:"codeID"`
}

type DeploymentInput

type DeploymentInput struct {
	CodeInfo    CodeInfo `json:"codeInfo"`
	InstallData []byte   `json:"installData"`
	InitInput   []byte   `json:"initInput"`
}

type DriverType

type DriverType uint8
const (
	DriverTypeNative DriverType = iota + 1
	DriverTypeBincc
	DriverTypeEVM
)

type MemStateStore

type MemStateStore struct {
	Storage storage.PersistStore
}

func NewMemStateStore

func NewMemStateStore() *MemStateStore

func (*MemStateStore) GetState

func (store *MemStateStore) GetState(key []byte) []byte

func (*MemStateStore) SetState

func (store *MemStateStore) SetState(key, value []byte)

func (*MemStateStore) VerifyState

func (store *MemStateStore) VerifyState(key []byte) []byte

type MockCallContext

type MockCallContext struct {
	*MemStateStore
	MockSender      []byte
	MockBlockHeight uint64
	MockBlockHash   []byte
	MockInput       []byte
}

func (*MockCallContext) BlockHash

func (wc *MockCallContext) BlockHash() []byte

func (*MockCallContext) BlockHeight

func (wc *MockCallContext) BlockHeight() uint64

func (*MockCallContext) Input

func (wc *MockCallContext) Input() []byte

func (*MockCallContext) Sender

func (wc *MockCallContext) Sender() []byte

type QueryData

type QueryData struct {
	CodeAddr []byte `json:"codeAddr"`
	Input    []byte `json:"input"`
	Sender   []byte `json:"sender"`
}

type StateGetter

type StateGetter interface {
	GetState(key []byte) []byte
}

type StateStore

type StateStore interface {
	VerifyState(key []byte) []byte
	GetState(key []byte) []byte
}

type StateTracker

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

StateTracker tracks state changes in key order get latest changed state for each key get state from base state getter if no changes occured for a key

func NewStateTracker

func NewStateTracker(state StateGetter, keyPrefix []byte) *StateTracker

func (*StateTracker) GetState

func (trk *StateTracker) GetState(key []byte) []byte

func (*StateTracker) GetStateChanges

func (trk *StateTracker) GetStateChanges() []*core.StateChange

func (*StateTracker) HasDependencyChanges

func (trk *StateTracker) HasDependencyChanges(child *StateTracker) bool

func (*StateTracker) Merge

func (trk *StateTracker) Merge(child *StateTracker)

func (*StateTracker) SetState

func (trk *StateTracker) SetState(key, value []byte)

func (*StateTracker) Spawn

func (trk *StateTracker) Spawn(keyPrefix []byte) *StateTracker

Spawn creates a new tracker with current tracker as base StateGetter

Jump to

Keyboard shortcuts

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