Merge branch 'feature/docker-experiments' into develop
This commit is contained in:
commit
8d43f6908c
|
@ -0,0 +1,6 @@
|
||||||
|
.git
|
||||||
|
node_modules
|
||||||
|
4bytes
|
||||||
|
!4bytes/signatures
|
||||||
|
trustwallet
|
||||||
|
!trustwallet/blockchains/ethereum/assets
|
|
@ -0,0 +1,19 @@
|
||||||
|
FROM node:12.22.3-alpine AS builder
|
||||||
|
WORKDIR /otterscan-build
|
||||||
|
COPY ["package.json", "package-lock.json", "/otterscan-build"]
|
||||||
|
RUN npm install
|
||||||
|
COPY ["run-nginx.sh", "tsconfig.json", "craco.config.js", "tailwind.config.js", "/otterscan-build"]
|
||||||
|
COPY ["public", "/otterscan-build/public"]
|
||||||
|
COPY ["src", "/otterscan-build/src"]
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM nginx:1.21.1-alpine
|
||||||
|
RUN apk add jq
|
||||||
|
COPY 4bytes/signatures /usr/share/nginx/html/signatures/
|
||||||
|
COPY trustwallet/blockchains/ethereum/assets /usr/share/nginx/html/assets/
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
COPY --from=builder /otterscan-build/build /usr/share/nginx/html/
|
||||||
|
COPY --from=builder /otterscan-build/run-nginx.sh /
|
||||||
|
WORKDIR /
|
||||||
|
|
||||||
|
CMD ["/run-nginx.sh"]
|
69
README.md
69
README.md
|
@ -107,9 +107,35 @@ Also pay attention to the `--http.corsdomain` parameter, CORS is required for th
|
||||||
|
|
||||||
Now you should have an Erigon node with Otterscan jsonrpc APIs enabled, running in dual mode with CORS enabled.
|
Now you should have an Erigon node with Otterscan jsonrpc APIs enabled, running in dual mode with CORS enabled.
|
||||||
|
|
||||||
### Clone Otterscan repository and build the project
|
### Run Otterscan docker image from Docker Hub
|
||||||
|
|
||||||
Make sure you have a working node 12/npm installation.
|
TODO: publish Otterscan official images as soon as it is validated.
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run --rm -p 5000:80 --name otterscan -d otterscan/otterscan:<versiontag>
|
||||||
|
```
|
||||||
|
|
||||||
|
This will download the Otterscan image from Docker Hub, run it locally using the default parameters, binding it to port 5000 (see the `-p` docker run parameter).
|
||||||
|
|
||||||
|
To stop Otterscan service, run:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker stop otterscan
|
||||||
|
```
|
||||||
|
|
||||||
|
By default it assumes your Erigon node is at http://127.0.0.1:8545. You can override the URL by setting the `ERIGON_URL` env variable on `docker run`:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run --rm -p 5000:80 --name otterscan -d --env ERIGON_URL="<your-erigon-node-url>" otterscan/otterscan:<versiontag>
|
||||||
|
```
|
||||||
|
|
||||||
|
### (Alternative 1) Build Otterscan docker image locally and run it
|
||||||
|
|
||||||
|
If you don't want to download from Docker Hub, you can build the docker image from the sources and run it.
|
||||||
|
|
||||||
|
If you just want to build the image locally, there is no need to install the development toolchain, just make sure you have a recent working Docker installation.
|
||||||
|
|
||||||
|
The entire build process will take place inside the docker multi-stage build.
|
||||||
|
|
||||||
Clone Otterscan repo and its submodules. Checkout the tag corresponding to your Erigon + Otterscan patches. It uses the same version tag from Erigon + Otterscan repo, i.e., if you built the `v2021.07.01-otterscan`, you should build the `v2021.07.01-otterscan` of Otterscan.
|
Clone Otterscan repo and its submodules. Checkout the tag corresponding to your Erigon + Otterscan patches. It uses the same version tag from Erigon + Otterscan repo, i.e., if you built the `v2021.07.01-otterscan`, you should build the `v2021.07.01-otterscan` of Otterscan.
|
||||||
|
|
||||||
|
@ -117,19 +143,19 @@ Clone Otterscan repo and its submodules. Checkout the tag corresponding to your
|
||||||
git clone --recurse-submodules git@github.com:wmitsuda/otterscan.git
|
git clone --recurse-submodules git@github.com:wmitsuda/otterscan.git
|
||||||
cd otterscan
|
cd otterscan
|
||||||
git checkout <version-tag-otterscan>
|
git checkout <version-tag-otterscan>
|
||||||
npm install
|
docker build -t otterscan -f Dockerfile .
|
||||||
npm run build
|
|
||||||
```
|
```
|
||||||
|
|
||||||
By default, it assumes your Erigon `rpcdaemon` processs is serving requests at http://127.0.0.1:8545. You can customize this URL by specifying the `REACT_APP_ERIGON_URL` environment variable at build time (it needs to be done at build time because the build process generates a static website).
|
This will run the entire build process inside a build container, merge the production build of the React app with the 4bytes and trustwallet assets into the same image format it is published in Docker Hub, but locally under the name `otterscan`.
|
||||||
|
|
||||||
To do that, export the variable before running `npm run build`:
|
Then you can start/stop it using the commands:
|
||||||
|
|
||||||
```
|
```
|
||||||
export REACT_APP_ERIGON_URL=<rpcdaemon-url>
|
docker run --rm -p 5000:80 --name otterscan -d otterscan
|
||||||
|
docker stop otterscan
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run it from the source
|
### (Alternative 2) Run a development build from the source
|
||||||
|
|
||||||
First, a brief explanation about the app:
|
First, a brief explanation about the app:
|
||||||
|
|
||||||
|
@ -141,25 +167,38 @@ First, a brief explanation about the app:
|
||||||
|
|
||||||
These instructions are subjected to changes in future for the sake of simplification.
|
These instructions are subjected to changes in future for the sake of simplification.
|
||||||
|
|
||||||
Open a new terminal and start the 4bytes method decoding service:
|
Make sure you have a working node 12/npm installation.
|
||||||
|
|
||||||
|
By default, it assumes your Erigon `rpcdaemon` processs is serving requests at http://127.0.0.1:8545. You can customize this URL by specifying the `REACT_APP_ERIGON_URL` environment variable at build time (it needs to be done at build time because the build process generates a static website).
|
||||||
|
|
||||||
|
To do that, export the variable before running `npm run build`:
|
||||||
|
|
||||||
```
|
```
|
||||||
npm run serve-4bytes
|
export REACT_APP_ERIGON_URL=<rpcdaemon-url>
|
||||||
```
|
```
|
||||||
|
|
||||||
Open another terminal and start the trustwallet assets service:
|
Start serving 4bytes and trustwallet assets at `localhost:3001` using a dockerized nginx:
|
||||||
|
|
||||||
```
|
```
|
||||||
npm run serve-trustwallet-assets
|
npm run start-assets
|
||||||
```
|
```
|
||||||
|
|
||||||
In another terminal start the Otterscan app:
|
To stop it, run:
|
||||||
|
|
||||||
```
|
```
|
||||||
npm run serve
|
npm run stop-assets
|
||||||
```
|
```
|
||||||
|
|
||||||
Otterscan should now be running at http://localhost:5000/.
|
To run Otterscan development build:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
Otterscan should now be running at http://localhost:3000/.
|
||||||
|
|
||||||
|
## Validating the installation (all methods)
|
||||||
|
|
||||||
**You can make sure it is working correctly if the homepage is able to show the latest block/timestamp your Erigon node is at just bellow the search button.**
|
**You can make sure it is working correctly if the homepage is able to show the latest block/timestamp your Erigon node is at just bellow the search button.**
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
#access_log /var/log/nginx/host.access.log main;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
|
||||||
|
# Base on: https://michielkalkman.com/snippets/nginx-cors-open-configuration/
|
||||||
|
if ($request_method = 'OPTIONS') {
|
||||||
|
add_header 'Access-Control-Allow-Origin' '*';
|
||||||
|
#
|
||||||
|
# Om nom nom cookies
|
||||||
|
#
|
||||||
|
add_header 'Access-Control-Allow-Credentials' 'true';
|
||||||
|
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
|
||||||
|
|
||||||
|
#
|
||||||
|
# Custom headers and headers various browsers *should* be OK with but aren't
|
||||||
|
#
|
||||||
|
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tell client that this pre-flight info is valid for 20 days
|
||||||
|
#
|
||||||
|
add_header 'Access-Control-Max-Age' 1728000;
|
||||||
|
add_header 'Content-Type' 'text/plain charset=UTF-8';
|
||||||
|
add_header 'Content-Length' 0;
|
||||||
|
return 204;
|
||||||
|
}
|
||||||
|
if ($request_method = 'GET') {
|
||||||
|
add_header 'Access-Control-Allow-Origin' '*';
|
||||||
|
add_header 'Access-Control-Allow-Credentials' 'true';
|
||||||
|
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
|
||||||
|
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#error_page 404 /404.html;
|
||||||
|
|
||||||
|
# redirect server error pages to the static page /50x.html
|
||||||
|
#
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -42,9 +42,11 @@
|
||||||
"build": "craco build",
|
"build": "craco build",
|
||||||
"test": "craco test",
|
"test": "craco test",
|
||||||
"eject": "react-scripts eject",
|
"eject": "react-scripts eject",
|
||||||
"serve-4bytes": "serve -p 3001 -C -c serve-4bytes.json",
|
"start-assets": "docker run --rm -p 3001:80 --name otterscan-assets -d -v$(pwd)/4bytes/signatures:/usr/share/nginx/html/signatures/ -v$(pwd)/trustwallet/blockchains/ethereum/assets:/usr/share/nginx/html/assets -v$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf nginx:1.21.1-alpine",
|
||||||
"serve-trustwallet-assets": "serve -p 3002 -C -c serve-trustwallet-assets.json",
|
"stop-assets": "docker stop otterscan-assets",
|
||||||
"serve": "serve -s build"
|
"build-docker": "docker build -t otterscan -f Dockerfile .",
|
||||||
|
"start-docker": "docker run --rm -p 5000:80 --name otterscan -d otterscan",
|
||||||
|
"stop-docker": "docker stop otterscan"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"erigonURL": "http://localhost:8545"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
PARAMS="{\"erigonURL\": $(echo $ERIGON_URL | jq -aR .)}"
|
||||||
|
echo $PARAMS > /usr/share/nginx/html/config.json
|
||||||
|
nginx -g "daemon off;"
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"public": "4bytes/signatures",
|
|
||||||
"headers": [
|
|
||||||
{
|
|
||||||
"source": "**",
|
|
||||||
"headers": [
|
|
||||||
{
|
|
||||||
"key": "Cache-Control",
|
|
||||||
"value": "max-age=600"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"directoryListing": false
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"public": "trustwallet/blockchains/ethereum/assets",
|
|
||||||
"headers": [
|
|
||||||
{
|
|
||||||
"source": "**",
|
|
||||||
"headers": [
|
|
||||||
{
|
|
||||||
"key": "Cache-Control",
|
|
||||||
"value": "max-age=600"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"directoryListing": false
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState, useEffect, useMemo } from "react";
|
import React, { useState, useEffect, useMemo, useContext } from "react";
|
||||||
import { useParams, useLocation, useHistory } from "react-router-dom";
|
import { useParams, useLocation, useHistory } from "react-router-dom";
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
|
@ -12,9 +12,9 @@ import ResultHeader from "./search/ResultHeader";
|
||||||
import PendingResults from "./search/PendingResults";
|
import PendingResults from "./search/PendingResults";
|
||||||
import TransactionItem from "./search/TransactionItem";
|
import TransactionItem from "./search/TransactionItem";
|
||||||
import { SearchController } from "./search/search";
|
import { SearchController } from "./search/search";
|
||||||
|
import { ProviderContext } from "./useProvider";
|
||||||
import { useENSCache } from "./useReverseCache";
|
import { useENSCache } from "./useReverseCache";
|
||||||
import { useFeeToggler } from "./search/useFeeToggler";
|
import { useFeeToggler } from "./search/useFeeToggler";
|
||||||
import { provider } from "./ethersconfig";
|
|
||||||
|
|
||||||
type BlockParams = {
|
type BlockParams = {
|
||||||
addressOrName: string;
|
addressOrName: string;
|
||||||
|
@ -26,6 +26,7 @@ type PageParams = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const AddressTransactions: React.FC = () => {
|
const AddressTransactions: React.FC = () => {
|
||||||
|
const provider = useContext(ProviderContext);
|
||||||
const params = useParams<BlockParams>();
|
const params = useParams<BlockParams>();
|
||||||
const location = useLocation<PageParams>();
|
const location = useLocation<PageParams>();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
@ -59,6 +60,9 @@ const AddressTransactions: React.FC = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const resolveName = async () => {
|
const resolveName = async () => {
|
||||||
const resolvedAddress = await provider.resolveName(params.addressOrName);
|
const resolvedAddress = await provider.resolveName(params.addressOrName);
|
||||||
if (resolvedAddress !== null) {
|
if (resolvedAddress !== null) {
|
||||||
|
@ -72,20 +76,30 @@ const AddressTransactions: React.FC = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
resolveName();
|
resolveName();
|
||||||
}, [params.addressOrName, history, params.direction, location.search]);
|
}, [
|
||||||
|
provider,
|
||||||
|
params.addressOrName,
|
||||||
|
history,
|
||||||
|
params.direction,
|
||||||
|
location.search,
|
||||||
|
]);
|
||||||
|
|
||||||
const [controller, setController] = useState<SearchController>();
|
const [controller, setController] = useState<SearchController>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!checksummedAddress) {
|
if (!provider || !checksummedAddress) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const readFirstPage = async () => {
|
const readFirstPage = async () => {
|
||||||
const _controller = await SearchController.firstPage(checksummedAddress);
|
const _controller = await SearchController.firstPage(
|
||||||
|
provider,
|
||||||
|
checksummedAddress
|
||||||
|
);
|
||||||
setController(_controller);
|
setController(_controller);
|
||||||
};
|
};
|
||||||
const readMiddlePage = async (next: boolean) => {
|
const readMiddlePage = async (next: boolean) => {
|
||||||
const _controller = await SearchController.middlePage(
|
const _controller = await SearchController.middlePage(
|
||||||
|
provider,
|
||||||
checksummedAddress,
|
checksummedAddress,
|
||||||
hash!,
|
hash!,
|
||||||
next
|
next
|
||||||
|
@ -93,15 +107,18 @@ const AddressTransactions: React.FC = () => {
|
||||||
setController(_controller);
|
setController(_controller);
|
||||||
};
|
};
|
||||||
const readLastPage = async () => {
|
const readLastPage = async () => {
|
||||||
const _controller = await SearchController.lastPage(checksummedAddress);
|
const _controller = await SearchController.lastPage(
|
||||||
|
provider,
|
||||||
|
checksummedAddress
|
||||||
|
);
|
||||||
setController(_controller);
|
setController(_controller);
|
||||||
};
|
};
|
||||||
const prevPage = async () => {
|
const prevPage = async () => {
|
||||||
const _controller = await controller!.prevPage(hash!);
|
const _controller = await controller!.prevPage(provider, hash!);
|
||||||
setController(_controller);
|
setController(_controller);
|
||||||
};
|
};
|
||||||
const nextPage = async () => {
|
const nextPage = async () => {
|
||||||
const _controller = await controller!.nextPage(hash!);
|
const _controller = await controller!.nextPage(provider, hash!);
|
||||||
setController(_controller);
|
setController(_controller);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -127,10 +144,10 @@ const AddressTransactions: React.FC = () => {
|
||||||
readLastPage();
|
readLastPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [checksummedAddress, params.direction, hash, controller]);
|
}, [provider, checksummedAddress, params.direction, hash, controller]);
|
||||||
|
|
||||||
const page = useMemo(() => controller?.getPage(), [controller]);
|
const page = useMemo(() => controller?.getPage(), [controller]);
|
||||||
const reverseCache = useENSCache(page);
|
const reverseCache = useENSCache(provider, page);
|
||||||
|
|
||||||
document.title = `Address ${params.addressOrName} | Otterscan`;
|
document.title = `Address ${params.addressOrName} | Otterscan`;
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,19 @@ import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
|
||||||
import Home from "./Home";
|
import Home from "./Home";
|
||||||
import Search from "./Search";
|
import Search from "./Search";
|
||||||
import Title from "./Title";
|
import Title from "./Title";
|
||||||
|
import { useProvider, ProviderContext } from "./useProvider";
|
||||||
|
|
||||||
const Block = React.lazy(() => import("./Block"));
|
const Block = React.lazy(() => import("./Block"));
|
||||||
const BlockTransactions = React.lazy(() => import("./BlockTransactions"));
|
const BlockTransactions = React.lazy(() => import("./BlockTransactions"));
|
||||||
const AddressTransactions = React.lazy(() => import("./AddressTransactions"));
|
const AddressTransactions = React.lazy(() => import("./AddressTransactions"));
|
||||||
const Transaction = React.lazy(() => import("./Transaction"));
|
const Transaction = React.lazy(() => import("./Transaction"));
|
||||||
|
|
||||||
const App = () => (
|
const App = () => {
|
||||||
|
const provider = useProvider();
|
||||||
|
|
||||||
|
return (
|
||||||
<Suspense fallback={<>LOADING</>}>
|
<Suspense fallback={<>LOADING</>}>
|
||||||
|
<ProviderContext.Provider value={provider}>
|
||||||
<Router>
|
<Router>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/" exact>
|
<Route path="/" exact>
|
||||||
|
@ -36,7 +41,9 @@ const App = () => (
|
||||||
</Route>
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
</Router>
|
</Router>
|
||||||
|
</ProviderContext.Provider>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default React.memo(App);
|
export default React.memo(App);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect, useState, useMemo } from "react";
|
import React, { useEffect, useState, useMemo, useContext } from "react";
|
||||||
import { useParams, NavLink } from "react-router-dom";
|
import { useParams, NavLink } from "react-router-dom";
|
||||||
import { ethers, BigNumber } from "ethers";
|
import { ethers, BigNumber } from "ethers";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
@ -6,7 +6,6 @@ import {
|
||||||
faChevronLeft,
|
faChevronLeft,
|
||||||
faChevronRight,
|
faChevronRight,
|
||||||
} from "@fortawesome/free-solid-svg-icons";
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { provider } from "./ethersconfig";
|
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
import StandardSubtitle from "./StandardSubtitle";
|
import StandardSubtitle from "./StandardSubtitle";
|
||||||
import ContentFrame from "./ContentFrame";
|
import ContentFrame from "./ContentFrame";
|
||||||
|
@ -17,6 +16,7 @@ import BlockLink from "./components/BlockLink";
|
||||||
import AddressOrENSName from "./components/AddressOrENSName";
|
import AddressOrENSName from "./components/AddressOrENSName";
|
||||||
import TransactionValue from "./components/TransactionValue";
|
import TransactionValue from "./components/TransactionValue";
|
||||||
import HexValue from "./components/HexValue";
|
import HexValue from "./components/HexValue";
|
||||||
|
import { ProviderContext } from "./useProvider";
|
||||||
import { useLatestBlockNumber } from "./useLatestBlock";
|
import { useLatestBlockNumber } from "./useLatestBlock";
|
||||||
|
|
||||||
type BlockParams = {
|
type BlockParams = {
|
||||||
|
@ -34,10 +34,15 @@ interface ExtendedBlock extends ethers.providers.Block {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Block: React.FC = () => {
|
const Block: React.FC = () => {
|
||||||
|
const provider = useContext(ProviderContext);
|
||||||
const params = useParams<BlockParams>();
|
const params = useParams<BlockParams>();
|
||||||
|
|
||||||
const [block, setBlock] = useState<ExtendedBlock>();
|
const [block, setBlock] = useState<ExtendedBlock>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const readBlock = async () => {
|
const readBlock = async () => {
|
||||||
let blockPromise: Promise<any>;
|
let blockPromise: Promise<any>;
|
||||||
if (ethers.utils.isHexString(params.blockNumberOrHash, 32)) {
|
if (ethers.utils.isHexString(params.blockNumberOrHash, 32)) {
|
||||||
|
@ -80,7 +85,7 @@ const Block: React.FC = () => {
|
||||||
setBlock(extBlock);
|
setBlock(extBlock);
|
||||||
};
|
};
|
||||||
readBlock();
|
readBlock();
|
||||||
}, [params.blockNumberOrHash]);
|
}, [provider, params.blockNumberOrHash]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (block) {
|
if (block) {
|
||||||
|
@ -97,7 +102,7 @@ const Block: React.FC = () => {
|
||||||
}
|
}
|
||||||
}, [block]);
|
}, [block]);
|
||||||
|
|
||||||
const latestBlockNumber = useLatestBlockNumber();
|
const latestBlockNumber = useLatestBlockNumber(provider);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StandardFrame>
|
<StandardFrame>
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import React, { useEffect, useState, useMemo } from "react";
|
import React, { useEffect, useState, useMemo, useContext } from "react";
|
||||||
import { useParams, useLocation } from "react-router";
|
import { useParams, useLocation } from "react-router";
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import { provider } from "./ethersconfig";
|
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
import StandardSubtitle from "./StandardSubtitle";
|
import StandardSubtitle from "./StandardSubtitle";
|
||||||
import ContentFrame from "./ContentFrame";
|
import ContentFrame from "./ContentFrame";
|
||||||
|
@ -14,6 +13,7 @@ import BlockLink from "./components/BlockLink";
|
||||||
import { ProcessedTransaction } from "./types";
|
import { ProcessedTransaction } from "./types";
|
||||||
import { PAGE_SIZE } from "./params";
|
import { PAGE_SIZE } from "./params";
|
||||||
import { useFeeToggler } from "./search/useFeeToggler";
|
import { useFeeToggler } from "./search/useFeeToggler";
|
||||||
|
import { ProviderContext } from "./useProvider";
|
||||||
import { useENSCache } from "./useReverseCache";
|
import { useENSCache } from "./useReverseCache";
|
||||||
|
|
||||||
type BlockParams = {
|
type BlockParams = {
|
||||||
|
@ -25,6 +25,7 @@ type PageParams = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const BlockTransactions: React.FC = () => {
|
const BlockTransactions: React.FC = () => {
|
||||||
|
const provider = useContext(ProviderContext);
|
||||||
const params = useParams<BlockParams>();
|
const params = useParams<BlockParams>();
|
||||||
const location = useLocation<PageParams>();
|
const location = useLocation<PageParams>();
|
||||||
const qs = queryString.parse(location.search);
|
const qs = queryString.parse(location.search);
|
||||||
|
@ -42,6 +43,10 @@ const BlockTransactions: React.FC = () => {
|
||||||
|
|
||||||
const [txs, setTxs] = useState<ProcessedTransaction[]>();
|
const [txs, setTxs] = useState<ProcessedTransaction[]>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const readBlock = async () => {
|
const readBlock = async () => {
|
||||||
const [_block, _receipts] = await Promise.all([
|
const [_block, _receipts] = await Promise.all([
|
||||||
provider.getBlockWithTransactions(blockNumber.toNumber()),
|
provider.getBlockWithTransactions(blockNumber.toNumber()),
|
||||||
|
@ -94,7 +99,7 @@ const BlockTransactions: React.FC = () => {
|
||||||
setTxs(processedResponses);
|
setTxs(processedResponses);
|
||||||
};
|
};
|
||||||
readBlock();
|
readBlock();
|
||||||
}, [blockNumber]);
|
}, [provider, blockNumber]);
|
||||||
|
|
||||||
const page = useMemo(() => {
|
const page = useMemo(() => {
|
||||||
if (!txs) {
|
if (!txs) {
|
||||||
|
@ -105,7 +110,7 @@ const BlockTransactions: React.FC = () => {
|
||||||
}, [txs, pageNumber]);
|
}, [txs, pageNumber]);
|
||||||
const total = useMemo(() => txs?.length ?? 0, [txs]);
|
const total = useMemo(() => txs?.length ?? 0, [txs]);
|
||||||
|
|
||||||
const reverseCache = useENSCache(page);
|
const reverseCache = useENSCache(provider, page);
|
||||||
|
|
||||||
document.title = `Block #${blockNumber} Txns | Otterscan`;
|
document.title = `Block #${blockNumber} Txns | Otterscan`;
|
||||||
|
|
||||||
|
|
13
src/Home.tsx
13
src/Home.tsx
|
@ -1,12 +1,13 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState, useContext } from "react";
|
||||||
import { NavLink, useHistory } from "react-router-dom";
|
import { NavLink, useHistory } from "react-router-dom";
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import Logo from "./Logo";
|
import Logo from "./Logo";
|
||||||
import Timestamp from "./components/Timestamp";
|
import Timestamp from "./components/Timestamp";
|
||||||
|
import { ProviderContext } from "./useProvider";
|
||||||
import { useLatestBlock } from "./useLatestBlock";
|
import { useLatestBlock } from "./useLatestBlock";
|
||||||
import { ERIGON_NODE } from "./ethersconfig";
|
|
||||||
|
|
||||||
const Home: React.FC = () => {
|
const Home: React.FC = () => {
|
||||||
|
const provider = useContext(ProviderContext);
|
||||||
const [search, setSearch] = useState<string>();
|
const [search, setSearch] = useState<string>();
|
||||||
const [canSubmit, setCanSubmit] = useState<boolean>(false);
|
const [canSubmit, setCanSubmit] = useState<boolean>(false);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
@ -25,7 +26,7 @@ const Home: React.FC = () => {
|
||||||
history.push(`/search?q=${search}`);
|
history.push(`/search?q=${search}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const latestBlock = useLatestBlock();
|
const latestBlock = useLatestBlock(provider);
|
||||||
|
|
||||||
document.title = "Home | Otterscan";
|
document.title = "Home | Otterscan";
|
||||||
|
|
||||||
|
@ -65,7 +66,11 @@ const Home: React.FC = () => {
|
||||||
</NavLink>
|
</NavLink>
|
||||||
)}
|
)}
|
||||||
<span className="mx-auto mt-5 text-xs text-gray-500">
|
<span className="mx-auto mt-5 text-xs text-gray-500">
|
||||||
Using Erigon node at {ERIGON_NODE}
|
{provider ? (
|
||||||
|
<>Using Erigon node at {provider.connection.url}</>
|
||||||
|
) : (
|
||||||
|
<>Waiting for the provider...</>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import React, { useState, useEffect, useCallback, useMemo } from "react";
|
import React, {
|
||||||
|
useState,
|
||||||
|
useEffect,
|
||||||
|
useCallback,
|
||||||
|
useMemo,
|
||||||
|
useContext,
|
||||||
|
} from "react";
|
||||||
import { Route, Switch, useParams } from "react-router-dom";
|
import { Route, Switch, useParams } from "react-router-dom";
|
||||||
import { BigNumber, ethers } from "ethers";
|
import { BigNumber, ethers } from "ethers";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
@ -6,7 +12,6 @@ import {
|
||||||
faCheckCircle,
|
faCheckCircle,
|
||||||
faTimesCircle,
|
faTimesCircle,
|
||||||
} from "@fortawesome/free-solid-svg-icons";
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { provider } from "./ethersconfig";
|
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
import StandardSubtitle from "./StandardSubtitle";
|
import StandardSubtitle from "./StandardSubtitle";
|
||||||
import Tab from "./components/Tab";
|
import Tab from "./components/Tab";
|
||||||
|
@ -22,6 +27,7 @@ import FormattedBalance from "./components/FormattedBalance";
|
||||||
import TokenTransferItem from "./TokenTransferItem";
|
import TokenTransferItem from "./TokenTransferItem";
|
||||||
import erc20 from "./erc20.json";
|
import erc20 from "./erc20.json";
|
||||||
import { TokenMetas, TokenTransfer, TransactionData, Transfer } from "./types";
|
import { TokenMetas, TokenTransfer, TransactionData, Transfer } from "./types";
|
||||||
|
import { ProviderContext } from "./useProvider";
|
||||||
|
|
||||||
const TRANSFER_TOPIC =
|
const TRANSFER_TOPIC =
|
||||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
||||||
|
@ -31,11 +37,16 @@ type TransactionParams = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const Transaction: React.FC = () => {
|
const Transaction: React.FC = () => {
|
||||||
|
const provider = useContext(ProviderContext);
|
||||||
const params = useParams<TransactionParams>();
|
const params = useParams<TransactionParams>();
|
||||||
const { txhash } = params;
|
const { txhash } = params;
|
||||||
|
|
||||||
const [txData, setTxData] = useState<TransactionData>();
|
const [txData, setTxData] = useState<TransactionData>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const readBlock = async () => {
|
const readBlock = async () => {
|
||||||
const [_response, _receipt] = await Promise.all([
|
const [_response, _receipt] = await Promise.all([
|
||||||
provider.getTransaction(txhash),
|
provider.getTransaction(txhash),
|
||||||
|
@ -109,7 +120,7 @@ const Transaction: React.FC = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
readBlock();
|
readBlock();
|
||||||
}, [txhash]);
|
}, [provider, txhash]);
|
||||||
|
|
||||||
const [transfers, setTransfers] = useState<Transfer[]>();
|
const [transfers, setTransfers] = useState<Transfer[]>();
|
||||||
const sendsEthToMiner = useMemo(() => {
|
const sendsEthToMiner = useMemo(() => {
|
||||||
|
@ -126,7 +137,7 @@ const Transaction: React.FC = () => {
|
||||||
}, [txData, transfers]);
|
}, [txData, transfers]);
|
||||||
|
|
||||||
const traceTransfersUsingOtsTrace = useCallback(async () => {
|
const traceTransfersUsingOtsTrace = useCallback(async () => {
|
||||||
if (!txData) {
|
if (!provider || !txData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +154,7 @@ const Transaction: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
setTransfers(_transfers);
|
setTransfers(_transfers);
|
||||||
}, [txData]);
|
}, [provider, txData]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
traceTransfersUsingOtsTrace();
|
traceTransfersUsingOtsTrace();
|
||||||
}, [traceTransfersUsingOtsTrace]);
|
}, [traceTransfersUsingOtsTrace]);
|
||||||
|
|
|
@ -16,7 +16,7 @@ const MethodName: React.FC<MethodNameProps> = ({ data }) => {
|
||||||
|
|
||||||
// Try to resolve 4bytes name
|
// Try to resolve 4bytes name
|
||||||
const fourBytes = _name.slice(2);
|
const fourBytes = _name.slice(2);
|
||||||
const signatureURL = `http://localhost:3001/${fourBytes}`;
|
const signatureURL = `http://localhost:3001/signatures/${fourBytes}`;
|
||||||
fetch(signatureURL)
|
fetch(signatureURL)
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ const TokenLogo: React.FC<TokenLogoProps> = (props) => (
|
||||||
const InternalTokenLogo: React.FC<TokenLogoProps> = ({ address, name }) => {
|
const InternalTokenLogo: React.FC<TokenLogoProps> = ({ address, name }) => {
|
||||||
const { src } = useImage({
|
const { src } = useImage({
|
||||||
srcList: [
|
srcList: [
|
||||||
`http://localhost:3002/${address}/logo.png`,
|
`http://localhost:3001/assets/${address}/logo.png`,
|
||||||
"/eth-diamond-black.png",
|
"/eth-diamond-black.png",
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
import { ethers } from "ethers";
|
|
||||||
|
|
||||||
export const ERIGON_NODE =
|
|
||||||
process.env.REACT_APP_ERIGON_URL || "http://127.0.0.1:8545";
|
|
||||||
|
|
||||||
export const provider = new ethers.providers.JsonRpcProvider(
|
|
||||||
ERIGON_NODE,
|
|
||||||
"mainnet"
|
|
||||||
);
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import { provider } from "../ethersconfig";
|
|
||||||
import { PAGE_SIZE } from "../params";
|
import { PAGE_SIZE } from "../params";
|
||||||
import { ProcessedTransaction, TransactionChunk } from "../types";
|
import { ProcessedTransaction, TransactionChunk } from "../types";
|
||||||
|
|
||||||
|
@ -27,7 +26,10 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static rawToProcessed = (_rawRes: any) => {
|
private static rawToProcessed = (
|
||||||
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
|
_rawRes: any
|
||||||
|
) => {
|
||||||
const _res: ethers.providers.TransactionResponse[] = _rawRes.txs.map(
|
const _res: ethers.providers.TransactionResponse[] = _rawRes.txs.map(
|
||||||
(t: any) => provider.formatter.transactionResponse(t)
|
(t: any) => provider.formatter.transactionResponse(t)
|
||||||
);
|
);
|
||||||
|
@ -56,6 +58,7 @@ export class SearchController {
|
||||||
};
|
};
|
||||||
|
|
||||||
private static async readBackPage(
|
private static async readBackPage(
|
||||||
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
address: string,
|
address: string,
|
||||||
baseBlock: number
|
baseBlock: number
|
||||||
): Promise<TransactionChunk> {
|
): Promise<TransactionChunk> {
|
||||||
|
@ -64,10 +67,11 @@ export class SearchController {
|
||||||
baseBlock,
|
baseBlock,
|
||||||
PAGE_SIZE,
|
PAGE_SIZE,
|
||||||
]);
|
]);
|
||||||
return this.rawToProcessed(_rawRes);
|
return this.rawToProcessed(provider, _rawRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async readForwardPage(
|
private static async readForwardPage(
|
||||||
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
address: string,
|
address: string,
|
||||||
baseBlock: number
|
baseBlock: number
|
||||||
): Promise<TransactionChunk> {
|
): Promise<TransactionChunk> {
|
||||||
|
@ -76,11 +80,14 @@ export class SearchController {
|
||||||
baseBlock,
|
baseBlock,
|
||||||
PAGE_SIZE,
|
PAGE_SIZE,
|
||||||
]);
|
]);
|
||||||
return this.rawToProcessed(_rawRes);
|
return this.rawToProcessed(provider, _rawRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async firstPage(address: string): Promise<SearchController> {
|
static async firstPage(
|
||||||
const newTxs = await SearchController.readBackPage(address, 0);
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
|
address: string
|
||||||
|
): Promise<SearchController> {
|
||||||
|
const newTxs = await SearchController.readBackPage(provider, address, 0);
|
||||||
return new SearchController(
|
return new SearchController(
|
||||||
address,
|
address,
|
||||||
newTxs.txs,
|
newTxs.txs,
|
||||||
|
@ -91,14 +98,19 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async middlePage(
|
static async middlePage(
|
||||||
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
address: string,
|
address: string,
|
||||||
hash: string,
|
hash: string,
|
||||||
next: boolean
|
next: boolean
|
||||||
): Promise<SearchController> {
|
): Promise<SearchController> {
|
||||||
const tx = await provider.getTransaction(hash);
|
const tx = await provider.getTransaction(hash);
|
||||||
const newTxs = next
|
const newTxs = next
|
||||||
? await SearchController.readBackPage(address, tx.blockNumber!)
|
? await SearchController.readBackPage(provider, address, tx.blockNumber!)
|
||||||
: await SearchController.readForwardPage(address, tx.blockNumber!);
|
: await SearchController.readForwardPage(
|
||||||
|
provider,
|
||||||
|
address,
|
||||||
|
tx.blockNumber!
|
||||||
|
);
|
||||||
return new SearchController(
|
return new SearchController(
|
||||||
address,
|
address,
|
||||||
newTxs.txs,
|
newTxs.txs,
|
||||||
|
@ -108,8 +120,11 @@ export class SearchController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async lastPage(address: string): Promise<SearchController> {
|
static async lastPage(
|
||||||
const newTxs = await SearchController.readForwardPage(address, 0);
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
|
address: string
|
||||||
|
): Promise<SearchController> {
|
||||||
|
const newTxs = await SearchController.readForwardPage(provider, address, 0);
|
||||||
return new SearchController(
|
return new SearchController(
|
||||||
address,
|
address,
|
||||||
newTxs.txs,
|
newTxs.txs,
|
||||||
|
@ -123,7 +138,10 @@ export class SearchController {
|
||||||
return this.txs.slice(this.pageStart, this.pageEnd);
|
return this.txs.slice(this.pageStart, this.pageEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
async prevPage(hash: string): Promise<SearchController> {
|
async prevPage(
|
||||||
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
|
hash: string
|
||||||
|
): Promise<SearchController> {
|
||||||
// Already on this page
|
// Already on this page
|
||||||
if (this.txs[this.pageEnd - 1].hash === hash) {
|
if (this.txs[this.pageEnd - 1].hash === hash) {
|
||||||
return this;
|
return this;
|
||||||
|
@ -133,6 +151,7 @@ export class SearchController {
|
||||||
const overflowPage = this.txs.slice(0, this.pageStart);
|
const overflowPage = this.txs.slice(0, this.pageStart);
|
||||||
const baseBlock = this.txs[0].blockNumber;
|
const baseBlock = this.txs[0].blockNumber;
|
||||||
const prevPage = await SearchController.readForwardPage(
|
const prevPage = await SearchController.readForwardPage(
|
||||||
|
provider,
|
||||||
this.address,
|
this.address,
|
||||||
baseBlock
|
baseBlock
|
||||||
);
|
);
|
||||||
|
@ -148,7 +167,10 @@ export class SearchController {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
async nextPage(hash: string): Promise<SearchController> {
|
async nextPage(
|
||||||
|
provider: ethers.providers.JsonRpcProvider,
|
||||||
|
hash: string
|
||||||
|
): Promise<SearchController> {
|
||||||
// Already on this page
|
// Already on this page
|
||||||
if (this.txs[this.pageStart].hash === hash) {
|
if (this.txs[this.pageStart].hash === hash) {
|
||||||
return this;
|
return this;
|
||||||
|
@ -158,6 +180,7 @@ export class SearchController {
|
||||||
const overflowPage = this.txs.slice(this.pageEnd);
|
const overflowPage = this.txs.slice(this.pageEnd);
|
||||||
const baseBlock = this.txs[this.txs.length - 1].blockNumber;
|
const baseBlock = this.txs[this.txs.length - 1].blockNumber;
|
||||||
const nextPage = await SearchController.readBackPage(
|
const nextPage = await SearchController.readBackPage(
|
||||||
|
provider,
|
||||||
this.address,
|
this.address,
|
||||||
baseBlock
|
baseBlock
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
|
export type OtterscanConfig = {
|
||||||
|
erigonURL: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useErigon = (): [boolean?, OtterscanConfig?] => {
|
||||||
|
const [configOK, setConfigOK] = useState<boolean>();
|
||||||
|
const [config, setConfig] = useState<OtterscanConfig>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const readConfig = async () => {
|
||||||
|
const res = await fetch("/config.json");
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
const _config: OtterscanConfig = await res.json();
|
||||||
|
setConfig(_config);
|
||||||
|
setConfigOK(res.ok);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
readConfig();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return [configOK, config];
|
||||||
|
};
|
|
@ -1,11 +1,14 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import { provider } from "./ethersconfig";
|
|
||||||
|
|
||||||
export const useLatestBlock = () => {
|
export const useLatestBlock = (provider?: ethers.providers.JsonRpcProvider) => {
|
||||||
const [latestBlock, setLatestBlock] = useState<ethers.providers.Block>();
|
const [latestBlock, setLatestBlock] = useState<ethers.providers.Block>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const readLatestBlock = async () => {
|
const readLatestBlock = async () => {
|
||||||
const blockNum = await provider.getBlockNumber();
|
const blockNum = await provider.getBlockNumber();
|
||||||
const _raw = await provider.send("erigon_getHeaderByNumber", [blockNum]);
|
const _raw = await provider.send("erigon_getHeaderByNumber", [blockNum]);
|
||||||
|
@ -26,15 +29,21 @@ export const useLatestBlock = () => {
|
||||||
return () => {
|
return () => {
|
||||||
provider.removeListener("block", listener);
|
provider.removeListener("block", listener);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [provider]);
|
||||||
|
|
||||||
return latestBlock;
|
return latestBlock;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useLatestBlockNumber = () => {
|
export const useLatestBlockNumber = (
|
||||||
|
provider?: ethers.providers.JsonRpcProvider
|
||||||
|
) => {
|
||||||
const [latestBlock, setLatestBlock] = useState<number>();
|
const [latestBlock, setLatestBlock] = useState<number>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const readLatestBlock = async () => {
|
const readLatestBlock = async () => {
|
||||||
const blockNum = await provider.getBlockNumber();
|
const blockNum = await provider.getBlockNumber();
|
||||||
setLatestBlock(blockNum);
|
setLatestBlock(blockNum);
|
||||||
|
@ -49,7 +58,7 @@ export const useLatestBlockNumber = () => {
|
||||||
return () => {
|
return () => {
|
||||||
provider.removeListener("block", listener);
|
provider.removeListener("block", listener);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [provider]);
|
||||||
|
|
||||||
return latestBlock;
|
return latestBlock;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import React from "react";
|
||||||
|
import { ethers } from "ethers";
|
||||||
|
import { useErigon } from "./useErigon";
|
||||||
|
|
||||||
|
export const DEFAULT_ERIGON_URL = "http://127.0.0.1:8545";
|
||||||
|
|
||||||
|
export const useProvider = (): ethers.providers.JsonRpcProvider | undefined => {
|
||||||
|
const [configOK, config] = useErigon();
|
||||||
|
if (!configOK) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let erigonURL = config?.erigonURL;
|
||||||
|
if (erigonURL === "") {
|
||||||
|
console.info(`Using default erigon URL: ${DEFAULT_ERIGON_URL}`);
|
||||||
|
erigonURL = DEFAULT_ERIGON_URL;
|
||||||
|
} else {
|
||||||
|
console.log(`Using configured erigon URL: ${erigonURL}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ethers.providers.JsonRpcProvider(erigonURL, "mainnet");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ProviderContext = React.createContext<
|
||||||
|
ethers.providers.JsonRpcProvider | undefined
|
||||||
|
>(undefined);
|
|
@ -1,12 +1,15 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
import { ethers } from "ethers";
|
||||||
import { ENSReverseCache, ProcessedTransaction } from "./types";
|
import { ENSReverseCache, ProcessedTransaction } from "./types";
|
||||||
import { provider } from "./ethersconfig";
|
|
||||||
|
|
||||||
export const useENSCache = (page?: ProcessedTransaction[]) => {
|
export const useENSCache = (
|
||||||
|
provider?: ethers.providers.JsonRpcProvider,
|
||||||
|
page?: ProcessedTransaction[]
|
||||||
|
) => {
|
||||||
const [reverseCache, setReverseCache] = useState<ENSReverseCache>();
|
const [reverseCache, setReverseCache] = useState<ENSReverseCache>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!page) {
|
if (!provider || !page) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +41,7 @@ export const useENSCache = (page?: ProcessedTransaction[]) => {
|
||||||
setReverseCache(cache);
|
setReverseCache(cache);
|
||||||
};
|
};
|
||||||
reverseResolve();
|
reverseResolve();
|
||||||
}, [page]);
|
}, [provider, page]);
|
||||||
|
|
||||||
return reverseCache;
|
return reverseCache;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue