-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreceipt.go
50 lines (43 loc) · 1.08 KB
/
receipt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/meshplus/bitxhub-model/pb"
)
func (c *Client) generateReceipt(from, to string, idx uint64, args [][]byte, proof []byte, status, encrypt bool, typ uint64) (*pb.IBTP, error) {
var result []*pb.ResultRes
res := &pb.ResultRes{Data: args}
result = append(result, res)
var multiStatus []bool
if typ == uint64(pb.IBTP_RECEIPT_SUCCESS) {
multiStatus = append(multiStatus, true)
} else {
multiStatus = append(multiStatus, false)
}
results := &pb.Result{Data: result, MultiStatus: multiStatus}
content, err := results.Marshal()
if err != nil {
return nil, err
}
var packed []byte
for _, ele := range args {
packed = append(packed, ele...)
}
payload := pb.Payload{
Encrypted: encrypt,
Content: content,
Hash: crypto.Keccak256(packed),
}
pd, err := payload.Marshal()
if err != nil {
return nil, err
}
return &pb.IBTP{
From: from,
To: to,
Index: idx,
Type: pb.IBTP_Type(typ),
TimeoutHeight: 0,
Proof: proof,
Payload: pd,
}, nil
}