Skip to content

Commit

Permalink
Complete ckb-sdk-go missing rpc
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Dec 16, 2024
1 parent 5f52557 commit 7ce104a
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 57 deletions.
12 changes: 6 additions & 6 deletions collector/builder/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func NewDaoTransactionBuilder(network types.Network, iterator collector.CellIter
depositCellCapacity := uint64(0)
reward := uint64(0)
if transactionType == DaoTransactionTypeWithdraw {
txWithStatus, err := client.GetTransaction(context.Background(), daoOutPoint.TxHash, nil)
txWithStatus, err := client.GetTransaction(context.Background(), daoOutPoint.TxHash, nil, nil)
if err != nil {
return nil, err
}
header, err := client.GetHeader(context.Background(), *txWithStatus.TxStatus.BlockHash)
header, err := client.GetHeader(context.Background(), *txWithStatus.TxStatus.BlockHash, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func getTransactionType(outputData []byte) (DaoTransactionType, error) {
}

func getDaoReward(withdrawOutPoint *types.OutPoint, client rpc.Client) (uint64, error) {
txWithStatus, err := client.GetTransaction(context.Background(), withdrawOutPoint.TxHash, nil)
txWithStatus, err := client.GetTransaction(context.Background(), withdrawOutPoint.TxHash, nil, nil)
if err != nil {
return 0, err
}
Expand All @@ -107,7 +107,7 @@ func getDaoReward(withdrawOutPoint *types.OutPoint, client rpc.Client) (uint64,
)
for i := 0; i < len(withdrawTx.Inputs); i++ {
outPoint := withdrawTx.Inputs[i].PreviousOutput
txWithStatus, err := client.GetTransaction(context.Background(), outPoint.TxHash, nil)
txWithStatus, err := client.GetTransaction(context.Background(), outPoint.TxHash, nil, nil)
if err != nil {
return 0, err
}
Expand All @@ -124,11 +124,11 @@ func getDaoReward(withdrawOutPoint *types.OutPoint, client rpc.Client) (uint64,
if depositCell == nil {
return 0, errors.New("can't find deposit cell")
}
depositBlockHeader, err := client.GetHeader(context.Background(), depositBlockHash)
depositBlockHeader, err := client.GetHeader(context.Background(), depositBlockHash, nil)
if err != nil {
return 0, err
}
withdrawBlockHeader, err := client.GetHeader(context.Background(), *withdrawBlockHash)
withdrawBlockHeader, err := client.GetHeader(context.Background(), *withdrawBlockHash, nil)
if err != nil {
return 0, err
}
Expand Down
12 changes: 6 additions & 6 deletions collector/handler/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type ClaimInfo struct {
}

func NewClaimInfo(client rpc.Client, withdrawOutpoint *types.OutPoint) (*ClaimInfo, error) {
txWithStatus, err := client.GetTransaction(context.Background(), withdrawOutpoint.TxHash, nil)
txWithStatus, err := client.GetTransaction(context.Background(), withdrawOutpoint.TxHash, nil, nil)
if err != nil {
return nil, err
}
Expand All @@ -113,7 +113,7 @@ func NewClaimInfo(client rpc.Client, withdrawOutpoint *types.OutPoint) (*ClaimIn
var depositBlockHash types.Hash
for i := 0; i < len(withdrawTx.Inputs); i++ {
outPoint := withdrawTx.Inputs[i].PreviousOutput
txWithStatus, err := client.GetTransaction(context.Background(), outPoint.TxHash, nil)
txWithStatus, err := client.GetTransaction(context.Background(), outPoint.TxHash, nil, nil)
if err != nil {
return nil, err
}
Expand All @@ -127,11 +127,11 @@ func NewClaimInfo(client rpc.Client, withdrawOutpoint *types.OutPoint) (*ClaimIn
if reflect.DeepEqual(depositBlockHash, types.Hash{}) {
return nil, errors.New("can't find deposit cell")
}
depositBlockHeader, err := client.GetHeader(context.Background(), depositBlockHash)
depositBlockHeader, err := client.GetHeader(context.Background(), depositBlockHash, nil)
if err != nil {
return nil, err
}
withdrawBlockHeader, err := client.GetHeader(context.Background(), *withdrawBlockHash)
withdrawBlockHeader, err := client.GetHeader(context.Background(), *withdrawBlockHash, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -177,12 +177,12 @@ type WithdrawInfo struct {
}

func NewWithdrawInfo(client rpc.Client, depositOutPoint *types.OutPoint) (*WithdrawInfo, error) {
txWithStatus, err := client.GetTransaction(context.Background(), depositOutPoint.TxHash, nil)
txWithStatus, err := client.GetTransaction(context.Background(), depositOutPoint.TxHash, nil, nil)
if err != nil {
return nil, err
}
depositBlockHash := txWithStatus.TxStatus.BlockHash
header, err := client.GetHeader(context.Background(), *depositBlockHash)
header, err := client.GetHeader(context.Background(), *depositBlockHash, nil)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions dao/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type DaoDepositCellInfo struct {

// GetDaoDepositCellInfo Get information for DAO cell deposited as outpoint and withdrawn in block of withdrawBlockHash
func (c *DaoHelper) GetDaoDepositCellInfo(outpoint *types.OutPoint, withdrawBlockHash types.Hash) (DaoDepositCellInfo, error) {
blockHeader, err := c.Client.GetHeader(context.Background(), withdrawBlockHash)
blockHeader, err := c.Client.GetHeader(context.Background(), withdrawBlockHash, nil)
if err != nil {
return DaoDepositCellInfo{}, err
}
Expand All @@ -33,7 +33,7 @@ func (c *DaoHelper) GetDaoDepositCellInfo(outpoint *types.OutPoint, withdrawBloc

// GetDaoDepositCellInfoWithWithdrawOutpoint Get information for DAO cell deposited as outpoint and withdrawn in block where the withdrawCellOutPoint is
func (c *DaoHelper) GetDaoDepositCellInfoWithWithdrawOutpoint(outpoint *types.OutPoint, withdrawCellOutPoint *types.OutPoint) (DaoDepositCellInfo, error) {
withdrawTransaction, err := c.Client.GetTransaction(context.Background(), withdrawCellOutPoint.TxHash, nil)
withdrawTransaction, err := c.Client.GetTransaction(context.Background(), withdrawCellOutPoint.TxHash, nil, nil)
if err != nil {
return DaoDepositCellInfo{}, err
}
Expand All @@ -51,11 +51,11 @@ func (c *DaoHelper) GetDaoDepositCellInfoByNow(outpoint *types.OutPoint) (DaoDep

// getDaoDepositCellInfo Get information for DAO cell deposited as outpoint and withdrawn in withdrawBlock
func (c *DaoHelper) getDaoDepositCellInfo(outpoint *types.OutPoint, withdrawBlockHeader *types.Header) (DaoDepositCellInfo, error) {
depositTransactionWithStatus, err := c.Client.GetTransaction(context.Background(), outpoint.TxHash, nil)
depositTransactionWithStatus, err := c.Client.GetTransaction(context.Background(), outpoint.TxHash, nil, nil)
if err != nil {
return DaoDepositCellInfo{}, err
}
depositBlockHeader, err := c.Client.GetHeader(context.Background(), *depositTransactionWithStatus.TxStatus.BlockHash)
depositBlockHeader, err := c.Client.GetHeader(context.Background(), *depositTransactionWithStatus.TxStatus.BlockHash, nil)
if err != nil {
return DaoDepositCellInfo{}, err
}
Expand Down
14 changes: 9 additions & 5 deletions indexer/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package indexer

import (
"encoding/json"

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

Expand All @@ -24,11 +26,13 @@ type SearchKey struct {
}

type Filter struct {
Script *types.Script `json:"script"`
ScriptLenRange *[2]uint64 `json:"script_len_range,omitempty"`
OutputDataLenRange *[2]uint64 `json:"output_data_len_range,omitempty"`
OutputCapacityRange *[2]uint64 `json:"output_capacity_range,omitempty"`
BlockRange *[2]uint64 `json:"block_range,omitempty"`
Script *types.Script `json:"script"`
ScriptLenRange *[2]uint64 `json:"script_len_range,omitempty"`
OutputData *json.RawMessage `json:"output_data,omitempty"`
OutputDataFilterMode *types.ScriptSearchMode `json:"output_data_filter_mode,omitempty"`
OutputDataLenRange *[2]uint64 `json:"output_data_len_range,omitempty"`
OutputCapacityRange *[2]uint64 `json:"output_capacity_range,omitempty"`
BlockRange *[2]uint64 `json:"block_range,omitempty"`
}

type LiveCell struct {
Expand Down
Loading

0 comments on commit 7ce104a

Please sign in to comment.