-
Notifications
You must be signed in to change notification settings - Fork 459
/
pattern.go
65 lines (53 loc) · 1.64 KB
/
pattern.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
package vmcontext
import (
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/venus/pkg/specactors/builtin"
"github.com/filecoin-project/venus/pkg/vm/runtime"
)
// IsAccountActor pattern checks if the caller is an account actor.
// Dragons: delete after switching to new actors
type IsAccountActor struct{}
// IsMatch returns "True" if the patterns matches
func (IsAccountActor) IsMatch(ctx runtime.PatternContext) bool {
return builtin.IsAccountActor(ctx.CallerCode())
}
// IsAInitActor pattern checks if the caller is the init actor.
// Dragons: delete after switching to new actors
type IsAInitActor struct{}
// IsMatch returns "True" if the patterns matches
func (IsAInitActor) IsMatch(ctx runtime.PatternContext) bool {
return builtin.IsInitActor(ctx.CallerCode())
}
// Any patterns always passses.
type Any struct{}
// IsMatch returns "True" if the patterns matches
func (Any) IsMatch(ctx runtime.PatternContext) bool {
return true
}
// AddressIn pattern checks if the callers address is in the list of items provided.
type AddressIn struct {
Addresses []address.Address
}
// IsMatch returns "True" if the patterns matches
func (p AddressIn) IsMatch(ctx runtime.PatternContext) bool {
for _, a := range p.Addresses {
if a == ctx.CallerAddr() {
return true
}
}
return false
}
// CodeIn pattern checks if the callers code CID is in the list of items provided.
type CodeIn struct {
Codes []cid.Cid
}
// IsMatch returns "True" if the patterns matches
func (p CodeIn) IsMatch(ctx runtime.PatternContext) bool {
for _, c := range p.Codes {
if c == ctx.CallerCode() {
return true
}
}
return false
}