Skip to content

Commit fa35dfa

Browse files
committed
fix (bscscan) use generic factory
1 parent 66b5e31 commit fa35dfa

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/clients/Web3ClientFactory.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import { IConfigData } from '@dequanto/config/interface/IConfigData';
1212
export namespace Web3ClientFactory {
1313

1414
export function get (platform: TPlatform | number, opts?: IWeb3EndpointOptions) {
15-
let options = $config.getWeb3Options(platform);
16-
if (options.platform === 'hardhat' || options.platform.startsWith('hh:')) {
15+
if (typeof platform === 'string' && (platform === 'hardhat' || platform.startsWith('hh:'))) {
1716
let client = di.resolve(HardhatProvider).client('localhost', opts);
18-
if (options.platform.startsWith('hh:')) {
19-
client.configureFork(options.platform.slice(3));
17+
if (platform.startsWith('hh:')) {
18+
client.configureFork(platform.slice(3));
2019
}
2120
return client;
2221
}
2322

23+
24+
let options = $config.getWeb3Options(platform);
2425
$require.notNull(options, `Unsupported platform ${platform} for web3 client`)
2526
return new EvmWeb3Client({
2627
...options,

src/utils/$config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export namespace $config {
4848
} else {
4949
platform = mix;
5050
}
51+
if (platform.startsWith('hh:')) {
52+
// Hardhat fork
53+
return { platform } as any;
54+
}
5155

5256
let web3Config = web3[platform];
5357
if (web3Config == null) {

test/BlockchainExplorer.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Bscscan } from '@dequanto/explorer/Bscscan';
21
import { $http } from '@dequanto/utils/$http';
32
import { File } from 'atma-io'
3+
import { BlockchainExplorerFactory } from '@dequanto/explorer/BlockchainExplorerFactory';
44

55
UTest({
66
async $before () {
@@ -16,7 +16,7 @@ UTest({
1616
},
1717

1818
async 'should fetch ABI by similar ByteCode' () {
19-
let bscscan = new Bscscan();
19+
let bscscan = BlockchainExplorerFactory.get('bsc');
2020
let { abi } = await bscscan.getContractAbi('0xfbD2aa7efA2B46Ce3c58D7ab0D92C176c71499C0');
2121
eq_(typeof abi, 'string');
2222
has_(abi, 'uint256');

0 commit comments

Comments
 (0)