@@ -256,11 +256,8 @@ class Psbt {
256
256
return tx ;
257
257
}
258
258
getFeeRate ( ) {
259
- return getTxCacheValue (
260
- '__FEE_RATE' ,
261
- 'fee rate' ,
262
- this . data . inputs ,
263
- this . __CACHE ,
259
+ return Number (
260
+ getTxCacheValue ( '__FEE_RATE' , 'fee rate' , this . data . inputs , this . __CACHE ) ,
264
261
) ;
265
262
}
266
263
getFee ( ) {
@@ -623,7 +620,7 @@ const transactionFromBuffer = buffer => new PsbtTransaction(buffer);
623
620
*/
624
621
class PsbtTransaction {
625
622
constructor ( buffer = Buffer . from ( [ 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ) {
626
- this . tx = transaction_1 . Transaction . fromBuffer ( buffer ) ;
623
+ this . tx = transaction_1 . Transaction . fromBuffer ( buffer , undefined , 'bigint' ) ;
627
624
checkTxEmpty ( this . tx ) ;
628
625
Object . defineProperty ( this , 'tx' , {
629
626
enumerable : false ,
@@ -656,7 +653,7 @@ class PsbtTransaction {
656
653
output . script === undefined ||
657
654
output . value === undefined ||
658
655
! Buffer . isBuffer ( output . script ) ||
659
- typeof output . value !== 'number '
656
+ typeof output . value !== 'bigint '
660
657
) {
661
658
throw new Error ( 'Error adding output.' ) ;
662
659
}
@@ -737,12 +734,15 @@ function check32Bit(num) {
737
734
}
738
735
}
739
736
function checkFees ( psbt , cache , opts ) {
740
- const feeRate = cache . __FEE_RATE || psbt . getFeeRate ( ) ;
737
+ const feeRate = Number ( cache . __FEE_RATE ) || psbt . getFeeRate ( ) ;
741
738
const vsize = cache . __EXTRACTED_TX . virtualSize ( ) ;
742
- const satoshis = feeRate * vsize ;
743
- if ( feeRate >= opts . maximumFeeRate ) {
739
+ const satoshis = BigInt ( feeRate ) * BigInt ( vsize ) ;
740
+ if ( Number ( feeRate ) >= opts . maximumFeeRate ) {
741
+ const satoshisPerCoin = BigInt ( 1e8 ) ;
742
+ const coinString = ( satoshis / satoshisPerCoin ) . toString ( ) ;
743
+ const satsString = ( satoshis % satoshisPerCoin ) . toString ( ) . padStart ( 8 , '0' ) ;
744
744
throw new Error (
745
- `Warning: You are paying around ${ ( satoshis / 1e8 ) . toFixed ( 8 ) } in ` +
745
+ `Warning: You are paying around ${ coinString } . ${ satsString } in ` +
746
746
`fees, which is ${ feeRate } satoshi per byte for a transaction ` +
747
747
`with a VSize of ${ vsize } bytes (segwit counted as 0.25 byte per ` +
748
748
`byte). Use setMaximumFeeRate method to raise your threshold, or ` +
@@ -1208,7 +1208,11 @@ function witnessStackToScriptWitness(witness) {
1208
1208
}
1209
1209
function addNonWitnessTxCache ( cache , input , inputIndex ) {
1210
1210
cache . __NON_WITNESS_UTXO_BUF_CACHE [ inputIndex ] = input . nonWitnessUtxo ;
1211
- const tx = transaction_1 . Transaction . fromBuffer ( input . nonWitnessUtxo ) ;
1211
+ const tx = transaction_1 . Transaction . fromBuffer (
1212
+ input . nonWitnessUtxo ,
1213
+ undefined ,
1214
+ 'bigint' ,
1215
+ ) ;
1212
1216
cache . __NON_WITNESS_UTXO_TX_CACHE [ inputIndex ] = tx ;
1213
1217
const self = cache ;
1214
1218
const selfIndex = inputIndex ;
@@ -1232,7 +1236,7 @@ function addNonWitnessTxCache(cache, input, inputIndex) {
1232
1236
} ) ;
1233
1237
}
1234
1238
function inputFinalizeGetAmts ( inputs , tx , cache , mustFinalize ) {
1235
- let inputAmount = 0 ;
1239
+ let inputAmount = BigInt ( 0 ) ;
1236
1240
inputs . forEach ( ( input , idx ) => {
1237
1241
if ( mustFinalize && input . finalScriptSig )
1238
1242
tx . ins [ idx ] . script = input . finalScriptSig ;
@@ -1250,15 +1254,15 @@ function inputFinalizeGetAmts(inputs, tx, cache, mustFinalize) {
1250
1254
inputAmount += out . value ;
1251
1255
}
1252
1256
} ) ;
1253
- const outputAmount = tx . outs . reduce ( ( total , o ) => total + o . value , 0 ) ;
1257
+ const outputAmount = tx . outs . reduce ( ( total , o ) => total + o . value , BigInt ( 0 ) ) ;
1254
1258
const fee = inputAmount - outputAmount ;
1255
1259
if ( fee < 0 ) {
1256
1260
throw new Error ( 'Outputs are spending more than Inputs' ) ;
1257
1261
}
1258
1262
const bytes = tx . virtualSize ( ) ;
1259
1263
cache . __FEE = fee ;
1260
1264
cache . __EXTRACTED_TX = tx ;
1261
- cache . __FEE_RATE = Math . floor ( fee / bytes ) ;
1265
+ cache . __FEE_RATE = fee / BigInt ( bytes ) ;
1262
1266
}
1263
1267
function nonWitnessUtxoTxFromCache ( cache , input , inputIndex ) {
1264
1268
const c = cache . __NON_WITNESS_UTXO_TX_CACHE ;
0 commit comments