Skip to content
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

Merged
merged 12 commits into from
Apr 27, 2022

Conversation

tmrlvi
Copy link
Contributor

@tmrlvi 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)

@tmrlvi
Copy link
Contributor Author

tmrlvi commented Mar 3, 2022

This solves Issue #1957

@codecov
Copy link

codecov bot commented Mar 6, 2022

Codecov Report

Merging #1964 (9ba4013) into dev (8d5faee) will decrease coverage by 0.05%.
The diff coverage is 0.00%.

@@            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     
Impacted Files Coverage Δ
cmd/kaspawallet/config.go 0.00% <ø> (ø)
cmd/kaspawallet/create_unsigned_tx.go 0.00% <0.00%> (ø)
...allet/daemon/server/create_unsigned_transaction.go 0.00% <0.00%> (ø)
cmd/kaspawallet/daemon/server/send.go 0.00% <0.00%> (ø)
cmd/kaspawallet/send.go 0.00% <0.00%> (ø)
...consensus/database/serialization/acceptancedata.go 42.85% <0.00%> (-36.74%) ⬇️
...tures/acceptancedatastore/acceptance_data_store.go 53.65% <0.00%> (-19.52%) ⬇️
infrastructure/network/addressmanager/store.go 77.84% <0.00%> (-1.27%) ⬇️
infrastructure/network/rpcclient/rpcclient.go 62.92% <0.00%> (+2.24%) ⬆️
...rver/grpcserver/protowire/rpc_get_mempool_entry.go 72.72% <0.00%> (+6.06%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d5faee...9ba4013. Read the comment docs.

Copy link
Collaborator

@someone235 someone235 left a 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
Copy link
Collaborator

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

@@ -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"`
Copy link
Collaborator

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()) ||
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@tmrlvi
Copy link
Contributor Author

tmrlvi commented Apr 15, 2022

I've updated the coded with changes to FromAddresses (plural)
I'm still testing (don't merge yet)

@tmrlvi
Copy link
Contributor Author

tmrlvi commented Apr 15, 2022

Fixed and tested

@tmrlvi
Copy link
Contributor Author

tmrlvi commented Apr 15, 2022

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):

  1. Use go-flags native option for multiple values (repeating flags)
  2. Implement custom parser for go-flags (as described in https://stackoverflow.com/a/28323276/3051715)

Do you think we should change the parsing, or is the way it is written now ok?

@tmrlvi tmrlvi requested a review from someone235 April 17, 2022 09:51
@@ -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)) ||
Copy link
Collaborator

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!

@someone235
Copy link
Collaborator

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):

  1. Use go-flags native option for multiple values (repeating flags)
  2. Implement custom parser for go-flags (as described in https://stackoverflow.com/a/28323276/3051715)

Do you think we should change the parsing, or is the way it is written now ok?

I think it's better to stick with the go-flags standard

@tmrlvi
Copy link
Contributor Author

tmrlvi commented Apr 26, 2022

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):

  1. Use go-flags native option for multiple values (repeating flags)
  2. Implement custom parser for go-flags (as described in https://stackoverflow.com/a/28323276/3051715)

Do you think we should change the parsing, or is the way it is written now ok?

I think it's better to stick with the go-flags standard

Ok, so I'm changing --from-addresses to --from-address, and allow for multiple uses. Example:

./kaspawallet create-unsigned-transaction -a <from_addr_1> -a <from_addr_2> -t <to_addr> -v <value>

@someone235 someone235 merged commit 540b0d3 into kaspanet:dev Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants