Documentation ¶
Index ¶
- type CellCollectionIterator
- type CellIterator
- func NewLiveCellIterator(client rpc.Client, key *indexer.SearchKey) CellIterator
- func NewLiveCellIteratorByLightClient(client lightclient.Client, key *indexer.SearchKey) CellIterator
- func NewLiveCellIteratorByLightClientFromAddress(client lightclient.Client, addr string) (CellIterator, error)
- func NewLiveCellIteratorFromAddress(client rpc.Client, addr string) (CellIterator, error)
- type ChangeOutputIndex
- type CkbLiveCellGetter
- type LightClientLiveCellGetter
- type LiveCellCollectResult
- type LiveCellCollector
- type LiveCellIterator
- type LiveCellsGetter
- type OffChainInputCollector
- type OffChainInputIterator
- type OutPointWithBlockNumber
- type ScriptHandler
- type TransactionBuilder
- type TransactionInputWithBlockNumber
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CellCollectionIterator ¶
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 LightClientLiveCellGetter ¶ added in v2.0.3
type LightClientLiveCellGetter struct { Client lightclient.Client Context context.Context }
type LiveCellCollectResult ¶
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 (c *LiveCellCollector) Iterator() (CellCollectionIterator, error)
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 ¶
func (r *LiveCellIterator) Next() *types.TransactionInput
type LiveCellsGetter ¶ added in v2.0.3
type OffChainInputCollector ¶ added in v2.0.3
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
func (r *OffChainInputIterator) Next() *types.TransactionInput
type OutPointWithBlockNumber ¶ added in v2.0.3
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 }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.