/
process_proposer_matches_events.go
66 lines (56 loc) · 2.28 KB
/
process_proposer_matches_events.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
57
58
59
60
61
62
63
64
65
66
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furyanprotocol/v4-chain/protocol/lib"
"github.com/furyanprotocol/v4-chain/protocol/x/clob/types"
)
// GetProcessProposerMatchesEvents gets the process proposer matches events from the latest block.
func (k Keeper) GetProcessProposerMatchesEvents(ctx sdk.Context) types.ProcessProposerMatchesEvents {
// Retrieve an instance of the memory store.
memStore := ctx.KVStore(k.memKey)
// Retrieve the `processProposerMatchesEvents` bytes from the store.
processProposerMatchesEventsBytes := memStore.Get(
[]byte(types.ProcessProposerMatchesEventsKey),
)
// Unmarshal the `processProposerMatchesEvents` into a struct and return it.
var processProposerMatchesEvents types.ProcessProposerMatchesEvents
k.cdc.MustUnmarshal(processProposerMatchesEventsBytes, &processProposerMatchesEvents)
return processProposerMatchesEvents
}
// MustSetProcessProposerMatchesEvents sets the process proposer matches events from the latest block.
// This function panics if:
// - the current block height does not match the block height of the ProcessProposerMatchesEvents
// - called outside of deliver TX mode
// - Any of the ProcessProposerMatchesEvents fields have duplicates.
//
// TODO(DEC-1281): add parameter validation.
func (k Keeper) MustSetProcessProposerMatchesEvents(
ctx sdk.Context,
processProposerMatchesEvents types.ProcessProposerMatchesEvents,
) {
lib.AssertDeliverTxMode(ctx)
if err := processProposerMatchesEvents.ValidateProcessProposerMatchesEvents(ctx); err != nil {
panic(err)
}
// Retrieve an instance of the memory store.
memStore := ctx.KVStore(k.memKey)
// Write `processProposerMatchesEvents` to the `memStore`.
memStore.Set(
[]byte(types.ProcessProposerMatchesEventsKey),
k.cdc.MustMarshal(&processProposerMatchesEvents),
)
}
// InitializeProcessProposerMatchesEvents initializes the process proposer matches events.
// This function should only be called from the CLOB genesis.
func (k Keeper) InitializeProcessProposerMatchesEvents(
ctx sdk.Context,
) {
processProposerMatchesEvents := types.ProcessProposerMatchesEvents{
BlockHeight: 1,
}
memStore := ctx.KVStore(k.memKey)
memStore.Set(
[]byte(types.ProcessProposerMatchesEventsKey),
k.cdc.MustMarshal(&processProposerMatchesEvents),
)
}