diff --git a/cmd/kaspawallet/config.go b/cmd/kaspawallet/config.go index ec3c8b83c..6d136741b 100644 --- a/cmd/kaspawallet/config.go +++ b/cmd/kaspawallet/config.go @@ -56,7 +56,7 @@ type sendConfig struct { Password string `long:"password" short:"p" description:"Wallet password"` DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"` ToAddress string `long:"to-address" short:"t" description:"The public address to send Kaspa to" required:"true"` - FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Kaspa from. Use multiple times to accept several addresses" required:"false"` + FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Kaspa from. Use multiple times to accept several addresses (Note: using this flag will send the change to one of the provided addresses)" required:"false"` SendAmount float64 `long:"send-amount" short:"v" description:"An amount to send in Kaspa (e.g. 1234.12345678)" required:"true"` UseExistingChangeAddress bool `long:"use-existing-change-address" short:"u" description:"Will use an existing change address (in case no change address was ever used, it will use a new one)"` Verbose bool `long:"show-serialized" short:"s" description:"Show a list of hex encoded sent transactions"` @@ -72,7 +72,7 @@ type sweepConfig struct { type createUnsignedTransactionConfig struct { DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"` ToAddress string `long:"to-address" short:"t" description:"The public address to send Kaspa to" required:"true"` - FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Kaspa from. Use multiple times to accept several addresses" required:"false"` + FromAddresses []string `long:"from-address" short:"a" description:"Specific public address to send Kaspa from. Use multiple times to accept several addresses (Note: using this flag will send the change to one of the provided addresses)" required:"false"` SendAmount float64 `long:"send-amount" short:"v" description:"An amount to send in Kaspa (e.g. 1234.12345678)" required:"true"` UseExistingChangeAddress bool `long:"use-existing-change-address" short:"u" description:"Will use an existing change address (in case no change address was ever used, it will use a new one)"` config.NetworkFlags diff --git a/cmd/kaspawallet/daemon/server/address.go b/cmd/kaspawallet/daemon/server/address.go index d26ca3107..991753871 100644 --- a/cmd/kaspawallet/daemon/server/address.go +++ b/cmd/kaspawallet/daemon/server/address.go @@ -10,27 +10,33 @@ import ( "github.com/pkg/errors" ) -func (s *server) changeAddress(useFirst bool) (util.Address, *walletAddress, error) { +func (s *server) changeAddress(useFirst bool, fromAddresses []*walletAddress) (util.Address, *walletAddress, error) { internalIndex := uint32(0) - if !useFirst { - err := s.keysFile.SetLastUsedInternalIndex(s.keysFile.LastUsedInternalIndex() + 1) - if err != nil { - return nil, nil, err + var walletAddr *walletAddress + if len(fromAddresses) != 0 { + walletAddr = fromAddresses[0] + } else { + if !useFirst { + err := s.keysFile.SetLastUsedInternalIndex(s.keysFile.LastUsedInternalIndex() + 1) + if err != nil { + return nil, nil, err + } + + err = s.keysFile.Save() + if err != nil { + return nil, nil, err + } + + internalIndex = s.keysFile.LastUsedInternalIndex() } - err = s.keysFile.Save() - if err != nil { - return nil, nil, err + walletAddr = &walletAddress{ + index: internalIndex, + cosignerIndex: s.keysFile.CosignerIndex, + keyChain: libkaspawallet.InternalKeychain, } - - internalIndex = s.keysFile.LastUsedInternalIndex() } - walletAddr := &walletAddress{ - index: internalIndex, - cosignerIndex: s.keysFile.CosignerIndex, - keyChain: libkaspawallet.InternalKeychain, - } path := s.walletAddressPath(walletAddr) address, err := libkaspawallet.Address(s.params, s.keysFile.ExtendedPublicKeys, s.keysFile.MinimumSignatures, path, s.keysFile.ECDSA) if err != nil { diff --git a/cmd/kaspawallet/daemon/server/create_unsigned_transaction.go b/cmd/kaspawallet/daemon/server/create_unsigned_transaction.go index 212812b4d..13ff6a955 100644 --- a/cmd/kaspawallet/daemon/server/create_unsigned_transaction.go +++ b/cmd/kaspawallet/daemon/server/create_unsigned_transaction.go @@ -61,7 +61,7 @@ func (s *server) createUnsignedTransactions(address string, amount uint64, fromA return nil, err } - changeAddress, changeWalletAddress, err := s.changeAddress(useExistingChangeAddress) + changeAddress, changeWalletAddress, err := s.changeAddress(useExistingChangeAddress, fromAddresses) if err != nil { return nil, err }