Repository: bitcoinjs/bitcoinjs-lib
Pull request #810 (2017-06-18 11:23:26)

Added link to Melis wallet
Full sources of the APIs using the library at:
https://github.com/melis-wallet/melis-api-js


Patch:
diff --git a/README.md b/README.md
index 060ed1cf..25862d13 100644
--- a/README.md
+++ b/README.md
@@ -131,6 +131,7 @@ If you have a use case that you feel could be listed here, please [ask for it](h
 - [Dogechain Wallet](https://dogechain.info)
 - [EI8HT Wallet](http://ei8.ht/)
 - [GreenAddress](https://greenaddress.it)
+- [Melis Wallet](https://melis.io)
 - [Robocoin](https://wallet.robocoin.com)
 - [Skyhook ATM](http://projectskyhook.com)
 
diff --git a/package.json b/package.json
index 4cca7177..e740e4d2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "bitcoinjs-lib",
-  "version": "3.0.3",
+  "version": "3.1.0",
   "description": "Client-side Bitcoin JavaScript library",
   "main": "./src/index.js",
   "engines": {
diff --git a/src/transaction.js b/src/transaction.js
index 41e00d90..86ccceab 100644
--- a/src/transaction.js
+++ b/src/transaction.js
@@ -191,6 +191,16 @@ Transaction.prototype.hasWitnesses = function () {
   })
 }
 
+Transaction.prototype.weight = function () {
+  var base = this.__byteLength(false)
+  var total = this.__byteLength(true)
+  return base * 3 + total
+}
+
+Transaction.prototype.virtualSize = function () {
+  return Math.ceil(this.weight() / 4)
+}
+
 Transaction.prototype.byteLength = function () {
   return this.__byteLength(true)
 }


Test patch:
diff --git a/test/fixtures/transaction.json b/test/fixtures/transaction.json
index 7fb51359..6bf60906 100644
--- a/test/fixtures/transaction.json
+++ b/test/fixtures/transaction.json
@@ -22,7 +22,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 192,
+      "weight": 768
     },
     {
       "description": "Standard transaction (2:2)",
@@ -57,7 +59,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 396,
+      "weight": 1584
     },
     {
       "description": "Standard transaction (14:2)",
@@ -151,7 +155,9 @@
           }
         ]
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 2596,
+      "weight": 10384
     },
     {
       "description": "Coinbase transaction",
@@ -175,7 +181,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": true
+      "coinbase": true,
+      "virtualSize": 126,
+      "weight": 504
     },
     {
       "description": "Transaction that ignores script chunking rules - Bug #367",
@@ -227,7 +235,9 @@
           }
         ]
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 249,
+      "weight": 996
     },
     {
       "description": "P2PK",
@@ -253,7 +263,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 158,
+      "weight": 632
     },
     {
       "description": "P2SH P2PK",
@@ -280,7 +292,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 193,
+      "weight": 772
     },
     {
       "description": "P2WSH P2PK",
@@ -309,7 +323,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 113,
+      "weight": 451
     },
     {
       "description": "P2SH P2WSH P2PK",
@@ -338,7 +354,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 148,
+      "weight": 591
     },
     {
       "description": "P2PKH",
@@ -363,7 +381,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 192,
+      "weight": 768
     },
     {
       "description": "P2SH P2PKH",
@@ -388,7 +408,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 217,
+      "weight": 868
     },
     {
       "description": "P2WSH P2PKH",
@@ -419,7 +441,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 119,
+      "weight": 476
     },
     {
       "description": "P2SH P2WSH P2PKH",
@@ -449,7 +473,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 154,
+      "weight": 616
     },
     {
       "description": "Multisig",
@@ -474,7 +500,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 159,
+      "weight": 636
     },
     {
       "description": "P2SH Multisig",
@@ -500,7 +528,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 196,
+      "weight": 784
     },
     {
       "description": "P2WSH Multisig",
@@ -530,7 +560,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 114,
+      "weight": 455
     },
     {
       "description": "P2SH P2WSH Multisig",
@@ -561,7 +593,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 149,
+      "weight": 595
     },
     {
       "description": "P2WKH",
@@ -590,7 +624,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 113,
+      "weight": 450
     },
     {
       "description": "P2SH P2WKH",
@@ -619,7 +655,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": false
+      "coinbase": false,
+      "virtualSize": 136,
+      "weight": 542
     },
     {
       "description": "Coinbase transaction w/ witness",
@@ -652,7 +690,9 @@
         ],
         "locktime": 0
       },
-      "coinbase": true
+      "coinbase": true,
+      "virtualSize": 156,
+      "weight": 624
     }
   ],
   "hashForSignature": [
diff --git a/test/transaction.js b/test/transaction.js
index 35beb81a..62c24d01 100644
--- a/test/transaction.js
+++ b/test/transaction.js
@@ -129,6 +129,24 @@ describe('Transaction', function () {
     })
   })
 
+  describe('weight/virtualSize', function () {
+    it('computes virtual size', function () {
+      fixtures.valid.forEach(function (f) {
+        var transaction = Transaction.fromHex(f.whex ? f.whex : f.hex)
+
+        assert.strictEqual(transaction.virtualSize(), f.virtualSize)
+      })
+    })
+
+    it('computes weight', function () {
+      fixtures.valid.forEach(function (f) {
+        var transaction = Transaction.fromHex(f.whex ? f.whex : f.hex)
+
+        assert.strictEqual(transaction.weight(), f.weight)
+      })
+    })
+  })
+
   describe('addInput', function () {
     var prevTxHash
     beforeEach(function () {