@dashevo/dashcore-lib
Advanced tools
Comparing version 0.17.11 to 0.17.12
@@ -65,1 +65,4 @@ /* eslint-disable */ | ||
}; | ||
module.exports.WrongOutPointError = require('./WrongOutPointError'); | ||
module.exports.WrongPublicKeyHashError = require('./WrongPublicKeyHashError'); |
@@ -22,6 +22,2 @@ /* eslint-disable */ | ||
var Input = require('./input'); | ||
var PublicKeyHashInput = Input.PublicKeyHash; | ||
var PublicKeyInput = Input.PublicKey; | ||
var MultiSigScriptHashInput = Input.MultiSigScriptHash; | ||
var MultiSigInput = Input.MultiSig; | ||
var Output = require('./output'); | ||
@@ -32,3 +28,11 @@ var Script = require('../script'); | ||
var Payload = require('./payload'); | ||
var Opcode = require('../opcode'); | ||
var PublicKeyHashInput = Input.PublicKeyHash; | ||
var PublicKeyInput = Input.PublicKey; | ||
var MultiSigScriptHashInput = Input.MultiSigScriptHash; | ||
var MultiSigInput = Input.MultiSig; | ||
var registeredTransactionTypes = Payload.constants.registeredTransactionTypes; | ||
var WrongOutPointError = errors.WrongOutPointError; | ||
var WrongPublicKeyHashError = errors.WrongPublicKeyHashError; | ||
@@ -113,2 +117,21 @@ /** | ||
/** | ||
* @param {Buffer} outPointBuffer | ||
* @return {{outputIndex: number, transactionHash: string}} | ||
*/ | ||
Transaction.parseOutPointBuffer = function parseOutPointBuffer(outPointBuffer) { | ||
if (outPointBuffer.length !== 36) { | ||
throw new WrongOutPointError('OutPoint buffer length expected to be 36 bytes'); | ||
} | ||
var bufferReader = new BufferReader(outPointBuffer); | ||
var transactionHash = bufferReader.read(32).toString('hex'); | ||
var outputIndex = bufferReader.readUInt32LE(4); | ||
return { | ||
transactionHash: transactionHash, | ||
outputIndex: outputIndex | ||
}; | ||
}; | ||
var hashProperty = { | ||
@@ -1375,2 +1398,6 @@ configurable: false, | ||
/** | ||
* @param {number} fundingAmount | ||
* @return {Transaction} | ||
*/ | ||
Transaction.prototype.addFundingOutput = function addFundingOutput(fundingAmount) { | ||
@@ -1386,2 +1413,42 @@ var script = new Script().add('OP_RETURN'); | ||
/** | ||
* @param {number} satoshisToBurn | ||
* @param {Buffer} publicKeyHash | ||
* @return {Transaction} | ||
*/ | ||
Transaction.prototype.addBurnOutput = function addBurnOutput(satoshisToBurn, publicKeyHash) { | ||
if (publicKeyHash.length !== 20) { | ||
throw new WrongPublicKeyHashError('Expect public key hash to be 20 bytes long'); | ||
} | ||
var script = new Script() | ||
.add(Opcode.OP_RETURN) | ||
.add(publicKeyHash); | ||
var output = new Output({ | ||
satoshis: satoshisToBurn, | ||
script: script | ||
}); | ||
this.addOutput(output); | ||
return this; | ||
}; | ||
/** | ||
* Gives an OutPoint buffer for the output at a given index | ||
* | ||
* @param {number} outputIndex | ||
* @return {Buffer} | ||
*/ | ||
Transaction.prototype.getOutPointBuffer = function getOutPointBuffer(outputIndex) { | ||
if (!this.outputs[outputIndex]) { | ||
throw new WrongOutPointError("There's no output with such index in the transaction"); | ||
} | ||
var binaryTransactionHash = Buffer.from(this.hash, 'hex'); | ||
var indexBuffer = Buffer.alloc(4); | ||
indexBuffer.writeUInt32LE(outputIndex, 0); | ||
return Buffer.concat([binaryTransactionHash, indexBuffer]); | ||
}; | ||
module.exports = Transaction; |
{ | ||
"name": "@dashevo/dashcore-lib", | ||
"version": "0.17.11", | ||
"version": "0.17.12", | ||
"description": "A pure and powerful JavaScript Dash library.", | ||
@@ -5,0 +5,0 @@ "author": "Dash Core Group, Inc. <dev@dash.org>", |
@@ -123,3 +123,3 @@ /* eslint-disable */ | ||
var parsed = new Transaction(expectedCommitementHex); | ||
console.log(parsed.hash); | ||
var actualCommitementHex = parsed.toString(); | ||
@@ -126,0 +126,0 @@ expect(actualCommitementHex).to.be.equal(expectedCommitementHex); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2856018
217
41153