Commit 624d83e1 authored by suyanlong's avatar suyanlong

😘 insteadof go mod path

parent d1bb9f73
Language: 'Proto'
BasedOnStyle: 'LLVM'
AccessModifierOffset: '-1'
AlignAfterOpenBracket: 'Align'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'true'
AlignEscapedNewlinesLeft: 'true'
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
ColumnLimit: '200'
IndentWidth: '4'
ContinuationIndentWidth: '4'
TabWidth: '4'
TabWidth: '4'
ReflowComments: 'true'
SortIncludes: 'true'
AllowShortFunctionsOnASingleLine: 'Empty'
AllowShortIfStatementsOnASingleLine: 'true'
test/*
plugins/build
Dockerfile
\ No newline at end of file
root = true
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 8
[Makefile]
indent_size = 4
indent_style = tab
[*.md]
trim_trailing_whitespace = false
[*.go]
indent_style = tab
[*.yml]
indent_style = space
indent_size = 2
[*.sh]
indent_style = space
indent_size = 2
...@@ -5,6 +5,11 @@ CURRENT_TAG =$(shell git describe --abbrev=0 --tags) ...@@ -5,6 +5,11 @@ CURRENT_TAG =$(shell git describe --abbrev=0 --tags)
GO = GO111MODULE=on go GO = GO111MODULE=on go
## make fabric1.4: build fabric(1.4) client plugin
chain33:
mkdir -p build
$(GO) build -o build/chain33-client ./*.go
help: Makefile 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/^/ /'
...@@ -17,11 +22,6 @@ test-coverage: ...@@ -17,11 +22,6 @@ test-coverage:
@go test -short -coverprofile cover.out -covermode=atomic ${TEST_PKGS} @go test -short -coverprofile cover.out -covermode=atomic ${TEST_PKGS}
@cat cover.out >> coverage.txt @cat cover.out >> coverage.txt
## make fabric1.4: build fabric(1.4) client plugin
chain33:
mkdir -p build
$(GO) build -o build/chain33-client ./*.go
docker: docker:
mkdir -p build mkdir -p build
cd build && rm -rf pier && cp -r ../../pier pier cd build && rm -rf pier && cp -r ../../pier pier
...@@ -35,6 +35,64 @@ release-binary: ...@@ -35,6 +35,64 @@ release-binary:
mkdir -p build mkdir -p build
$(GO) build -o build/chain33-client-${CURRENT_TAG}-${DISTRO} ./*.go $(GO) build -o build/chain33-client-${CURRENT_TAG}-${DISTRO} ./*.go
## make linter: Run golangci-lint ## make linter: Run golanci-lint
linter: linter:
golangci-lint run golangci-lint run
\ No newline at end of file golangci-lint run -E goimports -E bodyclose --skip-dirs-use-default
fmt_proto: ## go fmt protobuf file
@find . -name '*.proto' -not -path "./vendor/*" | xargs clang-format -i
fmt_shell: ## check shell file
@find . -name '*.sh' -not -path "./vendor/*" | xargs shfmt -w -s -i 4 -ci -bn
fmt_go: fmt_shell ## go fmt
@go fmt ./...
@find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w
goimports:fmt
@CGO_ENABLED=1 goimports-reviser -dir-path ./ -project-name gitlab.33.cn/link33/chain33-sdk-go -ignore-dir mock -rm-unused -set-alias -format
fmt: fmt_proto fmt_shell ## go fmt
@go fmt ./...
@find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w
@gofumpt -l -w .
clean:
@go clean
build-dep:
@go install golang.org/x/tools/cmd/goimports@latest
@go install github.com/suyanlong/aligner@latest
@go install mvdan.cc/gofumpt@latest
@go install mvdan.cc/sh/v3/cmd/shfmt@latest
@go install mvdan.cc/sh/v3/cmd/gosh@latest
@go install mvdan.cc/unparam@latest
@go install github.com/incu6us/goimports-reviser@master
@go install github.com/psampaz/go-mod-outdated@v0.8.0
# @apt install clang-format or brew isntall clang-format
# @apt install shellcheck or brew install shellcheck
aligner:
@aligner -r -c "//" -e ".go" comment
aligner-check:
@aligner -r -c "//" -e ".go" check
checkgofmt: ## get all go files and run go fmt on them
@files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s); if [ -n "$$files" ]; then \
echo "Error: 'make fmt' needs to be run on:"; \
find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s ;\
exit 1; \
fi;
@files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w); if [ -n "$$files" ]; then \
echo "Error: 'make fmt' needs to be run on:"; \
find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w ;\
exit 1; \
fi;
check: aligner-check checkgofmt
modmated:
@go list -u -m -json all | go-mod-outdated
...@@ -3,13 +3,6 @@ package main ...@@ -3,13 +3,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/33cn/chain33-sdk-go/client"
broker "github.com/33cn/chain33-sdk-go/dapp/broker"
"github.com/33cn/chain33-sdk-go/event"
//"github.com/33cn/chain33-sdk-go/types"
"github.com/33cn/chain33-sdk-go/util"
"os" "os"
"strconv" "strconv"
"strings" "strings"
...@@ -17,19 +10,22 @@ import ( ...@@ -17,19 +10,22 @@ import (
"github.com/Rican7/retry" "github.com/Rican7/retry"
"github.com/Rican7/retry/strategy" "github.com/Rican7/retry/strategy"
"github.com/hashicorp/go-hclog" hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin" plugin "github.com/hashicorp/go-plugin"
"github.com/link33/sidecar/model/pb" "gitlab.33.cn/link33/sidecar/model/pb"
"github.com/link33/sidecar/pkg/plugins" "gitlab.33.cn/link33/sidecar/pkg/plugins"
"gitlab.33.cn/link33/chain33-sdk-go/client"
broker "gitlab.33.cn/link33/chain33-sdk-go/dapp/broker"
"gitlab.33.cn/link33/chain33-sdk-go/event"
"gitlab.33.cn/link33/chain33-sdk-go/util"
) )
var ( var logger = hclog.New(&hclog.LoggerOptions{
logger = hclog.New(&hclog.LoggerOptions{ Name: "client",
Name: "client", Output: os.Stderr,
Output: os.Stderr, Level: hclog.Trace,
Level: hclog.Trace, })
})
)
var _ plugins.Client = (*Client)(nil) var _ plugins.Client = (*Client)(nil)
...@@ -49,10 +45,10 @@ const ( ...@@ -49,10 +45,10 @@ const (
type ContractMeta struct { type ContractMeta struct {
EventFilter string `json:"event_filter"` EventFilter string `json:"event_filter"`
//Username string `json:"username"` // Username string `json:"username"`
CCID string `json:"ccid"` CCID string `json:"ccid"`
//ChannelID string `json:"channel_id"` // ChannelID string `json:"channel_id"`
//ORG string `json:"org"` // ORG string `json:"org"`
PrivateKey string `json:"private_key"` PrivateKey string `json:"private_key"`
TimeoutHeight int64 `json:"timeout_height"` TimeoutHeight int64 `json:"timeout_height"`
ChainID string `json:"chain_id"` ChainID string `json:"chain_id"`
...@@ -77,17 +73,16 @@ type CallFunc struct { ...@@ -77,17 +73,16 @@ type CallFunc struct {
} }
func (c *Client) Kill() { func (c *Client) Kill() {
} }
func (c *Client) Exited() bool { func (c *Client) Exited() bool {
return true return true
} }
func (c *Client) Bind(kern plugins.Kernel) { func (c *Client) Bind(kern plugins.Kernel) {
} }
//插件合约初始化配置 // 插件合约初始化配置
func (c *Client) Initialize(configPath, appchainID string, extra []byte) error { func (c *Client) Initialize(configPath, appchainID string, extra []byte) error {
eventC := make(chan *pb.IBTP) eventC := make(chan *pb.IBTP)
config, err := UnmarshalConfig(configPath) config, err := UnmarshalConfig(configPath)
...@@ -150,7 +145,7 @@ func (c *Client) polling() { ...@@ -150,7 +145,7 @@ func (c *Client) polling() {
for { for {
select { select {
case <-c.ticker.C: case <-c.ticker.C:
//应用链broker合约需要适配一个查询接口,用户获取outMeta(跨到其他应用链上统计累计交易数量的索引) // 应用链broker合约需要适配一个查询接口,用户获取outMeta(跨到其他应用链上统计累计交易数量的索引)
outMeta, err := c.GetOutMeta() outMeta, err := c.GetOutMeta()
if err != nil { if err != nil {
continue continue
...@@ -164,21 +159,21 @@ func (c *Client) polling() { ...@@ -164,21 +159,21 @@ func (c *Client) polling() {
"error", err.Error()) "error", err.Error())
continue continue
} }
//用于本地记录本应用链与其他目标链之间发送得跨链数据包及收到跨链数据包之间的统计 // 用于本地记录本应用链与其他目标链之间发送得跨链数据包及收到跨链数据包之间的统计
meta, ok := c.serviceMeta[srcChainServiceID] meta, ok := c.serviceMeta[srcChainServiceID]
if !ok { if !ok {
meta = &pb.Interchain{ meta = &pb.Interchain{
ID: srcChainServiceID, ID: srcChainServiceID,
InterchainCounter: make(map[string]uint64), InterchainCounter: make(map[string]uint64),
ReceiptCounter: make(map[string]uint64), ReceiptCounter: make(map[string]uint64),
//SourceInterchainCounter: make(map[string]uint64), // SourceInterchainCounter: make(map[string]uint64),
SourceReceiptCounter: make(map[string]uint64), SourceReceiptCounter: make(map[string]uint64),
} }
c.serviceMeta[srcChainServiceID] = meta c.serviceMeta[srcChainServiceID] = meta
} }
for i := meta.InterchainCounter[dstChainServiceID] + 1; i <= index; i++ { for i := meta.InterchainCounter[dstChainServiceID] + 1; i <= index; i++ {
//根据索引去查询要跨到目标链上面的具体信息,并封装成ibtp协议包 // 根据索引去查询要跨到目标链上面的具体信息,并封装成ibtp协议包
ibtp, err := c.GetOutMessage(servicePair, i) ibtp, err := c.GetOutMessage(servicePair, i)
if err != nil { if err != nil {
logger.Error("Polling out message", logger.Error("Polling out message",
...@@ -187,7 +182,7 @@ func (c *Client) polling() { ...@@ -187,7 +182,7 @@ func (c *Client) polling() {
"error", err.Error()) "error", err.Error())
continue continue
} }
//将ibtp协议包发送给eventC通道,进行处理,同时跨链计数器到目标链项累计加1 // 将ibtp协议包发送给eventC通道,进行处理,同时跨链计数器到目标链项累计加1
c.eventC <- ibtp c.eventC <- ibtp
meta.InterchainCounter[dstChainServiceID]++ meta.InterchainCounter[dstChainServiceID]++
} }
...@@ -202,14 +197,14 @@ func (c *Client) polling() { ...@@ -202,14 +197,14 @@ func (c *Client) polling() {
// 跨链交易存在性证明 // 跨链交易存在性证明
func (c *Client) getProof(txhash string) ([]byte, error) { func (c *Client) getProof(txhash string) ([]byte, error) {
var proof []byte var proof []byte
var handle = func(txhash string) ([]byte, error) { handle := func(txhash string) ([]byte, error) {
// query proof from chain33 // query proof from chain33
txDetail, err := c.consumer.jsonClient.QueryTransaction(txhash) txDetail, err := c.consumer.jsonClient.QueryTransaction(txhash)
if err != nil { if err != nil {
return nil, err return nil, err
} }
txProof := txDetail.Proofs[0] txProof := txDetail.Proofs[0]
//FIXME 这里用json去序列化 // FIXME 这里用json去序列化
return []byte(txProof), nil return []byte(txProof), nil
} }
...@@ -236,7 +231,7 @@ func (c *Client) Type() string { ...@@ -236,7 +231,7 @@ func (c *Client) Type() string {
return Chain33Type return Chain33Type
} }
//FIXME 查询ID,后面需要实现 // FIXME 查询ID,后面需要实现
func (c *Client) ID() string { func (c *Client) ID() string {
info, err := c.consumer.jsonClient.QueryBrokerInfo() info, err := c.consumer.jsonClient.QueryBrokerInfo()
if err != nil { if err != nil {
...@@ -249,7 +244,7 @@ func (c *Client) GetIBTP() chan *pb.IBTP { ...@@ -249,7 +244,7 @@ func (c *Client) GetIBTP() chan *pb.IBTP {
return c.eventC return c.eventC
} }
//提交IBTP协议内容 // 提交IBTP协议内容
func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
ret := &pb.SubmitIBTPResponse{} ret := &pb.SubmitIBTPResponse{}
pd := &pb.Payload{} pd := &pb.Payload{}
...@@ -280,8 +275,8 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -280,8 +275,8 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
_, _, serviceID, err = parseChainServiceID(ibtp.From) _, _, serviceID, err = parseChainServiceID(ibtp.From)
} }
if ibtp.Category() == pb.IBTP_RESPONSE && content.Func == "" { if ibtp.Category() == pb.IBTP_RESPONSE && content.Func == "" {
//响应类型处理 // 响应类型处理
logger.Info("InvokeIndexUpdate", "ibtp", ibtp.ID()) logger.Info("InvokeIndexUpdate", "ibtp", ibtp.ID())
_, resp, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Nonce, serviceID, ibtp.Category()) _, resp, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Nonce, serviceID, ibtp.Category())
if err != nil { if err != nil {
...@@ -299,7 +294,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -299,7 +294,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
return ret, nil return ret, nil
} }
//var result [][]byte // var result [][]byte
var chResp string var chResp string
callFunc := CallFunc{ callFunc := CallFunc{
Func: content.Func, Func: content.Func,
...@@ -346,7 +341,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -346,7 +341,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
return ret, nil return ret, nil
} }
//TODO InvokerInterchain 方法内实现具体的跨链交易所需的逻辑,这里我们通过SDK方式控制跨链合约的内部交换 // TODO InvokerInterchain 方法内实现具体的跨链交易所需的逻辑,这里我们通过SDK方式控制跨链合约的内部交换
func (c *Client) InvokeInterchain(from string, index uint64, destAddr string, reqType uint64, bizCallData []byte) (string, *Response, error) { func (c *Client) InvokeInterchain(from string, index uint64, destAddr string, reqType uint64, bizCallData []byte) (string, *Response, error) {
args := util.ToChaincodeArgs(from, strconv.FormatUint(index, 10), destAddr, strconv.FormatUint(reqType, 10)) args := util.ToChaincodeArgs(from, strconv.FormatUint(index, 10), destAddr, strconv.FormatUint(reqType, 10))
args = append(args, bizCallData) args = append(args, bizCallData)
...@@ -377,14 +372,14 @@ func (c *Client) InvokeInterchain(from string, index uint64, destAddr string, re ...@@ -377,14 +372,14 @@ func (c *Client) InvokeInterchain(from string, index uint64, destAddr string, re
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
//logger.Info("response", "cc status", strconv.Itoa(int(res.ChaincodeStatus)), "payload", string(res.Payload)) // logger.Info("response", "cc status", strconv.Itoa(int(res.ChaincodeStatus)), "payload", string(res.Payload))
response := &Response{res.OK, res.Message, res.Data} response := &Response{res.OK, res.Message, res.Data}
return res.Message, response, nil return res.Message, response, nil
} }
// TODO 这里应该是getOutMessage可以获取跨链交易的txhash,通过查看库跨链交易的存在性证明来判断此笔跨链交易是否存在 // TODO 这里应该是getOutMessage可以获取跨链交易的txhash,通过查看库跨链交易的存在性证明来判断此笔跨链交易是否存在
func (c *Client) GetOutMessage(servicePair string, idx uint64) (*pb.IBTP, error) { func (c *Client) GetOutMessage(servicePair string, idx uint64) (*pb.IBTP, error) {
//获取txhash // 获取txhash
res, err := c.consumer.jsonClient.QueryOutMessage(servicePair, idx) res, err := c.consumer.jsonClient.QueryOutMessage(servicePair, idx)
proof, err := c.getProof(res.Message) proof, err := c.getProof(res.Message)
...@@ -435,7 +430,7 @@ func (c *Client) CommitCallback(ibtp *pb.IBTP) error { ...@@ -435,7 +430,7 @@ func (c *Client) CommitCallback(ibtp *pb.IBTP) error {
return nil return nil
} }
//回滚操IBTP // 回滚操IBTP
// @ibtp is the original ibtp merged from this appchain // @ibtp is the original ibtp merged from this appchain
func (c *Client) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPResponse, error) { func (c *Client) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPResponse, error) {
ret := &pb.RollbackIBTPResponse{Status: true} ret := &pb.RollbackIBTPResponse{Status: true}
...@@ -528,9 +523,9 @@ func (c *Client) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) { ...@@ -528,9 +523,9 @@ func (c *Client) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) {
return c.generateCallback(ibtp, result[1:], status) return c.generateCallback(ibtp, result[1:], status)
} }
//更新索引,正确执行的,执行失败的 // 更新索引,正确执行的,执行失败的
func (c *Client) InvokeIndexUpdate(from string, index uint64, serviceId string, category pb.IBTP_Category) (string, *Response, error) { func (c *Client) InvokeIndexUpdate(from string, index uint64, serviceId string, category pb.IBTP_Category) (string, *Response, error) {
//types.Response{Message:} // types.Response{Message:}
tx, err := broker.UpdateIndex("", from, serviceId, index, uint64(category), nil) tx, err := broker.UpdateIndex("", from, serviceId, index, uint64(category), nil)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
...@@ -540,7 +535,6 @@ func (c *Client) InvokeIndexUpdate(from string, index uint64, serviceId string, ...@@ -540,7 +535,6 @@ func (c *Client) InvokeIndexUpdate(from string, index uint64, serviceId string,
return "", nil, err return "", nil, err
} }
return response.Message, &Response{OK: response.OK, Message: response.Message, Data: response.Data}, nil return response.Message, &Response{OK: response.OK, Message: response.Message, Data: response.Data}, nil
} }
func (c *Client) GetSrcRollbackMeta() (map[string]uint64, error) { func (c *Client) GetSrcRollbackMeta() (map[string]uint64, error) {
...@@ -560,7 +554,7 @@ func (c *Client) GetDstRollbackMeta() (map[string]uint64, error) { ...@@ -560,7 +554,7 @@ func (c *Client) GetDstRollbackMeta() (map[string]uint64, error) {
// return nil, err // return nil, err
//} //}
//return c.unpackMap(response) // return c.unpackMap(response)
return nil, nil return nil, nil
} }
...@@ -574,7 +568,7 @@ func (c *Client) GetServices() []string { ...@@ -574,7 +568,7 @@ func (c *Client) GetServices() []string {
return services return services
} }
//查询chainID,后面需要实现 // 查询chainID,后面需要实现
func (c *Client) GetChainID() (string, string) { func (c *Client) GetChainID() (string, string) {
info, err := c.consumer.jsonClient.QueryBrokerInfo() info, err := c.consumer.jsonClient.QueryBrokerInfo()
if err != nil { if err != nil {
...@@ -607,7 +601,7 @@ func newChain33Handler(eventFilter string, eventC chan *pb.IBTP, pierId string) ...@@ -607,7 +601,7 @@ func newChain33Handler(eventFilter string, eventC chan *pb.IBTP, pierId string)
}, nil }, nil
} }
//监听事件 // 监听事件
func (h *handler) HandleMessage(deliveries *event.CCEvent, payload []byte) { func (h *handler) HandleMessage(deliveries *event.CCEvent, payload []byte) {
if deliveries.EventName == h.eventFilter { if deliveries.EventName == h.eventFilter {
e := &pb.IBTP{} e := &pb.IBTP{}
......
...@@ -15,6 +15,7 @@ type Config struct { ...@@ -15,6 +15,7 @@ type Config struct {
Chain33 Chain33 `toml:"fabric" json:"fabric"` Chain33 Chain33 `toml:"fabric" json:"fabric"`
Services []Service `mapstructure:"services" json:"services"` Services []Service `mapstructure:"services" json:"services"`
} }
type Chain33 struct { type Chain33 struct {
Addr string `toml:"addr" json:"addr"` Addr string `toml:"addr" json:"addr"`
Name string `toml:"name" json:"name"` Name string `toml:"name" json:"name"`
......
...@@ -2,8 +2,9 @@ package main ...@@ -2,8 +2,9 @@ package main
import ( import (
"fmt" "fmt"
chain33sdk "github.com/33cn/chain33-sdk-go/client"
"github.com/33cn/chain33-sdk-go/event" chain33sdk "gitlab.33.cn/link33/chain33-sdk-go/client"
"gitlab.33.cn/link33/chain33-sdk-go/event"
) )
type MessageHandler interface { type MessageHandler interface {
...@@ -34,7 +35,7 @@ func NewConsumer(config *Config, meta *ContractMeta, msgH MessageHandler, ctx ch ...@@ -34,7 +35,7 @@ func NewConsumer(config *Config, meta *ContractMeta, msgH MessageHandler, ctx ch
return c, nil return c, nil
} }
//这里采用笨方法,轮循不断拉取交易去判断 // 这里采用笨方法,轮循不断拉取交易去判断
func (c *Consumer) Start() error { func (c *Consumer) Start() error {
registration, notifier, errCh := c.jsonClient.RegisterTxEvent(0, c.meta.CCID, c.meta.EventFilter) registration, notifier, errCh := c.jsonClient.RegisterTxEvent(0, c.meta.CCID, c.meta.EventFilter)
c.registration = registration c.registration = registration
...@@ -65,7 +66,6 @@ func (c *Consumer) Shutdown() error { ...@@ -65,7 +66,6 @@ func (c *Consumer) Shutdown() error {
} }
func (c *Consumer) handle(deliveries *event.CCEvent) { func (c *Consumer) handle(deliveries *event.CCEvent) {
//t, err := c.jsonClient.QueryTransaction(deliveries.TxID) //t, err := c.jsonClient.QueryTransaction(deliveries.TxID)
//if err != nil { //if err != nil {
// return // return
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"strings" "strings"
"github.com/cloudflare/cfssl/log" "github.com/cloudflare/cfssl/log"
"github.com/link33/sidecar/model/pb" "gitlab.33.cn/link33/sidecar/model/pb"
) )
type Event struct { type Event struct {
...@@ -25,12 +25,12 @@ func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IB ...@@ -25,12 +25,12 @@ func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IB
} }
return &pb.IBTP{ return &pb.IBTP{
From: ev.SrcFullID, From: ev.SrcFullID,
To: ev.DstFullID, To: ev.DstFullID,
Nonce: ev.Index, Nonce: ev.Index,
Type: ibtpType, Type: ibtpType,
//TimeoutHeight: timeoutHeight, // TimeoutHeight: timeoutHeight,
Payload: pd, Payload: pd,
} }
} }
......
...@@ -63,7 +63,6 @@ func (broker *Broker) Init(stub shim.ChaincodeStubInterface) pb.Response { ...@@ -63,7 +63,6 @@ func (broker *Broker) Init(stub shim.ChaincodeStubInterface) pb.Response {
args := make([]string, 2) args := make([]string, 2)
return broker.initialize(stub, args) return broker.initialize(stub, args)
} }
func (broker *Broker) Invoke(stub shim.ChaincodeStubInterface) pb.Response { func (broker *Broker) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
...@@ -273,8 +272,8 @@ func (broker *Broker) pollingEvent(stub shim.ChaincodeStubInterface, args []stri ...@@ -273,8 +272,8 @@ func (broker *Broker) pollingEvent(stub shim.ChaincodeStubInterface, args []stri
if err := json.Unmarshal([]byte(args[0]), &m); err != nil { if err := json.Unmarshal([]byte(args[0]), &m); err != nil {
return shim.Error(fmt.Errorf("unmarshal out meta: %s", err).Error()) return shim.Error(fmt.Errorf("unmarshal out meta: %s", err).Error())
} }
//这段代码意思是从中间链pier端传来当前各类outterMeta 处理到得索引高度,然后从之后index+1 索引处开始是新增的outterMeta // 这段代码意思是从中间链pier端传来当前各类outterMeta 处理到得索引高度,然后从之后index+1 索引处开始是新增的outterMeta
//事件 // 事件
outMeta, err := broker.getMap(stub, outterMeta) outMeta, err := broker.getMap(stub, outterMeta)
if err != nil { if err != nil {
return shim.Error(err.Error()) return shim.Error(err.Error())
...@@ -307,23 +306,23 @@ func (broker *Broker) pollingEvent(stub shim.ChaincodeStubInterface, args []stri ...@@ -307,23 +306,23 @@ func (broker *Broker) pollingEvent(stub shim.ChaincodeStubInterface, args []stri
} }
func (broker *Broker) updateIndex(stub shim.ChaincodeStubInterface, srcChainServiceID, sequenceNum string, dstAddr string, reqType uint64) error { func (broker *Broker) updateIndex(stub shim.ChaincodeStubInterface, srcChainServiceID, sequenceNum string, dstAddr string, reqType uint64) error {
//获取当前的服务ID bxhid:appChainId:serviceID // 获取当前的服务ID bxhid:appChainId:serviceID
curServiceID, err := broker.genFullServiceID(stub, dstAddr) curServiceID, err := broker.genFullServiceID(stub, dstAddr)
if err != nil { if err != nil {
return err return err
} }
if reqType == 0 { if reqType == 0 {
//输入型key // 输入型key
inServicePair := genServicePair(srcChainServiceID, curServiceID) inServicePair := genServicePair(srcChainServiceID, curServiceID)
if err := broker.checkIndex(stub, inServicePair, sequenceNum, innerMeta); err != nil { if err := broker.checkIndex(stub, inServicePair, sequenceNum, innerMeta); err != nil {
return fmt.Errorf("inner meta:%v", err) return fmt.Errorf("inner meta:%v", err)
} }
//输入类型标记统计加1 // 输入类型标记统计加1
if err := broker.markInCounter(stub, inServicePair); err != nil { if err := broker.markInCounter(stub, inServicePair); err != nil {
return err return err
} }
} else if reqType == 1 { } else if reqType == 1 {
//输出类型key // 输出类型key
outServicePair := genServicePair(curServiceID, srcChainServiceID) outServicePair := genServicePair(curServiceID, srcChainServiceID)
if err := broker.checkIndex(stub, outServicePair, sequenceNum, callbackMeta); err != nil { if err := broker.checkIndex(stub, outServicePair, sequenceNum, callbackMeta); err != nil {
...@@ -334,7 +333,7 @@ func (broker *Broker) updateIndex(stub shim.ChaincodeStubInterface, srcChainServ ...@@ -334,7 +333,7 @@ func (broker *Broker) updateIndex(stub shim.ChaincodeStubInterface, srcChainServ
if err != nil { if err != nil {
return err return err
} }
//输出跨链交易回调响应索引值更新 // 输出跨链交易回调响应索引值更新
if err := broker.markCallbackCounter(stub, outServicePair, idx); err != nil { if err := broker.markCallbackCounter(stub, outServicePair, idx); err != nil {
return err return err
} }
...@@ -351,7 +350,7 @@ func (broker *Broker) updateIndex(stub shim.ChaincodeStubInterface, srcChainServ ...@@ -351,7 +350,7 @@ func (broker *Broker) updateIndex(stub shim.ChaincodeStubInterface, srcChainServ
if idx < meta[inServicePair]+1 { if idx < meta[inServicePair]+1 {
return fmt.Errorf("incorrect dstRollback index, expect %d", meta[inServicePair]+1) return fmt.Errorf("incorrect dstRollback index, expect %d", meta[inServicePair]+1)
} }
//输入链交易回滚时,相应dstRollBackCounter统计也要回滚 // 输入链交易回滚时,相应dstRollBackCounter统计也要回滚
if err := broker.markDstRollbackCounter(stub, inServicePair, idx); err != nil { if err := broker.markDstRollbackCounter(stub, inServicePair, idx); err != nil {
return err return err
} }
...@@ -364,7 +363,7 @@ func (broker *Broker) invokeIndexUpdate(stub shim.ChaincodeStubInterface, args [ ...@@ -364,7 +363,7 @@ func (broker *Broker) invokeIndexUpdate(stub shim.ChaincodeStubInterface, args [
if len(args) != 4 { if len(args) != 4 {
return errorResponse("incorrect number of arguments, expecting 4") return errorResponse("incorrect number of arguments, expecting 4")
} }
//更新索引 // 更新索引
srcServiceID := args[0] srcServiceID := args[0]
sequenceNum := args[1] sequenceNum := args[1]
dstAddr := args[2] dstAddr := args[2]
...@@ -393,6 +392,7 @@ func (broker *Broker) getChainId(stub shim.ChaincodeStubInterface) pb.Response { ...@@ -393,6 +392,7 @@ func (broker *Broker) getChainId(stub shim.ChaincodeStubInterface) pb.Response {
return successResponse([]byte(fmt.Sprintf("%s-%s", bxhId, appchainId))) return successResponse([]byte(fmt.Sprintf("%s-%s", bxhId, appchainId)))
} }
func (broker *Broker) genFullServiceID(stub shim.ChaincodeStubInterface, serviceId string) (string, error) { func (broker *Broker) genFullServiceID(stub shim.ChaincodeStubInterface, serviceId string) (string, error) {
bxhId, err := stub.GetState(bxhID) bxhId, err := stub.GetState(bxhID)
if err != nil { if err != nil {
...@@ -405,13 +405,13 @@ func (broker *Broker) genFullServiceID(stub shim.ChaincodeStubInterface, service ...@@ -405,13 +405,13 @@ func (broker *Broker) genFullServiceID(stub shim.ChaincodeStubInterface, service
} }
return fmt.Sprintf("%s:%s:%s", bxhId, appchainId, serviceId), nil return fmt.Sprintf("%s:%s:%s", bxhId, appchainId, serviceId), nil
} }
func genServicePair(from, to string) string { func genServicePair(from, to string) string {
return fmt.Sprintf("%s-%s", from, to) return fmt.Sprintf("%s-%s", from, to)
} }
//调用跨链方法,chain33中实现需要通过SDK包装实现相应的方法
// 调用跨链方法,chain33中实现需要通过SDK包装实现相应的方法
func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args []string) pb.Response { func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args []string) pb.Response {
if len(args) != 5 { if len(args) != 5 {
return errorResponse("incorrect number of arguments, expecting 5") return errorResponse("incorrect number of arguments, expecting 5")
...@@ -442,7 +442,7 @@ func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args [] ...@@ -442,7 +442,7 @@ func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args []
var ccArgs [][]byte var ccArgs [][]byte
ccArgs = append(ccArgs, []byte(callFunc.Func)) ccArgs = append(ccArgs, []byte(callFunc.Func))
ccArgs = append(ccArgs, callFunc.Args...) ccArgs = append(ccArgs, callFunc.Args...)
//调用相应链码, (链码名称,参数,通道名称) // 调用相应链码, (链码名称,参数,通道名称)
response := stub.InvokeChaincode(splitedCID[1], ccArgs, splitedCID[0]) response := stub.InvokeChaincode(splitedCID[1], ccArgs, splitedCID[0])
if response.Status != shim.OK { if response.Status != shim.OK {
return errorResponse(fmt.Sprintf("invoke chaincode '%s' function %s err: %s", splitedCID[1], callFunc.Func, response.Message)) return errorResponse(fmt.Sprintf("invoke chaincode '%s' function %s err: %s", splitedCID[1], callFunc.Func, response.Message))
...@@ -459,7 +459,7 @@ func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args [] ...@@ -459,7 +459,7 @@ func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args []
if err != nil { if err != nil {
return errorResponse(err.Error()) return errorResponse(err.Error())
} }
//将跨链交易执行结果存储保留,chain33中将跨链交易txhash保留 // 将跨链交易执行结果存储保留,chain33中将跨链交易txhash保留
if err := stub.PutState(inKey, value); err != nil { if err := stub.PutState(inKey, value); err != nil {
return errorResponse(err.Error()) return errorResponse(err.Error())
} }
......
...@@ -91,7 +91,6 @@ func (broker *Broker) markCallbackCounter(stub shim.ChaincodeStubInterface, from ...@@ -91,7 +91,6 @@ func (broker *Broker) markCallbackCounter(stub shim.ChaincodeStubInterface, from
func (broker *Broker) markDstRollbackCounter(stub shim.ChaincodeStubInterface, from string, index uint64) error { func (broker *Broker) markDstRollbackCounter(stub shim.ChaincodeStubInterface, from string, index uint64) error {
meta, err := broker.getMap(stub, dstRollbackMeta) meta, err := broker.getMap(stub, dstRollbackMeta)
if err != nil { if err != nil {
return err return err
} }
......
module github.com/meshplus/pier-client-fabric module gitlab.33.cn/link33/sidecar-client-chain33
go 1.13 go 1.13
require ( require (
github.com/33cn/chain33-sdk-go v0.0.0-20210401082041-88dd7aa3c0ab
github.com/Rican7/retry v0.1.0 github.com/Rican7/retry v0.1.0
github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v1.3.0 github.com/hashicorp/go-plugin v1.3.0
github.com/link33/sidecar v1.11.1-0.20210809064238-de527e06d443
github.com/spf13/viper v1.7.0 github.com/spf13/viper v1.7.0
gitlab.33.cn/link33/chain33-sdk-go v0.0.0-20211026072656-659d145568bf
gitlab.33.cn/link33/sidecar v0.0.0-20211026064749-b0d3bccb1dda
) )
replace ( replace (
github.com/33cn/chain33-sdk-go => ../../33cn/chain33-sdk-go
github.com/link33/sidecar => ../sidecar
github.com/go-kit/kit => github.com/go-kit/kit v0.8.0 github.com/go-kit/kit => github.com/go-kit/kit v0.8.0
github.com/golang/protobuf => github.com/golang/protobuf v1.3.2 github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3 github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3
......
This diff is collapsed.
...@@ -3,7 +3,7 @@ package main ...@@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/link33/sidecar/model/pb" "gitlab.33.cn/link33/sidecar/model/pb"
) )
func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) (result *pb.IBTP, err error) { func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) (result *pb.IBTP, err error) {
...@@ -32,6 +32,7 @@ func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) ...@@ -32,6 +32,7 @@ func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool)
typ = pb.IBTP_RECEIPT_FAILURE typ = pb.IBTP_RECEIPT_FAILURE
} }
// TODO
if original.Type == pb.IBTP_ROLLBACK { if original.Type == pb.IBTP_ROLLBACK {
typ = pb.IBTP_RECEIPT_ROLLBACK typ = pb.IBTP_RECEIPT_ROLLBACK
} }
...@@ -52,7 +53,7 @@ func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) ...@@ -52,7 +53,7 @@ func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool)
return &pb.IBTP{ return &pb.IBTP{
From: original.From, From: original.From,
To: original.To, To: original.To,
Index: original.Index, Nonce: original.Nonce,
Type: typ, Type: typ,
Proof: original.Proof, Proof: original.Proof,
Payload: pdb, Payload: pdb,
......
...@@ -6,23 +6,23 @@ source x.sh ...@@ -6,23 +6,23 @@ source x.sh
# $1 is arch, $2 is source code path # $1 is arch, $2 is source code path
case $1 in case $1 in
linux-amd64) linux-amd64)
print_blue "Compile for linux/amd64" print_blue "Compile for linux/amd64"
# docker pull golang:1.13 # docker pull golang:1.13
docker run -t \ docker run -t \
-v $2/../pier:/code/pier \ -v $2/../pier:/code/pier \
-v $2:/code/pier-client-chain33 \ -v $2:/code/pier-client-chain33 \
-v ~/.ssh:/root/.ssh \ -v ~/.ssh:/root/.ssh \
-v ~/.gitconfig:/root/.gitconfig \ -v ~/.gitconfig:/root/.gitconfig \
-v $GOPATH/pkg/mod:$GOPATH/pkg/mod \ -v $GOPATH/pkg/mod:$GOPATH/pkg/mod \
pier-ubuntu/compile \ pier-ubuntu/compile \
/bin/bash -c "go env -w GO111MODULE=on && /bin/bash -c "go env -w GO111MODULE=on &&
go env -w GOPROXY=https://goproxy.cn,direct && go env -w GOPROXY=https://goproxy.cn,direct &&
cd /code/pier-client-chain33 && cd /code/pier-client-chain33 &&
make chain33-1.65 && make chain33-1.65 &&
mv /code/pier-client-chain33/build/chain33-client-1.65.so /code/pier-client-chain33/build/chain33-client-1.4-linux.so" mv /code/pier-client-chain33/build/chain33-client-1.65.so /code/pier-client-chain33/build/chain33-client-1.4-linux.so"
;; ;;
*) *)
print_red "Other architectures are not supported yet" print_red "Other architectures are not supported yet"
;; ;;
esac esac
...@@ -5,4 +5,4 @@ APPCHAIN_NAME=$1 ...@@ -5,4 +5,4 @@ APPCHAIN_NAME=$1
pier --repo=/root/.pier appchain register --name=${APPCHAIN_NAME} --type=fabric --validators=/root/.pier/fabric/fabric.validators --desc="appchain for test" --version=1.4.3 pier --repo=/root/.pier appchain register --name=${APPCHAIN_NAME} --type=fabric --validators=/root/.pier/fabric/fabric.validators --desc="appchain for test" --version=1.4.3
pier --repo=/root/.pier rule deploy --path=/root/.pier/validating.wasm pier --repo=/root/.pier rule deploy --path=/root/.pier/validating.wasm
pier --repo=/root/.pier start pier --repo=/root/.pier start
\ No newline at end of file
...@@ -4,10 +4,10 @@ BLUE='\033[0;34m' ...@@ -4,10 +4,10 @@ BLUE='\033[0;34m'
NC='\033[0m' NC='\033[0m'
function print_blue() { function print_blue() {
printf "${BLUE}%s${NC}\n" "$1" printf "${BLUE}%s${NC}\n" "$1"
} }
print_blue "===> 1. Install golangci-lint" print_blue "===> 1. Install golangci-lint"
if ! type golanci-lint >/dev/null 2>&1; then if ! type golanci-lint >/dev/null 2>&1; then
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.0 go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.0
fi fi
\ No newline at end of file
...@@ -4,9 +4,9 @@ BLUE='\033[0;34m' ...@@ -4,9 +4,9 @@ BLUE='\033[0;34m'
NC='\033[0m' NC='\033[0m'
function print_blue() { function print_blue() {
printf "${BLUE}%s${NC}\n" "$1" printf "${BLUE}%s${NC}\n" "$1"
} }
function print_red() { function print_red() {
printf "${RED}%s${NC}\n" "$1" printf "${RED}%s${NC}\n" "$1"
} }
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