From e82a5a1fb8cbb29e443f85b8dfc08a9b35cd5260 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 9 Oct 2023 15:05:04 -0600 Subject: [PATCH] use utxo class for passing around utxo data --- fusiondart | 2 +- .../mixins/fusion_wallet_interface.dart | 47 ++++--------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/fusiondart b/fusiondart index 440ec6a81..56de6e9e8 160000 --- a/fusiondart +++ b/fusiondart @@ -1 +1 @@ -Subproject commit 440ec6a8189ccbcf4b9570d83c8fe1cd9910bdbe +Subproject commit 56de6e9e8cd3f1af9959be7dc4c14131058e7430 diff --git a/lib/services/mixins/fusion_wallet_interface.dart b/lib/services/mixins/fusion_wallet_interface.dart index 8bf14258b..02d093296 100644 --- a/lib/services/mixins/fusion_wallet_interface.dart +++ b/lib/services/mixins/fusion_wallet_interface.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; import 'package:fusiondart/fusiondart.dart' as fusion; @@ -114,12 +113,12 @@ mixin FusionWalletInterface { } /// Returns a list of all UTXOs in the wallet for the given address. - Future> getInputsByAddress(String address) async { + Future> getInputsByAddress(String address) async { final _utxos = await _db.getUTXOsByAddress(_walletId, address).findAll(); - List> futureInputs = _utxos + List> futureInputs = _utxos .map( - (utxo) => utxo.toFusionInput( + (utxo) => utxo.toFusionUtxoDTO( walletId: _walletId, dbInstance: _db, ), @@ -357,7 +356,7 @@ extension FusionUTXO on UTXO { } /// Converts a Stack Wallet UTXO to a FusionDart Input. - Future toFusionInput({ + Future toFusionUtxoDTO({ required String walletId, required MainDB dbInstance, }) async { @@ -376,44 +375,14 @@ extension FusionUTXO on UTXO { throw Exception("Public key for fetched address is empty"); } - return fusion.Input( - prevTxid: utf8.encode(txid), - prevIndex: vout, + return fusion.UtxoDTO( + txid: txid, + vout: vout, pubKey: addr.publicKey, - value: BigInt.from(value), + value: value, ); } catch (e) { rethrow; } } - - /// Converts a Stack Wallet UTXO to a FusionDart Output. - Future toFusionOutput({ - required String walletId, - required MainDB dbInstance, - }) async { - if (address == null) { - throw Exception("toFutionOutput Address is null"); - } - - // Search isar for address to get pubKey. - final Address addr = await _getAddressPubkey( - address: address!, - walletId: walletId, - dbInstance: dbInstance, - ); - - if (addr.publicKey.isEmpty) { - throw Exception("Public key for fetched address is empty"); - } - - if (addr.derivationPath == null) { - throw Exception("Derivation path for fetched address is empty"); - } - - return fusion.Output( - addr: addr.toFusionAddress(), - value: value, - ); - } }