cake_wallet/lib/decred/cw_decred.dart

138 lines
4.2 KiB
Dart
Raw Normal View History

part of 'decred.dart';
class CWDecred extends Decred {
CWDecred() {
// initialize the service for creating and loading dcr wallets.
DecredWalletService.init();
}
@override
WalletCredentials createDecredNewWalletCredentials(
{required String name, WalletInfo? walletInfo}) =>
DecredNewWalletCredentials(name: name, walletInfo: walletInfo);
@override
WalletCredentials createDecredRestoreWalletFromSeedCredentials(
{required String name,
required String mnemonic,
required String password}) =>
DecredRestoreWalletFromSeedCredentials(
name: name, mnemonic: mnemonic, password: password);
2024-03-14 08:36:51 +00:00
@override
WalletCredentials createDecredRestoreWalletFromPubkeyCredentials(
{required String name,
required String pubkey,
required String password}) =>
DecredRestoreWalletFromPubkeyCredentials(
name: name, pubkey: pubkey, password: password);
@override
2024-02-06 10:58:19 +00:00
WalletService createDecredWalletService(Box<WalletInfo> walletInfoSource,
Box<UnspentCoinsInfo> unspentCoinSource) {
return DecredWalletService(walletInfoSource, unspentCoinSource);
}
@override
List<TransactionPriority> getTransactionPriorities() =>
DecredTransactionPriority.all;
@override
TransactionPriority getMediumTransactionPriority() =>
DecredTransactionPriority.medium;
@override
TransactionPriority getDecredTransactionPriorityMedium() =>
DecredTransactionPriority.medium;
@override
TransactionPriority getDecredTransactionPrioritySlow() =>
DecredTransactionPriority.slow;
@override
TransactionPriority deserializeDecredTransactionPriority(int raw) =>
DecredTransactionPriority.deserialize(raw: raw);
@override
int getFeeRate(Object wallet, TransactionPriority priority) {
final decredWallet = wallet as DecredWallet;
return decredWallet.feeRate(priority);
}
@override
Object createDecredTransactionCredentials(
List<Output> outputs, TransactionPriority priority) =>
DecredTransactionCredentials(
outputs
.map((out) => OutputInfo(
fiatAmount: out.fiatAmount,
cryptoAmount: out.cryptoAmount,
address: out.address,
note: out.note,
sendAll: out.sendAll,
extractedAddress: out.extractedAddress,
isParsedAddress: out.isParsedAddress,
formattedCryptoAmount: out.formattedCryptoAmount))
.toList(),
priority: priority as DecredTransactionPriority);
@override
List<String> getAddresses(Object wallet) {
final decredWallet = wallet as DecredWallet;
return decredWallet.walletAddresses.addresses();
}
@override
String getAddress(Object wallet) {
final decredWallet = wallet as DecredWallet;
return decredWallet.walletAddresses.address;
}
@override
Future<void> generateNewAddress(Object wallet) async {
final decredWallet = wallet as DecredWallet;
await decredWallet.walletAddresses.generateNewAddress();
}
@override
String formatterDecredAmountToString({required int amount}) =>
decredAmountToString(amount: amount);
@override
double formatterDecredAmountToDouble({required int amount}) =>
decredAmountToDouble(amount: amount);
@override
int formatterStringDoubleToDecredAmount(String amount) =>
stringDoubleToDecredAmount(amount);
@override
List<Unspent> getUnspents(Object wallet) {
final decredWallet = wallet as DecredWallet;
return decredWallet.unspents();
}
2024-03-05 07:01:16 +00:00
@override
void updateUnspents(Object wallet) async {}
2024-03-05 07:01:16 +00:00
@override
int heightByDate(DateTime date) {
final genesisBlocktime =
DateTime.fromMillisecondsSinceEpoch(1454954400 * 1000);
final minutesDiff = date.difference(genesisBlocktime).inMinutes;
// Decred has five minute blocks on mainnet.
// NOTE: This is off by about a day.
// TODO: Remove this and just rescan from the wallet birthday.
return (minutesDiff / 5).toInt();
}
2024-03-12 07:52:54 +00:00
2024-03-14 08:36:51 +00:00
@override
List<String> getDecredWordList() => wordlist;
@override
String pubkey(Object wallet) {
final decredWallet = wallet as DecredWallet;
return decredWallet.pubkey;
}
}