mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-19 21:36:43 +00:00

* Added option to choose from address in kaspawallet + fixed a bug with 0 change * Checking if From is missing * Fixed after merge to kaspad0.12 * Applying changes also to send command * Better help description * Fixed bug where we take all utxos except the one we wanted * Swallow the parsing error only when we want to filter * checking for wallet address directly * go fmt * Changing to `--from-address` Co-authored-by: Ori Newman <orinewman1@gmail.com>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/keys"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func send(conf *sendConfig) error {
|
|
keysFile, err := keys.ReadKeysFile(conf.NetParams(), conf.KeysFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(keysFile.ExtendedPublicKeys) > len(keysFile.EncryptedMnemonics) {
|
|
return errors.Errorf("Cannot use 'send' command for multisig wallet without all of the keys")
|
|
}
|
|
|
|
daemonClient, tearDown, err := client.Connect(conf.DaemonAddress)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer tearDown()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout)
|
|
defer cancel()
|
|
|
|
sendAmountSompi := uint64(conf.SendAmount * constants.SompiPerKaspa)
|
|
|
|
createUnsignedTransactionsResponse, err :=
|
|
daemonClient.CreateUnsignedTransactions(ctx, &pb.CreateUnsignedTransactionsRequest{
|
|
From: conf.FromAddresses,
|
|
Address: conf.ToAddress,
|
|
Amount: sendAmountSompi,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(conf.Password) == 0 {
|
|
conf.Password = keys.GetPassword("Password:")
|
|
}
|
|
mnemonics, err := keysFile.DecryptMnemonics(conf.Password)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signedTransactions := make([][]byte, len(createUnsignedTransactionsResponse.UnsignedTransactions))
|
|
for i, unsignedTransaction := range createUnsignedTransactionsResponse.UnsignedTransactions {
|
|
signedTransaction, err := libkaspawallet.Sign(conf.NetParams(), mnemonics, unsignedTransaction, keysFile.ECDSA)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
signedTransactions[i] = signedTransaction
|
|
}
|
|
|
|
if len(signedTransactions) > 1 {
|
|
fmt.Printf("Broadcasting %d transactions\n", len(signedTransactions))
|
|
}
|
|
|
|
response, err := daemonClient.Broadcast(ctx, &pb.BroadcastRequest{Transactions: signedTransactions})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println("Transactions were sent successfully")
|
|
fmt.Println("Transaction ID(s): ")
|
|
for _, txID := range response.TxIDs {
|
|
fmt.Printf("\t%s\n", txID)
|
|
}
|
|
|
|
return nil
|
|
}
|