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 3253423
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 17 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.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

0 comments on commit 3253423

Please sign in to comment.