From c880dbd83c54cd1e338ecec4c3caebe183915fd7 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Tue, 31 Dec 2024 07:33:45 +0200 Subject: [PATCH 1/2] fix creating associated token account --- cw_solana/lib/solana_client.dart | 49 ++++++++++++++++++++++++++------ cw_solana/lib/solana_wallet.dart | 1 - 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/cw_solana/lib/solana_client.dart b/cw_solana/lib/solana_client.dart index 2207822bb..9412b4e9c 100644 --- a/cw_solana/lib/solana_client.dart +++ b/cw_solana/lib/solana_client.dart @@ -481,6 +481,9 @@ class SolanaWalletClient { final destinationOwner = Ed25519HDPublicKey.fromBase58(destinationAddress); final mint = Ed25519HDPublicKey.fromBase58(tokenMint); + // Input by the user + final amount = (inputAmount * math.pow(10, tokenDecimals)).toInt(); + ProgramAccount? associatedRecipientAccount; ProgramAccount? associatedSenderAccount; @@ -503,18 +506,46 @@ class SolanaWalletClient { } try { - associatedRecipientAccount ??= await _client!.createAssociatedTokenAccount( - mint: mint, - owner: destinationOwner, - funder: ownerKeypair, - ); + if (associatedRecipientAccount == null) { + final derivedAddress = await findAssociatedTokenAddress( + owner: destinationOwner, + mint: mint, + ); + + final instruction = AssociatedTokenAccountInstruction.createAccount( + mint: mint, + address: derivedAddress, + owner: ownerKeypair.publicKey, + funder: ownerKeypair.publicKey, + ); + + final _signedTx = await _signTransactionInternal( + message: Message.only(instruction), + signers: [ownerKeypair], + commitment: commitment, + latestBlockhash: await _getLatestBlockhash(commitment), + ); + + await sendTransaction( + signedTransaction: _signedTx, + commitment: commitment, + ); + + associatedRecipientAccount = ProgramAccount( + pubkey: derivedAddress.toBase58(), + account: Account( + owner: destinationOwner.toBase58(), + lamports: 0, + executable: false, + rentEpoch: BigInt.zero, + data: null, + ), + ); + } } catch (e) { throw SolanaCreateAssociatedTokenAccountException(e.toString()); } - // Input by the user - final amount = (inputAmount * math.pow(10, tokenDecimals)).toInt(); - final instruction = TokenInstruction.transfer( source: Ed25519HDPublicKey.fromBase58(associatedSenderAccount.pubkey), destination: Ed25519HDPublicKey.fromBase58(associatedRecipientAccount.pubkey), @@ -587,6 +618,8 @@ class SolanaWalletClient { signedTransaction.encode(), preflightCommitment: commitment, ); + print("#########"); + print(signature); _client!.waitForSignatureStatus(signature, status: commitment); diff --git a/cw_solana/lib/solana_wallet.dart b/cw_solana/lib/solana_wallet.dart index 33a2e7df4..15c065918 100644 --- a/cw_solana/lib/solana_wallet.dart +++ b/cw_solana/lib/solana_wallet.dart @@ -33,7 +33,6 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:solana/base58.dart'; import 'package:solana/metaplex.dart' as metaplex; import 'package:solana/solana.dart'; -import 'package:solana/src/crypto/ed25519_hd_keypair.dart'; part 'solana_wallet.g.dart'; From 26c1f0b85c2e2de404d9a4597d69650510b3e7c4 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Tue, 31 Dec 2024 08:06:56 +0200 Subject: [PATCH 2/2] remove print --- lib/entities/parse_address_from_domain.dart | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/entities/parse_address_from_domain.dart b/lib/entities/parse_address_from_domain.dart index 258ebf485..b13dfa9ad 100644 --- a/lib/entities/parse_address_from_domain.dart +++ b/lib/entities/parse_address_from_domain.dart @@ -259,25 +259,13 @@ class AddressResolver { } } - print("@@@@@@@@"); - print(formattedName); - print(domainParts); - print(name); - if (formattedName.contains(".")) { if (settingsStore.lookupsOpenAlias) { final txtRecord = await OpenaliasRecord.lookupOpenAliasRecord(formattedName); - print("@@@@@@@@"); - print(txtRecord); if (txtRecord != null) { final record = await OpenaliasRecord.fetchAddressAndName( formattedName: formattedName, ticker: ticker.toLowerCase(), txtRecord: txtRecord); - print("@@@@@@@@"); - print(record); - print(record.name); - print(record.address); - print(record.description); return ParsedAddress.fetchOpenAliasAddress(record: record, name: text); } }