Skip to content

Commit

Permalink
Add go bindings (#107)
Browse files Browse the repository at this point in the history
* Add go bindings

Also update dependencies and fix tests.

* Update genfiles and bindings by build bot

Truffle v5.1.56 (core: 5.1.56)
Solidity - 0.5.17 (solc-js)
Node v14.15.1
Web3.js v1.2.9

Co-authored-by: Build Bot <build@celer.network>
  • Loading branch information
Dominator008 and Build Bot committed Dec 6, 2020
1 parent c1ad4e3 commit 5078121
Show file tree
Hide file tree
Showing 23 changed files with 9,769 additions and 1,193 deletions.
95 changes: 46 additions & 49 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,51 @@ version: 2

# try to checkout pr merge if it exists, no op if not a pr build
checkout_pr_merge: &checkout_pr_merge
run:
name: try to checkout pr merge
command: git fetch origin "+refs/pull/${CIRCLE_PULL_REQUEST##*/}/merge" && git checkout -qf FETCH_HEAD || echo "not pr build"
run:
name: try to checkout pr merge
command: git fetch origin "+refs/pull/${CIRCLE_PULL_REQUEST##*/}/merge" && git checkout -qf FETCH_HEAD || echo "not pr build"

jobs:
build:
branches:
ignore:
- gh-pages
docker:
- image: circleci/node:10.15.3
steps:
- checkout
- <<: *checkout_pr_merge
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- run:
name: install node_modules if not exists
command: |
if [ ! -d "node_modules" ]; then
npm install --no-save
fi
- run:
name: fetch abigen binary if not exists
environment:
GETH_TOOL_VER: geth-alltools-linux-amd64-1.9.19-3e064192
GETH_VER_LOG: node_modules/geth_tool_ver.log
command: |
if [ ! -f "$GETH_VER_LOG" ] || [ $GETH_TOOL_VER != $(cat $GETH_VER_LOG) ]; then
echo "Fetching $GETH_TOOL_VER ..."
echo $GETH_TOOL_VER > $GETH_VER_LOG
curl -sL https://gethstore.blob.core.windows.net/builds/$GETH_TOOL_VER.tar.gz | tar -xz -C node_modules/.bin --strip 1 $GETH_TOOL_VER/abigen
fi
- run:
name: run truffle test
command: |
npm run ganache 2> /dev/null 1> /dev/null &
GANACHE_PID=$!
npm run test
kill -9 $GANACHE_PID
# git checkout -- gas_used_logs/ # discard changes generated during ci tests in gas_used_logs/
- run:
name: update genfiles and sync go bindings if PR
command: |
if [ -n "${CIRCLE_PULL_REQUEST##*/}" ]; then
bash ./gen_and_push.sh "${CIRCLE_PULL_REQUEST##*/}" "$CIRCLE_BRANCH"
fi
- save_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
paths:
- 'node_modules'
build:
docker:
- image: circleci/node:14.15.1
steps:
- checkout
- <<: *checkout_pr_merge
- restore_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
- run:
name: install node_modules if not exists
command: |
if [ ! -d "node_modules" ]; then
npm install --no-save
fi
- run:
name: fetch abigen binary if not exists
environment:
GETH_TOOL_VER: geth-alltools-linux-amd64-1.9.24-cc05b050
GETH_VER_LOG: node_modules/geth_tool_ver.log
command: |
if [ ! -f "$GETH_VER_LOG" ] || [ $GETH_TOOL_VER != $(cat $GETH_VER_LOG) ]; then
echo "Fetching $GETH_TOOL_VER ..."
echo $GETH_TOOL_VER > $GETH_VER_LOG
curl -sL https://gethstore.blob.core.windows.net/builds/$GETH_TOOL_VER.tar.gz | tar -xz -C node_modules/.bin --strip 1 $GETH_TOOL_VER/abigen
fi
- run:
name: run truffle test
command: |
npm run ganache 2> /dev/null 1> /dev/null &
GANACHE_PID=$!
npm run test
kill -9 $GANACHE_PID
# git checkout -- gas_used_logs/ # discard changes generated during ci tests in gas_used_logs/
- run:
name: update genfiles and sync go bindings if PR
command: |
if [ -n "${CIRCLE_PULL_REQUEST##*/}" ]; then
bash ./gen_and_push.sh "${CIRCLE_PULL_REQUEST##*/}" "$CIRCLE_BRANCH"
fi
- save_cache:
key: npm-cache-{{ checksum "package-lock.json" }}
paths:
- 'node_modules'
95 changes: 43 additions & 52 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
{
"parser": "babel-eslint",
"extends": [
"standard",
"plugin:promise/recommended",
"plugin:prettier/recommended"
],
"plugins": ["promise"],
"env": {
"browser": true,
"node": true,
"mocha": true,
"jest": true
},
"globals": {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {
// Strict mode
"strict": ["error", "global"],
"parser": "babel-eslint",
"extends": ["standard", "plugin:promise/recommended", "prettier"],
"plugins": ["promise"],
"env": {
"browser": true,
"node": true,
"mocha": true,
"jest": true
},
"globals": {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {
// Strict mode
"strict": ["error", "global"],

// Code style
"camelcase": ["error", { "properties": "never" }],
// "comma-dangle": ["error", "always-multiline"],
"comma-spacing": ["error", { "before": false, "after": true }],
"dot-notation": [
"error",
{ "allowKeywords": true, "allowPattern": "" }
],
"eol-last": ["error", "always"],
"eqeqeq": ["error", "smart"],
"generator-star-spacing": ["error", "before"],
"linebreak-style": ["error", "unix"],
"max-len": ["error", 120, 2],
"no-debugger": "off",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"no-redeclare": ["error", { "builtinGlobals": true }],
"no-trailing-spaces": ["error", { "skipBlankLines": false }],
"no-undef": "error",
"no-use-before-define": "off",
"no-var": "error",
"object-curly-spacing": ["error", "always"],
"prefer-const": "error",
"quotes": ["error", "single"],
// "semi": ["error", "always"],

"promise/always-return": "off",
"promise/avoid-new": "off"
}
// Code style
"camelcase": ["error", {"properties": "never"}],
"comma-dangle": ["error", "only-multiline"],
"comma-spacing": ["error", {"before": false, "after": true}],
"dot-notation": ["error", {"allowKeywords": true, "allowPattern": ""}],
"eol-last": ["error", "always"],
"eqeqeq": ["error", "smart"],
"generator-star-spacing": ["error", "before"],
"linebreak-style": ["error", "unix"],
"no-debugger": "off",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"no-redeclare": ["error", {"builtinGlobals": true}],
"no-trailing-spaces": ["error", {"skipBlankLines": false}],
"no-undef": "error",
"no-use-before-define": "off",
"no-var": "error",
"object-curly-spacing": ["error", "never"],
"prefer-const": "error",
"quotes": ["error", "single", {"allowTemplateLiterals": true}],
"semi": ["error", "always"],
"promise/always-return": "off",
"promise/avoid-new": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ ENV/

# my gitignore
node_modules/
.vscode/
6,473 changes: 6,473 additions & 0 deletions bindings/go/mainchain/dpos.go

Large diffs are not rendered by default.

1,864 changes: 1,864 additions & 0 deletions bindings/go/mainchain/sgn.go

Large diffs are not rendered by default.

26 changes: 5 additions & 21 deletions gen_and_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,26 @@ update_genfiles() {
# append a new commit with generated files to current PR
commit_and_push() {
git add genfiles/
git commit -m "Update genfiles by build bot" -m "$TRUFFLE_VER"
git add bindings/
git commit -m "Update genfiles and bindings by build bot" -m "$TRUFFLE_VER"
# gh_token is an env in CI project setting
git push https://${GH_TOKEN}@github.com/celer-network/sgn-contract.git $BRANCH &>/dev/null
}

# $1 is contract abi/bin name, $2 is go pkg name
abigen_files() {
# mkdir -p $2
../node_modules/.bin/abigen -abi ../genfiles/$1.abi -bin ../genfiles/$1.bin -pkg $2 -type $1 -out $2/$3.go
./node_modules/.bin/abigen -abi ./genfiles/$1.abi -bin ./genfiles/$1.bin -pkg $3 -type $1 -out $2/$3/$4.go
}

# send a PR to gobinding repo
sync_go_binding() {
echo "sync go binding ..."
PR_COMMIT_ID=$(git rev-parse --short HEAD)
echo sgn-contract PR Head Commit: $PR_COMMIT_ID
REPO=https://${GH_TOKEN}@github.com/celer-network/sgn.git
git clone $REPO sgn
pushd sgn
git checkout develop # based on develop branch of sgn repo
git fetch
echo "checkout branch $BRANCH"
git checkout $BRANCH || git checkout -b $BRANCH
git status
echo "abigen files ..."
abigen_files DPoS mainchain dpos
abigen_files SGN mainchain sgn
if [[ $(git status --porcelain) ]]; then
echo "syncing go binding on branch $BRANCH"
git add .
git status
git commit -m "Sync go binding based on sgn-contract PR $PRID" -m "sgn-contract commit: $PR_COMMIT_ID"
git push origin $BRANCH
fi
popd
rm -rf sgn
abigen_files DPoS bindings/go mainchain dpos
abigen_files SGN bindings/go mainchain sgn
}

echo "update go binding ..."
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/celer-network/sgn-contract

go 1.15

require github.com/ethereum/go-ethereum v1.9.24

0 comments on commit 5078121

Please sign in to comment.