mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
fix deprecated fee func and null fees.
This commit is contained in:
parent
420c73ed5d
commit
f279bf1f3b
1 changed files with 36 additions and 11 deletions
|
@ -1,9 +1,11 @@
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:socks5_proxy/socks_client.dart';
|
import 'package:socks5_proxy/socks_client.dart';
|
||||||
import 'package:solana/dto.dart';
|
import 'package:solana/dto.dart';
|
||||||
|
import 'package:solana/encoder.dart';
|
||||||
import 'package:solana/solana.dart';
|
import 'package:solana/solana.dart';
|
||||||
import 'package:stackwallet/models/balance.dart';
|
import 'package:stackwallet/models/balance.dart';
|
||||||
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'
|
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'
|
||||||
|
@ -54,6 +56,21 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
return balance!.value;
|
return balance!.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int?> _getEstimatedNetworkFee(Amount transferAmount) async {
|
||||||
|
final latestBlockhash = await _rpcClient?.getLatestBlockhash();
|
||||||
|
|
||||||
|
final compiledMessage = Message(instructions: [
|
||||||
|
SystemInstruction.transfer(
|
||||||
|
fundingAccount: (await _getKeyPair()).publicKey,
|
||||||
|
recipientAccount: (await _getKeyPair()).publicKey,
|
||||||
|
lamports: transferAmount.raw.toInt()),
|
||||||
|
]).compile(recentBlockhash: latestBlockhash!.value.blockhash, feePayer: (await _getKeyPair()).publicKey);
|
||||||
|
|
||||||
|
return await _rpcClient?.getFeeForMessage(
|
||||||
|
base64Encode(compiledMessage.toByteArray().toList()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FilterOperation? get changeAddressFilterOperation =>
|
FilterOperation? get changeAddressFilterOperation =>
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
|
@ -185,11 +202,13 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final fee = await _rpcClient?.getFees();
|
final fee = await _getEstimatedNetworkFee(amount);
|
||||||
// TODO [prio=low]: handle null fee.
|
if (fee == null) {
|
||||||
|
throw Exception("Failed to get fees, please check your node connection.");
|
||||||
|
}
|
||||||
|
|
||||||
return Amount(
|
return Amount(
|
||||||
rawValue: BigInt.from(fee!.value.feeCalculator.lamportsPerSignature),
|
rawValue: BigInt.from(fee as num),
|
||||||
fractionDigits: cryptoCurrency.fractionDigits,
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -198,15 +217,21 @@ class SolanaWallet extends Bip39Wallet<Solana> {
|
||||||
Future<FeeObject> get fees async {
|
Future<FeeObject> get fees async {
|
||||||
_checkClient();
|
_checkClient();
|
||||||
|
|
||||||
final fees = await _rpcClient?.getFees();
|
final fee = await _getEstimatedNetworkFee(Amount(
|
||||||
// TODO [prio=low]: handle null fees.
|
rawValue: BigInt.from(1000000000), // 1 SOL
|
||||||
|
fractionDigits: cryptoCurrency.fractionDigits,
|
||||||
|
));
|
||||||
|
if (fee == null) {
|
||||||
|
throw Exception("Failed to get fees, please check your node connection.");
|
||||||
|
}
|
||||||
|
|
||||||
return FeeObject(
|
return FeeObject(
|
||||||
numberOfBlocksFast: 1,
|
numberOfBlocksFast: 1,
|
||||||
numberOfBlocksAverage: 1,
|
numberOfBlocksAverage: 1,
|
||||||
numberOfBlocksSlow: 1,
|
numberOfBlocksSlow: 1,
|
||||||
fast: fees!.value.feeCalculator.lamportsPerSignature,
|
fast: fee,
|
||||||
medium: fees!.value.feeCalculator.lamportsPerSignature,
|
medium: fee,
|
||||||
slow: fees!.value.feeCalculator.lamportsPerSignature);
|
slow: fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
Loading…
Reference in a new issue