Skip to content

Commit

Permalink
Code clean and refactor (#498)
Browse files Browse the repository at this point in the history
* fix: Typos on SPEC

* refactor: Remove @ts-ignore

* refactor: package.json

* Update build solidity scripts to work in mac

* Update yarn.lock

* update yarn.lock
  • Loading branch information
mfornet authored Feb 25, 2021
1 parent 2f1795c commit 8dc2ca2
Show file tree
Hide file tree
Showing 26 changed files with 799 additions and 777 deletions.
4 changes: 2 additions & 2 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

The Rainbow bridge is a composition of software applications allowing smart contracts in different blockchains to establish trustless communication between them. It accomplished by having a mutual "smart contract"-based light clients in both blockchains; and cryptographical proofs of the including events (execution results) of smart contracts in blockchain blocks.
The Rainbow bridge is a composition of software applications allowing smart contracts in different blockchains to establish trustless communication between them. It accomplished by having a mutual "smart contract"-based light clients in both blockchains; and cryptographic proofs of the including events (execution results) of smart contracts in blockchain blocks.

## Architecture

Expand Down Expand Up @@ -41,4 +41,4 @@ Relations:
1. Non-trusted and non-authorized Ethereum relayer software (aka *EthRelayer*) could forward Ethereum block headers into *EthBridge* smart contract hosted in Near blockchain.
2. Non-trusted and non-authorized Near relayer software (aka *NearRelayer*) could forward Near block headers into *NearBridge* smart contract hosted in Ethereum network.
3. *NearProver* verifies Near transaction result was included into Near bloc. And then checks if this block image exisits in *NearBridge*.
4. *EthProver* verifies Ethereum event/log was included into Ethereum transaction receipt which was included into Ethereum block. And then checks if this block image exisits in *EthBridge*.
4. *EthProver* verifies Ethereum event/log was included into Ethereum transaction receipt which was included into Ethereum block. And then checks if this block image exists in *EthBridge*.
1 change: 0 additions & 1 deletion cli/commands/eth-dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const utils = require('ethereumjs-util')

class ETHDump {
static async execute (kindOfData, { path, startBlock, endBlock, ethNodeUrl }) {
// @ts-ignore
const web3 = new Web3(ethNodeUrl)
const extractor = new EthProofExtractor()
extractor.initialize(ethNodeUrl)
Expand Down
3 changes: 0 additions & 3 deletions cli/commands/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ class PrepareCommand {

env.LOCAL_CORE_SRC = coreSrc && path.resolve(coreSrc)

// @ts-ignore
const prepareScript = exec(shell, { env: env })
// @ts-ignore
prepareScript.stdout.on('data', function (data) {
process.stdout.write(data)
})

// @ts-ignore
prepareScript.stderr.on('data', function (data) {
process.stderr.write(data)
})
Expand Down
8 changes: 1 addition & 7 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "rainbow-bridge-cli",
"version": "4.0.0",
"author": "Near Inc. <[email protected]>",
"description": "CLI to set up the environment needed for the Rainbow Bridge to work.",
"main": "index.js",
"bin": {
"rainbow-bridge": "./index.js",
"rainbow": "./index.js"
},
"author": "Near Inc. <[email protected]>",
"repository": {
"type": "git",
"url": "git+https://github.com/near/rainbow-bridge.git"
Expand Down Expand Up @@ -36,11 +36,5 @@
"rainbow-bridge-testing": "1.0.0",
"rainbow-token-connector": "near/rainbow-token-connector#0646850267c42057e92f2d670eebe79c9c9211f9",
"request": "^2.88.2"
},
"devDependencies": {
"standard": "*"
},
"scripts": {
"standard": "standard"
}
}
6 changes: 3 additions & 3 deletions contracts/eth/nearbridge/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "NearBridge",
"name": "near-bridge",
"version": "0.0.1",
"description": "",
"repository": {
"type": "git",
"url": "git@github.com:nearprotocol/near-bridge.git"
"url": "git+https://github.com/near/rainbow-bridge.git"
},
"license": "MIT",
"dependencies": {
Expand Down Expand Up @@ -43,4 +43,4 @@
"lint": "yarn run lint:js && yarn run lint:sol",
"lint:fix": "yarn run lint:js:fix && yarn run lint:sol:fix"
}
}
}
6 changes: 3 additions & 3 deletions contracts/eth/nearprover/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "NearProver",
"name": "near-prover",
"version": "0.0.1",
"description": "",
"repository": {
"type": "git",
"url": "git@github.com:nearprotocol/near-bridge.git"
"url": "git+https://github.com/near/rainbow-bridge.git"
},
"license": "MIT",
"dependencies": {
Expand Down Expand Up @@ -42,4 +42,4 @@
"lint": "yarn run lint:js && yarn run lint:sol",
"lint:fix": "yarn run lint:js:fix && yarn run lint:sol:fix"
}
}
}
7 changes: 5 additions & 2 deletions contracts/eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"scripts": {
"build": "./build_all.sh"
},
"files": [ "nearbridge/contracts/*", "nearprover/contracts/*" ]
}
"files": [
"nearbridge/contracts/*",
"nearprover/contracts/*"
]
}
13 changes: 3 additions & 10 deletions contracts/near/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
{
"name": "rainbow-bridge-rs",
"version": "1.0.2",
"author": "Near Inc. <[email protected]>",
"description": "Rainbow Bridge Rust Contracts",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/near/rainbow-bridge.git"
},
"author": "Near Inc",
"license": "ISC",
"bugs": {
"url": "https://github.com/near/rainbow-bridge-rs/issues"
},
"homepage": "https://github.com/near/rainbow-bridge-rs#readme"
}
"license": "ISC"
}
5 changes: 0 additions & 5 deletions eth2near/eth2near-block-relay/eth-on-near-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function web3BlockToRlp (blockData) {
const borshSchema = {
bool: {
kind: 'function',
// @ts-ignore
ser: (b) => Buffer.from(Web3.utils.hexToBytes(b ? '0x01' : '0x00')),
deser: (z) => readerToHex(1)(z) === '0x01'
},
Expand Down Expand Up @@ -142,7 +141,6 @@ class EthOnNearClientContract extends BorshContract {
await this.accessKeyInit()
let initialized = false
try {
// @ts-ignore
initialized = await this.initialized()
} catch (e) {}
if (!initialized) {
Expand All @@ -151,7 +149,6 @@ class EthOnNearClientContract extends BorshContract {
const blockRlp = web3BlockToRlp(
await robustWeb3.getBlock(lastBlockNumber)
)
// @ts-ignore
await this.init(
{
validate_ethash: validateEthash,
Expand All @@ -169,11 +166,9 @@ class EthOnNearClientContract extends BorshContract {
}

console.log('Checking EthOnNearClient initialization.')
// @ts-ignore
const firstRoot = await this.dag_merkle_root({
epoch: 0
})
// @ts-ignore
const lastRoot = await this.dag_merkle_root({
epoch: 511
})
Expand Down
1 change: 0 additions & 1 deletion eth2near/eth2near-block-relay/eth-on-near-prover.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class EthOnNearProverContract extends BorshContract {
await this.accessKeyInit()

try {
// @ts-ignore
await this.init({
bridge_smart_contract: ethClientAccId
})
Expand Down
1 change: 0 additions & 1 deletion eth2near/eth2near-block-relay/eth-proof-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function logFromWeb3 (result) {

class EthProofExtractor {
initialize (ethNodeURL) {
// @ts-ignore
this.robustWeb3 = new RobustWeb3(ethNodeURL)
this.web3 = this.robustWeb3.web3
}
Expand Down
1 change: 0 additions & 1 deletion eth2near/eth2near-block-relay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class Eth2NearRelay {
}

this.ethClientContract = ethClientContract
// @ts-ignore
this.robustWeb3 = new RobustWeb3(ethNodeUrl)
this.web3 = this.robustWeb3.web3
this.metricsPort = metricsPort
Expand Down
8 changes: 1 addition & 7 deletions eth2near/eth2near-block-relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@
"prom-client": "^12.0.0",
"promisfy": "^1.2.0",
"rainbow-bridge-utils": "1.0.0"
},
"devDependencies": {
"standard": "*"
},
"scripts": {
"standard": "standard"
}
}
}
7 changes: 0 additions & 7 deletions near2eth/near2eth-block-relay/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const fs = require('fs')
// @ts-ignore
const bs58 = require('bs58')
// @ts-ignore
const { toBuffer } = require('eth-util-lite')
const { BN } = require('ethereumjs-util')
const {
Expand All @@ -25,7 +23,6 @@ class Near2EthRelay {
ethGasMultiplier,
metricsPort
}) {
// @ts-ignore
this.robustWeb3 = new RobustWeb3(ethNodeUrl)
this.web3 = this.robustWeb3.web3
this.ethMasterAccount = this.web3.eth.accounts.privateKeyToAccount(
Expand All @@ -47,7 +44,6 @@ class Near2EthRelay {

// Declare Near2EthClient contract.
this.clientContract = new this.web3.eth.Contract(
// @ts-ignore
JSON.parse(
fs.readFileSync(ethClientAbiPath)
),
Expand All @@ -72,13 +68,11 @@ class Near2EthRelay {
const headBlock = await this.near.connection.provider.block({
blockId: status.sync_info.latest_block_height
})
// @ts-ignore
const lastFinalBlockHash = headBlock.header.last_final_block
// The finalized block is not immediately available so we wait for it to become available.
let lightClientBlock = null
let currentValidators = null
while (!lightClientBlock) {
// @ts-ignore
currentValidators = await this.near.connection.provider.sendJsonRpc(
'EXPERIMENTAL_validators_ordered',
[lastFinalBlockHash]
Expand All @@ -101,7 +95,6 @@ class Near2EthRelay {
const borshInitialValidators = borshifyInitialValidators(
currentValidators
)
// @ts-ignore
let gasPrice = new BN(await this.web3.eth.getGasPrice()).mul(new BN(ethGasMultiplier))
let err
for (let i = 0; i < 10; i++) {
Expand Down
8 changes: 1 addition & 7 deletions near2eth/near2eth-block-relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,5 @@
"ethereumjs-util": "^6.2.0",
"prom-client": "^13.0.0",
"rainbow-bridge-utils": "1.0.0"
},
"devDependencies": {
"standard": "*"
},
"scripts": {
"standard": "standard"
}
}
}
2 changes: 0 additions & 2 deletions near2eth/watchdog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Watchdog {
ethClientAddress,
metricsPort
}) {
// @ts-ignore
this.robustWeb3 = new RobustWeb3(ethNodeUrl)
this.web3 = this.robustWeb3.web3
this.metricsPort = metricsPort
Expand All @@ -31,7 +30,6 @@ class Watchdog {
// Initialize client contract.
console.log('Deploying Near2EthClient contract.')
this.clientContract = new this.web3.eth.Contract(
// @ts-ignore
JSON.parse(fs.readFileSync(ethClientAbiPath)),
ethClientAddress,
{
Expand Down
8 changes: 1 addition & 7 deletions near2eth/watchdog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,5 @@
"eth-util-lite": "near/eth-util-lite#master",
"ethereumjs-tx": "^2.1.2",
"rainbow-bridge-utils": "1.0.0"
},
"devDependencies": {
"standard": "*"
},
"scripts": {
"standard": "standard"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"testing",
"utils"
]
}
}
8 changes: 1 addition & 7 deletions testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,5 @@
"ethereumjs-util": "^6.2.0",
"rainbow-bridge-utils": "1.0.0",
"rainbow-bridge-eth2near-block-relay": "1.0.0"
},
"devDependencies": {
"standard": "*"
},
"scripts": {
"standard": "standard"
}
}
}
4 changes: 0 additions & 4 deletions testing/transfer-eth-erc20/from-near.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ class TransferEthERC20FromNear {
web3.eth.defaultAccount = ethMasterAccount.address
ethMasterAccount = ethMasterAccount.address
const clientContract = new web3.eth.Contract(
// @ts-ignore
JSON.parse(fs.readFileSync(ethClientAbiPath)),
ethClientAddress,
{
Expand All @@ -407,7 +406,6 @@ class TransferEthERC20FromNear {
}
)
const proverContract = new web3.eth.Contract(
// @ts-ignore
JSON.parse(fs.readFileSync(ethProverAbiPath)),
ethProverAddress,
{
Expand All @@ -416,7 +414,6 @@ class TransferEthERC20FromNear {
}
)
const ethTokenLockerContract = new web3.eth.Contract(
// @ts-ignore
JSON.parse(fs.readFileSync(ethLockerAbiPath)),
ethLockerAddress,
{
Expand All @@ -425,7 +422,6 @@ class TransferEthERC20FromNear {
}
)
const ethERC20Contract = new web3.eth.Contract(
// @ts-ignore
JSON.parse(fs.readFileSync(ethErc20AbiPath)),
ethErc20Address,
{
Expand Down
1 change: 0 additions & 1 deletion testing/transfer-eth-erc20/near-mintable-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { Web3, BorshContract, readerToHex } = require('rainbow-bridge-utils')
const borshSchema = {
bool: {
kind: 'function',
// @ts-ignore
ser: (b) => Buffer.from(Web3.utils.hexToBytes(b ? '0x01' : '0x00')),
deser: (z) => readerToHex(1)(z) === '0x01'
},
Expand Down
Loading

0 comments on commit 8dc2ca2

Please sign in to comment.