1 Star 0 Fork 1

闫熊猫/pier-client-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
receipt.go 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
jzhe 提交于 2021-08-10 15:08 . feat:handle ibtp-2.0
package main
import (
"fmt"
"github.com/meshplus/bitxhub-model/pb"
)
func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) (result *pb.IBTP, err error) {
if original == nil {
return nil, fmt.Errorf("got nil ibtp To generate receipt: %w", err)
}
pd := &pb.Payload{}
if err := pd.Unmarshal(original.Payload); err != nil {
return nil, fmt.Errorf("ibtp payload unmarshal: %w", err)
}
originalContent := &pb.Content{}
if err := originalContent.Unmarshal(pd.Content); err != nil {
return nil, fmt.Errorf("ibtp payload unmarshal: %w", err)
}
content := &pb.Content{}
typ := pb.IBTP_RECEIPT_SUCCESS
if status {
content.Func = originalContent.Callback
content.Args = append(originalContent.ArgsCb, args...)
} else {
content.Func = originalContent.Rollback
content.Args = originalContent.ArgsRb
typ = pb.IBTP_RECEIPT_FAILURE
}
if original.Type == pb.IBTP_ROLLBACK {
typ = pb.IBTP_RECEIPT_ROLLBACK
}
b, err := content.Marshal()
if err != nil {
return nil, err
}
retPd := &pb.Payload{
Content: b,
}
pdb, err := retPd.Marshal()
if err != nil {
return nil, err
}
return &pb.IBTP{
From: original.From,
To: original.To,
Index: original.Index,
Type: typ,
Proof: original.Proof,
Payload: pdb,
Version: original.Version,
}, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/panda-yan/pier-client-fabric.git
git@gitee.com:panda-yan/pier-client-fabric.git
panda-yan
pier-client-fabric
pier-client-fabric
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385