Commit 08071845 authored by Alexader's avatar Alexader

chore(*): fix some linter errors and add make prepare

1. remove some unused code 2. add .golangci.yml for linter rule 3. add make prepare command
parent dbb5d3e6
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
# - deadcode
- depguard
- dogsled
- dupl
- errcheck
# - funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
# - golint
# - gomnd
- goprintffuncname
# - gosec
- gosimple
- govet
- ineffassign
# - interfacer
# - lll
- misspell
- nakedret
- rowserrcheck
# - scopelint
- staticcheck
- structcheck
# - stylecheck
- typecheck
- unconvert
# - unparam
# - unused
- varcheck
# - whitespace
...@@ -7,6 +7,9 @@ help: Makefile ...@@ -7,6 +7,9 @@ help: Makefile
@echo "Choose a command run:" @echo "Choose a command run:"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
prepare:
cd scripts && bash prepare.sh
## make fabric1.4: build fabric(1.4) client plugin ## make fabric1.4: build fabric(1.4) client plugin
fabric1.4: fabric1.4:
mkdir -p build mkdir -p build
...@@ -17,5 +20,5 @@ fabric1.4-linux: ...@@ -17,5 +20,5 @@ fabric1.4-linux:
## make linter: Run golanci-lint ## make linter: Run golanci-lint
linter: linter:
golangci-lint run -E goimports --skip-dirs-use-default -D staticcheck golangci-lint run
...@@ -383,44 +383,6 @@ func (c *Client) CommitCallback(ibtp *pb.IBTP) error { ...@@ -383,44 +383,6 @@ func (c *Client) CommitCallback(ibtp *pb.IBTP) error {
return nil return nil
} }
func (c *Client) unpackRet(response *channel.Response) (*peer.ChaincodeAction, error) {
txHash := response.Payload
l, err := ledger.New(c.consumer.channelProvider)
if err != nil {
return nil, fmt.Errorf("new ledger: %w", err)
}
t, err := l.QueryTransaction(fab.TransactionID(txHash))
if err != nil {
return nil, fmt.Errorf("query tx: %w", err)
}
pd := &common.Payload{}
if err := proto.Unmarshal(t.TransactionEnvelope.Payload, pd); err != nil {
return nil, fmt.Errorf("unmarshal envelope: %w", err)
}
pt := &peer.Transaction{}
if err := proto.Unmarshal(pd.Data, pt); err != nil {
return nil, fmt.Errorf("unmarshal peer tx: %w", err)
}
action := &peer.ChaincodeActionPayload{}
if err := proto.Unmarshal(pt.Actions[0].Payload, action); err != nil {
return nil, fmt.Errorf("unmarshal action: %w", err)
}
payload := &peer.ProposalResponsePayload{}
if err := proto.Unmarshal(action.Action.ProposalResponsePayload, payload); err != nil {
return nil, fmt.Errorf("unmarshal proposal: %w", err)
}
result := &peer.ChaincodeAction{}
if err := proto.Unmarshal(payload.Extension, result); err != nil {
return nil, fmt.Errorf("unmarshal chaincode action: %w", err)
}
return result, nil
}
func (c *Client) unpackIBTP(response *channel.Response, ibtpType pb.IBTP_Type) (*pb.IBTP, error) { func (c *Client) unpackIBTP(response *channel.Response, ibtpType pb.IBTP_Type) (*pb.IBTP, error) {
ret := &Event{} ret := &Event{}
if err := json.Unmarshal(response.Payload, ret); err != nil { if err := json.Unmarshal(response.Payload, ret); err != nil {
......
...@@ -196,6 +196,9 @@ func (broker *Broker) InterchainInvoke(stub shim.ChaincodeStubInterface, args [] ...@@ -196,6 +196,9 @@ func (broker *Broker) InterchainInvoke(stub shim.ChaincodeStubInterface, args []
} }
txValue, err := json.Marshal(tx) txValue, err := json.Marshal(tx)
if err != nil {
return shim.Error(err.Error())
}
// persist out message // persist out message
key := broker.outMsgKey(tx.DstChainID, strconv.FormatUint(tx.Index, 10)) key := broker.outMsgKey(tx.DstChainID, strconv.FormatUint(tx.Index, 10))
......
...@@ -2,8 +2,9 @@ package main ...@@ -2,8 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
"strconv" "strconv"
"github.com/hyperledger/fabric/core/chaincode/shim"
) )
func getUint64(stub shim.ChaincodeStubInterface, key string) (uint64, error) { func getUint64(stub shim.ChaincodeStubInterface, key string) (uint64, error) {
...@@ -27,9 +28,5 @@ func getAmountArg(arg string) (uint64, error) { ...@@ -27,9 +28,5 @@ func getAmountArg(arg string) (uint64, error) {
return 0, err return 0, err
} }
if amount < 0 {
return 0, fmt.Errorf("amount must be a positive integer, got %s", arg)
}
return amount, nil return amount, nil
} }
...@@ -10,6 +10,7 @@ require ( ...@@ -10,6 +10,7 @@ require (
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004
github.com/fsouza/go-dockerclient v1.6.3 // indirect github.com/fsouza/go-dockerclient v1.6.3 // indirect
github.com/golang/protobuf v1.3.2 github.com/golang/protobuf v1.3.2
github.com/golangci/golangci-lint v1.23.0 // indirect
github.com/google/certificate-transparency-go v1.1.0 // indirect github.com/google/certificate-transparency-go v1.1.0 // indirect
github.com/hashicorp/go-version v1.2.0 // indirect github.com/hashicorp/go-version v1.2.0 // indirect
github.com/hyperledger/fabric v1.4.6 github.com/hyperledger/fabric v1.4.6
...@@ -22,7 +23,7 @@ require ( ...@@ -22,7 +23,7 @@ require (
github.com/miekg/pkcs11 v1.0.3 // indirect github.com/miekg/pkcs11 v1.0.3 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
github.com/sirupsen/logrus v1.4.2 github.com/sirupsen/logrus v1.4.2
github.com/spf13/viper v1.4.0 github.com/spf13/viper v1.6.1
github.com/sykesm/zap-logfmt v0.0.3 // indirect github.com/sykesm/zap-logfmt v0.0.3 // indirect
) )
......
This diff is collapsed.
...@@ -4,8 +4,6 @@ import ( ...@@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/meshplus/bitxhub-model/pb" "github.com/meshplus/bitxhub-model/pb"
) )
...@@ -40,43 +38,3 @@ func (c *Client) generateCallback(toExecute *pb.IBTP, args [][]byte, proof []byt ...@@ -40,43 +38,3 @@ func (c *Client) generateCallback(toExecute *pb.IBTP, args [][]byte, proof []byt
Version: toExecute.Version, Version: toExecute.Version,
}, nil }, nil
} }
func (c *Client) interchainCharge(toExecute *pb.IBTP, response channel.Response) (*pb.IBTP, error) {
pd := &pb.Payload{}
if err := pd.Unmarshal(toExecute.Payload); err != nil {
return nil, fmt.Errorf("toExecute payload unmarshal: %w", err)
}
newArgs := [][]byte{[]byte("false"), pd.Args[0]}
if response.ChaincodeStatus == shim.OK {
newArgs[0] = []byte("true")
}
newArgs = append(newArgs, pd.Args[2:]...)
newPayload := &pb.Payload{
SrcContractId: pd.DstContractId,
DstContractId: pd.SrcContractId,
Func: "interchainConfirm",
Args: newArgs,
}
logger.Info("ack ibtp is:", newPayload)
pdb, err := newPayload.Marshal()
if err != nil {
return nil, err
}
proof, err := c.getProof(response)
if err != nil {
return nil, err
}
return &pb.IBTP{
From: toExecute.From,
To: toExecute.To,
Index: toExecute.Index,
Type: pb.IBTP_RECEIPT,
Timestamp: time.Now().UnixNano(),
Proof: proof,
Payload: pdb,
Version: toExecute.Version,
}, nil
}
#!/usr/bin/env bash
BLUE='\033[0;34m'
NC='\033[0m'
function print_blue() {
printf "${BLUE}%s${NC}\n" "$1"
}
print_blue "===> 1. Install golangci-lint"
if ! type golanci-lint >/dev/null 2>&1; then
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.0
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment