mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-02 03:06:29 +00:00
WIP tezos
This commit is contained in:
parent
273fd981f4
commit
62c1628fa7
13 changed files with 1111 additions and 796 deletions
|
@ -83,7 +83,7 @@ class _NewWalletRecoveryPhraseViewState
|
||||||
await _wallet.exit();
|
await _wallet.exit();
|
||||||
await ref
|
await ref
|
||||||
.read(pWallets)
|
.read(pWallets)
|
||||||
.deleteWallet(_wallet.walletId, ref.read(secureStoreProvider));
|
.deleteWallet(_wallet.info, ref.read(secureStoreProvider));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _copy() async {
|
Future<void> _copy() async {
|
||||||
|
|
|
@ -258,7 +258,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
|
||||||
isRestoring = false;
|
isRestoring = false;
|
||||||
|
|
||||||
await ref.read(pWallets).deleteWallet(
|
await ref.read(pWallets).deleteWallet(
|
||||||
info.walletId,
|
info,
|
||||||
ref.read(secureStoreProvider),
|
ref.read(secureStoreProvider),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,6 +14,7 @@ import 'package:stackwallet/providers/global/secure_store_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
|
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
||||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||||
|
|
||||||
class RestoreFailedDialog extends ConsumerStatefulWidget {
|
class RestoreFailedDialog extends ConsumerStatefulWidget {
|
||||||
|
@ -65,7 +66,7 @@ class _RestoreFailedDialogState extends ConsumerState<RestoreFailedDialog> {
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ref.read(pWallets).deleteWallet(
|
await ref.read(pWallets).deleteWallet(
|
||||||
walletId,
|
ref.read(pWalletInfo(walletId)),
|
||||||
ref.read(secureStoreProvider),
|
ref.read(secureStoreProvider),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -262,7 +262,7 @@ class _VerifyRecoveryPhraseViewState
|
||||||
|
|
||||||
Future<void> delete() async {
|
Future<void> delete() async {
|
||||||
await ref.read(pWallets).deleteWallet(
|
await ref.read(pWallets).deleteWallet(
|
||||||
_wallet.walletId,
|
_wallet.info,
|
||||||
ref.read(secureStoreProvider),
|
ref.read(secureStoreProvider),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ class _DeleteWalletRecoveryPhraseViewState
|
||||||
.getPrimaryEnabledButtonStyle(context),
|
.getPrimaryEnabledButtonStyle(context),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ref.read(pWallets).deleteWallet(
|
await ref.read(pWallets).deleteWallet(
|
||||||
widget.walletId,
|
ref.read(pWalletInfo(widget.walletId)),
|
||||||
ref.read(secureStoreProvider),
|
ref.read(secureStoreProvider),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
|
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
|
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||||
|
@ -238,7 +239,7 @@ class _ConfirmDeleteState extends ConsumerState<ConfirmDelete> {
|
||||||
label: "Continue",
|
label: "Continue",
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ref.read(pWallets).deleteWallet(
|
await ref.read(pWallets).deleteWallet(
|
||||||
widget.walletId,
|
ref.read(pWalletInfo(widget.walletId)),
|
||||||
ref.read(secureStoreProvider),
|
ref.read(secureStoreProvider),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import 'package:stackwallet/services/coins/monero/monero_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart';
|
import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
|
import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/stellar/stellar_wallet.dart';
|
import 'package:stackwallet/services/coins/stellar/stellar_wallet.dart';
|
||||||
import 'package:stackwallet/services/coins/tezos/tezos_wallet.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/amount/amount.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
@ -175,13 +174,7 @@ abstract class CoinServiceAPI {
|
||||||
);
|
);
|
||||||
|
|
||||||
case Coin.tezos:
|
case Coin.tezos:
|
||||||
return TezosWallet(
|
throw UnimplementedError("moved");
|
||||||
walletId: walletId,
|
|
||||||
walletName: walletName,
|
|
||||||
coin: coin,
|
|
||||||
secureStore: secureStorageInterface,
|
|
||||||
tracker: tracker,
|
|
||||||
);
|
|
||||||
|
|
||||||
case Coin.wownero:
|
case Coin.wownero:
|
||||||
throw UnimplementedError("moved");
|
throw UnimplementedError("moved");
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -55,36 +55,37 @@ class Wallets {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteWallet(
|
Future<void> deleteWallet(
|
||||||
String walletId,
|
WalletInfo info,
|
||||||
SecureStorageInterface secureStorage,
|
SecureStorageInterface secureStorage,
|
||||||
) async {
|
) async {
|
||||||
|
final walletId = info.walletId;
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"deleteWallet called with walletId=$walletId",
|
"deleteWallet called with walletId=$walletId",
|
||||||
level: LogLevel.Warning,
|
level: LogLevel.Warning,
|
||||||
);
|
);
|
||||||
|
|
||||||
final wallet = getWallet(walletId);
|
final wallet = _wallets[walletId];
|
||||||
_wallets.remove(walletId);
|
_wallets.remove(walletId);
|
||||||
await wallet.exit();
|
await wallet?.exit();
|
||||||
|
|
||||||
await secureStorage.delete(key: Wallet.mnemonicKey(walletId: walletId));
|
await secureStorage.delete(key: Wallet.mnemonicKey(walletId: walletId));
|
||||||
await secureStorage.delete(
|
await secureStorage.delete(
|
||||||
key: Wallet.mnemonicPassphraseKey(walletId: walletId));
|
key: Wallet.mnemonicPassphraseKey(walletId: walletId));
|
||||||
await secureStorage.delete(key: Wallet.privateKeyKey(walletId: walletId));
|
await secureStorage.delete(key: Wallet.privateKeyKey(walletId: walletId));
|
||||||
|
|
||||||
if (wallet.info.coin == Coin.wownero) {
|
if (info.coin == Coin.wownero) {
|
||||||
final wowService =
|
final wowService =
|
||||||
wownero.createWowneroWalletService(DB.instance.moneroWalletInfoBox);
|
wownero.createWowneroWalletService(DB.instance.moneroWalletInfoBox);
|
||||||
await wowService.remove(walletId);
|
await wowService.remove(walletId);
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("monero wallet: $walletId deleted", level: LogLevel.Info);
|
.log("monero wallet: $walletId deleted", level: LogLevel.Info);
|
||||||
} else if (wallet.info.coin == Coin.monero) {
|
} else if (info.coin == Coin.monero) {
|
||||||
final xmrService =
|
final xmrService =
|
||||||
monero.createMoneroWalletService(DB.instance.moneroWalletInfoBox);
|
monero.createMoneroWalletService(DB.instance.moneroWalletInfoBox);
|
||||||
await xmrService.remove(walletId);
|
await xmrService.remove(walletId);
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("monero wallet: $walletId deleted", level: LogLevel.Info);
|
.log("monero wallet: $walletId deleted", level: LogLevel.Info);
|
||||||
} else if (wallet.info.coin == Coin.epicCash) {
|
} else if (info.coin == Coin.epicCash) {
|
||||||
final deleteResult = await deleteEpicWallet(
|
final deleteResult = await deleteEpicWallet(
|
||||||
walletId: walletId, secureStore: secureStorage);
|
walletId: walletId, secureStore: secureStorage);
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
|
|
|
@ -10,7 +10,7 @@ import 'package:stackwallet/wallets/api/tezos/tezos_transaction.dart';
|
||||||
|
|
||||||
abstract final class TezosAPI {
|
abstract final class TezosAPI {
|
||||||
static final HTTP _client = HTTP();
|
static final HTTP _client = HTTP();
|
||||||
static const String _baseURL = 'https://api.tzstats.com';
|
static const String _baseURL = 'https://api.mainnet.tzkt.io';
|
||||||
|
|
||||||
static Future<List<TezosTransaction>?> getTransactions(String address) async {
|
static Future<List<TezosTransaction>?> getTransactions(String address) async {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:stackwallet/models/node_model.dart';
|
import 'package:stackwallet/models/node_model.dart';
|
||||||
|
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
||||||
import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_currency.dart';
|
import 'package:stackwallet/wallets/crypto_currency/intermediate/bip39_currency.dart';
|
||||||
|
@ -12,21 +13,37 @@ class Tezos extends Bip39Currency {
|
||||||
throw Exception("Unsupported network: $network");
|
throw Exception("Unsupported network: $network");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@override
|
|
||||||
// TODO: implement defaultNode
|
|
||||||
NodeModel get defaultNode => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement genesisHash
|
// TODO: implement genesisHash
|
||||||
String get genesisHash => throw UnimplementedError();
|
String get genesisHash => throw UnimplementedError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement minConfirms
|
int get minConfirms => 1;
|
||||||
int get minConfirms => throw UnimplementedError();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool validateAddress(String address) {
|
bool validateAddress(String address) {
|
||||||
// TODO: implement validateAddress
|
return RegExp(r"^tz[1-9A-HJ-NP-Za-km-z]{34}$").hasMatch(address);
|
||||||
throw UnimplementedError();
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
NodeModel get defaultNode {
|
||||||
|
switch (network) {
|
||||||
|
case CryptoCurrencyNetwork.main:
|
||||||
|
return NodeModel(
|
||||||
|
host: "https://mainnet.api.tez.ie",
|
||||||
|
port: 443,
|
||||||
|
name: DefaultNodes.defaultName,
|
||||||
|
id: DefaultNodes.buildId(Coin.tezos),
|
||||||
|
useSSL: true,
|
||||||
|
enabled: true,
|
||||||
|
coinName: Coin.tezos.name,
|
||||||
|
isFailover: true,
|
||||||
|
isDown: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||||
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
|
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
|
||||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
|
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
|
||||||
|
import 'package:tezart/tezart.dart' as tezart;
|
||||||
import 'package:web3dart/web3dart.dart' as web3dart;
|
import 'package:web3dart/web3dart.dart' as web3dart;
|
||||||
|
|
||||||
class TxData {
|
class TxData {
|
||||||
|
@ -51,6 +52,9 @@ class TxData {
|
||||||
final TransactionSubType? txSubType;
|
final TransactionSubType? txSubType;
|
||||||
final List<Map<String, dynamic>>? mintsMapLelantus;
|
final List<Map<String, dynamic>>? mintsMapLelantus;
|
||||||
|
|
||||||
|
// tezos specific
|
||||||
|
final tezart.OperationsList? tezosOperationsList;
|
||||||
|
|
||||||
TxData({
|
TxData({
|
||||||
this.feeRateType,
|
this.feeRateType,
|
||||||
this.feeRateAmount,
|
this.feeRateAmount,
|
||||||
|
@ -80,6 +84,7 @@ class TxData {
|
||||||
this.txType,
|
this.txType,
|
||||||
this.txSubType,
|
this.txSubType,
|
||||||
this.mintsMapLelantus,
|
this.mintsMapLelantus,
|
||||||
|
this.tezosOperationsList,
|
||||||
});
|
});
|
||||||
|
|
||||||
Amount? get amount => recipients != null && recipients!.isNotEmpty
|
Amount? get amount => recipients != null && recipients!.isNotEmpty
|
||||||
|
@ -121,6 +126,7 @@ class TxData {
|
||||||
TransactionType? txType,
|
TransactionType? txType,
|
||||||
TransactionSubType? txSubType,
|
TransactionSubType? txSubType,
|
||||||
List<Map<String, dynamic>>? mintsMapLelantus,
|
List<Map<String, dynamic>>? mintsMapLelantus,
|
||||||
|
tezart.OperationsList? tezosOperationsList,
|
||||||
}) {
|
}) {
|
||||||
return TxData(
|
return TxData(
|
||||||
feeRateType: feeRateType ?? this.feeRateType,
|
feeRateType: feeRateType ?? this.feeRateType,
|
||||||
|
@ -152,6 +158,7 @@ class TxData {
|
||||||
txType: txType ?? this.txType,
|
txType: txType ?? this.txType,
|
||||||
txSubType: txSubType ?? this.txSubType,
|
txSubType: txSubType ?? this.txSubType,
|
||||||
mintsMapLelantus: mintsMapLelantus ?? this.mintsMapLelantus,
|
mintsMapLelantus: mintsMapLelantus ?? this.mintsMapLelantus,
|
||||||
|
tezosOperationsList: tezosOperationsList ?? this.tezosOperationsList,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,5 +192,6 @@ class TxData {
|
||||||
'txType: $txType, '
|
'txType: $txType, '
|
||||||
'txSubType: $txSubType, '
|
'txSubType: $txSubType, '
|
||||||
'mintsMapLelantus: $mintsMapLelantus, '
|
'mintsMapLelantus: $mintsMapLelantus, '
|
||||||
|
'tezosOperationsList: $tezosOperationsList, '
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,85 +1,380 @@
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
|
import 'package:stackwallet/models/balance.dart';
|
||||||
|
import 'package:stackwallet/models/isar/models/blockchain_data/address.dart';
|
||||||
|
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
|
||||||
|
import 'package:stackwallet/models/node_model.dart';
|
||||||
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
import 'package:stackwallet/models/paymint/fee_object_model.dart';
|
||||||
|
import 'package:stackwallet/services/node_service.dart';
|
||||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
|
import 'package:stackwallet/utilities/default_nodes.dart';
|
||||||
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
import 'package:stackwallet/utilities/extensions/impl/string.dart';
|
||||||
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
import 'package:stackwallet/wallets/api/tezos/tezos_api.dart';
|
||||||
|
import 'package:stackwallet/wallets/api/tezos/tezos_rpc_api.dart';
|
||||||
|
import 'package:stackwallet/wallets/api/tezos/tezos_transaction.dart';
|
||||||
import 'package:stackwallet/wallets/crypto_currency/coins/tezos.dart';
|
import 'package:stackwallet/wallets/crypto_currency/coins/tezos.dart';
|
||||||
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
||||||
import 'package:stackwallet/wallets/models/tx_data.dart';
|
import 'package:stackwallet/wallets/models/tx_data.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart';
|
import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart';
|
||||||
|
import 'package:tezart/tezart.dart' as tezart;
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
|
const int GAS_LIMIT = 10200;
|
||||||
|
|
||||||
class TezosWallet extends Bip39Wallet {
|
class TezosWallet extends Bip39Wallet {
|
||||||
TezosWallet(CryptoCurrencyNetwork network) : super(Tezos(network));
|
TezosWallet(CryptoCurrencyNetwork network) : super(Tezos(network));
|
||||||
|
|
||||||
|
NodeModel? _xtzNode;
|
||||||
|
|
||||||
|
Future<tezart.Keystore> _getKeyStore() async {
|
||||||
|
final mnemonic = await getMnemonic();
|
||||||
|
final passphrase = await getMnemonicPassphrase();
|
||||||
|
return tezart.Keystore.fromMnemonic(mnemonic, password: passphrase);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Address> _getAddressFromMnemonic() async {
|
||||||
|
final keyStore = await _getKeyStore();
|
||||||
|
return Address(
|
||||||
|
walletId: walletId,
|
||||||
|
value: keyStore.address,
|
||||||
|
publicKey: keyStore.publicKey.toUint8ListFromBase58CheckEncoded,
|
||||||
|
derivationIndex: 0,
|
||||||
|
derivationPath: null,
|
||||||
|
type: info.coin.primaryAddressType,
|
||||||
|
subType: AddressSubType.receiving,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> init() async {
|
||||||
|
final _address = await getCurrentReceivingAddress();
|
||||||
|
if (_address == null) {
|
||||||
|
final address = await _getAddressFromMnemonic();
|
||||||
|
|
||||||
|
await mainDB.updateOrPutAddresses([address]);
|
||||||
|
}
|
||||||
|
|
||||||
|
await super.init();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement changeAddressFilterOperation
|
|
||||||
FilterOperation? get changeAddressFilterOperation =>
|
FilterOperation? get changeAddressFilterOperation =>
|
||||||
throw UnimplementedError();
|
throw UnimplementedError("Not used for $runtimeType");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement receivingAddressFilterOperation
|
|
||||||
FilterOperation? get receivingAddressFilterOperation =>
|
FilterOperation? get receivingAddressFilterOperation =>
|
||||||
throw UnimplementedError();
|
FilterGroup.and(standardReceivingAddressFilters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<TxData> confirmSend({required TxData txData}) {
|
Future<TxData> prepareSend({required TxData txData}) async {
|
||||||
|
if (txData.recipients == null || txData.recipients!.length != 1) {
|
||||||
|
throw Exception("$runtimeType prepareSend requires 1 recipient");
|
||||||
|
}
|
||||||
|
|
||||||
|
Amount sendAmount = txData.amount!;
|
||||||
|
|
||||||
|
if (sendAmount > info.cachedBalance.spendable) {
|
||||||
|
throw Exception("Insufficient available balance");
|
||||||
|
}
|
||||||
|
|
||||||
|
final bool isSendAll = sendAmount == info.cachedBalance.spendable;
|
||||||
|
|
||||||
|
final sourceKeyStore = await _getKeyStore();
|
||||||
|
final tezartClient = tezart.TezartClient(
|
||||||
|
(_xtzNode ?? getCurrentNode()).host,
|
||||||
|
);
|
||||||
|
|
||||||
|
final opList = await tezartClient.transferOperation(
|
||||||
|
source: sourceKeyStore,
|
||||||
|
destination: txData.recipients!.first.address,
|
||||||
|
amount: sendAmount.raw.toInt(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await opList.computeFees();
|
||||||
|
|
||||||
|
final fee = Amount(
|
||||||
|
rawValue: opList.operations
|
||||||
|
.map(
|
||||||
|
(e) => BigInt.from(e.fee),
|
||||||
|
)
|
||||||
|
.fold(
|
||||||
|
BigInt.zero,
|
||||||
|
(p, e) => p + e,
|
||||||
|
),
|
||||||
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isSendAll) {
|
||||||
|
sendAmount = sendAmount - fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
return txData.copyWith(
|
||||||
|
recipients: [
|
||||||
|
(
|
||||||
|
amount: sendAmount,
|
||||||
|
address: txData.recipients!.first.address,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
fee: fee,
|
||||||
|
tezosOperationsList: opList,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<TxData> confirmSend({required TxData txData}) async {
|
||||||
// TODO: implement confirmSend
|
// TODO: implement confirmSend
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Amount> estimateFeeFor(Amount amount, int feeRate) {
|
Future<Amount> estimateFeeFor(Amount amount, int feeRate) async {
|
||||||
// TODO: implement estimateFeeFor
|
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
|
// final ADDRESS_REPLACEME = (await getCurrentReceivingAddress())!.value;
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// final sourceKeyStore = await _getKeyStore();
|
||||||
|
// final tezartClient = tezart.TezartClient(
|
||||||
|
// (_xtzNode ?? getCurrentNode()).host,
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// final opList = await tezartClient.transferOperation(
|
||||||
|
// source: sourceKeyStore,
|
||||||
|
// destination: ADDRESS_REPLACEME,
|
||||||
|
// amount: amount.raw.toInt(),
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// await opList.run();
|
||||||
|
// await opList.estimate();
|
||||||
|
//
|
||||||
|
// final fee = Amount(
|
||||||
|
// rawValue: opList.operations
|
||||||
|
// .map(
|
||||||
|
// (e) => BigInt.from(e.fee),
|
||||||
|
// )
|
||||||
|
// .fold(
|
||||||
|
// BigInt.zero,
|
||||||
|
// (p, e) => p + e,
|
||||||
|
// ),
|
||||||
|
// fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// return fee;
|
||||||
|
// } catch (e, s) {
|
||||||
|
// Logging.instance.log(
|
||||||
|
// "Error in estimateFeeFor() in tezos_wallet.dart: $e\n$s}",
|
||||||
|
// level: LogLevel.Error,
|
||||||
|
// );
|
||||||
|
// rethrow;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement fees
|
Future<FeeObject> get fees async {
|
||||||
Future<FeeObject> get fees => throw UnimplementedError();
|
final feePerTx = (await estimateFeeFor(
|
||||||
|
Amount(
|
||||||
@override
|
rawValue: BigInt.one,
|
||||||
Future<bool> pingCheck() {
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
// TODO: implement pingCheck
|
),
|
||||||
throw UnimplementedError();
|
42))
|
||||||
|
.raw
|
||||||
|
.toInt();
|
||||||
|
Logging.instance.log("feePerTx:$feePerTx", level: LogLevel.Info);
|
||||||
|
return FeeObject(
|
||||||
|
numberOfBlocksFast: 10,
|
||||||
|
numberOfBlocksAverage: 10,
|
||||||
|
numberOfBlocksSlow: 10,
|
||||||
|
fast: feePerTx,
|
||||||
|
medium: feePerTx,
|
||||||
|
slow: feePerTx,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<TxData> prepareSend({required TxData txData}) {
|
Future<bool> pingCheck() async {
|
||||||
// TODO: implement prepareSend
|
final currentNode = getCurrentNode();
|
||||||
throw UnimplementedError();
|
return await TezosRpcAPI.testNetworkConnection(
|
||||||
|
nodeInfo: (
|
||||||
|
host: currentNode.host,
|
||||||
|
port: currentNode.port,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> recover({required bool isRescan}) {
|
Future<void> recover({required bool isRescan}) async {
|
||||||
// TODO: implement recover
|
await refreshMutex.protect(() async {
|
||||||
throw UnimplementedError();
|
if (isRescan) {
|
||||||
|
await mainDB.deleteWalletBlockchainData(walletId);
|
||||||
|
}
|
||||||
|
|
||||||
|
final address = await _getAddressFromMnemonic();
|
||||||
|
|
||||||
|
await mainDB.updateOrPutAddresses([address]);
|
||||||
|
|
||||||
|
await Future.wait([
|
||||||
|
updateBalance(),
|
||||||
|
updateTransactions(),
|
||||||
|
updateChainHeight(),
|
||||||
|
]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateBalance() {
|
Future<void> updateBalance() async {
|
||||||
// TODO: implement updateBalance
|
try {
|
||||||
throw UnimplementedError();
|
final currentNode = _xtzNode ?? getCurrentNode();
|
||||||
|
final balance = await TezosRpcAPI.getBalance(
|
||||||
|
nodeInfo: (host: currentNode.host, port: currentNode.port),
|
||||||
|
address: (await getCurrentReceivingAddress())!.value,
|
||||||
|
);
|
||||||
|
|
||||||
|
final balanceInAmount = Amount(
|
||||||
|
rawValue: balance!,
|
||||||
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
);
|
||||||
|
final newBalance = Balance(
|
||||||
|
total: balanceInAmount,
|
||||||
|
spendable: balanceInAmount,
|
||||||
|
blockedTotal: Amount(
|
||||||
|
rawValue: BigInt.zero,
|
||||||
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
),
|
||||||
|
pendingSpendable: Amount(
|
||||||
|
rawValue: BigInt.zero,
|
||||||
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await info.updateBalance(newBalance: newBalance, isar: mainDB.isar);
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance.log(
|
||||||
|
"Error getting balance in tezos_wallet.dart: $e\n$s}",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateChainHeight() {
|
Future<void> updateChainHeight() async {
|
||||||
// TODO: implement updateChainHeight
|
try {
|
||||||
throw UnimplementedError();
|
final currentNode = _xtzNode ?? getCurrentNode();
|
||||||
|
final height = await TezosRpcAPI.getChainHeight(
|
||||||
|
nodeInfo: (
|
||||||
|
host: currentNode.host,
|
||||||
|
port: currentNode.port,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await info.updateCachedChainHeight(
|
||||||
|
newHeight: height!,
|
||||||
|
isar: mainDB.isar,
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance.log(
|
||||||
|
"Error occurred in tezos_wallet.dart while getting"
|
||||||
|
" chain height for tezos: $e\n$s}",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateNode() {
|
Future<void> updateNode() async {
|
||||||
// TODO: implement updateNode
|
_xtzNode = NodeService(secureStorageInterface: secureStorageInterface)
|
||||||
throw UnimplementedError();
|
.getPrimaryNodeFor(coin: info.coin) ??
|
||||||
|
DefaultNodes.getNodeFor(info.coin);
|
||||||
|
|
||||||
|
await refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateTransactions() {
|
NodeModel getCurrentNode() {
|
||||||
// TODO: implement updateTransactions
|
return _xtzNode ??
|
||||||
throw UnimplementedError();
|
NodeService(secureStorageInterface: secureStorageInterface)
|
||||||
|
.getPrimaryNodeFor(coin: info.coin) ??
|
||||||
|
DefaultNodes.getNodeFor(info.coin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateUTXOs() {
|
Future<void> updateTransactions() async {
|
||||||
// TODO: implement updateUTXOs
|
// TODO: optimize updateTransactions
|
||||||
throw UnimplementedError();
|
|
||||||
|
final myAddress = (await getCurrentReceivingAddress())!;
|
||||||
|
List<TezosTransaction>? txs =
|
||||||
|
await TezosAPI.getTransactions(myAddress.value);
|
||||||
|
Logging.instance.log("Transactions: $txs", level: LogLevel.Info);
|
||||||
|
if (txs == null || txs.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Tuple2<Transaction, Address>> transactions = [];
|
||||||
|
for (final theTx in txs) {
|
||||||
|
final TransactionType txType;
|
||||||
|
|
||||||
|
if (myAddress.value == theTx.senderAddress) {
|
||||||
|
txType = TransactionType.outgoing;
|
||||||
|
} else if (myAddress.value == theTx.receiverAddress) {
|
||||||
|
if (myAddress.value == theTx.senderAddress) {
|
||||||
|
txType = TransactionType.sentToSelf;
|
||||||
|
} else {
|
||||||
|
txType = TransactionType.incoming;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
txType = TransactionType.unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
var transaction = Transaction(
|
||||||
|
walletId: walletId,
|
||||||
|
txid: theTx.hash,
|
||||||
|
timestamp: theTx.timestamp,
|
||||||
|
type: txType,
|
||||||
|
subType: TransactionSubType.none,
|
||||||
|
amount: theTx.amountInMicroTez,
|
||||||
|
amountString: Amount(
|
||||||
|
rawValue: BigInt.parse(theTx.amountInMicroTez.toString()),
|
||||||
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
).toJsonString(),
|
||||||
|
fee: theTx.feeInMicroTez,
|
||||||
|
height: theTx.height,
|
||||||
|
isCancelled: false,
|
||||||
|
isLelantus: false,
|
||||||
|
slateId: "",
|
||||||
|
otherData: "",
|
||||||
|
inputs: [],
|
||||||
|
outputs: [],
|
||||||
|
nonce: 0,
|
||||||
|
numberOfMessages: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
final Address theAddress;
|
||||||
|
switch (txType) {
|
||||||
|
case TransactionType.incoming:
|
||||||
|
case TransactionType.sentToSelf:
|
||||||
|
theAddress = myAddress;
|
||||||
|
break;
|
||||||
|
case TransactionType.outgoing:
|
||||||
|
case TransactionType.unknown:
|
||||||
|
theAddress = Address(
|
||||||
|
walletId: walletId,
|
||||||
|
value: theTx.receiverAddress,
|
||||||
|
publicKey: [],
|
||||||
|
derivationIndex: 0,
|
||||||
|
derivationPath: null,
|
||||||
|
type: AddressType.unknown,
|
||||||
|
subType: AddressSubType.unknown,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
transactions.add(Tuple2(transaction, theAddress));
|
||||||
|
}
|
||||||
|
await mainDB.addNewTransactionData(transactions, walletId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> updateUTXOs() async {
|
||||||
|
// do nothing. Not used in tezos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue