forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add old supply offset functions #629
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"cosmossdk.io/math" | ||
"cosmossdk.io/store/prefix" | ||
|
||
"github.com/cosmos/cosmos-sdk/runtime" | ||
"github.com/cosmos/cosmos-sdk/x/bank/types" | ||
) | ||
|
||
// NOTE: All these functions should only be used in the v27 migration | ||
// this file should be removed completely after the migration | ||
|
||
// GetSupplyOffset retrieves the SupplyOffset from store for a specific denom using the pre v26 (old) key | ||
// TODO: Remove after v27 migration | ||
func (k BaseViewKeeper) GetSupplyOffsetOld(ctx context.Context, denom string) math.Int { | ||
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) | ||
supplyOffsetStore := prefix.NewStore(store, types.SupplyOffsetKeyOld) | ||
|
||
bz := supplyOffsetStore.Get([]byte(denom)) | ||
if bz == nil { | ||
return math.NewInt(0) | ||
} | ||
|
||
var amount math.Int | ||
err := amount.Unmarshal(bz) | ||
if err != nil { | ||
panic(fmt.Errorf("unable to unmarshal supply offset value %v", err)) | ||
} | ||
|
||
return amount | ||
} | ||
|
||
// RemoveOldSupplyOffset removes the old supply offset key | ||
// TODO: Remove after v27 migration | ||
func (k BaseViewKeeper) RemoveOldSupplyOffset(ctx context.Context, denom string) { | ||
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) | ||
supplyOffsetStore := prefix.NewStore(store, types.SupplyOffsetKeyOld) | ||
|
||
supplyOffsetStore.Delete([]byte(denom)) | ||
} | ||
|
||
// setSupplyOffsetOld sets the supply offset for the given denom using the pre v26 (old) key | ||
// TODO: Remove after v27 migration | ||
func (k BaseKeeper) setSupplyOffsetOld(ctx context.Context, denom string, offsetAmount math.Int) { | ||
intBytes, err := offsetAmount.Marshal() | ||
if err != nil { | ||
panic(fmt.Errorf("unable to marshal amount value %v", err)) | ||
} | ||
|
||
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) | ||
supplyOffsetStore := prefix.NewStore(store, types.SupplyOffsetKeyOld) | ||
|
||
// Bank invariants and IBC requires to remove zero coins. | ||
if offsetAmount.IsZero() { | ||
supplyOffsetStore.Delete([]byte(denom)) | ||
} else { | ||
supplyOffsetStore.Set([]byte(denom), intBytes) | ||
} | ||
} | ||
|
||
// AddSupplyOffsetOld adjusts the current supply offset of a denom by the inputted offsetAmount using the pre v26 (old) key | ||
// TODO: Remove after v27 migration | ||
func (k BaseKeeper) AddSupplyOffsetOld(ctx context.Context, denom string, offsetAmount math.Int) { | ||
k.setSupplyOffsetOld(ctx, denom, k.GetSupplyOffsetOld(ctx, denom).Add(offsetAmount)) | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to verify that you checked NewPrefix 88 does not collide with []byte{0x88}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I did, this is the bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, just understood, thanks