create converter, refactor client config interface
MODIFY
src/constant.ts
src/constant.ts
@@ -14,3 +14,5 @@ export const LOGGER = new Logger();
export const BIG_ONE = new BN(1)
export const BIG_TWO = new BN(2)
export const CHECKPOINT_INTERVAL = new BN(10000)
+
+export const MAX_AMOUNT = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'

MODIFY
src/default.ts
src/default.ts
import { BaseWeb3Client } from "./model";
-import { setWeb3Client } from "./constant";
+import { setWeb3Client, Web3Client } from "./constant";
import { PlasmaClient } from "./plasma";
import { POSClient } from "./pos";
import { Web3Plugin } from "./plugins/plasma_web3_client";
-import { use, util } from "./utils";
+import { use } from "./utils";
export const defaultExport = {
set Web3Client(client: typeof BaseWeb3Client) {
setWeb3Client(client);
},
+ get Web3Client() {
+ return Web3Client;
+ },
use: use,
PlasmaClient: PlasmaClient,
POSClient: POSClient,
Web3Plugin: Web3Plugin,
- util: util
}
\ No newline at end of file

MODIFY
src/index.ts
src/index.ts
@@ -4,7 +4,9 @@ export * from "./pos";
export * from "./plasma";
export * from "./utils";
export * from "./interfaces";
+export * from "./types";
export * from "./model";
+export * from "./constant";
export * from "./plugins/plasma_web3_client";

ADD
src/interfaces/base_client_config.ts
+export interface IBaseClientConfig {
+ network: string;
+ version: string;
+ parent: {
+ provider: any;
+ defaultConfig: {
+ from: string;
+ }
+ };
+ child: {
+ provider: any;
+ defaultConfig: {
+ from: string;
+ }
+ };
+ log?: boolean;
+ requestConcurrency?: number;
+
+}

MODIFY
src/interfaces/index.ts
src/interfaces/index.ts
@@ -14,3 +14,4 @@ export * from "./block_with_transaction";
export * from "./rpc_request_payload";
export * from "./rpc_response_payload";
export * from "./map_promise_option";
+export * from "./base_client_config";
\ No newline at end of file

MODIFY
src/interfaces/plasma_client_config.ts
src/interfaces/plasma_client_config.ts
-export interface IPlasmaClientConfig {
- network: string;
- version: string;
- parent: {
- provider: any;
- defaultConfig: {
- from: string;
- }
- };
- child: {
- provider: any;
- defaultConfig: {
- from: string;
- }
- };
+import { IBaseClientConfig } from "./base_client_config";
+
+export interface IPlasmaClientConfig extends IBaseClientConfig {
+
depositManager?: string;
- log?: boolean;
}
\ No newline at end of file

MODIFY
src/interfaces/pos_client_config.ts
src/interfaces/pos_client_config.ts
-export interface IPOSClientConfig {
- network: string;
- version: string;
- parent: {
- provider: any;
- defaultConfig: {
- from: string;
- }
- };
- child: {
- provider: any;
- defaultConfig: {
- from: string;
- }
- };
+import { IBaseClientConfig } from "./base_client_config";
+
+export interface IPOSClientConfig extends IBaseClientConfig {
rootChainManager?: string;
rootChain?: string;
- log?: boolean;
- requestConcurrency?: number;
}
\ No newline at end of file

MODIFY
src/model/web3_side_chain_client.ts
src/model/web3_side_chain_client.ts
import { SideChainClientOption } from "../types";
-import { Web3Client } from "../constant";
+import { Web3Client, LOGGER } from "../constant";
import { IPlasmaClientConfig } from "../interfaces";
import MetaNetwork from '@maticnetwork/meta/network';
@@ -63,5 +63,9 @@ export class Web3SideChainClient {
get mainPOSContracts() {
return this.metaNetwork.Main.POSContracts;
}
+
+ get logger() {
+ return LOGGER;
+ }
}

MODIFY
src/pos/index.ts
src/pos/index.ts
@@ -8,6 +8,10 @@ import { RootChain } from "./root_chain";
import { initService } from "../services";
import { ERC721 } from "./erc721";
+export * from "./exit_manager";
+export * from "./root_chain_manager";
+export * from "./root_chain";
+
export class POSClient {
rootChainManager: RootChainManager;

ADD
src/utils/converter.ts
+import BN from "bn.js";
+
+export class Converter {
+ static toUint256(amount: BN | string | number) {
+ const dataType = typeof amount;
+ if (dataType === 'number') {
+ amount = new BN(amount);
+ } else if (dataType === 'string') {
+ if ((amount as string).slice(0, 2) === '0x') {
+ return amount;
+ }
+ amount = new BN(amount);
+ }
+ if (BN.isBN(amount)) {
+ return '0x' + amount.toString(16);
+ }
+ else {
+ throw new Error(`Invalid value ${amount}. Can not be converted to uint256`);
+ }
+ }
+}
\ No newline at end of file

MODIFY
src/utils/index.ts
src/utils/index.ts
@@ -8,7 +8,4 @@ export * from "./merge";
export * from "./map_promise";
export * from "./proof_util";
export * from "./http_request";
-
-export const util = {
- proof: ProofUtil
-};
\ No newline at end of file
+export * from "./converter";
\ No newline at end of file

create converter, refactor client config interface