mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* Add fee estimation to wallet * Add fee rate to kaspawallet parse * Update go version * Get rid of golint * Add RBF support to wallet * Fix bump_fee UTXO lookup and fix wrong change address * impl storage mass as per KIP9 * Use CalculateTransactionOverallMass where needed * Some fixes * Minor typos * Fix test * update version * BroadcastRBF -> BroadcastReplacement * rc3 * align proto files to only use camel case (fixed on RK as well) * Rename to FeePolicy and add MaxFee option + todo * apply max fee constrains * increase minChangeTarget to 10kas * fmt * Some fixes * fix description: maximum -> minimum * put min feerate check in the correct location * Fix calculateFeeLimits nil handling * Add validations to CLI flags * Change to rc6 * Add checkTransactionFeeRate * Add failed broadcast transactions on send error` * Fix estimateFee change value * Estimate fee correctly for --send-all * On estimateFee always assume that the recipient has ECDSA address * remove patch version --------- Co-authored-by: Michael Sutton <msutton@cs.huji.ac.il>
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/kaspanet/kaspad/app/appmessage"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet/serialization"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/rpcclient"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (s *server) BroadcastReplacement(_ context.Context, request *pb.BroadcastRequest) (*pb.BroadcastResponse, error) {
|
|
s.lock.Lock()
|
|
defer s.lock.Unlock()
|
|
|
|
txIDs, err := s.broadcastReplacement(request.Transactions, request.IsDomain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &pb.BroadcastResponse{TxIDs: txIDs}, nil
|
|
}
|
|
|
|
// broadcastReplacement assumes that all transactions depend on the first one
|
|
func (s *server) broadcastReplacement(transactions [][]byte, isDomain bool) ([]string, error) {
|
|
|
|
txIDs := make([]string, len(transactions))
|
|
var tx *externalapi.DomainTransaction
|
|
var err error
|
|
|
|
for i, transaction := range transactions {
|
|
|
|
if isDomain {
|
|
tx, err = serialization.DeserializeDomainTransaction(transaction)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
} else if !isDomain { //default in proto3 is false
|
|
tx, err = libkaspawallet.ExtractTransaction(transaction, s.keysFile.ECDSA)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// Once the first transaction is added to the mempool, the transactions that depend
|
|
// on the replaced transaction will be removed, so there's no need to submit them
|
|
// as RBF transactions.
|
|
if i == 0 {
|
|
txIDs[i], err = sendTransactionRBF(s.rpcClient, tx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
txIDs[i], err = sendTransaction(s.rpcClient, tx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
}
|
|
|
|
for _, input := range tx.Inputs {
|
|
s.usedOutpoints[input.PreviousOutpoint] = time.Now()
|
|
}
|
|
}
|
|
|
|
s.forceSync()
|
|
return txIDs, nil
|
|
}
|
|
|
|
func sendTransactionRBF(client *rpcclient.RPCClient, tx *externalapi.DomainTransaction) (string, error) {
|
|
submitTransactionResponse, err := client.SubmitTransactionReplacement(appmessage.DomainTransactionToRPCTransaction(tx), consensushashing.TransactionID(tx).String())
|
|
if err != nil {
|
|
return "", errors.Wrapf(err, "error submitting transaction replacement")
|
|
}
|
|
return submitTransactionResponse.TransactionID, nil
|
|
}
|