Files
herolib/lib/threefold/tfgrid3deployer/kvstore.v
mariobassem 1da8a2d319 feat(tfgrid3deployer): add delete method for deployments
- add a delete method for deployments which deletes all deployment
  contracts
- improve logging messages
- update examples according to changes
2025-01-15 13:00:04 +02:00

34 lines
1.0 KiB
V

module tfgrid3deployer
import freeflowuniverse.herolib.core.base as context
// Will be changed when we support the logic of the TFChain one
pub struct KVStoreFS {}
fn (kvs KVStoreFS) set(key string, data []u8) ! {
// set in context
mut mycontext := context.context_new()!
mut session := mycontext.session_new(name: 'deployer')!
mut db := session.db_get()!
db.set(key: key, valueb: data) or { return error('Cannot set the key due to: ${err}') }
}
fn (kvs KVStoreFS) get(key string) ![]u8 {
mut mycontext := context.context_new()!
mut session := mycontext.session_new(name: 'deployer')!
mut db := session.db_get()!
value := db.get(key: key) or { return error('Cannot get value of key ${key} due to: ${err}') }
if value.len == 0 {
return error('The value is empty.')
}
return value.bytes()
}
fn (kvs KVStoreFS) delete(key string) ! {
mut mycontext := context.context_new()!
mut session := mycontext.session_new(name: 'deployer')!
mut db := session.db_get()!
db.delete(key: key) or { return error('Cannot set the key due to: ${err}') }
}