rm BN and use from web3 plugin
MODIFY
package.json
package.json
{
"name": "@maticnetwork/maticjs",
- "version": "3.0.0-beta.12",
+ "version": "3.0.0-beta.14",
"description": "Javascript developer library for interacting with Matic Network",
"main": "dist/npm.export.js",
"types": "dist/ts/index.d.ts",

MODIFY
src/abstracts/base_big_number.ts
src/abstracts/base_big_number.ts
+import { throwNotImplemented } from "..";
+
export abstract class BaseBigNumber {
- static isBN(value): boolean {
- throw new Error("not implemented");
+ static isBN(value) {
+ return throwNotImplemented<boolean>();
}
abstract toString(): string;

MODIFY
src/constant.ts
src/constant.ts
-import { utils } from "./utils"
-
-export const BIG_ONE = new utils.BN(1)
-export const BIG_TWO = new utils.BN(2)
-export const CHECKPOINT_INTERVAL = new utils.BN(10000)
-
export const MAX_AMOUNT = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'

MODIFY
src/implementation/bn.ts
src/implementation/bn.ts
import BN from "bn.js";
+import { throwNotImplemented } from "..";
import { BaseBigNumber } from "../abstracts";
export class MaticBigNumber extends BaseBigNumber {
- private bn_: BN;
constructor(value) {
super();
- this.bn_ = new BN(value);
-
- // this.bn_.toString()
- }
-
- static isBN(value) {
- if (value instanceof MaticBigNumber) {
- return true;
- }
- return BN.isBN(value);
}
toString(base?) {
- return this.bn_.toString(base);
+ return throwNotImplemented<string>();
}
toNumber() {
- return this.bn_.toNumber();
+ return throwNotImplemented<number>();
}
toBuffer(base?) {
- return this.bn_.toBuffer();
+ return throwNotImplemented<Buffer>();
}
- // static from(value) {
- // return new MaticBigNumber(value);
- // }
-
add(value: BaseBigNumber) {
- const bn = this.bn_.add(
- new BN(value.toString())
- );
- return new MaticBigNumber(bn);
+ return throwNotImplemented<BaseBigNumber>();
}
sub(value: BaseBigNumber) {
- const bn = this.bn_.sub(
- new BN(value.toString())
- );
- return new MaticBigNumber(bn);
+ return throwNotImplemented<BaseBigNumber>();
}
mul(value: BaseBigNumber) {
- const bn = this.bn_.mul(
- new BN(value.toString())
- );
- return new MaticBigNumber(bn);
+ return throwNotImplemented<BaseBigNumber>();
}
div(value: BaseBigNumber) {
- const bn = this.bn_.div(
- new BN(value.toString())
- );
- return new MaticBigNumber(bn);
+ return throwNotImplemented<BaseBigNumber>();
}
lte(value: BaseBigNumber) {
- return this.bn_.lte(
- new BN(value.toString())
- );
+ return throwNotImplemented<boolean>();
}
lt(value: BaseBigNumber) {
- return this.bn_.lt(
- new BN(value.toString())
- );
+ return throwNotImplemented<boolean>();
+
}
gte(value: BaseBigNumber) {
- return this.bn_.gte(
- new BN(value.toString())
- );
+ return throwNotImplemented<boolean>();
+
}
gt(value: BaseBigNumber) {
- return this.bn_.gt(
- new BN(value.toString())
- );
+ return throwNotImplemented<boolean>();
+
}
eq(value: BaseBigNumber) {
- return this.bn_.eq(
- new BN(value.toString())
- );
+ return throwNotImplemented<boolean>();
}
}
\ No newline at end of file

MODIFY
src/pos/root_chain.ts
src/pos/root_chain.ts
import { BaseToken, utils, Web3SideChainClient } from "../utils";
import { TYPE_AMOUNT } from "../types";
-import { BIG_ONE, CHECKPOINT_INTERVAL, BIG_TWO } from "../constant";
import { IPOSClientConfig, ITransactionOption } from "../interfaces";
import { BaseBigNumber } from "..";
@@ -27,15 +26,19 @@ export class RootChain extends BaseToken<IPOSClientConfig> {
}
async findRootBlockFromChild(childBlockNumber: TYPE_AMOUNT): Promise<BaseBigNumber> {
+ const bigOne = new utils.BN(1);
+ const bigtwo = new utils.BN(2);
+ const checkPointInterval = new utils.BN(10000);
+
childBlockNumber = new utils.BN(childBlockNumber);
// first checkpoint id = start * 10000
- let start = BIG_ONE;
+ let start = bigOne;
// last checkpoint id = end * 10000
const method = await this.method("currentHeaderBlock");
const currentHeaderBlock = await method.read<string>();
let end = new utils.BN(currentHeaderBlock).div(
- CHECKPOINT_INTERVAL
+ checkPointInterval
);
// binary search on all the checkpoints to find the checkpoint that contains the childBlockNumber
@@ -45,10 +48,10 @@ export class RootChain extends BaseToken<IPOSClientConfig> {
ans = start;
break;
}
- const mid = start.add(end).div(BIG_TWO);
+ const mid = start.add(end).div(bigtwo);
const headerBlocksMethod = await this.method(
"headerBlocks",
- mid.mul(CHECKPOINT_INTERVAL).toString()
+ mid.mul(checkPointInterval).toString()
);
const headerBlock = await headerBlocksMethod.read<{ start: number, end: number }>();
@@ -61,13 +64,13 @@ export class RootChain extends BaseToken<IPOSClientConfig> {
break;
} else if (headerStart.gt(childBlockNumber)) {
// childBlockNumber was checkpointed before this header
- end = mid.sub(BIG_ONE);
+ end = mid.sub(bigOne);
} else if (headerEnd.lt(childBlockNumber)) {
// childBlockNumber was checkpointed after this header
- start = mid.add(BIG_ONE);
+ start = mid.add(bigOne);
}
}
- return ans.mul(CHECKPOINT_INTERVAL);
+ return ans.mul(checkPointInterval);
}
}
\ No newline at end of file

MODIFY
src/utils/index.ts
src/utils/index.ts
@@ -16,6 +16,7 @@ export * from "./resolve";
export * from "./promise_resolve";
export * from "./bridge_client";
export * from "./abi_manager";
+export * from "./not_implemented";
export const utils = {

ADD
src/utils/not_implemented.ts
+export const throwNotImplemented = <T>() => {
+ throw new Error("not implemented");
+ return '' as any as T;
+};
\ No newline at end of file

rm BN and use from web3 plugin