add init on pos
MODIFY
src/helpers/abi_helper.ts
src/helpers/abi_helper.ts
@@ -44,10 +44,13 @@ export class ABIHelper {
getABI(contractName: string, bridgeType = 'plasma'): Promise<any> {
let targetBridgeABICache = cache[this.networkName][this.version].
abi[bridgeType];
+
+ if (targetBridgeABICache) {
const abiForContract = targetBridgeABICache[contractName];
- if (targetBridgeABICache && abiForContract) {
+ if (abiForContract) {
return promiseResolve<any>(abiForContract);
}
+ }
return service.abi.getABI(
this.networkName,
this.version,

MODIFY
src/plasma/index.ts
src/plasma/index.ts
@@ -51,6 +51,7 @@ export class PlasmaClient {
init() {
const client = this.client_;
+ return client.init().then(_ => {
return this.client_.getABI("DepositManager").then(abi => {
this.depositManager = new DepositManager(
client.parent,
@@ -58,6 +59,7 @@ export class PlasmaClient {
abi
);
});
+ });
}
}

MODIFY
src/pos/index.ts
src/pos/index.ts
@@ -24,6 +24,14 @@ export class POSClient {
this.client_ = new Web3SideChainClient(config);
+
+ }
+
+ init() {
+ console.log("init method called");
+ const client = this.client_;
+ let config: IPOSClientConfig = client.config;
+ return client.init().then(_ => {
const mainPOSContracts = this.client_.mainPOSContracts;
config = Object.assign(
{
@@ -51,6 +59,8 @@ export class POSClient {
);
LOGGER.enableLog(config.log);
+ return this;
+ });
}
erc20(tokenAddress, isParent?: boolean) {

MODIFY
src/utils/web3_side_chain_client.ts
src/utils/web3_side_chain_client.ts
@@ -31,6 +31,7 @@ export class Web3SideChainClient {
const network = config.network;
const version = config.version;
const abiHelper = this.abiHelper = new ABIHelper(network, version);
+ console.log("init called", abiHelper);
return abiHelper.init().catch(err => {
throw new Error(`network ${network} - ${version} is not supported`);
});

MODIFY
test/debug.js
test/debug.js
@@ -32,7 +32,7 @@ const execute = async () => {
const childProvider = new providers.JsonRpcProvider(rpc.child);
- const matic = new POSClient({
+ const posClient = new POSClient({
network: 'testnet',
version: 'mumbai',
parent: {
@@ -49,9 +49,12 @@ const execute = async () => {
}
});
+ await posClient.init();
+ console.log("init called");
+
// const mumbaiERC720Token = matic.erc20(mumbaiERC720);
- const goerliERC720Token = matic.erc20(goerliERC720, true);
- // return console.log("balance", await mumbaiERC720Token.getBalance(from));
+ const goerliERC720Token = posClient.erc20(goerliERC720, true);
+ return console.log("balance", await goerliERC720Token.getBalance(from));
const tx = await goerliERC720Token.approve(100);
console.log("txHash", await tx.getTransactionHash());

MODIFY
webpack/webpack.base.config.js
webpack/webpack.base.config.js
@@ -32,6 +32,7 @@ exports.default = {
},
externals: {
web3: 'web3',
+ ethers: 'ethers',
'ethereumjs-util': 'ethereumjs-util',
'query-string': 'query-string',
'bn.js': 'bn.js',

add init on pos