bitcore-node-zcash/lib/PoolMatch.js

39 lines
763 B
JavaScript
Raw Normal View History

2014-02-17 10:04:01 -08:00
'use strict';
require('classtool');
function spec(b) {
var fs = require('fs');
var buffertools = require('buffertools');
var db = b.db || JSON.parse( fs.readFileSync(b.poolMatchFile || './poolMatchFile.json'));
var PoolMatch = function() {
var self = this;
2014-02-18 09:35:54 -08:00
self.strings = {};
2014-02-17 10:04:01 -08:00
db.forEach(function(pool) {
pool.searchStrings.forEach(function(s) {
2014-02-18 09:35:54 -08:00
self.strings[s] = {
poolName: pool.poolName,
url: pool.url
};
2014-02-17 10:04:01 -08:00
});
});
};
2014-02-17 10:04:01 -08:00
PoolMatch.prototype.match = function(buffer) {
var self = this;
2014-02-18 09:35:54 -08:00
for(var k in self.strings) {
if (buffertools.indexOf(buffer, k) >= 0) {
return self.strings[k];
2014-02-17 10:04:01 -08:00
}
2014-02-18 09:35:54 -08:00
};
2014-02-17 10:04:01 -08:00
};
return PoolMatch;
}
module.defineClass(spec);