@bsv/overlay-express
Version:
BSV Blockchain Overlay Express
79 lines • 2.95 kB
JavaScript
/**
* Prevents banned SHIP records from being written to discovery storage.
*/
export class BanAwareSHIPStorage {
wrapped;
banService;
logger;
constructor(wrapped, banService, logger = console) {
this.wrapped = wrapped;
this.banService = banService;
this.logger = logger;
}
async ensureIndexes() {
return await this.wrapped.ensureIndexes();
}
async hasDuplicateRecord(identityKey, domain, topic) {
return await this.wrapped.hasDuplicateRecord(identityKey, domain, topic);
}
async storeSHIPRecord(txid, outputIndex, identityKey, domain, topic) {
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from SHIP storage`);
return;
}
if (await this.banService.isDomainBanned(domain)) {
this.logger.log(`[BAN] Blocked banned domain ${domain} from SHIP storage (${txid}.${outputIndex})`);
return;
}
return await this.wrapped.storeSHIPRecord(txid, outputIndex, identityKey, domain, topic);
}
async deleteSHIPRecord(txid, outputIndex) {
return await this.wrapped.deleteSHIPRecord(txid, outputIndex);
}
async findRecord(...args) {
return await this.wrapped.findRecord(...args);
}
async findAll(...args) {
return await this.wrapped.findAll(...args);
}
}
/**
* Prevents banned SLAP records from being written to discovery storage.
*/
export class BanAwareSLAPStorage {
wrapped;
banService;
logger;
constructor(wrapped, banService, logger = console) {
this.wrapped = wrapped;
this.banService = banService;
this.logger = logger;
}
async ensureIndexes() {
return await this.wrapped.ensureIndexes();
}
async hasDuplicateRecord(identityKey, domain, service) {
return await this.wrapped.hasDuplicateRecord(identityKey, domain, service);
}
async storeSLAPRecord(txid, outputIndex, identityKey, domain, service) {
if (await this.banService.isOutpointBanned(txid, outputIndex)) {
this.logger.log(`[BAN] Blocked banned outpoint ${txid}.${outputIndex} from SLAP storage`);
return;
}
if (await this.banService.isDomainBanned(domain)) {
this.logger.log(`[BAN] Blocked banned domain ${domain} from SLAP storage (${txid}.${outputIndex})`);
return;
}
return await this.wrapped.storeSLAPRecord(txid, outputIndex, identityKey, domain, service);
}
async deleteSLAPRecord(txid, outputIndex) {
return await this.wrapped.deleteSLAPRecord(txid, outputIndex);
}
async findRecord(...args) {
return await this.wrapped.findRecord(...args);
}
async findAll(...args) {
return await this.wrapped.findAll(...args);
}
}
//# sourceMappingURL=BanAwareDiscoveryStorage.js.map