Skip to content

Commit 1d255e8

Browse files
committed
formatting and cleanup
Run the formatter on all files remove non-error console.log
1 parent 5356382 commit 1d255e8

File tree

11 files changed

+163
-113
lines changed

11 files changed

+163
-113
lines changed

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"packages": [
3-
"packages/*"
3+
"packages/*"
44
],
55
"version": "independent",
66
"useWorkspaces": true

package.json

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
22
"name": "root",
33
"devDependencies": {
4-
"@typescript-eslint/eslint-plugin": "^5.11.0",
5-
"@typescript-eslint/parser": "^5.11.0",
6-
"eslint": "^8.8.0",
7-
"eslint-config-airbnb-base": "^15.0.0",
8-
"eslint-config-prettier": "^8.3.0",
9-
"eslint-plugin-import": "^2.25.4",
10-
"lerna": "^4.0.0",
11-
"prettier": "^2.5.1",
12-
"typescript": "^4.5.5"
4+
"@typescript-eslint/eslint-plugin": "^5.11.0",
5+
"@typescript-eslint/parser": "^5.11.0",
6+
"eslint": "^8.8.0",
7+
"eslint-config-airbnb-base": "^15.0.0",
8+
"eslint-config-prettier": "^8.3.0",
9+
"eslint-plugin-import": "^2.25.4",
10+
"lerna": "^4.0.0",
11+
"prettier": "^2.5.1",
12+
"typescript": "^4.5.5"
1313
},
1414
"workspaces": {
15-
"packages": [
16-
"packages/**"
17-
]
15+
"packages": [
16+
"packages/**"
17+
]
1818
},
1919
"scripts": {
20-
"setup": "npx lerna bootstrap --hoist",
21-
"build": "npx lerna run build",
22-
"clean": "npx lerna run clean",
23-
"compile": "npx lerna run compile",
24-
"lint": "npx lerna run lint",
25-
"format": "npx lerna run format",
26-
"start": "npx lerna exec --scope server -- npm run start"
20+
"setup": "npx lerna bootstrap --hoist",
21+
"build": "npx lerna run build",
22+
"clean": "npx lerna run clean",
23+
"compile": "npx lerna run compile",
24+
"lint": "npx lerna run lint",
25+
"format": "npx lerna run format",
26+
"start": "npx lerna exec --scope server -- npm run start"
2727
}
2828
}

packages/bridge/src/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ export { BridgeImpl } from './lib/bridge';
22

33
export interface Bridge {
44
parity(): Parity;
5+
56
web3(): Web3;
7+
68
net(): Net;
9+
710
eth(): Eth;
811
}
912

@@ -18,42 +21,57 @@ export interface Web3 {
1821

1922
export interface Net {
2023
listening(): boolean;
24+
2125
peerCount(): number;
26+
2227
version(): number;
2328
}
2429

2530
export interface Eth {
2631
// getProof();
2732
// accounts();
2833
blockNumber(): number;
34+
2935
call(call: any, blockParam: string): Promise<string>;
36+
3037
// coinbase();
3138
estimateGas(): number;
39+
3240
gasPrice(): number;
41+
3342
getBalance(): number;
43+
3444
getBlockByHash(hash: string): any;
45+
3546
getBlockByNumber(blockNum: number): any;
47+
3648
// getBlockTransactionCountByHash();
3749
// getBlockTransactionCountByNumber();
3850
getCode(): number;
51+
3952
chainId(): number;
53+
4054
// getLogs();
4155
// getStorageAt();
4256
// getTransactionByBlockHashAndIndex();
4357
// getTransactionByBLockNumberAndIndex();
4458
// getTransactionByHash();
4559
getTransactionCount(): number;
60+
4661
getTransactionReceipt(hash: string): Promise<any>;
62+
4763
// getUncleByBlockHashAndIndex();
4864
// getUncleByBlockNumberAndIndex();
4965
// getUncleCountByBlockHash();
5066
// getUncleCountByBlockNumber();
5167
// getWork();
5268
feeHistory(): any;
69+
5370
// hashrate();
5471
// mining();
5572
// protocolVersion();
5673
sendRawTransaction(transaction: string): Promise<string>;
74+
5775
// sendTransaction();
5876
// sign();
5977
// signTransaction();

packages/bridge/src/lib/eth.ts

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Eth } from '../index';
22
import {
3-
ContractExecuteTransaction,
4-
Client,
53
AccountId,
4+
Client,
65
ContractCallQuery,
6+
ContractExecuteTransaction,
77
ContractId,
88
TransactionReceiptQuery,
99
} from '@hashgraph/sdk';
10+
1011
var cache = require('js-cache');
1112

1213
export class EthImpl implements Eth {
@@ -43,15 +44,11 @@ export class EthImpl implements Eth {
4344
}
4445

4546
const transactionId = cache.get(Buffer.from(hash, 'hex'));
46-
console.log(transactionId);
4747

48-
console.log('transactionId.toString()');
49-
console.log(transactionId.toString());
5048
try {
5149
let receipt = await new TransactionReceiptQuery()
5250
.setTransactionId(transactionId)
5351
.execute(client);
54-
console.log(receipt);
5552
} catch (e) {
5653
console.log(e);
5754
throw e;
@@ -178,7 +175,6 @@ export class EthImpl implements Eth {
178175
'302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137',
179176
},
180177
});
181-
console.log(client);
182178
} catch (error) {
183179
console.log(error);
184180
throw new Error(
@@ -192,10 +188,6 @@ export class EthImpl implements Eth {
192188

193189
txRequest = txRequest.populateFromForeignTransaction(transaction);
194190

195-
console.log(txRequest);
196-
197-
console.log('ProtoBuf');
198-
199191
var contractExecuteResponse = null;
200192

201193
if (client instanceof Client) {
@@ -215,8 +207,6 @@ export class EthImpl implements Eth {
215207
contractExecuteResponse.transactionId
216208
);
217209

218-
console.log(contractExecuteResponse);
219-
220210
// try {
221211
// const contractRecord = await contractExecuteResponse.getRecord(client);
222212
//
@@ -237,8 +227,6 @@ export class EthImpl implements Eth {
237227
const hashString = Buffer.from(txnHash).toString('hex');
238228

239229
var receipt = await this.getTransactionReceipt(hashString);
240-
console.log('receipt');
241-
console.log(receipt);
242230

243231
return Buffer.from(contractExecuteResponse.transactionHash).toString('hex');
244232
}
@@ -291,9 +279,7 @@ export class EthImpl implements Eth {
291279
contractCallQuery.setSenderId(senderId);
292280
}
293281

294-
console.log(contractCallQuery);
295282
const contractCallResponse = await contractCallQuery.execute(client);
296-
console.log(contractCallResponse);
297283
return Buffer.from(contractCallResponse.asBytes())
298284
.toString('hex')
299285
.replace('^(0x)?0+', '');

packages/bridge/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"rootDir": "./src" /* Specify the root folder within your source files. */,
5-
"outDir": "./dist" /* Specify an output folder for all emitted files. */
4+
"rootDir": "./src",
5+
/* Specify the root folder within your source files. */ "outDir": "./dist"
6+
/* Specify an output folder for all emitted files. */
67
},
78
"exclude": ["node_modules", "dist"]
89
}

packages/server/package.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66
"keywords": [],
77
"author": "",
88
"dependencies": {
9-
"bridge": "^0.1.0",
10-
"koa": "^2.13.4",
11-
"koa-body-parser": "^0.2.1",
12-
"koa-jsonrpc": "^1.1.1",
13-
"koa-router": "^10.1.1"
9+
"bridge": "^0.1.0",
10+
"koa": "^2.13.4",
11+
"koa-body-parser": "^0.2.1",
12+
"koa-jsonrpc": "^1.1.1",
13+
"koa-router": "^10.1.1"
1414
},
1515
"devDependencies": {
16-
"@koa/cors": "^3.1.0",
17-
"@types/cors": "^2.8.12",
18-
"@types/express": "^4.17.13",
19-
"@types/koa-bodyparser": "^4.3.5",
20-
"@types/koa-router": "^7.4.4",
21-
"@types/node": "^17.0.14",
22-
"tsc": "^2.0.4",
23-
"typescript": "^4.5.5"
16+
"@koa/cors": "^3.1.0",
17+
"@types/cors": "^2.8.12",
18+
"@types/express": "^4.17.13",
19+
"@types/koa-bodyparser": "^4.3.5",
20+
"@types/koa-router": "^7.4.4",
21+
"@types/node": "^17.0.14",
22+
"tsc": "^2.0.4",
23+
"typescript": "^4.5.5"
2424
},
2525
"scripts": {
26-
"build": "npm run clean && npm run compile",
27-
"clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
28-
"compile": "../../node_modules/typescript/bin/tsc -b tsconfig.json",
29-
"start": "NODE_PATH=../../node_modules node dist/index.js"
26+
"build": "npm run clean && npm run compile",
27+
"clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
28+
"compile": "../../node_modules/typescript/bin/tsc -b tsconfig.json",
29+
"start": "NODE_PATH=../../node_modules node dist/index.js"
3030
}
3131
}

packages/server/src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import app from "./server";
1+
import app from './server'
2+
23
async function main() {
3-
await app.listen({port: 7546});
4+
await app.listen({ port: 7546 })
45
}
56

6-
main();
7+
main()

packages/server/src/server.ts

+61-37
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
1-
import Koa from 'koa';
2-
import koaJsonRpc from 'koa-jsonrpc';
3-
import {Bridge, BridgeImpl} from 'bridge';
1+
import Koa from 'koa'
2+
import koaJsonRpc from 'koa-jsonrpc'
3+
import { Bridge, BridgeImpl } from 'bridge'
44

5-
const bridge: Bridge = new BridgeImpl();
6-
const app = new Koa();
7-
const rpc = koaJsonRpc();
5+
const bridge: Bridge = new BridgeImpl()
6+
const app = new Koa()
7+
const rpc = koaJsonRpc()
88

9-
rpc.use('net_listening', async () => { return "" + bridge.net().listening() });
10-
rpc.use('net_version', async () => { return toHexString(bridge.net().version()) });
11-
rpc.use('eth_blockNumber', async () => { return toHexString(bridge.eth().blockNumber()) });
12-
rpc.use('eth_estimateGas', async () => { return toHexString(bridge.eth().estimateGas()) });
13-
rpc.use('eth_getBalance', async () => { return toHexString(bridge.eth().getBalance()) });
14-
rpc.use('eth_getCode', async () => { return toHexString(bridge.eth().getCode()) });
15-
rpc.use('eth_chainId', async () => { return toHexString(bridge.eth().chainId()) });
16-
rpc.use('eth_getBlockByNumber', async (params:any) => { return bridge.eth().getBlockByNumber(params?.[0]) });
17-
rpc.use('eth_getBlockByHash', async (params:any) => { return bridge.eth().getBlockByHash(params?.[0]) });
18-
rpc.use('eth_gasPrice', async () => { return toHexString(bridge.eth().gasPrice()) });
19-
rpc.use('eth_getTransactionCount', async () => { return toHexString(bridge.eth().getTransactionCount()) });
9+
rpc.use('net_listening', async () => {
10+
return '' + bridge.net().listening()
11+
})
12+
rpc.use('net_version', async () => {
13+
return toHexString(bridge.net().version())
14+
})
15+
rpc.use('eth_blockNumber', async () => {
16+
return toHexString(bridge.eth().blockNumber())
17+
})
18+
rpc.use('eth_estimateGas', async () => {
19+
return toHexString(bridge.eth().estimateGas())
20+
})
21+
rpc.use('eth_getBalance', async () => {
22+
return toHexString(bridge.eth().getBalance())
23+
})
24+
rpc.use('eth_getCode', async () => {
25+
return toHexString(bridge.eth().getCode())
26+
})
27+
rpc.use('eth_chainId', async () => {
28+
return toHexString(bridge.eth().chainId())
29+
})
30+
rpc.use('eth_getBlockByNumber', async (params: any) => {
31+
return bridge.eth().getBlockByNumber(params?.[0])
32+
})
33+
rpc.use('eth_getBlockByHash', async (params: any) => {
34+
return bridge.eth().getBlockByHash(params?.[0])
35+
})
36+
rpc.use('eth_gasPrice', async () => {
37+
return toHexString(bridge.eth().gasPrice())
38+
})
39+
rpc.use('eth_getTransactionCount', async () => {
40+
return toHexString(bridge.eth().getTransactionCount())
41+
})
2042
rpc.use('eth_call', async (params: any) => {
21-
try {
22-
return bridge.eth().call(params?.[0], "params?.[1]");
23-
} catch (e) {
24-
console.log(e);
25-
throw e;
26-
}
27-
});
28-
rpc.use('eth_sendRawTransaction', async (params:any) => {
29-
try {
30-
return bridge.eth().sendRawTransaction(params?.[0]);
31-
} catch (e) {
32-
console.log(e);
33-
throw e;
34-
}
35-
});
36-
rpc.use('eth_getTransactionReceipt', async (hash: string) => { return bridge.eth().getTransactionReceipt(hash) });
37-
app.use(rpc.app());
43+
try {
44+
return bridge.eth().call(params?.[0], 'params?.[1]')
45+
} catch (e) {
46+
console.log(e)
47+
throw e
48+
}
49+
})
50+
rpc.use('eth_sendRawTransaction', async (params: any) => {
51+
try {
52+
return bridge.eth().sendRawTransaction(params?.[0])
53+
} catch (e) {
54+
console.log(e)
55+
throw e
56+
}
57+
})
58+
rpc.use('eth_getTransactionReceipt', async (hash: string) => {
59+
return bridge.eth().getTransactionReceipt(hash)
60+
})
61+
app.use(rpc.app())
3862

39-
export default app;
63+
export default app
4064

4165
// const app:Application = new Application();
4266
// app.use(
@@ -48,6 +72,6 @@ export default app;
4872
// export default app;
4973
//
5074

51-
function toHexString(num:number) {
52-
return "0x" + num.toString(16);
75+
function toHexString(num: number) {
76+
return '0x' + num.toString(16)
5377
}

0 commit comments

Comments
 (0)