Implement payments for app deployments #17

Merged
nabarun merged 27 commits from iv-integrate-payments into main 2024-10-28 09:46:19 +00:00
2 changed files with 36 additions and 0 deletions
Showing only changes of commit 92a270afa2 - Show all commits

View File

@ -483,6 +483,21 @@ export class Registry {
return this.registry.getAuctionsByIds([auctionId]);
}
async sendTokensToAccount(receiverAddress: string, amount: string): Promise<any> {
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
await registryTransactionWithRetry(() =>
this.registry.sendCoins(
{
amount,
denom: 'tlnt',
destinationAddress: receiverAddress
},
this.registryConfig.privateKey,
fee
)
);
}
getLrn(appName: string): string {
assert(this.registryConfig.authority, "Authority doesn't exist");
return `lrn://${this.registryConfig.authority}/applications/${appName}`;

View File

@ -212,6 +212,9 @@ export class Service {
if (!deployment.project.fundsReleased) {
const fundsReleased = await this.releaseDeployerFundsByProjectId(deployment.projectId);
// Return remaining amount to owner
await this.returnCreatorFundsByProjectId(deployment.projectId);
await this.db.updateProjectById(deployment.projectId, {
fundsReleased,
});
@ -1324,6 +1327,24 @@ export class Service {
return false;
}
async returnCreatorFundsByProjectId(projectId: string) {
const project = await this.db.getProjectById(projectId);
if (!project || !project.auctionId) {
log(`Project ${projectId} ${!project ? 'not found' : 'does not have an auction'}`);
return false;
}
const auction = await this.getAuctionData(project.auctionId);
const amountToBeReturned = auction.winnerPrice * auction.numProviders
await this.laconicRegistry.sendTokensToAccount(
project.paymentAddress,
amountToBeReturned.toString()
);
}
async getDeployers(): Promise<Deployer[]> {
const dbDeployers = await this.db.getDeployers();