2021-12-24 12:52:08 +00:00
|
|
|
part of 'monero.dart';
|
|
|
|
|
|
|
|
class CWMoneroAccountList extends MoneroAccountList {
|
|
|
|
CWMoneroAccountList(this._wallet);
|
2022-07-28 17:03:16 +00:00
|
|
|
final Object _wallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
@computed
|
|
|
|
ObservableList<Account> get accounts {
|
|
|
|
final moneroWallet = _wallet as MoneroWallet;
|
|
|
|
final accounts = moneroWallet.walletAddresses.accountList
|
|
|
|
.accounts
|
|
|
|
.map((acc) => Account(id: acc.id, label: acc.label))
|
|
|
|
.toList();
|
|
|
|
return ObservableList<Account>.of(accounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void update(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.accountList.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void refresh(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.accountList.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Account> getAll(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.walletAddresses.accountList
|
|
|
|
.getAll()
|
|
|
|
.map((acc) => Account(id: acc.id, label: acc.label))
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<void> addAccount(Object wallet, {required String label}) async {
|
2021-12-24 12:52:08 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
2022-07-28 17:03:16 +00:00
|
|
|
await moneroWallet.walletAddresses.accountList.addAccount(label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label}) async {
|
2021-12-24 12:52:08 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
2022-07-28 17:03:16 +00:00
|
|
|
await moneroWallet.walletAddresses.accountList
|
2021-12-24 12:52:08 +00:00
|
|
|
.setLabelAccount(
|
|
|
|
accountIndex: accountIndex,
|
|
|
|
label: label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CWMoneroSubaddressList extends MoneroSubaddressList {
|
|
|
|
CWMoneroSubaddressList(this._wallet);
|
2022-10-12 17:09:57 +00:00
|
|
|
final Object _wallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
@computed
|
|
|
|
ObservableList<Subaddress> get subaddresses {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
void update(Object wallet, {required int accountIndex}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.subaddressList.update(accountIndex: accountIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
void refresh(Object wallet, {required int accountIndex}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
moneroWallet.walletAddresses.subaddressList.refresh(accountIndex: accountIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Subaddress> getAll(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.walletAddresses
|
|
|
|
.subaddressList
|
|
|
|
.getAll()
|
|
|
|
.map((sub) => Subaddress(id: sub.id, label: sub.label, address: sub.address))
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<void> addSubaddress(Object wallet, {required int accountIndex, required String label}) async {
|
2021-12-24 12:52:08 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
2022-07-28 17:03:16 +00:00
|
|
|
await moneroWallet.walletAddresses.subaddressList
|
2021-12-24 12:52:08 +00:00
|
|
|
.addSubaddress(
|
|
|
|
accountIndex: accountIndex,
|
|
|
|
label: label);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> setLabelSubaddress(Object wallet,
|
2022-10-12 17:09:57 +00:00
|
|
|
{required int accountIndex, required int addressIndex, required String label}) async {
|
2021-12-24 12:52:08 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
2022-07-28 17:03:16 +00:00
|
|
|
await moneroWallet.walletAddresses.subaddressList
|
2021-12-24 12:52:08 +00:00
|
|
|
.setLabelSubaddress(
|
|
|
|
accountIndex: accountIndex,
|
|
|
|
addressIndex: addressIndex,
|
|
|
|
label: label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CWMoneroWalletDetails extends MoneroWalletDetails {
|
|
|
|
CWMoneroWalletDetails(this._wallet);
|
2022-10-12 17:09:57 +00:00
|
|
|
final Object _wallet;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@computed
|
2022-10-12 17:09:57 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
Account get account {
|
|
|
|
final moneroWallet = _wallet as MoneroWallet;
|
|
|
|
final acc = moneroWallet.walletAddresses.account;
|
2022-10-12 17:09:57 +00:00
|
|
|
return Account(id: acc!.id, label: acc.label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
2022-10-12 17:09:57 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
MoneroBalance get balance {
|
|
|
|
final moneroWallet = _wallet as MoneroWallet;
|
|
|
|
final balance = moneroWallet.balance;
|
2022-10-12 17:09:57 +00:00
|
|
|
throw Exception('Unimplemented');
|
|
|
|
// return MoneroBalance();
|
2022-03-30 15:57:04 +00:00
|
|
|
//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
|
2021-12-24 12:52:08 +00:00
|
|
|
MoneroAccountList getAccountList(Object wallet) {
|
|
|
|
return CWMoneroAccountList(wallet);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
MoneroSubaddressList getSubaddressList(Object wallet) {
|
|
|
|
return CWMoneroSubaddressList(wallet);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
TransactionHistoryBase getTransactionHistory(Object wallet) {
|
2021-12-31 13:05:27 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.transactionHistory;
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
MoneroWalletDetails getMoneroWalletDetails(Object wallet) {
|
|
|
|
return CWMoneroWalletDetails(wallet);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
int getHeigthByDate({required DateTime date}) {
|
2021-12-31 13:05:27 +00:00
|
|
|
return getMoneroHeigthByDate(date: date);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
TransactionPriority getDefaultTransactionPriority() {
|
|
|
|
return MoneroTransactionPriority.slow;
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
TransactionPriority deserializeMoneroTransactionPriority({required int raw}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return MoneroTransactionPriority.deserialize(raw: raw);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
List<TransactionPriority> getTransactionPriorities() {
|
|
|
|
return MoneroTransactionPriority.all;
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
List<String> getMoneroWordList(String language) {
|
2022-01-19 14:25:58 +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;
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
WalletCredentials createMoneroRestoreWalletFromKeysCredentials({
|
2022-10-12 17:09:57 +00:00
|
|
|
required String name,
|
|
|
|
required String spendKey,
|
|
|
|
required String viewKey,
|
|
|
|
required String address,
|
|
|
|
required String password,
|
|
|
|
required String language,
|
|
|
|
required int height}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return MoneroRestoreWalletFromKeysCredentials(
|
|
|
|
name: name,
|
|
|
|
spendKey: spendKey,
|
|
|
|
viewKey: viewKey,
|
|
|
|
address: address,
|
|
|
|
password: password,
|
|
|
|
language: language,
|
|
|
|
height: height);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
WalletCredentials createMoneroRestoreWalletFromSeedCredentials({
|
|
|
|
required String name,
|
|
|
|
required String password,
|
|
|
|
required int height,
|
|
|
|
required String mnemonic}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return MoneroRestoreWalletFromSeedCredentials(
|
|
|
|
name: name,
|
|
|
|
password: password,
|
|
|
|
height: height,
|
|
|
|
mnemonic: mnemonic);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
WalletCredentials createMoneroNewWalletCredentials({
|
|
|
|
required String name,
|
|
|
|
required String language,
|
|
|
|
String? password,}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return MoneroNewWalletCredentials(
|
|
|
|
name: name,
|
|
|
|
password: password,
|
|
|
|
language: language);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
Map<String, String> getKeys(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
final keys = moneroWallet.keys;
|
|
|
|
return <String, String>{
|
|
|
|
'privateSpendKey': keys.privateSpendKey,
|
|
|
|
'privateViewKey': keys.privateViewKey,
|
|
|
|
'publicSpendKey': keys.publicSpendKey,
|
|
|
|
'publicViewKey': keys.publicViewKey};
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Object createMoneroTransactionCreationCredentials({
|
|
|
|
required List<Output> outputs,
|
|
|
|
required TransactionPriority priority}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return 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);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
Object createMoneroTransactionCreationCredentialsRaw({
|
|
|
|
required List<OutputInfo> outputs,
|
|
|
|
required TransactionPriority priority}) {
|
2022-07-28 17:03:16 +00:00
|
|
|
return MoneroTransactionCreationCredentials(
|
|
|
|
outputs: outputs,
|
|
|
|
priority: priority as MoneroTransactionPriority);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
String formatterMoneroAmountToString({required int amount}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return moneroAmountToString(amount: amount);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
double formatterMoneroAmountToDouble({required int amount}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return moneroAmountToDouble(amount: amount);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-10-12 17:09:57 +00:00
|
|
|
int formatterMoneroParseAmount({required String amount}) {
|
2021-12-24 12:52:08 +00:00
|
|
|
return moneroParseAmount(amount: amount);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
Account getCurrentAccount(Object wallet) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
final acc = moneroWallet.walletAddresses.account;
|
2022-10-12 17:09:57 +00:00
|
|
|
return Account(id: acc!.id, label: acc.label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-03-30 15:57:04 +00:00
|
|
|
void setCurrentAccount(Object wallet, int id, String label) {
|
2021-12-24 12:52:08 +00:00
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
2022-03-30 15:57:04 +00:00
|
|
|
moneroWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
void onStartup() {
|
|
|
|
monero_wallet_api.onStartup();
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
int getTransactionInfoAccountId(TransactionInfo tx) {
|
|
|
|
final moneroTransactionInfo = tx as MoneroTransactionInfo;
|
|
|
|
return moneroTransactionInfo.accountIndex;
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2021-12-24 12:52:08 +00:00
|
|
|
WalletService createMoneroWalletService(Box<WalletInfo> walletInfoSource) {
|
|
|
|
return MoneroWalletService(walletInfoSource);
|
|
|
|
}
|
2022-01-31 12:08:38 +00:00
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-01-31 12:08:38 +00:00
|
|
|
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.getTransactionAddress(accountIndex, addressIndex);
|
|
|
|
}
|
2022-04-12 15:38:47 +00:00
|
|
|
|
2022-07-28 17:03:16 +00:00
|
|
|
@override
|
2022-04-12 15:38:47 +00:00
|
|
|
String getSubaddressLabel(Object wallet, int accountIndex, int addressIndex) {
|
|
|
|
final moneroWallet = wallet as MoneroWallet;
|
|
|
|
return moneroWallet.getSubaddressLabel(accountIndex, addressIndex);
|
|
|
|
}
|
2022-07-28 17:03:16 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Map<String, String> pendingTransactionInfo(Object transaction) {
|
|
|
|
final ptx = transaction as PendingMoneroTransaction;
|
|
|
|
return {'id': ptx.id, 'hex': ptx.hex, 'key': ptx.txKey};
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|