Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some rpc response type should be hex string #231

Draft
wants to merge 1 commit into
base: v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions indexer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const (
)

type SearchKey struct {
Script *types.Script `json:"script"`
ScriptType types.ScriptType `json:"script_type"`
ScriptSearchMode types.ScriptSearchMode `json:"script_search_mode,omitempty"`
Filter *Filter `json:"filter,omitempty"`
WithData bool `json:"with_data"`
Script *types.Script `json:"script"`
ScriptType types.ScriptType `json:"script_type"`
ScriptSearchMode types.ScriptSearchMode `json:"script_search_mode,omitempty"`
Filter *Filter `json:"filter,omitempty"`
WithData bool `json:"with_data"`
GroupByTransaction *bool `json:"group_by_transaction,omitempty"`
}

type Filter struct {
Expand Down
25 changes: 17 additions & 8 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ type Client interface {

RemoveTransaction(ctx context.Context, tx_hash types.Hash) (bool, error)

SendAlert(ctx context.Context, alert types.AlertMessage) error
SendAlert(ctx context.Context, alert types.Alert) error

GetBlockTemplate(ctx context.Context) (types.BlockTemplate, error)

TxPoolReady(ctx context.Context) (bool, error)

// GetRawTxPool Returns all transaction ids in tx pool as a json array of string transaction ids.
GetRawTxPool(ctx context.Context, verbose *bool) (*types.RawTxPool, error)
GetRawTxPool(ctx context.Context) (*types.RawTxPool, error)
// GetRawTxPool Returns all transaction ids in tx pool as a json array of string transaction ids.
GetRawTxPoolVerbose(ctx context.Context) (*types.RawTxPoolVerbose, error)

// ClearTxPool Removes all transactions from the transaction pool.
ClearTxPool(ctx context.Context) error
Expand Down Expand Up @@ -774,14 +776,21 @@ func (cli *client) TxPoolInfo(ctx context.Context) (*types.TxPoolInfo, error) {
return &result, nil
}

func (cli *client) GetRawTxPool(ctx context.Context, verbose *bool) (*types.RawTxPool, error) {
func (cli *client) GetRawTxPool(ctx context.Context) (*types.RawTxPool, error) {
var txPool types.RawTxPool

if verbose == nil {
defaultVerbose := false
verbose = &defaultVerbose
err := cli.c.CallContext(ctx, &txPool, "get_raw_tx_pool")
if err != nil {
return nil, err
}
err := cli.c.CallContext(ctx, &txPool, "get_raw_tx_pool", verbose)

return &txPool, err
}

func (cli *client) GetRawTxPoolVerbose(ctx context.Context) (*types.RawTxPoolVerbose, error) {
var txPool types.RawTxPoolVerbose

err := cli.c.CallContext(ctx, &txPool, "get_raw_tx_pool", true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -996,7 +1005,7 @@ func (cli *client) RemoveTransaction(ctx context.Context, tx_hash types.Hash) (b
return result, nil
}

func (cli *client) SendAlert(ctx context.Context, alert types.AlertMessage) error {
func (cli *client) SendAlert(ctx context.Context, alert types.Alert) error {
return cli.c.CallContext(ctx, nil, "send_alert", alert)
}

Expand Down
18 changes: 17 additions & 1 deletion rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,21 @@ func TestClient_ClearTxPool(t *testing.T) {
}

func TestClient_GetRawTxPool(t *testing.T) {
rawTxPool, err := testClient.GetRawTxPool(ctx, nil)
rawTxPool, err := testClient.GetRawTxPool(ctx)
if err != nil {
t.Fatal(err)
}
assert.NotNil(t, rawTxPool)
}

func TestClient_GetRawTxPoolVerbose(t *testing.T) {
rawTxPoolVerbose, err := testClient.GetRawTxPoolVerbose(ctx)
if err != nil {
t.Fatal(err)
}
assert.NotNil(t, rawTxPoolVerbose)
}

func TestClient_GetBlockchainInfo(t *testing.T) {
blockchainInfo, err := testClient.GetBlockchainInfo(ctx)
if err != nil {
Expand Down Expand Up @@ -557,3 +565,11 @@ func TestClient_GetTransactions_ExactMode(t *testing.T) {
assert.NotEqual(t, 0, resp2.Objects[0].BlockNumber)
assert.NotEqual(t, "", resp2.Objects[0].IoType)
}

func TestClient_GetPoolTxDetailInfo(t *testing.T) {
info, err := testClient.GetPoolTxDetailInfo(ctx, types.HexToHash("0x8277d74d33850581f8d843613ded0c2a1722dec0e87e748f45c115dfb14210f1"))
if err != nil {
t.Fatal(err)
}
assert.NotNil(t, info)
}
Loading
Loading