-
Notifications
You must be signed in to change notification settings - Fork 23
/
auth.go
65 lines (60 loc) · 2.03 KB
/
auth.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 testutil
import (
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/likecoin/likecoin-chain/v2/bech32-migration/utils"
)
func AssertAuthAddressBech32(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) bool {
ok := true
utils.IterateStoreByPrefix(ctx, storeKey, types.AddressStoreKeyPrefix, func(bz []byte) []byte {
var accountI types.AccountI
err := cdc.UnmarshalInterface(bz, &accountI)
if err != nil {
panic(err)
}
var acc string
var itype string
switch accountI.(type) {
case *types.BaseAccount:
acc = accountI.(*types.BaseAccount).Address
itype = "BaseAccount"
case *types.ModuleAccount:
acc = accountI.(*types.ModuleAccount).Address
itype = "ModuleAccount"
case *vestingtypes.BaseVestingAccount:
acc = accountI.(*vestingtypes.BaseVestingAccount).Address
itype = "BaseVestingAccount"
case *vestingtypes.ContinuousVestingAccount:
acc = accountI.(*vestingtypes.ContinuousVestingAccount).Address
itype = "ContinuousVestingAccount"
case *vestingtypes.DelayedVestingAccount:
acc = accountI.(*vestingtypes.DelayedVestingAccount).Address
itype = "DelayedVestingAccount"
case *vestingtypes.PeriodicVestingAccount:
acc = accountI.(*vestingtypes.PeriodicVestingAccount).Address
itype = "PeriodicVestingAccount"
case *vestingtypes.PermanentLockedAccount:
acc = accountI.(*vestingtypes.PermanentLockedAccount).Address
itype = "PermanentLockedAccount"
default:
ctx.Logger().Info(
"Warning: unknown account type, skipping migration",
"address", accountI.GetAddress().String(),
"account_number", accountI.GetAccountNumber(),
"public_key", accountI.GetPubKey(),
"sequence", accountI.GetSequence(),
)
return bz
}
if !strings.HasPrefix(acc, "like") {
ctx.Logger().Info(fmt.Sprintf("Bad prefix found: %s, interface type: %s", acc, itype))
ok = false
}
return bz
})
return ok
}