Skip to content

Commit

Permalink
Add additional EVM-compatible RPC methods (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliqun authored Aug 1, 2024
1 parent 1074975 commit 883091f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ Comparatively running your full node, Confura makes it easy to build a high perf

#### Metrics

* Component instrumentation && monitoring using [RED](https://www.weave.works/blog/the-red-method-key-metrics-for-microservices-architecture/) method.
- Component instrumentation && monitoring using [RED](https://www.weave.works/blog/the-red-method-key-metrics-for-microservices-architecture/) method.

#### EVM Compatibility

- Strives for maximum compatibility with EVM-compatible blockchains, spaces, and Layer2 solutions.

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion rpc/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (api *ethAPI) GetTransactionCount(
return (*hexutil.Big)(count), err
}

// SendTransaction injects a signed transaction into the pending pool for execution.
// SendRawTransaction injects a signed transaction into the pending pool for execution.
//
// If the transaction was a contract creation use the TransactionReceipt method to get the
// contract address after the transaction has been mined.
Expand Down
15 changes: 15 additions & 0 deletions rpc/net_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/Conflux-Chain/confura/rpc/cache"
"github.com/ethereum/go-ethereum/common/hexutil"
)

// netAPI provides evm space net RPC proxy API.
Expand All @@ -14,3 +15,17 @@ func (api *netAPI) Version(ctx context.Context) (string, error) {
w3c := GetEthClientFromContext(ctx)
return cache.EthDefault.GetNetVersion(w3c.Client)
}

// Listening returns true if client is actively listening for network connections.
func (api *netAPI) Listening(ctx context.Context) (res bool, err error) {
w3c := GetEthClientFromContext(ctx)
err = w3c.Client.CallContext(ctx, &res, "net_listening")
return res, err
}

// PeerCount Returns number of peers currently connected to the client.
func (api *netAPI) PeerCount(ctx context.Context) (res hexutil.Uint64, err error) {
w3c := GetEthClientFromContext(ctx)
err = w3c.Client.CallContext(ctx, (*uint64)(&res), "net_peerCount")
return res, err
}
8 changes: 8 additions & 0 deletions rpc/web3_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/Conflux-Chain/confura/rpc/cache"
"github.com/ethereum/go-ethereum/common/hexutil"
)

// web3API provides evm space web3 RPC proxy API.
Expand All @@ -14,3 +15,10 @@ func (api *web3API) ClientVersion(ctx context.Context) (string, error) {
w3c := GetEthClientFromContext(ctx)
return cache.EthDefault.GetClientVersion(w3c.Client)
}

// Sha3 returns Keccak-256 (not the standardized SHA3-256) hash of the given data.
func (api *web3API) Sha3(ctx context.Context, data hexutil.Bytes) (res hexutil.Bytes, err error) {
w3c := GetEthClientFromContext(ctx)
err = w3c.Client.CallContext(ctx, &res, "web3_sha3", data)
return res, err
}

0 comments on commit 883091f

Please sign in to comment.