-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1b567f
commit 10d72d7
Showing
25 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package v040 | ||
|
||
// AddrLen defines a valid address length | ||
const AddrLen = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package v040 | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v040" | ||
) | ||
|
||
// KVStore keys | ||
var ( | ||
BalancesPrefix = []byte("balances") | ||
) | ||
|
||
// AddressFromBalancesStore returns an account address from a balances prefix | ||
// store. The key must not contain the perfix BalancesPrefix as the prefix store | ||
// iterator discards the actual prefix. | ||
func AddressFromBalancesStore(key []byte) sdk.AccAddress { | ||
addr := key[:v040auth.AddrLen] | ||
if len(addr) != v040auth.AddrLen { | ||
panic(fmt.Sprintf("unexpected account address key length; got: %d, expected: %d", len(addr), v040auth.AddrLen)) | ||
} | ||
|
||
return sdk.AccAddress(addr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package v042 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v040" | ||
v040bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v040" | ||
) | ||
|
||
// KVStore keys | ||
var ( | ||
// BalancesPrefix is the for the account balances store. We use a byte | ||
// (instead of say `[]]byte("balances")` to save some disk space). | ||
BalancesPrefix = []byte{0x02} | ||
) | ||
|
||
// AddressFromBalancesStore returns an account address from a balances prefix | ||
// store. The key must not contain the perfix BalancesPrefix as the prefix store | ||
// iterator discards the actual prefix. | ||
func AddressFromBalancesStore(key []byte) sdk.AccAddress { | ||
addrLen := key[0] | ||
addr := key[1 : addrLen+1] | ||
|
||
return sdk.AccAddress(addr) | ||
} | ||
|
||
// CreateAccountBalancesPrefix creates the prefix for an account's balances. | ||
func CreateAccountBalancesPrefix(addr []byte) []byte { | ||
return append(BalancesPrefix, address.MustLengthPrefix(addr)...) | ||
} | ||
|
||
// StoreMigration performs in-place store migrations from v0.40 to v0.42. The | ||
// migration includes: | ||
// | ||
// - Change addresses to be length-prefixed. | ||
// - Change balances prefix to 1 byte | ||
func StoreMigration(store sdk.KVStore) error { | ||
// old key is of format: | ||
// prefix ("balances") || addrBytes (20 bytes) || denomBytes | ||
// new key is of format | ||
// prefix (0x02) || addrLen (1 byte) || addrBytes || denomBytes | ||
oldStore := prefix.NewStore(store, v040bank.BalancesPrefix) | ||
newStore := prefix.NewStore(store, BalancesPrefix) | ||
|
||
oldStoreIter := oldStore.Iterator(nil, nil) | ||
defer oldStoreIter.Close() | ||
|
||
for ; oldStoreIter.Valid(); oldStoreIter.Next() { | ||
addr := v040bank.AddressFromBalancesStore(oldStoreIter.Key()) | ||
denom := oldStoreIter.Key()[1+v040auth.AddrLen:] | ||
newStoreKey := append(CreateAccountBalancesPrefix(addr), denom...) | ||
|
||
newStore.Set(newStoreKey, oldStoreIter.Value()) // Values don't change. | ||
oldStore.Delete(oldStoreIter.Key()) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package v042_test | ||
|
||
import "testing" | ||
|
||
func TestStoreMigration(t *testing.T) { | ||
// TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package v042 | ||
|
||
const ( | ||
ModuleName = "bank" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.