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>
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/server"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/keys"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func sign(conf *signConfig) error {
|
|
if conf.Transaction == "" && conf.TransactionFile == "" {
|
|
return errors.Errorf("Either --transaction or --transaction-file is required")
|
|
}
|
|
if conf.Transaction != "" && conf.TransactionFile != "" {
|
|
return errors.Errorf("Both --transaction and --transaction-file cannot be passed at the same time")
|
|
}
|
|
|
|
keysFile, err := keys.ReadKeysFile(conf.NetParams(), conf.KeysFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(conf.Password) == 0 {
|
|
conf.Password = keys.GetPassword("Password:")
|
|
}
|
|
privateKeys, err := keysFile.DecryptMnemonics(conf.Password)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
transactionsHex := conf.Transaction
|
|
if conf.TransactionFile != "" {
|
|
transactionHexBytes, err := ioutil.ReadFile(conf.TransactionFile)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "Could not read hex from %s", conf.TransactionFile)
|
|
}
|
|
transactionsHex = strings.TrimSpace(string(transactionHexBytes))
|
|
}
|
|
partiallySignedTransactions, err := server.DecodeTransactionsFromHex(transactionsHex)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
updatedPartiallySignedTransactions := make([][]byte, len(partiallySignedTransactions))
|
|
for i, partiallySignedTransaction := range partiallySignedTransactions {
|
|
updatedPartiallySignedTransactions[i], err =
|
|
libkaspawallet.Sign(conf.NetParams(), privateKeys, partiallySignedTransaction, keysFile.ECDSA)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
areAllTransactionsFullySigned := true
|
|
for _, updatedPartiallySignedTransaction := range updatedPartiallySignedTransactions {
|
|
// This is somewhat redundant to check all transactions, but we do that just-in-case
|
|
isFullySigned, err := libkaspawallet.IsTransactionFullySigned(updatedPartiallySignedTransaction)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !isFullySigned {
|
|
areAllTransactionsFullySigned = false
|
|
}
|
|
}
|
|
|
|
if areAllTransactionsFullySigned {
|
|
fmt.Fprintln(os.Stderr, "The transaction is signed and ready to broadcast")
|
|
} else {
|
|
fmt.Fprintln(os.Stderr, "Successfully signed transaction")
|
|
}
|
|
|
|
fmt.Println(server.EncodeTransactionsToHex(updatedPartiallySignedTransactions))
|
|
return nil
|
|
}
|