Skip to content

Commit

Permalink
PoS Add RestakeRewards flag to TxnTypeStake
Browse files Browse the repository at this point in the history
  • Loading branch information
tholonious committed Jul 11, 2023
1 parent 24f73b6 commit cbb4f06
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/block_view_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
type StakeEntry struct {
StakerPKID *PKID
ValidatorPKID *PKID
RestakeRewards bool
StakeAmountNanos *uint256.Int
ExtraData map[string][]byte
isDeleted bool
Expand All @@ -49,6 +50,7 @@ func (stakeEntry *StakeEntry) Copy() *StakeEntry {
return &StakeEntry{
StakerPKID: stakeEntry.StakerPKID.NewPKID(),
ValidatorPKID: stakeEntry.ValidatorPKID.NewPKID(),
RestakeRewards: stakeEntry.RestakeRewards,
StakeAmountNanos: stakeEntry.StakeAmountNanos.Clone(),
ExtraData: copyExtraData(stakeEntry.ExtraData),
isDeleted: stakeEntry.isDeleted,
Expand All @@ -70,6 +72,7 @@ func (stakeEntry *StakeEntry) RawEncodeWithoutMetadata(blockHeight uint64, skipM
var data []byte
data = append(data, EncodeToBytes(blockHeight, stakeEntry.StakerPKID, skipMetadata...)...)
data = append(data, EncodeToBytes(blockHeight, stakeEntry.ValidatorPKID, skipMetadata...)...)
data = append(data, BoolToByte(stakeEntry.RestakeRewards))
data = append(data, VariableEncodeUint256(stakeEntry.StakeAmountNanos)...)
data = append(data, EncodeExtraData(stakeEntry.ExtraData)...)
return data
Expand All @@ -90,6 +93,12 @@ func (stakeEntry *StakeEntry) RawDecodeWithoutMetadata(blockHeight uint64, rr *b
return errors.Wrapf(err, "StakeEntry.Decode: Problem reading ValidatorPKID: ")
}

// RestakeRewards
stakeEntry.RestakeRewards, err = ReadBoolByte(rr)
if err != nil {
return errors.Wrapf(err, "StakeEntry.Decode: Problem reading RestakeRewards")
}

// StakeAmountNanos
stakeEntry.StakeAmountNanos, err = VariableDecodeUint256(rr)
if err != nil {
Expand Down Expand Up @@ -215,6 +224,7 @@ func (lockedStakeEntry *LockedStakeEntry) GetEncoderType() EncoderType {

type StakeMetadata struct {
ValidatorPublicKey *PublicKey
RestakeRewards bool
StakeAmountNanos *uint256.Int
}

Expand All @@ -225,6 +235,7 @@ func (txnData *StakeMetadata) GetTxnType() TxnType {
func (txnData *StakeMetadata) ToBytes(preSignature bool) ([]byte, error) {
var data []byte
data = append(data, EncodeByteArray(txnData.ValidatorPublicKey.ToBytes())...)
data = append(data, BoolToByte(txnData.RestakeRewards))
data = append(data, VariableEncodeUint256(txnData.StakeAmountNanos)...)
return data, nil
}
Expand All @@ -239,6 +250,12 @@ func (txnData *StakeMetadata) FromBytes(data []byte) error {
}
txnData.ValidatorPublicKey = NewPublicKey(validatorPublicKeyBytes)

// RestakeRewards
txnData.RestakeRewards, err = ReadBoolByte(rr)
if err != nil {
return errors.Wrapf(err, "StakeMetadata.FromBytes: Problem reading RestakeRewards: ")
}

// StakeAmountNanos
txnData.StakeAmountNanos, err = VariableDecodeUint256(rr)
if err != nil {
Expand Down Expand Up @@ -353,13 +370,15 @@ func (txnData *UnlockStakeMetadata) New() DeSoTxnMetadata {
type StakeTxindexMetadata struct {
StakerPublicKeyBase58Check string
ValidatorPublicKeyBase58Check string
RestakeRewards bool
StakeAmountNanos *uint256.Int
}

func (txindexMetadata *StakeTxindexMetadata) RawEncodeWithoutMetadata(blockHeight uint64, skipMetadata ...bool) []byte {
var data []byte
data = append(data, EncodeByteArray([]byte(txindexMetadata.StakerPublicKeyBase58Check))...)
data = append(data, EncodeByteArray([]byte(txindexMetadata.ValidatorPublicKeyBase58Check))...)
data = append(data, BoolToByte(txindexMetadata.RestakeRewards))
data = append(data, VariableEncodeUint256(txindexMetadata.StakeAmountNanos)...)
return data
}
Expand All @@ -381,6 +400,12 @@ func (txindexMetadata *StakeTxindexMetadata) RawDecodeWithoutMetadata(blockHeigh
}
txindexMetadata.ValidatorPublicKeyBase58Check = string(validatorPublicKeyBase58CheckBytes)

// RestakeRewards
txindexMetadata.RestakeRewards, err = ReadBoolByte(rr)
if err != nil {
return errors.Wrapf(err, "StakeTxindexMetadata.Decode: Problem reading RestakeRewards: ")
}

// StakeAmountNanos
txindexMetadata.StakeAmountNanos, err = VariableDecodeUint256(rr)
if err != nil {
Expand Down Expand Up @@ -1202,6 +1227,7 @@ func (bav *UtxoView) _connectStake(
currentStakeEntry := &StakeEntry{
StakerPKID: transactorPKIDEntry.PKID,
ValidatorPKID: prevValidatorEntry.ValidatorPKID,
RestakeRewards: txMeta.RestakeRewards,
StakeAmountNanos: stakeAmountNanos,
ExtraData: mergeExtraData(prevExtraData, txn.ExtraData),
}
Expand Down

0 comments on commit cbb4f06

Please sign in to comment.