lint: use single quote
MODIFY
.eslintrc.js
.eslintrc.js
@@ -14,5 +14,6 @@ module.exports = {
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// trailing comma
'comma-dangle': ['error', 'always-multiline'],
+ 'quotes': ['error', 'single'],
}
}

MODIFY
src/helpers/blocks.js
src/helpers/blocks.js
-import utils from "ethereumjs-util"
+import utils from 'ethereumjs-util'
const sha3 = utils.sha3
const BN = utils.BN
@@ -28,8 +28,8 @@ export async function getHeaders(start, end, web3) {
}
export function getBlockHeader(block) {
- const n = new BN(block.number).toArrayLike(Buffer, "be", 32)
- const ts = new BN(block.timestamp).toArrayLike(Buffer, "be", 32)
+ const n = new BN(block.number).toArrayLike(Buffer, 'be', 32)
+ const ts = new BN(block.timestamp).toArrayLike(Buffer, 'be', 32)
const txRoot = utils.toBuffer(block.transactionsRoot)
const receiptsRoot = utils.toBuffer(block.receiptsRoot)
return sha3(Buffer.concat([n, ts, txRoot, receiptsRoot]))

MODIFY
src/helpers/merkle-tree.js
src/helpers/merkle-tree.js
-import utils from "ethereumjs-util"
-import { Buffer } from "safe-buffer"
+import utils from 'ethereumjs-util'
+import { Buffer } from 'safe-buffer'
const sha3 = utils.sha3
export default class MerkleTree {
constructor(leaves = []) {
if (leaves.length < 1) {
- throw new Error("Atleast 1 leaf needed")
+ throw new Error('Atleast 1 leaf needed')
}
const depth = Math.ceil(Math.log(leaves.length) / Math.log(2))
if (depth > 20) {
- throw new Error("Depth must be 20 or less")
+ throw new Error('Depth must be 20 or less')
}
const l = leaves.concat(

MODIFY
src/helpers/proofs.js
src/helpers/proofs.js
-import Trie from "merkle-patricia-tree"
-import utils from "ethereumjs-util"
-import EthereumTx from "ethereumjs-tx"
-import EthereumBlock from "ethereumjs-block/from-rpc"
+import Trie from 'merkle-patricia-tree'
+import utils from 'ethereumjs-util'
+import EthereumTx from 'ethereumjs-tx'
+import EthereumBlock from 'ethereumjs-block/from-rpc'
-import MerkleTree from "./merkle-tree"
+import MerkleTree from './merkle-tree'
const rlp = utils.rlp
@@ -39,7 +39,7 @@ export async function getTxProof(tx, block) {
}
if (reminder.length > 0) {
- return reject(new Error("Node does not contain the key"))
+ return reject(new Error('Node does not contain the key'))
}
const prf = {
@@ -60,9 +60,9 @@ export function getReceiptBytes(receipt) {
if (receipt.status !== undefined && receipt.status !== null) {
status = receipt.status
if (status === true) {
- status = "0x01"
+ status = '0x01'
} else if (status === false) {
- status = "0x00"
+ status = '0x00'
}
}
@@ -117,7 +117,7 @@ export async function getReceiptProof(receipt, block, web3) {
}
if (reminder.length > 0) {
- return reject(new Error("Node does not contain the key"))
+ return reject(new Error('Node does not contain the key'))
}
const prf = {
@@ -145,7 +145,7 @@ export function verifyHeaderProof({ value, valueIndex, headerRoot, proof }) {
}
export function verifyTxProof(proof) {
- const path = utils.toBuffer(proof.path).toString("hex")
+ const path = utils.toBuffer(proof.path).toString('hex')
const value = rlp.decode(utils.toBuffer(proof.value))
const parentNodes = rlp.decode(utils.toBuffer(proof.parentNodes))
const txRoot = utils.toBuffer(proof.root)
@@ -159,7 +159,7 @@ export function verifyTxProof(proof) {
currentNode = parentNodes[i]
const encodedNode = Buffer.from(
utils.sha3(rlp.encode(currentNode)),
- "hex"
+ 'hex'
)
if (!nodeKey.equals(encodedNode)) {
return false
@@ -183,7 +183,7 @@ export function verifyTxProof(proof) {
break
case 2:
pathPtr += nibblesToTraverse(
- currentNode[0].toString("hex"),
+ currentNode[0].toString('hex'),
path,
pathPtr
)
@@ -219,8 +219,8 @@ export function verifyReceiptProof(proof) {
// raw header
function getRawHeader(_block) {
- if (typeof _block.difficulty !== "string") {
- _block.difficulty = "0x" + _block.difficulty.toString(16)
+ if (typeof _block.difficulty !== 'string') {
+ _block.difficulty = '0x' + _block.difficulty.toString(16)
}
const block = new EthereumBlock(_block)
@@ -229,9 +229,9 @@ function getRawHeader(_block) {
// squanch transaction
export function squanchTx(tx) {
- tx.gasPrice = "0x" + parseInt(tx.gasPrice).toString(16)
- tx.value = "0x" + parseInt(tx.value).toString(16) || "0"
- tx.gas = "0x" + parseInt(tx.gas).toString(16)
+ tx.gasPrice = '0x' + parseInt(tx.gasPrice).toString(16)
+ tx.value = '0x' + parseInt(tx.value).toString(16) || '0'
+ tx.gas = '0x' + parseInt(tx.gas).toString(16)
tx.data = tx.input
return tx
}
@@ -239,8 +239,8 @@ export function squanchTx(tx) {
function nibblesToTraverse(encodedPartialPath, path, pathPtr) {
let partialPath
if (
- String(encodedPartialPath[0]) === "0" ||
- String(encodedPartialPath[0]) === "2"
+ String(encodedPartialPath[0]) === '0' ||
+ String(encodedPartialPath[0]) === '2'
) {
partialPath = encodedPartialPath.slice(2)
} else {
@@ -250,6 +250,6 @@ function nibblesToTraverse(encodedPartialPath, path, pathPtr) {
if (partialPath === path.slice(pathPtr, pathPtr + partialPath.length)) {
return partialPath.length
} else {
- throw new Error("path was wrong")
+ throw new Error('path was wrong')
}
}

MODIFY
src/index.js
src/index.js
-import "isomorphic-fetch"
+import 'isomorphic-fetch'
-import Web3 from "web3"
-import utils from "ethereumjs-util"
-import queryString from "query-string"
+import Web3 from 'web3'
+import utils from 'ethereumjs-util'
+import queryString from 'query-string'
import {
getTxBytes,
@@ -12,20 +12,20 @@ import {
verifyTxProof,
verifyReceiptProof,
verifyHeaderProof,
-} from "./helpers/proofs"
-import { getHeaders, getBlockHeader } from "./helpers/blocks"
-import MerkleTree from "./helpers/merkle-tree"
+} from './helpers/proofs'
+import { getHeaders, getBlockHeader } from './helpers/blocks'
+import MerkleTree from './helpers/merkle-tree'
-import RootChainArtifacts from "../artifacts/RootChain"
-import ChildERC20Artifacts from "../artifacts/ChildERC20"
-import StandardTokenArtifacts from "../artifacts/StandardToken"
+import RootChainArtifacts from '../artifacts/RootChain'
+import ChildERC20Artifacts from '../artifacts/ChildERC20'
+import StandardTokenArtifacts from '../artifacts/StandardToken'
const rlp = utils.rlp
export default class Matic {
constructor(options = {}) {
- this._throwIfNull(options.maticProvider, "maticProvider is required")
- this._throwIfNull(options.parentProvider, "parentProvider is required")
+ this._throwIfNull(options.maticProvider, 'maticProvider is required')
+ this._throwIfNull(options.parentProvider, 'parentProvider is required')
this._web3 = new Web3(options.maticProvider)
this._parentWeb3 = new Web3(options.parentProvider)
@@ -354,7 +354,7 @@ export default class Matic {
const from = options.from || this.walletAddress
if (!from) {
throw new Error(
- "`from` required in options or set wallet using maticObject.wallet = <private key>"
+ '`from` required in options or set wallet using maticObject.wallet = <private key>'
)
}
@@ -364,7 +364,7 @@ export default class Matic {
: options.gasLimit || options.gas,
!options.gasPrice ? await web3.eth.getGasPrice() : options.gasPrice,
!options.nonce
- ? await web3.eth.getTransactionCount(from, "pending")
+ ? await web3.eth.getTransactionCount(from, 'pending')
: options.nonce,
!options.chainId ? await web3.eth.net.getId() : options.chainId,
])
@@ -381,9 +381,9 @@ export default class Matic {
_wrapWeb3Promise(promise, options) {
return promise
- .on("transactionHash", options.onTransactionHash)
- .on("receipt", options.onReceipt)
- .on("error", options.onError)
+ .on('transactionHash', options.onTransactionHash)
+ .on('receipt', options.onReceipt)
+ .on('error', options.onError)
}
_apiCall(data = {}) {
@@ -391,13 +391,13 @@ export default class Matic {
const queryParams = data.query && queryString.stringify(data.query || {})
- const url = `${data.url}?${queryParams || ""}`
+ const url = `${data.url}?${queryParams || ''}`
return fetch(url, {
- method: data.method || (data.body ? "POST" : "GET"),
+ method: data.method || (data.body ? 'POST' : 'GET'),
headers: {
- "Content-Type": "application/json",
- Accept: "application/json",
+ 'Content-Type': 'application/json',
+ Accept: 'application/json',
...headers,
},
body: data.body ? JSON.stringify(data.body) : null,

MODIFY
test/index.spec.js
test/index.spec.js
/* global describe, it, beforeEach */
-import chai from "chai"
+import chai from 'chai'
-import Matic from "../src"
+import Matic from '../src'
// set up chai
chai.should()
const expect = chai.expect
-describe("Matic SDK", () => {
- it("should throw error for no required options", () => {
- expect(() => new Matic()).to.throw("maticProvider is required")
+describe('Matic SDK', () => {
+ it('should throw error for no required options', () => {
+ expect(() => new Matic()).to.throw('maticProvider is required')
expect(
- () => new Matic({ maticProvider: "http://localhost:8545" })
- ).to.throw("parentProvider is required")
+ () => new Matic({ maticProvider: 'http://localhost:8545' })
+ ).to.throw('parentProvider is required')
})
- describe("getters and setters", () => {
+ describe('getters and setters', () => {
let maticObject
let kovanTx
beforeEach(() => {
kovanTx =
- "0xb2b90497065c19f7b94d676e5b91bcd23ea71b0b2b4dc71afc184735410bbc42"
+ '0xb2b90497065c19f7b94d676e5b91bcd23ea71b0b2b4dc71afc184735410bbc42'
maticObject = new Matic({
- maticProvider: "https://kovan.infura.io",
- parentProvider: "https://kovan.infura.io",
+ maticProvider: 'https://kovan.infura.io',
+ parentProvider: 'https://kovan.infura.io',
})
})
- it("should create web3 object properly", async() => {
+ it('should create web3 object properly', async() => {
maticObject.web3.should.not.equal(null)
maticObject.parentWeb3.should.not.equal(null)
})
- it("should fetch tx properly", async() => {
+ it('should fetch tx properly', async() => {
const s = await maticObject.getTx(kovanTx)
s.hash.should.equal(kovanTx)
})
- it("should fetch receipt properly", async() => {
+ it('should fetch receipt properly', async() => {
const s = await maticObject.getReceipt(kovanTx)
s.transactionHash.should.equal(kovanTx)
})
- it("should create account", async() => {
+ it('should create account', async() => {
const n = maticObject.newAccount()
n.should.not.equal(null)
maticObject.wallet.should.not.equal(null)
})
- it("should set wallet", async() => {
+ it('should set wallet', async() => {
const pk =
- "0x3a1076bf45ab87712ad64ccb3b10217737f7faacbf2872e88fdd9a537d8fe266"
+ '0x3a1076bf45ab87712ad64ccb3b10217737f7faacbf2872e88fdd9a537d8fe266'
maticObject.wallet = pk
maticObject.wallet.should.not.equal(null)
maticObject.wallet.privateKey.should.equal(pk)

lint: use single quote