-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for from
address in kaspawallet send
#1964
Conversation
tmrlvi
commented
Mar 3, 2022
- Add an option to choose the from address in a transactions when sending KAS
- Do not use change address is change is 0 (transaction with 0 output is not accepted by kaspad anyway)
This solves Issue #1957 |
Codecov Report
@@ Coverage Diff @@
## dev #1964 +/- ##
==========================================
- Coverage 59.51% 59.45% -0.06%
==========================================
Files 675 675
Lines 32201 32213 +12
==========================================
- Hits 19165 19153 -12
- Misses 10276 10309 +33
+ Partials 2760 2751 -9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to what I wrote in the comments, I think it's better to wait for #1951 to be merged before merging this PR, so the compounded transaction will also be created only from the FromAddresses
.
@@ -28,9 +28,17 @@ func (s *server) CreateUnsignedTransaction(_ context.Context, request *pb.Create | |||
return nil, err | |||
} | |||
|
|||
var fromAddress util.Address = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The =nil
here is redundant
cmd/kaspawallet/config.go
Outdated
@@ -54,13 +54,15 @@ 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 (default: localhost:8082)"` | |||
ToAddress string `long:"to-address" short:"t" description:"The public address to send Kaspa to" required:"true"` | |||
FromAddress string `long:"from-address" short:"a" description:"Specific public address to send Kaspa from" required:"false"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not a big deal, I would prefer to directly implement it with multiple addresses (FromAddresses
)
@@ -68,7 +80,9 @@ func (s *server) selectUTXOs(spendAmount uint64, feePerInput uint64) ( | |||
} | |||
|
|||
for _, utxo := range s.utxosSortedByAmount { | |||
if !isUTXOSpendable(utxo, dagInfo.VirtualDAAScore, s.params.BlockCoinbaseMaturity) { | |||
addr, err := s.walletAddressString(utxo.address) | |||
if err != nil || (from != nil && addr != from.String()) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you swallow the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought to ignore invalid UTXOs (which cannot be formatted to address). Maybe a better approach would be to convert from
to walletAddress
type and explicitly throw an error if failing. I'll look into it
I've updated the coded with changes to |
Fixed and tested |
Discussion point: currently, I implement multiple addresses using comma, which make argument parsing a bit cumbersome. There are two option to make it better (that I can think of):
Do you think we should change the parsing, or is the way it is written now ok? |
@@ -83,7 +98,8 @@ func (s *server) selectUTXOs(spendAmount uint64, feePerInput uint64) ( | |||
} | |||
|
|||
for _, utxo := range s.utxosSortedByAmount { | |||
if !isUTXOSpendable(utxo, dagInfo.VirtualDAAScore, s.params.BlockCoinbaseMaturity) { | |||
if (fromAddresses != nil && !slices.Contains(fromAddresses, utxo.address)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! First use of generics in the codebase!
I think it's better to stick with the |
Ok, so I'm changing
|