2021-12-24 12:52:08 +00:00
|
|
|
part of 'monero.dart';
|
|
|
|
|
|
|
|
class CWMoneroAccountList extends MoneroAccountList {
|
2023-08-24 13:54:05 +00:00
|
|
|
CWMoneroAccountList(this._wallet);
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-08-24 13:54:05 +00:00
|
|
|
final Object _wallet;
|
|
|
|
|
|
|
|
@override
|
|
|
|
@computed
|
2021-12-24 12:52:08 +00:00
|
|
|
ObservableList<Account> get accounts {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = _wallet as MoneroWallet;
|
|
|
|
final accounts = moneroWallet.walletAddresses.accountList.accounts
|
|
|
|
.map((acc) => Account(id: acc.id, label: acc.label, balance: acc.balance))
|
|
|
|
.toList();
|
|
|
|
return ObservableList<Account>.of(accounts);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void update(Object wallet) {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.accountList.update();
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-08-24 13:54:05 +00:00
|
|
|
void refresh(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.accountList.refresh();
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-08-24 13:54:05 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
List<Account> getAll(Object wallet) {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.walletAddresses.accountList
|
|
|
|
.getAll()
|
|
|
|
.map((acc) => Account(id: acc.id, label: acc.label, balance: acc.balance))
|
|
|
|
.toList();
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<void> addAccount(Object wallet, {required String label}) async {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
await moneroWallet.walletAddresses.accountList.addAccount(label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-08-24 13:54:05 +00:00
|
|
|
Future<void> setLabelAccount(Object wallet,
|
|
|
|
{required int accountIndex, required String label}) async {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
await moneroWallet.walletAddresses.accountList
|
|
|
|
.setLabelAccount(accountIndex: accountIndex, label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CWMoneroSubaddressList extends MoneroSubaddressList {
|
2023-08-24 13:54:05 +00:00
|
|
|
CWMoneroSubaddressList(this._wallet);
|
|
|
|
|
|
|
|
final Object _wallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-08-24 13:54:05 +00:00
|
|
|
@override
|
|
|
|
@computed
|
2021-12-24 12:52:08 +00:00
|
|
|
ObservableList<Subaddress> get subaddresses {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = _wallet as MoneroWallet;
|
|
|
|
final subAddresses = moneroWallet.walletAddresses.subaddressList.subaddresses
|
|
|
|
.map((sub) => Subaddress(id: sub.id, address: sub.address, label: sub.label))
|
|
|
|
.toList();
|
|
|
|
return ObservableList<Subaddress>.of(subAddresses);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
void update(Object wallet, {required int accountIndex}) {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.subaddressList.update(accountIndex: accountIndex);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
void refresh(Object wallet, {required int accountIndex}) {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.subaddressList.refresh(accountIndex: accountIndex);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Subaddress> getAll(Object wallet) {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.walletAddresses.subaddressList
|
|
|
|
.getAll()
|
|
|
|
.map((sub) => Subaddress(id: sub.id, label: sub.label, address: sub.address))
|
|
|
|
.toList();
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-08-24 13:54:05 +00:00
|
|
|
Future<void> addSubaddress(Object wallet,
|
|
|
|
{required int accountIndex, required String label}) async {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
await moneroWallet.walletAddresses.subaddressList
|
|
|
|
.addSubaddress(accountIndex: accountIndex, label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> setLabelSubaddress(Object wallet,
|
2022-10-12 17:09:57 +00:00
|
|
|
{required int accountIndex, required int addressIndex, required String label}) async {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
await moneroWallet.walletAddresses.subaddressList
|
|
|
|
.setLabelSubaddress(accountIndex: accountIndex, addressIndex: addressIndex, label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CWMoneroWalletDetails extends MoneroWalletDetails {
|
2023-08-24 13:54:05 +00:00
|
|
|
CWMoneroWalletDetails(this._wallet);
|
|
|
|
|
|
|
|
final Object _wallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-08-24 13:54:05 +00:00
|
|
|
@computed
|
2022-10-12 17:09:57 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
Account get account {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = _wallet as MoneroWallet;
|
|
|
|
final acc = moneroWallet.walletAddresses.account;
|
|
|
|
return Account(id: acc!.id, label: acc.label, balance: acc.balance);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
2022-10-12 17:09:57 +00:00
|
|
|
@override
|
2023-08-24 13:54:05 +00:00
|
|
|
MoneroBalance get balance {
|
2022-10-12 17:09:57 +00:00
|
|
|
throw Exception('Unimplemented');
|
2023-08-24 13:54:05 +00:00
|
|
|
// return MoneroBalance();
|
|
|
|
//return MoneroBalance(
|
|
|
|
// fullBalance: balance.fullBalance,
|
|
|
|
// unlockedBalance: balance.unlockedBalance);
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class CWMonero extends Monero {
|
2022-10-12 17:09:57 +00:00
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
MoneroAccountList getAccountList(Object wallet) => CWMoneroAccountList(wallet);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
MoneroSubaddressList getSubaddressList(Object wallet) => CWMoneroSubaddressList(wallet);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
TransactionHistoryBase getTransactionHistory(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.transactionHistory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
MoneroWalletDetails getMoneroWalletDetails(Object wallet) => CWMoneroWalletDetails(wallet);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
int getHeightByDate({required DateTime date}) => getMoneroHeigthByDate(date: date);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
TransactionPriority getDefaultTransactionPriority() => MoneroTransactionPriority.automatic;
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
TransactionPriority getMoneroTransactionPrioritySlow() => MoneroTransactionPriority.slow;
|
|
|
|
|
|
|
|
@override
|
|
|
|
TransactionPriority getMoneroTransactionPriorityAutomatic() =>
|
|
|
|
MoneroTransactionPriority.automatic;
|
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
TransactionPriority deserializeMoneroTransactionPriority({required int raw}) =>
|
|
|
|
MoneroTransactionPriority.deserialize(raw: raw);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
List<TransactionPriority> getTransactionPriorities() => MoneroTransactionPriority.all;
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
List<String> getMoneroWordList(String language) {
|
2023-11-25 00:37:12 +00:00
|
|
|
if (language.startsWith("POLYSEED_")) {
|
|
|
|
final lang = language.replaceAll("POLYSEED_", "");
|
|
|
|
return PolyseedLang.getByEnglishName(lang).words;
|
|
|
|
}
|
2023-08-24 13:54:05 +00:00
|
|
|
switch (language.toLowerCase()) {
|
|
|
|
case 'english':
|
|
|
|
return EnglishMnemonics.words;
|
|
|
|
case 'chinese (simplified)':
|
|
|
|
return ChineseSimplifiedMnemonics.words;
|
|
|
|
case 'dutch':
|
|
|
|
return DutchMnemonics.words;
|
|
|
|
case 'german':
|
|
|
|
return GermanMnemonics.words;
|
|
|
|
case 'japanese':
|
|
|
|
return JapaneseMnemonics.words;
|
|
|
|
case 'portuguese':
|
|
|
|
return PortugueseMnemonics.words;
|
|
|
|
case 'russian':
|
|
|
|
return RussianMnemonics.words;
|
|
|
|
case 'spanish':
|
|
|
|
return SpanishMnemonics.words;
|
|
|
|
case 'french':
|
|
|
|
return FrenchMnemonics.words;
|
|
|
|
case 'italian':
|
|
|
|
return ItalianMnemonics.words;
|
|
|
|
default:
|
|
|
|
return EnglishMnemonics.words;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
WalletCredentials createMoneroRestoreWalletFromKeysCredentials(
|
2023-11-02 15:52:47 +00:00
|
|
|
{required String name,
|
|
|
|
required String spendKey,
|
|
|
|
required String viewKey,
|
|
|
|
required String address,
|
|
|
|
required String password,
|
|
|
|
required String language,
|
|
|
|
required int height}) =>
|
|
|
|
MoneroRestoreWalletFromKeysCredentials(
|
|
|
|
name: name,
|
|
|
|
spendKey: spendKey,
|
|
|
|
viewKey: viewKey,
|
|
|
|
address: address,
|
|
|
|
password: password,
|
|
|
|
language: language,
|
|
|
|
height: height);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
WalletCredentials createMoneroRestoreWalletFromSeedCredentials(
|
2023-11-02 15:52:47 +00:00
|
|
|
{required String name,
|
|
|
|
required String password,
|
|
|
|
required int height,
|
|
|
|
required String mnemonic}) =>
|
|
|
|
MoneroRestoreWalletFromSeedCredentials(
|
|
|
|
name: name, password: password, height: height, mnemonic: mnemonic);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
WalletCredentials createMoneroNewWalletCredentials({
|
2022-10-12 17:09:57 +00:00
|
|
|
required String name,
|
|
|
|
required String language,
|
2023-11-25 00:37:12 +00:00
|
|
|
required bool isPolyseed,
|
2023-11-02 15:52:47 +00:00
|
|
|
String? password}) =>
|
2023-11-25 00:37:12 +00:00
|
|
|
MoneroNewWalletCredentials(
|
|
|
|
name: name, password: password, language: language, isPolyseed: isPolyseed);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, String> getKeys(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
final keys = moneroWallet.keys;
|
|
|
|
return <String, String>{
|
|
|
|
'privateSpendKey': keys.privateSpendKey,
|
2021-12-24 12:52:08 +00:00
|
|
|
'privateViewKey': keys.privateViewKey,
|
|
|
|
'publicSpendKey': keys.publicSpendKey,
|
2023-08-24 13:54:05 +00:00
|
|
|
'publicViewKey': keys.publicViewKey
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Object createMoneroTransactionCreationCredentials(
|
2023-11-02 15:52:47 +00:00
|
|
|
{required List<Output> outputs, required TransactionPriority priority}) =>
|
|
|
|
MoneroTransactionCreationCredentials(
|
|
|
|
outputs: 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 MoneroTransactionPriority);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Object createMoneroTransactionCreationCredentialsRaw(
|
2023-11-02 15:52:47 +00:00
|
|
|
{required List<OutputInfo> outputs, required TransactionPriority priority}) =>
|
|
|
|
MoneroTransactionCreationCredentials(
|
|
|
|
outputs: outputs, priority: priority as MoneroTransactionPriority);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
String formatterMoneroAmountToString({required int amount}) =>
|
|
|
|
moneroAmountToString(amount: amount);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
double formatterMoneroAmountToDouble({required int amount}) =>
|
|
|
|
moneroAmountToDouble(amount: amount);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
int formatterMoneroParseAmount({required String amount}) => moneroParseAmount(amount: amount);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Account getCurrentAccount(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
final acc = moneroWallet.walletAddresses.account;
|
|
|
|
return Account(id: acc!.id, label: acc.label, balance: acc.balance);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void setCurrentAccount(Object wallet, int id, String label, String? balance) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.account =
|
|
|
|
monero_account.Account(id: id, label: label, balance: balance);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-11-02 15:52:47 +00:00
|
|
|
void onStartup() => monero_wallet_api.onStartup();
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
int getTransactionInfoAccountId(TransactionInfo tx) {
|
|
|
|
final moneroTransactionInfo = tx as MoneroTransactionInfo;
|
|
|
|
return moneroTransactionInfo.accountIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
WalletService createMoneroWalletService(
|
2023-11-02 15:52:47 +00:00
|
|
|
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource) =>
|
|
|
|
MoneroWalletService(walletInfoSource, unspentCoinSource);
|
2023-08-24 13:54:05 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.getTransactionAddress(accountIndex, addressIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String getSubaddressLabel(Object wallet, int accountIndex, int addressIndex) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.getSubaddressLabel(accountIndex, addressIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, String> pendingTransactionInfo(Object transaction) {
|
|
|
|
final ptx = transaction as PendingMoneroTransaction;
|
|
|
|
return {'id': ptx.id, 'hex': ptx.hex, 'key': ptx.txKey};
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Unspent> getUnspents(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
2023-11-15 23:12:23 +00:00
|
|
|
return moneroWallet.unspentCoins;
|
2023-08-24 13:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2024-01-30 17:57:47 +00:00
|
|
|
Future<void> updateUnspents(Object wallet) async {
|
2023-08-24 13:54:05 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
await moneroWallet.updateUnspent();
|
|
|
|
}
|
2023-09-27 17:33:40 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<int> getCurrentHeight() async {
|
|
|
|
return monero_wallet.getCurrentHeight();
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|