Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar-client-chain33
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar-client-chain33
Commits
d1bb9f73
Commit
d1bb9f73
authored
Oct 26, 2021
by
harrylee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update sidecar-client-chain33
parent
9a3a8eef
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
43 deletions
+63
-43
README.md
README.md
+5
-5
client.go
client.go
+51
-31
event.go
event.go
+3
-3
go.mod
go.mod
+3
-3
go.sum
go.sum
+0
-0
receipt.go
receipt.go
+1
-1
No files found.
README.md
View file @
d1bb9f73
#
Pie
r Client Fabric
#
Sideca
r 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
Use the following command to build
```
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
`.so`
file will be used by
[
Pier
](
https://git
hub.com/meshplus/pie
r
)
.
This
`.so`
file will be used by
[
Pier
](
https://git
lab.33.cn/link33/sideca
r
)
.
## 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
)
client.go
View file @
d1bb9f73
...
...
@@ -19,8 +19,8 @@ import (
"github.com/Rican7/retry/strategy"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/
meshplus/bitxhub-
model/pb"
"github.com/
meshplus/pie
r/pkg/plugins"
"github.com/
link33/sidecar/
model/pb"
"github.com/
link33/sideca
r/pkg/plugins"
)
var
(
...
...
@@ -76,6 +76,17 @@ type CallFunc struct {
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
{
eventC
:=
make
(
chan
*
pb
.
IBTP
)
...
...
@@ -127,6 +138,12 @@ func (c *Client) Start() error {
return
c
.
consumer
.
Start
()
}
func
(
c
*
Client
)
Stop
()
error
{
c
.
ticker
.
Stop
()
c
.
done
<-
true
return
c
.
consumer
.
Shutdown
()
}
// polling event from broker
// 从应用链broker合约拉取跨链事件(出去的)
func
(
c
*
Client
)
polling
()
{
...
...
@@ -154,7 +171,7 @@ func (c *Client) polling() {
ID
:
srcChainServiceID
,
InterchainCounter
:
make
(
map
[
string
]
uint64
),
ReceiptCounter
:
make
(
map
[
string
]
uint64
),
SourceInterchainCounter
:
make
(
map
[
string
]
uint64
),
//
SourceInterchainCounter: make(map[string]uint64),
SourceReceiptCounter
:
make
(
map
[
string
]
uint64
),
}
c
.
serviceMeta
[
srcChainServiceID
]
=
meta
...
...
@@ -211,12 +228,6 @@ func (c *Client) getProof(txhash string) ([]byte, error) {
return
proof
,
nil
}
func
(
c
*
Client
)
Stop
()
error
{
c
.
ticker
.
Stop
()
c
.
done
<-
true
return
c
.
consumer
.
Shutdown
()
}
func
(
c
*
Client
)
Name
()
string
{
return
c
.
name
}
...
...
@@ -225,6 +236,15 @@ func (c *Client) Type() string {
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
{
return
c
.
eventC
}
...
...
@@ -260,26 +280,26 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
_
,
_
,
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
())
_
,
resp
,
err
:=
c
.
InvokeIndexUpdate
(
srcChainServiceID
,
ibtp
.
Index
,
serviceID
,
ibtp
.
Category
())
_
,
resp
,
err
:=
c
.
InvokeIndexUpdate
(
srcChainServiceID
,
ibtp
.
Nonce
,
serviceID
,
ibtp
.
Category
())
if
err
!=
nil
{
return
nil
,
err
}
ret
.
Status
=
resp
.
OK
ret
.
Message
=
resp
.
Message
if
ibtp
.
Type
==
pb
.
IBTP_ROLLBACK
{
ret
.
Result
,
err
=
c
.
generateCallback
(
ibtp
,
nil
,
ret
.
Status
)
if
err
!=
nil
{
return
nil
,
err
}
}
//
if ibtp.Type == pb.IBTP_ROLLBACK {
//
ret.Result, err = c.generateCallback(ibtp, nil, ret.Status)
//
if err != nil {
//
return nil, err
//
}
//
}
return
ret
,
nil
}
var
result
[][]
byte
//
var result [][]byte
var
chResp
string
callFunc
:=
CallFunc
{
Func
:
content
.
Func
,
...
...
@@ -290,13 +310,13 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
ret
.
Status
=
false
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
{
return
nil
,
err
}
chResp
=
res
}
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
{
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) {
return
ret
,
err
}
ret
.
Result
,
err
=
c
.
generateCallback
(
ibtp
,
result
,
ret
.
Status
)
if
err
!=
nil
{
return
nil
,
err
}
//
ret.Result, err = c.generateCallback(ibtp, result, ret.Status)
//
if err != nil {
//
return nil, err
//
}
ret
.
Result
.
Proof
=
proof
...
...
@@ -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
=
append
(
args
,
bizCallData
)
splitedCID
:=
strings
.
Split
(
destAddr
,
"&"
)
if
len
(
splitedCID
)
!=
2
{
return
""
,
nil
,
fmt
.
Errorf
(
"destaddr is not expect type!"
)
if
len
(
splitedCID
)
!=
2
{
return
""
,
nil
,
fmt
.
Errorf
(
"destaddr is not expect type!"
)
}
request
:=
&
client
.
Request
{
Exec
:
splitedCID
[
1
],
...
...
@@ -377,7 +397,7 @@ func (c *Client) GetOutMessage(servicePair string, idx uint64) (*pb.IBTP, error)
// FIXME 查看跨入交易的执行结果,是否执行成功
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
{
return
nil
,
fmt
.
Errorf
(
"execute QueryInMessage: %w"
,
err
)
}
...
...
@@ -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
_
,
resp
,
err
:=
c
.
InvokeInterchain
(
srcChainServiceID
,
ibtp
.
Index
,
serviceID
,
reqType
,
bizData
)
_
,
resp
,
err
:=
c
.
InvokeInterchain
(
srcChainServiceID
,
ibtp
.
Nonce
,
serviceID
,
reqType
,
bizData
)
if
err
!=
nil
{
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) {
if
err
!=
nil
{
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
{
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) {
}
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
{
return
nil
,
err
}
...
...
@@ -519,7 +539,7 @@ func (c *Client) InvokeIndexUpdate(from string, index uint64, serviceId string,
if
err
!=
nil
{
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
}
...
...
event.go
View file @
d1bb9f73
...
...
@@ -5,7 +5,7 @@ import (
"strings"
"github.com/cloudflare/cfssl/log"
"github.com/
meshplus/bitxhub-
model/pb"
"github.com/
link33/sidecar/
model/pb"
)
type
Event
struct
{
...
...
@@ -27,9 +27,9 @@ func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IB
return
&
pb
.
IBTP
{
From
:
ev
.
SrcFullID
,
To
:
ev
.
DstFullID
,
Index
:
ev
.
Index
,
Nonce
:
ev
.
Index
,
Type
:
ibtpType
,
TimeoutHeight
:
timeoutHeight
,
//
TimeoutHeight: timeoutHeight,
Payload
:
pd
,
}
}
...
...
go.mod
View file @
d1bb9f73
...
...
@@ -8,14 +8,14 @@ require (
github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v1.3.0
github.com/meshplus/bitxhub-model v1.2.1-0.20210805064451-03258148acad
github.com/meshplus/pier v1.11.1-0.20210809064238-de527e06d443
github.com/link33/sidecar v1.11.1-0.20210809064238-de527e06d443
github.com/spf13/viper v1.7.0
)
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/golang/protobuf => github.com/golang/protobuf v1.3.2
github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3
...
...
go.sum
View file @
d1bb9f73
This diff is collapsed.
Click to expand it.
receipt.go
View file @
d1bb9f73
...
...
@@ -3,7 +3,7 @@ package main
import
(
"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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment