|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | 4 | "strings" |
6 | 5 |
|
7 | 6 | "github.com/cloudflare/cfssl/log" |
| 7 | + "github.com/ethereum/go-ethereum/crypto" |
8 | 8 | "github.com/meshplus/bitxhub-model/pb" |
9 | 9 | ) |
10 | 10 |
|
11 | 11 | type Event struct { |
12 | | - Index uint64 `json:"index"` |
13 | | - DstFullID string `json:"dst_full_id"` |
14 | | - SrcFullID string `json:"src_full_id"` |
15 | | - Func string `json:"func"` |
16 | | - Args string `json:"args"` |
17 | | - Argscb string `json:"argscb"` |
18 | | - Argsrb string `json:"argsrb"` |
| 12 | + Index uint64 `json:"index"` |
| 13 | + DstFullID string `json:"dst_full_id"` |
| 14 | + SrcFullID string `json:"src_full_id"` |
| 15 | + Encrypt bool `json:"encrypt"` |
| 16 | + CallFunc CallFunc `json:"call_func"` |
| 17 | + CallBack CallFunc `json:"callback"` |
| 18 | + RollBack CallFunc `json:"rollback"` |
19 | 19 | } |
20 | 20 |
|
21 | 21 | func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IBTP { |
@@ -44,25 +44,26 @@ func handleArgs(args string) [][]byte { |
44 | 44 | } |
45 | 45 |
|
46 | 46 | func (ev *Event) encryptPayload() ([]byte, error) { |
47 | | - funcSplit := strings.Split(ev.Func, ",") |
48 | | - if len(funcSplit) != 3 { |
49 | | - return nil, fmt.Errorf("ibtp func not is (func, callback,rollback)") |
50 | | - } |
51 | 47 | content := &pb.Content{ |
52 | | - Func: funcSplit[0], |
53 | | - Args: handleArgs(ev.Args), |
54 | | - Callback: funcSplit[1], |
55 | | - ArgsCb: handleArgs(ev.Argscb), |
56 | | - Rollback: funcSplit[2], |
57 | | - ArgsRb: handleArgs(ev.Argsrb), |
| 48 | + Func: ev.CallFunc.Func, |
| 49 | + Args: ev.CallFunc.Args, |
58 | 50 | } |
59 | 51 | data, err := content.Marshal() |
60 | 52 | if err != nil { |
61 | 53 | return nil, err |
62 | 54 | } |
63 | 55 |
|
| 56 | + var packed []byte |
| 57 | + packed = append(packed, []byte(ev.CallFunc.Func)...) |
| 58 | + for _, arg := range ev.CallFunc.Args { |
| 59 | + packed = append(packed, arg...) |
| 60 | + } |
| 61 | + hash := crypto.Keccak256(packed) |
| 62 | + |
64 | 63 | ibtppd := &pb.Payload{ |
65 | | - Content: data, |
| 64 | + Encrypted: ev.Encrypt, |
| 65 | + Content: data, |
| 66 | + Hash: hash, |
66 | 67 | } |
67 | 68 | return ibtppd.Marshal() |
68 | 69 | } |
|
0 commit comments