make web3sidechainclient generic to take config
MODIFY
package.json
package.json
{
"name": "@maticnetwork/maticjs",
- "version": "3.0.0-beta.3",
+ "version": "3.0.0-beta.4",
"description": "Javascript developer library for interacting with Matic Network",
"main": "dist/npm.export.js",
"types": "dist/ts/index.d.ts",

MODIFY
src/pos/erc20.ts
src/pos/erc20.ts
@@ -4,8 +4,8 @@ import { Converter, Web3SideChainClient } from "../utils";
import { POSToken } from "./pos_token";
import { TYPE_AMOUNT } from "../types";
import { ExitUtil } from "./exit_util";
-import { Log_Event_Signature, ERROR_TYPE } from "../enums";
-import { MAX_AMOUNT } from "..";
+import { Log_Event_Signature } from "../enums";
+import { IPOSClientConfig, MAX_AMOUNT } from "..";
export class ERC20 extends POSToken {
@@ -13,7 +13,7 @@ export class ERC20 extends POSToken {
constructor(
tokenAddress: string,
isParent: boolean,
- client: Web3SideChainClient,
+ client: Web3SideChainClient<IPOSClientConfig>,
rootChainManager: RootChainManager,
exitUtil: ExitUtil
) {

MODIFY
src/pos/erc721.ts
src/pos/erc721.ts
-import { ITransactionOption } from "../interfaces";
+import { IPOSClientConfig, ITransactionOption } from "../interfaces";
import { RootChainManager } from "./root_chain_manager";
import { Converter, Web3SideChainClient } from "../utils";
import { POSToken } from "./pos_token";
@@ -12,7 +12,7 @@ export class ERC721 extends POSToken {
constructor(
tokenAddress: string,
isParent: boolean,
- client: Web3SideChainClient,
+ client: Web3SideChainClient<IPOSClientConfig>,
rootChainManager: RootChainManager,
exitUtil: ExitUtil
) {

MODIFY
src/pos/index.ts
src/pos/index.ts
@@ -15,7 +15,7 @@ export class POSClient extends BridgeClient {
rootChainManager: RootChainManager;
rootChain: RootChain;
- private client_: Web3SideChainClient;
+ private client_: Web3SideChainClient<IPOSClientConfig>;

MODIFY
src/pos/pos_token.ts
src/pos/pos_token.ts
import { BaseToken, Web3SideChainClient, promiseResolve } from "../utils";
-import { IContractInitParam } from "../interfaces";
+import { IBaseClientConfig, IContractInitParam, IPOSClientConfig } from "../interfaces";
import { RootChainManager } from "./root_chain_manager";
import { ExitUtil } from "./exit_util";
-export class POSToken extends BaseToken {
+export class POSToken extends BaseToken<IPOSClientConfig> {
private predicateAddress: string;
constructor(
contractParam: IContractInitParam,
- client: Web3SideChainClient,
+ client: Web3SideChainClient<IPOSClientConfig>,
protected rootChainManager: RootChainManager,
protected exitUtil: ExitUtil
) {

MODIFY
src/pos/root_chain.ts
src/pos/root_chain.ts
@@ -2,11 +2,11 @@ import { BaseToken, Web3SideChainClient } from "../utils";
import { TYPE_AMOUNT } from "../types";
import BN from "bn.js";
import { BIG_ONE, CHECKPOINT_INTERVAL, BIG_TWO } from "../constant";
-import { ITransactionOption } from "../interfaces";
+import { IPOSClientConfig, ITransactionOption } from "../interfaces";
-export class RootChain extends BaseToken {
+export class RootChain extends BaseToken<IPOSClientConfig> {
- constructor(client_: Web3SideChainClient, address: string) {
+ constructor(client_: Web3SideChainClient<IPOSClientConfig>, address: string) {
super({
address: address,
name: 'RootChain',

MODIFY
src/pos/root_chain_manager.ts
src/pos/root_chain_manager.ts
import { BaseToken, Web3SideChainClient } from "../utils";
-import { ITransactionOption } from "../interfaces";
+import { IPOSClientConfig, ITransactionOption } from "../interfaces";
-export class RootChainManager extends BaseToken {
+export class RootChainManager extends BaseToken<IPOSClientConfig> {
- constructor(client_: Web3SideChainClient, address: string) {
+ constructor(client_: Web3SideChainClient<IPOSClientConfig>, address: string) {
super({
address: address,
name: 'RootChainManager',

MODIFY
src/utils/base_token.ts
src/utils/base_token.ts
import { Web3SideChainClient } from "./web3_side_chain_client";
-import { ITransactionConfig, ITransactionOption, IContractInitParam } from "../interfaces";
+import { ITransactionConfig, ITransactionOption, IContractInitParam, IPOSClientConfig, IBaseClientConfig } from "../interfaces";
import { BaseContractMethod, BaseContract, BaseWeb3Client } from "../abstracts";
import { Converter, merge } from "../utils";
import { EXTRA_GAS_FOR_PROXY_CALL } from "../constant";
@@ -16,16 +16,17 @@ export interface ITransactionConfigParam {
isParent?: boolean;
}
-export class BaseToken {
+export class BaseToken<T_CLIENT_CONFIG> {
private contract_: BaseContract;
constructor(
protected contractParam: IContractInitParam,
- protected client: Web3SideChainClient,
+ protected client: Web3SideChainClient<T_CLIENT_CONFIG>,
) {
}
+
getContract(): Promise<BaseContract> {
if (this.contract_) {
return promiseResolve<BaseContract>(this.contract_ as any);
@@ -157,11 +158,13 @@ export class BaseToken {
}
protected get parentDefaultConfig() {
- return this.client.config.parent.defaultConfig;
+ const config: IBaseClientConfig = this.client.config as any;
+ return config.parent.defaultConfig;
}
protected get childDefaultConfig() {
- return this.client.config.child.defaultConfig;
+ const config: IBaseClientConfig = this.client.config as any;
+ return config.child.defaultConfig;
}
protected async createTransactionConfig({ txConfig, method, isParent, isWrite }: ITransactionConfigParam) {

MODIFY
src/utils/web3_side_chain_client.ts
src/utils/web3_side_chain_client.ts
import { Web3Client } from "../constant";
-import { IPOSClientConfig } from "../interfaces";
+import { IBaseClientConfig, IPOSClientConfig } from "../interfaces";
import { BaseWeb3Client } from "../abstracts";
import { ABIManager } from "../helpers";
import { Logger } from "./logger";
-export class Web3SideChainClient {
+export class Web3SideChainClient<T_CONFIG> {
parent: BaseWeb3Client;
child: BaseWeb3Client;
- config: IPOSClientConfig;
+ config: T_CONFIG;
abiHelper: ABIManager;
logger = new Logger();
- constructor(config: IPOSClientConfig) {
+ constructor(config: T_CONFIG) {
config = config || {} as any;
- config.parent.defaultConfig = config.parent.defaultConfig || {} as any;
- config.child.defaultConfig = config.child.defaultConfig || {} as any;
- this.config = config;
+ const baseConfig: IBaseClientConfig = config as any;
+ baseConfig.parent.defaultConfig = baseConfig.parent.defaultConfig || {} as any;
+ baseConfig.child.defaultConfig = baseConfig.child.defaultConfig || {} as any;
+ this.config = baseConfig as any;
if (!Web3Client) {
throw new Error("Web3Client is not set");
}
- this.parent = new (Web3Client as any)(config.parent.provider, this.logger);
- this.child = new (Web3Client as any)(config.child.provider, this.logger);
+ this.parent = new (Web3Client as any)(baseConfig.parent.provider, this.logger);
+ this.child = new (Web3Client as any)(baseConfig.child.provider, this.logger);
- this.logger.enableLog(config.log);
+ this.logger.enableLog(baseConfig.log);
}
init() {
- const config = this.config;
+ const config = this.config as any as IBaseClientConfig;
const network = config.network;
const version = config.version;
const abiHelper = this.abiHelper = new ABIManager(network, version);

MODIFY
test/config.js
test/config.js
@@ -4,20 +4,6 @@ const env = dotenv.config({
path: path.join(__dirname, '.env')
});
module.exports = {
- plasma: {
- parent: {
- erc20: '0x3f152B63Ec5CA5831061B2DccFb29a874C317502',
- erc721: '0xfA08B72137eF907dEB3F202a60EfBc610D2f224b',
- },
- child: {
- erc20: '0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e',
- erc721: '0x33FC58F12A56280503b04AC7911D1EceEBcE179c',
- },
- registryAddress: '0x56B082d0a590A7ce5d170402D6f7f88B58F71988',
- rootChainAddress: '0x82a72315E16cE224f28E1F1fB97856d3bF83f010', // The address for the main Plasma contract in Ropsten testnet
- withdrawManagerAddress: '0x3cf9aD3395028a42EAfc949e2EC4588396b8A7D4', // An address for the WithdrawManager contract on Ropsten testnet
- depositManagerAddress: '0x3Bc6701cA1C32BBaC8D1ffA2294EE3444Ad93989', // An address for a DepositManager contract in Ropsten testnet
- },
rpc: {
parent: process.env.ROOT_RPC,
child: process.env.MATIC_RPC || 'https://rpc-mumbai.matic.today',

MODIFY
test/debug.js
test/debug.js
@@ -2,7 +2,7 @@ const { PlasmaClient, POSClient, use, Web3SideChainClient } = require("@maticnet
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
const HDWalletProvider = require("@truffle/hdwallet-provider");
-const { user1, plasma, rpc, pos } = require("./config");
+const { user1, rpc, pos } = require("./config");
use(Web3ClientPlugin);
const from = user1.address;
@@ -34,7 +34,7 @@ const execute = async () => {
console.log("init called");
// const mumbaiERC720Token = client.erc721('0x33fc58f12a56280503b04ac7911d1eceebce179c');
- const goerliERC20Token = client.erc20(plasma.parent.erc20, true);
+ const goerliERC20Token = client.erc20(pos.parent.erc20, true);
return console.log(await goerliERC20Token.getBalance(from));

MODIFY
tslint.json
tslint.json
"allow-leading-underscore",
"allow-trailing-underscore"
],
- "no-shadowed-variable": true
+ "no-shadowed-variable": true,
+ "naming-convention": [true,
+ // this config will apply to properties AND methods, if you only need it for properties, use "property" instead of "member"
+ {"type": "member", "format": "camelCase"}, // use camelCase for all members, will be inherited by protected and private
+ {"type": "member", "modifiers": "protected", "trailingUnderscore": "require"}, // protected members will be REQUIRED to have a leading underscore. you can use "allow" as alternative
+ {"type": "member", "modifiers": "private", "suffix": "__"} // to simply allow and not enforce double leading underscores, use "prefix": ["__", ""]
+ ]
}
}
\ No newline at end of file

make web3sidechainclient generic to take config