make some logs debug logs
MODIFY
src/common/SDKClient.ts
src/common/SDKClient.ts
@@ -80,7 +80,6 @@ export default class SDKClient extends ContractsBase {
}
async transferMaticEth(to: address, amount: BN | string, options?: SendOptions) {
- console.log(to, this.encode(amount))
if (options && (!options.from || !amount || !to)) {
throw new Error('options.from, to or amount is missing')
}

MODIFY
src/common/Web3Client.ts
src/common/Web3Client.ts
import Web3 from 'web3'
import { SendOptions, address } from '../types/Common'
+const logger = {
+ info: require('debug')('maticjs:Web3Client'),
+ debug: require('debug')('maticjs:debug:Web3Client'),
+}
+
export default class Web3Client {
public parentWeb3: Web3
public web3: Web3
@@ -80,7 +85,7 @@ export default class Web3Client {
_options.gas = _options.gas || this.maticDefaultOptions.gas
_options.gasPrice = _options.gasPrice || this.maticDefaultOptions.gasPrice
}
- console.log('sending tx with', { _options })
+ logger.debug('sending tx with', { _options })
return this.wrapWeb3Promise(txObject.send(_options), _options)
}

MODIFY
src/libs/ProofsUtil.ts
src/libs/ProofsUtil.ts
@@ -7,6 +7,11 @@ const MerkleTree = require('./MerkleTree')
const EthereumBlock = require('ethereumjs-block/from-rpc')
const rlp = ethUtils.rlp
+const logger = {
+ info: require('debug')('maticjs:Web3Client'),
+ debug: require('debug')('maticjs:debug:Web3Client'),
+}
+
export default class ProofsUtil {
static getBlockHeader(block) {
const n = new BN(block.number).toArrayLike(Buffer, 'be', 32)
@@ -17,13 +22,13 @@ export default class ProofsUtil {
}
static async buildCheckpointRoot(web3, start, end) {
- console.log('buildCheckpointRoot...')
+ logger.debug('buildCheckpointRoot...')
const tree = await ProofsUtil.buildBlockHeaderMerkle(web3, start, end)
return ethUtils.bufferToHex(tree.getRoot())
}
static async buildBlockProof(web3, start, end, blockNumber) {
- console.log('buildBlockProof...', start, end, blockNumber)
+ logger.debug('buildBlockProof...', start, end, blockNumber)
const tree = await ProofsUtil.buildBlockHeaderMerkle(web3, start, end)
const proof = tree.getProof(ProofsUtil.getBlockHeader(await web3.eth.getBlock(blockNumber, true)))
return ethUtils.bufferToHex(Buffer.concat(proof))
@@ -32,7 +37,7 @@ export default class ProofsUtil {
static async buildBlockHeaderMerkle(web3, start, end) {
const headers = []
for (let i = start; i <= end; i++) {
- console.log('fetching block', i)
+ logger.debug('fetching block', i)
const _blockHeader = ProofsUtil.getBlockHeader(await web3.eth.getBlock(i, true))
headers.push(_blockHeader)
}
@@ -58,9 +63,7 @@ export default class ProofsUtil {
// promise
return new Promise((resolve, reject) => {
- txTrie.findPath(
- rlp.encode(tx.transactionIndex),
- (err, rawTxNode, reminder, stack) => {
+ txTrie.findPath(rlp.encode(tx.transactionIndex), (err, rawTxNode, reminder, stack) => {
if (err) {
return reject(err)
}
@@ -74,11 +77,10 @@ export default class ProofsUtil {
parentNodes: stack.map(s => s.raw),
root: ProofsUtil.getRawHeader(block).transactionsTrie,
path: rlp.encode(tx.transactionIndex),
- value: rlp.decode(rawTxNode.value)
+ value: rlp.decode(rawTxNode.value),
}
resolve(prf)
- }
- )
+ })
})
}
@@ -130,9 +132,7 @@ export default class ProofsUtil {
// promise
return new Promise((resolve, reject) => {
- receiptsTrie.findPath(
- rlp.encode(receipt.transactionIndex),
- (err, rawReceiptNode, reminder, stack) => {
+ receiptsTrie.findPath(rlp.encode(receipt.transactionIndex), (err, rawReceiptNode, reminder, stack) => {
if (err) {
return reject(err)
}
@@ -146,20 +146,17 @@ export default class ProofsUtil {
parentNodes: stack.map(s => s.raw),
root: ProofsUtil.getRawHeader(block).receiptTrie,
path: rlp.encode(receipt.transactionIndex),
- value: rlp.decode(rawReceiptNode.value)
+ value: rlp.decode(rawReceiptNode.value),
}
resolve(prf)
- }
- )
+ })
})
}
static getReceiptBytes(receipt) {
return rlp.encode([
ethUtils.toBuffer(
- receipt.status !== undefined && receipt.status != null
- ? receipt.status ? 1 : 0
- : receipt.root
+ receipt.status !== undefined && receipt.status != null ? (receipt.status ? 1 : 0) : receipt.root
),
ethUtils.toBuffer(receipt.cumulativeGasUsed),
ethUtils.toBuffer(receipt.logsBloom),
@@ -170,9 +167,9 @@ export default class ProofsUtil {
return [
ethUtils.toBuffer(l.address), // convert address to buffer
l.topics.map(ethUtils.toBuffer), // convert topics to buffer
- ethUtils.toBuffer(l.data) // convert data to buffer
+ ethUtils.toBuffer(l.data), // convert data to buffer
]
- })
+ }),
])
}
}

MODIFY
src/root/RootChain.ts
src/root/RootChain.ts
@@ -5,6 +5,11 @@ import { MaticClientInitializationOptions } from '../types/Common'
import Web3Client from '../common/Web3Client'
import BN from 'bn.js'
+const logger = {
+ info: require('debug')('maticjs:Web3Client'),
+ debug: require('debug')('maticjs:debug:Web3Client'),
+}
+
export default class RootChain extends ContractsBase {
public rootChain: Contract
@@ -33,11 +38,10 @@ export default class RootChain extends ContractsBase {
break
}
let mid = start.add(end).div(new BN(2))
- console.log({ start: start.toString(), mid: mid.toString(), end: end.toString() }) // eslint-disable-line
+ logger.debug({ start: start.toString(), mid: mid.toString(), end: end.toString() }) // eslint-disable-line
const headerBlock = await this.web3Client.call(
this.rootChain.methods.headerBlocks(mid.mul(new BN(10000)).toString())
)
- // console.log('headerBlock', headerBlock)
const headerStart = new BN(headerBlock.start)
const headerEnd = new BN(headerBlock.end)
if (headerStart.lte(childBlockNumber) && childBlockNumber.lte(headerEnd)) {

MODIFY
src/root/WithdrawManager.ts
src/root/WithdrawManager.ts
@@ -83,7 +83,7 @@ export default class WithdrawManager extends ContractsBase {
async processExits(token: address, options?: SendOptions) {
options = options || {}
if (!options || !options.gas || options.gas < 2000000) {
- console.log('processExits can be gas expensive, sending in 2000000 gas but even this might not be enough') // eslint-disable-line
+ logger.info('processExits can be gas expensive, sending in 2000000 gas but even this might not be enough') // eslint-disable-line
options.gas = 2000000
}
const txObject = this.withdrawManager.methods.processExits(token)

make some logs debug logs