import { MultiIndex, MultiIndexValue } from "./mi"; import { Name } from "./name"; export class Singleton { key: u64; mi: MultiIndex; constructor(code: Name, scope: Name, table: Name) { this.key = table.N; this.mi = new MultiIndex(code, scope, table); } set(value: T, payer: Name): void { let it = this.mi.find(this.key); if (it.isOk()) { this.mi.update(it, value, payer); } else { this.mi.store(value, payer); } } getOrNull(): T | null { let it = this.mi.find(this.key); if (it.isOk()) { return it.getValue(); } return null; // return instantiate(); } get(): T { let it = this.mi.find(this.key); if (it.isOk()) { return it.getValue()!; } return instantiate(); } remove(): void { let it = this.mi.find(this.key); if (it.isOk()) { this.mi.remove(it); } } } // func NewSingletonDB(code, scope, table chain.Name, unpacker ...Unpacker) *SingletonDB; // func (t *SingletonDB) Set(data DBValue, payer chain.Name); // func (t *SingletonDB) Get() interface{}; // func (t *SingletonDB) Remove();