@bsv/overlay-express
Version:
BSV Blockchain Overlay Express
78 lines • 3.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BanAwareSLAPStorage = exports.BanAwareSHIPStorage = void 0;
/**
* Prevents banned SHIP records from being written to discovery storage.
*/
class BanAwareSHIPStorage {
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);
}
}
exports.BanAwareSHIPStorage = BanAwareSHIPStorage;
/**
* Prevents banned SLAP records from being written to discovery storage.
*/
class BanAwareSLAPStorage {
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);
}
}
exports.BanAwareSLAPStorage = BanAwareSLAPStorage;
//# sourceMappingURL=BanAwareDiscoveryStorage.js.map