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
0d6dfd49
Unverified
Commit
0d6dfd49
authored
Apr 19, 2021
by
jzhe
Committed by
GitHub
Apr 19, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #32 from meshplus/feat/did-adaptation
Feat/did adaptation
parents
eba020ca
da3e8cf9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
148 additions
and
100 deletions
+148
-100
client.go
client.go
+26
-22
event.go
event.go
+16
-16
broker.go
example/contracts/src/broker/broker.go
+44
-43
helper.go
example/contracts/src/broker/helper.go
+21
-0
meta.go
example/contracts/src/broker/meta.go
+10
-4
data_swapper.go
example/contracts/src/data_swapper/data_swapper.go
+4
-5
transfer.go
example/contracts/src/transfer/transfer.go
+8
-10
go.mod
go.mod
+1
-0
go.sum
go.sum
+18
-0
No files found.
client.go
View file @
0d6dfd49
...
...
@@ -8,11 +8,10 @@ import (
"strings"
"time"
"github.com/hashicorp/go-hclog"
"github.com/Rican7/retry"
"github.com/Rican7/retry/strategy"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-protos-go/common"
...
...
@@ -22,6 +21,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric/common/util"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/bitxid"
"github.com/meshplus/pier/pkg/plugins"
)
...
...
@@ -56,14 +56,14 @@ type ContractMeta struct {
}
type
Client
struct
{
meta
*
ContractMeta
consumer
*
Consumer
eventC
chan
*
pb
.
IBTP
pierId
string
name
string
outMeta
map
[
string
]
uint64
ticker
*
time
.
Ticker
done
chan
bool
meta
*
ContractMeta
consumer
*
Consumer
eventC
chan
*
pb
.
IBTP
appchainID
string
name
string
outMeta
map
[
string
]
uint64
ticker
*
time
.
Ticker
done
chan
bool
}
type
CallFunc
struct
{
...
...
@@ -71,7 +71,7 @@ type CallFunc struct {
Args
[][]
byte
`json:"args"`
}
func
(
c
*
Client
)
Initialize
(
configPath
,
pierId
string
,
extra
[]
byte
)
error
{
func
(
c
*
Client
)
Initialize
(
configPath
,
appchainID
string
,
extra
[]
byte
)
error
{
eventC
:=
make
(
chan
*
pb
.
IBTP
)
fabricConfig
,
err
:=
UnmarshalConfig
(
configPath
)
if
err
!=
nil
{
...
...
@@ -94,7 +94,7 @@ func (c *Client) Initialize(configPath, pierId string, extra []byte) error {
m
=
make
(
map
[
string
]
uint64
)
}
mgh
,
err
:=
newFabricHandler
(
contractmeta
.
EventFilter
,
eventC
,
pierId
)
mgh
,
err
:=
newFabricHandler
(
contractmeta
.
EventFilter
,
eventC
,
appchainID
)
if
err
!=
nil
{
return
err
}
...
...
@@ -108,7 +108,7 @@ func (c *Client) Initialize(configPath, pierId string, extra []byte) error {
c
.
consumer
=
csm
c
.
eventC
=
eventC
c
.
meta
=
contractmeta
c
.
pierId
=
pierId
c
.
appchainID
=
appchainID
c
.
name
=
fabricConfig
.
Name
c
.
outMeta
=
m
c
.
ticker
=
time
.
NewTicker
(
2
*
time
.
Second
)
...
...
@@ -161,11 +161,11 @@ func (c *Client) polling() {
}
for
_
,
ev
:=
range
evs
{
ev
.
Proof
=
proof
c
.
eventC
<-
ev
.
Convert2IBTP
(
c
.
pierId
,
pb
.
IBTP_INTERCHAIN
)
c
.
eventC
<-
ev
.
Convert2IBTP
(
c
.
appchainID
,
pb
.
IBTP_INTERCHAIN
)
if
c
.
outMeta
==
nil
{
c
.
outMeta
=
make
(
map
[
string
]
uint64
)
}
c
.
outMeta
[
ev
.
DstChainID
]
++
c
.
outMeta
[
string
(
bitxid
.
DID
(
ev
.
DstContractDID
)
.
GetChainDID
())
]
++
}
case
<-
c
.
done
:
logger
.
Info
(
"Stop long polling"
)
...
...
@@ -204,12 +204,12 @@ func (c *Client) getProof(response channel.Response) ([]byte, error) {
var
err
error
proof
,
err
=
handle
(
response
)
if
err
!=
nil
{
logger
.
Error
(
"
can't get proof"
,
"er
r"
,
err
.
Error
())
logger
.
Error
(
"
Can't get proof"
,
"erro
r"
,
err
.
Error
())
return
err
}
return
nil
},
strategy
.
Wait
(
2
*
time
.
Second
));
err
!=
nil
{
logger
.
Error
(
"
get proof retry failed"
,
"er
r"
,
err
.
Error
())
logger
.
Error
(
"
Can't get proof"
,
"erro
r"
,
err
.
Error
())
}
return
proof
,
nil
...
...
@@ -342,7 +342,7 @@ func (c *Client) InvokeInterchain(from string, index uint64, destAddr string, ca
return
nil
},
strategy
.
Wait
(
2
*
time
.
Second
));
err
!=
nil
{
logger
.
Error
(
"Can't send rollback ibtp back to bitxhub"
,
"err"
,
err
.
Error
())
logger
.
Error
(
"Can't send rollback ibtp back to bitxhub"
,
"err
or
"
,
err
.
Error
())
}
if
err
!=
nil
{
...
...
@@ -372,7 +372,11 @@ func (c *Client) GetOutMessage(to string, idx uint64) (*pb.IBTP, error) {
return
nil
,
err
}
return
c
.
unpackIBTP
(
&
response
,
pb
.
IBTP_INTERCHAIN
)
proof
,
err
:=
c
.
getProof
(
response
)
if
err
!=
nil
{
return
nil
,
err
}
return
c
.
unpackIBTP
(
&
response
,
pb
.
IBTP_INTERCHAIN
,
proof
)
}
func
(
c
*
Client
)
GetInMessage
(
from
string
,
index
uint64
)
([][]
byte
,
error
)
{
...
...
@@ -489,13 +493,13 @@ func (c Client) InvokeIndexUpdate(from string, index uint64, category pb.IBTP_Ca
return
&
res
,
response
,
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
,
proof
[]
byte
)
(
*
pb
.
IBTP
,
error
)
{
ret
:=
&
Event
{}
if
err
:=
json
.
Unmarshal
(
response
.
Payload
,
ret
);
err
!=
nil
{
return
nil
,
err
}
return
ret
.
Convert2IBTP
(
c
.
pierId
,
ibtpType
),
nil
ret
.
Proof
=
proof
return
ret
.
Convert2IBTP
(
c
.
appchainID
,
ibtpType
),
nil
}
func
(
c
*
Client
)
unpackMap
(
response
channel
.
Response
)
(
map
[
string
]
uint64
,
error
)
{
...
...
event.go
View file @
0d6dfd49
...
...
@@ -6,32 +6,32 @@ import (
"github.com/cloudflare/cfssl/log"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/bitxid"
)
type
Event
struct
{
Index
uint64
`json:"index"`
DstChainID
string
`json:"dst_chain_id"`
SrcContractID
string
`json:"src_contract_id"`
DstContractID
string
`json:"dst_contract_id"`
Func
string
`json:"func"`
Args
string
`json:"args"`
Callback
string
`json:"callback"`
Argscb
string
`json:"argscb"`
Rollback
string
`json:"rollback"`
Argsrb
string
`json:"argsrb"`
Proof
[]
byte
`json:"proof"`
Extra
[]
byte
`json:"extra"`
Index
uint64
`json:"index"`
DstContractDID
string
`json:"dst_contract_did"`
SrcContractID
string
`json:"src_contract_id"`
Func
string
`json:"func"`
Args
string
`json:"args"`
Callback
string
`json:"callback"`
Argscb
string
`json:"argscb"`
Rollback
string
`json:"rollback"`
Argsrb
string
`json:"argsrb"`
Proof
[]
byte
`json:"proof"`
Extra
[]
byte
`json:"extra"`
}
func
(
ev
*
Event
)
Convert2IBTP
(
from
string
,
ibtpType
pb
.
IBTP_Type
)
*
pb
.
IBTP
{
func
(
ev
*
Event
)
Convert2IBTP
(
srcMethod
string
,
ibtpType
pb
.
IBTP_Type
)
*
pb
.
IBTP
{
pd
,
err
:=
ev
.
encryptPayload
()
if
err
!=
nil
{
log
.
Fatalf
(
"Get ibtp payload :%s"
,
err
)
}
return
&
pb
.
IBTP
{
From
:
from
,
To
:
ev
.
DstChainID
,
From
:
srcMethod
,
To
:
string
(
bitxid
.
DID
(
ev
.
DstContractDID
)
.
GetChainDID
())
,
Index
:
ev
.
Index
,
Type
:
ibtpType
,
Timestamp
:
time
.
Now
()
.
UnixNano
(),
...
...
@@ -53,7 +53,7 @@ func handleArgs(args string) [][]byte {
func
(
ev
*
Event
)
encryptPayload
()
([]
byte
,
error
)
{
content
:=
&
pb
.
Content
{
SrcContractId
:
ev
.
SrcContractID
,
DstContractId
:
ev
.
DstContractID
,
DstContractId
:
bitxid
.
DID
(
ev
.
DstContractDID
)
.
GetAddress
()
,
Func
:
ev
.
Func
,
Args
:
handleArgs
(
ev
.
Args
),
Callback
:
ev
.
Callback
,
...
...
example/contracts/src/broker/broker.go
View file @
0d6dfd49
...
...
@@ -26,16 +26,15 @@ const (
type
Broker
struct
{}
type
Event
struct
{
Index
uint64
`json:"index"`
DstChainID
string
`json:"dst_chain_id"`
SrcContractID
string
`json:"src_contract_id"`
DstContractID
string
`json:"dst_contract_id"`
Func
string
`json:"func"`
Args
string
`json:"args"`
Callback
string
`json:"callback"`
Argscb
string
`json:"argscb"`
Rollback
string
`json:"rollback"`
Argsrb
string
`json:"argsrb"`
Index
uint64
`json:"index"`
DstContractDID
string
`json:"dst_contract_did"`
SrcContractID
string
`json:"src_contract_id"`
Func
string
`json:"func"`
Args
string
`json:"args"`
Callback
string
`json:"callback"`
Argscb
string
`json:"argscb"`
Rollback
string
`json:"rollback"`
Argsrb
string
`json:"argsrb"`
}
type
CallFunc
struct
{
...
...
@@ -129,8 +128,7 @@ func (broker *Broker) initialize(stub shim.ChaincodeStubInterface) pb.Response {
}
// EmitInterchainEvent
// address to,
// address tid,
// string destContractDID,
// string func,
// string args,
// string callback;
...
...
@@ -138,18 +136,22 @@ func (broker *Broker) initialize(stub shim.ChaincodeStubInterface) pb.Response {
// string rollback;
// string argsRb;
func
(
broker
*
Broker
)
EmitInterchainEvent
(
stub
shim
.
ChaincodeStubInterface
,
args
[]
string
)
pb
.
Response
{
if
len
(
args
)
!=
8
{
return
shim
.
Error
(
"incorrect number of arguments, expecting
8
"
)
if
len
(
args
)
!=
7
{
return
shim
.
Error
(
"incorrect number of arguments, expecting
7
"
)
}
destChainID
:=
args
[
0
]
destContractDID
:=
args
[
0
]
destChainMethod
:=
parseMethod
(
destContractDID
)
if
destChainMethod
==
""
{
return
ErrInvalidDID
(
destContractDID
)
}
outMeta
,
err
:=
broker
.
getMap
(
stub
,
outterMeta
)
if
err
!=
nil
{
return
shim
.
Error
(
err
.
Error
())
}
if
_
,
ok
:=
outMeta
[
destChain
ID
];
!
ok
{
outMeta
[
destChain
ID
]
=
0
if
_
,
ok
:=
outMeta
[
destChain
Method
];
!
ok
{
outMeta
[
destChain
Method
]
=
0
}
cid
,
err
:=
getChaincodeID
(
stub
)
...
...
@@ -158,19 +160,18 @@ func (broker *Broker) EmitInterchainEvent(stub shim.ChaincodeStubInterface, args
}
tx
:=
&
Event
{
Index
:
outMeta
[
destChainID
]
+
1
,
DstChainID
:
destChainID
,
SrcContractID
:
cid
,
DstContractID
:
args
[
1
],
Func
:
args
[
2
],
Args
:
args
[
3
],
Callback
:
args
[
4
],
Argscb
:
args
[
5
],
Rollback
:
args
[
6
],
Argsrb
:
args
[
7
],
Index
:
outMeta
[
destChainMethod
]
+
1
,
DstContractDID
:
destContractDID
,
SrcContractID
:
cid
,
Func
:
args
[
1
],
Args
:
args
[
2
],
Callback
:
args
[
3
],
Argscb
:
args
[
4
],
Rollback
:
args
[
5
],
Argsrb
:
args
[
6
],
}
outMeta
[
tx
.
DstChainID
]
++
outMeta
[
destChainMethod
]
++
txValue
,
err
:=
json
.
Marshal
(
tx
)
if
err
!=
nil
{
...
...
@@ -178,7 +179,7 @@ func (broker *Broker) EmitInterchainEvent(stub shim.ChaincodeStubInterface, args
}
// persist out message
key
:=
broker
.
outMsgKey
(
tx
.
DstChainID
,
strconv
.
FormatUint
(
tx
.
Index
,
10
))
key
:=
broker
.
outMsgKey
(
destChainMethod
,
strconv
.
FormatUint
(
tx
.
Index
,
10
))
if
err
:=
stub
.
PutState
(
key
,
txValue
);
err
!=
nil
{
return
shim
.
Error
(
fmt
.
Errorf
(
"persist event: %w"
,
err
)
.
Error
())
}
...
...
@@ -258,15 +259,15 @@ func (broker *Broker) pollingEvent(stub shim.ChaincodeStubInterface, args []stri
return
shim
.
Error
(
err
.
Error
())
}
events
:=
make
([]
*
Event
,
0
)
for
addr
,
idx
:=
range
outMeta
{
startPos
,
ok
:=
m
[
addr
]
for
method
,
idx
:=
range
outMeta
{
startPos
,
ok
:=
m
[
method
]
if
!
ok
{
startPos
=
0
}
for
i
:=
startPos
+
1
;
i
<=
idx
;
i
++
{
eb
,
err
:=
stub
.
GetState
(
broker
.
outMsgKey
(
addr
,
strconv
.
FormatUint
(
i
,
10
)))
eb
,
err
:=
stub
.
GetState
(
broker
.
outMsgKey
(
method
,
strconv
.
FormatUint
(
i
,
10
)))
if
err
!=
nil
{
fmt
.
Printf
(
"get out event by key %s fail"
,
broker
.
outMsgKey
(
addr
,
strconv
.
FormatUint
(
i
,
10
)))
fmt
.
Printf
(
"get out event by key %s fail"
,
broker
.
outMsgKey
(
method
,
strconv
.
FormatUint
(
i
,
10
)))
continue
}
e
:=
&
Event
{}
...
...
@@ -284,17 +285,17 @@ func (broker *Broker) pollingEvent(stub shim.ChaincodeStubInterface, args []stri
return
shim
.
Success
(
ret
)
}
func
(
broker
*
Broker
)
updateIndex
(
stub
shim
.
ChaincodeStubInterface
,
sourceChain
ID
,
sequenceNum
string
,
isReq
bool
)
error
{
func
(
broker
*
Broker
)
updateIndex
(
stub
shim
.
ChaincodeStubInterface
,
sourceChain
Method
,
sequenceNum
string
,
isReq
bool
)
error
{
if
isReq
{
if
err
:=
broker
.
checkIndex
(
stub
,
sourceChain
ID
,
sequenceNum
,
innerMeta
);
err
!=
nil
{
if
err
:=
broker
.
checkIndex
(
stub
,
sourceChain
Method
,
sequenceNum
,
innerMeta
);
err
!=
nil
{
return
err
}
if
err
:=
broker
.
markInCounter
(
stub
,
sourceChain
ID
);
err
!=
nil
{
if
err
:=
broker
.
markInCounter
(
stub
,
sourceChain
Method
);
err
!=
nil
{
return
err
}
}
else
{
if
err
:=
broker
.
checkIndex
(
stub
,
sourceChain
ID
,
sequenceNum
,
callbackMeta
);
err
!=
nil
{
if
err
:=
broker
.
checkIndex
(
stub
,
sourceChain
Method
,
sequenceNum
,
callbackMeta
);
err
!=
nil
{
return
err
}
...
...
@@ -302,7 +303,7 @@ func (broker *Broker) updateIndex(stub shim.ChaincodeStubInterface, sourceChainI
if
err
!=
nil
{
return
err
}
if
err
:=
broker
.
markCallbackCounter
(
stub
,
sourceChain
ID
,
idx
);
err
!=
nil
{
if
err
:=
broker
.
markCallbackCounter
(
stub
,
sourceChain
Method
,
idx
);
err
!=
nil
{
return
err
}
}
...
...
@@ -315,14 +316,14 @@ func (broker *Broker) invokeIndexUpdate(stub shim.ChaincodeStubInterface, args [
return
errorResponse
(
"incorrect number of arguments, expecting 3"
)
}
sourceChain
ID
:=
args
[
0
]
sourceChain
Method
:=
args
[
0
]
sequenceNum
:=
args
[
1
]
isReq
,
err
:=
strconv
.
ParseBool
(
args
[
2
])
if
err
!=
nil
{
return
errorResponse
(
fmt
.
Sprintf
(
"cannot parse %s to bool"
,
args
[
3
]))
}
if
err
:=
broker
.
updateIndex
(
stub
,
sourceChain
ID
,
sequenceNum
,
isReq
);
err
!=
nil
{
if
err
:=
broker
.
updateIndex
(
stub
,
sourceChain
Method
,
sequenceNum
,
isReq
);
err
!=
nil
{
return
errorResponse
(
err
.
Error
())
}
...
...
@@ -334,7 +335,7 @@ func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args []
return
errorResponse
(
"incorrect number of arguments, expecting 5"
)
}
s
ourceChainID
:=
args
[
0
]
s
rcChainMethod
:=
args
[
0
]
sequenceNum
:=
args
[
1
]
targetCID
:=
args
[
2
]
isReq
,
err
:=
strconv
.
ParseBool
(
args
[
3
])
...
...
@@ -342,7 +343,7 @@ func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args []
return
errorResponse
(
fmt
.
Sprintf
(
"cannot parse %s to bool"
,
args
[
3
]))
}
if
err
:=
broker
.
updateIndex
(
stub
,
s
ourceChainID
,
sequenceNum
,
isReq
);
err
!=
nil
{
if
err
:=
broker
.
updateIndex
(
stub
,
s
rcChainMethod
,
sequenceNum
,
isReq
);
err
!=
nil
{
return
errorResponse
(
err
.
Error
())
}
...
...
@@ -364,7 +365,7 @@ func (broker *Broker) invokeInterchain(stub shim.ChaincodeStubInterface, args []
return
errorResponse
(
fmt
.
Sprintf
(
"invoke chaincode '%s' function %s err: %s"
,
splitedCID
[
1
],
callFunc
.
Func
,
response
.
Message
))
}
inKey
:=
broker
.
inMsgKey
(
s
ourceChainID
,
sequenceNum
)
inKey
:=
broker
.
inMsgKey
(
s
rcChainMethod
,
sequenceNum
)
value
,
err
:=
json
.
Marshal
(
response
)
if
err
!=
nil
{
return
errorResponse
(
err
.
Error
())
...
...
example/contracts/src/broker/helper.go
View file @
0d6dfd49
...
...
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode/shim"
...
...
@@ -200,3 +201,23 @@ func (broker *Broker) checkWhitelist(stub shim.ChaincodeStubInterface, function
return
broker
.
onlyWhitelist
(
stub
)
}
func
(
broker
*
Broker
)
validDID
(
did
string
)
bool
{
s
:=
strings
.
Split
(
did
,
":"
)
if
len
(
s
)
!=
4
||
s
[
0
]
!=
"did"
||
s
[
1
]
==
""
||
s
[
2
]
==
""
||
s
[
3
]
==
""
{
return
false
}
return
true
}
func
parseMethod
(
did
string
)
string
{
s
:=
strings
.
Split
(
did
,
":"
)
if
len
(
s
)
!=
4
||
s
[
0
]
!=
"did"
||
s
[
1
]
==
""
||
s
[
2
]
==
""
||
s
[
3
]
==
""
{
return
""
}
return
fmt
.
Sprintf
(
"%s:%s:%s:."
,
s
[
0
],
s
[
1
],
s
[
2
])
}
func
ErrInvalidDID
(
did
string
)
pb
.
Response
{
return
errorResponse
(
fmt
.
Sprintf
(
"Invalid did format for %s"
,
did
))
}
example/contracts/src/broker/meta.go
View file @
0d6dfd49
...
...
@@ -19,9 +19,12 @@ func (broker *Broker) getOutMessage(stub shim.ChaincodeStubInterface, args []str
if
len
(
args
)
<
2
{
return
shim
.
Error
(
"incorrect number of arguments, expecting 2"
)
}
destChain
ID
:=
args
[
0
]
destChain
Method
:=
args
[
0
]
sequenceNum
:=
args
[
1
]
key
:=
broker
.
outMsgKey
(
destChainID
,
sequenceNum
)
if
!
broker
.
validDID
(
destChainMethod
)
{
return
ErrInvalidDID
(
destChainMethod
)
}
key
:=
broker
.
outMsgKey
(
destChainMethod
,
sequenceNum
)
v
,
err
:=
stub
.
GetState
(
key
)
if
err
!=
nil
{
return
shim
.
Error
(
err
.
Error
())
...
...
@@ -42,9 +45,12 @@ func (broker *Broker) getInMessage(stub shim.ChaincodeStubInterface, args []stri
if
len
(
args
)
<
2
{
return
shim
.
Error
(
"incorrect number of arguments, expecting 2"
)
}
sourceChain
ID
:=
args
[
0
]
sourceChain
Method
:=
args
[
0
]
sequenceNum
:=
args
[
1
]
key
:=
broker
.
inMsgKey
(
sourceChainID
,
sequenceNum
)
if
!
broker
.
validDID
(
sourceChainMethod
)
{
return
ErrInvalidDID
(
sourceChainMethod
)
}
key
:=
broker
.
inMsgKey
(
sourceChainMethod
,
sequenceNum
)
v
,
err
:=
stub
.
GetState
(
key
)
if
err
!=
nil
{
return
shim
.
Error
(
err
.
Error
())
...
...
example/contracts/src/data_swapper/data_swapper.go
View file @
0d6dfd49
...
...
@@ -61,11 +61,10 @@ func (s *DataSwapper) get(stub shim.ChaincodeStubInterface, args []string) pb.Re
}
return
shim
.
Success
(
value
)
case
3
:
// args[0]: destination appchain id
// args[1]: destination contract address
// args[2]: key
b
:=
util
.
ToChaincodeArgs
(
emitInterchainEventFunc
,
args
[
0
],
args
[
1
],
"interchainGet"
,
args
[
2
],
"interchainSet"
,
args
[
2
],
""
,
""
)
case
2
:
// args[0]: destination appchain contract did
// args[1]: key
b
:=
util
.
ToChaincodeArgs
(
emitInterchainEventFunc
,
args
[
0
],
"interchainGet"
,
args
[
2
],
"interchainSet"
,
args
[
2
],
""
,
""
)
response
:=
stub
.
InvokeChaincode
(
brokerContractName
,
b
,
channelID
)
if
response
.
Status
!=
shim
.
OK
{
return
shim
.
Error
(
fmt
.
Errorf
(
"invoke broker chaincode %s error: %s"
,
brokerContractName
,
response
.
Message
)
.
Error
())
...
...
example/contracts/src/transfer/transfer.go
View file @
0d6dfd49
...
...
@@ -91,14 +91,12 @@ func (t *Transfer) transfer(stub shim.ChaincodeStubInterface, args []string) pb.
}
return
shim
.
Success
(
nil
)
case
5
:
// args[0]: destination appchain id
// args[1]: destination contract address
dest
:=
args
[
0
]
address
:=
args
[
1
]
sender
:=
args
[
2
]
receiver
:=
args
[
3
]
amountArg
:=
args
[
4
]
case
4
:
// args[0]: destination appchain contract did
destContractDID
:=
args
[
0
]
sender
:=
args
[
1
]
receiver
:=
args
[
2
]
amountArg
:=
args
[
3
]
amount
,
err
:=
getAmountArg
(
amountArg
)
if
err
!=
nil
{
...
...
@@ -123,7 +121,7 @@ func (t *Transfer) transfer(stub shim.ChaincodeStubInterface, args []string) pb.
args
:=
strings
.
Join
([]
string
{
sender
,
receiver
,
amountArg
},
","
)
argsRb
:=
strings
.
Join
([]
string
{
sender
,
amountArg
},
","
)
b
:=
util
.
ToChaincodeArgs
(
emitInterchainEventFunc
,
dest
,
address
,
"interchainCharge"
,
args
,
""
,
""
,
"interchainRollback"
,
argsRb
)
b
:=
util
.
ToChaincodeArgs
(
emitInterchainEventFunc
,
dest
ContractDID
,
"interchainCharge"
,
args
,
""
,
""
,
"interchainRollback"
,
argsRb
)
response
:=
stub
.
InvokeChaincode
(
brokerContractName
,
b
,
channelID
)
if
response
.
Status
!=
shim
.
OK
{
return
shim
.
Error
(
fmt
.
Errorf
(
"invoke broker chaincode %s"
,
response
.
Message
)
.
Error
())
...
...
@@ -131,7 +129,7 @@ func (t *Transfer) transfer(stub shim.ChaincodeStubInterface, args []string) pb.
return
shim
.
Success
(
nil
)
default
:
return
shim
.
Error
(
"incorrect number of arguments"
)
return
shim
.
Error
(
fmt
.
Sprintf
(
"incorrect number of arguments %d"
,
len
(
args
))
)
}
}
...
...
go.mod
View file @
0d6dfd49
...
...
@@ -6,6 +6,7 @@ require (
github.com/OneOfOne/xxhash v1.2.5 // indirect
github.com/Rican7/retry v0.1.0
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/meshplus/bitxid v0.0.0-20210331074321-62187b1145f5
github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f
github.com/elastic/gosigar v0.8.1-0.20180330100440-37f05ff46ffa // indirect
github.com/ethereum/go-ethereum v1.9.18 // indirect
...
...
go.sum
View file @
0d6dfd49
...
...
@@ -65,6 +65,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bitxhub/bitxid v0.2.0 h1:5o8EPtkwWmWhFGuPsmUGaG6Q9sC2GaWe8SrKibo91d8=
github.com/bitxhub/bitxid v0.2.0/go.mod h1:fOr+il1qUap5OTo6p4krM3Hsk4OZkGxC30BIjjwNz2c=
github.com/bombsimon/wsl/v2 v2.0.0 h1:+Vjcn+/T5lSrO8Bjzhk4v14Un/2UyCA1E3V5j9nwTkQ=
github.com/bombsimon/wsl/v2 v2.0.0/go.mod h1:mf25kr/SqFEPhhcxW1+7pxzGlW+hIl/hYTKY95VwV8U=
github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ=
...
...
@@ -406,6 +408,7 @@ github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3/go.mod h1:MZ2ZmwcBpvOo
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/hyperledger/fabric v1.4.8 h1:G0PeG/WHHAApO/PXkDAcwjur5L5+FNiVbhKidzNX4Z4=
github.com/hyperledger/fabric v1.4.11 h1:Z+cB0cPclR2VcoESlrcIRHI+vWv8TvRDESC9pwYw1nU=
github.com/hyperledger/fabric v2.0.1+incompatible h1:7W+yG0gLKTC7NLcWPT3vfpnaseztPpH9wXGfAW7yvBs=
github.com/hyperledger/fabric v2.0.1+incompatible/go.mod h1:tGFAOCT696D3rG0Vofd2dyWYLySHlh0aQjf7Q1HAju0=
github.com/hyperledger/fabric v2.1.1+incompatible h1:cYYRv3vVg4kA6DmrixLxwn1nwBEUuYda8DsMwlaMKbY=
...
...
@@ -721,6 +724,7 @@ github.com/meshplus/bitxhub v1.0.0-rc2/go.mod h1:ijWzPl7GExD3IKXJ0LhV4q680kDy1IF
github.com/meshplus/bitxhub-core v0.1.0-rc1/go.mod h1:ayq95vbGEh/G2nKyPeXPc62zanWhDuusVpIDAHm4Rk0=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20200513081655-9e99eb6078ff/go.mod h1:JAxVCppTLwO6+NG6z0ycK0RuZZvNFavsx5vqrsV2ewM=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20200526060151-b0efad4a2046/go.mod h1:txnekA7OS4YIixuSCk62BFKkmlqMP2w4R6Em8AR04pg=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20201021153523-274a013bfd41/go.mod h1:/SQKAylZzPup1JTc3WoApLEsB4uV3enXB2ib6jLpYUk=
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210204062242-16739cd5ee9a/go.mod h1:MHf0waxqnW4Qwfpq66jqvJP+FritN5OTs/8wlQcNlJY=
github.com/meshplus/bitxhub-kit v1.0.0-rc1 h1:gNi8IFU5CMHT3KE2I4ACj5alMW9h/4cV8xOxn7wSmtA=
github.com/meshplus/bitxhub-kit v1.0.0-rc1/go.mod h1:ra/AhOkPvpElI+wXrB9G6DjdcrdxFU3vMwA5MYKr9D0=
...
...
@@ -734,8 +738,12 @@ github.com/meshplus/bitxhub-kit v1.0.1-0.20200525112026-df2160653e23 h1:Q3+du0aT
github.com/meshplus/bitxhub-kit v1.0.1-0.20200525112026-df2160653e23/go.mod h1:8Pprmnq+2fFi5kJP0qcbwPl/fe22nro0OamjtwD0LJM=
github.com/meshplus/bitxhub-kit v1.0.1-0.20200813124031-6f6bdc99564f h1:86DXIUH6wUXYotD+xXWjAucay1+dk1A5PnWPLd79tRo=
github.com/meshplus/bitxhub-kit v1.0.1-0.20200813124031-6f6bdc99564f/go.mod h1:Whtgcr25HOF6iJv0Ib5/BPnEXq9iNFO89j8JQkElISk=
github.com/meshplus/bitxhub-kit v1.0.1 h1:OeXXdASOkh/XAvf815eYK+J6p25pRKhkQICHNhjyIAc=
github.com/meshplus/bitxhub-kit v1.0.1/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.1/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021105954-468d0a9d7957/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201023030558-9f36554d5d5d/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201023073721-052e6b89ea39/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d h1:J9tzTNf29mR0r97An3KoAtZQYlwpNhlMItWKyzKJLHU=
github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d/go.mod h1:KR7ZlXhII9n0Bu8viaZTScvXCYn0MCQnYlsTvHPp0XA=
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
...
...
@@ -749,15 +757,21 @@ github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200729120451-6ff9eb7fe8fc h1:40
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200729120451-6ff9eb7fe8fc/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200731025300-2bb1717059e0 h1:HICOZKS7qw4++eT0EXioutryV0O+v6aPp1jdhjlfJyU=
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200731025300-2bb1717059e0/go.mod h1:QK8aACbxtZEA3Hk1BOCirW0uxMWLsMrLDpWz9FweIKM=
github.com/meshplus/bitxhub-model v1.1.1/go.mod h1:lUl9vPZXM9tP+B0ABRW/2eOW/6KCmjFTdoiTj5Vut/A=
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23/go.mod h1:4qWBZx5wv7WZzUqiuBsbkQqQ2Ju8aOFpsoNpBBNy8Us=
github.com/meshplus/bitxhub-model v1.1.2-0.20201023091417-b6445e44d535/go.mod h1:4qWBZx5wv7WZzUqiuBsbkQqQ2Ju8aOFpsoNpBBNy8Us=
github.com/meshplus/bitxhub-model v1.1.2-0.20210107045700-cee670a2e117/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
github.com/meshplus/bitxhub-model v1.1.2-0.20210120083349-c7a006b03fcb h1:PxGQL22OVxozkvEgVvxHol9WDqCZlhyvnd0Bu0HBX1Y=
github.com/meshplus/bitxhub-model v1.1.2-0.20210120083349-c7a006b03fcb/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
github.com/meshplus/bitxhub-model v1.1.2-0.20210312014622-c3ad532b64ad h1:aTK2R7ATKdfAQe96xaXM91r6I1GPGvqFkHmum57G+G8=
github.com/meshplus/bitxhub-model v1.1.2-0.20210312014622-c3ad532b64ad/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
github.com/meshplus/bitxid v0.0.0-20210331074321-62187b1145f5 h1:AIK+w1w46SDjf3BGQstCnzoLRK1OeDullbaATaXbTHc=
github.com/meshplus/bitxid v0.0.0-20210331074321-62187b1145f5/go.mod h1:vAldSRfDe2Qo7exsSTbchVmZWXPY7fhWQrRw18QJHho=
github.com/meshplus/go-bitxhub-client v1.0.0-rc3/go.mod h1:FpiCyf6KhydcqthrHdvvPhbPIcD92b+Ju8T7WvQtSyM=
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20200509065005-851bf8c357e4/go.mod h1:JIfB02707GTRV97lMdw09GStYlK4upf1kn3B4DvwQYA=
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20200731031000-ec0387c42327 h1:oWNQm4YnDeRCy6VGPq6Kaw2y89nBRWP3WfRD2XbwS+c=
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20200731031000-ec0387c42327/go.mod h1:sZiSJ/ogv44V1OKMlg6rFxR6ib137h9Gc5PaC5W57RQ=
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20201023092924-5f9a248146f9/go.mod h1:6e0wKF//AwnJPlzXsfl5EDLRzn+/Wt8+fOEbKsYSFlc=
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20210301024916-b7461066a067/go.mod h1:ZWklYGrAMQcknmMMyxZtRU1IiBRuoYy570QNTp3WJbI=
github.com/meshplus/go-lightp2p v0.0.0-20200817105923-6b3aee40fa54/go.mod h1:G89UJaeqCQFxFdp8wzy1AdKfMtDEhpySau0pjDNeeaw=
github.com/meshplus/pier v1.0.0-rc1.0.20200707085406-951dc93be28b h1:2w2wGZ1XSHosf5vQDP3hE5LbLqRJusXJAW99oX/MrH4=
...
...
@@ -772,6 +786,8 @@ github.com/meshplus/pier v1.0.0-rc1.0.20200717044435-de24cfbef0f3 h1:zpSyEHn69VF
github.com/meshplus/pier v1.0.0-rc1.0.20200717044435-de24cfbef0f3/go.mod h1:78k4sa5aeOKXGBOU776vnRHaoZ4BJ8H0vassLC8oPQs=
github.com/meshplus/pier v1.1.0-rc1.0.20200824115625-bb57600455be h1:SAFio4GGQp3cTj+XcMF+xwJInMaKrFTGqQ+v+A9b2qg=
github.com/meshplus/pier v1.1.0-rc1.0.20200824115625-bb57600455be/go.mod h1:U9cOVTRdwGpWRz6A+zwIMDO76GL5w9l8W1NAtXIg/1U=
github.com/meshplus/pier v1.1.0-rc1.0.20201026071918-4c36946bf7b5 h1:xb4THDuIXhjxVSACVcMySj3QTlbRKCFUIc6E7rcj57I=
github.com/meshplus/pier v1.1.0-rc1.0.20201026071918-4c36946bf7b5/go.mod h1:3x/fZekC4rSb7yTY7L4MvXqoZBEhXJvDUA/nI30WSzg=
github.com/meshplus/pier v1.5.1-0.20210312103925-148435c71325 h1:3Nhv1eK+7s0GXf1gs1oDZm9EdIfeeLN91lA6+yYczk0=
github.com/meshplus/pier v1.5.1-0.20210312103925-148435c71325/go.mod h1:oj6DRUxEpSfj8pwTw7BjwhjUfx5sam840WKOkCfrli8=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
...
...
@@ -1024,6 +1040,7 @@ github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
...
...
@@ -1280,6 +1297,7 @@ golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f h1:mOhmO9WsBaJCNmaZHPtHs9wOcdqdKCjF6OPJlmDM3KI=
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq0iqbV3ZA+u6+0TlNCo=
golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
...
...
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