diff --git a/package-lock.json b/package-lock.json index ea89e7e..a9ed162 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scryptlib", - "version": "2.1.37", + "version": "2.1.38", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scryptlib", - "version": "2.1.37", + "version": "2.1.38", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 2b2755b..d64beb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scryptlib", - "version": "2.1.37", + "version": "2.1.38", "description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.", "engines": { "node": ">=14.0.0" diff --git a/patches/bsv/index.d.ts b/patches/bsv/index.d.ts index 463de3b..fb49be1 100644 --- a/patches/bsv/index.d.ts +++ b/patches/bsv/index.d.ts @@ -929,6 +929,7 @@ declare module 'bsv' { outputScript?: Script | string, satoshis?: number ): this; + removeInput(txId: string, outputIndex: number): void; addOutput(output: Transaction.Output): this; addData(value: Buffer | string): this; lockUntilDate(time: Date | number): this; @@ -958,9 +959,7 @@ declare module 'bsv' { getSerializationError(opts?: object): any; - _getUnspentValue(): number; - _estimateFee(): number; - _estimateSize: number; + getUnspentValue(): number; setInputScript(inputIndex: number | { inputIndex: number, privateKey?: PrivateKey | Array, @@ -978,6 +977,7 @@ declare module 'bsv' { sealAsync(): Promise; isSealed(): boolean; getChangeAmount(): number; + getEstimateSize(): number; getEstimateFee(): number; checkFeeRate(feePerKb?: number): boolean; prevouts(): string; diff --git a/patches/bsv/lib/bn.js b/patches/bsv/lib/bn.js index 87d6528..1874343 100644 --- a/patches/bsv/lib/bn.js +++ b/patches/bsv/lib/bn.js @@ -50,7 +50,7 @@ var Buffer try { - Buffer = require('buffer').Buffer + Buffer = require('buffer/').Buffer } catch (e) { } diff --git a/patches/bsv/lib/transaction/transaction.js b/patches/bsv/lib/transaction/transaction.js index 978f7eb..e35c7d5 100644 --- a/patches/bsv/lib/transaction/transaction.js +++ b/patches/bsv/lib/transaction/transaction.js @@ -202,7 +202,7 @@ Transaction.prototype.getSerializationError = function (opts) { return new errors.Transaction.InvalidSatoshis() } - var unspent = this._getUnspentValue() + var unspent = this.getUnspentValue() var unspentError if (unspent < 0) { if (!opts.disableMoreOutputThanInput) { @@ -876,7 +876,7 @@ Transaction.prototype._updateChangeOutput = function () { script: this._changeScript, satoshis: 0 })) - var available = this._getUnspentValue() + var available = this.getUnspentValue() var fee = this.getFee() var changeAmount = available - fee this._removeOutput(this._changeIndex) @@ -917,7 +917,7 @@ Transaction.prototype.getFee = function () { } // if no change output is set, fees should equal all the unspent amount if (!this._changeScript) { - return this._getUnspentValue() + return this.getUnspentValue() } return this._estimateFee() } @@ -930,7 +930,7 @@ Transaction.prototype._estimateFee = function () { return Math.ceil(estimatedSize / 1000 * (this._feePerKb || Transaction.FEE_PER_KB)) } -Transaction.prototype._getUnspentValue = function () { +Transaction.prototype.getUnspentValue = function () { return this._getInputAmount() - this._getOutputAmount() } @@ -951,6 +951,10 @@ Transaction.prototype._clearSignatures = function () { // ??? script // // 4 locktime +Transaction.prototype.getEstimateSize = function () { + return this._estimateSize() +} + Transaction.prototype._estimateSize = function () { var result = 4 + 4 // size of version + size of locktime result += Varint(this.inputs.length).toBuffer().length @@ -1439,7 +1443,7 @@ Transaction.prototype.getEstimateFee = function () { * @returns true or false */ Transaction.prototype.checkFeeRate = function (feePerKb) { - var fee = this._getUnspentValue() + var fee = this.getUnspentValue() var estimatedSize = this._estimateSize() var expectedRate = (feePerKb || this._feePerKb || Transaction.FEE_PER_KB) / 1000