From 903d70de3ce5dbe8b7ed01c51ab9c69bb8a8f19a Mon Sep 17 00:00:00 2001 From: Sergey Ukustov Date: Thu, 18 Apr 2019 22:07:16 +0400 Subject: [PATCH] More of funky comparisons, now for TX --- lib/funky.js | 5 +++++ lib/ledger.js | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/funky.js b/lib/funky.js index 40cbc5f..5c463e8 100644 --- a/lib/funky.js +++ b/lib/funky.js @@ -1,6 +1,11 @@ const MTX = require('bcoin/lib/primitives/mtx'); +const TX = require('bcoin/lib/primitives/tx'); const CoinView = require('bcoin/lib/coins/coinview'); +export function isTX(obj) { + return TX.isTX(obj) || (obj.constructor.toString() == TX.toString()) || isMTX(obj) +} + export function isMTX(obj) { return MTX.isMTX(obj) || (obj.constructor.toString() == MTX.toString()) } diff --git a/lib/ledger.js b/lib/ledger.js index b4167b7..5fe26e1 100644 --- a/lib/ledger.js +++ b/lib/ledger.js @@ -79,7 +79,7 @@ class LedgerBTCApp { async getTrustedInput(tx, inputIndex) { assert(this.device); - assert(TX.isTX(tx)); + assert(funky.isTX(tx)); const messages = utilTX.splitTransaction(tx); @@ -121,7 +121,7 @@ class LedgerBTCApp { async hashTransactionStart(tx, view, tis, isNew, hasWitness) { assert(this.device); - assert(TX.isTX(tx), 'tx must be instanceof TX'); + assert(funky.isTX(tx), 'tx must be instanceof TX'); assert(funky.isCoinView(view), 'view must be instanceof CoinView'); assert(typeof tis === 'object', 'Trusted input map not found.'); @@ -269,7 +269,7 @@ class LedgerBTCApp { async hashTransactionStartSegwit(tx, view, key, prev) { assert(this.device); - assert(TX.isTX(tx)); + assert(funky.isTX(tx)); const newTX = new TX(); newTX.inject(tx); @@ -305,7 +305,7 @@ class LedgerBTCApp { async hashOutputFinalize(tx) { assert(this.device); - assert(funky.isMTX(tx)); + assert(funky.isTX(tx)); let size = encoding.sizeVarint(tx.outputs.length); @@ -347,7 +347,7 @@ class LedgerBTCApp { async hashSign(tx, path, type) { assert(this.device); - assert(TX.isTX(tx)); + assert(funky.isTX(tx)); if (typeof path === 'string') path = util.parsePath(path, true);