Skip to content

Commit e674870

Browse files
committed
client builds and works in node, browsers, and ts
1 parent bb17c6f commit e674870

25 files changed

+39473
-112
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
# ethwatch
2-
3-
```
4-
{
5-
blockNumber: 15514490,
6-
blockHash: '0x68e47a75ec0047f38709981d3dcb781f066b6c004961fb0a41e893a6043d4f8c',
7-
transactionIndex: 141,
8-
removed: false,
9-
address: '0x9862F120da5b92a767Cc981dbbf60126a76d2009',
10-
data: '0x',
11-
topics: [
12-
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
13-
'0x0000000000000000000000000000000000000000000000000000000000000000',
14-
'0x000000000000000000000000efa9bebe299de7acaeca6876e1e4f5508eeef2db',
15-
'0x0000000000000000000000000000000000000000000000000000000000000ece'
16-
],
17-
transactionHash: '0xf5e6eaf75a5b72a4dde96c983031fe53a286a83cf4bf383f7fca8cda42518298',
18-
logIndex: 223
19-
}
20-
```
1+
# Look ma, no RPC polling!
212

223
### TODO
23-
- Optimize web package size
4+
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {
4+
modules: false,
5+
useBuiltIns: 'usage',
6+
corejs: 3,
7+
bugfixes: true,
8+
shippedProposals: true,
9+
targets: {
10+
browsers: [
11+
'supports async-functions',
12+
'supports cryptography',
13+
'supports es6',
14+
'supports promises',
15+
'supports promise-finally',
16+
'supports es6-generators',
17+
'supports rtcpeerconnection',
18+
'not dead',
19+
'not ie <= 11',
20+
'not ie_mob <= 11'
21+
]
22+
},
23+
exclude: ['transform-regenerator', '@babel/plugin-transform-regenerator']
24+
}],
25+
['@babel/preset-typescript']
26+
],
27+
plugins: [
28+
'transform-typescript-metadata',
29+
["@babel/plugin-proposal-decorators", { "legacy": true }],
30+
'lodash',
31+
'add-module-exports',
32+
"@babel/plugin-transform-modules-commonjs",
33+
]
34+
}

ethwatch-client/examples/USDT.js

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethwatch-client/examples/USDT.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EthWatch } from '../src/index'
1+
import EthWatch from '../src/index'
22

33
const ethWatch = new EthWatch()
44

ethwatch-client/examples/test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<head>
3-
<script src="bundle.js"></script>
3+
<script src="../dist/ethwatch-client.web.js"></script>
44
<script>
55
const ethWatch = new EthWatch()
66

ethwatch-client/package.json

+24-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33
"version": "0.0.1",
44
"description": "Watch Ethereum/EVM log events in a secure, robust, and scalable way",
55
"scripts": {
6-
"test": "echo \"Error: no test specified\" && exit 1",
7-
"serve": "webpack-cli serve --mode development",
8-
"build": "webpack"
6+
"build": "npm run clean && npm run build-development && npm run build-production",
7+
"build-node-env": "tsc --build ./tsconfig.json",
8+
"build-development": "NODE_ENV=development npm run build-node-env && npm run build-browser-development",
9+
"build-production": "NODE_ENV=production npm run build-node-env && npm run build-browser-production",
10+
"build-browser-development": "NODE_ENV=development webpack --mode=development --progress",
11+
"build-browser-production": "NODE_ENV=production webpack --mode=production --progress",
12+
"clean": "jest --clearCache || true; rm -rf dist vendor *.tsbuildinfo node_modules/.cache || true"
13+
},
14+
"types": "./dist/types/src/index.d.ts",
15+
"main": "./dist/src/exports-commonjs.js",
16+
"browser": "./dist/ethwatch-client.web.js",
17+
"exports": {
18+
"browser": "./dist/ethwatch-client.web.js",
19+
"default": {
20+
"import": "./dist/src/exports-esm.mjs",
21+
"require": "./dist/src/exports-commonjs.js"
22+
}
923
},
10-
"types": "./dist/src/index.d.ts",
11-
"main": "./dist/bundle.js",
12-
"browser": "./dist/bundle.js",
1324
"keywords": [
1425
"Ethereum",
1526
"EVM",
@@ -21,21 +32,27 @@
2132
"@types/memoizee": "^0.4.8",
2233
"babel-core": "^6.26.3",
2334
"babel-loader": "^8.2.5",
35+
"babel-plugin-add-module-exports": "^1.0.4",
36+
"babel-plugin-lodash": "^3.3.4",
37+
"babel-plugin-transform-typescript-metadata": "^0.3.2",
2438
"babel-preset-es2015": "^6.24.1",
2539
"crypto-browserify": "^3.12.0",
40+
"git-revision-webpack-plugin": "^5.0.0",
2641
"html-webpack-plugin": "^5.5.0",
42+
"lodash-webpack-plugin": "^0.11.6",
2743
"ts-loader": "^9.4.0",
2844
"ts-node": "^10.9.1",
2945
"typed-emitter": "^2.1.0",
3046
"typescript": "^4.9.4",
3147
"webpack": "^5.74.0",
48+
"webpack-bundle-analyzer": "^4.7.0",
3249
"webpack-cli": "^4.10.0",
3350
"webpack-dev-server": "^4.11.1"
3451
},
3552
"dependencies": {
3653
"@streamr/utils": "^7.2.0",
54+
"core-js": "^3.27.1",
3755
"ethers": "^5.7.2",
38-
"events": "^3.3.0",
3956
"memoizee": "^0.4.15",
4057
"node-polyfill-webpack-plugin": "^2.0.1",
4158
"streamr-client": "^7.2.0"

ethwatch-client/src/EthWatch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EthereumAddress, PermissionAssignment, Stream, StreamPermission, StreamrClient, Subscription, UserPermissionAssignment } from 'streamr-client'
22
import { keyToArrayIndex } from '@streamr/utils'
3-
import * as memoize from 'memoizee'
3+
import memoize from 'memoizee'
44
import { WatchedContract } from './WatchedContract'
55
import { RawEvent } from './RawEvent'
66

ethwatch-client/src/WatchedContract.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TypedEmitter from 'typed-emitter'
33
import { EthereumAddress } from 'streamr-client'
44
import { Event } from './Event'
55
import { RawEvent } from './RawEvent'
6-
import * as EventEmitter from 'events'
6+
import EventEmitter from 'events'
77
import { ParsedEvent } from './ParsedEvent'
88

99
type Events = {
@@ -12,7 +12,7 @@ type Events = {
1212
timeout: (event: Event) => void,
1313
}
1414

15-
export class WatchedContract extends (EventEmitter as unknown as new () => TypedEmitter<Events>) {
15+
export class WatchedContract extends ((EventEmitter as unknown) as new () => TypedEmitter<Events>) {
1616
private readonly address: string
1717
private readonly abi: string
1818
private readonly requiredConfirmations: number
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as EthWatchExports from './exports'
2+
Object.assign(EthWatchExports.EthWatch, EthWatchExports)
3+
export default EthWatchExports.EthWatch
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
// CJS entrypoint.
3+
const EthWatchExports = require('./exports')
4+
5+
Object.assign(EthWatchExports.EthWatch, EthWatchExports)
6+
7+
// required to get require('ethwatch-client') instead of require('ethwatch-client').default
8+
module.exports = EthWatchExports.EthWatch

ethwatch-client/src/exports-esm.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// ESM EntryPoint
2+
import EthWatch from './index.js'
3+
export * from './index.js'
4+
// required to get import EthWatch from 'ethwatch-client' to work
5+
export default EthWatch.default
6+
// note this file is manually copied as-is into dist/src since we don't want tsc to compile it to commonjs

ethwatch-client/src/exports.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './EthWatch'
2+
export * from './Event'
3+
export * from './WatchedContract'
4+
export * from './ParsedEvent'
5+
export * from './RawEvent'

ethwatch-client/src/index.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { EthWatch } from './EthWatch'
1+
/**
2+
* EthWatch Client
3+
*
4+
* @packageDocumentation
5+
* @module EthWatch
6+
*/
27

3-
if (window) {
4-
// @ts-ignore
5-
window.EthWatch = EthWatch
6-
}
8+
import { EthWatch } from './EthWatch'
79

8-
export * from './EthWatch'
9-
export * from './Event'
10-
export * from './WatchedContract'
11-
export * from './ParsedEvent'
12-
export * from './RawEvent'
10+
export * from './exports'
11+
export default EthWatch
12+
// Note awful export wrappers in exports-commonjs.js & exports-esm.mjs
13+

ethwatch-client/tsconfig.browser.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"extends": "../tsconfig.browser.json",
3+
"compilerOptions": {
4+
"composite": true,
5+
"noEmit": true,
6+
"declarationDir": "dist/types",
7+
"outDir": "dist",
8+
"experimentalDecorators": true,
9+
"emitDecoratorMetadata": true,
10+
"strictBindCallApply": true,
11+
"baseUrl": ".",
12+
"paths": {
13+
"stream": ["readable-stream"],
14+
"util": ["util"],
15+
"http": ["./src/shim/http-https.js"],
16+
"@ethersproject/wordlists": [
17+
"@ethersproject/wordlists/lib.esm/browser-wordlists.js"
18+
],
19+
"https": ["./src/shim/http-https.js"],
20+
"crypto": ["crypto-browserify"],
21+
"buffer": ["buffer/"],
22+
"node-fetch": ["./src/shim/node-fetch.ts"],
23+
"@streamr/protocol/*": ["@streamr/protocol/src/*"],
24+
"@streamr/protocol": ["@streamr/protocol/src/index.ts"],
25+
"@streamr/network-node": ["@streamr/network-node/src/browser.ts"],
26+
"@streamr/network-node/src/connection/NodeWebRtcConnection.ts": [
27+
"@streamr/network-node/src/connection/BrowserWebRtcConnection.ts"
28+
],
29+
"@streamr/network-node/src/connection/ws/NodeClientWsEndpoint.ts": [
30+
"@streamr/network-node/src/connection/ws/BrowserClientWsEndpoint.ts"
31+
],
32+
"@streamr/network-node/src/connection/ws/NodeClientWsConnection.ts": [
33+
"@streamr/network-node/src/connection/ws/BrowserClientWsConnection.ts"
34+
],
35+
"@streamr/network-node/src/helpers/logger/LoggerNode.ts": [
36+
"@streamr/network-node/src/helpers/logger/LoggerBrowser.ts"
37+
]
38+
}
39+
},
40+
"include": [
41+
"package.json",
42+
"src/**/*",
43+
"src/**/*.json",
44+
"vendor/**/*",
45+
"src/config.schema.json"
46+
],
47+
"exclude": ["src/exports-esm.mjs"],
48+
"references": [
49+
{ "path": "../test-utils/tsconfig.node.json" },
50+
{ "path": "../protocol/tsconfig.node.json" },
51+
{ "path": "../network/tsconfig.node.json" }
52+
]
53+
}

ethwatch-client/tsconfig.jest.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"extends": "../tsconfig.jest.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"declarationDir": "dist/types",
6+
"lib": ["es2021", "dom"],
7+
"experimentalDecorators": true,
8+
"emitDecoratorMetadata": true,
9+
"resolveJsonModule": true
10+
},
11+
"include": [
12+
"package.json",
13+
"src/**/*",
14+
"src/**/*.json",
15+
"vendor/**/*",
16+
"src/config.schema.json",
17+
"test/**/*"
18+
],
19+
"exclude": [
20+
"test/legacy/*",
21+
"test/memory/*",
22+
"test/exports/*",
23+
"src/exports-esm.mjs"
24+
],
25+
"references": []
26+
}

ethwatch-client/tsconfig.json

+1-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"module": "commonjs",
4-
"strict": true,
5-
"noImplicitReturns": true,
6-
"removeComments": true,
7-
"preserveConstEnums": true,
8-
"sourceMap": true,
9-
"declaration": true,
10-
"target": "es2015",
11-
"lib": ["es2017", "dom"],
12-
"outDir": "dist",
13-
"rootDir": "./",
14-
"baseUrl": ".",
15-
"paths": {
16-
"*": ["types/*"]
17-
}
18-
},
19-
"include": [
20-
"src/**/*"
21-
],
22-
"exclude": [
23-
"node_modules/*"
24-
]
2+
"extends": "./tsconfig.jest.json"
253
}

ethwatch-client/tsconfig.node.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "../tsconfig.node.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"declarationDir": "dist/types",
6+
"lib": ["es2021", "dom"],
7+
"experimentalDecorators": true,
8+
"emitDecoratorMetadata": true,
9+
"resolveJsonModule": true
10+
},
11+
"include": [
12+
"package.json",
13+
"src/**/*",
14+
"src/**/*.json",
15+
"vendor/**/*",
16+
"src/config.schema.json"
17+
],
18+
"exclude": ["src/exports-esm.mjs"],
19+
"references": []
20+
}

0 commit comments

Comments
 (0)