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

Wallet: better error for send() if no outputs given #664

Merged
merged 2 commits into from
Mar 1, 2019

Conversation

pinheadmz
Copy link
Member

If you try to wallet.send() with an empty outputs array, the error you currently get is:
No outputs available.

This was confusing me because I thought the wallet was unable to find any coins to spend, like it had a zero balance or coinbase outputs were not mature yet.

This PR changes that error to At least one output required. which indicates to the user/developer more specifically which output is missing.

@tynes
Copy link
Member

tynes commented Jan 18, 2019

Good change. I agree with this

@pinheadmz pinheadmz added quick Can be fixed quickly, code change less than 10 lines logs / errors Better feedback to user or prevent user error labels Jan 23, 2019
@braydonf braydonf added the wallet Wallet related label Feb 6, 2019
Copy link
Collaborator

@BluSyn BluSyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@braydonf
Copy link
Contributor

braydonf commented Mar 1, 2019

Okay, that is more clear.

While testing, also got this message as a result of a missing address (slightly incorrect):

./bin/bwallet-cli --network=regtest send 
Error: Output is dust.
    at WalletClient.request (/home/bgf/c/bcoin/bcoin/node_modules/bcurl/lib/client.js:213:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)

It also looks like lib/wallet/wallet isn't used in any tests, only lib/wallet/walletdb.

Here is a test case after adding const Wallet = require('../lib/wallet/wallet'); to test/wallet-test.js:

it('should throw error with missing outputs', async () => {
  const wallet = new Wallet({});

  let err = null;

  try {
     await wallet.send({outputs: []});
  } catch (e) {
    err = e;  
 }

  assert(err);
  assert.equal(err.message, 'At least one output required.')
});

@braydonf
Copy link
Contributor

braydonf commented Mar 1, 2019

nit: commit message is without wallet: prefix

@pinheadmz
Copy link
Member Author

nit addressed and test added. Re: output is dust, I think that makes sense, the first thing it's checking after the basic shape of the input object is the value of the first output, which in your example is null and probably cast to 0

@codecov-io

This comment has been minimized.

@braydonf braydonf merged commit e40e1c2 into bcoin-org:master Mar 1, 2019
braydonf added a commit that referenced this pull request Mar 1, 2019
Wallet: better error for send() if no outputs given
@braydonf braydonf added this to the 2.0.0 milestone Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logs / errors Better feedback to user or prevent user error quick Can be fixed quickly, code change less than 10 lines wallet Wallet related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants