-
Notifications
You must be signed in to change notification settings - Fork 833
/
revenues.go
156 lines (135 loc) · 4.38 KB
/
revenues.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/evmos/v10/x/revenue/types"
)
// GetRevenues returns all registered Revenues.
func (k Keeper) GetRevenues(ctx sdk.Context) []types.Revenue {
revenues := []types.Revenue{}
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixRevenue)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var revenue types.Revenue
k.cdc.MustUnmarshal(iterator.Value(), &revenue)
revenues = append(revenues, revenue)
}
return revenues
}
// IterateRevenues iterates over all registered contracts and performs a
// callback with the corresponding Revenue.
func (k Keeper) IterateRevenues(
ctx sdk.Context,
handlerFn func(fee types.Revenue) (stop bool),
) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixRevenue)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var revenue types.Revenue
k.cdc.MustUnmarshal(iterator.Value(), &revenue)
if handlerFn(revenue) {
break
}
}
}
// GetRevenue returns the Revenue for a registered contract
func (k Keeper) GetRevenue(
ctx sdk.Context,
contract common.Address,
) (types.Revenue, bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixRevenue)
bz := store.Get(contract.Bytes())
if len(bz) == 0 {
return types.Revenue{}, false
}
var revenue types.Revenue
k.cdc.MustUnmarshal(bz, &revenue)
return revenue, true
}
// SetRevenue stores the Revenue for a registered contract.
func (k Keeper) SetRevenue(ctx sdk.Context, revenue types.Revenue) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixRevenue)
key := revenue.GetContractAddr()
bz := k.cdc.MustMarshal(&revenue)
store.Set(key.Bytes(), bz)
}
// DeleteRevenue deletes a Revenue of a registered contract.
func (k Keeper) DeleteRevenue(ctx sdk.Context, fee types.Revenue) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixRevenue)
key := fee.GetContractAddr()
store.Delete(key.Bytes())
}
// SetDeployerMap stores a contract-by-deployer mapping
func (k Keeper) SetDeployerMap(
ctx sdk.Context,
deployer sdk.AccAddress,
contract common.Address,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixDeployer)
key := append(deployer.Bytes(), contract.Bytes()...)
store.Set(key, []byte{1})
}
// DeleteDeployerMap deletes a contract-by-deployer mapping
func (k Keeper) DeleteDeployerMap(
ctx sdk.Context,
deployer sdk.AccAddress,
contract common.Address,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixDeployer)
key := append(deployer.Bytes(), contract.Bytes()...)
store.Delete(key)
}
// SetWithdrawerMap stores a contract-by-withdrawer mapping
func (k Keeper) SetWithdrawerMap(
ctx sdk.Context,
withdrawer sdk.AccAddress,
contract common.Address,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixWithdrawer)
key := append(withdrawer.Bytes(), contract.Bytes()...)
store.Set(key, []byte{1})
}
// DeleteWithdrawMap deletes a contract-by-withdrawer mapping
func (k Keeper) DeleteWithdrawerMap(
ctx sdk.Context,
withdrawer sdk.AccAddress,
contract common.Address,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixWithdrawer)
key := append(withdrawer.Bytes(), contract.Bytes()...)
store.Delete(key)
}
// IsRevenueRegistered checks if a contract was registered for receiving
// transaction fees
func (k Keeper) IsRevenueRegistered(
ctx sdk.Context,
contract common.Address,
) bool {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixRevenue)
return store.Has(contract.Bytes())
}
// IsDeployerMapSet checks if a given contract-by-withdrawer mapping is set in
// store
func (k Keeper) IsDeployerMapSet(
ctx sdk.Context,
deployer sdk.AccAddress,
contract common.Address,
) bool {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixDeployer)
key := append(deployer.Bytes(), contract.Bytes()...)
return store.Has(key)
}
// IsWithdrawerMapSet checks if a giveb contract-by-withdrawer mapping is set in
// store
func (k Keeper) IsWithdrawerMapSet(
ctx sdk.Context,
withdrawer sdk.AccAddress,
contract common.Address,
) bool {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixWithdrawer)
key := append(withdrawer.Bytes(), contract.Bytes()...)
return store.Has(key)
}