Skip to content

Commit

Permalink
Merge pull request #332 from Build-Squad/ruben/pyxfluencer-escrow-exi…
Browse files Browse the repository at this point in the history
…stance-and-verification-of-funds

Check Escrow Account Existance and Funds availability on Validator Token Account - Add minor solana-client changes
  • Loading branch information
rcolomina authored May 1, 2024
2 parents cef89bf + e8694c7 commit 538bf1f
Show file tree
Hide file tree
Showing 19 changed files with 310 additions and 227 deletions.
21 changes: 6 additions & 15 deletions solana-client/components/CancelEscrowSolana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,15 @@ export const CancelEscrowSolana: FC<CancelEscrowSolanaProps> = ({business,
skipPreflight: true
}

try {
const signature = await sendTransaction(tx, connection, options);
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing", txSign);
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if(txSign.value.err != null){
throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch(error)
{
console.error(error)
}
const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);

}

return (
<button className={styles.button} onClick={onClick}>Cancel Business {business}</button>
<button className={styles.button} onClick={onClick}>
Cancel Business {business}
</button>
)

}
17 changes: 3 additions & 14 deletions solana-client/components/CancelEscrowSpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,10 @@ export const CancelEscrowSpl: FC<CancelEscrowSplProps> = (
const options = {
skipPreflight: true
}
const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);


try {
const signature = await sendTransaction(tx, connection, options);
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing", txSign);
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if(txSign.value.err != null){
throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch(error)
{
console.error(error)
}
}

return (
Expand Down
20 changes: 5 additions & 15 deletions solana-client/components/ClaimEscrowSolana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,11 @@ export const ClaimEscrowSolana: FC<ClaimEscrowSolanaProps> = ({
const options = {
skipPreflight: false
}
try {
const signature = await sendTransaction(tx, connection, options);
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing",txSign)
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if(txSign.value.err != null){
throw new Error(`Instruction error number found: `+txSign.value.err['InstructionError'][0].toString());

}
}
catch(error)
{
console.error(error)
}

const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);



}

Expand Down
19 changes: 4 additions & 15 deletions solana-client/components/ClaimEscrowSpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,10 @@ export const ClaimEscrowSpl: FC<ClaimEscrowSplProps> = ({ business,
const options = {
skipPreflight: true
}
try {
const signature = await sendTransaction(tx, connection, options);
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing", txSign)
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if (txSign.value.err != null) {
throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());

}
}
catch (error) {
console.warn("an error was raised sending claim for spl");
console.error(error)
}
const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);


}

return (
Expand Down
23 changes: 5 additions & 18 deletions solana-client/components/CreateEscrowSolana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const CreateEscrowSolana: FC<CreateEscrowSolanaProps> = ({validator, busi
)
} else {
console.warn("Wallet does NOT Business Configuration");
console.log("public",publicKey)
console.log("wallet",wallet.publicKey)
console.log("public:",publicKey.toString())
console.log("wallet:",wallet.publicKey.toString())
}


Expand Down Expand Up @@ -100,22 +100,9 @@ export const CreateEscrowSolana: FC<CreateEscrowSolanaProps> = ({validator, busi
const options = {
skipPreflight: true
}

try {
const signature = await sendTransaction(tx, connection, options);
console.debug("signature", signature.valueOf());
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing",txSign.value);
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if(txSign.value.err != null){
throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch(error)
{
console.error(error);
}

const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);
}

return (
Expand Down
19 changes: 3 additions & 16 deletions solana-client/components/CreateEscrowSpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,9 @@ export const CreateEscrowSpl: FC<CreateEscrowSplProps> = ({validator,
skipPreflight: true,
confirm: false
}

try {
const signature = await sendTransaction(tx, connection, options);
console.debug("signature", signature.valueOf());
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing",txSign.value);
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if(txSign.value.err != null){
throw new Error(`Instruction Error Number Found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch(error)
{
console.error(error);
}
const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);

}

return (
Expand Down
23 changes: 4 additions & 19 deletions solana-client/components/Validate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const Validate: FC<ValidateProps> = ({validator,
</div>
)
} else {
console.log("wallet",wallet.publicKey)
console.log("wallet",wallet.publicKey.toString())
}


Expand Down Expand Up @@ -109,29 +109,14 @@ export const Validate: FC<ValidateProps> = ({validator,
preflightCommitment: 'confirmed'
};

try {
const signature = await sendTransaction(tx, connection, options);
console.debug("signature", signature.valueOf());
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing",txSign.value);
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if(txSign.value.err != null){
throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch(error)
{
console.error(error)
alert("Error Found on Validation " + error);
}

const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);

}

return (
<button className={styles.button} onClick={onClick}>
{textButton}
{textButton} | Validator == {validator}
</button>
)

Expand Down
23 changes: 4 additions & 19 deletions solana-client/components/ValidateEscrowSpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ValidateEscrowSpl: FC<ValidateEscrowSplProps> = ({
</div>
)
} else {
console.log("wallet", wallet.publicKey)
console.log("wallet", wallet.publicKey.toString())
}


Expand Down Expand Up @@ -104,29 +104,14 @@ export const ValidateEscrowSpl: FC<ValidateEscrowSplProps> = ({
const options = {
skipPreflight: true
}

try {
const signature = await sendTransaction(tx, connection, options);
console.debug("signature", signature.valueOf());
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing", txSign.value);
console.debug("context", txSign.context);
console.debug("value", txSign.value);
if (txSign.value.err != null) {
throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch (error) {
console.error(error)
alert("Error Found on Validation " + error);
}

const signature = await sendTransaction(tx, connection, options);
await utils.confirmTransactionSignature(signature, connection);

}

return (
<button className={styles.button} onClick={onClick}>
{textButton}
{textButton} | Validator == {validator}
</button>
)

Expand Down
28 changes: 23 additions & 5 deletions solana-client/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ import {
TransactionInstruction,
TransactionSignature,
clusterApiUrl,
TransactionConfirmationStrategy,
} from '@solana/web3.js';

import { useAnchorWallet, useWallet } from '@solana/wallet-adapter-react';

import idl from "../xfluencer.json"

//import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet";
import { TOKEN_PROGRAM_ID } from "@project-serum/anchor/dist/cjs/utils/token";

import { Connection, Commitment } from '@solana/web3.js'
import { SignerWalletAdapterProps } from "@solana/wallet-adapter-base";
import { SendTransactionOptions, SignerWalletAdapterProps } from "@solana/wallet-adapter-base";


export enum AccountState {
Expand Down Expand Up @@ -255,12 +258,10 @@ export async function getOrCreateAssociatedTokenAccount(

// This is the optimal logic, considering TX fee, client-side computation, RPC roundtrips and guaranteed idempotent.
// Sadly we can't do this atomically.
let account;
let account = null;
try {
console.log("associatedToken", associatedToken.toString())
account = await getAccountInfo(connection,
associatedToken,
commitment, programId)
account = await getAccountInfo(connection, associatedToken, commitment, programId)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error) {
Expand Down Expand Up @@ -358,6 +359,23 @@ export const getAnchorProgram = (connection: Connection): anchor.Program => {
}


export const confirmTransactionSignature = async (
signature: string,
connection: Connection,
) =>{
try {
const txSign = await connection.confirmTransaction(signature, "processed");
console.debug("txSing:", txSign, "context", txSign.context.slot, "value", txSign.value.err);
if(txSign.value.err != null){
throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch(error)
{
console.error(error)
}

}



Expand Down
Loading

0 comments on commit 538bf1f

Please sign in to comment.