-
Notifications
You must be signed in to change notification settings - Fork 1
/
match_result.go
45 lines (40 loc) · 1.14 KB
/
match_result.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
package keeper
import (
"github.com/Timwood0x10/sei-chain/x/dex/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const MatchResultKey = "match-result"
func (k Keeper) SetMatchResult(ctx sdk.Context, contractAddr string, result *types.MatchResult) {
store := prefix.NewStore(
ctx.KVStore(k.storeKey),
types.MatchResultPrefix(contractAddr),
)
height := ctx.BlockHeight()
result.Height = height
result.ContractAddr = contractAddr
bz, err := result.Marshal()
if err != nil {
panic(err)
}
store.Set([]byte(MatchResultKey), bz)
}
func (k Keeper) GetMatchResultState(ctx sdk.Context, contractAddr string) (*types.MatchResult, bool) {
store := prefix.NewStore(
ctx.KVStore(k.storeKey),
types.MatchResultPrefix(contractAddr),
)
bz := store.Get([]byte(MatchResultKey))
result := types.MatchResult{}
if err := result.Unmarshal(bz); err != nil {
panic(err)
}
return &result, true
}
func (k Keeper) DeleteMatchResultState(ctx sdk.Context, contractAddr string) {
store := prefix.NewStore(
ctx.KVStore(k.storeKey),
types.MatchResultPrefix(contractAddr),
)
store.Delete([]byte(MatchResultKey))
}