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

Could not send, "Negative output" #24

Closed
vuminhquang opened this issue May 17, 2019 · 24 comments
Closed

Could not send, "Negative output" #24

vuminhquang opened this issue May 17, 2019 · 24 comments

Comments

@vuminhquang
Copy link

Hello KZen people,
I've have a wallet with 2 derivative addresses. When I do the transaction within these 2 addresses, there are no error.
However when I try to transfer BTC to an outside address, I got this error:
thread 'main' panicked at 'called Result::unwrap() on an Err value: Error("missing field result", line: 1, column: 122)', src/libcore/result.rs:xxx:xx
The command is:
image

Tried to take the raw transaction out and send it manually through https://testnet.smartbit.com.au/txs/pushtx, I got this error
PUSH TRANSACTION ERROR: 16: BAD-TXNS-VOUT-NEGATIVE
After decode the transaction, I found this in the output
{
"addresses": null,
"script": "001429dd1071596903f049574e8e1f8529e14a4a4737",
"script_type": "pay-to-witness-pubkey-hash",
"value": -10000
}
The whole raw is
000000000001011c65b37fa305ef8b4c4ccb9731c2b14aa7dc933acbf08e0dc845c5148c7ea8180000000000ffffffff02e8030000000000001976a91452db02dda5c812097c67307ee63c23c22ea955e288acf0d8ffffffffffff16001429dd1071596903f049574e8e1f8529e14a4a473702473044022065ef7a2f120198f4acb7048edf90d070622583149eeb38c5fecb9f669e669b6202200532d8662932be31ae2586364f8fb7862ac93d0464eb07599e518eb468f0f0830121036b3a6ead2e7617c155f39f2f1b9a8ec963c0fb0b3c46154ea1074fe14d4221bb00000000

Hope to hear from you soon :)

Thank you

@omershlo
Copy link
Contributor

Hi,

I think your problem might be that you are not waiting for enough confirmation between receiving and sending.
Try to start new wallet. receive btc. wait until your wallet show you a positive balance (not pending, us e -b to see balance). Once enough time passed try to send. let us know if you still get the error.

@vuminhquang
Copy link
Author

Hello @omershlo ,
Thank you for your fast response 👍 .
I'd checked, via the wallet and also via a neural site (blockcypher.com)
image
image

And still get the same error.
image

@omershlo
Copy link
Contributor

I will try to recreate it. Can you provide more details pleas?
the exact flow of commands you used maybe?
cc: @oleiba , if you saw it before.

@vuminhquang
Copy link
Author

Hello,
The steps were:
cli create-wallet
cli wallet -a //get address1
Got the address then go to a faucet, fund it. (Got 1 million satoshis)
cli wallet -a //add one more address
cli wallet send -t address1 amount 1000 satoshis //this done successfully
cli wallet send -t outside address
-> get negative output here

@vuminhquang
Copy link
Author

upload the wallet.data file for yor ease to recreate.
wallet.data.txt

@omershlo
Copy link
Contributor

what is the amount you sent to the outside address?
what are the balance and pending values at time of failed send?

@vuminhquang
Copy link
Author

I send only 10_000 satoshis outside, the total amount in the wallet is 1 million, though. The exact balance and pending value, I've did a screenshot from the privious comment. Pending value is 0 when do the transaction.

@omershlo
Copy link
Contributor

I got it!
even though you say the number are 1m and 10k in fact from the screenshots it looks that you had balance of 1340711 and you sent ALL: 1340711. Please make sure to always specify the amount you want to send and make sure you have enough for change.

@vuminhquang
Copy link
Author

vuminhquang commented May 17, 2019

Sorry my friend,
The last command used to send outside was:
./cli wallet send -t mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey -a 0.00001000
So the amount was specified.
To be sure, I've just run the command "cli wallet -b" again. You can see that 1340711 (it's around 1m, right) still in the pocket
image

Thus, I think that it's not the real problem we got.

@omershlo
Copy link
Contributor

omershlo commented May 17, 2019

my claim was that you have 1340711 in balance and you try to send all without considering the 0.0001 constant fee. You should try to send no more than balance - 0.0001BTC.
I might be wrong of-course. I will try to follow your steps.

@vuminhquang
Copy link
Author

You should try to send no more than balance - 0.0001BTC.

Sure, you can see in the last command, I set the amount only "-a 0.00001"

I will try to follow your steps.

Thank you, please help me. I attach the file wallet.data in previous comment. You can take it any time.

@omershlo
Copy link
Contributor

I managed to recreate. I will look into it and report when fixed.
Thank you very much!

@omershlo
Copy link
Contributor

I just remembered that this is probably a known old issue that the wallet was not able to do more than 1 transaction. I fixed it my branch: #18 (use legacy wallet and legacy send). Please make sure it works on this branch while I am deploying the fix to master

@vuminhquang
Copy link
Author

Hello,
I guess that these are the commands to use:
./cli create-wallet-legacy
./cli wallet-legacy -a
./cli wallet-legacy -b
./cli wallet-legacy send-legacy -t mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey -a 0.00001000

When I try (after delete wallet.data)
./cli create-wallet-legacy
Get this error
image

So, I put back wallet.data, and run
./cli wallet-legacy -b
./cli wallet-legacy send-legacy -t mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey -a 0.00001000
Then, the output's error
image

@omershlo
Copy link
Contributor

well, you are right. now I really don't have explanation, I will dive deep and let you know

@omershlo
Copy link
Contributor

omershlo commented May 18, 2019

meanwhile - try do it without sending a transaction to yourself

@omershlo
Copy link
Contributor

I pushed some fix to my branch. try it now

@omershlo
Copy link
Contributor

working?

@vuminhquang
Copy link
Author

vuminhquang commented May 18, 2019

Hello :),
Now we get the result printed out. Still get the error, seems that the tx is not sent
image

@omershlo
Copy link
Contributor

Try again

@vuminhquang
Copy link
Author

Not better
image

@omershlo
Copy link
Contributor

I started from scratch to make sure and followed your scenario {generate address A, receive to address, generate new address, send x to A, send x to outside address (I used the one you used)}.
using my branch with legacy - it works fine. please try again from scratch as well. Here is the transcript from my machine.
There is one problem when one of my calls to electrum returned the error you faced but calling it a second later worked. I am not sure why is that - maybe network issue between me and the server. I will need to understand it better but I think that the edge case that was discovered in this issue was solved (the problem was that we forgot to include the fee as part of the coin selection algorithm)

➜  gotham-client git:(gg18_v1) ./target/release/cli create-wallet-legacy
Network: [testnet], Creating wallet
(id: ecd0b44d-deef-412b-b01f-ec2bf6245d3f) Took: PT0.924541056S
Network: [testnet], Wallet saved to disk
Network: [testnet], Escrow initiated
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -a
Network: [testnet], Address: [tb1qgj6f2y808nu84vgjt49nsz96tpmmh3y6av7my6]
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
Network: [testnet], Balance: [balance: 0, pending: 1000000]
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
Network: [testnet], Balance: [balance: 1000000, pending: 0]
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -a
Network: [testnet], Address: [tb1qrf4dnf079rr3uleltfewnpnusnsc7rj2aagv6u]
➜  gotham-client git:(gg18_v1) RUST_BACKTRACE=1 ./target/release/cli wallet-legacy send-legacy -t tb1qrf4dnf079rr3uleltfewnpnusnsc7rj2aagv6u -a 0.0001
total selected : 1000000
 amount_satoshi : 10000
 fees : 10000
 result  : 980000
(id: ecd0b44d-deef-412b-b01f-ec2bf6245d3f) Took: PT1.226775308S
raw: "00000000000101d0d24a027ae1f1440800c01293b73e5a01f3b877b52bd055dd39adf8e6f8c0df0100000000ffffffff0210270000000000001600141a6ad9a5fe28c71e7f3f5a72e9867c84e18f0e4a20f40e0000000000160014588cbd58568fb325017996a526440a9d577ddc7002473044022076ab0a300f2f56a00a7bcc8cd6441e8c31af433bb6af71d4316fc824b0deb82702203f6e0c95b0288602fc86430de89d39d7548966b57b4f8e3cc1d746dd864e3fca01210245bdcaab0213826cffc412103a8bf359c63043aed55e754e119da77467f3e4ad00000000"
Network: [testnet], Sent 0.0001 BTC to address tb1qrf4dnf079rr3uleltfewnpnusnsc7rj2aagv6u. Transaction ID: ac539940bf33c0d301606c7cab12271c53327f9de605ece91331ed273712b5cf
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-1000000`, expected u64", line: 1, column: 76)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-1000000`, expected u64", line: 1, column: 76)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
Network: [testnet], Balance: [balance: 990000, pending: 0]
➜  gotham-client git:(gg18_v1) RUST_BACKTRACE=1 ./target/release/cli wallet-legacy send-legacy -t mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey -a 0.0001 
total selected : 990000
 amount_satoshi : 10000
 fees : 10000
 result  : 970000
(id: ecd0b44d-deef-412b-b01f-ec2bf6245d3f) Took: PT1.454316835S
(id: ecd0b44d-deef-412b-b01f-ec2bf6245d3f) Took: PT1.064589936S
raw: "00000000000102cfb5123727ed3113e9ec05e69d7f32531c2712ab7c6c6001d3c033bf409953ac0000000000ffffffffcfb5123727ed3113e9ec05e69d7f32531c2712ab7c6c6001d3c033bf409953ac0100000000ffffffff0210270000000000001976a91452db02dda5c812097c67307ee63c23c22ea955e288ac10cd0e000000000016001495e37ef14b24b48d200eb3f1d1a64ad4fd8095610247304402207c83dca46a3b495978f6707ed9100ea59e57cd6fda166ee91d3854b60b8d99620220064e8b0a4a1994f842e8bea95a6f6f549aa1980f47b0b62513d2192477e2348d012102d48ccac10c6aeddafb326576c272af30105051e007f7814dd56d7243da6b4b0a0247304402200d4a5e6c87ed4a556423767b1e46eafdda0ddeb3769c839875eac34cd6c04244022068167dbc2a65ea7aa5fd117ab05077aa9283cd80c89d2984f9c7fbc20a9b44ef0121034ec74f35774dc2e4b0d0d91109a6c312830e82e6fa1e736ca43acea240cab9a100000000"
Network: [testnet], Sent 0.0001 BTC to address mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey. Transaction ID: 5e52a06e87f04ff088d3a866c78159ad263254f9f0b53e803a91abd6ae5b7fe9
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-10000`, expected u64", line: 1, column: 72)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) cargo build --release                
   Compiling gotham-client v0.1.0 (/Users/omershlo/Downloads/from_github/gotham-city/gotham-client)
    Finished release [optimized] target(s) in 19.57s
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-10000`, expected u64", line: 1, column: 72)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-10000`, expected u64", line: 1, column: 72)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-10000`, expected u64", line: 1, column: 72)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
Network: [testnet], Balance: [balance: 970000, pending: 0]
➜  gotham-client git:(gg18_v1) RUST_BACKTRACE=1 ./target/release/cli wallet-legacy send-legacy -t mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey -a 0.0001
(id: ecd0b44d-deef-412b-b01f-ec2bf6245d3f) Took: PT1.204025821S
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("missing field `result`", line: 1, column: 189)', src/libcore/result.rs:997:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::continue_panic_fmt
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: client_lib::wallet::Wallet::send
  10: cli::main
  11: std::rt::lang_start::{{closure}}
  12: std::panicking::try::do_call
  13: __rust_maybe_catch_panic
  14: std::rt::lang_start_internal
  15: main
➜  gotham-client git:(gg18_v1) RUST_BACKTRACE=1 ./target/release/cli wallet-legacy send-legacy -t mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey -a 0.0001
(id: ecd0b44d-deef-412b-b01f-ec2bf6245d3f) Took: PT1.049966127S
Network: [testnet], Sent 0.0001 BTC to address mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey. Transaction ID: ece39a1c67c291024948df8a8ce4c42b618251af5f1a65ecda616fc2b1054084
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-970000`, expected u64", line: 1, column: 74)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-970000`, expected u64", line: 1, column: 74)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 60, kind: TimedOut, message: "Operation timed out" }', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid value: integer `-970000`, expected u64", line: 1, column: 74)', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
➜  gotham-client git:(gg18_v1) ./target/release/cli wallet-legacy -b
Network: [testnet], Balance: [balance: 950000, pending: 0]
➜  gotham-client git:(gg18_v1) RUST_BACKTRACE=1 ./target/release/cli wallet-legacy send-legacy -t mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey -a 0.0001
(id: ecd0b44d-deef-412b-b01f-ec2bf6245d3f) Took: PT1.641642987S
Network: [testnet], Sent 0.0001 BTC to address mo544wyeKE47cV8k5ZRFsrMQjdkjaCGHey. Transaction ID: e43fe72671116da355edcda991571da56734ee3072a251a58823334f739f8925

@vuminhquang
Copy link
Author

👍 It looks promising. I'll try do it again later when comeback and update the result for you.

@oleiba
Copy link
Contributor

oleiba commented Oct 6, 2019

Closing, please reopen if you see need.

@oleiba oleiba closed this as completed Oct 6, 2019
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

No branches or pull requests

3 participants