mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 14:35:53 +00:00
Use one of the From addresses as a change address
This commit is contained in:
parent
7d44275eb1
commit
9ce6b2b187
@ -56,7 +56,7 @@ type sendConfig struct {
|
|||||||
Password string `long:"password" short:"p" description:"Wallet password"`
|
Password string `long:"password" short:"p" description:"Wallet password"`
|
||||||
DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"`
|
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"`
|
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"`
|
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)"`
|
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"`
|
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 {
|
type createUnsignedTransactionConfig struct {
|
||||||
DaemonAddress string `long:"daemonaddress" short:"d" description:"Wallet daemon server to connect to"`
|
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"`
|
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"`
|
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)"`
|
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
|
config.NetworkFlags
|
||||||
|
|||||||
@ -10,8 +10,12 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"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)
|
internalIndex := uint32(0)
|
||||||
|
var walletAddr *walletAddress
|
||||||
|
if len(fromAddresses) != 0 {
|
||||||
|
walletAddr = fromAddresses[0]
|
||||||
|
} else {
|
||||||
if !useFirst {
|
if !useFirst {
|
||||||
err := s.keysFile.SetLastUsedInternalIndex(s.keysFile.LastUsedInternalIndex() + 1)
|
err := s.keysFile.SetLastUsedInternalIndex(s.keysFile.LastUsedInternalIndex() + 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -26,11 +30,13 @@ func (s *server) changeAddress(useFirst bool) (util.Address, *walletAddress, err
|
|||||||
internalIndex = s.keysFile.LastUsedInternalIndex()
|
internalIndex = s.keysFile.LastUsedInternalIndex()
|
||||||
}
|
}
|
||||||
|
|
||||||
walletAddr := &walletAddress{
|
walletAddr = &walletAddress{
|
||||||
index: internalIndex,
|
index: internalIndex,
|
||||||
cosignerIndex: s.keysFile.CosignerIndex,
|
cosignerIndex: s.keysFile.CosignerIndex,
|
||||||
keyChain: libkaspawallet.InternalKeychain,
|
keyChain: libkaspawallet.InternalKeychain,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
path := s.walletAddressPath(walletAddr)
|
path := s.walletAddressPath(walletAddr)
|
||||||
address, err := libkaspawallet.Address(s.params, s.keysFile.ExtendedPublicKeys, s.keysFile.MinimumSignatures, path, s.keysFile.ECDSA)
|
address, err := libkaspawallet.Address(s.params, s.keysFile.ExtendedPublicKeys, s.keysFile.MinimumSignatures, path, s.keysFile.ECDSA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -61,7 +61,7 @@ func (s *server) createUnsignedTransactions(address string, amount uint64, fromA
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
changeAddress, changeWalletAddress, err := s.changeAddress(useExistingChangeAddress)
|
changeAddress, changeWalletAddress, err := s.changeAddress(useExistingChangeAddress, fromAddresses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user