Merge pull request #855 from cypherstack/testing_julian

quick vSize calc
This commit is contained in:
julian-CStack 2024-05-09 09:37:53 -06:00 committed by GitHub
commit 827527776d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 59 additions and 2 deletions

View file

@ -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';

View 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;
}

View file

@ -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,

View file

@ -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",