forked from mito-systems/sol-mem-gen
Store escrow in tweet table on successful lock creation
This commit is contained in:
parent
5be2edfd43
commit
c923edf3c5
@ -10,4 +10,10 @@ export class Tweet {
|
||||
|
||||
@Column({ unique: true })
|
||||
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) {
|
||||
console.error('Transaction failed for', error.signature);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return escrow;
|
||||
|
@ -34,7 +34,7 @@ const provider = new anchor.AnchorProvider(
|
||||
|
||||
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))) {
|
||||
console.log('No balance available to create lock, skipping...');
|
||||
|
@ -23,8 +23,9 @@ export async function verifySignatureInTweet(transactionSignature: string): Prom
|
||||
}
|
||||
|
||||
export async function processTweet(txSignature: string, memeUrl: string | null) {
|
||||
return await (global.appDataSource as DataSource).transaction(async (transactionalEntityManager) => {
|
||||
const tweetRepository = transactionalEntityManager.getRepository(global.entities.Tweet as EntityTarget<Tweet>);
|
||||
const tweetRepository = (global.appDataSource as DataSource).getRepository(
|
||||
global.entities.Tweet as EntityTarget<Tweet>
|
||||
);
|
||||
|
||||
const tweet = await tweetRepository.save({
|
||||
transactionSignature: txSignature,
|
||||
@ -38,19 +39,31 @@ export async function processTweet(txSignature: string, memeUrl: string | null)
|
||||
const { authority, amount } = await extractTxInfo(txSignature);
|
||||
|
||||
if (!authority || Number(amount) <= 0) {
|
||||
return { error: "Invalid transaction details" }
|
||||
return { error: "Invalid transaction details" };
|
||||
}
|
||||
|
||||
const escrow = await createRewardLock(authority, amount);
|
||||
|
||||
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' }
|
||||
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