forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
context.go
48 lines (37 loc) · 931 Bytes
/
context.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
package auth
import (
"github.com/cosmos/cosmos-sdk/types"
)
/*
Usage:
var accounts types.AccountMapper
// Fetch all signer accounts.
addrs := tx.GetSigners()
signers := make([]types.Account, len(addrs))
for i, addr := range addrs {
acc := accounts.GetAccount(ctx)
signers[i] = acc
}
ctx = auth.SetSigners(ctx, signers)
// Get all signer accounts.
signers := auth.GetSigners(ctx)
for i, signer := range signers {
signer.Address() == tx.GetSigners()[i]
}
*/
type contextKey int // local to the auth module
const (
contextKeySigners contextKey = iota
)
// add the signers to the context
func WithSigners(ctx types.Context, accounts []types.Account) types.Context {
return ctx.WithValue(contextKeySigners, accounts)
}
// get the signers from the context
func GetSigners(ctx types.Context) []types.Account {
v := ctx.Value(contextKeySigners)
if v == nil {
return []types.Account{}
}
return v.([]types.Account)
}