From 81764be9c54ddf98accfa268cfbe0892242276bb Mon Sep 17 00:00:00 2001 From: Stilldabomb Date: Sun, 25 Mar 2018 02:27:13 -0700 Subject: [PATCH 1/7] Fix double import breakage Fixed problem where it would break on double import, causing the program to crash saying there can only be one instance. --- index.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index eaa6107a4..155556eaf 100644 --- a/index.js +++ b/index.js @@ -4,15 +4,12 @@ var bitcore = module.exports; // module information bitcore.version = 'v' + require('./package.json').version; -bitcore.versionGuard = function(version) { - if (version !== undefined) { - var message = 'More than one instance of bitcore-lib found. ' + - 'Please make sure to require bitcore-lib and check that submodules do' + - ' not also include their own bitcore-lib dependency.'; - throw new Error(message); - } -}; -bitcore.versionGuard(global._bitcore); + +if (global._bitcore !== undefined) { + module.exports = global._bitcore; + return; +} + global._bitcore = bitcore.version; // crypto From c8c12c2cd2aa1fccd4bcfc46766bc15a18d955fe Mon Sep 17 00:00:00 2001 From: Stilldabomb Date: Sun, 25 Mar 2018 02:34:57 -0700 Subject: [PATCH 2/7] Remove unneeded test Wanted to replace with something more useful, but would require a way to double import bitcore-lib. --- test/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/index.js b/test/index.js index 47bad735a..0707f273b 100644 --- a/test/index.js +++ b/test/index.js @@ -7,10 +7,4 @@ describe('#versionGuard', function() { it('global._bitcore should be defined', function() { should.equal(global._bitcore, bitcore.version); }); - - it('throw an error if version is already defined', function() { - (function() { - bitcore.versionGuard('version'); - }).should.throw('More than one instance of bitcore'); - }); }); From c92176141dbdc0030c5295fe3a091fa3134ad6a9 Mon Sep 17 00:00:00 2001 From: Jeremy Saeger Date: Sun, 25 Mar 2018 03:19:30 -0700 Subject: [PATCH 3/7] Add fix to bitcore-lib.js --- bitcore-lib.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/bitcore-lib.js b/bitcore-lib.js index 3014204b9..519f8abaa 100644 --- a/bitcore-lib.js +++ b/bitcore-lib.js @@ -54080,15 +54080,12 @@ var bitcore = module.exports; // module information bitcore.version = 'v' + require('./package.json').version; -bitcore.versionGuard = function(version) { - if (version !== undefined) { - var message = 'More than one instance of bitcore-lib found. ' + - 'Please make sure to require bitcore-lib and check that submodules do' + - ' not also include their own bitcore-lib dependency.'; - throw new Error(message); - } -}; -bitcore.versionGuard(global._bitcore); + +if (global._bitcore !== undefind) { + module.exports = global._bitcore; + return; +} + global._bitcore = bitcore.version; // crypto From 73d3274f4df50c94b819cb0847aa77b7ac5dca84 Mon Sep 17 00:00:00 2001 From: Jeremy Saeger Date: Sun, 25 Mar 2018 03:23:15 -0700 Subject: [PATCH 4/7] Fixed global instance value --- bitcore-lib.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bitcore-lib.js b/bitcore-lib.js index 519f8abaa..eb7cf31d3 100644 --- a/bitcore-lib.js +++ b/bitcore-lib.js @@ -54086,7 +54086,7 @@ if (global._bitcore !== undefind) { return; } -global._bitcore = bitcore.version; +global._bitcore = bitcore; // crypto bitcore.crypto = {}; diff --git a/index.js b/index.js index 155556eaf..0ab20008b 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ if (global._bitcore !== undefined) { return; } -global._bitcore = bitcore.version; +global._bitcore = bitcore; // crypto bitcore.crypto = {}; From c66fcbfa5c1def8bbf82615f50dcf812c75275c6 Mon Sep 17 00:00:00 2001 From: Jeremy Saeger Date: Sun, 25 Mar 2018 03:30:34 -0700 Subject: [PATCH 5/7] Fixed global instance value.. again --- bitcore-lib.js | 3 +-- index.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bitcore-lib.js b/bitcore-lib.js index eb7cf31d3..27e8a5d6b 100644 --- a/bitcore-lib.js +++ b/bitcore-lib.js @@ -54086,8 +54086,6 @@ if (global._bitcore !== undefind) { return; } -global._bitcore = bitcore; - // crypto bitcore.crypto = {}; bitcore.crypto.BN = require('./lib/crypto/bn'); @@ -54141,5 +54139,6 @@ bitcore.deps._ = require('lodash'); // Internal usage, exposed for testing/advanced tweaking bitcore.Transaction.sighash = require('./lib/transaction/sighash'); +global._bitcore = bitcore; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) },{"./lib/address":1,"./lib/block":4,"./lib/block/blockheader":3,"./lib/block/merkleblock":5,"./lib/crypto/bn":6,"./lib/crypto/ecdsa":7,"./lib/crypto/hash":8,"./lib/crypto/point":9,"./lib/crypto/random":10,"./lib/crypto/signature":11,"./lib/encoding/base58":12,"./lib/encoding/base58check":13,"./lib/encoding/bufferreader":14,"./lib/encoding/bufferwriter":15,"./lib/encoding/varint":16,"./lib/errors":17,"./lib/hdprivatekey.js":19,"./lib/hdpublickey.js":20,"./lib/networks":21,"./lib/opcode":22,"./lib/privatekey":23,"./lib/publickey":24,"./lib/script":25,"./lib/transaction":28,"./lib/transaction/sighash":36,"./lib/unit":40,"./lib/uri":41,"./lib/util/buffer":42,"./lib/util/js":43,"./lib/util/preconditions":44,"./package.json":320,"bn.js":280,"bs58":281,"buffer":47,"elliptic":285,"lodash":319}]},{},[]); diff --git a/index.js b/index.js index 0ab20008b..69cdf88d5 100644 --- a/index.js +++ b/index.js @@ -10,8 +10,6 @@ if (global._bitcore !== undefined) { return; } -global._bitcore = bitcore; - // crypto bitcore.crypto = {}; bitcore.crypto.BN = require('./lib/crypto/bn'); @@ -64,3 +62,5 @@ bitcore.deps._ = require('lodash'); // Internal usage, exposed for testing/advanced tweaking bitcore.Transaction.sighash = require('./lib/transaction/sighash'); + +global._bitcore = bitcore; From 3842d7568454cd5e56c3ccc04e9f49f32d496dd1 Mon Sep 17 00:00:00 2001 From: Jeremy Saeger Date: Sun, 25 Mar 2018 03:41:54 -0700 Subject: [PATCH 6/7] Fixed test again --- test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 0707f273b..ea64101b3 100644 --- a/test/index.js +++ b/test/index.js @@ -5,6 +5,6 @@ var bitcore = require("../"); describe('#versionGuard', function() { it('global._bitcore should be defined', function() { - should.equal(global._bitcore, bitcore.version); + should.equal(global._bitcore, bitcore); }); }); From 7fd395afe9f704e87941f2f43d886e8dbb8f9757 Mon Sep 17 00:00:00 2001 From: Jeremy Saeger Date: Sun, 25 Mar 2018 04:03:38 -0700 Subject: [PATCH 7/7] Added conflict check --- bitcore-lib.js | 4 ++++ index.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/bitcore-lib.js b/bitcore-lib.js index 27e8a5d6b..0d78d13c3 100644 --- a/bitcore-lib.js +++ b/bitcore-lib.js @@ -54082,6 +54082,10 @@ var bitcore = module.exports; bitcore.version = 'v' + require('./package.json').version; if (global._bitcore !== undefind) { + if (typeof global._bitcore !== 'object' || global._bitcore.version !== bitcore.version) { + throw new Error('Outdated version of bitcore-lib found, ' + + 'please make sure all dependencies have the same version.'); + } module.exports = global._bitcore; return; } diff --git a/index.js b/index.js index 69cdf88d5..af199970d 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,10 @@ var bitcore = module.exports; bitcore.version = 'v' + require('./package.json').version; if (global._bitcore !== undefined) { + if (typeof global._bitcore !== 'object' || global._bitcore.version !== bitcore.version) { + throw new Error('Outdated version of bitcore-lib found, ' + + 'please make sure all dependencies have the same version.'); + } module.exports = global._bitcore; return; }