mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
Merge pull request #846 from detherminal/testing
solana fee estimation fixes
This commit is contained in:
commit
5aa1f7b08a
1 changed files with 16 additions and 23 deletions
|
@ -18,7 +18,6 @@ import 'package:stackwallet/services/tor_service.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/enums/fee_rate_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/wallets/crypto_currency/coins/solana.dart';
|
||||
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
||||
|
@ -65,11 +64,8 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
|||
fundingAccount: pubKey,
|
||||
recipientAccount: pubKey,
|
||||
lamports: transferAmount.raw.toInt(),
|
||||
),
|
||||
]).compile(
|
||||
recentBlockhash: latestBlockhash!.value.blockhash,
|
||||
feePayer: pubKey,
|
||||
);
|
||||
)
|
||||
]).compile(recentBlockhash: latestBlockhash!.value.blockhash, feePayer: (await _getKeyPair()).publicKey);
|
||||
|
||||
return await _rpcClient?.getFeeForMessage(
|
||||
base64Encode(compiledMessage.toByteArray().toList()),
|
||||
|
@ -118,19 +114,10 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
|||
throw Exception("Insufficient available balance");
|
||||
}
|
||||
|
||||
int feeAmount;
|
||||
final currentFees = await fees;
|
||||
switch (txData.feeRateType) {
|
||||
case FeeRateType.fast:
|
||||
feeAmount = currentFees.fast;
|
||||
break;
|
||||
case FeeRateType.slow:
|
||||
feeAmount = currentFees.slow;
|
||||
break;
|
||||
case FeeRateType.average:
|
||||
default:
|
||||
feeAmount = currentFees.medium;
|
||||
break;
|
||||
final feeAmount = await _getEstimatedNetworkFee(sendAmount);
|
||||
if (feeAmount == null) {
|
||||
throw Exception(
|
||||
"Failed to get fees, please check your node connection.");
|
||||
}
|
||||
|
||||
// Rent exemption of Solana
|
||||
|
@ -179,7 +166,12 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
|||
recipientAccount: recipientPubKey,
|
||||
lamports: txData.amount!.raw.toInt()),
|
||||
ComputeBudgetInstruction.setComputeUnitPrice(
|
||||
microLamports: txData.fee!.raw.toInt()),
|
||||
microLamports: txData.fee!.raw.toInt() - 5000),
|
||||
// 5000 lamports is the base fee for a transaction. This instruction adds the necessary fee on top of base fee if it is needed.
|
||||
ComputeBudgetInstruction.setComputeUnitLimit(units: 1000000),
|
||||
// 1000000 is the multiplication number to turn the compute unit price of microLamports to lamports.
|
||||
// These instructions also help the user to not pay more than the shown fee.
|
||||
// See: https://solanacookbook.com/references/basic-transactions.html#how-to-change-compute-budget-fee-priority-for-a-transaction
|
||||
],
|
||||
);
|
||||
|
||||
|
@ -379,7 +371,7 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
|||
for (final tx in transactionsList!) {
|
||||
final senderAddress =
|
||||
(tx.transaction as ParsedTransaction).message.accountKeys[0].pubkey;
|
||||
final receiverAddress =
|
||||
var receiverAddress =
|
||||
(tx.transaction as ParsedTransaction).message.accountKeys[1].pubkey;
|
||||
var txType = isar.TransactionType.unknown;
|
||||
final txAmount = Amount(
|
||||
|
@ -388,9 +380,10 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
|||
fractionDigits: cryptoCurrency.fractionDigits,
|
||||
);
|
||||
|
||||
if ((senderAddress == (await _getKeyPair()).address) &&
|
||||
(receiverAddress == (await _getKeyPair()).address)) {
|
||||
if ((senderAddress == (await _getKeyPair()).address) && (receiverAddress == "11111111111111111111111111111111")) {
|
||||
// The account that is only 1's are System Program accounts which means there is no receiver except the sender, see: https://explorer.solana.com/address/11111111111111111111111111111111
|
||||
txType = isar.TransactionType.sentToSelf;
|
||||
receiverAddress = senderAddress;
|
||||
} else if (senderAddress == (await _getKeyPair()).address) {
|
||||
txType = isar.TransactionType.outgoing;
|
||||
} else if (receiverAddress == (await _getKeyPair()).address) {
|
||||
|
|
Loading…
Reference in a new issue