-
Notifications
You must be signed in to change notification settings - Fork 1
/
signers.go
36 lines (32 loc) · 1.13 KB
/
signers.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
package depdecorators
import (
"encoding/hex"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
type SignerDepDecorator struct {
ReadOnly bool
}
func (d SignerDepDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sdk.Tx, next sdk.AnteDepGenerator) (newTxDeps []sdkacltypes.AccessOperation, err error) {
sigTx, ok := tx.(authsigning.SigVerifiableTx)
if !ok {
return txDeps, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type")
}
var accessType sdkacltypes.AccessType
if d.ReadOnly {
accessType = sdkacltypes.AccessType_READ
} else {
accessType = sdkacltypes.AccessType_WRITE
}
for _, signer := range sigTx.GetSigners() {
txDeps = append(txDeps, sdkacltypes.AccessOperation{
AccessType: accessType,
ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE,
IdentifierTemplate: hex.EncodeToString(authtypes.AddressStoreKey(signer)),
})
}
return next(txDeps, tx)
}