Skip to content

Commit

Permalink
Merge pull request #222 from shaojunda/shaojunda-fix-get-live-cell
Browse files Browse the repository at this point in the history
fix: make parameter includeTxPool effective in GetLiveCell
  • Loading branch information
quake authored Aug 15, 2024
2 parents 81d4efa + a74a3c1 commit 2b53eaf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
26 changes: 18 additions & 8 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ type Client interface {
GetPackedHeaderByNumber(ctx context.Context, number uint64) (*types.Header, error)
// GetLiveCell returns the information about a cell by out_point if it is live.
// If second with_data argument set to true, will return cell data and data_hash if it is live.
GetLiveCell(ctx context.Context, outPoint *types.OutPoint, withData bool, include_tx_pool *bool) (*types.CellWithStatus, error)
GetLiveCell(ctx context.Context, outPoint *types.OutPoint, withData bool, includeTxPool *bool) (*types.CellWithStatus, error)

// GetTransaction returns the information about a transaction requested by transaction hash.
GetTransaction(ctx context.Context, hash types.Hash, only_committed *bool) (*types.TransactionWithStatus, error)
GetTransaction(ctx context.Context, hash types.Hash, onlyCommitted *bool) (*types.TransactionWithStatus, error)

// GetBlockEconomicState return block economic state, It includes the rewards details and when it is finalized.
GetBlockEconomicState(ctx context.Context, hash types.Hash) (*types.BlockEconomicState, error)
Expand Down Expand Up @@ -446,22 +446,32 @@ func (cli *client) VerifyTransactionAndWitnessProof(ctx context.Context, proof *
return result, err
}

func (cli *client) GetLiveCell(ctx context.Context, point *types.OutPoint, withData bool, include_tx_pool *bool) (*types.CellWithStatus, error) {
var result types.CellWithStatus
err := cli.c.CallContext(ctx, &result, "get_live_cell", *point, withData)
func (cli *client) GetLiveCell(ctx context.Context, point *types.OutPoint, withData bool, includeTxPool *bool) (*types.CellWithStatus, error) {
var (
result types.CellWithStatus
err error
)

if includeTxPool == nil {
err = cli.c.CallContext(ctx, &result, "get_live_cell", *point, withData)
} else {
err = cli.c.CallContext(ctx, &result, "get_live_cell", *point, withData, *includeTxPool)
}

if err != nil {
return nil, err
}

return &result, err
}

func (cli *client) GetTransaction(ctx context.Context, hash types.Hash, only_committed *bool) (*types.TransactionWithStatus, error) {
func (cli *client) GetTransaction(ctx context.Context, hash types.Hash, onlyCommitted *bool) (*types.TransactionWithStatus, error) {
var result types.TransactionWithStatus
var err error
if only_committed == nil {
if onlyCommitted == nil {
err = cli.c.CallContext(ctx, &result, "get_transaction", hash)
} else {
err = cli.c.CallContext(ctx, &result, "get_transaction", hash, *only_committed)
err = cli.c.CallContext(ctx, &result, "get_transaction", hash, *onlyCommitted)
}
if err != nil {
return nil, err
Expand Down
15 changes: 15 additions & 0 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,21 @@ func TestClient_GetLiveCell(t *testing.T) {
assert.NotNil(t, cellWithStatus)
}

func TestClient_GetLiveCellIncludeTxPool(t *testing.T) {
outPoint := types.OutPoint{
TxHash: types.HexToHash("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37"),
Index: 0,
}

includeTxPool := true

cellWithStatus, err := testClient.GetLiveCell(ctx, &outPoint, true, &includeTxPool)
if err != nil {
t.Fatal(err)
}
assert.NotNil(t, cellWithStatus)
}

func TestGetTip(t *testing.T) {
resp, err := testClient.GetIndexerTip(context.Background())
assert.NoError(t, err)
Expand Down

0 comments on commit 2b53eaf

Please sign in to comment.