Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add yield amount base units state change metadata to connect coin lockup #1426

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/block_view_lockups.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,9 @@ func (bav *UtxoView) _connectCoinLockup(
PrevLockedBalanceEntries: previousLockedBalanceEntries,
SetLockedBalanceEntries: setLockedBalanceEntries,
PrevCoinEntry: prevCoinEntry,
StateChangeMetadata: &CoinLockupStateChangeMetadata{
YieldAmountBaseUnits: yieldFromTxn,
},
})

// Construct UtxoOps in the event this transaction is reverted.
Expand Down
29 changes: 29 additions & 0 deletions lib/state_change_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"bytes"
"github.com/deso-protocol/core/collections"
"github.com/deso-protocol/uint256"
"github.com/pkg/errors"
)

Expand All @@ -25,6 +26,7 @@ const (
EncoderTypeStakeRewardStateChangeMetadata EncoderType = 2000015
EncoderTypeUnjailValidatorStateChangeMetadata EncoderType = 2000016
EncoderTypeUnregisterAsValidatorStateChangeMetadata EncoderType = 2000017
EncoderTypeCoinLockupStateChangeMetadata EncoderType = 2000018
)

func GetStateChangeMetadataFromOpType(opType OperationType) DeSoEncoder {
Expand Down Expand Up @@ -692,3 +694,30 @@ func (metadata *UnregisterAsValidatorStateChangeMetadata) GetVersionByte(blockHe
func (metadata *UnregisterAsValidatorStateChangeMetadata) GetEncoderType() EncoderType {
return EncoderTypeUnregisterAsValidatorStateChangeMetadata
}

type CoinLockupStateChangeMetadata struct {
YieldAmountBaseUnits *uint256.Int
}

func (metadata *CoinLockupStateChangeMetadata) RawEncodeWithoutMetadata(blockHeight uint64, skipMetadata ...bool) []byte {
var data []byte
data = append(data, VariableEncodeUint256(metadata.YieldAmountBaseUnits)...)
return data
}

func (metadata *CoinLockupStateChangeMetadata) RawDecodeWithoutMetadata(blockHeight uint64, rr *bytes.Reader) error {
var err error
metadata.YieldAmountBaseUnits, err = VariableDecodeUint256(rr)
if err != nil {
return errors.Wrapf(err, "CoinLockupStateChangeMetadata.Decode: Problem reading YieldAmountBaseUnits")
}
return nil
}

func (metadata *CoinLockupStateChangeMetadata) GetVersionByte(blockHeight uint64) byte {
return 0
}

func (metadata *CoinLockupStateChangeMetadata) GetEncoderType() EncoderType {
return EncoderTypeCoinLockupStateChangeMetadata
}
Loading