Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

allow connecting to remote nodes #5633

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
1,992 changes: 1,083 additions & 909 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
"truffle": "5.1.20",
"universal-analytics": "^0.4.13",
"unzip-stream": "0.3.0",
"web3": "1.2.6",
"web3-providers-http": "1.2.6",
"web3-providers-ws": "1.2.6",
"web3": "4.1.1",
"web3-providers-http": "4.0.5",
"web3-providers-ws": "4.0.5",
"xterm": "^4.4.0",
"xterm-addon-fit": "^0.3.0"
},
Expand Down
5 changes: 4 additions & 1 deletion src/common/services/GoogleAnalyticsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class GoogleAnalyticsService {
hostname = "public";
}
}

const config = {
hostname,
port: workspaceSettings.server.port,
Expand All @@ -126,6 +126,8 @@ class GoogleAnalyticsService {
hardfork: workspaceSettings.server.hardfork,
fork: workspaceSettings.server.fork,
fork_block_number: workspaceSettings.server.fork_block_number,
useRemoteServer: workspaceSettings.useRemoteServer || false,
remoteServer: workspaceSettings.remoteServer || "",
};

this.user.set("cd1", config.hostname);
Expand All @@ -141,6 +143,7 @@ class GoogleAnalyticsService {
this.user.set("cd11", config.hardfork);
this.user.set("cd12", config.fork);
this.user.set("cd13", config.fork_block_number);
this.user.set("cd14", config.remoteServer);
}
}
}
Expand Down
36 changes: 21 additions & 15 deletions src/integrations/ethereum/common/redux/blocks/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ const prefix = "BLOCKS";
const PAGE_SIZE = 15;

export const CLEAR_BLOCKS_IN_VIEW = `${prefix}/CLEAR_BLOCKS_IN_VIEW`;
export const clearBlocksInView = function() {
export const clearBlocksInView = function () {
return { type: CLEAR_BLOCKS_IN_VIEW, blocks: [] };
};

export const requestPage = function(startBlockNumber, endBlockNumber) {
return function(dispatch, getState) {
/**
*
* @param {number} startBlockNumber
* @param {number} endBlockNumber
* @returns {function(dispatch, getState): Promise<void>}
*/
export const requestPage = function (startBlockNumber, endBlockNumber) {
return function (dispatch, getState) {
if (startBlockNumber == null) {
startBlockNumber = getState().core.latestBlock;
}
Expand All @@ -33,23 +39,23 @@ export const requestPage = function(startBlockNumber, endBlockNumber) {
};

// The "next" page is the next set of blocks, from the last requested down to 0
export const requestNextPage = function() {
return function(dispatch, getState) {
export const requestNextPage = function () {
return function (dispatch, getState) {
var blocksInView = getState().blocks.inView;
var earliestBlockInView = blocksInView[blocksInView.length - 1].number;
var earliestBlockInView = Number(blocksInView[blocksInView.length - 1].number);
dispatch(requestPage(earliestBlockInView - 1));
};
};

export const requestPreviousPage = function() {
return function(dispatch, getState) {
export const requestPreviousPage = function () {
return function (dispatch, getState) {
var blocksInView = getState().blocks.inView;

if (blocksInView.length == 0) {
return dispatch(requestPage(getState().core.latestBlock));
}

var latestBlockInView = blocksInView[0].number;
var latestBlockInView = Number(blocksInView[0].number);
var latestBlock = getState().core.latestBlock;

var startBlock = Math.min(latestBlock, latestBlockInView + PAGE_SIZE);
Expand All @@ -62,8 +68,8 @@ export const requestPreviousPage = function() {
export const SET_BLOCKS_REQUESTED = `${prefix}/SET_BLOCKS_REQUESTED`;
export const ADD_BLOCKS_TO_VIEW = `${prefix}/ADD_BLOCKS_TO_VIEW`;

export const addBlocksToView = function(startBlockNumber, endBlockNumber) {
return async function(dispatch, getState) {
export const addBlocksToView = function (startBlockNumber, endBlockNumber) {
return async function (dispatch, getState) {
const state = getState();
const requested = state.blocks.requested;
const web3Instance = state.web3.web3Instance;
Expand Down Expand Up @@ -91,7 +97,7 @@ export const addBlocksToView = function(startBlockNumber, endBlockNumber) {
};
};

const getBlock = async function(number, web3Instance) {
const getBlock = async function (number, web3Instance) {
// Now actually request it
let block = await web3Request("getBlock", [number, false], web3Instance);
let transactionCount = await web3Request(
Expand All @@ -104,8 +110,8 @@ const getBlock = async function(number, web3Instance) {
};

export const SET_CURRENT_BLOCK_SHOWN = `${prefix}/SET_CURRENT_BLOCK_SHOWN`;
export const showBlock = function(number) {
return async function(dispatch, getState) {
export const showBlock = function (number) {
return async function (dispatch, getState) {
let block = await web3ActionCreator(dispatch, getState, "getBlock", [
number,
true,
Expand All @@ -126,6 +132,6 @@ export const showBlock = function(number) {
dispatch({ type: SET_CURRENT_BLOCK_SHOWN, block });
};
};
export const clearBlockShown = function() {
export const clearBlockShown = function () {
return { type: SET_CURRENT_BLOCK_SHOWN, block: null };
};
27 changes: 14 additions & 13 deletions src/integrations/ethereum/common/redux/core/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
web3ActionCreator,
} from "../web3/helpers/Web3ActionCreator";
import { getAccounts } from "../accounts/actions";
import { ContractOnceRequiresCallbackError } from "web3";

const prefix = "CORE";

Expand All @@ -11,8 +12,8 @@ export function setKeyData(mnemonic, hdPath, privateKeys) {
}

export const SET_GAS_PRICE = `${prefix}/SET_GAS_PRICE`;
export const getGasPrice = function() {
return async function(dispatch, getState) {
export const getGasPrice = function () {
return async function (dispatch, getState) {
let gasPrice = await web3ActionCreator(dispatch, getState, "getGasPrice");
var currentPrice = getState().core.gasPrice;
gasPrice = gasPrice.toString(10);
Expand All @@ -24,8 +25,8 @@ export const getGasPrice = function() {
};

export const SET_GAS_LIMIT = `${prefix}/SET_GAS_LIMIT`;
export const getGasLimit = function() {
return async function(dispatch, getState) {
export const getGasLimit = function () {
return async function (dispatch, getState) {
let block = await web3ActionCreator(dispatch, getState, "getBlock", [
"latest",
]);
Expand All @@ -39,8 +40,8 @@ export const getGasLimit = function() {
};
};

export const setBlockNumberToLatest = function() {
return async function(dispatch, getState) {
export const setBlockNumberToLatest = function () {
return async function (dispatch, getState) {
const blockNumber = await web3ActionCreator(
dispatch,
getState,
Expand All @@ -54,8 +55,8 @@ export const setBlockNumberToLatest = function() {
};

export const SET_BLOCK_NUMBER = `${prefix}/SET_BLOCK_NUMBER`;
export const setBlockNumber = function(number) {
return function(dispatch) {
export const setBlockNumber = function (number) {
return function (dispatch) {
dispatch({ type: SET_BLOCK_NUMBER, number });

// Refresh our accounts if the block changed.
Expand All @@ -64,20 +65,20 @@ export const setBlockNumber = function(number) {
};

export const GET_BLOCK_SUBSCRIPTION = `${prefix}/GET_BLOCK_SUBSCRIPTION`;
export const getBlockSubscription = function() {
return async function(dispatch, getState) {
export const getBlockSubscription = function () {
return async function (dispatch, getState) {
let subscription = await web3ActionCreator(
dispatch,
getState,
"subscribe",
["newBlockHeaders"],
["newHeads"],
);

subscription.on("data", blockHeader => {
let currentBlockNumber = getState().core.latestBlock;

if (blockHeader.number != currentBlockNumber) {
dispatch(setBlockNumber(blockHeader.number));
if (Number(blockHeader.number) != currentBlockNumber) {
dispatch(setBlockNumber(Number(blockHeader.number)));
}
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/integrations/ethereum/common/redux/core/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const initialState = {
transactions: [],
};

export default function(state = initialState, action) {
export default function (state = initialState, action) {
let accountBalances;
let accountNonces;
switch (action.type) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export default function(state = initialState, action) {

case Core.SET_BLOCK_NUMBER:
return Object.assign({}, state, {
latestBlock: action.number,
latestBlock: Number(action.number),
});

default:
Expand Down
28 changes: 17 additions & 11 deletions src/integrations/ethereum/common/redux/events/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ const PAGE_SIZE = 10;
export const ADD_EVENTS_TO_VIEW = `${prefix}/ADD_EVENTS_TO_VIEW`;
export const CLEAR_EVENTS_IN_VIEW = `${prefix}/CLEAR_EVENTS_IN_VIEW`;
export const SET_BLOCKS_REQUESTED = `${prefix}/SET_BLOCKS_REQUESTED`;
export const clearEventsInView = function() {
export const clearEventsInView = function () {
return { type: CLEAR_EVENTS_IN_VIEW, events: [] };
};

export const SET_SUBSCRIBED_TOPICS = `${prefix}/SET_SUBSCRIBED_TOPICS`;
export const setSubscribedTopics = function(topics) {
export const setSubscribedTopics = function (topics) {
return { type: SET_SUBSCRIBED_TOPICS, topics };
};

export const SET_LOADING = `${prefix}/SET_LOADING`;
export const requestPage = function(startBlockNumber, endBlockNumber) {
return async function(dispatch, getState) {
/**
* @param {number} startBlockNumber
* @param {number} endBlockNumber
* @returns {function(any, any): Promise<void>}
*/

export const requestPage = function (startBlockNumber, endBlockNumber) {
return async function (dispatch, getState) {
if (startBlockNumber == null) {
startBlockNumber = getState().core.latestBlock;
}
Expand All @@ -30,7 +36,6 @@ export const requestPage = function(startBlockNumber, endBlockNumber) {
: 0;
}


let earliestBlockToRequest = Math.max(
startBlockNumber - PAGE_SIZE,
endBlockNumber,
Expand Down Expand Up @@ -112,16 +117,16 @@ export const requestPage = function(startBlockNumber, endBlockNumber) {
};

// The "next" page is the next set of blocks, from the last requested down to 0
export const requestNextPage = function() {
return function(dispatch, getState) {
export const requestNextPage = function () {
return function (dispatch, getState) {
var blocksRequested = Object.keys(getState().events.blocksRequested);
var earliestBlockRequested = Math.min.apply(Math, blocksRequested);
dispatch(requestPage(earliestBlockRequested - 1));
};
};

export const requestPreviousPage = function() {
return function(dispatch, getState) {
export const requestPreviousPage = function () {
return function (dispatch, getState) {
var blocksRequested = Object.keys(getState().events.blocksRequested);

if (blocksRequested.length == 0) {
Expand All @@ -131,6 +136,7 @@ export const requestPreviousPage = function() {
var latestBlockRequested = Math.max.apply(Math, blocksRequested);
var latestBlock = getState().core.latestBlock;


var startBlock = Math.min(latestBlock, latestBlockRequested + PAGE_SIZE);
var endBlock = latestBlockRequested + 1;

Expand All @@ -139,8 +145,8 @@ export const requestPreviousPage = function() {
};

export const GET_DECODED_EVENT = `${prefix}/GET_DECODED_EVENT`;
export const getDecodedEvent = function(transactionHash, logIndex) {
return async function(dispatch, getState) {
export const getDecodedEvent = function (transactionHash, logIndex) {
return async function (dispatch, getState) {
let event;

const transaction = await web3ActionCreator(
Expand Down
Loading