Commit d1bb9f73 authored by harrylee's avatar harrylee

update sidecar-client-chain33

parent 9a3a8eef
# Pier Client Fabric # Sidecar Client Fabric
Pier-client-fabric is the plugin implementation for fabric blockchain. Sidecar-client-fabric is the plugin implementation for chain33 blockchain.
## How to build ## How to build
Use the following command to build Use the following command to build
```shell script ```shell script
make fabric1.4 make chain33
``` ```
This will create a `build` directory under the project path and generate a `fabric-client-1.4.so` inside the `build`. This will create a `build` directory under the project path and generate a `fabric-client-1.4.so` inside the `build`.
This `.so` file will be used by [Pier](https://github.com/meshplus/pier). This `.so` file will be used by [Pier](https://gitlab.33.cn/link33/sidecar).
## Usage ## Usage
Details about how to use this plugin can be found in [here](https://github.com/meshplus/pier/wiki/Pier%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3) # Details about how to use this plugin can be found in [here](https://gitlab.33.cn/link33/sidecar/blob/master/README.md)
...@@ -19,8 +19,8 @@ import ( ...@@ -19,8 +19,8 @@ import (
"github.com/Rican7/retry/strategy" "github.com/Rican7/retry/strategy"
"github.com/hashicorp/go-hclog" "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin" "github.com/hashicorp/go-plugin"
"github.com/meshplus/bitxhub-model/pb" "github.com/link33/sidecar/model/pb"
"github.com/meshplus/pier/pkg/plugins" "github.com/link33/sidecar/pkg/plugins"
) )
var ( var (
...@@ -76,6 +76,17 @@ type CallFunc struct { ...@@ -76,6 +76,17 @@ type CallFunc struct {
Args [][]byte `json:"args"` Args [][]byte `json:"args"`
} }
func (c *Client) Kill() {
}
func (c *Client) Exited() bool {
return true
}
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)
...@@ -127,6 +138,12 @@ func (c *Client) Start() error { ...@@ -127,6 +138,12 @@ func (c *Client) Start() error {
return c.consumer.Start() return c.consumer.Start()
} }
func (c *Client) Stop() error {
c.ticker.Stop()
c.done <- true
return c.consumer.Shutdown()
}
// polling event from broker // polling event from broker
// 从应用链broker合约拉取跨链事件(出去的) // 从应用链broker合约拉取跨链事件(出去的)
func (c *Client) polling() { func (c *Client) polling() {
...@@ -154,7 +171,7 @@ func (c *Client) polling() { ...@@ -154,7 +171,7 @@ func (c *Client) polling() {
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
...@@ -211,12 +228,6 @@ func (c *Client) getProof(txhash string) ([]byte, error) { ...@@ -211,12 +228,6 @@ func (c *Client) getProof(txhash string) ([]byte, error) {
return proof, nil return proof, nil
} }
func (c *Client) Stop() error {
c.ticker.Stop()
c.done <- true
return c.consumer.Shutdown()
}
func (c *Client) Name() string { func (c *Client) Name() string {
return c.name return c.name
} }
...@@ -225,6 +236,15 @@ func (c *Client) Type() string { ...@@ -225,6 +236,15 @@ func (c *Client) Type() string {
return Chain33Type return Chain33Type
} }
//FIXME 查询ID,后面需要实现
func (c *Client) ID() string {
info, err := c.consumer.jsonClient.QueryBrokerInfo()
if err != nil {
return ""
}
return fmt.Sprintf("%s:%s", info.GetBxhId(), info.GetAppChainId())
}
func (c *Client) GetIBTP() chan *pb.IBTP { func (c *Client) GetIBTP() chan *pb.IBTP {
return c.eventC return c.eventC
} }
...@@ -260,26 +280,26 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -260,26 +280,26 @@ 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 == "" || ibtp.Type == pb.IBTP_ROLLBACK { 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.Index, serviceID, ibtp.Category()) _, resp, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Nonce, serviceID, ibtp.Category())
if err != nil { if err != nil {
return nil, err return nil, err
} }
ret.Status = resp.OK ret.Status = resp.OK
ret.Message = resp.Message ret.Message = resp.Message
if ibtp.Type == pb.IBTP_ROLLBACK { //if ibtp.Type == pb.IBTP_ROLLBACK {
ret.Result, err = c.generateCallback(ibtp, nil, ret.Status) // ret.Result, err = c.generateCallback(ibtp, nil, ret.Status)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
} //}
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,
...@@ -290,13 +310,13 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -290,13 +310,13 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
ret.Status = false ret.Status = false
ret.Message = fmt.Sprintf("marshal ibtp %s func %s and args: %s", ibtp.ID(), callFunc.Func, err.Error()) ret.Message = fmt.Sprintf("marshal ibtp %s func %s and args: %s", ibtp.ID(), callFunc.Func, err.Error())
res, _, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Index, serviceID, ibtp.Category()) res, _, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Nonce, serviceID, ibtp.Category())
if err != nil { if err != nil {
return nil, err return nil, err
} }
chResp = res chResp = res
} else { } else {
res, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Index, serviceID, uint64(ibtp.Category()), bizData) res, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Nonce, serviceID, uint64(ibtp.Category()), bizData)
if err != nil { if err != nil {
return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Func, err) return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Func, err)
} }
...@@ -316,10 +336,10 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -316,10 +336,10 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
return ret, err return ret, err
} }
ret.Result, err = c.generateCallback(ibtp, result, ret.Status) //ret.Result, err = c.generateCallback(ibtp, result, ret.Status)
if err != nil { //if err != nil {
return nil, err // return nil, err
} //}
ret.Result.Proof = proof ret.Result.Proof = proof
...@@ -331,8 +351,8 @@ func (c *Client) InvokeInterchain(from string, index uint64, destAddr string, re ...@@ -331,8 +351,8 @@ func (c *Client) InvokeInterchain(from string, index uint64, destAddr string, re
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)
splitedCID := strings.Split(destAddr, "&") splitedCID := strings.Split(destAddr, "&")
if len(splitedCID) != 2{ if len(splitedCID) != 2 {
return "",nil, fmt.Errorf("destaddr is not expect type!") return "", nil, fmt.Errorf("destaddr is not expect type!")
} }
request := &client.Request{ request := &client.Request{
Exec: splitedCID[1], Exec: splitedCID[1],
...@@ -377,7 +397,7 @@ func (c *Client) GetOutMessage(servicePair string, idx uint64) (*pb.IBTP, error) ...@@ -377,7 +397,7 @@ func (c *Client) GetOutMessage(servicePair string, idx uint64) (*pb.IBTP, error)
// FIXME 查看跨入交易的执行结果,是否执行成功 // FIXME 查看跨入交易的执行结果,是否执行成功
func (c *Client) GetInMessage(servicePair string, index uint64) ([][]byte, error) { func (c *Client) GetInMessage(servicePair string, index uint64) ([][]byte, error) {
response, err := c.consumer.jsonClient.QueryInMessage( servicePair, index) response, err := c.consumer.jsonClient.QueryInMessage(servicePair, index)
if err != nil { if err != nil {
return nil, fmt.Errorf("execute QueryInMessage: %w", err) return nil, fmt.Errorf("execute QueryInMessage: %w", err)
} }
...@@ -468,7 +488,7 @@ func (c *Client) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPR ...@@ -468,7 +488,7 @@ func (c *Client) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPR
} }
// pb.IBTP_RESPONSE indicates it is to update callback counter // pb.IBTP_RESPONSE indicates it is to update callback counter
_, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Index, serviceID, reqType, bizData) _, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Nonce, serviceID, reqType, bizData)
if err != nil { if err != nil {
return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Rollback, err) return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Rollback, err)
} }
...@@ -488,7 +508,7 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) { ...@@ -488,7 +508,7 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, _, err = c.InvokeIndexUpdate(original.From, original.Index, serviceID, original.Category()) _, _, err = c.InvokeIndexUpdate(original.From, original.Nonce, serviceID, original.Category())
if err != nil { if err != nil {
logger.Error("update in meta", "ibtp_id", original.ID(), "error", err.Error()) logger.Error("update in meta", "ibtp_id", original.ID(), "error", err.Error())
} }
...@@ -496,7 +516,7 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) { ...@@ -496,7 +516,7 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) {
} }
func (c *Client) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) { func (c *Client) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) {
result, err := c.GetInMessage(ibtp.ServicePair(), ibtp.Index) result, err := c.GetInMessage(ibtp.ID(), ibtp.Nonce)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -519,7 +539,7 @@ func (c *Client) InvokeIndexUpdate(from string, index uint64, serviceId string, ...@@ -519,7 +539,7 @@ func (c *Client) InvokeIndexUpdate(from string, index uint64, serviceId string,
if err != nil { if err != nil {
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
} }
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"strings" "strings"
"github.com/cloudflare/cfssl/log" "github.com/cloudflare/cfssl/log"
"github.com/meshplus/bitxhub-model/pb" "github.com/link33/sidecar/model/pb"
) )
type Event struct { type Event struct {
...@@ -27,9 +27,9 @@ func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IB ...@@ -27,9 +27,9 @@ 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,
Index: ev.Index, Nonce: ev.Index,
Type: ibtpType, Type: ibtpType,
TimeoutHeight: timeoutHeight, //TimeoutHeight: timeoutHeight,
Payload: pd, Payload: pd,
} }
} }
......
...@@ -8,14 +8,14 @@ require ( ...@@ -8,14 +8,14 @@ require (
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/meshplus/bitxhub-model v1.2.1-0.20210805064451-03258148acad github.com/link33/sidecar v1.11.1-0.20210809064238-de527e06d443
github.com/meshplus/pier v1.11.1-0.20210809064238-de527e06d443
github.com/spf13/viper v1.7.0 github.com/spf13/viper v1.7.0
) )
replace ( replace (
github.com/33cn/chain33-sdk-go => ../../gopath/src/github.com/33cn/chain33-sdk-go 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/meshplus/bitxhub-model/pb" "github.com/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) {
......
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