Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
add abigen script
Browse files Browse the repository at this point in the history
  • Loading branch information
albertchon committed Oct 29, 2020
1 parent a59fb9c commit 44e4e8e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
61 changes: 61 additions & 0 deletions abigen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

truffle build

# dev_utils.go generation
cat build/contracts/DevUtils.json | jq .abi > DevUtils.abi
abigen --abi DevUtils.abi --pkg XXX > dev_utils.go
rm -f DevUtils.abi

perl -i.tmp -pe 's/package XXX/package wrappers/' dev_utils.go
perl -i.tmp -pe 's/XXXDevUtils/DevUtils/g' dev_utils.go
perl -i.tmp -pe 's/_XXX/f/g' dev_utils.go
perl -i.tmp -pe 's/XXX/DevUtils/g' dev_utils.go
perl -i.tmp -pe 'BEGIN {undef $/;} s/\/\/ LibOrderOrder[^\}]*\}//smg' dev_utils.go
perl -i.tmp -pe 's/LibOrderOrderInfo/OrderInfo/g' dev_utils.go
perl -i.tmp -pe 's/LibZeroExTransactionZeroExTransaction/ZeroExTransaction/g' dev_utils.go
perl -i.tmp -pe 's/LibOrderOrder/Order/g' dev_utils.go
rm -f dev_utils.go.tmp
gofmt -w dev_utils.go

# exchange.go generation
cat build/contracts/Exchange.json | jq .abi > Exchange.abi
abigen --abi Exchange.abi --pkg XXX > exchange.go
rm -f Exchange.abi

perl -i.tmp -pe 's/package XXX/package wrappers/' exchange.go
perl -i.tmp -pe 's/XXXExchange/Exchange/g' exchange.go
perl -i.tmp -pe 's/_XXX/f/g' exchange.go
perl -i.tmp -pe 's/XXX/Exchange/g' exchange.go
perl -i.tmp -pe 'BEGIN {undef $/;} s/\/\/ LibOrderOrder[^\}]*\}//smg' exchange.go
perl -i.tmp -pe 's/LibOrderOrderInfo/OrderInfo/g' exchange.go
perl -i.tmp -pe 's/LibZeroExTransactionZeroExTransaction/ZeroExTransaction/g' exchange.go
perl -i.tmp -pe 's/LibOrderOrder/Order/g' exchange.go
rm -f exchange.go.tmp
gofmt -w exchange.go

# erc20.go generation
cat build/contracts/ERC20Token.json | jq .abi > ERC20Token.abi
abigen --abi ERC20Token.abi --pkg XXX > erc20.go
rm -f ERC20Token.abi

perl -i.tmp -pe 's/package XXX/package wrappers/' erc20.go
perl -i.tmp -pe 's/XXXERC20/ERC20/g' erc20.go
perl -i.tmp -pe 's/_XXX/f/g' erc20.go
perl -i.tmp -pe 's/XXX/ERC20/g' erc20.go
rm -f erc20.go.tmp
gofmt -w erc20.go

# weth9.go generation
cat build/contracts/WETH9.json | jq .abi > WETH9.abi
abigen --abi WETH9.abi --pkg XXX > weth9.go
rm -f WETH9.abi

perl -i.tmp -pe 's/package XXX/package wrappers/' weth9.go
perl -i.tmp -pe 's/XXXWETH9/WETH9/g' weth9.go
perl -i.tmp -pe 's/_XXX/f/g' weth9.go
perl -i.tmp -pe 's/XXX/WETH9/g' weth9.go
rm -f weth9.go.tmp
gofmt -w weth9.go

echo "All done! Move dev_utils.go, exchange.go, erc20.go, weth9.go into zeroex-go/wrappers/ now.\nmv dev_utils.go exchange.go erc20.go weth9.go ../zeroex-go/wrappers"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dotenv": "^8.2.0"
},
"scripts": {
"abigen": "sh ./abigen.sh",
"postinstall": "patch-package"
}
}

0 comments on commit 44e4e8e

Please sign in to comment.