Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 1x 1x 1x 1x 1x 1x 13x 13x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 15x 15x 1x 7x 7x 7x 1x 1x 6x 6x 6x 1x 1x 5x 5x 1x 1x 1x 1x 4x 4x 4x 4x 4x 97x 97x 93x 93x 4x 4x 4x 4x 97x 4x 4x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x | "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Distance = exports.Node = void 0;
const bs58_1 = require("bs58");
class Node {
constructor(id) {
this.id = id;
}
valueOf() {
return this.id;
}
toString() {
return `Node(${this.id})`;
}
equals(other) {
if (typeof other === 'string') {
return this.id === other;
}
if (other instanceof Node) {
return this.id === other.id;
}
return false;
}
decode() {
return (0, bs58_1.decode)(this.id.substring(3));
}
isValid() {
if (!this.id.startsWith('FC_')) {
return false;
}
return this.decode().length === 32;
}
distance(other) {
return new Distance(this, other);
}
static parse(id) {
const node = new Node(id);
//process.env.IS_UNITTEST !== 'true' &&
if (!node.isValid()) {
throw new Error(`Invalid ID: '${id}'`);
}
return node;
}
}
exports.Node = Node;
class Distance {
constructor(node1, node2) {
this._distance = 256;
if (node1 !== undefined && node2 !== undefined) {
const id1 = node1.decode();
const id2 = node2.decode();
for (let i = 0; i < 32; i++) {
const x = id1[i] ^ id2[i];
if (x === 0) {
this._distance -= 8;
}
else {
this._distance -= x.toString(2).padStart(8, '0').indexOf('1');
break;
}
}
}
}
get distance() {
return this._distance;
}
toString() {
// console.log('Distance.toString()');
return `Distance(${this._distance})`;
}
lessThan(other) {
// console.log('Distance.lessThan()');
if (typeof other === 'number') {
return this._distance < other;
}
if (other instanceof Distance) {
return this._distance < other._distance;
}
return false;
}
equals(other) {
// console.log('Distance.lessThan()', typeof other, other);
if (typeof other === 'number') {
return this._distance === other;
}
if (other instanceof Distance) {
return this._distance === other._distance;
}
return false;
}
}
exports.Distance = Distance;
|