@@ -22,7 +22,7 @@ import {
22
22
} from "@truffle/codec" ;
23
23
import * as Utils from "./utils" ;
24
24
import type * as DecoderTypes from "./types" ;
25
- import Web3 from "web3" ;
25
+ import Web3Utils from "web3-utils " ;
26
26
import type { ContractObject as Artifact } from "@truffle/contract-schema/spec" ;
27
27
import BN from "bn.js" ;
28
28
import type { Provider } from "web3/providers" ;
@@ -33,10 +33,10 @@ import {
33
33
InvalidAddressError ,
34
34
VariableNotFoundError ,
35
35
MemberNotFoundError ,
36
- ArrayIndexOutOfBoundsError ,
37
36
NoProviderError
38
37
} from "./errors" ;
39
38
import { Shims } from "@truffle/compile-common" ;
39
+ import { ProviderAdapter } from "./ProviderAdapter" ;
40
40
//sorry for the untyped import, but...
41
41
const SourceMapUtils = require ( "@truffle/source-map-utils" ) ;
42
42
@@ -45,7 +45,7 @@ const SourceMapUtils = require("@truffle/source-map-utils");
45
45
* @category Decoder
46
46
*/
47
47
export class ProjectDecoder {
48
- private web3 : Web3 ;
48
+ private providerAdapter : ProviderAdapter ;
49
49
50
50
private compilations : Compilations . Compilation [ ] ;
51
51
private contexts : Contexts . Contexts = { } ; //all contexts
@@ -72,7 +72,7 @@ export class ProjectDecoder {
72
72
if ( ! provider ) {
73
73
throw new NoProviderError ( ) ;
74
74
}
75
- this . web3 = new Web3 ( provider ) ;
75
+ this . providerAdapter = new ProviderAdapter ( provider ) ;
76
76
this . compilations = compilations ;
77
77
this . ensSettings = ensSettings || { } ;
78
78
let allocationInfo : AbiData . Allocate . ContractAllocationInfo [ ] ;
@@ -133,7 +133,7 @@ export class ProjectDecoder {
133
133
) : Promise < Uint8Array > {
134
134
//if pending, ignore the cache
135
135
if ( block === "pending" ) {
136
- return Conversion . toBytes ( await this . web3 . eth . getCode ( address , block ) ) ;
136
+ return Conversion . toBytes ( await this . providerAdapter . getCode ( address , block ) ) ;
137
137
}
138
138
139
139
//otherwise, start by setting up any preliminary layers as needed
@@ -145,7 +145,7 @@ export class ProjectDecoder {
145
145
return this . codeCache [ block ] [ address ] ;
146
146
}
147
147
//otherwise, get it, cache it, and return it
148
- let code = Conversion . toBytes ( await this . web3 . eth . getCode ( address , block ) ) ;
148
+ let code = Conversion . toBytes ( await this . providerAdapter . getCode ( address , block ) ) ;
149
149
this . codeCache [ block ] [ address ] = code ;
150
150
return code ;
151
151
}
@@ -163,7 +163,7 @@ export class ProjectDecoder {
163
163
return "pending" ;
164
164
}
165
165
166
- return ( await this . web3 . eth . getBlock ( block ) ) . number ;
166
+ return parseInt ( ( await this . providerAdapter . getBlockByNumber ( block ) ) . number ) ;
167
167
}
168
168
169
169
/**
@@ -346,7 +346,7 @@ export class ProjectDecoder {
346
346
const fromBlockNumber = await this . regularizeBlock ( fromBlock ) ;
347
347
const toBlockNumber = await this . regularizeBlock ( toBlock ) ;
348
348
349
- const logs = await this . web3 . eth . getPastLogs ( {
349
+ const logs = await this . providerAdapter . getPastLogs ( {
350
350
address,
351
351
fromBlock : fromBlockNumber ,
352
352
toBlock : toBlockNumber
@@ -552,10 +552,10 @@ export class ProjectDecoder {
552
552
address : string ,
553
553
block : DecoderTypes . BlockSpecifier = "latest"
554
554
) : Promise < ContractInstanceDecoder > {
555
- if ( ! Web3 . utils . isAddress ( address ) ) {
555
+ if ( ! Web3Utils . isAddress ( address ) ) {
556
556
throw new InvalidAddressError ( address ) ;
557
557
}
558
- address = Web3 . utils . toChecksumAddress ( address ) ;
558
+ address = Web3Utils . toChecksumAddress ( address ) ;
559
559
const blockNumber = await this . regularizeBlock ( block ) ;
560
560
const deployedBytecode = Conversion . toHexString (
561
561
await this . getCode ( address , blockNumber )
@@ -610,8 +610,8 @@ export class ProjectDecoder {
610
610
/**
611
611
* @protected
612
612
*/
613
- public getWeb3 ( ) : Web3 {
614
- return this . web3 ;
613
+ public getProviderAdapter ( ) : ProviderAdapter {
614
+ return this . providerAdapter ;
615
615
}
616
616
617
617
/**
@@ -636,7 +636,7 @@ export class ProjectDecoder {
636
636
* @category Decoder
637
637
*/
638
638
export class ContractDecoder {
639
- private web3 : Web3 ;
639
+ private providerAdapter : ProviderAdapter ;
640
640
641
641
private contexts : Contexts . Contexts ; //note: this is deployed contexts only!
642
642
@@ -669,7 +669,7 @@ export class ContractDecoder {
669
669
this . contract = contract ;
670
670
this . compilation = compilation ;
671
671
this . projectDecoder = projectDecoder ;
672
- this . web3 = projectDecoder . getWeb3 ( ) ;
672
+ this . providerAdapter = projectDecoder . getProviderAdapter ( ) ;
673
673
this . contexts = projectDecoder . getDeployedContexts ( ) ;
674
674
this . userDefinedTypes = this . projectDecoder . getUserDefinedTypes ( ) ;
675
675
@@ -751,7 +751,7 @@ export class ContractDecoder {
751
751
* @protected
752
752
*/
753
753
public async init ( ) : Promise < void > {
754
- this . contractNetwork = ( await this . web3 . eth . net . getId ( ) ) . toString ( ) ;
754
+ this . contractNetwork = await this . providerAdapter . getNetworkId ( ) ;
755
755
}
756
756
757
757
private get context ( ) : Contexts . Context {
@@ -1002,7 +1002,7 @@ export class ContractDecoder {
1002
1002
* @category Decoder
1003
1003
*/
1004
1004
export class ContractInstanceDecoder {
1005
- private web3 : Web3 ;
1005
+ private providerAdapter : ProviderAdapter ;
1006
1006
1007
1007
private compilation : Compilations . Compilation ;
1008
1008
private contract : Compilations . Contract ;
@@ -1036,12 +1036,12 @@ export class ContractInstanceDecoder {
1036
1036
constructor ( contractDecoder : ContractDecoder , address ?: string ) {
1037
1037
this . contractDecoder = contractDecoder ;
1038
1038
this . projectDecoder = this . contractDecoder . getProjectDecoder ( ) ;
1039
- this . web3 = this . projectDecoder . getWeb3 ( ) ;
1039
+ this . providerAdapter = this . projectDecoder . getProviderAdapter ( ) ;
1040
1040
if ( address !== undefined ) {
1041
- if ( ! Web3 . utils . isAddress ( address ) ) {
1041
+ if ( ! Web3Utils . isAddress ( address ) ) {
1042
1042
throw new InvalidAddressError ( address ) ;
1043
1043
}
1044
- this . contractAddress = Web3 . utils . toChecksumAddress ( address ) ;
1044
+ this . contractAddress = Web3Utils . toChecksumAddress ( address ) ;
1045
1045
}
1046
1046
1047
1047
this . referenceDeclarations = this . projectDecoder . getReferenceDeclarations ( ) ;
@@ -1076,7 +1076,7 @@ export class ContractInstanceDecoder {
1076
1076
this . contractCode = Conversion . toHexString (
1077
1077
await this . getCode (
1078
1078
this . contractAddress ,
1079
- await this . web3 . eth . getBlockNumber ( ) //not "latest" because regularized
1079
+ await this . providerAdapter . getBlockNumber ( ) //not "latest" because regularized
1080
1080
)
1081
1081
) ;
1082
1082
@@ -1253,10 +1253,10 @@ export class ContractInstanceDecoder {
1253
1253
address : this . contractAddress ,
1254
1254
code : this . contractCode ,
1255
1255
balanceAsBN : new BN (
1256
- await this . web3 . eth . getBalance ( this . contractAddress , blockNumber )
1256
+ await this . providerAdapter . getBalance ( this . contractAddress , blockNumber )
1257
1257
) ,
1258
1258
nonceAsBN : new BN (
1259
- await this . web3 . eth . getTransactionCount (
1259
+ await this . providerAdapter . getTransactionCount (
1260
1260
this . contractAddress ,
1261
1261
blockNumber
1262
1262
)
@@ -1383,7 +1383,7 @@ export class ContractInstanceDecoder {
1383
1383
//if pending, bypass the cache
1384
1384
if ( block === "pending" ) {
1385
1385
return Conversion . toBytes (
1386
- await this . web3 . eth . getStorageAt ( address , slot , block ) ,
1386
+ await this . providerAdapter . getStorageAt ( address , slot , block ) ,
1387
1387
Codec . Evm . Utils . WORD_SIZE
1388
1388
) ;
1389
1389
}
@@ -1401,7 +1401,7 @@ export class ContractInstanceDecoder {
1401
1401
}
1402
1402
//otherwise, get it, cache it, and return it
1403
1403
let word = Conversion . toBytes (
1404
- await this . web3 . eth . getStorageAt ( address , slot , block ) ,
1404
+ await this . providerAdapter . getStorageAt ( address , slot , block ) ,
1405
1405
Codec . Evm . Utils . WORD_SIZE
1406
1406
) ;
1407
1407
this . storageCache [ block ] [ address ] [ slot . toString ( ) ] = word ;
0 commit comments