This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
codes.go
97 lines (84 loc) · 2.76 KB
/
codes.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package builtin
import (
"sort"
"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
)
// The built-in actor code IDs
var (
SystemActorCodeID cid.Cid
InitActorCodeID cid.Cid
CronActorCodeID cid.Cid
AccountActorCodeID cid.Cid
StoragePowerActorCodeID cid.Cid
StorageMinerActorCodeID cid.Cid
StorageMarketActorCodeID cid.Cid
PaymentChannelActorCodeID cid.Cid
MultisigActorCodeID cid.Cid
RewardActorCodeID cid.Cid
VerifiedRegistryActorCodeID cid.Cid
CallerTypesSignable []cid.Cid
)
var builtinActors map[cid.Cid]*actorInfo
type actorInfo struct {
name string
signer bool
}
func init() {
builder := cid.V1Builder{Codec: cid.Raw, MhType: mh.IDENTITY}
builtinActors = make(map[cid.Cid]*actorInfo)
for id, info := range map[*cid.Cid]*actorInfo{ //nolint:nomaprange
&SystemActorCodeID: {name: "fil/7/system"},
&InitActorCodeID: {name: "fil/7/init"},
&CronActorCodeID: {name: "fil/7/cron"},
&StoragePowerActorCodeID: {name: "fil/7/storagepower"},
&StorageMinerActorCodeID: {name: "fil/7/storageminer"},
&StorageMarketActorCodeID: {name: "fil/7/storagemarket"},
&PaymentChannelActorCodeID: {name: "fil/7/paymentchannel"},
&RewardActorCodeID: {name: "fil/7/reward"},
&VerifiedRegistryActorCodeID: {name: "fil/7/verifiedregistry"},
&AccountActorCodeID: {name: "fil/7/account", signer: true},
&MultisigActorCodeID: {name: "fil/7/multisig", signer: true},
} {
c, err := builder.Sum([]byte(info.name))
if err != nil {
panic(err)
}
*id = c
builtinActors[c] = info
}
// Set of actor code types that can represent external signing parties.
for id, info := range builtinActors { //nolint:nomaprange
if info.signer {
CallerTypesSignable = append(CallerTypesSignable, id)
}
}
sort.Slice(CallerTypesSignable, func(i, j int) bool {
return CallerTypesSignable[i].KeyString() < CallerTypesSignable[j].KeyString()
})
}
// IsBuiltinActor returns true if the code belongs to an actor defined in this repo.
func IsBuiltinActor(code cid.Cid) bool {
_, isBuiltin := builtinActors[code]
return isBuiltin
}
// ActorNameByCode returns the (string) name of the actor given a cid code.
func ActorNameByCode(code cid.Cid) string {
if !code.Defined() {
return "<undefined>"
}
info, ok := builtinActors[code]
if !ok {
return "<unknown>"
}
return info.name
}
// Tests whether a code CID represents an actor that can be an external principal: i.e. an account or multisig.
// We could do something more sophisticated here: https://github.com/filecoin-project/specs-actors/issues/178
func IsPrincipal(code cid.Cid) bool {
info, ok := builtinActors[code]
if !ok {
return false
}
return info.signer
}