bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.67k stars 2.1k forks source link

Reduce warnings about future segwit version when parsing output scripts #1800

Open woofbotapp opened 2 years ago

woofbotapp commented 2 years ago

https://github.com/bitcoinjs/bitcoinjs-lib/blob/93af5afe67dbc491e36bdfc8d48a00179093f7d1/ts_src/address.ts#L52

I'm writing an app that continuously parses lots of transactions (for analysis purposes) This warning is printed every time such output-script is parsed, and it really spams my logs.

Please make it possible to avoid this warning, maybe via an environment variable. Another reasonable option is to print the warning only after the first time such an output-script is found, and not in following occurrences.

Thanks!

junderw commented 2 years ago

A few thoughts:

  1. This will be fixed for segwit v1 addresses in an upcoming release (once we finish taproot support)
  2. That said, console.warn was meant primarily for wallet developers to be sure that they don't show versions they can't guarantee are safe.
  3. However, we have no way programmatically to relay that info back to the program, and the program has no way to tell us "ok, I made my GUI understandable so the end user is not in danger".
  4. Also, we want to respect the BIP and DO NOT THROW on parsing unknown segwit versions.

Perhaps we should add a new set of functions for to/fromOutputScript and deprecate the current ones for removal in the next major version bump?

junderw commented 2 years ago

As a temporary solution, though super hackey, the consuming app could do something like:

function wrappedFromOutputScript(script, network) {
  const oldWarn = console.warn
  console.warn = () => {}
  const result = fromOutputScript(script, network)
  console.warn = oldWarn
  return result
}
woofbotapp commented 2 years ago

As a temporary solution, though super hackey, the consuming app could do something like:

function wrappedFromOutputScript(script, network) {
  const oldWarn = console.warn
  console.warn = () => {}
  const result = fromOutputScript(script, network)
  console.warn = oldWarn
  return result
}

giphy

PatrickGeyer commented 1 year ago

Is there an ETA on this at all?

motorina0 commented 1 year ago

Is there an ETA on this at all?

Please help review this PR https://github.com/bitcoinjs/bitcoinjs-lib/pull/1742, and the rest will follow 🎵

pedrobranco commented 6 months ago

This also happens when parsing some Litecoin transactions. Maybe adding an optional argument in fromOutputScript to disable these warnings?

junderw commented 6 months ago

I guess we can just do it once. See PR.