moneybutton / bsv

Bitcoin SV javascript library
Other
204 stars 104 forks source link

Throws error when parsing specific tx output script #90

Closed kevinejohn closed 4 years ago

kevinejohn commented 5 years ago

When parsing this transaction's (https://whatsonchain.com/tx/ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767) output scripts bsv throws this error:

Error
    at new NodeError (/project/node_modules/bsv/lib/errors/index.js:20:41)
    at Function.Script.fromBuffer (/project/node_modules/bsv/lib/script/script.js:101:15)
{
  message: "Invalid script buffer: can't parse valid script from given buffer 4e",

Looks like this was fixed for bitcoinjs-lib: https://github.com/bitcoinjs/bitcoinjs-lib/pull/375

bitcartel commented 4 years ago

This issue is reproducible.

var bsv = require("bsv");
var script = new bsv.Script("4e");

Invalid script buffer: can't parse valid script from given buffer 4e

When parsing the script, a buffer reader will attempt to read data which does not exist, resulting in a ranger error being thrown. This exception is caught and rethrown as the above invalid script buffer.

If the intent is to have the caller place bsv scripting calls within a try catch, it should be documented so that developers are aware that there could be exceptions which propagate up the call stack.

Returning null, similar to the fix for bitcoinjs-lib, could also be an option but that would require existing applications to check for a null script.

ryanxcharles commented 4 years ago

Closing due to imminent release of bsv 2.0. Please let me know if you still have this issue.

I believe the bitcore ASM format is fundamentally broken and may not be able to resolve this issue ever - you may need to use one of the other formats. There are 3 string formats in the new library.