Skip to content

Commit

Permalink
add deleteWebsite cli function
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Sep 26, 2024
1 parent 739d10d commit 59a928a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
54 changes: 45 additions & 9 deletions cli/src/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Command } from '@commander-js/extra-typings'
import { SmartContract } from '@massalabs/massa-web3'

import { makeProviderFromNodeURLAndSecret } from './utils'
import { Listr, ListrTask } from 'listr2'
import { DeleteCtx } from '../tasks/tasks'

export const deleteCommand = new Command('delete')
.alias('d')
Expand All @@ -21,15 +23,49 @@ export const deleteCommand = new Command('delete')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const sc = new SmartContract(provider, address)

console.error('deleteWebsite not implemented yet in the SC')
const ctx: DeleteCtx = {
provider: provider,
sc: sc,
address: address,
}

// No deleteWebsite in the SC yet
const tasks = new Listr(deleteWebsiteTask(), {
concurrent: false,
})

// sc.call('deleteWebsite', new Uint8Array())
// .then((result) => {
// console.log(result)
// })
// .catch((error) => {
// console.error(error)
// })
try {
await tasks.run(ctx)
} catch (error) {
console.error('Error during the process:', error)
process.exit(1)
}
})

export function deleteWebsiteTask(): ListrTask {
return {
title: 'Deleting website',
task: async (ctx, task) => {
// No deleteWebsite in the SC yet
await deleteWebsite(ctx)
},
rendererOptions: {
outputBar: Infinity,
persistentOutput: true,
collapseSubtasks: false,
},
}
}

async function deleteWebsite(ctx: DeleteCtx) {
if (!ctx.sc) {
throw new Error('Smart contract is not deployed yet')
}
ctx.sc
.call('deleteWebsite', new Uint8Array())
.then(() => {
console.log(`Successfully deleted the website at ${ctx.address}`)
})
.catch((error: any) => {
console.error(error)
})
}
2 changes: 1 addition & 1 deletion cli/src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { listFiles } from '../lib/website/read'
export const listFilesCommand = new Command('list')
.alias('ls')
.description('Lists files from the given website on Massa blockchain')
.option('-a, --address <address>', 'Address of the website to edit')
.option('-a, --address <address>', 'Address of the website to list')
.action(async (options, command) => {
const globalOptions = command.parent?.opts()

Expand Down
6 changes: 6 additions & 0 deletions cli/src/tasks/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ export interface UploadCtx {
chunkSize: number
minimalFees: bigint
}

export interface DeleteCtx {
provider: Web3Provider
sc?: SmartContract
address: string
}
3 changes: 1 addition & 2 deletions smart-contract/assembly/contracts/deweb-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export function deleteFiles(_binaryArgs: StaticArray<u8>): void {
}
}

//TODO: verify that this function throws is mustValue is empty
export function deleteWebsite(_: StaticArray<u8>): void {
_onlyOwner();
const filePaths = FILES_PATH_LIST.mustValue();
Expand All @@ -182,8 +183,6 @@ export function deleteWebsite(_: StaticArray<u8>): void {
FILES_PATH_LIST.set([]);
}

//TODO: delete all files in project

//TODO: delete all metadata

//TODO: delete SC

0 comments on commit 59a928a

Please sign in to comment.