mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 22:45:45 +00:00
feat: add counter for activated TAs
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
e06fc55630
commit
064e7c1b38
@ -1,6 +1,7 @@
|
|||||||
package keeper
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/planetmint/planetmint-go/util"
|
"github.com/planetmint/planetmint-go/util"
|
||||||
@ -16,6 +17,8 @@ func (k Keeper) StoreTrustAnchor(ctx sdk.Context, ta types.TrustAnchor, activate
|
|||||||
var appendValue []byte
|
var appendValue []byte
|
||||||
if activated {
|
if activated {
|
||||||
appendValue = []byte{1}
|
appendValue = []byte{1}
|
||||||
|
counter := k.GetActivatedTACounter(ctx)
|
||||||
|
k.setActivatedTACounter(ctx, counter+1)
|
||||||
} else {
|
} else {
|
||||||
appendValue = []byte{0}
|
appendValue = []byte{0}
|
||||||
}
|
}
|
||||||
@ -46,3 +49,20 @@ func (k Keeper) GetTrustAnchor(ctx sdk.Context, pubKey string) (val types.TrustA
|
|||||||
}
|
}
|
||||||
return val, false, true
|
return val, false, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k Keeper) setActivatedTACounter(ctx sdk.Context, counter uint64) {
|
||||||
|
taCounterStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.TAIndexKey))
|
||||||
|
bz := make([]byte, 8)
|
||||||
|
binary.BigEndian.PutUint64(bz, counter)
|
||||||
|
taCounterStore.Set([]byte(types.ActivatedTACounterKey), bz)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k Keeper) GetActivatedTACounter(ctx sdk.Context) (counter uint64) {
|
||||||
|
taCounterStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.TAIndexKey))
|
||||||
|
bz := taCounterStore.Get([]byte(types.ActivatedTACounterKey))
|
||||||
|
if bz == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
counter = binary.BigEndian.Uint64(bz)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@ -69,3 +69,11 @@ func TestUpdateTrustAnchor(t *testing.T) {
|
|||||||
assert.True(t, activated)
|
assert.True(t, activated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestActivatedTACounter(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
keeper, ctx := keepertest.MachineKeeper(t)
|
||||||
|
createNTrustAnchor(t, keeper, ctx, 100)
|
||||||
|
counter := keeper.GetActivatedTACounter(ctx)
|
||||||
|
assert.Equal(t, uint64(50), counter)
|
||||||
|
}
|
||||||
|
|||||||
@ -28,6 +28,8 @@ const (
|
|||||||
LiquidAssetKey = "Machine/LiquidAsset/"
|
LiquidAssetKey = "Machine/LiquidAsset/"
|
||||||
|
|
||||||
ParamsKey = "Machine/Params"
|
ParamsKey = "Machine/Params"
|
||||||
|
|
||||||
|
ActivatedTACounterKey = "ActivatedTACounter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func KeyPrefix(p string) []byte {
|
func KeyPrefix(p string) []byte {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user