refactor address model changes back into fusion interface

This commit is contained in:
sneurlax 2023-09-20 10:17:52 -05:00
parent c43cf94c38
commit 6b0dd30dee
2 changed files with 40 additions and 39 deletions

View file

@ -236,14 +236,3 @@ class DerivationPath {
@override @override
int get hashCode => value.hashCode; int get hashCode => value.hashCode;
} }
extension ToFusionAddress on Address {
FusionAddress.Address toFusionAddress() {
return FusionAddress.Address(
addr: value,
publicKey:
publicKey, // Assuming List<byte> and List<int> are compatible
derivationPath:
FusionAddress.DerivationPath(derivationPath?.value ?? ""));
}
}

View file

@ -385,6 +385,46 @@ mixin FusionWalletInterface {
} }
} }
/// An extension of Stack Wallet's Address class that adds CashFusion functionality.
extension FusionAddress on Address {
fusion_address.Address toFusionAddress() {
return fusion_address.Address(
addr: value,
publicKey:
publicKey, // Assuming List<byte> and List<int> are compatible
derivationPath:
fusion_address.DerivationPath(derivationPath?.value ?? ""));
}
}
/// An extension of Stack Wallet's UTXO class that adds CashFusion functionality.
///
/// This class is used to convert Stack Wallet's UTXO class to FusionDart's
/// Input and Output classes.
extension FusionUTXO on UTXO {
/// Converts a Stack Wallet UTXO to a FusionDart Input.
fusion_input.Input toFusionInput({required List<int> pubKey}) {
return fusion_input.Input(
prevTxid: utf8.encode(txid), // TODO verify this is what we want.
prevIndex: vout, // TODO verify this is what we want.
pubKey: pubKey, // TODO fix public key.
amount: value,
);
}
/// Converts a Stack Wallet UTXO to a FusionDart Output.
fusion_output.Output toFusionOutput({required String address}) {
return fusion_output.Output(
addr: fusion_address.Address(
addr: address,
publicKey: utf8.encode(address.toString()), // TODO fix public key.
derivationPath: null, // TODO fix derivation path.
),
value: value,
);
}
}
/// An extension of Stack Wallet's Transaction class that adds CashFusion functionality. /// An extension of Stack Wallet's Transaction class that adds CashFusion functionality.
extension FusionTransaction on Transaction { extension FusionTransaction on Transaction {
// WIP. // WIP.
@ -480,31 +520,3 @@ extension FusionTransaction on Transaction {
return fusionTransaction; return fusionTransaction;
} }
} }
/// An extension of Stack Wallet's UTXO class that adds CashFusion functionality.
///
/// This class is used to convert Stack Wallet's UTXO class to FusionDart's
/// Input and Output classes.
extension FusionUTXO on UTXO {
/// Converts a Stack Wallet UTXO to a FusionDart Input.
fusion_input.Input toFusionInput({required List<int> pubKey}) {
return fusion_input.Input(
prevTxid: utf8.encode(txid), // TODO verify this is what we want.
prevIndex: vout, // TODO verify this is what we want.
pubKey: pubKey, // TODO fix public key.
amount: value,
);
}
/// Converts a Stack Wallet UTXO to a FusionDart Output.
fusion_output.Output toFusionOutput({required String address}) {
return fusion_output.Output(
addr: fusion_address.Address(
addr: address,
publicKey: utf8.encode(address.toString()), // TODO fix public key.
derivationPath: null, // TODO fix derivation path.
),
value: value,
);
}
}