mirror of
https://github.com/luxfi/platformvm.git
synced 2026-10-30 15:22:12 +00:00
- Drop atomic_block.go + legacy *_block_test.go (consolidated) - Add block/v0/ subdir + lift_v0.go for old version handling - Copyright header: 'Lux Industries, Inc.' → 'Lux Industries Inc' (no comma) - block_adapter.go: new adapter layer
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package state
|
|
|
|
import (
|
|
"github.com/luxfi/database"
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
type delegatorMetadata struct {
|
|
PotentialReward uint64 `serialize:"true"`
|
|
StakerStartTime uint64 `serialize:"true"`
|
|
|
|
txID ids.ID
|
|
}
|
|
|
|
func parseDelegatorMetadata(bytes []byte, metadata *delegatorMetadata) error {
|
|
var err error
|
|
switch len(bytes) {
|
|
case database.Uint64Size:
|
|
// only potential reward was stored
|
|
metadata.PotentialReward, err = database.ParseUInt64(bytes)
|
|
default:
|
|
_, err = MetadataCodec.Unmarshal(bytes, metadata)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func writeDelegatorMetadata(db database.KeyValueWriter, metadata *delegatorMetadata, codecVersion uint16) error {
|
|
// The "0" codec is skipped for [delegatorMetadata]. This is to ensure the
|
|
// [validatorMetadata] codec version is the same as the [delegatorMetadata]
|
|
// codec version.
|
|
//
|
|
if codecVersion == 0 {
|
|
return database.PutUInt64(db, metadata.txID[:], metadata.PotentialReward)
|
|
}
|
|
metadataBytes, err := MetadataCodec.Marshal(codecVersion, metadata)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return db.Put(metadata.txID[:], metadataBytes)
|
|
}
|