bitcoinjs-lib icon indicating copy to clipboard operation
bitcoinjs-lib copied to clipboard

bitcoin.script.classifyOutput is not a function

Open mfaizan1 opened this issue 6 years ago • 11 comments
trafficstars

I have been trying to find it's alternative for hours now but lack of official documentation makes it difficult to find proper method

after going through number of issues i know that this function was deprecated or removed but what is its alternative ?

mfaizan1 avatar Dec 04 '18 22:12 mfaizan1

install v3 instead.

or update your code to use v4.

junderw avatar Dec 05 '18 00:12 junderw

install v3 instead.

or update your code to use v4.

it is already v4 "bitcoinjs-lib": "^4.0.2",

mfaizan1 avatar Dec 05 '18 00:12 mfaizan1

update your code to use v4.

package.json is not code.

"update your code to use v4" means "stop using bitcoin.script.classifyOutput since it is no longer available in v4"

junderw avatar Dec 05 '18 01:12 junderw

update your code to use v4.

package.json is not code.

"update your code to use v4" means "stop using bitcoin.script.classifyOutput since it is no longer available in v4"

thats what i am asking what to use instead of classifyOutput ?

mfaizan1 avatar Dec 05 '18 01:12 mfaizan1

@mfaizan1 what is your use case for classifyOutput?

dcousens avatar Dec 05 '18 03:12 dcousens

thats what i am asking what to use instead of classifyOutput?

There is no 1:1 exact replacement for classifyOutput.

Please show us some code and for what you are using classifyOutput.

Most likely you can accomplish the same goal with the payments API.

junderw avatar Dec 05 '18 03:12 junderw

thats what i am asking what to use instead of classifyOutput?

There is no 1:1 exact replacement for classifyOutput.

Please show us some code and for what you are using classifyOutput.

Most likely you can accomplish the same goal with the payments API. @dcousens here is the code i am trying to use.

var decodeOutput = function(tx){

    var format = function(out, n){
        var vout = {
            satoshi: out.value,
            value: (1e-8 * out.value).toFixed(8),
            n: n,
            scriptPubKey: {
                asm: Btc.script.toASM(out.script),
                hex: out.script.toString('hex'),
                type: Btc.script.classifyOutput(out.script),
                addresses: [],
            },
        };
        switch(vout.scriptPubKey.type){
        case 'pubkeyhash':
        case 'scripthash':
            vout.scriptPubKey.addresses.push(Btc.address.fromOutputScript(out.script, Btc.networks.regtest));
            break;
        }
        return vout
    }

    var result = [];
    tx.outs.forEach(function(out, n){
        result.push(format(out, n));
    })
    return result
}

mfaizan1 avatar Dec 05 '18 09:12 mfaizan1

"bitcoinjs-lib": "^4.0.2",

  • Quick 'dirty' fix : bitcoin.script.classifyOutput = require('./node_modules/bitcoinjs-lib/src/classify').output;

rodpimenta avatar Dec 12 '18 03:12 rodpimenta

Please don't

dcousens avatar Dec 12 '18 07:12 dcousens

thats what i am asking what to use instead of classifyOutput?

There is no 1:1 exact replacement for classifyOutput. Please show us some code and for what you are using classifyOutput. Most likely you can accomplish the same goal with the payments API. @dcousens here is the code i am trying to use.

var decodeOutput = function(tx){

    var format = function(out, n){
        var vout = {
            satoshi: out.value,
            value: (1e-8 * out.value).toFixed(8),
            n: n,
            scriptPubKey: {
                asm: Btc.script.toASM(out.script),
                hex: out.script.toString('hex'),
                type: Btc.script.classifyOutput(out.script),
                addresses: [],
            },
        };
        switch(vout.scriptPubKey.type){
        case 'pubkeyhash':
        case 'scripthash':
            vout.scriptPubKey.addresses.push(Btc.address.fromOutputScript(out.script, Btc.networks.regtest));
            break;
        }
        return vout
    }

    var result = [];
    tx.outs.forEach(function(out, n){
        result.push(format(out, n));
    })
    return result
}

Did you ever get this figured out IC nobody answered you. I have same question.

mmvphil avatar May 05 '19 03:05 mmvphil

@mfaizan1 , @mmvphil I fixed decodeOutput function to align with the latest bitcoinjs-lib version. Please refer to https://github.com/bitcoinjs/bitcoinjs-lib/issues/760#issuecomment-1692806359.

bomzj avatar Aug 25 '23 06:08 bomzj