gshell_changes

[?]
Nov 10, 2023, 7:05 PM
CN6PVEIDCNCQD6GRZ3XB66VIFXLL7DW5IVWTAO6WTKG7D4OYZIJAC

Dependencies

Change contents

  • replacement in psc_at_app/src/index.ts at line 10
    [2.86][2.86:159]()
    import { Transaction, SystemProgram, PublicKey } from '@solana/web3.js';
    [2.86]
    [2.159]
    import { Connection, Keypair, PublicKey, sendAndConfirmTransaction, SystemProgram, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
    import { Buffer } from 'buffer';
    window.Buffer = Buffer;
  • edit in psc_at_app/src/index.ts at line 14
    [2.160][2.160:161]()
  • replacement in psc_at_app/src/index.ts at line 103
    [2.2360][2.2360:2394]()
    let wallet: { address: string; };
    [2.2360]
    [2.2394]
    let wallet;
  • replacement in psc_at_app/src/index.ts at line 107
    [2.2461][2.2461:2603]()
    const resp = await window.glow.connect();
    if (resp && resp.address) {
    wallet = resp.address
    updateUI(true, resp.address);
    [2.2461]
    [3.23401]
    wallet = await window.glow.connect();
    if (wallet && wallet.address) {
    wallet.address
    updateUI(true, wallet.address);
  • edit in psc_at_app/src/index.ts at line 420
    [2.4636][2.4636:4707]()
    const MEMO_PROGRAM_ID = 'Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo';
  • edit in psc_at_app/src/index.ts at line 430
    [2.5032]
    [3.32625]
    // async function sending_post(combinedString: string) {
    // try {
  • replacement in psc_at_app/src/index.ts at line 434
    [3.32626][2.5033:5364]()
    function createTransaction(amountInLamports: number, sender: PublicKey, recipient: PublicKey, memoText: string): Transaction {
    const transaction = new Transaction();
    transaction.add(
    SystemProgram.transfer({
    fromPubkey: sender,
    toPubkey: recipient,
    lamports: amountInLamports,
    })
    );
    [3.32626]
    [2.5364]
    // const userPublicKey = new PublicKey(wallet.address);
    // // let tx = new Transaction();
    // // const connection = new Connection('http://rpc.solscan.com');
    // // console.log(connection)
    // // const { blockhash } = await connection.getLatestBlockhash();
    // // tx.recentBlockhash = blockhash;
    // // tx.feePayer = userPublicKey;
    // // // Add Memo Instruction
    // // tx.add(
    // // new TransactionInstruction({
    // // keys: [{ pubkey: userPublicKey, isSigner: true, isWritable: true }],
    // // data: Buffer.from(combinedString, "utf-8"),
    // // programId: new PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
    // // })
    // // );
    // // Determine the amount to transfer
    // const tokenPrice = await fetchTokenPrice();
    // const amountInSol = Math.ceil((1 / tokenPrice) * 1000) / 1000;
    // const amountInLamports = amountInSol * LAMPORTS_PER_SOL;
    // // Add Transfer Instruction
    // const transaction = new Transaction().add( SystemProgram.transfer({
    // fromPubkey: userPublicKey,toPubkey: new PublicKey("7nbet512GtFRGiPrrS7Ji1BXjdfAeFYQWG7tNqBatvW6"),
    // lamports: amountInLamports}),);
  • replacement in psc_at_app/src/index.ts at line 465
    [2.5365][2.5365:5497]()
    // Use TextEncoder to convert memoText to bytes
    const encoder = new TextEncoder();
    const memoData = encoder.encode(memoText);
    [2.5365]
    [2.5497]
    // // Convert transaction to base-64 encoding
    // // const transactionBase64 = tx.serialize().toString('base64');
  • replacement in psc_at_app/src/index.ts at line 468
    [2.5498][2.5498:5654]()
    const memoInstruction = {
    keys: [],
    programId: new PublicKey(MEMO_PROGRAM_ID),
    data: memoData,
    };
    transaction.add(memoInstruction);
    [2.5498]
    [2.5654]
    // // Sign and Send Transaction using Glow
    // const { signature } = await window.glow.signAndSendTransaction({
    // transactionBase64: transaction,
    // network: "mainnet",
    // waitForConfirmation: true
    // });
  • replacement in psc_at_app/src/index.ts at line 475
    [2.5655][2.5655:5679]()
    return transaction;
    }
    [2.5655]
    [2.5679]
    // // Return the transaction signature
    // console.log(signature);
    // } catch (error) {
    // console.error('Failed to send transaction:', error);
    // }
    // }
  • edit in psc_at_app/src/index.ts at line 483
    [2.5680]
    [2.5680]
    async function getLatestBlockhash() {
    try {
    const response = await fetch('https://solana-blockdata-philiasocial.replit.app/getLatestBlockhash');
    if (!response.ok) {
    throw new Error('Network response was not ok ' + response.statusText);
    }
    const blockhash = await response.text(); // assuming the blockhash is returned as plain text
    return blockhash;
    } catch (error) {
    console.error('Failed to fetch blockhash:', error);
    throw error; // re-throw the error so it can be handled by the calling code
    }
    }
  • edit in psc_at_app/src/index.ts at line 498
    [2.5735]
    [2.5735]
    try {
    const userPublicKey = new PublicKey(wallet.address);
    const blockhash = await getLatestBlockhash();
  • replacement in psc_at_app/src/index.ts at line 503
    [2.5736][2.5736:5861]()
    console.log(wallet)
    // if (!wallet) {
    // console.error('No account is connected');
    // return;
    // }
    [2.5736]
    [2.5861]
    console.log(blockhash)
    // Determine the amount to transfer
    const tokenPrice = await fetchTokenPrice();
    const amountInSol = 1 / tokenPrice;
    const amountInLamports = Math.floor(amountInSol * LAMPORTS_PER_SOL);
    console.log(amountInLamports)
    // Add Transfer Instruction
    // Add Transfer Instruction
    const transferInstruction = SystemProgram.transfer({
    fromPubkey: userPublicKey,
    toPubkey: new PublicKey("7nbet512GtFRGiPrrS7Ji1BXjdfAeFYQWG7tNqBatvW6"),
    lamports: amountInLamports,
    });
  • replacement in psc_at_app/src/index.ts at line 521
    [2.5862][3.32626:32636](),[3.32626][3.32626:32636](),[3.32636][2.5863:5986]()
    try {
    const tokenPrice = await fetchTokenPrice();
    const amountInSol = Math.ceil((1 / tokenPrice) * 1000) / 1000;
    [2.5862]
    [3.5452]
    console.log(combinedString)
    // Add Memo Instruction
    const memoInstruction = new TransactionInstruction({
    keys: [{ pubkey: userPublicKey, isSigner: true, isWritable: true }],
    data: Buffer.from(combinedString, "utf-8"),
    programId: new PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
    });
  • replacement in psc_at_app/src/index.ts at line 529
    [3.5453][2.5987:6085]()
    console.log(amountInSol)
    const amountInLamports = amountInSol * LAMPORTS_PER_SOL;
    [3.5453]
    [2.6085]
    // Combine the transfer and memo instructions into an array
    const instructions = [
    transferInstruction,
    memoInstruction,
    ];
    // create v0 compatible message
    const messageV0 = new TransactionMessage({
    payerKey: userPublicKey,
    recentBlockhash: blockhash,
    instructions,
    }).compileToV0Message();
  • edit in psc_at_app/src/index.ts at line 542
    [2.6086][2.6086:6221]()
    const sender = new PublicKey(wallet);
    const recipient = new PublicKey('7nbet512GtFRGiPrrS7Ji1BXjdfAeFYQWG7tNqBatvW6');
  • replacement in psc_at_app/src/index.ts at line 543
    [2.6222][2.6222:6480]()
    const transaction = createTransaction(amountInLamports, sender, recipient, combinedString);
    const transactionBytes = new Uint8Array(transaction.serialize());
    const transactionBase64 = btoa(new TextDecoder().decode(transactionBytes));
    [2.6222]
    [2.6480]
    const serializedTransactionV0 = new VersionedTransaction(messageV0).serialize();
    // Convert the serialized transaction to a base64 string
    const transactionBase64 = Buffer.from(serializedTransactionV0).toString('base64');
  • replacement in psc_at_app/src/index.ts at line 547
    [2.6481][2.6481:6634]()
    await window.glow.signAndSendTransaction({
    transactionBase64,
    network: "mainnet",
    waitForConfirmation: true,
    [2.6481]
    [2.6634]
    // Sign and Send Transaction using Glow
    const {
    signature
    } = await window.glow.signAndSendTransaction({
    transactionBase64: transactionBase64,
    network: "mainnet", // Note: Changed from "mainnet" to "devnet" as per your example
    waitForConfirmation: true
  • replacement in psc_at_app/src/index.ts at line 556
    [2.6647][2.6647:6738]()
    } catch (error) {
    console.error('Failed to send transaction:', error);
    }
    }
    [2.6647]
    [2.6738]
    // Return the transaction signature
    console.log(signature);
    if(signature) {
    await sendWords(signature, wallet.address);
    // showModal();
    } else {
    console.error('Transaction hash is not available');
    }
  • edit in psc_at_app/src/index.ts at line 568
    [2.6739]
    [2.6739]
    } catch (error) {
    console.error('Failed to send transaction:', error);
    }
    }
  • edit in psc_at_app/src/index.ts at line 710
    [3.6003][3.6003:6062](),[3.6062][3.33286:33289](),[3.33286][3.33286:33289](),[3.33289][3.6063:6192]()
    // Check the button state
    // await checkButtonState();
    // // If the button is disabled, exit the function early
    // if ($('#generate_algo').is(':disabled')) {
    // return;
    // }
  • edit in psc_at_app/src/index.ts at line 711
    [3.33369]
    [2.10608]
  • edit in psc_at_app/src/index.ts at line 722
    [2.10919]
    [3.6245]
  • edit in psc_at_app/package.json at line 27
    [3.118961]
    [3.118961]
    "buffer": "^6.0.3",
  • edit in psc_at_app/package-lock.json at line 27
    [3.120005]
    [3.120005]
    "buffer": "^6.0.3",