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 extra data to max spend and diamond txn construction #883

Merged
Merged
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
1 change: 1 addition & 0 deletions lib/block_view_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func _giveDeSoDiamonds(t *testing.T, chain *Blockchain, db *badger.DB, params *D
senderPkBytes,
diamondPostHash,
diamondLevel,
nil,
feeRateNanosPerKB,
nil,
[]*DeSoOutput{})
Expand Down
12 changes: 10 additions & 2 deletions lib/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4639,6 +4639,7 @@ func (bc *Blockchain) CreateBasicTransferTxnWithDiamonds(
SenderPublicKey []byte,
DiamondPostHash *BlockHash,
DiamondLevel int64,
ExtraData map[string][]byte,
// Standard transaction fields
minFeeRateNanosPerKB uint64, mempool *DeSoMempool, additionalOutputs []*DeSoOutput) (
_txn *MsgDeSoTxn, _totalInput uint64, _spendAmount uint64, _changeAmount uint64, _fees uint64, _err error) {
Expand Down Expand Up @@ -4688,11 +4689,14 @@ func (bc *Blockchain) CreateBasicTransferTxnWithDiamonds(
// This function does not compute a signature.
}

delete(ExtraData, DiamondLevelKey)
delete(ExtraData, DiamondPostHashKey)

// Make a map for the diamond extra data and add it.
diamondsExtraData := make(map[string][]byte)
diamondsExtraData[DiamondLevelKey] = IntToBuf(DiamondLevel)
diamondsExtraData[DiamondPostHashKey] = DiamondPostHash[:]
txn.ExtraData = diamondsExtraData
txn.ExtraData = mergeExtraData(ExtraData, diamondsExtraData)

// We don't need to make any tweaks to the amount because it's basically
// a standard "pay per kilobyte" transaction.
Expand All @@ -4718,7 +4722,7 @@ func (bc *Blockchain) CreateBasicTransferTxnWithDiamonds(
}

func (bc *Blockchain) CreateMaxSpend(
senderPkBytes []byte, recipientPkBytes []byte, minFeeRateNanosPerKB uint64,
senderPkBytes []byte, recipientPkBytes []byte, extraData map[string][]byte, minFeeRateNanosPerKB uint64,
mempool *DeSoMempool, additionalOutputs []*DeSoOutput) (
_txn *MsgDeSoTxn, _totalInputAdded uint64, _spendAmount uint64, _fee uint64, _err error) {

Expand All @@ -4736,6 +4740,10 @@ func (bc *Blockchain) CreateMaxSpend(
// This function does not compute a signature.
}

if len(extraData) > 0 {
txn.ExtraData = extraData
}

if bc.BlockTip().Height >= bc.params.ForkHeights.BalanceModelBlockHeight {
var utxoView *UtxoView
var err error
Expand Down
Loading