mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 20:09:23 +00:00
Merge pull request #855 from cypherstack/testing_julian
quick vSize calc
This commit is contained in:
commit
827527776d
4 changed files with 59 additions and 2 deletions
|
@ -9,5 +9,9 @@
|
|||
*/
|
||||
|
||||
export 'impl/big_int.dart';
|
||||
export 'impl/box_shadow.dart';
|
||||
export 'impl/cl_transaction.dart';
|
||||
export 'impl/contract_abi.dart';
|
||||
export 'impl/gradient.dart';
|
||||
export 'impl/string.dart';
|
||||
export 'impl/uint8_list.dart';
|
||||
|
|
53
lib/utilities/extensions/impl/cl_transaction.dart
Normal file
53
lib/utilities/extensions/impl/cl_transaction.dart
Normal file
|
@ -0,0 +1,53 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:coinlib_flutter/coinlib_flutter.dart';
|
||||
|
||||
extension CLTransactionExt on Transaction {
|
||||
int weight() {
|
||||
final base = _byteLength(false);
|
||||
final total = _byteLength(true);
|
||||
return base * 3 + total;
|
||||
}
|
||||
|
||||
int vSize() => (weight() / 4).ceil();
|
||||
|
||||
int _byteLength(final bool allowWitness) {
|
||||
final hasWitness = allowWitness && isWitness;
|
||||
return (hasWitness ? 10 : 8) +
|
||||
_encodingLength(inputs.length) +
|
||||
_encodingLength(outputs.length) +
|
||||
inputs.fold<int>(0, (sum, input) => sum + input.size) +
|
||||
outputs.fold<int>(0, (sum, output) => sum + output.size) +
|
||||
(hasWitness
|
||||
? inputs.fold(0, (sum, input) {
|
||||
if (input is! WitnessInput) {
|
||||
return sum;
|
||||
} else {
|
||||
return sum + _vectorSize(input.witness);
|
||||
}
|
||||
})
|
||||
: 0);
|
||||
}
|
||||
|
||||
int _varSliceSize(Uint8List someScript) {
|
||||
final length = someScript.length;
|
||||
return _encodingLength(length) + length;
|
||||
}
|
||||
|
||||
int _vectorSize(List<Uint8List> someVector) {
|
||||
final length = someVector.length;
|
||||
return _encodingLength(length) +
|
||||
someVector.fold(
|
||||
0,
|
||||
(sum, witness) => sum + _varSliceSize(witness),
|
||||
);
|
||||
}
|
||||
|
||||
int _encodingLength(int number) => number < 0xfd
|
||||
? 1
|
||||
: number <= 0xffff
|
||||
? 3
|
||||
: number <= 0xffffffff
|
||||
? 5
|
||||
: 9;
|
||||
}
|
|
@ -768,7 +768,7 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
|
||||
return txData.copyWith(
|
||||
raw: clTx.toHex(),
|
||||
vSize: clTx.size,
|
||||
vSize: clTx.vSize(),
|
||||
tempTx: TransactionV2(
|
||||
walletId: walletId,
|
||||
blockHash: null,
|
||||
|
|
|
@ -866,7 +866,7 @@ mixin PaynymInterface<T extends PaynymCurrencyInterface>
|
|||
);
|
||||
}
|
||||
|
||||
return Tuple2(clTx.toHex(), clTx.size);
|
||||
return Tuple2(clTx.toHex(), clTx.vSize());
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
"_createNotificationTx(): $e\n$s",
|
||||
|
|
Loading…
Reference in a new issue