Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (options.address instanceof Nimiq.Wallet) {
this.minerOptions.addr = options.address.address;
} else if (options.address instanceof Nimiq.Address) {
this.minerOptions.addr = options.address;
} else if (typeof options.address == "string") {
this.minerOptions.addr = Nimiq.Address.fromUserFriendlyAddress(options.address);
} else {
this.theWrapper.callbacks.error("MinerHelper:initMiner", NimiqWrapper.ERROR_MESSAGES.BAD_ADDRESS);
}
}
if (this.minerOptions.pool) {
if (this.theWrapper.nodeType == "NANO") {
this.wrappedMiner = new Nimiq.NanoPoolMiner(this.theWrapper.wrappedNode.blockchain, this.theWrapper.wrappedNode.network.time, this.minerOptions.addr, Nimiq.BasePoolMiner.generateDeviceId(this.theWrapper.wrappedNode.network.config), this.minerOptions.data);
} else {
this.wrappedMiner = new Nimiq.SmartPoolMiner(this.theWrapper.wrappedNode.blockchain, this.theWrapper.wrappedNode.accounts, this.theWrapper.wrappedNode.mempool, this.theWrapper.wrappedNode.network.time, this.minerOptions.addr, Nimiq.BasePoolMiner.generateDeviceId(this.theWrapper.wrappedNode.network.config), this.minerOptions.data);
}
} else {
this.wrappedMiner = new Nimiq.Miner(this.theWrapper.wrappedNode.blockchain, this.theWrapper.wrappedNode.accounts, this.theWrapper.wrappedNode.mempool, this.theWrapper.wrappedNode.network.time, this.minerOptions.addr, this.minerOptions.data);
}
this.theWrapper.wrappedNode.miner = this.wrappedMiner;
this.wrappedMiner.on('start', () => this.theWrapper.callbacks.minerChanged('started'));
this.wrappedMiner.on('stop', () => this.theWrapper.callbacks.minerChanged('stopped'));
if (this.minerOptions.pool) {
this.wrappedMiner.on('connection-state', state => {
if (state == Nimiq.BasePoolMiner.ConnectionState.CONNECTED) {
this.theWrapper.callbacks.connectionState("connected");
} else if (state == Nimiq.BasePoolMiner.ConnectionState.CONNECTING) {
this.theWrapper.callbacks.connectionState("connecting");this.wrappedMiner.on('connection-state', state => {
if (state == Nimiq.BasePoolMiner.ConnectionState.CONNECTED) {
this.theWrapper.callbacks.connectionState("connected");
} else if (state == Nimiq.BasePoolMiner.ConnectionState.CONNECTING) {
this.theWrapper.callbacks.connectionState("connecting");
} else if (state == Nimiq.BasePoolMiner.ConnectionState.CLOSED) {
this.theWrapper.callbacks.connectionState("disconnected");
} else {
this.theWrapper.callbacks.error("MinerHelper:initMiner", NimiqWrapper.ERROR_MESSAGES.UNKNOWN_STATE);
}
});this.wrappedMiner.on('connection-state', state => {
if (state == Nimiq.BasePoolMiner.ConnectionState.CONNECTED) {
this.theWrapper.callbacks.connectionState("connected");
} else if (state == Nimiq.BasePoolMiner.ConnectionState.CONNECTING) {
this.theWrapper.callbacks.connectionState("connecting");
} else if (state == Nimiq.BasePoolMiner.ConnectionState.CLOSED) {
this.theWrapper.callbacks.connectionState("disconnected");
} else {
this.theWrapper.callbacks.error("MinerHelper:initMiner", NimiqWrapper.ERROR_MESSAGES.UNKNOWN_STATE);
}
});