Auto renewable channels

This class is intended for automatic opening of new channels when the specified balance is reached and automatic payment from the current channel. Example: https://github.com/BIoTws/endless-channels-example

Constructor

walletId - String

timeout - Number - in ms

maxOpenChannels - Number

timeForMutualClosingChannel - Number

Example: init

JS module
const autoRenewableChannel = new AutoRenewableChannel(wallets[0], peerDeviceAddress, 20000, 2);
await autoRenewableChannel.openNewChannel({
walletId: wallets[0],
peerAddress: null,
myAmount: 100,
peerAmount: 100,
age: 10
});

Example: channel approval

JS module
const core = require('biot-core');
const AutoRenewableChannel = require('biot-core/lib/AutoRenewableChannel');
async function start() {
await core.init('test');
let wallets = await core.getMyDeviceWallets();
const autoRenewableChannel = new AutoRenewableChannel(wallets[0], null, 20000, 2);
autoRenewableChannel.init();
autoRenewableChannel.events.on('start', console.error);
autoRenewableChannel.events.on('new_transfer', (amount, message, id) => {
console.error('new transfer', amount, message, id);
});
autoRenewableChannel.events.on('request_approve_channel', async (objInfo) => {
console.error('new Channel: ', objInfo);
console.error(await autoRenewableChannel.approve(objInfo.index));
});
}
start().catch(console.error);

Events

Error

autoRenewableChannel.events.on('error', (error, id) => {
console.error('channelError', id, error);
});

start

This event is triggered once at the start of the first channel. The event fires after approve channel.

autoRenewableChannel.events.on('start', (id) => {
console.error('channel start:', id);
});

init

init autoRenewableChannel

autoRenewableChannel.events.on('init', stats => {
console.error(peerId, device_address timeForMutualClosingChannel);
});

request_approve_channel

This event notifies us of the request to open the first channel. Contains technical information.

Structure objInfo:

peerDeviceAddress - String - peer device address for opening channel

myAddress - String - peer byteball address

peerAmount - Number - your amount in bytes

myAmount: - Number - peer amount in bytes

age - Number - Timeout in MCI for withdrawal bytes from channel when using one-side closure

id - String - channel id

myUnilateralAddress - Array - The address of the peer for signing transactions inside the channel

myDestinationAddress - Array - The address of the peer for withdrawal from the channel

JS module
autoRenewableChannel.events.on('request_approve_channel', async (objInfo) => {
console.error('info: ', objInfo); //request to open
if (objInfo.peerAmount === 100) {
await autoRenewableChannel.approve(objInfo.id);
} else {
await autoRenewableChannel.reject(objInfo.id);
}
});

changed_step

autoRenewableChannel.events.on('changed_step', (step, id) => {
console.error('changed_step: ', step, id);
});

new_transfer

autoRenewableChannel.events.on('new_transfer', async (amount, message, id) => {
console.error('new_transfer: ', amount, message, id);
});