refactor CashFusion Address model and add toFusionAddress method

to go from Stack Address -> CashFusion Address
This commit is contained in:
sneurlax 2023-08-06 22:02:40 -05:00
parent 2692ebfc68
commit 6246b6c931
3 changed files with 20 additions and 2 deletions

@ -1 +1 @@
Subproject commit 58f18eddee78be0ee393a23d03ccba94e252d8cf
Subproject commit b4209c1523cf53d9db805ce0924e6902c716c0f3

View file

@ -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<byte> and List<int> are compatible
derivationPath:
FusionAddress.DerivationPath(derivationPath?.value ?? ""));
}
}

View file

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