Skip to content

Commit

Permalink
Fix some rpc response type should be hexstring
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 22, 2024
1 parent 1107c77 commit 5b761d7
Show file tree
Hide file tree
Showing 5 changed files with 468 additions and 14 deletions.
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.RawTxPool

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
24 changes: 24 additions & 0 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,27 @@ 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)
}

func TestClient_GetHeader(t *testing.t) {

Check failure on line 569 in rpc/client_test.go

View workflow job for this annotation

GitHub Actions / test

wrong signature for TestClient_GetHeader, must be: func TestClient_GetHeader(t *testing.T)
// 0xd5ac7cf8c34a975bf258a34f1c2507638487ab71aa4d10a9ec73704aa3abf9cd
header, err := testClient.GetHeader(context.background(), types.HexToHash("0xd5ac7cf8c34a975bf258a34f1c2507638487ab71aa4d10a9ec73704aa3abf9cd"), nil)
if err != nil {
t.Fatal(err)
}
assert.NotNil(t, header)
}

// GetRawTxPool
func TestClient_GetRawTxPool(t *testing.T) {
resp, err := testClient.GetRawTxPool(context.Background())
assert.NoError(t, err)
assert.NotNil(t, resp)
}
Loading

0 comments on commit 5b761d7

Please sign in to comment.