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

Provide better feedback when Transaction is not fully signed #1076

Closed
dskloet opened this issue Feb 14, 2015 · 11 comments
Closed

Provide better feedback when Transaction is not fully signed #1076

dskloet opened this issue Feb 14, 2015 · 11 comments

Comments

@dskloet
Copy link
Contributor

dskloet commented Feb 14, 2015

I'm trying to broadcast a transaction but I keep getting this meaningless error in the broadcast callback, for what I think is a perfectly fine transaction. How can I debug this error? Here's the code that gives the error:

<html><body>
<script src="bitcore.min.js"></script>
<script src="bitcore-explorers.min.js"></script>
<script>
var bitcore = require('bitcore');
var explorers = require('bitcore-explorers');

var tx = new bitcore.Transaction('0100000004675f813a8a3bdfcfefc76db024b3c31b41fdec0e8c44cdac5d933b067ae3a045000000006a473044022072c9f556d7116157b208c6774f7f2f0698a29c567c1d82ba0e4b27d31af5bc8c022033a340c0f051ca72bd9fbce8b9156d2ef6e280cf05bce5bfe05ce840ebf7f4bf01210364ca17e9a443f775d3a26cd8e4f4873c7186c481fb741ec5e66b1c9b8571b3c8ffffffff185f22601506eda04d65643a94cb0f1d6ff0350a9c75950d1f80f48f157f0eab0000000000ffffffff9a14bd3b132e84408ded7a2a96f1fa76ed3ec03900673b87abe53161aa3cacfa0000000000ffffffff6928d19b1e902207fb4c8707a7af3ad4c97c70f7c4041255a9682427807392e70100000000ffffffff0280969800000000001976a9142f1b6a429396647d29cfc7254422e0e16740810788ac30a99e00000000001976a914689eea5c9eb3c296af083cb1c7dbdfce0386d11388ac00000000');

var insight = new explorers.Insight();
insight.broadcast(tx, function(err, txid) {
  if (err != null) {
    window.console.log('Broadcast Error:', err);
  } else {
    window.console.log('txid:', txid);
  }
});
</script>
</body></html>
@dskloet
Copy link
Contributor Author

dskloet commented Feb 15, 2015

I thought new Insight() was testnet by default.
I changed it to new Insight('https://test-insight.bitpay.com', 'testnet'); and now it says Unexpected token T.
I figured out that it is because it's trying to parse an error message as if it is a successful response.
The error message is Transaction rejected by network (code -26). Reason: 64: non-canonical. What does this mean?

@eordano
Copy link
Contributor

eordano commented Feb 15, 2015

Hmm, we need better checks on bitcore-explorers. Looks like some inputs are missing signatures. Take a look at the "script" fields, they are empty:

After doing:

var bitcore = require('bitcore');
var tx = bitcore.Transaction('0100000004675f813a8a3bdfcfefc76db024b3c31b41fdec0e8c44cdac5d933b067ae3a045000000006a473044022072c9f556d7116157b208c6774f7f2f0698a29c567c1d82ba0e4b27d31af5bc8c022033a340c0f051ca72bd9fbce8b9156d2ef6e280cf05bce5bfe05ce840ebf7f4bf01210364ca17e9a443f775d3a26cd8e4f4873c7186c481fb741ec5e66b1c9b8571b3c8ffffffff185f22601506eda04d65643a94cb0f1d6ff0350a9c75950d1f80f48f157f0eab0000000000ffffffff9a14bd3b132e84408ded7a2a96f1fa76ed3ec03900673b87abe53161aa3cacfa0000000000ffffffff6928d19b1e902207fb4c8707a7af3ad4c97c70f7c4041255a9682427807392e70100000000ffffffff0280969800000000001976a9142f1b6a429396647d29cfc7254422e0e16740810788ac30a99e00000000001976a914689eea5c9eb3c296af083cb1c7dbdfce0386d11388ac00000000');
console.log(tx.toJSON());

I'm getting (only the first input is signed):

{
  "version": 1,
  "inputs": [
    {
      "prevTxId": "45a0e37a063b935daccd448c0eecfd411bc3b324b06dc7efcfdf3b8a3a815f67",
      "outputIndex": 0,
      "sequenceNumber": 4294967295,
      "script": "71 0x3044022072c9f556d7116157b208c6774f7f2f0698a29c567c1d82ba0e4b27d31af5bc8c022033a340c0f051ca72bd9fbce8b9156d2ef6e280cf05bce5bfe05ce840ebf7f4bf01 33 0x0364ca17e9a443f775d3a26cd8e4f4873c7186c481fb741ec5e66b1c9b8571b3c8"
    },
    {
      "prevTxId": "ab0e7f158ff4801f0d95759c0a35f06f1d0fcb943a64654da0ed061560225f18",
      "outputIndex": 0,
      "sequenceNumber": 4294967295,
      "script": ""
    },
    {
      "prevTxId": "faac3caa6131e5ab873b670039c03eed76faf1962a7aed8d40842e133bbd149a",
      "outputIndex": 0,
      "sequenceNumber": 4294967295,
      "script": ""
    },
    {
      "prevTxId": "e7927380272468a9551204c4f7707cc9d43aafa707874cfb0722901e9bd12869",
      "outputIndex": 1,
      "sequenceNumber": 4294967295,
      "script": ""
    }
  ],
  "outputs": [
    {
      "satoshis": 10000000,
      "script": "OP_DUP OP_HASH160 20 0x2f1b6a429396647d29cfc7254422e0e167408107 OP_EQUALVERIFY OP_CHECKSIG"
    },
    {
      "satoshis": 10398000,
      "script": "OP_DUP OP_HASH160 20 0x689eea5c9eb3c296af083cb1c7dbdfce0386d113 OP_EQUALVERIFY OP_CHECKSIG"
    }
  ],
  "nLockTime": 0
}

@dskloet
Copy link
Contributor Author

dskloet commented Feb 15, 2015

Thanks!
I had noticed the missing scripts but I had no idea what it meant.
Does script mean signature here?
I thought I only needed one signature because I'm only sending from one address, but I realize now that each output is signed rather than the entire transaction?

So it seems the main problem is not having clear error messages. I already filed the other bug about it trying to parse the error message but probably more can be done to make it clear and to do earlier checks?

@eordano
Copy link
Contributor

eordano commented Feb 15, 2015

Thanks for trying out the library. Your feedback helps us improve the API towards becoming the most usable library out there. I'll cross reference these current issues:

@eordano eordano changed the title SyntaxError: Unexpected token G Provide better feedback when Transaction is not fully signed Feb 15, 2015
@dskloet
Copy link
Contributor Author

dskloet commented Feb 15, 2015

It's fun to try it out and was pretty easy until I ran into this problem.
I made a simple web app to sign transactions offline.
I felt bad for bothering you with all my problems so I'm glad to hear you're happy with the feedback.

@maraoz
Copy link
Contributor

maraoz commented Feb 18, 2015

@dskloet thanks a lot for finding this! we'll fix it shortly and report back

@braydonf
Copy link
Contributor

Related? bitpay/bitcore-explorers#20

@braydonf
Copy link
Contributor

This is now reporting an error before broadcasting, as reported in bitpay/bitcore-explorers#20

bitcore.ErrorTransactionInputMissingPreviousOutput: No previous output information.

@braydonf
Copy link
Contributor

Instantiating an instance of Transaction from a hexa serialized version is also causing other problems/confusion: #1199

@braydonf braydonf removed the ready label May 12, 2015
@braydonf
Copy link
Contributor

transaction.serialize() throws an error now if a transaction isn't fully signed, and this should be resolved.

@braydonf braydonf added ready and removed ready labels Aug 14, 2015
@braydonf braydonf closed this as completed Jun 6, 2016
@OliveIT
Copy link

OliveIT commented Apr 27, 2019

I got this error when I was trying to sign with a wrong secret key.

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

5 participants