contract

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContractDuplicated = errors.New("contract is duplicated")
	ErrContractNotFound   = errors.New("contract not found")
)

pre-define errors for supporting bytom errorFormatter

Functions

This section is empty.

Types

type ChainService

type ChainService interface {
	BestChain() (uint64, bc.Hash)
	FinalizedHeight() uint64
	GetBlockByHash(*bc.Hash) (*types.Block, error)
	GetBlockByHeight(uint64) (*types.Block, error)
	BlockWaiter(height uint64) <-chan struct{}
}

type ChainStatus

type ChainStatus struct {
	BlockHeight uint64  `json:"block_height"`
	BlockHash   bc.Hash `json:"block_hash"`
}

type Contract

type Contract struct {
	Hash            chainjson.HexBytes `json:"id"`
	Alias           string             `json:"alias"`
	Contract        chainjson.HexBytes `json:"contract"`
	CallProgram     chainjson.HexBytes `json:"call_program"`
	RegisterProgram chainjson.HexBytes `json:"register_program"`
}

Contract describe user contract

type Infrastructure

type Infrastructure struct {
	Chain      ChainService
	Repository Repository
}

func NewInfrastructure

func NewInfrastructure(chain ChainService, repository Repository) *Infrastructure

type Instance

type Instance struct {
	TraceID       string   `json:"trace_id"`
	UTXOs         []*UTXO  `json:"utxos"`
	TxHash        *bc.Hash `json:"tx_hash"`
	Status        Status   `json:"status"`
	EndedHeight   uint64   `json:"ended_height"`
	ScannedHash   bc.Hash  `json:"scanned_hash"`
	ScannedHeight uint64   `json:"scanned_height"`
	Unconfirmed   []*TreeNode
}

type Registry

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

Registry tracks and stores all user contract.

func NewRegistry

func NewRegistry(db dbm.DB) *Registry

NewRegistry create new registry

func (*Registry) GetContract

func (reg *Registry) GetContract(hash chainjson.HexBytes) (*Contract, error)

GetContract get user contract

func (*Registry) ListContracts

func (reg *Registry) ListContracts() ([]*Contract, error)

ListContracts returns user contracts

func (*Registry) SaveContract

func (reg *Registry) SaveContract(contract *Contract) error

SaveContract save user contract

func (*Registry) UpdateContract

func (reg *Registry) UpdateContract(hash chainjson.HexBytes, alias string) error

UpdateContract updates user contract alias

type Repository

type Repository interface {
	GetInstance(traceID string) (*Instance, error)
	LoadInstances() ([]*Instance, error)
	SaveInstances(instances []*Instance) error
	SaveInstancesWithStatus(instances []*Instance, blockHeight uint64, blockHash bc.Hash) error
	RemoveInstance(traceID string)
	GetChainStatus() *ChainStatus
	SaveChainStatus(status *ChainStatus) error
}

type Status

type Status uint8
const (
	Lagging Status = iota + 1
	InSync
	Ended
	OffChain
)

type TraceService

type TraceService struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTraceService

func NewTraceService(infra *Infrastructure) *TraceService

func (*TraceService) AddUnconfirmedTx

func (t *TraceService) AddUnconfirmedTx(tx *types.Tx)

func (*TraceService) ApplyBlock

func (t *TraceService) ApplyBlock(block *types.Block) error

func (*TraceService) BestHash

func (t *TraceService) BestHash() bc.Hash

func (*TraceService) BestHeight

func (t *TraceService) BestHeight() uint64

func (*TraceService) CreateInstance

func (t *TraceService) CreateInstance(txHash, blockHash bc.Hash) ([]string, error)

func (*TraceService) DetachBlock

func (t *TraceService) DetachBlock(block *types.Block) error

func (*TraceService) GetInstance

func (t *TraceService) GetInstance(traceID string) (*Instance, error)

func (*TraceService) RemoveInstance

func (t *TraceService) RemoveInstance(traceID string) error

type TraceStore

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

func NewTraceStore

func NewTraceStore(db dbm.DB) *TraceStore

func (*TraceStore) GetChainStatus

func (t *TraceStore) GetChainStatus() *ChainStatus

GetChainStatus return the current chain status

func (*TraceStore) GetInstance

func (t *TraceStore) GetInstance(traceID string) (*Instance, error)

GetInstance return instance by given trace id

func (*TraceStore) LoadInstances

func (t *TraceStore) LoadInstances() ([]*Instance, error)

LoadInstances used to load all instances in db

func (*TraceStore) RemoveInstance

func (t *TraceStore) RemoveInstance(traceID string)

RemoveInstance delete a instance by given trace id

func (*TraceStore) SaveChainStatus

func (t *TraceStore) SaveChainStatus(chainStatus *ChainStatus) error

SaveChainStatus save the chain status

func (*TraceStore) SaveInstances

func (t *TraceStore) SaveInstances(instances []*Instance) error

SaveInstances used to batch save multiple instances

func (*TraceStore) SaveInstancesWithStatus

func (t *TraceStore) SaveInstancesWithStatus(instances []*Instance, blockHeight uint64, blockHash bc.Hash) error

SaveInstancesWithStatus batch save the instances and chain status

type TraceUpdater

type TraceUpdater struct {
	*TraceService
	// contains filtered or unexported fields
}

func NewTraceUpdater

func NewTraceUpdater(traceService *TraceService, chain ChainService) *TraceUpdater

func (*TraceUpdater) Sync

func (t *TraceUpdater) Sync()

type TreeNode

type TreeNode struct {
	TxHash   bc.Hash     `json:"tx_hash"`
	UTXOs    []*UTXO     `json:"utxos"`
	Children []*TreeNode `json:"children"`
}

type UTXO

type UTXO struct {
	Hash      bc.Hash    `json:"hash"`
	AssetID   bc.AssetID `json:"asset_id"`
	Amount    uint64     `json:"amount"`
	Program   []byte     `json:"program"`
	SourceID  bc.Hash    `json:"source_id"`
	SourcePos uint64     `json:"source_pos"`
	StateData [][]byte   `json:"state_data"`
}

Jump to

Keyboard shortcuts

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