Skip to content

Commit 12d2338

Browse files
committed
Refactor API and move impl out of server. Use koa-jsonrpc.
1 parent 1ccb136 commit 12d2338

19 files changed

+336
-463
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
dist
33
pnpm-lock.yaml
44
package-lock.json
5+
tsconfig.tsbuildinfo

lerna.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"version": "0.1.0",
32
"packages": [
43
"packages/*"
5-
]
4+
],
5+
"version": "independent",
6+
"useWorkspaces": true
67
}

package.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
{
2-
"name": "swirlds-json-rpc-bridge",
3-
"dependencies": {
4-
"lerna": "^4.0.0"
2+
"name": "root",
3+
"devDependencies": {
4+
"lerna": "^4.0.0",
5+
"typescript": "^4.5.5"
6+
},
7+
"workspaces": {
8+
"packages": [
9+
"packages/**"
10+
]
11+
},
12+
"scripts": {
13+
"compile": "npx lerna run compile",
14+
"start": "lerna exec --scope @workspace/app -- yarn start",
15+
"test": "lerna run test --since",
16+
"new-version": "lerna version --conventional-commits --yes",
17+
"diff": "lerna diff"
518
}
619
}

packages/bridge/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
"name": "bridge",
33
"version": "0.1.0",
44
"description": "",
5-
"types": "./dist/index.d.ts",
5+
"types": "dist/index.d.ts",
66
"main": "dist/index.js",
7+
"files": [ "dist" ],
78
"keywords": [],
89
"author": "",
910
"devDependencies": {
1011
"@types/node": "^17.0.14",
1112
"typescript": "^4.5.5"
13+
},
14+
"scripts": {
15+
"build": "npm run clean && npm run compile",
16+
"clean": "rm -rf ./dist && rom -rf tsconfig.tsbuildinfo",
17+
"compile": "npx tsc -b tsconfig.json"
1218
}
1319
}

packages/bridge/src/bridge.ts

-122
This file was deleted.

packages/bridge/src/index.ts

+64-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,64 @@
1-
export * from './bridge'
2-
export * from './jsonrpc'
1+
export { BridgeImpl } from './lib/bridge';
2+
3+
export interface Bridge {
4+
parity() : Parity;
5+
web3() : Web3;
6+
net() : Net;
7+
eth() : Eth;
8+
}
9+
10+
export interface Parity {
11+
// nextNonce();
12+
}
13+
14+
export interface Web3 {
15+
// clientVersion();
16+
// sha();
17+
}
18+
19+
export interface Net {
20+
listening() : boolean;
21+
peerCount() : number;
22+
version() : number;
23+
}
24+
25+
export interface Eth {
26+
// getProof();
27+
// accounts();
28+
blockNumber() : number;
29+
// call();
30+
// coinbase();
31+
estimateGas() : number;
32+
gasPrice() : number;
33+
getBalance() : number;
34+
getBlockByHash(hash : string) : any;
35+
getBlockByNumber(blockNum : number) : any;
36+
// getBlockTransactionCountByHash();
37+
// getBlockTransactionCountByNumber();
38+
getCode() : number;
39+
chainId() : number;
40+
// getLogs();
41+
// getStorageAt();
42+
// getTransactionByBlockHashAndIndex();
43+
// getTransactionByBLockNumberAndIndex();
44+
// getTransactionByHash();
45+
getTransactionCount() : number;
46+
// getTransactionReceipt();
47+
// getUncleByBlockHashAndIndex();
48+
// getUncleByBlockNumberAndIndex();
49+
// getUncleCountByBlockHash();
50+
// getUncleCountByBlockNumber();
51+
// getWork();
52+
// feeHistory();
53+
// hashrate();
54+
// mining();
55+
// protocolVersion();
56+
// sendRawTransaction();
57+
// sendTransaction();
58+
// sign();
59+
// signTransaction();
60+
// signTypedData();
61+
// submitHashrate();
62+
// submitWork();
63+
// syncing();
64+
}

packages/bridge/src/jsonrpc.ts

-59
This file was deleted.

packages/bridge/src/lib/bridge.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Bridge, Eth, Net, Parity, Web3} from '../index';
2+
import {ParityImpl} from './parity';
3+
import {Web3Impl} from './web3';
4+
import {NetImpl} from './net';
5+
import {EthImpl} from './eth';
6+
7+
export class BridgeImpl implements Bridge {
8+
private parityImpl:Parity = new ParityImpl();
9+
private web3Impl:Web3 = new Web3Impl();
10+
private netImpl:Net = new NetImpl();
11+
private ethImpl:Eth = new EthImpl();
12+
13+
parity(): Parity {
14+
return this.parityImpl;
15+
}
16+
17+
web3(): Web3 {
18+
return this.web3Impl;
19+
}
20+
21+
net(): Net {
22+
return this.netImpl;
23+
}
24+
25+
eth(): Eth {
26+
return this.ethImpl;
27+
}
28+
}

0 commit comments

Comments
 (0)