Skip to content

Commit f3b5b3c

Browse files
committed
⏪️ Use int rather than BigInt
1 parent ad5038d commit f3b5b3c

File tree

2 files changed

+103
-102
lines changed

2 files changed

+103
-102
lines changed

packages/agent_dart_base/lib/wallet/btc/bdk/bdk.dart

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,10 @@ class PartiallySignedTransaction {
889889
}
890890

891891
/// Return feeAmount
892-
Future<BigInt?> feeAmount() async {
892+
Future<int?> feeAmount() async {
893893
try {
894894
final res = await Api.psbtFeeAmount(psbtStr: psbtBase64);
895-
return res;
895+
return res?.toInt();
896896
} on AnyhowException catch (e, s) {
897897
Error.throwWithStackTrace(configException(e.message), s);
898898
}
@@ -1140,8 +1140,8 @@ class TxBuilder {
11401140
}
11411141

11421142
///Add a recipient to the internal list
1143-
TxBuilder addRecipient(bridge.Script script, BigInt amount) {
1144-
_recipients.add(ScriptAmount(script: script, amount: amount));
1143+
TxBuilder addRecipient(bridge.Script script, int amount) {
1144+
_recipients.add(ScriptAmount(script: script, amount: BigInt.from(amount)));
11451145
return this;
11461146
}
11471147

@@ -1189,7 +1189,7 @@ class TxBuilder {
11891189
ForeignUtxo(
11901190
outpoint: OutPoint(txid: ext.txid, vout: ext.vout),
11911191
txout: TxOutForeign(
1192-
value: ext.value,
1192+
value: BigInt.from(ext.value),
11931193
scriptPubkey: ext.scriptPk,
11941194
),
11951195
),
@@ -1325,12 +1325,12 @@ class TxBuilder {
13251325
return this;
13261326
}
13271327

1328-
Future<BigInt?> calNetworkFee(Wallet wallet) async {
1328+
Future<int?> calNetworkFee(Wallet wallet) async {
13291329
final res = await finish(wallet);
13301330
return res.psbt.feeAmount();
13311331
}
13321332

1333-
Future<BigInt> calFee(Wallet wallet) async {
1333+
Future<int> calFee(Wallet wallet) async {
13341334
final res = await Api.txCalFeeFinish(
13351335
wallet: wallet._wallet,
13361336
recipients: _recipients,
@@ -1347,26 +1347,26 @@ class TxBuilder {
13471347
changePolicy: _changeSpendPolicy,
13481348
shuffleUtxo: _shuffleUtxos,
13491349
);
1350-
return res;
1350+
return res.toInt();
13511351
}
13521352

1353-
BigInt getTotalOutput() {
1354-
BigInt total = BigInt.zero;
1353+
int getTotalOutput() {
1354+
int total = 0;
13551355
for (final e in _txOutputs) {
13561356
total += e.value;
13571357
}
13581358
return total;
13591359
}
13601360

1361-
BigInt getTotalInput() {
1362-
BigInt total = BigInt.zero;
1361+
int getTotalInput() {
1362+
int total = 0;
13631363
for (final e in _txInputs) {
13641364
total += e.value;
13651365
}
13661366
return total;
13671367
}
13681368

1369-
BigInt getUnspend() {
1369+
int getUnspend() {
13701370
return getTotalInput() - getTotalOutput();
13711371
}
13721372

@@ -1425,7 +1425,7 @@ class InscriptionValue {
14251425
});
14261426

14271427
final String inscriptionId;
1428-
final BigInt outputValue;
1428+
final int outputValue;
14291429
}
14301430

14311431
class OutPointExt extends OutPoint {
@@ -1441,7 +1441,7 @@ class OutPointExt extends OutPoint {
14411441
required this.scriptPk,
14421442
}) : super(txid: '', vout: 0);
14431443

1444-
final BigInt value;
1444+
final int value;
14451445
final String scriptPk;
14461446

14471447
String get uniqueKey => '$txid:$vout';
@@ -1517,26 +1517,26 @@ class TxBuilderResult {
15171517

15181518
bool? signed;
15191519

1520-
BigInt getTotalInput() {
1521-
return _txInputs.fold(BigInt.zero, (p, v) => p + v.value);
1520+
int getTotalInput() {
1521+
return _txInputs.fold(0, (p, v) => p + v.value);
15221522
}
15231523

1524-
BigInt getTotalOutput() {
1525-
return _txOutputs.fold(BigInt.zero, (p, v) => p + v.value);
1524+
int getTotalOutput() {
1525+
return _txOutputs.fold(0, (p, v) => p + v.value);
15261526
}
15271527

15281528
Future<void> dumpTx({
15291529
void Function(Object?)? logPrint = print,
15301530
}) async {
15311531
final tx = await psbt.extractTx();
15321532
final size = Uint8List.fromList(await tx.serialize()).length;
1533-
final feePaid = await psbt.feeAmount();
1533+
final feePaid = BigInt.from((await psbt.feeAmount())!);
15341534
final feeRate = (await psbt.feeRate())!.asSatPerVb();
15351535
final inputs = await tx.input();
15361536
final outputs = await tx.output();
15371537

15381538
final inputStrings = <String>[];
1539-
BigInt totalInput = BigInt.zero;
1539+
int totalInput = 0;
15401540
for (int i = 0; i < _txInputs.length; i += 1) {
15411541
final input = _txInputs[i];
15421542
final found = inputs.firstWhereOrNull((e) {
@@ -1583,7 +1583,7 @@ ${outputString.join("\n")}
15831583
Summary in Sats
15841584
Inputs: + $totalInput
15851585
Outputs: - $totalOutput
1586-
fee: - ${feePaid!}
1586+
fee: - $feePaid
15871587
Remain: ${totalOutput - feePaid}
15881588
==============================================================================================
15891589
''');
@@ -1937,7 +1937,7 @@ class Wallet {
19371937
txId: txId,
19381938
index: i,
19391939
address: addr,
1940-
value: element.value,
1940+
value: element.value.toInt(),
19411941
isMine: addr.address == address,
19421942
isChange: false,
19431943
),
@@ -1954,7 +1954,7 @@ class Wallet {
19541954
TxOutExt(
19551955
index: i,
19561956
address: addr,
1957-
value: element.value,
1957+
value: element.value.toInt(),
19581958
isMine: addr.address == address,
19591959
isChange: i == outputs.length - 1 ? true : false,
19601960
),
@@ -1973,8 +1973,8 @@ class Wallet {
19731973
fee: feePaid!,
19741974
feeRate: feeRate,
19751975
size: size,
1976-
totalInputValue: inputsExt.fold(BigInt.zero, (v, i) => i.value + v),
1977-
totalOutputValue: outputsExt.fold(BigInt.zero, (v, i) => i.value + v),
1976+
totalInputValue: inputsExt.fold(0, (v, i) => i.value + v),
1977+
totalOutputValue: outputsExt.fold(0, (v, i) => i.value + v),
19781978
psbt: psbt,
19791979
);
19801980
}

0 commit comments

Comments
 (0)