mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-01 12:04:21 +01:00
Solana Wallet New Implementation (#2011)
* Feat: Implement Solana wallet using on_chain * v4.23.0 release candidate (#1974) * v4.23.0 release candidate * - Fix restoring zano from QR - Fix Zano confirmations count - Fix birdpay - Fix balance display * Fix Zano assets showing amount before they are added * - handle fetching token data while the API is busy - potential fix for duplicate transactions * fix receive confirmations, maybe * revert onChangeWallet cleanup * Fix confirmations not updating * improve zano wallet opening, fix CI commands and messages on slack (#1979) Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Cache wallet when creating/restoring as well * - hardcode Trocador Maximum limit for Zano temporarily - Configure Cake Zano node to use SSL * reformatting [skip ci] * revert to non-ssl * update build numbers [skip ci] * disable zano for desktop [skip ci] --------- Co-authored-by: cyan <cyjan@mrcyjanek.net> * CW-711 passphrase for XMR/WOWcreation (#1992) * add monero passphrase add wownero passphrase add passphrase to seed screen * obscure passphrase by default disable passphrase create for zano * Update lib/view_model/wallet_keys_view_model.dart [skip ci] * Update lib/src/screens/wallet_keys/wallet_keys_page.dart [skip ci] * Update lib/view_model/advanced_privacy_settings_view_model.dart * dynamic passphrase icon * fix polyseed not being encrypted by passphrase --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * show Zano keys properly in the keys tab (#2004) * fix: Switch private key hex encoding * Modified existing implementation to use older version of packages * fix: Fetch direct transaction history amounts instead of decimals, and add Create Account Instructions to Transaction History List * fix: Remove Create Account entries in Transaction History and disable activating token accounts of selected tokens * feat: Add passphrase support to Solana * fix: Issues with transaction amount and dissappearing transaction history items (very annoying bug) * fix: Issue with flipping transactions and incorrect transaction status * PR Review fixes --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> Co-authored-by: cyan <cyjan@mrcyjanek.net>
This commit is contained in:
co-authored by
Omar Hatem
cyan
parent
1c29be7993
commit
1b5be705f6
@@ -1,5 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:cake_wallet/core/wallet_connect/chain_service/solana/entities/solana_sign_message.dart';
|
||||
import 'package:cake_wallet/core/wallet_connect/chain_service/solana/solana_chain_id.dart';
|
||||
import 'package:cake_wallet/core/wallet_connect/wc_bottom_sheet_service.dart';
|
||||
@@ -8,9 +10,9 @@ import 'package:cake_wallet/src/screens/wallet_connect/widgets/message_display_w
|
||||
import 'package:cake_wallet/core/wallet_connect/models/connection_model.dart';
|
||||
import 'package:cake_wallet/src/screens/wallet_connect/widgets/connection_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/wallet_connect/widgets/modals/web3_request_modal.dart';
|
||||
import 'package:cw_core/solana_rpc_http_service.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:solana/base58.dart';
|
||||
import 'package:solana/solana.dart';
|
||||
import 'package:on_chain/solana/solana.dart';
|
||||
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
|
||||
import '../chain_service.dart';
|
||||
import '../../wallet_connect_key_service.dart';
|
||||
@@ -27,25 +29,19 @@ class SolanaChainServiceImpl implements ChainService {
|
||||
|
||||
final SolanaChainId reference;
|
||||
|
||||
final SolanaClient solanaClient;
|
||||
final SolanaRPC solanaProvider;
|
||||
|
||||
final Ed25519HDKeyPair? ownerKeyPair;
|
||||
final SolanaPrivateKey? ownerPrivateKey;
|
||||
|
||||
SolanaChainServiceImpl({
|
||||
required this.reference,
|
||||
required this.wcKeyService,
|
||||
required this.bottomSheetService,
|
||||
required this.wallet,
|
||||
required this.ownerKeyPair,
|
||||
required String webSocketUrl,
|
||||
required Uri rpcUrl,
|
||||
SolanaClient? solanaClient,
|
||||
}) : solanaClient = solanaClient ??
|
||||
SolanaClient(
|
||||
rpcUrl: rpcUrl,
|
||||
websocketUrl: Uri.parse(webSocketUrl),
|
||||
timeout: const Duration(minutes: 5),
|
||||
) {
|
||||
required this.ownerPrivateKey,
|
||||
required String formattedRPCUrl,
|
||||
SolanaRPC? solanaProvider,
|
||||
}) : solanaProvider = solanaProvider ?? SolanaRPC(SolanaRPCHTTPService(url: formattedRPCUrl)) {
|
||||
for (final String event in getEvents()) {
|
||||
wallet.registerEventEmitter(chainId: getChainId(), event: event);
|
||||
}
|
||||
@@ -110,26 +106,20 @@ class SolanaChainServiceImpl implements ChainService {
|
||||
}
|
||||
|
||||
try {
|
||||
final message =
|
||||
await solanaClient.rpcClient.getMessageFromEncodedTx(solanaSignTx.transaction);
|
||||
// Convert transaction string to bytes
|
||||
List<int> transactionBytes = base64Decode(solanaSignTx.transaction);
|
||||
|
||||
final sign = await ownerKeyPair?.signMessage(
|
||||
message: message,
|
||||
recentBlockhash: solanaSignTx.recentBlockhash ?? '',
|
||||
final message = SolanaTransactionUtils.deserializeMessageLegacy(transactionBytes);
|
||||
|
||||
final sign = ownerPrivateKey!.sign(message.serialize());
|
||||
|
||||
final signature = solanaProvider.request(
|
||||
SolanaRPCSendTransaction(
|
||||
encodedTransaction: Base58Encoder.encode(sign),
|
||||
commitment: Commitment.confirmed,
|
||||
),
|
||||
);
|
||||
|
||||
if (sign == null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
String signature = await solanaClient.sendAndConfirmTransaction(
|
||||
message: message,
|
||||
signers: [ownerKeyPair!],
|
||||
commitment: Commitment.confirmed,
|
||||
);
|
||||
|
||||
printV(signature);
|
||||
|
||||
bottomSheetService.queueBottomSheet(
|
||||
isModalDismissible: true,
|
||||
widget: BottomSheetMessageDisplayWidget(
|
||||
@@ -161,10 +151,10 @@ class SolanaChainServiceImpl implements ChainService {
|
||||
if (authError != null) {
|
||||
return authError;
|
||||
}
|
||||
Signature? sign;
|
||||
List<int>? sign;
|
||||
|
||||
try {
|
||||
sign = await ownerKeyPair?.sign(base58decode(solanaSignMessage.message));
|
||||
sign = ownerPrivateKey!.sign(Base58Decoder.decode(solanaSignMessage.message));
|
||||
} catch (e) {
|
||||
printV(e);
|
||||
}
|
||||
@@ -173,7 +163,7 @@ class SolanaChainServiceImpl implements ChainService {
|
||||
return '';
|
||||
}
|
||||
|
||||
String signature = sign.toBase58();
|
||||
final signature = Base58Encoder.encode(sign);
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:eth_sig_util/eth_sig_util.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:on_chain/solana/solana.dart' hide Store;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
|
||||
|
||||
@@ -140,29 +141,28 @@ abstract class Web3WalletServiceBase with Store {
|
||||
for (final cId in SolanaChainId.values) {
|
||||
final node = appStore.settingsStore.getCurrentNode(appStore.wallet!.type);
|
||||
|
||||
Uri rpcUri = node.uri;
|
||||
String webSocketUrl = 'wss://${node.uriRaw}';
|
||||
String formattedUrl;
|
||||
String protocolUsed = node.isSSL ? "https" : "http";
|
||||
|
||||
if (node.uriRaw == 'rpc.ankr.com') {
|
||||
String ankrApiKey = secrets.ankrApiKey;
|
||||
|
||||
rpcUri = Uri.https(node.uriRaw, '/solana/$ankrApiKey');
|
||||
webSocketUrl = 'wss://${node.uriRaw}/solana/ws/$ankrApiKey';
|
||||
formattedUrl = '$protocolUsed://${node.uriRaw}/$ankrApiKey';
|
||||
} else if (node.uriRaw == 'solana-mainnet.core.chainstack.com') {
|
||||
String chainStackApiKey = secrets.chainStackApiKey;
|
||||
|
||||
rpcUri = Uri.https(node.uriRaw, '/$chainStackApiKey');
|
||||
webSocketUrl = 'wss://${node.uriRaw}/$chainStackApiKey';
|
||||
formattedUrl = '$protocolUsed://${node.uriRaw}/$chainStackApiKey';
|
||||
} else {
|
||||
formattedUrl = '$protocolUsed://${node.uriRaw}';
|
||||
}
|
||||
|
||||
SolanaChainServiceImpl(
|
||||
reference: cId,
|
||||
rpcUrl: rpcUri,
|
||||
webSocketUrl: webSocketUrl,
|
||||
formattedRPCUrl: formattedUrl,
|
||||
wcKeyService: walletKeyService,
|
||||
bottomSheetService: _bottomSheetHandler,
|
||||
wallet: _web3Wallet,
|
||||
ownerKeyPair: solana!.getWalletKeyPair(appStore.wallet!),
|
||||
ownerPrivateKey: SolanaPrivateKey.fromSeedHex(solana!.getPrivateKey(appStore.wallet!)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +52,8 @@ class CWSolana extends Solana {
|
||||
String getPrivateKey(WalletBase wallet) => (wallet as SolanaWallet).privateKey;
|
||||
|
||||
@override
|
||||
String getPublicKey(WalletBase wallet) => (wallet as SolanaWallet).keys.publicKey.toBase58();
|
||||
|
||||
@override
|
||||
Ed25519HDKeyPair? getWalletKeyPair(WalletBase wallet) => (wallet as SolanaWallet).walletKeyPair;
|
||||
|
||||
String getPublicKey(WalletBase wallet) =>
|
||||
(wallet as SolanaWallet).solanaPublicKey.toAddress().address;
|
||||
Object createSolanaTransactionCredentials(
|
||||
List<Output> outputs, {
|
||||
required CryptoCurrency currency,
|
||||
|
||||
@@ -326,7 +326,7 @@ class _WalletKeysPageBodyState extends State<WalletKeysPageBody>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildBottomActionPanel({
|
||||
required String titleForClipboard,
|
||||
required String dataToCopy,
|
||||
|
||||
@@ -78,6 +78,7 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
|
||||
WalletType.ethereum,
|
||||
WalletType.polygon,
|
||||
WalletType.tron,
|
||||
WalletType.solana,
|
||||
WalletType.monero,
|
||||
WalletType.wownero,
|
||||
WalletType.zano,
|
||||
|
||||
Reference in New Issue
Block a user