From 36aa7fc93d48485d936b9f866dc1d7cec69a8f43 Mon Sep 17 00:00:00 2001 From: Lazy Nina <> Date: Wed, 20 Dec 2023 13:47:00 -0500 Subject: [PATCH] Add extra data to max spend and diamond txn construction --- lib/block_view_post_test.go | 1 + lib/blockchain.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/block_view_post_test.go b/lib/block_view_post_test.go index 7ed0e83be..d43e11330 100644 --- a/lib/block_view_post_test.go +++ b/lib/block_view_post_test.go @@ -146,6 +146,7 @@ func _giveDeSoDiamonds(t *testing.T, chain *Blockchain, db *badger.DB, params *D senderPkBytes, diamondPostHash, diamondLevel, + nil, feeRateNanosPerKB, nil, []*DeSoOutput{}) diff --git a/lib/blockchain.go b/lib/blockchain.go index c3953f420..d1d0f7633 100644 --- a/lib/blockchain.go +++ b/lib/blockchain.go @@ -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) { @@ -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. @@ -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) { @@ -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