@btc-vision/btc-runtime
Version:
Bitcoin Smart Contract Runtime
55 lines (43 loc) • 990 B
text/typescript
import { Address } from '../types/Address';
import { Nested } from './Nested';
export class MapOfMap<T> extends Map<
Address,
Nested<T>
> {
public pointer: u16;
constructor(
pointer: u16,
) {
super();
this.pointer = pointer;
}
public get(key: Address): Nested<T> {
this.createKeyMerger(key);
return super.get(key);
}
public set(key: Address, value: Nested<T>): this {
this.createKeyMerger(key);
return <this>super.set(key, value);
}
public has(key: Address): bool {
return super.has(key);
}
public delete(key: Address): bool {
return super.delete(key);
}
public clear(): void {
super.clear();
}
private createKeyMerger(key: Address): void {
if (!super.has(key)) {
super.set(key, new Nested<T>(key, this.pointer));
}
}
}