diff --git a/CMakeLists.txt b/CMakeLists.txt index f8a8c7310..f0c69b5aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,9 @@ add_custom_target(brick GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} ${ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} DEPENDS libtool) +add_custom_target(mpdumpdiag GO111MODULE=on GOBIN=${BIN_DIR} go install ${GCFLAGS} -ldflags \"-X main.githash=`git describe --tags`\" ./tools/mpdumpdiag/... + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) + add_custom_target(deps DEPENDS libtool) add_custom_target(check GO111MODULE=on go test -timeout 600s ./... diff --git a/Docker/Dockerfile.builder b/Docker/Dockerfile.builder index 88e23b2aa..ba38f13e6 100644 --- a/Docker/Dockerfile.builder +++ b/Docker/Dockerfile.builder @@ -4,4 +4,3 @@ RUN apt-get -y update && apt-get -y install build-essential git cmake binutils m RUN git clone --branch ${GIT_TAG} --recursive https://github.com/aergoio/aergo.git \ && cd aergo \ && make aergosvr polaris colaris aergocli aergoluac brick - diff --git a/Docker/Dockerfile.local b/Docker/Dockerfile.local new file mode 100644 index 000000000..b2a6e8f16 --- /dev/null +++ b/Docker/Dockerfile.local @@ -0,0 +1,4 @@ +FROM golang:1.19.0-bullseye as builder +RUN apt-get -y update && apt-get -y install build-essential git cmake binutils m4 file +COPY . aergo +RUN cd aergo && make aergosvr polaris colaris aergocli aergoluac brick diff --git a/Docker/build-local.sh b/Docker/build-local.sh new file mode 100755 index 000000000..f18a3c406 --- /dev/null +++ b/Docker/build-local.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + +# This script can be used to build the Docker images manually (outside of CI) + +set -e + +MAIN_TAG=$1 +SECOND_TAG=$2 +THIRD_TAG=$3 + +if [[ -z "$MAIN_TAG" ]] +then + echo "Usage:" + echo " build-local.sh tag [second-tag] [third-tag]" + echo "Example:" + echo " build-local.sh 0.12.0-rc" + echo " build-local.sh 0.12.0 0.12 latest" + exit 1 +fi + + +echo "Preparing local folder for build" + +cd .. +git submodule update --init --recursive +make clean || true +rm -rf build +go clean --cache + + +if [[ -z "$THIRD_TAG" ]] +then + if [[ -z "$SECOND_TAG" ]] + then + declare -a tags=("$MAIN_TAG") + else + declare -a tags=("$MAIN_TAG" "$SECOND_TAG") + fi +else + declare -a tags=("$MAIN_TAG" "$SECOND_TAG" "$THIRD_TAG") +fi + +echo "Building Docker images for ${tags[*]} using local folder" +sleep 1 + +BUILDER_TAG="aergo/local-builder" +echo "Building ${BUILDER_TAG}" + +docker build --no-cache --file Docker/Dockerfile.local -t ${BUILDER_TAG} . +cd - +docker create --name extract ${BUILDER_TAG} +docker cp extract:/go/aergo/bin/ . +docker cp extract:/go/aergo/cmd/brick/arglog.toml bin/brick-arglog.toml +docker cp extract:/go/aergo/libtool/lib/ . +docker rm -f extract + +declare -a names=("node" "tools" "polaris") +for name in "${names[@]}" +do + tagsExpanded=() + for tag in "${tags[@]}"; do + tagsExpanded+=("-t aergo/$name:$tag") + done + echo "[aergo/$name:${tags[*]}]" + DOCKERFILE="Dockerfile.$name" + echo docker build -q ${tagsExpanded[@]} --file $DOCKERFILE . + imageid=`docker build -q ${tagsExpanded[@]} --file $DOCKERFILE .` + docker images --format "Done: \t{{.Repository}}:{{.Tag}} \t{{.ID}} ({{.Size}})" | grep "${imageid:7:12}" +done + +rm -rf bin lib + +echo -e "\nREPOSITORY TAG IMAGE ID CREATED SIZE" +for name in "${names[@]}" +do + for tag in "${tags[@]}" + do + docker images aergo/$name:$tag | tail -1 + done +done + +echo -e "\nYou can now push these to Docker Hub." +echo "For example:" + +declare -a names=("node" "tools" "polaris") +for name in "${names[@]}" +do + for tag in "${tags[@]}" + do + echo " docker push aergo/$name:$tag" + done +done diff --git a/Makefile b/Makefile index f4b54a3b2..b23750fe1 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ endif BUILD_RULES := \ deps \ - aergocli aergosvr aergoluac polaris colaris brick \ + aergocli aergosvr aergoluac polaris colaris brick mpdumpdiag\ libtool libtool-clean \ libluajit liblmdb libgmp \ libluajit-clean liblmdb-clean libgmp-clean \ diff --git a/README.md b/README.md index c5c5551ee..b63615755 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ You can see the current public network status on [Aergoscan](https://aergoscan.i * Various Smart Contract Examples * Provide some standard smart contracts * TestNet - * Launch the Test Network to provide network for community and experment + * Launch the Test Network to provide network for community and experiment * We provide https://aergoscan.io. ### 1st: Aergo Alpha (31, Oct, 2018) diff --git a/aergo-protobuf b/aergo-protobuf index 0c3579cd4..f0b2b8a6a 160000 --- a/aergo-protobuf +++ b/aergo-protobuf @@ -1 +1 @@ -Subproject commit 0c3579cd42f830eb787715a78895d971b8ee5fce +Subproject commit f0b2b8a6a9347c5b9c44c5bb9e2a30f13a47235b diff --git a/blacklist/blacklist.go b/blacklist/blacklist.go new file mode 100644 index 000000000..373b608d2 --- /dev/null +++ b/blacklist/blacklist.go @@ -0,0 +1,59 @@ +package blacklist + +import ( + "github.com/aergoio/aergo/v2/types" + "github.com/aergoio/aergo/v2/internal/common" + "github.com/aergoio/aergo/v2/internal/enc/hex" +) + +type Blacklist struct { + sourcelist []string // account address (b58 encoded like Am...) or id (32 bytes in hex = 64 bytes) + blocked map[string]bool // all above converted to account id (32 bytes) +} + +var globalBlacklist *Blacklist + +// Initialize sets up the blacklist with the given addresses. +// This function should be called only once at the start. +func Initialize(addresses []string) { + conf := &Blacklist{} + conf.sourcelist = make([]string, len(addresses)) + copy(conf.sourcelist, addresses) + conf.blocked = make(map[string]bool) + for _, v := range addresses { + key, err := toKey(v) + if err == nil { + conf.blocked[key] = true + } else { + // Handle invalid address, log or take other actions as needed + } + } + globalBlacklist = conf +} + +func Check(address string) bool { + if globalBlacklist == nil { + return false + } + key, err := toKey(address) + if err != nil { + return false + } + return globalBlacklist.blocked[key] +} + +func toKey(address string) (string, error) { + var key []byte + var err error + if len(address) == 64 { + key, err = hex.Decode(address) + } else { + var addr []byte + addr, err = types.DecodeAddress(address) + if err != nil { + return "", err + } + key = common.Hasher(addr) + } + return string(key), err +} diff --git a/chain/chainhandle.go b/chain/chainhandle.go index 0a35e7082..d28e4e742 100644 --- a/chain/chainhandle.go +++ b/chain/chainhandle.go @@ -979,12 +979,19 @@ func executeTx(execCtx context.Context, ccc consensus.ChainConsensusCluster, cdb return err } - if recipient, err = name.Resolve(bs, txBody.Recipient, isQuirkTx); err != nil { - return err + isMultiCall := (txBody.Type == types.TxType_MULTICALL) + + if !isMultiCall { + if recipient, err = name.Resolve(bs, txBody.Recipient, isQuirkTx); err != nil { + return err + } } + var receiver *state.AccountState status := "SUCCESS" - if len(recipient) > 0 { + if isMultiCall { + receiver = sender + } else if len(recipient) > 0 { receiver, err = state.GetAccountState(recipient, bs.StateDB) if receiver != nil && txBody.Type == types.TxType_REDEPLOY { status = "RECREATED" @@ -1001,8 +1008,9 @@ func executeTx(execCtx context.Context, ccc consensus.ChainConsensusCluster, cdb var txFee *big.Int var rv string var events []*types.Event + switch txBody.Type { - case types.TxType_NORMAL, types.TxType_REDEPLOY, types.TxType_TRANSFER, types.TxType_CALL, types.TxType_DEPLOY: + case types.TxType_NORMAL, types.TxType_TRANSFER, types.TxType_CALL, types.TxType_MULTICALL, types.TxType_DEPLOY, types.TxType_REDEPLOY: rv, events, txFee, err = contract.Execute(execCtx, bs, cdb, tx.GetTx(), sender, receiver, bi, executionMode, false) sender.SubBalance(txFee) case types.TxType_GOVERNANCE: diff --git a/cmd/aergocli/cmd/contract.go b/cmd/aergocli/cmd/contract.go index 9d0b6f4cb..fb949583f 100644 --- a/cmd/aergocli/cmd/contract.go +++ b/cmd/aergocli/cmd/contract.go @@ -3,6 +3,7 @@ package cmd import ( "bytes" "context" + "math/big" "encoding/json" "errors" "fmt" @@ -70,17 +71,17 @@ func init() { contractCmd.PersistentFlags().Uint64VarP(&gas, "gaslimit", "g", 0, "Gas limit") deployCmd := &cobra.Command{ - Use: `deploy [flags] --payload 'payload string' [args] - aergocli contract deploy [flags] [args] + Use: `deploy [flags] [args] + aergocli contract deploy [flags] --payload 'payload string' [args] - You can pass constructor arguments by passing a JSON string as the optional final parameter, e.g. "[1, 2, 3]".`, - Short: "Deploy a compiled contract to the server", - Args: nArgs([]int{1, 2, 3, 4}), + You can pass arguments to the constructor() function by passing a JSON string as the optional final parameter, e.g. '[1, "test"]'`, + Short: "Deploy a contract to the server", + Args: nArgs([]int{1, 2, 3}), RunE: runDeployCmd, DisableFlagsInUseLine: true, } deployCmd.PersistentFlags().Uint64Var(&nonce, "nonce", 0, "manually set a nonce (default: set nonce automatically)") - deployCmd.PersistentFlags().StringVar(&data, "payload", "", "result of compiling a contract") + deployCmd.PersistentFlags().StringVar(&data, "payload", "", "result of compiling a contract with aergoluac") deployCmd.PersistentFlags().StringVar(&amount, "amount", "0", "amount of token to send with deployment, in aer") deployCmd.PersistentFlags().StringVarP(&contractID, "redeploy", "r", "", "redeploy the contract") deployCmd.Flags().StringVar(&pw, "password", "", "password (optional, will be asked on the terminal if not given)") @@ -101,6 +102,19 @@ func init() { callCmd.PersistentFlags().BoolVar(&feeDelegation, "delegation", false, "request fee delegation to contract") callCmd.Flags().StringVar(&pw, "password", "", "password (optional, will be asked on the terminal if not given)") + multicallCmd := &cobra.Command{ + Use: `multicall [flags]