Skip to content

Commit

Permalink
Merge pull request #296 from Build-Squad/main
Browse files Browse the repository at this point in the history
Release <- Main
  • Loading branch information
varsha1305nav authored Apr 4, 2024
2 parents 6a4ea70 + d1d3cd1 commit 4c480a9
Show file tree
Hide file tree
Showing 174 changed files with 9,846 additions and 2,197 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/deploy_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,34 @@ jobs:
host: ${{ secrets.DEVSERVER }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SECRETKEY }}
command_timeout: 50m
command_timeout: 5m
script: |
cd xfluencer/influencer-marketplace
git pull
pgrep gunicorn | xargs kill -9
cd src/api/marketplace
source venv/bin/activate
pip3 install -r requirements.txt
pip3 install pyxfluencer-1.0.2-py3-none-any.whl
pip3 install pyxfluencer-1.2.0-py3-none-any.whl
python3 manage.py migrate
python3 manage.py collectstatic -link --noinput
echo "Stopping previous processes..."
pgrep gunicorn | xargs kill -9
echo "Stopping redis service..."
sudo systemctl stop redis
echo "Starting redis service..."
sudo systemctl start redis
echo "Starting gunicorn..."
nohup sh -c 'gunicorn -w 4 marketplace.wsgi:application > gunicorn.out 2>&1' &
echo "Gunicorn started."
echo "Starting celery worker..."
nohup sh -c 'celery -A marketplace worker -l info > celery_worker.out 2>&1' &
echo "Celery worker started."
echo "Starting celery beat..."
nohup sh -c 'celery -A marketplace beat -l info > celery_beat.out 2>&1' &
echo "Celery beat started."
sudo systemctl restart nginx
sudo supervisorctl restart marketplace
echo "Restarted nginx"
- name: Remove Github Actions IP from security group
if: always()
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/deploy_prod_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Deploy API - Prod

on:
push:
branches: [ release ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Get Github action IP
id: ip
uses: haythem/[email protected]
- name: Setting environment variables..
run: |
echo "AWS_DEFAULT_REGION=eu-west-2" >> $GITHUB_ENV
echo "AWS_SG_NAME=${{ secrets.AWS_SECURITY_GROUP_ID_PROD }}" >> $GITHUB_ENV
- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}

- name: Steps
uses: appleboy/ssh-action@master
continue-on-error: false
with:
host: ${{ secrets.PRODSERVER_API }}
username: ${{ secrets.USERNAME_PROD }}
key: ${{ secrets.SECRETKEY_PROD }}
command_timeout: 5m
script: |
cd xfluencer/influencer-marketplace
pwd
git status
git pull
pgrep gunicorn | xargs kill -9
cd src/api/marketplace
source venv/bin/activate
pip3 install -r requirements.txt
python3 manage.py migrate
python3 manage.py collectstatic -link --noinput
echo "Stopping previous processes..."
pgrep gunicorn | xargs kill -9
echo "Stopping redis service..."
sudo systemctl stop redis
echo "Starting redis service..."
sudo systemctl start redis
echo "Starting gunicorn..."
nohup sh -c 'gunicorn -w 4 marketplace.wsgi:application > gunicorn.out 2>&1' &
echo "Gunicorn started."
echo "Starting celery worker..."
nohup sh -c 'celery -A marketplace worker -l info > celery_worker.out 2>&1' &
echo "Celery worker started."
echo "Starting celery beat..."
nohup sh -c 'celery -A marketplace beat -l info > celery_beat.out 2>&1' &
echo "Celery beat started."
sudo systemctl restart nginx
echo "Restarted nginx"
- name: Remove Github Actions IP from security group
if: always()
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
55 changes: 55 additions & 0 deletions .github/workflows/deploy_prod_ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy UI - Prod

on:
push:
branches: [ release ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Get Github action IP
id: ip
uses: haythem/[email protected]
- name: Setting environment variables..
run: |
echo "AWS_DEFAULT_REGION=eu-west-2" >> $GITHUB_ENV
echo "AWS_SG_NAME=${{ secrets.AWS_SECURITY_GROUP_ID_PROD }}" >> $GITHUB_ENV
- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}

- name: Steps
uses: appleboy/ssh-action@master
continue-on-error: false
with:
host: ${{ secrets.PRODSERVER_UI }}
username: ${{ secrets.USERNAME_PROD }}
key: ${{ secrets.SECRETKEY_PROD }}
command_timeout: 5m
script: |
cd xfluencer/influencer-marketplace
git pull
cd src/ui
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm use 20
npm cache clean -f
npm install
npm run build
sudo systemctl restart nginx
pm2 stop marketplace
pm2 start npm --name marketplace -- start
- name: Remove Github Actions IP from security group
if: always()
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ env.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
2 changes: 1 addition & 1 deletion .github/workflows/deploy_ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
host: ${{ secrets.DEVSERVER_UI }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SECRETKEY_UI }}
command_timeout: 50m
command_timeout: 5m
script: |
cd xfluencer/influencer-marketplace
git pull
Expand Down
21 changes: 10 additions & 11 deletions solana-client/components/CancelEscrowSolana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const CancelEscrowSolana: FC<CancelEscrowSolanaProps> = ({business, influ
commitment: "confirmed",
confirmTransactionInitialTimeout: 30000
});

const program = utils.getAnchorProgram(connection);
const provider = new AnchorProvider(connection, wallet, {})
setProvider(provider)
Expand All @@ -47,7 +48,7 @@ export const CancelEscrowSolana: FC<CancelEscrowSolanaProps> = ({business, influ
console.warn("Wallet was not connected")
return (
<div className={styles.buttonContainer}>
<button className={styles.button} disabled>CREATE (wallet not connected)</button>
<button className={styles.button} disabled>CANCEL (wallet not connected)</button>
</div> )
}

Expand All @@ -56,7 +57,6 @@ export const CancelEscrowSolana: FC<CancelEscrowSolanaProps> = ({business, influ
const business_pk = new PublicKey(business)
const influencer_pk = new PublicKey(influencer);


const [escrowPDA] = await PublicKey.findProgramAddress([
utf8.encode('escrow'),
business_pk.toBuffer(),
Expand All @@ -65,29 +65,30 @@ export const CancelEscrowSolana: FC<CancelEscrowSolanaProps> = ({business, influ
],
programId
);
console.log()


const ix = await program.methods.cancelEscrowSol()
.accounts({
business: business_pk,
escrowAccount: escrowPDA,
systemProgram: anchor.web3.SystemProgram.programId,
systemProgram: anchor.web3.SystemProgram.programId,
})
.instruction();

const tx = new Transaction().add(ix);

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("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());

throw new Error(`Instruction error number found: ` + txSign.value.err['InstructionError'][0].toString());
}
}
catch(error)
Expand All @@ -97,9 +98,7 @@ export const CancelEscrowSolana: FC<CancelEscrowSolanaProps> = ({business, influ
}

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

}
148 changes: 148 additions & 0 deletions solana-client/components/CancelEscrowSpl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import {
Connection,
PublicKey,
Transaction,
clusterApiUrl,
SYSVAR_RENT_PUBKEY
} from "@solana/web3.js"

import {
getAssociatedTokenAddress,
TOKEN_PROGRAM_ID,
} from '@solana/spl-token';

import {
AnchorProvider,
setProvider,
BN
} from "@project-serum/anchor"

import styles from '../styles/PingButton.module.css'
import idl from "../xfluencer.json"

import { useAnchorWallet, useWallet } from '@solana/wallet-adapter-react';
import * as anchor from "@coral-xyz/anchor";

import { FC } from "react";
import { utf8 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";

import * as utils from "./utils";
import { log } from "console";

const programId = new PublicKey(idl.metadata.address);

export const findATA = (
walletKey: PublicKey,
mintKey: PublicKey,
): Promise<PublicKey> => {
return getAssociatedTokenAddress(
mintKey,
walletKey,
true, // allowOwnerOffCurve aka PDA
);
};

interface CancelEscrowSplProps {
business: string,
validatorAuthority: string,
mintTokenAccount: string,
orderCode: number
}

export const CancelEscrowSpl: FC<CancelEscrowSplProps> = (
{business,
validatorAuthority,
mintTokenAccount,
orderCode}) => {

const wallet = useAnchorWallet()
const connection = new Connection(clusterApiUrl('devnet'),
{
commitment: "confirmed",
confirmTransactionInitialTimeout: 30000
});

const program = utils.getAnchorProgram(connection);
const provider = new AnchorProvider(connection, wallet, {})
setProvider(provider)
const { publicKey, signTransaction, sendTransaction } = useWallet()

if (!connection || !publicKey) {
console.warn("Wallet was not connected")
return (
<div className={styles.buttonContainer}>
<button className={styles.button} disabled>CREATE (wallet not connected)</button>
</div> )
}

const onClick = async () => {

// transform strings to publick keys
const business_pk = new PublicKey(business)
const validatorAuthorityPk = new PublicKey(validatorAuthority) ;
const mintPublicKey = new PublicKey(mintTokenAccount);

console.log(business_pk.toString())

// discover ATA for Business
const associatedTokenAccForBusiness
= await findATA(business_pk, mintPublicKey);

// discover PDA for vault token account
const [vaultAccountPda, vault_account_bump]
= await PublicKey.findProgramAddress(
[Buffer.from(anchor.utils.bytes.utf8.encode("token-seed"+orderCode.toString()))],
program.programId
);

// discover PDA for escrow (data) account
const [escrowAccountPda, ]
= await PublicKey.findProgramAddress(
[Buffer.from(anchor.utils.bytes.utf8.encode("escrow-data"+orderCode.toString()))],
program.programId
);

// prepare instruction for cancel escrow using SPL
const ix = await program.methods.cancelEscrowSpl(
new BN(orderCode)
)
.accounts({
business: business_pk,
businessDepositTokenAccount: associatedTokenAccForBusiness,
vaultAccount: vaultAccountPda,
vaultAuthority: validatorAuthorityPk,
escrowAccount: escrowAccountPda,
tokenProgram: TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
})
.instruction();

const tx = new Transaction().add(ix);

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.error(error)
}
}

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

}
Loading

0 comments on commit 4c480a9

Please sign in to comment.