Implement payments for app deployments #17
@ -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}`;
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user