fix log issue
MODIFY
src/plasma/erc20.ts
src/plasma/erc20.ts
@@ -21,10 +21,13 @@ export class ERC20 extends PlasmaToken {
}, client, contracts);
}
- getPredicate(): Promise<BaseContract> {
- return this['getPredicate_']("erc721Predicate", "ERC721Predicate");
+ getPredicate() {
+ return this['getPredicate_'](
+ "erc20Predicate", "ERC20Predicate"
+ );
}
+
getBalance(userAddress: string, option: ITransactionOption = {}) {
return this.getContract().then(contract => {
const method = contract.method(

MODIFY
src/plasma/erc20_predicate.ts
src/plasma/erc20_predicate.ts
@@ -7,7 +7,7 @@ export class ErcPredicate extends BaseToken {
{
isParent: true,
address: address,
- name: contractName // "ERC20Predicate"
+ name: contractName
},
client
);

MODIFY
src/plasma/erc721.ts
src/plasma/erc721.ts
@@ -85,11 +85,10 @@ export class ERC721 extends PlasmaToken {
}
getPredicate() {
- return this['getPredicate_'](
- "erc20Predicate", "ERC20Predicate"
- );
+ return this['getPredicate_']("erc721Predicate", "ERC721Predicate");
}
+
private withdrawChallenge_(burnTxHash: string, isFast: boolean, option: ITransactionOption) {
return Promise.all([
this.getPredicate(),
@@ -100,6 +99,7 @@ export class ERC721 extends PlasmaToken {
)
]).then(result => {
const [predicate, payload] = result;
+ console.log("address", predicate.address);
const method = predicate.method(
"startExitWithBurntTokens",
payload

MODIFY
src/plasma/index.ts
src/plasma/index.ts
@@ -48,7 +48,6 @@ export class PlasmaClient extends BridgeClient {
constructor(config: IPlasmaClientConfig) {
super();
this.client_ = new Web3SideChainClient(config);
- this.client_.logger.enableLog(config.log);
}
init() {

MODIFY
src/plasma/plasma_token.ts
src/plasma/plasma_token.ts
@@ -16,7 +16,7 @@ export class PlasmaToken extends BaseToken {
super(contractParam_, client);
}
- private getPredicate_(methodName: string, contractName: string): Promise<BaseContract> {
+ protected getPredicate_(methodName: string, contractName: string): Promise<BaseContract> {
if (this.predicate_) {
return promiseResolve(this.predicate_);
}

MODIFY
src/pos/index.ts
src/pos/index.ts
@@ -21,7 +21,6 @@ export class POSClient extends BridgeClient {
constructor(config: IPOSClientConfig) {
super();
this.client_ = new Web3SideChainClient(config);
- this.client_.logger.enableLog(config.log);
}
init() {

MODIFY
src/utils/base_token.ts
src/utils/base_token.ts
@@ -154,7 +154,7 @@ export class BaseToken {
protected async createTransactionConfig({ txConfig, method, isParent, isWrite }: ITransactionConfigParam) {
const defaultConfig = isParent ? this.parentDefaultConfig : this.childDefaultConfig;
txConfig = Object.assign(defaultConfig, (txConfig || {}));
- console.log("txConfig", txConfig, isParent, isWrite);
+ this.client.logger.log("txConfig", txConfig, "onRoot", isParent, "isWrite", isWrite);
const client = isParent ? this.client.parent :
this.client.child;
const estimateGas = (config: ITransactionConfig) => {
@@ -170,7 +170,7 @@ export class BaseToken {
!txConfig.nonce ? client.getTransactionCount(txConfig.from as string, 'pending') : txConfig.nonce,
!txConfig.chainId ? client.getChainId() : txConfig.chainId,
]);
- console.log("calculated");
+ this.client.logger.log("options filled");
txConfig.gasLimit = isParent ? Number(gasLimit) + EXTRA_GAS_FOR_PROXY_CALL : gasLimit;
txConfig.gasPrice = gasPrice;
txConfig.nonce = nonce;

MODIFY
src/utils/logger.ts
src/utils/logger.ts
@@ -6,7 +6,7 @@ export class Logger {
private isEnabled: boolean;
enableLog(value) {
- this.isEnabled = true;
+ this.isEnabled = value ? true : false;
}
log(...message) {

MODIFY
src/utils/merkle_tree.ts
src/utils/merkle_tree.ts
@@ -25,7 +25,6 @@ export class MerkleTree {
() => utils.zeros(32)
)
);
- console.log("this.leaves", this.leaves, "leaves", leaves);
this.layers = [this.leaves];
this.createHashes(this.leaves);
}
@@ -35,7 +34,6 @@ export class MerkleTree {
return false;
}
- console.log("nodes", nodes);
const treeLevel = [];
for (let i = 0; i < nodes.length; i += 2) {

MODIFY
src/utils/web3_side_chain_client.ts
src/utils/web3_side_chain_client.ts
@@ -12,6 +12,8 @@ export class Web3SideChainClient {
abiHelper: ABIManager;
+ logger = new Logger();
+
constructor(config: IPlasmaClientConfig) {
config = config || {} as any;
config.parent.defaultConfig = config.parent.defaultConfig || {} as any;
@@ -25,6 +27,7 @@ export class Web3SideChainClient {
this.parent = new (Web3Client as any)(config.parent.provider, this.logger);
this.child = new (Web3Client as any)(config.child.provider, this.logger);
+ this.logger.enableLog(config.log);
}
init() {
@@ -50,8 +53,6 @@ export class Web3SideChainClient {
return this.abiHelper.getAddress("Main.POSContracts");
}
- get logger() {
- return new Logger();
- }
+
}

MODIFY
test/debug.js
test/debug.js
@@ -12,6 +12,7 @@ const execute = async () => {
const goerliERC720 = plasma.parent.erc721;
const client = new PlasmaClient({
+ log: true,
network: 'testnet',
version: 'mumbai',
parent: {
@@ -59,16 +60,18 @@ const execute = async () => {
// console.log("tx", tx);
// const result = await client.isCheckPointed('0x41162584974896bfc96d91e7ce72009373cd31acabe92024950831ee7b8067c0')
// console.log("result", result);
- const tx = await goerliERC720Token.withdrawChallengeFaster(
+ const tx = await goerliERC720Token.withdrawChallenge(
'0x41162584974896bfc96d91e7ce72009373cd31acabe92024950831ee7b8067c0',
{
// nonce: 11793,
// gasPrice: '1000',
// gas: 10000,
// returnTransaction: true,
- // gasPrice: '4000000000'
+ // gasPrice: '4000000000',
+ returnTransaction: true
}
);
+ return console.log("tx", tx)
console.log("txHash", await tx.getTransactionHash());
console.log("txReceipt", await tx.getReceipt());
}

fix log issue