mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 20:39:51 +00:00
fix(cw_tari): initial implementation
This commit is contained in:
parent
eab91de9f6
commit
7fbffc8dc9
10 changed files with 339 additions and 1 deletions
31
cw_tari/.gitignore
vendored
Normal file
31
cw_tari/.gitignore
vendored
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Miscellaneous
|
||||||
|
*.class
|
||||||
|
*.log
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
.DS_Store
|
||||||
|
.atom/
|
||||||
|
.buildlog/
|
||||||
|
.history
|
||||||
|
.svn/
|
||||||
|
migrate_working_dir/
|
||||||
|
|
||||||
|
# IntelliJ related
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# The .vscode folder contains launch configuration and tasks you configure in
|
||||||
|
# VS Code which you may wish to be included in version control, so this line
|
||||||
|
# is commented out by default.
|
||||||
|
#.vscode/
|
||||||
|
|
||||||
|
# Flutter/Dart/Pub related
|
||||||
|
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||||
|
/pubspec.lock
|
||||||
|
**/doc/api/
|
||||||
|
.dart_tool/
|
||||||
|
.flutter-plugins
|
||||||
|
.flutter-plugins-dependencies
|
||||||
|
build/
|
10
cw_tari/.metadata
Normal file
10
cw_tari/.metadata
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# This file tracks properties of this Flutter project.
|
||||||
|
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||||
|
#
|
||||||
|
# This file should be version controlled and should not be manually edited.
|
||||||
|
|
||||||
|
version:
|
||||||
|
revision: "8495dee1fd4aacbe9de707e7581203232f591b2f"
|
||||||
|
channel: "stable"
|
||||||
|
|
||||||
|
project_type: package
|
3
cw_tari/CHANGELOG.md
Normal file
3
cw_tari/CHANGELOG.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
## 0.0.1
|
||||||
|
|
||||||
|
* TODO: Describe initial release.
|
1
cw_tari/README.md
Normal file
1
cw_tari/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# cw_tari
|
4
cw_tari/analysis_options.yaml
Normal file
4
cw_tari/analysis_options.yaml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
include: package:flutter_lints/flutter.yaml
|
||||||
|
|
||||||
|
# Additional information about this file can be found at
|
||||||
|
# https://dart.dev/guides/language/analysis-options
|
36
cw_tari/lib/tari_balance.dart
Normal file
36
cw_tari/lib/tari_balance.dart
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import 'package:cw_core/balance.dart';
|
||||||
|
import 'package:cw_core/monero_amount_format.dart';
|
||||||
|
|
||||||
|
class TariBalance extends Balance {
|
||||||
|
TariBalance({required this.fullBalance, required this.unlockedBalance})
|
||||||
|
: formattedUnconfirmedBalance =
|
||||||
|
moneroAmountToString(amount: fullBalance - unlockedBalance),
|
||||||
|
formattedUnlockedBalance =
|
||||||
|
moneroAmountToString(amount: unlockedBalance),
|
||||||
|
super(unlockedBalance, fullBalance);
|
||||||
|
|
||||||
|
factory TariBalance.fromFfi((int, int, int, int) result) {
|
||||||
|
final availableBalance = result.$1;
|
||||||
|
final pendingIncoming = result.$2;
|
||||||
|
final pendingOutgoing = result.$3;
|
||||||
|
final timeLockedBalance = result.$4;
|
||||||
|
|
||||||
|
return TariBalance(
|
||||||
|
fullBalance: availableBalance +
|
||||||
|
pendingIncoming +
|
||||||
|
pendingOutgoing +
|
||||||
|
timeLockedBalance,
|
||||||
|
unlockedBalance: availableBalance);
|
||||||
|
}
|
||||||
|
|
||||||
|
final int fullBalance;
|
||||||
|
final int unlockedBalance;
|
||||||
|
final String formattedUnconfirmedBalance;
|
||||||
|
final String formattedUnlockedBalance;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get formattedAvailableBalance => formattedUnlockedBalance;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get formattedAdditionalBalance => formattedUnconfirmedBalance;
|
||||||
|
}
|
192
cw_tari/lib/tari_wallet.dart
Normal file
192
cw_tari/lib/tari_wallet.dart
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
|
import 'package:cw_core/node.dart';
|
||||||
|
import 'package:cw_core/pending_transaction.dart';
|
||||||
|
import 'package:cw_core/sync_status.dart';
|
||||||
|
import 'package:cw_core/transaction_priority.dart';
|
||||||
|
import 'package:cw_core/wallet_addresses.dart';
|
||||||
|
import 'package:cw_core/wallet_base.dart';
|
||||||
|
import 'package:cw_core/wallet_info.dart';
|
||||||
|
import 'package:cw_core/wallet_keys_file.dart';
|
||||||
|
import 'package:cw_tari/tari_balance.dart';
|
||||||
|
import 'package:cw_tari/tari_wallet_addresses.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
import 'package:tari/tari.dart';
|
||||||
|
|
||||||
|
part 'tari_wallet.g.dart';
|
||||||
|
|
||||||
|
abstract class TariWallet = TariWalletBase with _$TariWallet;
|
||||||
|
|
||||||
|
abstract class TariWalletBase extends WalletBase<
|
||||||
|
TariBalance,
|
||||||
|
EVMChainTransactionHistory,
|
||||||
|
EVMChainTransactionInfo> with Store, WalletKeysFile {
|
||||||
|
TariWalletBase({
|
||||||
|
required WalletInfo walletInfo,
|
||||||
|
required String password,
|
||||||
|
required TariWalletFfi walletFfi,
|
||||||
|
}) : syncStatus = const NotConnectedSyncStatus(),
|
||||||
|
walletAddresses = TariWalletAddresses(walletInfo),
|
||||||
|
_password = password,
|
||||||
|
_walletFfi = walletFfi,
|
||||||
|
balance = ObservableMap<CryptoCurrency, TariBalance>.of({
|
||||||
|
CryptoCurrency.tari: TariBalance.fromFfi(walletFfi.getBalance()),
|
||||||
|
}),
|
||||||
|
super(walletInfo) {
|
||||||
|
this.walletInfo = walletInfo;
|
||||||
|
transactionHistory =
|
||||||
|
setUpTransactionHistory(walletInfo, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
final TariWalletFfi _walletFfi;
|
||||||
|
final String _password;
|
||||||
|
|
||||||
|
@override
|
||||||
|
WalletAddresses walletAddresses;
|
||||||
|
|
||||||
|
@override
|
||||||
|
@observable
|
||||||
|
SyncStatus syncStatus;
|
||||||
|
|
||||||
|
@override
|
||||||
|
@observable
|
||||||
|
late ObservableMap<CryptoCurrency, TariBalance> balance;
|
||||||
|
|
||||||
|
Future<void> init() async {
|
||||||
|
await walletAddresses.init();
|
||||||
|
await transactionHistory.init();
|
||||||
|
|
||||||
|
await save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int calculateEstimatedFee(TransactionPriority priority, int? amount) {
|
||||||
|
return 0; // ToDo
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> changePassword(String password) =>
|
||||||
|
throw UnimplementedError("changePassword");
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close({bool shouldCleanup = false}) async {
|
||||||
|
_walletFfi.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
@override
|
||||||
|
Future<void> connectToNode({required Node node}) async {
|
||||||
|
try {
|
||||||
|
syncStatus = ConnectingSyncStatus();
|
||||||
|
|
||||||
|
// ToDo
|
||||||
|
|
||||||
|
syncStatus = ConnectedSyncStatus();
|
||||||
|
} catch (e) {
|
||||||
|
syncStatus = FailedSyncStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
@override
|
||||||
|
Future<void> startSync() async {
|
||||||
|
try {
|
||||||
|
syncStatus = AttemptingSyncStatus();
|
||||||
|
|
||||||
|
// ToDo
|
||||||
|
|
||||||
|
syncStatus = SyncedSyncStatus();
|
||||||
|
} catch (e) {
|
||||||
|
syncStatus = FailedSyncStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<PendingTransaction> createTransaction(Object credentials) async {
|
||||||
|
// ToDo
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Map<String, EVMChainTransactionInfo>> fetchTransactions() async {
|
||||||
|
// ToDo
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Object get keys => throw UnimplementedError("keys");
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> rescan({required int height}) {
|
||||||
|
throw UnimplementedError("rescan");
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> save() async {
|
||||||
|
await walletAddresses.updateAddressesInBox();
|
||||||
|
await transactionHistory.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get seed => _walletFfi.getMnemonic();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get privateKey => null;
|
||||||
|
|
||||||
|
@override
|
||||||
|
WalletKeysData get walletKeysData => WalletKeysData(
|
||||||
|
mnemonic: seed,
|
||||||
|
privateKey: privateKey,
|
||||||
|
passphrase: passphrase,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> updateBalance() async {
|
||||||
|
balance[CryptoCurrency.tari] = TariBalance.fromFfi(_walletFfi.getBalance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> renameWalletFiles(String newWalletName) async {
|
||||||
|
// final transactionHistoryFileNameForWallet = getTransactionHistoryFileName();
|
||||||
|
//
|
||||||
|
// final currentWalletPath =
|
||||||
|
// await pathForWallet(name: walletInfo.name, type: type);
|
||||||
|
// final currentWalletFile = File(currentWalletPath);
|
||||||
|
//
|
||||||
|
// final currentDirPath =
|
||||||
|
// await pathForWalletDir(name: walletInfo.name, type: type);
|
||||||
|
// final currentTransactionsFile =
|
||||||
|
// File('$currentDirPath/$transactionHistoryFileNameForWallet');
|
||||||
|
//
|
||||||
|
// // Copies current wallet files into new wallet name's dir and files
|
||||||
|
// if (currentWalletFile.existsSync()) {
|
||||||
|
// final newWalletPath =
|
||||||
|
// await pathForWallet(name: newWalletName, type: type);
|
||||||
|
// await currentWalletFile.copy(newWalletPath);
|
||||||
|
// }
|
||||||
|
// if (currentTransactionsFile.existsSync()) {
|
||||||
|
// final newDirPath =
|
||||||
|
// await pathForWalletDir(name: newWalletName, type: type);
|
||||||
|
// await currentTransactionsFile
|
||||||
|
// .copy('$newDirPath/$transactionHistoryFileNameForWallet');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Delete old name's dir and files
|
||||||
|
// await Directory(currentDirPath).delete(recursive: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<String> signMessage(String message, {String? address}) async =>
|
||||||
|
_walletFfi.signMessage(message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> verifyMessage(String message, String signature,
|
||||||
|
{String? address}) async {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get password => _password;
|
||||||
|
}
|
36
cw_tari/lib/tari_wallet_addresses.dart
Normal file
36
cw_tari/lib/tari_wallet_addresses.dart
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:cw_core/wallet_addresses.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
|
||||||
|
part 'tari_addresses.g.dart';
|
||||||
|
|
||||||
|
class TariWalletAddresses = TariWalletAddressesBase with _$TariWalletAddresses;
|
||||||
|
|
||||||
|
abstract class TariWalletAddressesBase extends WalletAddresses with Store {
|
||||||
|
TariWalletAddressesBase(super.walletInfo) : address = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
@observable
|
||||||
|
String address;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get primaryAddress => address;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> init() async {
|
||||||
|
address = walletInfo.address;
|
||||||
|
await updateAddressesInBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> updateAddressesInBox() async {
|
||||||
|
try {
|
||||||
|
addressesMap.clear();
|
||||||
|
addressesMap[address] = '';
|
||||||
|
await saveAddressesInBox();
|
||||||
|
} catch (e) {
|
||||||
|
log(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
cw_tari/pubspec.yaml
Normal file
25
cw_tari/pubspec.yaml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
name: cw_tari
|
||||||
|
description: "A CakeWallet Package for Tari"
|
||||||
|
version: 0.0.0
|
||||||
|
publish_to: none
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: ^3.6.0
|
||||||
|
flutter: ">=1.17.0"
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
cw_core:
|
||||||
|
path: ../cw_core
|
||||||
|
hive: ^2.2.3
|
||||||
|
mobx: ^2.0.7+4
|
||||||
|
tari:
|
||||||
|
path: ../../tari/clients/dart/
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
flutter_lints: ^5.0.0
|
||||||
|
|
||||||
|
flutter:
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -x -e
|
set -x -e
|
||||||
|
|
||||||
for cwcoin in cw_{core,evm,monero,bitcoin,nano,bitcoin_cash,solana,tron,wownero,zano,decred}
|
for cwcoin in cw_{core,evm,monero,bitcoin,nano,bitcoin_cash,solana,tron,wownero,zano,decred,tari}
|
||||||
do
|
do
|
||||||
if [[ "x$1" == "xasync" ]];
|
if [[ "x$1" == "xasync" ]];
|
||||||
then
|
then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue