nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bitcoinjs/bitcoinjs-lib
Pull request #599 (2016-06-22 05:05:03)

TxBuilder: add setVersion
I wasn't sure about this function at first,  as it seemed so pass-through'ish (aka, perhaps a a sign of bad design).

But with BIP68 about to come into effect,  it may be worth having some sanity checking logic here.  We'll see.

(aka, `setVersion(1)` for a transaction the CSV OP codes is effectively invalid AFAIK)


Patch:
diff --git a/src/transaction_builder.js b/src/transaction_builder.js
index 0ec07188..53847450 100644
--- a/src/transaction_builder.js
+++ b/src/transaction_builder.js
@@ -163,6 +163,13 @@ TransactionBuilder.prototype.setLockTime = function (locktime) {
   this.tx.locktime = locktime
 }
 
+TransactionBuilder.prototype.setVersion = function (version) {
+  typeforce(types.UInt32, version)
+
+  // XXX: this might eventually become more complex depending on what the versions represent
+  this.tx.version = version
+}
+
 TransactionBuilder.fromTransaction = function (transaction, network) {
   var txb = new TransactionBuilder(network)
 


Test patch:
diff --git a/test/transaction_builder.js b/test/transaction_builder.js
index afbb6d9a..51cde35a 100644
--- a/test/transaction_builder.js
+++ b/test/transaction_builder.js
@@ -17,14 +17,8 @@ function construct (f, sign) {
   var network = NETWORKS[f.network]
   var txb = new TransactionBuilder(network)
 
-  // FIXME: add support for version in TransactionBuilder API
-  if (f.version !== undefined) {
-    txb.tx.version = f.version
-  }
-
-  if (f.locktime !== undefined) {
-    txb.setLockTime(f.locktime)
-  }
+  if (f.version !== undefined) txb.setVersion(f.version)
+  if (f.locktime !== undefined) txb.setLockTime(f.locktime)
 
   f.inputs.forEach(function (input) {
     var prevTxScript
Repository: bitcoinjs/bitcoinjs-lib
Pull request #603 (2016-07-12 02:32:54)

Transaction: allow parameterizable buffer

jprichardson: utACK. Would you add a test?
dcousens: Going to put this in https://github.com/bitcoinjs/bitcoinjs-lib/pull/614,  so will add test today
fanatid: utACK

Patch:
diff --git a/src/transaction.js b/src/transaction.js
index f645dcac..cbd316cb 100644
--- a/src/transaction.js
+++ b/src/transaction.js
@@ -241,7 +241,7 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT
   // serialize and hash
   var buffer = new Buffer(txTmp.byteLength() + 4)
   buffer.writeInt32LE(hashType, buffer.length - 4)
-  txTmp.toBuffer().copy(buffer, 0)
+  txTmp.toBuffer(buffer, 0)
 
   return bcrypto.hash256(buffer)
 }
@@ -255,10 +255,10 @@ Transaction.prototype.getId = function () {
   return bufferReverse(this.getHash()).toString('hex')
 }
 
-Transaction.prototype.toBuffer = function () {
-  var buffer = new Buffer(this.byteLength())
+Transaction.prototype.toBuffer = function (buffer, initialOffset) {
+  if (!buffer) buffer = new Buffer(this.byteLength())
 
-  var offset = 0
+  var offset = initialOffset || 0
   function writeSlice (slice) {
     slice.copy(buffer, offset)
     offset += slice.length
@@ -304,6 +304,9 @@ Transaction.prototype.toBuffer = function () {
 
   writeUInt32(this.locktime)
 
+  // avoid slicing unless necessary
+  if (initialOffset !== undefined) return buffer.slice(initialOffset, offset)
+
   return buffer
 }
 


Test patch:
diff --git a/test/transaction.js b/test/transaction.js
index d11ab294..b17dbf8a 100644
--- a/test/transaction.js
+++ b/test/transaction.js
@@ -67,6 +67,24 @@ describe('Transaction', function () {
         assert.strictEqual(actual.toHex(), f.hex, actual.toHex())
       })
     })
+
+    it('accepts target Buffer and offset parameters', function () {
+      var f = fixtures.valid[0]
+      var actual = fromRaw(f.raw)
+      var byteLength = actual.byteLength()
+
+      var target = new Buffer(byteLength * 2)
+      var a = actual.toBuffer(target, 0)
+      var b = actual.toBuffer(target, byteLength)
+
+      assert.strictEqual(a.length, byteLength)
+      assert.strictEqual(b.length, byteLength)
+      assert.strictEqual(a.toString('hex'), f.hex)
+      assert.strictEqual(b.toString('hex'), f.hex)
+      assert.deepEqual(a, b)
+      assert.deepEqual(a, target.slice(0, byteLength))
+      assert.deepEqual(b, target.slice(byteLength))
+    })
   })
 
   describe('addInput', function () {
Repository: bitcoinjs/bitcoinjs-lib
Pull request #629 (2016-09-27 03:56:08)

types: add Satoshi

dcousens: Might be worth making this a separate library.  But I use this type all the time in my own projects...  probably worth changing some of our `UInt53` types over to it tbh.
dcousens: Failing due to https://github.com/bitcoinjs/bitcoinjs-lib/issues/631
Good to merge.

Patch:
diff --git a/src/transaction.js b/src/transaction.js
index cbd316cb..676a53c4 100644
--- a/src/transaction.js
+++ b/src/transaction.js
@@ -117,7 +117,7 @@ Transaction.prototype.addInput = function (hash, index, sequence, scriptSig) {
 }
 
 Transaction.prototype.addOutput = function (scriptPubKey, value) {
-  typeforce(types.tuple(types.Buffer, types.UInt53), arguments)
+  typeforce(types.tuple(types.Buffer, types.Satoshi), arguments)
 
   // Add the output and return the output's index
   return (this.outs.push({
diff --git a/src/types.js b/src/types.js
index e41207fc..1dbdcc51 100644
--- a/src/types.js
+++ b/src/types.js
@@ -6,6 +6,11 @@ function UInt31 (value) {
   return typeforce.UInt32(value) && value <= UINT31_MAX
 }
 
+var SATOSHI_MAX = 2.1 * 1e15
+function Satoshi (value) {
+  return typeforce.UInt53(value) && value <= SATOSHI_MAX
+}
+
 function Bip32Path (value) {
   return typeforce.String(value) &&
     value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
@@ -26,7 +31,7 @@ var Network = typeforce.compile({
   pubKeyHash: typeforce.UInt8,
   scriptHash: typeforce.UInt8,
   wif: typeforce.UInt8,
-  dustThreshold: typeforce.UInt53
+  dustThreshold: Satoshi
 })
 
 // extend typeforce types with ours
@@ -38,6 +43,7 @@ var types = {
   Hash160bit: typeforce.BufferN(20),
   Hash256bit: typeforce.BufferN(32),
   Network: Network,
+  Satoshi: Satoshi,
   UInt2: UInt2,
   UInt31: UInt31,
   Bip32Path: Bip32Path


Test patch:
diff --git a/test/types.js b/test/types.js
index bd023771..df0550a2 100644
--- a/test/types.js
+++ b/test/types.js
@@ -46,4 +46,19 @@ describe('types', function () {
       }, /Expected Buffer\(Length: 32\), got Buffer\(Length: 20\)/)
     })
   })
+
+  describe('Satoshi', function () {
+    [
+      { value: -1, result: false },
+      { value: 0, result: true },
+      { value: 1, result: true },
+      { value: 20999999 * 1e8, result: true },
+      { value: 21000000 * 1e8, result: true },
+      { value: 21000001 * 1e8, result: false }
+    ].forEach(function (f) {
+      it('returns ' + f.result + ' for valid for ' + f.value, function () {
+        assert.strictEqual(types.Satoshi(f.value), f.result)
+      })
+    })
+  })
 })
Repository: bitcoinjs/bitcoinjs-lib
Pull request #658 (2016-10-10 06:10:26)

types: cleanup and refactor BIP32 error message


Patch:
diff --git a/src/hdnode.js b/src/hdnode.js
index 27228e91..3965ff10 100644
--- a/src/hdnode.js
+++ b/src/hdnode.js
@@ -294,7 +294,7 @@ HDNode.prototype.isNeutered = function () {
 }
 
 HDNode.prototype.derivePath = function (path) {
-  typeforce(types.Bip32Path, path)
+  typeforce(types.BIP32Path, path)
 
   var splitPath = path.split('/')
   if (splitPath[0] === 'm') {
diff --git a/src/types.js b/src/types.js
index 1dbdcc51..51165a82 100644
--- a/src/types.js
+++ b/src/types.js
@@ -1,21 +1,20 @@
 var typeforce = require('typeforce')
 
 var UINT31_MAX = Math.pow(2, 31) - 1
-function UInt2 (value) { return (value & 3) === value }
 function UInt31 (value) {
   return typeforce.UInt32(value) && value <= UINT31_MAX
 }
 
+function BIP32Path (value) {
+  return typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
+}
+BIP32Path.toJSON = function () { return 'BIP32 derivation path' }
+
 var SATOSHI_MAX = 2.1 * 1e15
 function Satoshi (value) {
   return typeforce.UInt53(value) && value <= SATOSHI_MAX
 }
 
-function Bip32Path (value) {
-  return typeforce.String(value) &&
-    value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
-}
-
 // external dependent types
 var BigInt = typeforce.quacksLike('BigInteger')
 var ECPoint = typeforce.quacksLike('Point')
@@ -37,6 +36,7 @@ var Network = typeforce.compile({
 // extend typeforce types with ours
 var types = {
   BigInt: BigInt,
+  BIP32Path: BIP32Path,
   Buffer256bit: typeforce.BufferN(32),
   ECPoint: ECPoint,
   ECSignature: ECSignature,
@@ -44,9 +44,7 @@ var types = {
   Hash256bit: typeforce.BufferN(32),
   Network: Network,
   Satoshi: Satoshi,
-  UInt2: UInt2,
-  UInt31: UInt31,
-  Bip32Path: Bip32Path
+  UInt31: UInt31
 }
 
 for (var typeName in typeforce) {


Test patch:
diff --git a/test/hdnode.js b/test/hdnode.js
index 37d62a35..2c4383e5 100644
--- a/test/hdnode.js
+++ b/test/hdnode.js
@@ -384,7 +384,7 @@ describe('HDNode', function () {
       fixtures.invalid.derivePath.forEach(function (fx) {
         assert.throws(function () {
           master.derivePath(fx)
-        }, /Expected Bip32Path/)
+        }, /Expected BIP32 derivation path/)
       })
     })
   })
Repository: bitcoinjs/bitcoinjs-lib
Pull request #661 (2016-10-12 02:15:39)

travis: remove iojs
Did `iojs` even have a LTS release?


Patch:
diff --git a/.travis.yml b/.travis.yml
index 037e1f8b..463c24bc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,6 @@ before_install:
   - npm install npm -g
 node_js:
   - "0.12"
-  - "io.js"
   - "4"
   - "5"
   - "6"
diff --git a/src/hdnode.js b/src/hdnode.js
index 27228e91..3965ff10 100644
--- a/src/hdnode.js
+++ b/src/hdnode.js
@@ -294,7 +294,7 @@ HDNode.prototype.isNeutered = function () {
 }
 
 HDNode.prototype.derivePath = function (path) {
-  typeforce(types.Bip32Path, path)
+  typeforce(types.BIP32Path, path)
 
   var splitPath = path.split('/')
   if (splitPath[0] === 'm') {
diff --git a/src/types.js b/src/types.js
index 1dbdcc51..51165a82 100644
--- a/src/types.js
+++ b/src/types.js
@@ -1,21 +1,20 @@
 var typeforce = require('typeforce')
 
 var UINT31_MAX = Math.pow(2, 31) - 1
-function UInt2 (value) { return (value & 3) === value }
 function UInt31 (value) {
   return typeforce.UInt32(value) && value <= UINT31_MAX
 }
 
+function BIP32Path (value) {
+  return typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
+}
+BIP32Path.toJSON = function () { return 'BIP32 derivation path' }
+
 var SATOSHI_MAX = 2.1 * 1e15
 function Satoshi (value) {
   return typeforce.UInt53(value) && value <= SATOSHI_MAX
 }
 
-function Bip32Path (value) {
-  return typeforce.String(value) &&
-    value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
-}
-
 // external dependent types
 var BigInt = typeforce.quacksLike('BigInteger')
 var ECPoint = typeforce.quacksLike('Point')
@@ -37,6 +36,7 @@ var Network = typeforce.compile({
 // extend typeforce types with ours
 var types = {
   BigInt: BigInt,
+  BIP32Path: BIP32Path,
   Buffer256bit: typeforce.BufferN(32),
   ECPoint: ECPoint,
   ECSignature: ECSignature,
@@ -44,9 +44,7 @@ var types = {
   Hash256bit: typeforce.BufferN(32),
   Network: Network,
   Satoshi: Satoshi,
-  UInt2: UInt2,
-  UInt31: UInt31,
-  Bip32Path: Bip32Path
+  UInt31: UInt31
 }
 
 for (var typeName in typeforce) {


Test patch:
diff --git a/test/hdnode.js b/test/hdnode.js
index 37d62a35..2c4383e5 100644
--- a/test/hdnode.js
+++ b/test/hdnode.js
@@ -384,7 +384,7 @@ describe('HDNode', function () {
       fixtures.invalid.derivePath.forEach(function (fx) {
         assert.throws(function () {
           master.derivePath(fx)
-        }, /Expected Bip32Path/)
+        }, /Expected BIP32 derivation path/)
       })
     })
   })