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'; 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); } }