Skip to content

Commit

Permalink
Register Web3Api extension (paritytech#147)
Browse files Browse the repository at this point in the history
* Remove unnecessary re-export

* Register Web3Api extension

* Add test

* Fix checker

* Prettify
  • Loading branch information
tgmichel authored Dec 23, 2020
1 parent ac06244 commit f12b8ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
11 changes: 8 additions & 3 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ pub fn create_full<C, P, BE>(
{
use substrate_frame_rpc_system::{FullSystem, SystemApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use frontier_rpc::{EthApiServer, NetApi, NetApiServer, EthPubSubApiServer};
use frontier_rpc::{NetApi, NetApiServer, Web3Api, Web3ApiServer};
// Our drop in replacements for the Eth APIs. These can be removed after
// https://github.com/paritytech/frontier/pull/199 lands
use server_hotfixes::EthApi;
use pubsub_hotfixes::EthPubSubApi;
use server_hotfixes::{EthApi, EthApiServer};
use pubsub_hotfixes::{EthPubSubApi, EthPubSubApiServer};

let mut io = jsonrpc_core::IoHandler::default();
let FullDeps {
Expand Down Expand Up @@ -129,6 +129,11 @@ pub fn create_full<C, P, BE>(
network.clone(),
))
);
io.extend_with(
Web3ApiServer::to_delegate(Web3Api::new(
client.clone(),
))
);
io.extend_with(
EthPubSubApiServer::to_delegate(EthPubSubApi::new(
pool.clone(),
Expand Down
2 changes: 1 addition & 1 deletion node/rpc/src/server_hotfixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use frontier_rpc_core::types::{
use frontier_rpc_primitives::{EthereumRuntimeRPCApi, ConvertTransaction, TransactionStatus};
use frontier_rpc::{internal_err, error_on_execution_failure, EthSigner};

pub use frontier_rpc_core::{EthApiServer, NetApiServer};
pub use frontier_rpc_core::EthApiServer;
use codec::{self, Encode};

pub struct EthApi<B: BlockT, C, P, CT, BE, H: ExHashT> {
Expand Down
17 changes: 17 additions & 0 deletions tests/tests/test-web3api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect } from "chai";
import { step } from "mocha-steps";
import { describeWithMoonbeam, customRequest } from "./util";

describeWithMoonbeam("Moonbeam RPC (Web3Api)", `simple-specs.json`, (context) => {
step("should get client version", async function () {
const version = await context.web3.eth.getNodeInfo();
expect(version).to.be.equal("moonbeam-standalone/v6.0/fc-rpc-0.1.0");
});

step("should remote sha3", async function () {
const data = context.web3.utils.stringToHex("hello");
const hash = await customRequest(context.web3, "web3_sha3", [data]);
const local_hash = context.web3.utils.sha3("hello");
expect(hash.result).to.be.equal(local_hash);
});
});

0 comments on commit f12b8ae

Please sign in to comment.