mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-22 19:39:22 +00:00
use final where possible in sol wallet
This commit is contained in:
parent
0fdc4c76a3
commit
f7cadcdc62
1 changed files with 22 additions and 21 deletions
|
@ -37,7 +37,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Address> _getCurrentAddress() async {
|
Future<Address> _getCurrentAddress() async {
|
||||||
var addressStruct = Address(
|
final addressStruct = Address(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
value: (await _getKeyPair()).address,
|
value: (await _getKeyPair()).address,
|
||||||
publicKey: List<int>.empty(),
|
publicKey: List<int>.empty(),
|
||||||
|
@ -50,7 +50,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
|
|
||||||
Future<int> _getCurrentBalanceInLamports() async {
|
Future<int> _getCurrentBalanceInLamports() async {
|
||||||
_checkClient();
|
_checkClient();
|
||||||
var balance = await _rpcClient?.getBalance((await _getKeyPair()).address);
|
final balance = await _rpcClient?.getBalance((await _getKeyPair()).address);
|
||||||
return balance!.value;
|
return balance!.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
@override
|
@override
|
||||||
Future<void> checkSaveInitialReceivingAddress() async {
|
Future<void> checkSaveInitialReceivingAddress() async {
|
||||||
try {
|
try {
|
||||||
var address = (await _getKeyPair()).address;
|
final address = (await _getKeyPair()).address;
|
||||||
|
|
||||||
await mainDB.updateOrPutAddresses([
|
await mainDB.updateOrPutAddresses([
|
||||||
Address(
|
Address(
|
||||||
|
@ -90,14 +90,14 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
throw Exception("$runtimeType prepareSend requires 1 recipient");
|
throw Exception("$runtimeType prepareSend requires 1 recipient");
|
||||||
}
|
}
|
||||||
|
|
||||||
Amount sendAmount = txData.amount!;
|
final Amount sendAmount = txData.amount!;
|
||||||
|
|
||||||
if (sendAmount > info.cachedBalance.spendable) {
|
if (sendAmount > info.cachedBalance.spendable) {
|
||||||
throw Exception("Insufficient available balance");
|
throw Exception("Insufficient available balance");
|
||||||
}
|
}
|
||||||
|
|
||||||
int feeAmount;
|
int feeAmount;
|
||||||
var currentFees = await fees;
|
final currentFees = await fees;
|
||||||
switch (txData.feeRateType) {
|
switch (txData.feeRateType) {
|
||||||
case FeeRateType.fast:
|
case FeeRateType.fast:
|
||||||
feeAmount = currentFees.fast;
|
feeAmount = currentFees.fast;
|
||||||
|
@ -114,9 +114,10 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
// Rent exemption of Solana
|
// Rent exemption of Solana
|
||||||
final accInfo =
|
final accInfo =
|
||||||
await _rpcClient?.getAccountInfo((await _getKeyPair()).address);
|
await _rpcClient?.getAccountInfo((await _getKeyPair()).address);
|
||||||
int minimumRent = await _rpcClient?.getMinimumBalanceForRentExemption(
|
final int minimumRent =
|
||||||
accInfo!.value!.data.toString().length) ??
|
await _rpcClient?.getMinimumBalanceForRentExemption(
|
||||||
0; // TODO revisit null condition.
|
accInfo!.value!.data.toString().length) ??
|
||||||
|
0; // TODO revisit null condition.
|
||||||
if (minimumRent >
|
if (minimumRent >
|
||||||
((await _getCurrentBalanceInLamports()) -
|
((await _getCurrentBalanceInLamports()) -
|
||||||
txData.amount!.raw.toInt() -
|
txData.amount!.raw.toInt() -
|
||||||
|
@ -146,8 +147,8 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
_checkClient();
|
_checkClient();
|
||||||
|
|
||||||
final keyPair = await _getKeyPair();
|
final keyPair = await _getKeyPair();
|
||||||
var recipientAccount = txData.recipients!.first;
|
final recipientAccount = txData.recipients!.first;
|
||||||
var recipientPubKey =
|
final recipientPubKey =
|
||||||
Ed25519HDPublicKey.fromBase58(recipientAccount.address);
|
Ed25519HDPublicKey.fromBase58(recipientAccount.address);
|
||||||
final message = Message(
|
final message = Message(
|
||||||
instructions: [
|
instructions: [
|
||||||
|
@ -230,7 +231,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
@override
|
@override
|
||||||
Future<void> recover({required bool isRescan}) async {
|
Future<void> recover({required bool isRescan}) async {
|
||||||
await refreshMutex.protect(() async {
|
await refreshMutex.protect(() async {
|
||||||
var addressStruct = await _getCurrentAddress();
|
final addressStruct = await _getCurrentAddress();
|
||||||
|
|
||||||
await mainDB.updateOrPutAddresses([addressStruct]);
|
await mainDB.updateOrPutAddresses([addressStruct]);
|
||||||
|
|
||||||
|
@ -254,7 +255,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
try {
|
try {
|
||||||
_checkClient();
|
_checkClient();
|
||||||
|
|
||||||
var balance = await _rpcClient?.getBalance(info.cachedReceivingAddress);
|
final balance = await _rpcClient?.getBalance(info.cachedReceivingAddress);
|
||||||
|
|
||||||
// Rent exemption of Solana
|
// Rent exemption of Solana
|
||||||
final accInfo =
|
final accInfo =
|
||||||
|
@ -265,7 +266,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
accInfo!.value!.data.toString().length) ??
|
accInfo!.value!.data.toString().length) ??
|
||||||
0;
|
0;
|
||||||
// TODO [prio=low]: revisit null condition.
|
// TODO [prio=low]: revisit null condition.
|
||||||
var spendableBalance = balance!.value - minimumRent;
|
final spendableBalance = balance!.value - minimumRent;
|
||||||
|
|
||||||
final newBalance = Balance(
|
final newBalance = Balance(
|
||||||
total: Amount(
|
total: Amount(
|
||||||
|
@ -300,7 +301,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
try {
|
try {
|
||||||
_checkClient();
|
_checkClient();
|
||||||
|
|
||||||
int blockHeight = await _rpcClient?.getSlot() ?? 0;
|
final int blockHeight = await _rpcClient?.getSlot() ?? 0;
|
||||||
// TODO [prio=low]: Revisit null condition.
|
// TODO [prio=low]: Revisit null condition.
|
||||||
|
|
||||||
await info.updateCachedChainHeight(
|
await info.updateCachedChainHeight(
|
||||||
|
@ -335,21 +336,21 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
try {
|
try {
|
||||||
_checkClient();
|
_checkClient();
|
||||||
|
|
||||||
var transactionsList = await _rpcClient?.getTransactionsList(
|
final transactionsList = await _rpcClient?.getTransactionsList(
|
||||||
(await _getKeyPair()).publicKey,
|
(await _getKeyPair()).publicKey,
|
||||||
encoding: Encoding.jsonParsed);
|
encoding: Encoding.jsonParsed);
|
||||||
var txsList =
|
final txsList =
|
||||||
List<Tuple2<isar.Transaction, Address>>.empty(growable: true);
|
List<Tuple2<isar.Transaction, Address>>.empty(growable: true);
|
||||||
|
|
||||||
// TODO [prio=low]: Revisit null assertion below.
|
// TODO [prio=low]: Revisit null assertion below.
|
||||||
|
|
||||||
for (final tx in transactionsList!) {
|
for (final tx in transactionsList!) {
|
||||||
var senderAddress =
|
final senderAddress =
|
||||||
(tx.transaction as ParsedTransaction).message.accountKeys[0].pubkey;
|
(tx.transaction as ParsedTransaction).message.accountKeys[0].pubkey;
|
||||||
var receiverAddress =
|
final receiverAddress =
|
||||||
(tx.transaction as ParsedTransaction).message.accountKeys[1].pubkey;
|
(tx.transaction as ParsedTransaction).message.accountKeys[1].pubkey;
|
||||||
var txType = isar.TransactionType.unknown;
|
var txType = isar.TransactionType.unknown;
|
||||||
var txAmount = Amount(
|
final txAmount = Amount(
|
||||||
rawValue:
|
rawValue:
|
||||||
BigInt.from(tx.meta!.postBalances[1] - tx.meta!.preBalances[1]),
|
BigInt.from(tx.meta!.postBalances[1] - tx.meta!.preBalances[1]),
|
||||||
fractionDigits: cryptoCurrency.fractionDigits,
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
@ -364,7 +365,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
txType = isar.TransactionType.incoming;
|
txType = isar.TransactionType.incoming;
|
||||||
}
|
}
|
||||||
|
|
||||||
var transaction = isar.Transaction(
|
final transaction = isar.Transaction(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
txid: (tx.transaction as ParsedTransaction).signatures[0],
|
txid: (tx.transaction as ParsedTransaction).signatures[0],
|
||||||
timestamp: tx.blockTime!,
|
timestamp: tx.blockTime!,
|
||||||
|
@ -384,7 +385,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
numberOfMessages: 0,
|
numberOfMessages: 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
var txAddress = Address(
|
final txAddress = Address(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
value: receiverAddress,
|
value: receiverAddress,
|
||||||
publicKey: List<int>.empty(),
|
publicKey: List<int>.empty(),
|
||||||
|
|
Loading…
Reference in a new issue