Skip to content

Commit

Permalink
Merge pull request #260 from sCrypt-Inc/bsv
Browse files Browse the repository at this point in the history
Bsv
  • Loading branch information
zhfnjust authored Jan 31, 2024
2 parents 5720211 + 08cfaae commit fcf7119
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions patches/bsv/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PrivateKey>,
Expand All @@ -978,6 +977,7 @@ declare module 'bsv' {
sealAsync(): Promise<this>;
isSealed(): boolean;
getChangeAmount(): number;
getEstimateSize(): number;
getEstimateFee(): number;
checkFeeRate(feePerKb?: number): boolean;
prevouts(): string;
Expand Down
2 changes: 1 addition & 1 deletion patches/bsv/lib/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

var Buffer
try {
Buffer = require('buffer').Buffer
Buffer = require('buffer/').Buffer
} catch (e) {
}

Expand Down
14 changes: 9 additions & 5 deletions patches/bsv/lib/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fcf7119

Please sign in to comment.