-
Notifications
You must be signed in to change notification settings - Fork 320
/
receipt_log.go
78 lines (64 loc) · 1.96 KB
/
receipt_log.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2020 IoTeX Foundation
// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache
// License 2.0 that can be found in the LICENSE file.
package staking
import (
"context"
"github.com/iotexproject/go-pkgs/hash"
"github.com/iotexproject/iotex-address/address"
"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/action/protocol"
)
type receiptLog struct {
addr string
topics action.Topics
data []byte
postFairbankMigration bool
}
func newReceiptLog(addr, topic string, postFairbankMigration bool) *receiptLog {
r := receiptLog{
addr: addr,
postFairbankMigration: postFairbankMigration,
}
if postFairbankMigration {
r.topics = action.Topics{hash.BytesToHash256([]byte(topic))}
} else {
r.topics = action.Topics{hash.Hash256b([]byte(topic))}
}
return &r
}
func (r *receiptLog) AddTopics(topics ...[]byte) {
if r.postFairbankMigration {
for i := range topics {
r.topics = append(r.topics, hash.BytesToHash256(topics[i]))
}
}
}
func (r *receiptLog) AddAddress(addr address.Address) {
if !r.postFairbankMigration && addr != nil {
r.topics = append(r.topics, hash.Hash256b(addr.Bytes()))
}
}
func (r *receiptLog) SetData(data []byte) {
r.data = data
}
func (r *receiptLog) Build(ctx context.Context, err error) *action.Log {
blkCtx := protocol.MustGetBlockCtx(ctx)
actionCtx := protocol.MustGetActionCtx(ctx)
log := action.Log{
Address: r.addr,
Topics: r.topics,
BlockHeight: blkCtx.BlockHeight,
ActionHash: actionCtx.ActionHash,
}
if r.postFairbankMigration {
return &log
}
if err == nil {
log.Data = r.data
return &log
}
return nil
}