mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-29 08:28:50 +00:00
Implemented mempoolUTXOSet.addTransaction
This commit is contained in:
parent
099f023b5b
commit
d88fe305c5
@ -2,7 +2,9 @@ package mempool
|
||||
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/utxo"
|
||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool/model"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type mempoolUTXOSet struct {
|
||||
@ -37,7 +39,34 @@ func (mpus *mempoolUTXOSet) getParentsInPool(transaction *model.MempoolTransacti
|
||||
}
|
||||
|
||||
func (mpus *mempoolUTXOSet) addTransaction(transaction *model.MempoolTransaction) error {
|
||||
panic("mempoolUTXOSet.addTransaction not implemented") // TODO (Mike)
|
||||
outpoint := &externalapi.DomainOutpoint{TransactionID: *transaction.TransactionID()}
|
||||
|
||||
for i, input := range transaction.Transaction.Inputs {
|
||||
outpoint.Index = uint32(i)
|
||||
|
||||
// Sanity check for consistency
|
||||
if existingTx, exists := mpus.transactionsByPreviousOutpoint[input.PreviousOutpoint]; exists {
|
||||
return errors.Errorf("outpoint %s is already used by %s",
|
||||
input.PreviousOutpoint, existingTx.TransactionID())
|
||||
}
|
||||
|
||||
delete(mpus.poolUnspentOutputs, *outpoint)
|
||||
mpus.transactionsByPreviousOutpoint[input.PreviousOutpoint] = transaction
|
||||
}
|
||||
|
||||
for i, output := range transaction.Transaction.Outputs {
|
||||
outpoint := externalapi.DomainOutpoint{TransactionID: *transaction.TransactionID(), Index: uint32(i)}
|
||||
|
||||
// Sanity check for consistency
|
||||
if _, exists := mpus.poolUnspentOutputs[outpoint]; exists {
|
||||
return errors.Errorf("outpoint %s already exists", outpoint)
|
||||
}
|
||||
|
||||
mpus.poolUnspentOutputs[outpoint] =
|
||||
utxo.NewUTXOEntry(output.Value, output.ScriptPublicKey, false, model.UnacceptedDAAScore)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mpus *mempoolUTXOSet) removeTransaction(transactionID *externalapi.DomainTransactionID) error {
|
||||
|
||||
6
domain/miningmanager/mempool/model/constants.go
Normal file
6
domain/miningmanager/mempool/model/constants.go
Normal file
@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
import "math"
|
||||
|
||||
// UnacceptedDAAScore is used to for UTXOEntries that were created by transactions in the mempool.
|
||||
const UnacceptedDAAScore = math.MaxUint64
|
||||
Loading…
x
Reference in New Issue
Block a user