forked from mito-systems/sol-mem-gen
Store escrow in tweet table on successful lock creation
This commit is contained in:
parent
7acb3ee182
commit
a935e3653c
@ -10,4 +10,10 @@ export class Tweet {
|
|||||||
|
|
||||||
@Column({ unique: true })
|
@Column({ unique: true })
|
||||||
transactionSignature!: string;
|
transactionSignature!: string;
|
||||||
|
|
||||||
|
@Column({ type: 'boolean', nullable: true })
|
||||||
|
isLockCreated!: boolean | null;
|
||||||
|
|
||||||
|
@Column({ type: 'text', unique: true, nullable: true })
|
||||||
|
lockEscrow!: string | null;
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,7 @@ export async function createVestingPlanV2(params: CreateVestingPlanParams) {
|
|||||||
|
|
||||||
if(confirmedTransaction === null) {
|
if(confirmedTransaction === null) {
|
||||||
console.error('Transaction failed for', error.signature);
|
console.error('Transaction failed for', error.signature);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return escrow;
|
return escrow;
|
||||||
|
@ -34,7 +34,7 @@ const provider = new anchor.AnchorProvider(
|
|||||||
|
|
||||||
anchor.setProvider(provider);
|
anchor.setProvider(provider);
|
||||||
|
|
||||||
export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipientPubKey: anchor.web3.PublicKey, duration: BN, balance: BN): Promise<anchor.web3.PublicKey | void> {
|
export async function createLock(tokenLockerKeypair: anchor.web3.Keypair, recipientPubKey: anchor.web3.PublicKey, duration: BN, balance: BN): Promise<anchor.web3.PublicKey | undefined> {
|
||||||
|
|
||||||
if (balance.eq(new BN(0))) {
|
if (balance.eq(new BN(0))) {
|
||||||
console.log('No balance available to create lock, skipping...');
|
console.log('No balance available to create lock, skipping...');
|
||||||
|
@ -23,34 +23,47 @@ export async function verifySignatureInTweet(transactionSignature: string): Prom
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function processTweet(txSignature: string, memeUrl: string | null) {
|
export async function processTweet(txSignature: string, memeUrl: string | null) {
|
||||||
return await (global.appDataSource as DataSource).transaction(async (transactionalEntityManager) => {
|
const tweetRepository = (global.appDataSource as DataSource).getRepository(
|
||||||
const tweetRepository = transactionalEntityManager.getRepository(global.entities.Tweet as EntityTarget<Tweet>);
|
global.entities.Tweet as EntityTarget<Tweet>
|
||||||
|
);
|
||||||
|
|
||||||
const tweet = await tweetRepository.save({
|
const tweet = await tweetRepository.save({
|
||||||
transactionSignature: txSignature,
|
transactionSignature: txSignature,
|
||||||
url: memeUrl,
|
url: memeUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isFourthUser = tweet.id % 4 === 0;
|
const isFourthUser = tweet.id % 4 === 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isFourthUser) {
|
if (isFourthUser) {
|
||||||
const { authority, amount } = await extractTxInfo(txSignature);
|
const { authority, amount } = await extractTxInfo(txSignature);
|
||||||
|
|
||||||
if (!authority || Number(amount) <= 0) {
|
if (!authority || Number(amount) <= 0) {
|
||||||
return { error: "Invalid transaction details" }
|
return { error: "Invalid transaction details" };
|
||||||
}
|
|
||||||
|
|
||||||
const escrow = await createRewardLock(authority, amount);
|
|
||||||
|
|
||||||
return { success: true, data: { escrow } };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: true, message: 'Tweet verified' }
|
const escrow = await createRewardLock(authority, amount);
|
||||||
} catch (error) {
|
|
||||||
console.error('Error locking tokens.');
|
|
||||||
|
|
||||||
throw new Error("Transaction failed.");
|
if (!escrow) {
|
||||||
|
throw new Error("Lock not created");
|
||||||
|
}
|
||||||
|
|
||||||
|
await tweetRepository.update(tweet.id, {
|
||||||
|
isLockCreated: true,
|
||||||
|
lockEscrow: escrow.toString()
|
||||||
|
});
|
||||||
|
|
||||||
|
return { success: true, data: { escrow } };
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return { success: true, message: 'Tweet verified' };
|
||||||
|
} catch (error) {
|
||||||
|
await tweetRepository.update(tweet.id, {
|
||||||
|
isLockCreated: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.error('Error locking tokens.');
|
||||||
|
|
||||||
|
throw new Error("Transaction failed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user