-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from line/brew0722/v2/feat/merge-wasmd-0.16.0…
…-alpha1 feat(wasm): x/wasm stargate migration
- Loading branch information
Showing
168 changed files
with
33,856 additions
and
11,240 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
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,80 @@ | ||
package prefix | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/line/lbm-sdk/v2/store/types" | ||
tmdb "github.com/tendermint/tm-db" | ||
) | ||
|
||
// LegacyStore is an implementation to pass the store | ||
// to the wasmvm for tendermint/tm-db dependency. | ||
// line/tm-db/v2 has a modification to the Iterator interface, occurred a type mismatch. | ||
// Do not use it for any purpose other than passing it to wasmvm in x/wasm. | ||
type LegacyStore struct { | ||
Store | ||
} | ||
|
||
func NewLegacyStore(parent types.KVStore, prefix []byte) LegacyStore { | ||
return LegacyStore{ | ||
Store{ | ||
parent: parent, | ||
prefix: prefix, | ||
}, | ||
} | ||
} | ||
|
||
func (s LegacyStore) Iterator(start, end []byte) tmdb.Iterator { | ||
newstart := cloneAppend(s.prefix, start) | ||
|
||
var newend []byte | ||
if end == nil { | ||
newend = cpIncr(s.prefix) | ||
} else { | ||
newend = cloneAppend(s.prefix, end) | ||
} | ||
|
||
iter := s.parent.Iterator(newstart, newend) | ||
|
||
return newLegacyPrefixIterator(s.prefix, start, end, iter) | ||
} | ||
|
||
func (s LegacyStore) ReverseIterator(start, end []byte) tmdb.Iterator { | ||
newstart := cloneAppend(s.prefix, start) | ||
|
||
var newend []byte | ||
if end == nil { | ||
newend = cpIncr(s.prefix) | ||
} else { | ||
newend = cloneAppend(s.prefix, end) | ||
} | ||
|
||
iter := s.parent.ReverseIterator(newstart, newend) | ||
|
||
return newLegacyPrefixIterator(s.prefix, start, end, iter) | ||
} | ||
|
||
func (s LegacyStore) SdkIterator(start, end []byte) types.Iterator { | ||
return s.Store.Iterator(start, end) | ||
} | ||
|
||
type legacyPrefixIterator struct { | ||
prefixIterator | ||
} | ||
|
||
func newLegacyPrefixIterator(prefix, start, end []byte, parent types.Iterator) *legacyPrefixIterator { | ||
return &legacyPrefixIterator{ | ||
prefixIterator{ | ||
prefix: prefix, | ||
start: start, | ||
end: end, | ||
iter: parent, | ||
valid: parent.Valid() && bytes.HasPrefix(parent.Key(), prefix), | ||
}, | ||
} | ||
} | ||
|
||
// Implements Iterator | ||
func (pi *legacyPrefixIterator) Close() { | ||
pi.iter.Close() | ||
} |
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.