Skip to content

Commit

Permalink
feat: add multi sign support (#85)
Browse files Browse the repository at this point in the history
* feat: implement mint && createBridgeCell

* impl burn && watch burn event

* code clean

* feat: support tron network

* feat: fix tron integration

* feat: support eos chain

* feat: use ForceBridgeCongi instead of nconf

* fix: bugfix on ckb handler

* chore: code format

* chore: bugfix when deploy ckb

* feat: impl molecule serialization

* feat: optimize ckb handler for eth

* fix(tron): optimize tron handler

* feat: optimize ckb handler for tron

* feat: support getSudtBalance

* feat: optimize ckb handler for eos

* chore: clean code

* minor change

* fix: fix unit test

* chore: make github-ci

* minor change

* fix: fix pr comments

* fix: use indexer waitUntilSync intead of asleep

* fix: ckb rpc url fix

* fix: github ci fix

* fix: the problem of amount conversion

* fix: amount visualization optimization

* chore: use tron shasta testnet

* feat: support btc cross-chain

* fix: update burn hash start with 0x of btc module

* fix: remove usless comments

* feat: support btc cross-chain

* chore: remove usless comments

* feat: impl ckb multisig

* fix: github ci fix

* chore: minor change

* chore: remove unused file

* chore: test github ci

* chore: test github ci

* chore: test github ci

* feat: optimize bridge cell when mint same asset

* chore: remove unused file

* chore: clean code

* merge from main

* fix: bugfix when txStatus is null

* fix: github ci

* fix: github ci

* fix: github ci

* fix: use config.json instead of  multisig infos.json

* chore: minor change

* feat: add multi-sign server

* remove pwlocks dep

* minor change

* refactor: add multisigMgr

* feat: add ckb mint & create bridge cell verify

* refactor: opt sig server

* feat: add eth unlock verify (#2)

* feat: add eth unlock verify

* feat: add unlock record verify

* chore: update the config

* feat: add eth signer

* fix(ci): ckbSigner support btc,eos,tron

* merge: merge main branch code before refactor (#5)

* fix: fix ckb contract name and burn amount (#58)

* fix: add btc confirm and orm time zone and contract eth name

* chore: format ckb contract code

* chore: format ckb contract code

* fix: remove btc confirm part

* fix(cli): fix cli asset ownLockHash (#59)

Co-authored-by: wangbing <wangbing@cryptape.com>

* fix: add btc confirm number and add sql timezone (#60)

* fix: add btc confirm and orm time zone and contract eth name

* chore: format ckb contract code

* chore: format ckb contract code

* fix: remove ckb contracts

* chore: format ckb code

* feat: update ckb assetid (#62)

* fix(rpc): fix getBalance too slow (#63)

* feat: update ckb assetid

* feat: update ckb getBalance

* fix: update txSummary

* fix(eos): using private node in ci test (#42)

Co-authored-by: wangbing <wangbing@cryptape.com>

* chore: lint for staged files  (#65)

* chore: lint for staged files

* chore: check the types when lint

* docs: add user-guide.md (#61)

* docs: add user-guide.md

* chore: add pw-lock ref link

* fix: update tx summary query (#66)

* fix: opt log (#57)

* fix: opt log

* feat(log): 增加file类型的日志输出

* chore(log): opt ckb & eth handler log

* chore(log): opt ci test log

* fix: update tron-ci test order, to fix tron ci test failed cause by local time large then tron test server time

Co-authored-by: wangbing <wangbing@cryptape.com>

* chore: prepare husky to avoid cannot find git error (#70)

* fix(ckb-contracts): add bridge_lock_hash_type to recipient data (#67)

* fix(ckb-contracts): add bridge_lock_hash_type to recipient data

* fix

* fix

* fix

* fix: change watch ckb mint status way (#69)

* fix: change watch ckb mint status way

* fix: update ckb handler

* chore: update code

* chore: update logger

* chore: update logger info

* chore: reset mint sent log

* fix: remove mysql index of enum

* fix: use index

* feat: support use private key path in config (#75)

* feat: support use private key path in config

* fix ci

* lint

* fix(offchain): deploy asset bridge cell when start (#74)

* fix(offchain): deploy asset bridge cell when start

* fix

* feat: support query by other chain address  (#71)

* feat: support other address query

* chore: format log

* chore: format response

* fix: update filter

* fix: pass the ci

* fix: pass the tron ci

Co-authored-by: Eric.Wang <136147966@qq.com>
Co-authored-by: wangbing <wangbing@cryptape.com>
Co-authored-by: Yonghui Lin <homura.dev@gmail.com>
Co-authored-by: mkxbl <33241113+mkxbl@users.noreply.github.com>
Co-authored-by: JacobDenver007 <29848184+JacobDenver007@users.noreply.github.com>
Co-authored-by: Wenchao Hu <me@huwenchao.com>

* style: format code to pass the verify

* feat: add ckb-multi-sign

* chore: update the code lint

* fix: fix some problems

* style: format code to pass check

* style: remove src package

* chore: format code

* fix: use main branch lint-staged

* fix: remove unused code and config

Co-authored-by: LeonLi000 <matrix.skygirl@gmail.com>
Co-authored-by: jacobdenver007 <jacobdenver@163.com>
Co-authored-by: wangbing <wangbing@cryptape.com>
Co-authored-by: Eric.Wang <136147966@qq.com>
Co-authored-by: Yonghui Lin <homura.dev@gmail.com>
Co-authored-by: mkxbl <33241113+mkxbl@users.noreply.github.com>
Co-authored-by: JacobDenver007 <29848184+JacobDenver007@users.noreply.github.com>
Co-authored-by: Wenchao Hu <me@huwenchao.com>
  • Loading branch information
9 people committed May 26, 2021
1 parent 64e7b76 commit 573df19
Show file tree
Hide file tree
Showing 44 changed files with 1,722 additions and 344 deletions.
25 changes: 24 additions & 1 deletion offchain-modules/config.json.example
Expand Up @@ -14,6 +14,10 @@
"0x193c96316c6cada898f067004aa07a5d48fcecdb1aa158784f2e8868a4db7ce8",
"0x57c246bcb73e5d3409a903c94d46b3b118fdcfb81c5e51d3b0df72e883623fa7"
],
"multiSignHosts": [
"http://localhost:8090/force-bridge/sign-server/api/v1",
"http://localhost:8091/force-bridge/sign-server/api/v1"
],
"multiSignThreshold": 2,
"contractAddress": "0x8326e1d621Cd32752920ed2A44B49bB1a96c7391",
"confirmNumber": 1,
Expand Down Expand Up @@ -57,7 +61,26 @@
"ckb": {
"ckbRpcUrl": "http://127.0.0.1:8114",
"ckbIndexerUrl": "http://127.0.0.1:8116",
"privateKey": "0xa800c82df5461756ae99b5c6677d019c98cc98c7786b80d7b2e77256e46ea1fe",
"multisigScript": {
"R": 0,
"M": 2,
"publicKeyHashes": [
"0x40dcec2ef1ffc2340ea13ff4dd9671d2f9787e95",
"0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7",
"0x470dcdc5e44064909650113a274b3b36aecb6dc7",
"0xd9a188cc1985a7d4a31f141f4ebb61f241aec182",
"0xebf9befcd8396e88cab8fcb920ab149231658f4b"
]
},
"keys": [
"0xd00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc",
"0x63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d"
],
"hosts": [
"http://127.0.0.1:8090/force-bridge/sign-server/api/v1",
"http://127.0.0.1:8091/force-bridge/sign-server/api/v1"
],
"fromPrivateKey": "0xa800c82df5461756ae99b5c6677d019c98cc98c7786b80d7b2e77256e46ea1fe",
"ownerLockHash": "0x49beb8c4c29d06e05452b5d9ea8e86ffd4ea2b614498ba1a0c47890a0ad4f550",
"deps": {
"bridgeLock": {
Expand Down
32 changes: 23 additions & 9 deletions offchain-modules/package.json
Expand Up @@ -14,29 +14,32 @@
"build": "lerna run build",
"test": "ava",
"lint": "run-p check:prettier check:eslint",
"lint-staged": "eslint --fix $(git diff --cached --staged --name-only --relative | grep -E \"(.ts$)\")",
"lint-staged": "npm run build && eslint --fix $(git diff --cached --staged --name-only --relative | grep -E \"(.ts$)\")",
"fix": "run-p fix:prettier fix:eslint",
"fix:eslint": "eslint --fix --format=pretty 'packages/*/src/**/*.ts'",
"fix:prettier": "prettier --write .",
"watch:start": "ts-node-dev --respawn --transpile-only ./packages/apps/relayer/index.ts",
"check:prettier": "prettier -c .",
"check:eslint": "yarn eslint --format=pretty 'packages/*/src/**/*.ts'",
"clean": "rimraf lumos_db dist force-bridge.sqlite",
"clean": "rimraf lumos_db indexer-data dist force-bridge.sqlite",
"eth-test": "ts-node ./packages/scripts/src/integration-test/eth.ts",
"eos-test": "ts-node ./packages/scripts/src/integration-test/eos.ts",
"tron-test": "ts-node ./packages/scripts/src/integration-test/tron.ts",
"prepare-xchain-test": "sleep 2",
"btc-test": "ts-node ./packages/scripts/src/integration-test/btc.ts",
"xchain-test": "run-s prepare-xchain-test eth-test",
"integration-test": "run-p -r start xchain-test",
"ci": "run-s clean build deploy integration-test",
"prepare-xchain-test": "sleep 5",
"btc-test": "ts-node ./packages/scripts/src/integration-test/btc.ts",
"integration-test": "run-p -r start sign-server1 sign-server2 xchain-test",
"ci": "run-s clean build deploy init-multisig prepare-xchain-test integration-test",
"test:unit": "nyc --silent ava",
"cov": "run-s build test:unit",
"cov:html": "nyc report --reporter=html",
"cov:send": "nyc report --reporter=lcov && codecov",
"cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
"deploy": "ts-node-dev ./packages/scripts/src/deploy_ckb.ts",
"prepare": "cd .. && husky install offchain-modules/.husky"
"prepare": "cd .. && husky install offchain-modules/.husky",
"init-multisig": "ts-node ./packages/x/src/ckb/tx-helper/multisig/deploy.ts",
"sign-server1": "ts-node ./packages/app-multisign-server/src/index.ts --port 8090 --index 0",
"sign-server2": "ts-node ./packages/app-multisign-server/src/index.ts --port 8091 --index 1"
},
"author": "",
"license": "MIT",
Expand Down Expand Up @@ -68,12 +71,18 @@
"tsconfig-paths": "^3.9.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.2.2"
"typescript": "^4.2.2",
"@types/minimist": "^1.2.1"
},
"dependencies": {
"@ckb-lumos/base": "^0.16.0",
"@ckb-lumos/indexer": "^0.16.0",
"@ckb-lumos/rpc": "^0.16.0",
"@ckb-lumos/rpc": "0.16.0",
"@ckb-lumos/common-scripts": "^0.16.0",
"@ckb-lumos/config-manager": "^0.16.0",
"@ckb-lumos/hd": "^0.16.0",
"@ckb-lumos/helpers": "^0.16.0",
"@ckb-lumos/transaction-manager": "^0.16.0",
"@lay2/pw-core": "^0.3.22",
"@nervosnetwork/ckb-sdk-core": "^0.39.0",
"@types/node": "^15.0.2",
Expand Down Expand Up @@ -125,5 +134,10 @@
"npm run lint-staged",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
2 changes: 1 addition & 1 deletion offchain-modules/packages/app-cli/src/btc.ts
Expand Up @@ -102,7 +102,7 @@ async function doUnlock(
const amount = options.get('amount');

const account = new Account(privateKey);
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.indexer));
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.ckbIndexer));
const burnAmount = new Amount(Unit.fromBTC(amount).toSatoshis(), 0);
const burnTx = await generator.burn(
await account.getLockscript(),
Expand Down
2 changes: 1 addition & 1 deletion offchain-modules/packages/app-cli/src/eos.ts
Expand Up @@ -105,7 +105,7 @@ async function doUnlock(
}

const account = new Account(privateKey);
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.indexer));
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.ckbIndexer));
const burnTx = await generator.burn(
await account.getLockscript(),
recipientAddress,
Expand Down
2 changes: 1 addition & 1 deletion offchain-modules/packages/app-cli/src/eth.ts
Expand Up @@ -102,7 +102,7 @@ async function doUnlock(
const token = !options.get('asset') ? ETH_ASSET : options.get('asset');

const account = new Account(privateKey);
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.indexer));
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.ckbIndexer));
const burnTx = await generator.burn(
await account.getLockscript(),
recipientAddress,
Expand Down
2 changes: 1 addition & 1 deletion offchain-modules/packages/app-cli/src/tron.ts
Expand Up @@ -85,7 +85,7 @@ async function doUnlock(
const privateKey = options.get('privateKey');

const account = new Account(privateKey);
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.indexer));
const generator = new CkbTxGenerator(ForceBridgeCore.ckb, new IndexerCollector(ForceBridgeCore.ckbIndexer));
const burnTx = await generator.burn(
await account.getLockscript(),
recipientAddress,
Expand Down
2 changes: 1 addition & 1 deletion offchain-modules/packages/app-cli/src/utils.ts
Expand Up @@ -44,7 +44,7 @@ export async function getSudtBalance(address: string, asset: Asset): Promise<Amo
};

const userScript = ForceBridgeCore.ckb.utils.addressToScript(address);
const collector = new IndexerCollector(ForceBridgeCore.indexer);
const collector = new IndexerCollector(ForceBridgeCore.ckbIndexer);
return await collector.getSUDTBalance(
new Script(sudtType.codeHash, sudtType.args, sudtType.hashType),
new Script(userScript.codeHash, userScript.args, userScript.hashType as HashType),
Expand Down
14 changes: 14 additions & 0 deletions offchain-modules/packages/app-multisign-server/package.json
@@ -0,0 +1,14 @@
{
"name": "@force-bridge/app-multisign-server",
"main": "dist",
"scripts": {
"build": "yarn run clean && yarn run compile",
"clean": "rimraf -rf ./dist",
"compile": "tsc -p tsconfig.build.json",
"prepublishOnly": "yarn run build",
"test": "yarn run build"
},
"dependencies": {
"@force-bridge/x": "*"
}
}

0 comments on commit 573df19

Please sign in to comment.