Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar-client-fabric
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
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-fabric
Commits
8f564747
Unverified
Commit
8f564747
authored
Jul 17, 2020
by
Alexader
Committed by
GitHub
Jul 17, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17 from meshplus/feat/replace-go-plugin
feat(client): replace native go plugin mechanism with grpc plugin
parents
f245bb5b
b67da12b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
51 deletions
+42
-51
Makefile
Makefile
+3
-2
client.go
client.go
+35
-23
pier.toml
config/pier.toml
+1
-1
go.mod
go.mod
+3
-25
go.sum
go.sum
+0
-0
No files found.
Makefile
View file @
8f564747
...
...
@@ -18,7 +18,7 @@ test-coverage:
## make fabric1.4: build fabric(1.4) client plugin
fabric1.4
:
mkdir
-p
build
$(GO)
build
-
-buildmode
=
plugin
-o
build/fabric-client-1.4.so
./
*
.go
$(GO)
build
-
o
build/fabric-client-1.4
./
*
.go
docker
:
mkdir
-p
build
...
...
@@ -31,4 +31,4 @@ fabric1.4-linux:
## make linter: Run golanci-lint
linter
:
golangci-lint run
golangci-lint run
\ No newline at end of file
client.go
View file @
8f564747
...
...
@@ -10,6 +10,7 @@ import (
"github.com/Rican7/retry"
"github.com/Rican7/retry/strategy"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/go-plugin"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
...
...
@@ -19,14 +20,13 @@ import (
"github.com/hyperledger/fabric/common/util"
"github.com/meshplus/bitxhub-kit/log"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/pier/pkg/model"
"github.com/meshplus/pier/pkg/plugins/client"
"github.com/meshplus/pier/pkg/plugins"
"github.com/sirupsen/logrus"
)
var
logger
=
log
.
NewWithModule
(
"client"
)
var
_
client
.
Client
=
(
*
Client
)(
nil
)
var
_
plugins
.
Client
=
(
*
Client
)(
nil
)
const
(
GetInnerMetaMethod
=
"getInnerMeta"
// get last index of each source chain executing tx
...
...
@@ -57,14 +57,14 @@ type Client struct {
done
chan
bool
}
func
NewClient
(
configPath
,
pierId
string
,
extra
[]
byte
)
(
client
.
Client
,
error
)
{
func
(
c
*
Client
)
Initialize
(
configPath
,
pierId
string
,
extra
[]
byte
)
error
{
eventC
:=
make
(
chan
*
pb
.
IBTP
)
fabricConfig
,
err
:=
UnmarshalConfig
(
configPath
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unmarshal config for plugin :%w"
,
err
)
return
fmt
.
Errorf
(
"unmarshal config for plugin :%w"
,
err
)
}
c
:=
&
ContractMeta
{
c
ontractmeta
:=
&
ContractMeta
{
EventFilter
:
fabricConfig
.
EventFilter
,
Username
:
fabricConfig
.
Username
,
CCID
:
fabricConfig
.
CCID
,
...
...
@@ -74,33 +74,33 @@ func NewClient(configPath, pierId string, extra []byte) (client.Client, error) {
m
:=
make
(
map
[
string
]
uint64
)
if
err
:=
json
.
Unmarshal
(
extra
,
&
m
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unmarshal extra for plugin :%w"
,
err
)
return
fmt
.
Errorf
(
"unmarshal extra for plugin :%w"
,
err
)
}
if
m
==
nil
{
m
=
make
(
map
[
string
]
uint64
)
}
mgh
,
err
:=
newFabricHandler
(
c
.
EventFilter
,
eventC
,
pierId
)
mgh
,
err
:=
newFabricHandler
(
c
ontractmeta
.
EventFilter
,
eventC
,
pierId
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
done
:=
make
(
chan
bool
)
csm
,
err
:=
NewConsumer
(
configPath
,
c
,
mgh
,
done
)
csm
,
err
:=
NewConsumer
(
configPath
,
c
ontractmeta
,
mgh
,
done
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
return
&
Client
{
consumer
:
csm
,
eventC
:
eventC
,
meta
:
c
,
pierId
:
pierId
,
name
:
fabricConfig
.
Name
,
outMeta
:
m
,
ticker
:
time
.
NewTicker
(
2
*
time
.
Second
),
done
:
done
,
},
nil
c
.
consumer
=
csm
c
.
eventC
=
eventC
c
.
meta
=
contractmeta
c
.
pierId
=
pierId
c
.
name
=
fabricConfig
.
Name
c
.
outMeta
=
m
c
.
ticker
=
time
.
NewTicker
(
2
*
time
.
Second
)
c
.
done
=
done
return
nil
}
func
(
c
*
Client
)
Start
()
error
{
...
...
@@ -225,9 +225,9 @@ func (c *Client) GetIBTP() chan *pb.IBTP {
return
c
.
eventC
}
func
(
c
*
Client
)
SubmitIBTP
(
ibtp
*
pb
.
IBTP
)
(
*
model
.
Plugin
Response
,
error
)
{
func
(
c
*
Client
)
SubmitIBTP
(
ibtp
*
pb
.
IBTP
)
(
*
pb
.
SubmitIBTP
Response
,
error
)
{
pd
:=
&
pb
.
Payload
{}
ret
:=
&
model
.
Plugin
Response
{}
ret
:=
&
pb
.
SubmitIBTP
Response
{}
if
err
:=
pd
.
Unmarshal
(
ibtp
.
Payload
);
err
!=
nil
{
return
ret
,
fmt
.
Errorf
(
"ibtp payload unmarshal: %w"
,
err
)
}
...
...
@@ -431,3 +431,15 @@ func (h *handler) HandleMessage(deliveries *fab.CCEvent, payload []byte) {
h
.
eventC
<-
e
}
}
func
main
()
{
plugin
.
Serve
(
&
plugin
.
ServeConfig
{
HandshakeConfig
:
plugins
.
Handshake
,
Plugins
:
map
[
string
]
plugin
.
Plugin
{
plugins
.
PluginName
:
&
plugins
.
AppchainGRPCPlugin
{
Impl
:
&
Client
{}},
},
GRPCServer
:
plugin
.
DefaultGRPCServer
,
})
logger
.
Println
(
"Plugin server down"
)
}
config/pier.toml
View file @
8f564747
...
...
@@ -29,5 +29,5 @@ peers = [
]
[appchain]
plugin
=
"fabric-client-1.4
.so
"
plugin
=
"fabric-client-1.4"
config
=
"fabric"
go.mod
View file @
8f564747
...
...
@@ -7,40 +7,18 @@ require (
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004
github.com/golang/protobuf v1.4.0
github.com/golangci/golangci-lint v1.23.0 // indirect
github.com/google/certificate-transparency-go v1.1.0 // indirect
github.com/hashicorp/go-plugin v1.3.0
github.com/hyperledger/fabric v2.0.1+incompatible
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20200330074707-cfe579e86986
github.com/hyperledger/fabric-sdk-go v1.0.0-alpha5
github.com/meshplus/bitxhub-kit v1.0.1-0.20200525112026-df2160653e23
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200
608065824-2fbc63639e92
github.com/meshplus/pier v
0.0.0-00010101000000-000000000000
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200
707045101-18b88b80efb1
github.com/meshplus/pier v
1.0.0-rc1.0.20200717044435-de24cfbef0f3
github.com/sirupsen/logrus v1.5.0
github.com/spf13/viper v1.6.1
)
replace github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
replace google.golang.org/grpc => google.golang.org/grpc v1.27.1
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.7
replace golang.org/x/net => golang.org/x/net v0.0.0-20200202094626-16171245cfb2
replace github.com/meshplus/pier => ../pier
replace golang.org/x/text => golang.org/x/text v0.3.0
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f
replace github.com/spf13/afero => github.com/spf13/afero v1.1.2
replace github.com/spf13/pflag => github.com/spf13/pflag v1.0.5
replace github.com/pelletier/go-toml => github.com/pelletier/go-toml v1.2.0
replace github.com/spf13/jwalterweatherman => github.com/spf13/jwalterweatherman v1.0.0
replace github.com/mholt/archiver => github.com/mholt/archiver v0.0.0-20180417220235-e4ef56d48eb0
go.sum
View file @
8f564747
This diff is collapsed.
Click to expand it.
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