mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
fix: auto format code and remove electrumx coin control
This commit is contained in:
parent
526025f0f0
commit
6f2ddf7423
2 changed files with 158 additions and 215 deletions
|
@ -1,30 +1,17 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:decimal/decimal.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:stackwallet/models/balance.dart' as SWBalance;
|
|
||||||
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart' as SWTransaction;
|
|
||||||
import 'package:stackwallet/models/isar/models/blockchain_data/address.dart' as SWAddress;
|
|
||||||
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
|
||||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
|
||||||
import 'package:stackwallet/pages/wallet_view/sub_widgets/wallet_balance_toggle_sheet.dart';
|
|
||||||
import 'package:stackwallet/services/coins/coin_service.dart';
|
|
||||||
import 'package:stackwallet/services/mixins/coin_control_interface.dart';
|
|
||||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
|
||||||
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
|
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
import 'package:stackwallet/db/isar/main_db.dart';
|
import 'package:stackwallet/db/isar/main_db.dart';
|
||||||
|
import 'package:stackwallet/models/balance.dart' as SWBalance;
|
||||||
|
import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'
|
||||||
|
as SWAddress;
|
||||||
|
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'
|
||||||
|
as SWTransaction;
|
||||||
|
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
||||||
import 'package:stackwallet/models/node_model.dart';
|
import 'package:stackwallet/models/node_model.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||||
import 'package:stackwallet/utilities/default_nodes.dart';
|
import 'package:stackwallet/services/coins/coin_service.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
||||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
|
||||||
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
|
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
|
||||||
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart';
|
||||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||||
|
@ -33,14 +20,20 @@ import 'package:stackwallet/services/mixins/wallet_cache.dart';
|
||||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||||
import 'package:stackwallet/services/node_service.dart';
|
import 'package:stackwallet/services/node_service.dart';
|
||||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||||
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
|
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||||
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
|
||||||
|
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
|
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
const int MINIMUM_CONFIRMATIONS = 1;
|
const int MINIMUM_CONFIRMATIONS = 1;
|
||||||
|
|
||||||
class StellarWallet extends CoinServiceAPI
|
class StellarWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
with WalletCache, WalletDB, CoinControlInterface {
|
|
||||||
|
|
||||||
late StellarSDK stellarSdk;
|
late StellarSDK stellarSdk;
|
||||||
late Network stellarNetwork;
|
late Network stellarNetwork;
|
||||||
|
|
||||||
|
@ -116,7 +109,7 @@ class StellarWallet extends CoinServiceAPI
|
||||||
// then periodically check
|
// then periodically check
|
||||||
_networkAliveTimer = Timer.periodic(
|
_networkAliveTimer = Timer.periodic(
|
||||||
Constants.networkAliveTimerDuration,
|
Constants.networkAliveTimerDuration,
|
||||||
(_) async {
|
(_) async {
|
||||||
_periodicPingCheck();
|
_periodicPingCheck();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -165,68 +158,68 @@ class StellarWallet extends CoinServiceAPI
|
||||||
Coin get coin => _coin;
|
Coin get coin => _coin;
|
||||||
late Coin _coin;
|
late Coin _coin;
|
||||||
|
|
||||||
Future<bool> accoutExists(String accountId) async {
|
Future<bool> _accountExists(String accountId) async {
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AccountResponse receiverAccount = await stellarSdk.accounts
|
AccountResponse receiverAccount =
|
||||||
.account(accountId);
|
await stellarSdk.accounts.account(accountId);
|
||||||
if (receiverAccount.accountId != "") {
|
if (receiverAccount.accountId != "") {
|
||||||
exists = true;
|
exists = true;
|
||||||
}
|
}
|
||||||
} catch(e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("Error getting account ${e.toString()} - ${s.toString()}", level: LogLevel.Error);
|
Logging.instance.log(
|
||||||
|
"Error getting account ${e.toString()} - ${s.toString()}",
|
||||||
|
level: LogLevel.Error);
|
||||||
}
|
}
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String> confirmSend({required Map<String, dynamic> txData}) async {
|
Future<String> confirmSend({required Map<String, dynamic> txData}) async {
|
||||||
final secretSeed = await _secureStore.read(
|
final secretSeed = await _secureStore.read(key: '${_walletId}_secretSeed');
|
||||||
key: '${_walletId}_secretSeed'
|
|
||||||
);
|
|
||||||
KeyPair senderKeyPair = KeyPair.fromSecretSeed(secretSeed!);
|
KeyPair senderKeyPair = KeyPair.fromSecretSeed(secretSeed!);
|
||||||
AccountResponse sender = await stellarSdk.accounts.account(senderKeyPair.accountId);
|
AccountResponse sender =
|
||||||
|
await stellarSdk.accounts.account(senderKeyPair.accountId);
|
||||||
final amountToSend = txData['recipientAmt'] as Amount;
|
final amountToSend = txData['recipientAmt'] as Amount;
|
||||||
|
|
||||||
//First check if account exists, can be skipped, but if the account does not exist,
|
//First check if account exists, can be skipped, but if the account does not exist,
|
||||||
// the transaction fee will be charged when the transaction fails.
|
// the transaction fee will be charged when the transaction fails.
|
||||||
bool validAccount = await accoutExists(txData['address'] as String);
|
bool validAccount = await _accountExists(txData['address'] as String);
|
||||||
Transaction transaction;
|
Transaction transaction;
|
||||||
|
|
||||||
if (!validAccount) {
|
if (!validAccount) {
|
||||||
//Fund the account, user must ensure account is correct
|
//Fund the account, user must ensure account is correct
|
||||||
CreateAccountOperationBuilder createAccBuilder =
|
CreateAccountOperationBuilder createAccBuilder =
|
||||||
CreateAccountOperationBuilder(
|
CreateAccountOperationBuilder(
|
||||||
txData['address'] as String, amountToSend.decimal.toString()
|
txData['address'] as String, amountToSend.decimal.toString());
|
||||||
);
|
|
||||||
transaction = TransactionBuilder(sender)
|
transaction = TransactionBuilder(sender)
|
||||||
.addOperation(createAccBuilder.build())
|
.addOperation(createAccBuilder.build())
|
||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
transaction = TransactionBuilder(sender)
|
transaction = TransactionBuilder(sender)
|
||||||
.addOperation(PaymentOperationBuilder(
|
.addOperation(PaymentOperationBuilder(txData['address'] as String,
|
||||||
txData['address'] as String, Asset.NATIVE,
|
Asset.NATIVE, amountToSend.decimal.toString())
|
||||||
amountToSend.decimal.toString())
|
.build())
|
||||||
.build()
|
.build();
|
||||||
).build();
|
|
||||||
}
|
}
|
||||||
transaction.sign(senderKeyPair, stellarNetwork);
|
transaction.sign(senderKeyPair, stellarNetwork);
|
||||||
try {
|
try {
|
||||||
SubmitTransactionResponse response = await stellarSdk.submitTransaction(transaction);
|
SubmitTransactionResponse response =
|
||||||
|
await stellarSdk.submitTransaction(transaction);
|
||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
throw("Unable to send transaction");
|
throw ("Unable to send transaction");
|
||||||
}
|
}
|
||||||
return response.hash!;
|
return response.hash!;
|
||||||
} catch(e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("Error sending TX $e - $s", level: LogLevel.Error);
|
Logging.instance.log("Error sending TX $e - $s", level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<SWAddress.Address?> get _currentReceivingAddress =>
|
Future<SWAddress.Address?> get _currentReceivingAddress => db
|
||||||
db.getAddresses(walletId)
|
.getAddresses(walletId)
|
||||||
.filter()
|
.filter()
|
||||||
.typeEqualTo(SWAddress.AddressType.unknown)
|
.typeEqualTo(SWAddress.AddressType.unknown)
|
||||||
.and()
|
.and()
|
||||||
|
@ -242,7 +235,8 @@ class StellarWallet extends CoinServiceAPI
|
||||||
// final nodeURI = Uri.parse("${getCurrentNode().host}:${getCurrentNode().port}");
|
// final nodeURI = Uri.parse("${getCurrentNode().host}:${getCurrentNode().port}");
|
||||||
final nodeURI = Uri.parse(getCurrentNode().host);
|
final nodeURI = Uri.parse(getCurrentNode().host);
|
||||||
final httpClient = http.Client();
|
final httpClient = http.Client();
|
||||||
FeeStatsResponse fsp = await FeeStatsRequestBuilder(httpClient, nodeURI).execute();
|
FeeStatsResponse fsp =
|
||||||
|
await FeeStatsRequestBuilder(httpClient, nodeURI).execute();
|
||||||
return int.parse(fsp.lastLedgerBaseFee);
|
return int.parse(fsp.lastLedgerBaseFee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,8 +273,11 @@ class StellarWallet extends CoinServiceAPI
|
||||||
NodeModel getCurrentNode() {
|
NodeModel getCurrentNode() {
|
||||||
if (_xlmNode != null) {
|
if (_xlmNode != null) {
|
||||||
return _xlmNode!;
|
return _xlmNode!;
|
||||||
} else if (NodeService(secureStorageInterface: _secureStore).getPrimaryNodeFor(coin: coin) != null) {
|
} else if (NodeService(secureStorageInterface: _secureStore)
|
||||||
return NodeService(secureStorageInterface: _secureStore).getPrimaryNodeFor(coin: coin)!;
|
.getPrimaryNodeFor(coin: coin) !=
|
||||||
|
null) {
|
||||||
|
return NodeService(secureStorageInterface: _secureStore)
|
||||||
|
.getPrimaryNodeFor(coin: coin)!;
|
||||||
} else {
|
} else {
|
||||||
return DefaultNodes.getNodeFor(coin);
|
return DefaultNodes.getNodeFor(coin);
|
||||||
}
|
}
|
||||||
|
@ -291,9 +288,9 @@ class StellarWallet extends CoinServiceAPI
|
||||||
// final nodeURI = Uri.parse("${getCurrentNode().host}:${getCurrentNode().port}");
|
// final nodeURI = Uri.parse("${getCurrentNode().host}:${getCurrentNode().port}");
|
||||||
final nodeURI = Uri.parse(getCurrentNode().host);
|
final nodeURI = Uri.parse(getCurrentNode().host);
|
||||||
|
|
||||||
|
|
||||||
final httpClient = http.Client();
|
final httpClient = http.Client();
|
||||||
FeeStatsResponse fsp = await FeeStatsRequestBuilder(httpClient, nodeURI).execute();
|
FeeStatsResponse fsp =
|
||||||
|
await FeeStatsRequestBuilder(httpClient, nodeURI).execute();
|
||||||
|
|
||||||
return FeeObject(
|
return FeeObject(
|
||||||
numberOfBlocksFast: 0,
|
numberOfBlocksFast: 0,
|
||||||
|
@ -301,12 +298,12 @@ class StellarWallet extends CoinServiceAPI
|
||||||
numberOfBlocksSlow: 0,
|
numberOfBlocksSlow: 0,
|
||||||
fast: int.parse(fsp.lastLedgerBaseFee) * 100,
|
fast: int.parse(fsp.lastLedgerBaseFee) * 100,
|
||||||
medium: int.parse(fsp.lastLedgerBaseFee) * 50,
|
medium: int.parse(fsp.lastLedgerBaseFee) * 50,
|
||||||
slow: int.parse(fsp.lastLedgerBaseFee) * 10
|
slow: int.parse(fsp.lastLedgerBaseFee) * 10);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> fullRescan(int maxUnusedAddressGap, int maxNumberOfIndexesToCheck) async {
|
Future<void> fullRescan(
|
||||||
|
int maxUnusedAddressGap, int maxNumberOfIndexesToCheck) async {
|
||||||
await _prefs.init();
|
await _prefs.init();
|
||||||
await updateTransactions();
|
await updateTransactions();
|
||||||
await updateChainHeight();
|
await updateChainHeight();
|
||||||
|
@ -338,25 +335,16 @@ class StellarWallet extends CoinServiceAPI
|
||||||
await _prefs.init();
|
await _prefs.init();
|
||||||
|
|
||||||
String mnemonic = await Wallet.generate24WordsMnemonic();
|
String mnemonic = await Wallet.generate24WordsMnemonic();
|
||||||
await _secureStore.write(
|
await _secureStore.write(key: '${_walletId}_mnemonic', value: mnemonic);
|
||||||
key: '${_walletId}_mnemonic',
|
await _secureStore.write(key: '${_walletId}_mnemonicPassphrase', value: "");
|
||||||
value: mnemonic
|
|
||||||
);
|
|
||||||
await _secureStore.write(
|
|
||||||
key: '${_walletId}_mnemonicPassphrase',
|
|
||||||
value: ""
|
|
||||||
);
|
|
||||||
|
|
||||||
Wallet wallet = await Wallet.from(mnemonic);
|
Wallet wallet = await Wallet.from(mnemonic);
|
||||||
KeyPair keyPair = await wallet.getKeyPair(index: 0);
|
KeyPair keyPair = await wallet.getKeyPair(index: 0);
|
||||||
String address = keyPair.accountId;
|
String address = keyPair.accountId;
|
||||||
String secretSeed = keyPair.secretSeed; //This will be required for sending a tx
|
String secretSeed =
|
||||||
|
keyPair.secretSeed; //This will be required for sending a tx
|
||||||
|
|
||||||
|
await _secureStore.write(key: '${_walletId}_secretSeed', value: secretSeed);
|
||||||
await _secureStore.write(
|
|
||||||
key: '${_walletId}_secretSeed',
|
|
||||||
value: secretSeed
|
|
||||||
);
|
|
||||||
|
|
||||||
final swAddress = SWAddress.Address(
|
final swAddress = SWAddress.Address(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
|
@ -365,21 +353,16 @@ class StellarWallet extends CoinServiceAPI
|
||||||
derivationIndex: 0,
|
derivationIndex: 0,
|
||||||
derivationPath: null,
|
derivationPath: null,
|
||||||
type: SWAddress.AddressType.unknown, // TODO: set type
|
type: SWAddress.AddressType.unknown, // TODO: set type
|
||||||
subType: SWAddress.AddressSubType.unknown
|
subType: SWAddress.AddressSubType.unknown);
|
||||||
);
|
|
||||||
|
|
||||||
await db.putAddress(swAddress);
|
await db.putAddress(swAddress);
|
||||||
|
|
||||||
await Future.wait([
|
await Future.wait(
|
||||||
updateCachedId(walletId),
|
[updateCachedId(walletId), updateCachedIsFavorite(false)]);
|
||||||
updateCachedIsFavorite(false)
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> getAddressSW() async {
|
Future<String> getAddressSW() async {
|
||||||
var mnemonic = await _secureStore.read(
|
var mnemonic = await _secureStore.read(key: '${_walletId}_mnemonic');
|
||||||
key: '${_walletId}_mnemonic'
|
|
||||||
);
|
|
||||||
|
|
||||||
Wallet wallet = await Wallet.from(mnemonic!);
|
Wallet wallet = await Wallet.from(mnemonic!);
|
||||||
KeyPair keyPair = await wallet.getKeyPair(index: 0);
|
KeyPair keyPair = await wallet.getKeyPair(index: 0);
|
||||||
|
@ -400,16 +383,22 @@ class StellarWallet extends CoinServiceAPI
|
||||||
Future<int> get maxFee => throw UnimplementedError();
|
Future<int> get maxFee => throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<String>> get mnemonic => mnemonicString.then((value) => value!.split(" "));
|
Future<List<String>> get mnemonic =>
|
||||||
|
mnemonicString.then((value) => value!.split(" "));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> get mnemonicPassphrase => _secureStore.read(key: '${_walletId}_mnemonicPassphrase');
|
Future<String?> get mnemonicPassphrase =>
|
||||||
|
_secureStore.read(key: '${_walletId}_mnemonicPassphrase');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> get mnemonicString => _secureStore.read(key: '${_walletId}_mnemonic');
|
Future<String?> get mnemonicString =>
|
||||||
|
_secureStore.read(key: '${_walletId}_mnemonic');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Map<String, dynamic>> prepareSend({required String address, required Amount amount, Map<String, dynamic>? args}) async {
|
Future<Map<String, dynamic>> prepareSend(
|
||||||
|
{required String address,
|
||||||
|
required Amount amount,
|
||||||
|
Map<String, dynamic>? args}) async {
|
||||||
try {
|
try {
|
||||||
final feeRate = args?["feeRate"];
|
final feeRate = args?["feeRate"];
|
||||||
var fee = 1000;
|
var fee = 1000;
|
||||||
|
@ -440,13 +429,12 @@ class StellarWallet extends CoinServiceAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> recoverFromMnemonic({
|
Future<void> recoverFromMnemonic(
|
||||||
required String mnemonic,
|
{required String mnemonic,
|
||||||
String? mnemonicPassphrase,
|
String? mnemonicPassphrase,
|
||||||
required int maxUnusedAddressGap,
|
required int maxUnusedAddressGap,
|
||||||
required int maxNumberOfIndexesToCheck,
|
required int maxNumberOfIndexesToCheck,
|
||||||
required int height
|
required int height}) async {
|
||||||
}) async {
|
|
||||||
if ((await mnemonicString) != null ||
|
if ((await mnemonicString) != null ||
|
||||||
(await this.mnemonicPassphrase) != null) {
|
(await this.mnemonicPassphrase) != null) {
|
||||||
throw Exception("Attempted to overwrite mnemonic on restore!");
|
throw Exception("Attempted to overwrite mnemonic on restore!");
|
||||||
|
@ -463,10 +451,7 @@ class StellarWallet extends CoinServiceAPI
|
||||||
key: '${_walletId}_mnemonicPassphrase',
|
key: '${_walletId}_mnemonicPassphrase',
|
||||||
value: mnemonicPassphrase ?? "",
|
value: mnemonicPassphrase ?? "",
|
||||||
);
|
);
|
||||||
await _secureStore.write(
|
await _secureStore.write(key: '${_walletId}_secretSeed', value: secretSeed);
|
||||||
key: '${_walletId}_secretSeed',
|
|
||||||
value: secretSeed
|
|
||||||
);
|
|
||||||
|
|
||||||
final swAddress = SWAddress.Address(
|
final swAddress = SWAddress.Address(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
|
@ -475,15 +460,12 @@ class StellarWallet extends CoinServiceAPI
|
||||||
derivationIndex: 0,
|
derivationIndex: 0,
|
||||||
derivationPath: null,
|
derivationPath: null,
|
||||||
type: SWAddress.AddressType.unknown, // TODO: set type
|
type: SWAddress.AddressType.unknown, // TODO: set type
|
||||||
subType: SWAddress.AddressSubType.unknown
|
subType: SWAddress.AddressSubType.unknown);
|
||||||
);
|
|
||||||
|
|
||||||
await db.putAddress(swAddress);
|
await db.putAddress(swAddress);
|
||||||
|
|
||||||
await Future.wait([
|
await Future.wait(
|
||||||
updateCachedId(walletId),
|
[updateCachedId(walletId), updateCachedIsFavorite(false)]);
|
||||||
updateCachedIsFavorite(false)
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateChainHeight() async {
|
Future<void> updateChainHeight() async {
|
||||||
|
@ -491,20 +473,22 @@ class StellarWallet extends CoinServiceAPI
|
||||||
.order(RequestBuilderOrder.DESC)
|
.order(RequestBuilderOrder.DESC)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.execute()
|
.execute()
|
||||||
.then((value) => value.records!.first.sequence).onError((error, stackTrace) =>
|
.then((value) => value.records!.first.sequence)
|
||||||
throw("Error getting chain height"));
|
.onError((error, stackTrace) => throw ("Error getting chain height"));
|
||||||
await updateCachedChainHeight(height);
|
await updateCachedChainHeight(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateTransactions() async {
|
Future<void> updateTransactions() async {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Tuple2<SWTransaction.Transaction, SWAddress.Address?>> transactionList = [];
|
List<Tuple2<SWTransaction.Transaction, SWAddress.Address?>>
|
||||||
|
transactionList = [];
|
||||||
|
|
||||||
Page<OperationResponse> payments = await stellarSdk.payments
|
Page<OperationResponse> payments = await stellarSdk.payments
|
||||||
.forAccount(await getAddressSW()).order(RequestBuilderOrder.DESC)
|
.forAccount(await getAddressSW())
|
||||||
.execute().onError((error, stackTrace) =>
|
.order(RequestBuilderOrder.DESC)
|
||||||
throw("Could not fetch transactions"));
|
.execute()
|
||||||
|
.onError(
|
||||||
|
(error, stackTrace) => throw ("Could not fetch transactions"));
|
||||||
|
|
||||||
for (OperationResponse response in payments.records!) {
|
for (OperationResponse response in payments.records!) {
|
||||||
// PaymentOperationResponse por;
|
// PaymentOperationResponse por;
|
||||||
|
@ -515,8 +499,7 @@ class StellarWallet extends CoinServiceAPI
|
||||||
"ALL TRANSACTIONS IS ${por.transactionSuccessful}",
|
"ALL TRANSACTIONS IS ${por.transactionSuccessful}",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
|
|
||||||
Logging.instance.log(
|
Logging.instance.log("THIS TX HASH IS ${por.transactionHash}",
|
||||||
"THIS TX HASH IS ${por.transactionHash}",
|
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
|
|
||||||
SWTransaction.TransactionType type;
|
SWTransaction.TransactionType type;
|
||||||
|
@ -526,14 +509,18 @@ class StellarWallet extends CoinServiceAPI
|
||||||
type = SWTransaction.TransactionType.incoming;
|
type = SWTransaction.TransactionType.incoming;
|
||||||
}
|
}
|
||||||
final amount = Amount(
|
final amount = Amount(
|
||||||
rawValue: BigInt.parse(float.parse(por.amount!).toStringAsFixed(coin.decimals).replaceAll(".", "")),
|
rawValue: BigInt.parse(float
|
||||||
fractionDigits: coin.decimals,
|
.parse(por.amount!)
|
||||||
);
|
.toStringAsFixed(coin.decimals)
|
||||||
|
.replaceAll(".", "")),
|
||||||
|
fractionDigits: coin.decimals,
|
||||||
|
);
|
||||||
int fee = 0;
|
int fee = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
//Query the transaction linked to the payment,
|
//Query the transaction linked to the payment,
|
||||||
// por.transaction returns a null sometimes
|
// por.transaction returns a null sometimes
|
||||||
TransactionResponse tx = await stellarSdk.transactions.transaction(por.transactionHash!);
|
TransactionResponse tx =
|
||||||
|
await stellarSdk.transactions.transaction(por.transactionHash!);
|
||||||
|
|
||||||
if (tx.hash.isNotEmpty) {
|
if (tx.hash.isNotEmpty) {
|
||||||
fee = tx.feeCharged!;
|
fee = tx.feeCharged!;
|
||||||
|
@ -542,7 +529,8 @@ class StellarWallet extends CoinServiceAPI
|
||||||
var theTransaction = SWTransaction.Transaction(
|
var theTransaction = SWTransaction.Transaction(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
txid: por.transactionHash!,
|
txid: por.transactionHash!,
|
||||||
timestamp: DateTime.parse(por.createdAt!).millisecondsSinceEpoch ~/ 1000,
|
timestamp:
|
||||||
|
DateTime.parse(por.createdAt!).millisecondsSinceEpoch ~/ 1000,
|
||||||
type: type,
|
type: type,
|
||||||
subType: SWTransaction.TransactionSubType.none,
|
subType: SWTransaction.TransactionSubType.none,
|
||||||
amount: 0,
|
amount: 0,
|
||||||
|
@ -559,18 +547,20 @@ class StellarWallet extends CoinServiceAPI
|
||||||
numberOfMessages: null,
|
numberOfMessages: null,
|
||||||
);
|
);
|
||||||
SWAddress.Address? receivingAddress = await _currentReceivingAddress;
|
SWAddress.Address? receivingAddress = await _currentReceivingAddress;
|
||||||
SWAddress.Address address = type == SWTransaction.TransactionType.incoming
|
SWAddress.Address address =
|
||||||
? receivingAddress!
|
type == SWTransaction.TransactionType.incoming
|
||||||
: SWAddress.Address(
|
? receivingAddress!
|
||||||
walletId: walletId,
|
: SWAddress.Address(
|
||||||
value: por.sourceAccount!,
|
walletId: walletId,
|
||||||
publicKey: KeyPair.fromAccountId(por.sourceAccount!).publicKey,
|
value: por.sourceAccount!,
|
||||||
derivationIndex: 0,
|
publicKey:
|
||||||
derivationPath: null,
|
KeyPair.fromAccountId(por.sourceAccount!).publicKey,
|
||||||
type: SWAddress.AddressType.unknown, // TODO: set type
|
derivationIndex: 0,
|
||||||
subType: SWAddress.AddressSubType.unknown
|
derivationPath: null,
|
||||||
);
|
type: SWAddress.AddressType.unknown, // TODO: set type
|
||||||
Tuple2<SWTransaction.Transaction, SWAddress.Address> tuple = Tuple2(theTransaction, address);
|
subType: SWAddress.AddressSubType.unknown);
|
||||||
|
Tuple2<SWTransaction.Transaction, SWAddress.Address> tuple =
|
||||||
|
Tuple2(theTransaction, address);
|
||||||
transactionList.add(tuple);
|
transactionList.add(tuple);
|
||||||
} else if (response is CreateAccountOperationResponse) {
|
} else if (response is CreateAccountOperationResponse) {
|
||||||
CreateAccountOperationResponse caor = response;
|
CreateAccountOperationResponse caor = response;
|
||||||
|
@ -581,12 +571,16 @@ class StellarWallet extends CoinServiceAPI
|
||||||
type = SWTransaction.TransactionType.incoming;
|
type = SWTransaction.TransactionType.incoming;
|
||||||
}
|
}
|
||||||
final amount = Amount(
|
final amount = Amount(
|
||||||
rawValue: BigInt.parse(float.parse(caor.startingBalance!).toStringAsFixed(coin.decimals).replaceAll(".", "")),
|
rawValue: BigInt.parse(float
|
||||||
|
.parse(caor.startingBalance!)
|
||||||
|
.toStringAsFixed(coin.decimals)
|
||||||
|
.replaceAll(".", "")),
|
||||||
fractionDigits: coin.decimals,
|
fractionDigits: coin.decimals,
|
||||||
);
|
);
|
||||||
int fee = 0;
|
int fee = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
TransactionResponse tx = await stellarSdk.transactions.transaction(caor.transactionHash!);
|
TransactionResponse tx =
|
||||||
|
await stellarSdk.transactions.transaction(caor.transactionHash!);
|
||||||
if (tx.hash.isNotEmpty) {
|
if (tx.hash.isNotEmpty) {
|
||||||
fee = tx.feeCharged!;
|
fee = tx.feeCharged!;
|
||||||
height = tx.ledger;
|
height = tx.ledger;
|
||||||
|
@ -594,7 +588,8 @@ class StellarWallet extends CoinServiceAPI
|
||||||
var theTransaction = SWTransaction.Transaction(
|
var theTransaction = SWTransaction.Transaction(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
txid: caor.transactionHash!,
|
txid: caor.transactionHash!,
|
||||||
timestamp: DateTime.parse(caor.createdAt!).millisecondsSinceEpoch ~/ 1000,
|
timestamp:
|
||||||
|
DateTime.parse(caor.createdAt!).millisecondsSinceEpoch ~/ 1000,
|
||||||
type: type,
|
type: type,
|
||||||
subType: SWTransaction.TransactionSubType.none,
|
subType: SWTransaction.TransactionSubType.none,
|
||||||
amount: 0,
|
amount: 0,
|
||||||
|
@ -611,17 +606,20 @@ class StellarWallet extends CoinServiceAPI
|
||||||
numberOfMessages: null,
|
numberOfMessages: null,
|
||||||
);
|
);
|
||||||
SWAddress.Address? receivingAddress = await _currentReceivingAddress;
|
SWAddress.Address? receivingAddress = await _currentReceivingAddress;
|
||||||
SWAddress.Address address = type == SWTransaction.TransactionType.incoming
|
SWAddress.Address address =
|
||||||
? receivingAddress!
|
type == SWTransaction.TransactionType.incoming
|
||||||
: SWAddress.Address(
|
? receivingAddress!
|
||||||
walletId: walletId,
|
: SWAddress.Address(
|
||||||
value: caor.sourceAccount!,
|
walletId: walletId,
|
||||||
publicKey: KeyPair.fromAccountId(caor.sourceAccount!).publicKey,
|
value: caor.sourceAccount!,
|
||||||
derivationIndex: 0,
|
publicKey:
|
||||||
derivationPath: null,
|
KeyPair.fromAccountId(caor.sourceAccount!).publicKey,
|
||||||
type: SWAddress.AddressType.unknown, // TODO: set type
|
derivationIndex: 0,
|
||||||
subType: SWAddress.AddressSubType.unknown);
|
derivationPath: null,
|
||||||
Tuple2<SWTransaction.Transaction, SWAddress.Address> tuple = Tuple2(theTransaction, address);
|
type: SWAddress.AddressType.unknown, // TODO: set type
|
||||||
|
subType: SWAddress.AddressSubType.unknown);
|
||||||
|
Tuple2<SWTransaction.Transaction, SWAddress.Address> tuple =
|
||||||
|
Tuple2(theTransaction, address);
|
||||||
transactionList.add(tuple);
|
transactionList.add(tuple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,12 +629,12 @@ class StellarWallet extends CoinServiceAPI
|
||||||
"Exception rethrown from updateTransactions(): $e\n$s",
|
"Exception rethrown from updateTransactions(): $e\n$s",
|
||||||
level: LogLevel.Error);
|
level: LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateBalance() async {
|
Future<void> updateBalance() async {
|
||||||
try {
|
try {
|
||||||
AccountResponse accountResponse = await stellarSdk.accounts.account(await getAddressSW());
|
AccountResponse accountResponse =
|
||||||
|
await stellarSdk.accounts.account(await getAddressSW());
|
||||||
for (Balance balance in accountResponse.balances) {
|
for (Balance balance in accountResponse.balances) {
|
||||||
switch (balance.assetType) {
|
switch (balance.assetType) {
|
||||||
case Asset.TYPE_NATIVE:
|
case Asset.TYPE_NATIVE:
|
||||||
|
@ -662,9 +660,9 @@ class StellarWallet extends CoinServiceAPI
|
||||||
await updateCachedBalance(_balance!);
|
await updateCachedBalance(_balance!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"ERROR GETTING BALANCE $e\$s",
|
"ERROR GETTING BALANCE $e\n$s",
|
||||||
level: LogLevel.Info,
|
level: LogLevel.Info,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -747,12 +745,13 @@ class StellarWallet extends CoinServiceAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<SWTransaction.Transaction>> get transactions => db.getTransactions(walletId).findAll();
|
Future<List<SWTransaction.Transaction>> get transactions =>
|
||||||
|
db.getTransactions(walletId).findAll();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateNode(bool shouldRefresh) async {
|
Future<void> updateNode(bool shouldRefresh) async {
|
||||||
_xlmNode = NodeService(secureStorageInterface: _secureStore)
|
_xlmNode = NodeService(secureStorageInterface: _secureStore)
|
||||||
.getPrimaryNodeFor(coin: coin) ??
|
.getPrimaryNodeFor(coin: coin) ??
|
||||||
DefaultNodes.getNodeFor(coin);
|
DefaultNodes.getNodeFor(coin);
|
||||||
|
|
||||||
if (shouldRefresh) {
|
if (shouldRefresh) {
|
||||||
|
@ -784,14 +783,14 @@ class StellarWallet extends CoinServiceAPI
|
||||||
);
|
);
|
||||||
|
|
||||||
final address = txData["address"] is String
|
final address = txData["address"] is String
|
||||||
? await db.getAddress(walletId, txData["address"] as String)
|
? await db.getAddress(walletId, txData["address"] as String)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
await db.addNewTransactionData(
|
await db.addNewTransactionData(
|
||||||
[
|
[
|
||||||
Tuple2(transaction, address),
|
Tuple2(transaction, address),
|
||||||
],
|
],
|
||||||
walletId,
|
walletId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
60
pubspec.lock
60
pubspec.lock
|
@ -956,7 +956,7 @@ packages:
|
||||||
path: "crypto_plugins/flutter_liblelantus"
|
path: "crypto_plugins/flutter_liblelantus"
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "0.0.1"
|
version: "0.0.2"
|
||||||
lints:
|
lints:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -1365,62 +1365,6 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.2.1"
|
version: "3.2.1"
|
||||||
shared_preferences:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shared_preferences
|
|
||||||
sha256: "0344316c947ffeb3a529eac929e1978fcd37c26be4e8468628bac399365a3ca1"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.2.0"
|
|
||||||
shared_preferences_android:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shared_preferences_android
|
|
||||||
sha256: fe8401ec5b6dcd739a0fe9588802069e608c3fdbfd3c3c93e546cf2f90438076
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.2.0"
|
|
||||||
shared_preferences_foundation:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shared_preferences_foundation
|
|
||||||
sha256: f39696b83e844923b642ce9dd4bd31736c17e697f6731a5adf445b1274cf3cd4
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.3.2"
|
|
||||||
shared_preferences_linux:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shared_preferences_linux
|
|
||||||
sha256: "71d6806d1449b0a9d4e85e0c7a917771e672a3d5dc61149cc9fac871115018e1"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.3.0"
|
|
||||||
shared_preferences_platform_interface:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shared_preferences_platform_interface
|
|
||||||
sha256: "23b052f17a25b90ff2b61aad4cc962154da76fb62848a9ce088efe30d7c50ab1"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.3.0"
|
|
||||||
shared_preferences_web:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shared_preferences_web
|
|
||||||
sha256: "7347b194fb0bbeb4058e6a4e87ee70350b6b2b90f8ac5f8bd5b3a01548f6d33a"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.2.0"
|
|
||||||
shared_preferences_windows:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shared_preferences_windows
|
|
||||||
sha256: f95e6a43162bce43c9c3405f3eb6f39e5b5d11f65fab19196cf8225e2777624d
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.3.0"
|
|
||||||
shelf:
|
shelf:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -1927,4 +1871,4 @@ packages:
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.0.2 <4.0.0"
|
dart: ">=3.0.2 <4.0.0"
|
||||||
flutter: ">=3.10.0"
|
flutter: ">=3.10.3"
|
||||||
|
|
Loading…
Reference in a new issue