collector

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 9 Imported by: 4

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CellCollectionIterator

type CellCollectionIterator interface {
	HasNext() bool
	Next() error
	CurrentItem() (*indexer.LiveCell, error)
	Iterator() (CellCollectionIterator, error)
}

type CellIterator

type CellIterator interface {
	HasNext() bool
	Next() *types.TransactionInput
}

func NewLiveCellIterator

func NewLiveCellIterator(client rpc.Client, key *indexer.SearchKey) CellIterator

func NewLiveCellIteratorByLightClient added in v2.0.3

func NewLiveCellIteratorByLightClient(client lightclient.Client, key *indexer.SearchKey) CellIterator

func NewLiveCellIteratorByLightClientFromAddress added in v2.0.3

func NewLiveCellIteratorByLightClientFromAddress(client lightclient.Client, addr string) (CellIterator, error)

func NewLiveCellIteratorFromAddress

func NewLiveCellIteratorFromAddress(client rpc.Client, addr string) (CellIterator, error)

type ChangeOutputIndex

type ChangeOutputIndex struct {
	Value int
}

type CkbLiveCellGetter added in v2.0.3

type CkbLiveCellGetter struct {
	Client  rpc.Client
	Context context.Context
}

func (*CkbLiveCellGetter) GetCells added in v2.0.3

func (c *CkbLiveCellGetter) GetCells(searchKey *indexer.SearchKey, order indexer.SearchOrder, limit uint64, afterCursor string) (*indexer.LiveCells, error)

type LightClientLiveCellGetter added in v2.0.3

type LightClientLiveCellGetter struct {
	Client  lightclient.Client
	Context context.Context
}

func (*LightClientLiveCellGetter) GetCells added in v2.0.3

func (c *LightClientLiveCellGetter) GetCells(searchKey *indexer.SearchKey, order indexer.SearchOrder, limit uint64, afterCursor string) (*indexer.LiveCells, error)

type LiveCellCollectResult

type LiveCellCollectResult struct {
	LiveCells []*indexer.LiveCell
	Capacity  uint64
	Options   map[string]interface{}
}

type LiveCellCollector

type LiveCellCollector struct {
	Client      rpc.Client
	SearchKey   *indexer.SearchKey
	SearchOrder indexer.SearchOrder
	Limit       uint64
	LastCursor  string
	EmptyData   bool
	TypeScript  *types.Script
	// contains filtered or unexported fields
}

func NewLiveCellCollector

func NewLiveCellCollector(client rpc.Client, searchKey *indexer.SearchKey, searchOrder indexer.SearchOrder, limit uint64, afterCursor string) *LiveCellCollector

func (*LiveCellCollector) CurrentItem

func (c *LiveCellCollector) CurrentItem() (*indexer.LiveCell, error)

func (*LiveCellCollector) HasNext

func (c *LiveCellCollector) HasNext() bool

func (*LiveCellCollector) Iterator

func (*LiveCellCollector) Next

func (c *LiveCellCollector) Next() error

type LiveCellIterator

type LiveCellIterator struct {
	LiveCellGetter LiveCellsGetter
	SearchKey      *indexer.SearchKey
	SearchOrder    indexer.SearchOrder
	Limit          uint64
	// contains filtered or unexported fields
}

func (*LiveCellIterator) HasNext

func (r *LiveCellIterator) HasNext() bool

func (*LiveCellIterator) Next

type LiveCellsGetter added in v2.0.3

type LiveCellsGetter interface {
	GetCells(searchKey *indexer.SearchKey, order indexer.SearchOrder, limit uint64, afterCursor string) (*indexer.LiveCells, error)
}

type OffChainInputCollector added in v2.0.3

type OffChainInputCollector struct {
	Client rpc.Client
	// contains filtered or unexported fields
}

func NewOffChainInputCollector added in v2.0.3

func NewOffChainInputCollector(Client rpc.Client) *OffChainInputCollector

func (*OffChainInputCollector) ApplyOffChainTransaction added in v2.0.3

func (c *OffChainInputCollector) ApplyOffChainTransaction(tipBlockNumber uint64, transaction types.Transaction)

type OffChainInputIterator added in v2.0.3

type OffChainInputIterator struct {
	Iterator                    *LiveCellIterator
	Collector                   *OffChainInputCollector
	ConsumeOffChainCellsFirstly bool
	// contains filtered or unexported fields
}

func NewOffChainInputIterator added in v2.0.3

func NewOffChainInputIterator(iterator CellIterator, collector *OffChainInputCollector, consumeOffChainCellsFirstly bool) *OffChainInputIterator

func NewOffChainInputIteratorFromAddress added in v2.0.3

func NewOffChainInputIteratorFromAddress(client rpc.Client, addr string, collector *OffChainInputCollector, consumeOffChainCellsFirstly bool) (*OffChainInputIterator, error)

func (*OffChainInputIterator) GetLiveCells added in v2.0.3

func (r *OffChainInputIterator) GetLiveCells(searchKey *indexer.SearchKey, order indexer.SearchOrder, limit uint64, afterCursor string) (*indexer.LiveCells, error)

func (*OffChainInputIterator) HasNext added in v2.0.3

func (r *OffChainInputIterator) HasNext() bool

func (*OffChainInputIterator) Next added in v2.0.3

type OutPointWithBlockNumber added in v2.0.3

type OutPointWithBlockNumber struct {
	*types.OutPoint
	// contains filtered or unexported fields
}

type ScriptHandler

type ScriptHandler interface {
	BuildTransaction(builder TransactionBuilder, group *transaction.ScriptGroup, context interface{}) (bool, error)
}

The interface ScriptHandler is for scripts to register their building logic.

The function BuildTransaction is the callback called by TransactionBuilder for each script group and each context passed in TransactionBuilder.Build. The context provides extra data for the script.

Be calfully on when to run the logic for the script. TransactionBuilder will not check whether the script group matches the script.

The callback often does two things:

  • Fill witness placeholder to make fee calculation correct.
  • Add cell deps for the script.

Returns bool indicating whether the transaction has been modified.

Example
package main

import (
	"reflect"

	"github.com/nervosnetwork/ckb-sdk-go/v2/collector"
	"github.com/nervosnetwork/ckb-sdk-go/v2/collector/builder"
	"github.com/nervosnetwork/ckb-sdk-go/v2/transaction"
	"github.com/nervosnetwork/ckb-sdk-go/v2/types"
)

// SimpleLockScriptHandler is an example script handler to add specified cell dep and prefill the witness.
type SimpleLockScriptHandler struct {
	CellDep            *types.CellDep
	WitnessPlaceholder []byte
	CodeHash           types.Hash
}

func (r *SimpleLockScriptHandler) isMatched(script *types.Script) bool {
	if script == nil {
		return false
	}
	return reflect.DeepEqual(script.CodeHash, r.CodeHash)
}

func (r *SimpleLockScriptHandler) BuildTransaction(builder collector.TransactionBuilder, group *transaction.ScriptGroup, context interface{}) (bool, error) {
	// Only run on matched groups
	if group == nil || !r.isMatched(group.Script) {
		return false, nil
	}
	index := group.InputIndices[0]
	// set the witness placeholder
	if err := builder.SetWitness(uint(index), types.WitnessTypeLock, r.WitnessPlaceholder); err != nil {
		return false, err
	}
	// CkbTransactionBuilder.AddCellDep will remove duplications automatically.
	builder.AddCellDep(r.CellDep)
	return true, nil
}

func main() {
	txHash := "0x1234"
	typeScriptHash := "0xabcd"

	s := builder.SimpleTransactionBuilder{}
	s.Register(&SimpleLockScriptHandler{
		CellDep: &types.CellDep{
			OutPoint: &types.OutPoint{
				TxHash: types.HexToHash(txHash),
				Index:  0,
			},
			DepType: types.DepTypeCode,
		},
		CodeHash:           types.HexToHash(typeScriptHash),
		WitnessPlaceholder: make([]byte, 8),
	})
}
Output:

type TransactionBuilder

type TransactionBuilder interface {
	SetVersion(version uint32)
	AddHeaderDep(headerDep types.Hash) int
	AddCellDep(cellDep *types.CellDep) int
	AddInput(input *types.CellInput) int
	SetSince(index uint, since uint64) error
	AddOutput(output *types.CellOutput, data []byte) int
	SetOutputData(index uint, data []byte) error
	SetWitness(index uint, witnessType types.WitnessType, data []byte) error
	AddScriptGroup(group *transaction.ScriptGroup) int
	Build(contexts ...interface{}) (*transaction.TransactionWithScriptGroups, error)
}

type TransactionInputWithBlockNumber added in v2.0.3

type TransactionInputWithBlockNumber struct {
	types.TransactionInput
	// contains filtered or unexported fields
}

Directories

Path Synopsis
Package builder implements CKB transaction builder.
Package builder implements CKB transaction builder.

Jump to

Keyboard shortcuts

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