-
Notifications
You must be signed in to change notification settings - Fork 23
/
gov.go
56 lines (52 loc) · 1.91 KB
/
gov.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
package gov
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/likecoin/likecoin-chain/v3/bech32-migration/utils"
)
func MigrateAddressBech32(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) {
ctx.Logger().Info("Migration of address bech32 for gov module begin")
voteCount := uint64(0)
utils.IterateStoreByPrefix(ctx, storeKey, types.VotesKeyPrefix, func(bz []byte) []byte {
vote := types.Vote{}
cdc.MustUnmarshal(bz, &vote)
vote.Voter = utils.ConvertAccAddr(vote.Voter)
voteCount++
return cdc.MustMarshal(&vote)
})
depositCount := uint64(0)
utils.IterateStoreByPrefix(ctx, storeKey, types.DepositsKeyPrefix, func(bz []byte) []byte {
deposit := types.Deposit{}
cdc.MustUnmarshal(bz, &deposit)
deposit.Depositor = utils.ConvertAccAddr(deposit.Depositor)
depositCount++
return cdc.MustMarshal(&deposit)
})
communityPoolSpendProposalCount := uint64(0)
utils.IterateStoreByPrefix(ctx, storeKey, types.ProposalsKeyPrefix, func(bz []byte) []byte {
proposal := types.Proposal{}
cdc.MustUnmarshal(bz, &proposal)
content := proposal.GetContent()
communityPoolSpendProposal, ok := content.(*distrtypes.CommunityPoolSpendProposal)
if !ok {
return bz
}
communityPoolSpendProposal.Recipient = utils.ConvertAccAddr(communityPoolSpendProposal.Recipient)
newContentAny, err := codectypes.NewAnyWithValue(communityPoolSpendProposal)
if err != nil {
panic(err)
}
proposal.Content = newContentAny
communityPoolSpendProposalCount++
return cdc.MustMarshal(&proposal)
})
ctx.Logger().Info(
"Migration of address bech32 for gov module done",
"vote_count", voteCount,
"deposit_count", depositCount,
"community_pool_spend_proposal_count", communityPoolSpendProposalCount,
)
}