forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkauth.go
41 lines (37 loc) · 1.24 KB
/
linkauth.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
package system
import "github.com/eoscochain/eos-go"
// NewLinkAuth creates an action from the `eosio.system` contract
// called `linkauth`.
//
// `linkauth` allows you to attach certain permission to the given
// `code::actionName`. With this set on-chain, you can use the
// `requiredPermission` to sign transactions for `code::actionName`
// and not rely on your `active` (which might be more sensitive as it
// can sign anything) for the given operation.
func NewLinkAuth(account, code eos.AccountName, actionName eos.ActionName, requiredPermission eos.PermissionName) *eos.Action {
a := &eos.Action{
Account: AN("eosio"),
Name: ActN("linkauth"),
Authorization: []eos.PermissionLevel{
{
Actor: account,
Permission: eos.PermissionName("active"),
},
},
ActionData: eos.NewActionData(LinkAuth{
Account: account,
Code: code,
Type: actionName,
Requirement: requiredPermission,
}),
}
return a
}
// LinkAuth represents the native `linkauth` action, through the
// system contract.
type LinkAuth struct {
Account eos.AccountName `json:"account"`
Code eos.AccountName `json:"code"`
Type eos.ActionName `json:"type"`
Requirement eos.PermissionName `json:"requirement"`
}