From 6246b6c931dcd97bf762af81e8eba411680cdc60 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sun, 6 Aug 2023 22:02:40 -0500 Subject: [PATCH] refactor CashFusion Address model and add toFusionAddress method to go from Stack Address -> CashFusion Address --- fusiondart | 2 +- lib/models/isar/models/blockchain_data/address.dart | 13 +++++++++++++ lib/services/mixins/fusion_interface.dart | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fusiondart b/fusiondart index 58f18edde..b4209c152 160000 --- a/fusiondart +++ b/fusiondart @@ -1 +1 @@ -Subproject commit 58f18eddee78be0ee393a23d03ccba94e252d8cf +Subproject commit b4209c1523cf53d9db805ce0924e6902c716c0f3 diff --git a/lib/models/isar/models/blockchain_data/address.dart b/lib/models/isar/models/blockchain_data/address.dart index 028bee04a..630b61a57 100644 --- a/lib/models/isar/models/blockchain_data/address.dart +++ b/lib/models/isar/models/blockchain_data/address.dart @@ -10,6 +10,7 @@ import 'dart:convert'; +import 'package:fusiondart/src/models/address.dart' as FusionAddress; import 'package:isar/isar.dart'; import 'package:stackwallet/exceptions/address/address_exception.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/crypto_currency_address.dart'; @@ -212,3 +213,15 @@ class DerivationPath { @override int get hashCode => value.hashCode; } + +extension ToFusionAddress on Address { + FusionAddress.Address toFusionAddress() { + return FusionAddress.Address( + addr: value, + id: id.toString(), // Assuming id can be converted to a String + publicKey: + publicKey, // Assuming List and List are compatible + derivationPath: + FusionAddress.DerivationPath(derivationPath?.value ?? "")); + } +} diff --git a/lib/services/mixins/fusion_interface.dart b/lib/services/mixins/fusion_interface.dart index da5592d8d..fc721d781 100644 --- a/lib/services/mixins/fusion_interface.dart +++ b/lib/services/mixins/fusion_interface.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:fusiondart/fusiondart.dart'; +import 'package:fusiondart/src/models/address.dart' as fusion_address; import 'package:isar/isar.dart'; import 'package:stackwallet/db/isar/main_db.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; @@ -41,9 +42,13 @@ mixin FusionInterface { // add stack change address final String currentChangeAddress = await _getCurrentChangeAddress(); - // await mainFusionObject.addChangeAddress(currentChangeAddress); + // cast from String to Address final Address? changeAddress = await _db.getAddress(_walletId, currentChangeAddress); + // cast from Stack's Address to Fusiondart's Address + final fusion_address.Address fusionChangeAddress = + changeAddress!.toFusionAddress(); + await mainFusionObject.addChangeAddress(fusionChangeAddress); Logging.instance.log( "FusionInterface fuse() changeAddress: $changeAddress", level: LogLevel.Info,