Skip to content

Commit

Permalink
Merge pull request #31 from bnb-chain/develop
Browse files Browse the repository at this point in the history
prepare for the release v0.0.1
  • Loading branch information
unclezoro authored Aug 5, 2022
2 parents f6a8b29 + 302a962 commit 4e81686
Show file tree
Hide file tree
Showing 408 changed files with 5,408 additions and 8,883 deletions.
23 changes: 15 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
## Types of changes
### Description

_Put an `x` in the boxes that apply_
- [ ] New feature
- [ ] Fix bug
- [ ] Recode
- [ ] Log or code annotation change
- [ ] Documentation Update (if none of the other choices apply)
## Change descrpition
add a description of your changes here...

### Rationale

tell us why we need these changes...

### Example

add an example CLI or API response...

### Changes

Notable changes:
* add each change in a bullet point here
* ...
30 changes: 30 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Integration

on:
push:
branches:
- develop

jobs:
deploy:
runs-on: self-hosted
permissions:
issues: write
pull-requests: write
steps:
- name: deploy new zkbas
run: |
cd /tmp
sudo rm -rf ./zkbas
git clone --branch github-action https://github.com/bnb-chain/zkbas.git
echo "start deploy new zkbas"
sudo bash -x ./zkbas/deploy-local.sh new
echo "end deploy"
- name: run integration test
run: |
echo "start integration test"
cd /tmp
sudo bash -x ./zkbas/local-test.sh
echo "end integration test"
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# with Go source code. If you know what GOPATH is then you probably
# don't need to bother with make.

.PHONY: zecrey android ios zecrey-cross evm all test clean
.PHONY: zecrey-linux zecrey-linux-386 zecrey-linux-amd64 zecrey-linux-mips64 zecrey-linux-mips64le
.PHONY: zecrey-linux-arm zecrey-linux-arm-5 zecrey-linux-arm-6 zecrey-linux-arm-7 zecrey-linux-arm64
.PHONY: zecrey-darwin zecrey-darwin-386 zecrey-darwin-amd64
.PHONY: zecrey-windows zecrey-windows-386 zecrey-windows-amd64
.PHONY: zkbas android ios zkbas-cross evm all test clean
.PHONY: zkbas-linux zkbas-linux-386 zkbas-linux-amd64 zkbas-linux-mips64 zkbas-linux-mips64le
.PHONY: zkbas-linux-arm zkbas-linux-arm-5 zkbas-linux-arm-6 zkbas-linux-arm-7 zkbas-linux-arm64
.PHONY: zkbas-darwin zkbas-darwin-386 zkbas-darwin-amd64
.PHONY: zkbas-windows zkbas-windows-386 zkbas-windows-amd64

APP = ./service/api/app
EXPLORE = ./service/api/explorer
Expand All @@ -20,4 +20,11 @@ app:

globalRPCProto:
cd $(globalRPCProtoPath) && goctl rpc protoc globalRPC.proto --go_out=. --go-grpc_out=. --zrpc_out=.;
@echo "Done generate globalRPCProto";
@echo "Done generate globalRPCProto";


deploy:
sudo bash -x ./deploy-local.sh new

test:
sudo bash -x ./local-test.sh
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# zecrey-legend
# zkbas


### goctl
Expand All @@ -10,3 +10,8 @@ goctl api go -api xx.api -dir . -style gozero
goctl rpc protoc xx.proto --go_out=. --go-grpc_out=. --zrpc_out=.
```

### mockgen

```shell
go install github.com/golang/mock/[email protected]
```
12 changes: 6 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ for val in $api; do

echo "Docker Build & Push [${val}]: "
declare -l lower="${val}"
docker build -t us-central1-docker.pkg.dev/zecrey-330903/zecrey-webhook/${lower}:$1 -f service/api/${val}/Dockerfile .
docker push us-central1-docker.pkg.dev/zecrey-330903/zecrey-webhook/${lower}:$1
docker build -t us-central1-docker.pkg.dev/zkbas-330903/zkbas-webhook/${lower}:$1 -f service/api/${val}/Dockerfile .
docker push us-central1-docker.pkg.dev/zkbas-330903/zkbas-webhook/${lower}:$1
docker image prune --filter label=stage=gobuilder --force

rm ./bin/${lower}
Expand All @@ -60,8 +60,8 @@ for val in $rpc; do

echo "Docker Build & Push [${val}]: "
declare -l lower="${val}"
docker build -t us-central1-docker.pkg.dev/zecrey-330903/zecrey-webhook/${lower}:$1 -f service/rpc/${val}/Dockerfile .
docker push us-central1-docker.pkg.dev/zecrey-330903/zecrey-webhook/${lower}:$1
docker build -t us-central1-docker.pkg.dev/zkbas-330903/zkbas-webhook/${lower}:$1 -f service/rpc/${val}/Dockerfile .
docker push us-central1-docker.pkg.dev/zkbas-330903/zkbas-webhook/${lower}:$1
docker image prune --filter label=stage=gobuilder --force

rm ./bin/${lower}
Expand All @@ -76,9 +76,9 @@ for val in $cronjob; do
declare -l lower="${val}"


docker build --no-cache -t us-central1-docker.pkg.dev/zecrey-330903/zecrey-webhook/${lower}:$1 -f service/cronjob/${val}/Dockerfile .
docker build --no-cache -t us-central1-docker.pkg.dev/zkbas-330903/zkbas-webhook/${lower}:$1 -f service/cronjob/${val}/Dockerfile .

docker push us-central1-docker.pkg.dev/zecrey-330903/zecrey-webhook/${lower}:$1
docker push us-central1-docker.pkg.dev/zkbas-330903/zkbas-webhook/${lower}:$1
docker image prune --filter label=stage=gobuilder --force


Expand Down
50 changes: 2 additions & 48 deletions common/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ const (

minAccountIndex = 0
maxAccountIndex = math.MaxUint32

minPublicKeyLength = 20
maxPublicKeyLength = 50

minPairIndex = 0
maxPairIndex = math.MaxUint32

minLPAmount = 0
maxLPAmount = math.MaxUint32

minTxtype = 0
maxTxtype = 8

minLimit = 0
maxLimit = 50

minOffset = 0
maxOffset = math.MaxUint32
)

func CheckAccountName(accountName string) bool {
Expand All @@ -44,44 +26,16 @@ func CheckFormatAccountName(accountName string) bool {
return len(accountName) > maxAccountNameLengthOmitSpace
}

func CheckAccountPK(accountPK string) bool {
return len(accountPK) > maxPublicKeyLength
}

func CheckAssetId(assetId uint32) bool {
return assetId > maxAssetId
}

func CheckAccountIndex(accountIndex uint32) bool {
return accountIndex > maxAccountIndex
}

func CheckPairIndex(pairIndex uint32) bool {
return pairIndex > maxAccountIndex
}

func CheckAmount(amount string) bool { //true:report errors false:continue
return false
}

func CheckTxType(txType uint32) bool {
return txType > maxTxtype
}

func CheckTypeLimit(limit uint32) bool {
return limit > maxLimit
}

func CheckTypeOffset(offset uint32) bool {
return offset > maxOffset
}

func CheckLPAmount(lPAmount uint32) bool {
return lPAmount > maxLPAmount
}

func CheckOffset(offerset, total uint32) bool {
return offerset < total
func CheckOffset(offset, total uint32) bool {
return offset < total
}

// Format AccountName and
Expand Down
3 changes: 2 additions & 1 deletion common/commonAsset/balanceHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
"errors"

"github.com/bnb-chain/zkbas-crypto/ffmath"
"github.com/bnb-chain/zkbas/common/commonConstant"
"github.com/zeromicro/go-zero/core/logx"

"github.com/bnb-chain/zkbas/common/commonConstant"
)

/*
Expand Down
6 changes: 3 additions & 3 deletions common/commonAsset/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package commonAsset

import "math/big"
import (
"math/big"
)

const (
// asset type
Expand All @@ -25,8 +27,6 @@ const (
NftAssetType = 3
CollectionNonceAssetType = 4

RateBase = 10000

BuyOfferType = 0
SellOfferType = 1
)
Expand Down
21 changes: 0 additions & 21 deletions common/commonAsset/errcode/errcode.go

This file was deleted.

4 changes: 3 additions & 1 deletion common/commonAsset/nftHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package commonAsset

import (
"encoding/json"

"github.com/bnb-chain/zkbas/common/commonConstant"
"github.com/bnb-chain/zkbas/errorcode"
)

type NftInfo struct {
Expand All @@ -41,7 +43,7 @@ func (info *NftInfo) String() string {
func ParseNftInfo(infoStr string) (info *NftInfo, err error) {
err = json.Unmarshal([]byte(infoStr), &info)
if err != nil {
return nil, err
return nil, errorcode.JsonErrUnmarshal
}
return info, nil
}
Expand Down
4 changes: 3 additions & 1 deletion common/commonAsset/poolHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"math/big"

"github.com/zeromicro/go-zero/core/logx"

"github.com/bnb-chain/zkbas/errorcode"
)

type LiquidityInfo struct {
Expand Down Expand Up @@ -98,7 +100,7 @@ func ConstructLiquidityInfo(pairIndex int64, assetAId int64, assetAAmount string
func ParseLiquidityInfo(infoStr string) (info *LiquidityInfo, err error) {
err = json.Unmarshal([]byte(infoStr), &info)
if err != nil {
return nil, err
return nil, errorcode.JsonErrUnmarshal
}
return info, nil
}
51 changes: 6 additions & 45 deletions common/commonAsset/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package commonAsset

import (
"encoding/json"
"fmt"
"math/big"

"github.com/bnb-chain/zkbas/common/commonAsset/errcode"
"github.com/bnb-chain/zkbas/common/model/account"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"

"github.com/bnb-chain/zkbas/common/model/account"
"github.com/bnb-chain/zkbas/errorcode"
)

type AccountAsset struct {
Expand All @@ -48,7 +48,7 @@ func ParseAccountAsset(balance string) (asset *AccountAsset, err error) {
err = json.Unmarshal([]byte(balance), &asset)
if err != nil {
logx.Errorf("[ParseAccountAsset] unable to parse account asset")
return nil, err
return nil, errorcode.JsonErrUnmarshal
}
return asset, nil
}
Expand Down Expand Up @@ -76,7 +76,7 @@ type AccountInfo struct {
func FromFormatAccountInfo(formatAccountInfo *AccountInfo) (accountInfo *account.Account, err error) {
assetInfoBytes, err := json.Marshal(formatAccountInfo.AssetInfo)
if err != nil {
return nil, err
return nil, errorcode.JsonErrMarshal
}
accountInfo = &account.Account{
Model: gorm.Model{
Expand All @@ -100,7 +100,7 @@ func ToFormatAccountInfo(accountInfo *account.Account) (formatAccountInfo *Accou
var assetInfo map[int64]*AccountAsset
err = json.Unmarshal([]byte(accountInfo.AssetInfo), &assetInfo)
if err != nil {
return nil, errcode.ErrUnmarshal.RefineError(fmt.Sprint(accountInfo.AssetInfo))
return nil, errorcode.JsonErrUnmarshal
}
formatAccountInfo = &AccountInfo{
AccountId: accountInfo.ID,
Expand Down Expand Up @@ -130,42 +130,3 @@ type FormatAccountHistoryInfo struct {
L2BlockHeight int64
Status int
}

func FromFormatAccountHistoryInfo(formatAccountInfo *FormatAccountHistoryInfo) (accountInfo *account.AccountHistory, err error) {
assetInfoBytes, err := json.Marshal(formatAccountInfo.AssetInfo)
if err != nil {
return nil, err
}
accountInfo = &account.AccountHistory{
Model: gorm.Model{
ID: formatAccountInfo.AccountId,
},
AccountIndex: formatAccountInfo.AccountIndex,
Nonce: formatAccountInfo.Nonce,
CollectionNonce: formatAccountInfo.CollectionNonce,
AssetInfo: string(assetInfoBytes),
AssetRoot: formatAccountInfo.AssetRoot,
L2BlockHeight: formatAccountInfo.L2BlockHeight,
}
return accountInfo, nil
}

func ToFormatAccountHistoryInfo(accountInfo *account.AccountHistory) (formatAccountInfo *FormatAccountHistoryInfo, err error) {
var (
assetInfo map[int64]*AccountAsset
)
err = json.Unmarshal([]byte(accountInfo.AssetInfo), &assetInfo)
if err != nil {
return nil, err
}
formatAccountInfo = &FormatAccountHistoryInfo{
AccountId: accountInfo.ID,
AccountIndex: accountInfo.AccountIndex,
Nonce: accountInfo.Nonce,
CollectionNonce: accountInfo.CollectionNonce,
AssetInfo: assetInfo,
AssetRoot: accountInfo.AssetRoot,
L2BlockHeight: accountInfo.L2BlockHeight,
}
return formatAccountInfo, nil
}
3 changes: 2 additions & 1 deletion common/commonAsset/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package commonAsset

import (
"fmt"
"github.com/bnb-chain/zkbas-crypto/ffmath"
"math/big"
"testing"

"github.com/bnb-chain/zkbas-crypto/ffmath"
)

func TestFromFormatAccountInfo(t *testing.T) {
Expand Down
Loading

0 comments on commit 4e81686

Please sign in to comment.