Commit 5213e2b7 authored by Alexader's avatar Alexader

refactor(*): use new ibtp payload structure

parent 38d16740
...@@ -231,12 +231,16 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*model.PluginResponse, error) { ...@@ -231,12 +231,16 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*model.PluginResponse, error) {
if err := pd.Unmarshal(ibtp.Payload); err != nil { if err := pd.Unmarshal(ibtp.Payload); err != nil {
return ret, fmt.Errorf("ibtp payload unmarshal: %w", err) return ret, fmt.Errorf("ibtp payload unmarshal: %w", err)
} }
content := &pb.Content{}
if err := content.Unmarshal(pd.Content); err != nil {
return ret, fmt.Errorf("ibtp content unmarshal: %w", err)
}
args := util.ToChaincodeArgs(ibtp.From, strconv.FormatUint(ibtp.Index, 10), pd.DstContractId) args := util.ToChaincodeArgs(ibtp.From, strconv.FormatUint(ibtp.Index, 10), content.DstContractId)
args = append(args, pd.Args...) args = append(args, content.Args...)
request := channel.Request{ request := channel.Request{
ChaincodeID: c.meta.CCID, ChaincodeID: c.meta.CCID,
Fcn: pd.Func, Fcn: content.Func,
Args: args, Args: args,
} }
...@@ -271,7 +275,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*model.PluginResponse, error) { ...@@ -271,7 +275,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*model.PluginResponse, error) {
ret.Message = response.Message ret.Message = response.Message
// If no callback function to invoke, then simply return // If no callback function to invoke, then simply return
if pd.Callback == "" { if content.Callback == "" {
return ret, nil return ret, nil
} }
...@@ -280,9 +284,9 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*model.PluginResponse, error) { ...@@ -280,9 +284,9 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*model.PluginResponse, error) {
return ret, err return ret, err
} }
switch pd.Func { switch content.Func {
case "interchainGet": case "interchainGet":
newArgs = append(newArgs, pd.Args[0]) newArgs = append(newArgs, content.Args[0])
newArgs = append(newArgs, result...) newArgs = append(newArgs, result...)
case "interchainCharge": case "interchainCharge":
newArgs = append(newArgs, []byte("false")) newArgs = append(newArgs, []byte("false"))
......
...@@ -43,13 +43,21 @@ func (ev *Event) encryptPayload() ([]byte, error) { ...@@ -43,13 +43,21 @@ func (ev *Event) encryptPayload() ([]byte, error) {
for _, a := range as { for _, a := range as {
args = append(args, []byte(a)) args = append(args, []byte(a))
} }
ibtppd := &pb.Payload{ content := &pb.Content{
SrcContractId: ev.SrcContractID, SrcContractId: ev.SrcContractID,
DstContractId: ev.DstContractID, DstContractId: ev.DstContractID,
Func: ev.Func, Func: ev.Func,
Args: args, Args: args,
Callback: ev.Callback, Callback: ev.Callback,
} }
data, err := content.Marshal()
if err != nil {
return nil, err
}
ibtppd := &pb.Payload{
Content: data,
}
return ibtppd.Marshal() return ibtppd.Marshal()
} }
......
...@@ -4,6 +4,7 @@ go 1.13 ...@@ -4,6 +4,7 @@ go 1.13
require ( require (
github.com/Rican7/retry v0.1.0 github.com/Rican7/retry v0.1.0
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004
github.com/golang/protobuf v1.4.0 github.com/golang/protobuf v1.4.0
github.com/golangci/golangci-lint v1.23.0 // indirect github.com/golangci/golangci-lint v1.23.0 // indirect
...@@ -18,9 +19,12 @@ require ( ...@@ -18,9 +19,12 @@ require (
github.com/meshplus/pier v0.0.0-00010101000000-000000000000 github.com/meshplus/pier v0.0.0-00010101000000-000000000000
github.com/sirupsen/logrus v1.5.0 github.com/sirupsen/logrus v1.5.0
github.com/spf13/viper v1.6.1 github.com/spf13/viper v1.6.1
sigs.k8s.io/yaml v1.2.0 // indirect
) )
replace github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
replace google.golang.org/grpc => google.golang.org/grpc v1.28.1
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.7 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 golang.org/x/net => golang.org/x/net v0.0.0-20200202094626-16171245cfb2
......
This diff is collapsed.
...@@ -7,34 +7,47 @@ import ( ...@@ -7,34 +7,47 @@ import (
"github.com/meshplus/bitxhub-model/pb" "github.com/meshplus/bitxhub-model/pb"
) )
func (c *Client) generateCallback(toExecute *pb.IBTP, args [][]byte, proof []byte) (result *pb.IBTP, err error) { func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, proof []byte) (result *pb.IBTP, err error) {
if toExecute == nil { if original == nil {
return nil, fmt.Errorf("got nil ibtp to generate receipt: %w", err) return nil, fmt.Errorf("got nil ibtp to generate receipt: %w", err)
} }
pd := &pb.Payload{} pd := &pb.Payload{}
if err := pd.Unmarshal(toExecute.Payload); err != nil { if err := pd.Unmarshal(original.Payload); err != nil {
return nil, fmt.Errorf("ibtp payload unmarshal: %w", err) return nil, fmt.Errorf("ibtp payload unmarshal: %w", err)
} }
pdb := &pb.Payload{ originalContent := &pb.Content{}
SrcContractId: pd.DstContractId, if err := originalContent.Unmarshal(pd.Content); err != nil {
DstContractId: pd.SrcContractId, return nil, fmt.Errorf("ibtp payload unmarshal: %w", err)
Func: pd.Callback, }
content := &pb.Content{
SrcContractId: originalContent.DstContractId,
DstContractId: originalContent.SrcContractId,
Func: originalContent.Callback,
Args: args, Args: args,
} }
b, err := pdb.Marshal() b, err := content.Marshal()
if err != nil {
return nil, err
}
retPd := &pb.Payload{
Content: b,
}
pdb, err := retPd.Marshal()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &pb.IBTP{ return &pb.IBTP{
From: toExecute.From, From: original.From,
To: toExecute.To, To: original.To,
Index: toExecute.Index, Index: original.Index,
Type: pb.IBTP_RECEIPT, Type: pb.IBTP_RECEIPT,
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Proof: proof, Proof: proof,
Payload: b, Payload: pdb,
Version: toExecute.Version, Version: original.Version,
}, nil }, nil
} }
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