1
1
'use strict'
2
- import { Web3 , Web3PluginBase } from 'web3'
3
- import { toNumber } from 'web3-utils'
2
+ import { toNumber , ethers } from 'ethers'
4
3
5
- export function extendWeb3 ( web3 ) {
6
- if ( ! web3 . debug ) {
7
- web3 . registerPlugin ( new Web3DebugPlugin ( ) )
8
- }
9
- }
10
-
11
- export function loadWeb3 ( url ) {
12
- if ( ! url ) url = 'http://localhost:8545'
13
- const web3 = new Web3 ( )
14
- web3 . setProvider ( new Web3 . providers . HttpProvider ( url ) )
15
- extendWeb3 ( web3 )
16
- return web3
17
- }
18
-
19
- export function setProvider ( web3 , url ) {
20
- web3 . setProvider ( new web3 . providers . HttpProvider ( url ) )
4
+ export function loadWeb3 ( url = 'http://localhost:8545' ) {
5
+ const provider = new ethers . JsonRpcProvider ( url )
6
+ extendProvider ( provider )
7
+ return provider
21
8
}
22
9
23
10
export function web3DebugNode ( network ) {
@@ -35,32 +22,24 @@ export function web3DebugNode (network) {
35
22
return null
36
23
}
37
24
38
- class Web3DebugPlugin extends Web3PluginBase {
39
- public pluginNamespace = 'debug'
25
+ export function extendProvider ( provider ) { // Provider should be ethers.js provider
26
+
27
+ if ( ! provider . debug ) provider . debug = { }
40
28
41
- public preimage ( key , cb ) {
42
- this . requestManager . send ( {
43
- method : 'debug_preimage' ,
44
- params : [ key ]
45
- } )
29
+ provider . debug . preimage = ( key , cb ) => {
30
+ this . send ( 'debug_preimage' , [ key ] )
46
31
. then ( result => cb ( null , result ) )
47
32
. catch ( error => cb ( error ) )
48
33
}
49
34
50
- public traceTransaction ( txHash , options , cb ) {
51
- this . requestManager . send ( {
52
- method : 'debug_traceTransaction' ,
53
- params : [ txHash , options ]
54
- } )
35
+ provider . debug . traceTransaction = ( txHash , options , cb ) => {
36
+ this . send ( 'debug_traceTransaction' , [ txHash , options ] )
55
37
. then ( result => cb ( null , result ) )
56
38
. catch ( error => cb ( error ) )
57
39
}
58
40
59
- public storageRangeAt ( txBlockHash , txIndex , address , start , maxSize , cb ) {
60
- this . requestManager . send ( {
61
- method : 'debug_storageRangeAt' ,
62
- params : [ txBlockHash , toNumber ( txIndex ) , address , start , maxSize ]
63
- } )
41
+ provider . debug . storageRangeAt = ( txBlockHash , txIndex , address , start , maxSize , cb ) => {
42
+ this . send ( 'debug_storageRangeAt' , [ txBlockHash , toNumber ( txIndex ) , address , start , maxSize ] )
64
43
. then ( result => cb ( null , result ) )
65
44
. catch ( error => cb ( error ) )
66
45
}
0 commit comments