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'
4
4
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 ( )
8
8
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
+ } )
20
42
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 ( ) )
38
62
39
- export default app ;
63
+ export default app
40
64
41
65
// const app:Application = new Application();
42
66
// app.use(
@@ -48,6 +72,6 @@ export default app;
48
72
// export default app;
49
73
//
50
74
51
- function toHexString ( num :number ) {
52
- return "0x" + num . toString ( 16 ) ;
75
+ function toHexString ( num : number ) {
76
+ return '0x' + num . toString ( 16 )
53
77
}
0 commit comments