Channel backup & #157 custom expiry time for invoice
Channel backup & #157 custom expiry time for invoicepull/163/head
parent
9b2024ef29
commit
c2c159dba5
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,100 @@
|
|||||||
|
var request = require('request-promise');
|
||||||
|
var fs = require('fs');
|
||||||
|
var common = require('../common');
|
||||||
|
var logger = require('./logger');
|
||||||
|
var options = {};
|
||||||
|
|
||||||
|
exports.getBackup = (req, res, next) => {
|
||||||
|
options = common.getOptions();
|
||||||
|
let channel_backup_file = '';
|
||||||
|
let message = '';
|
||||||
|
if (req.params.channelPoint === 'ALL') {
|
||||||
|
message = 'All Channels Backup Successful!';
|
||||||
|
channel_backup_file = common.selectedNode.channel_backup_path + '/all-channels.bak';
|
||||||
|
options.url = common.getSelLNDServerUrl() + '/channels/backup';
|
||||||
|
} else {
|
||||||
|
message = 'Channel ' + req.params.channelPoint + ' Backup Successful!';
|
||||||
|
channel_backup_file = common.selectedNode.channel_backup_path + '/channel-' + req.params.channelPoint.replace(':', '-') + '.bak';
|
||||||
|
let channelpoint = req.params.channelPoint.replace(':', '/');
|
||||||
|
options.url = common.getSelLNDServerUrl() + '/channels/backup/' + channelpoint;
|
||||||
|
let exists = fs.existsSync(channel_backup_file);
|
||||||
|
if (exists) {
|
||||||
|
fs.writeFile(channel_backup_file, '', () => { });
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
var createStream = fs.createWriteStream(channel_backup_file);
|
||||||
|
createStream.end();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return res.status(500).json({ message: 'Channels Backup Failed!', error: err });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request(options).then(function (body) {
|
||||||
|
logger.info('\r\nChannels Backup: 16: ' + new Date().toJSON().slice(0,19) + ': INFO: Channel Backup: ' + JSON.stringify(body));
|
||||||
|
fs.writeFile(channel_backup_file, JSON.stringify(body), function(err) {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).json({ message: 'Channels Backup Failed!', error: err.error });
|
||||||
|
} else {
|
||||||
|
res.status(200).json({ message: message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
logger.info('\r\nChannels Backup: 27: ' + new Date().toJSON().slice(0,19) + ': ERROR: Channel Backup: ' + JSON.stringify(err));
|
||||||
|
return res.status(500).json({
|
||||||
|
message: 'Channels Backup Failed!',
|
||||||
|
error: err.error
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.postBackupVerify = (req, res, next) => {
|
||||||
|
options = common.getOptions();
|
||||||
|
options.url = common.getSelLNDServerUrl() + '/channels/backup/verify';
|
||||||
|
let channel_verify_file = '';
|
||||||
|
let message = '';
|
||||||
|
let verify_backup = '';
|
||||||
|
if (req.params.channelPoint === 'ALL') {
|
||||||
|
message = 'All Channels Verify Successful!';
|
||||||
|
channel_verify_file = common.selectedNode.channel_backup_path + '/all-channels.bak';
|
||||||
|
let exists = fs.existsSync(channel_verify_file);
|
||||||
|
if (exists) {
|
||||||
|
verify_backup = fs.readFileSync(channel_verify_file, 'utf-8');
|
||||||
|
if (verify_backup !== '') {
|
||||||
|
verify_backup = JSON.parse(verify_backup);
|
||||||
|
delete verify_backup.single_chan_backups;
|
||||||
|
options.form = JSON.stringify(verify_backup);
|
||||||
|
} else {
|
||||||
|
res.status(404).json({ message: 'Channels backup to verify does not Exist!' });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
verify_backup = '';
|
||||||
|
res.status(404).json({ message: 'Channels backup to verify does not Exist!' });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message = 'Channel ' + req.params.channelPoint + ' Verify Successful!';
|
||||||
|
channel_verify_file = common.selectedNode.channel_backup_path + '/channel-' + req.params.channelPoint.replace(':', '-') + '.bak';
|
||||||
|
let exists = fs.existsSync(channel_verify_file);
|
||||||
|
if (exists) {
|
||||||
|
verify_backup = fs.readFileSync(channel_verify_file, 'utf-8');
|
||||||
|
options.form = JSON.stringify({ single_chan_backups: { chan_backups: [JSON.parse(verify_backup)] } });
|
||||||
|
} else {
|
||||||
|
verify_backup = '';
|
||||||
|
res.status(404).json({ message: 'Channel backup to verify does not Exist!' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (verify_backup !== '') {
|
||||||
|
request.post(options).then(function (body) {
|
||||||
|
logger.info('\r\nChannels Backup Verify: 73: ' + new Date().toJSON().slice(0,19) + ': INFO: Channel Backup Verify: ' + JSON.stringify(body));
|
||||||
|
res.status(201).json({ message: message });
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
logger.info('\r\nChannels Backup Verify: 77: ' + new Date().toJSON().slice(0,19) + ': ERROR: Channel Backup Verify: ' + JSON.stringify(err));
|
||||||
|
return res.status(404).json({
|
||||||
|
message: 'Channel backup to Verify failed!',
|
||||||
|
error: err.error
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,9 @@
|
|||||||
|
const ChannelsBackupController = require("../controllers/channelsBackup");
|
||||||
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
|
const authCheck = require("./authCheck");
|
||||||
|
|
||||||
|
router.get("/:channelPoint", authCheck, ChannelsBackupController.getBackup);
|
||||||
|
router.post("/verify/:channelPoint", authCheck, ChannelsBackupController.postBackupVerify);
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -0,0 +1,47 @@
|
|||||||
|
<div fxLayout="column">
|
||||||
|
<div class="padding-gap">
|
||||||
|
<mat-card>
|
||||||
|
<mat-card-header>
|
||||||
|
<mat-card-subtitle>
|
||||||
|
<h2>All Channels Backup</h2>
|
||||||
|
</mat-card-subtitle>
|
||||||
|
</mat-card-header>
|
||||||
|
<mat-card-content>
|
||||||
|
<div fxLayout="column" fxLayout.gt-sm="row wrap" fxFlex="100" fxLayoutAlign="space-between start">
|
||||||
|
<button fxFlex="49" fxLayoutAlign="center center" mat-raised-button color="primary" tabindex="1" (click)="onBackupChannels({})">Backup</button>
|
||||||
|
<button fxFlex="49" fxLayoutAlign="center center" mat-raised-button color="accent" tabindex="2" (click)="onVerifyChannels({})">Verify Backup</button>
|
||||||
|
</div>
|
||||||
|
</mat-card-content>
|
||||||
|
</mat-card>
|
||||||
|
</div>
|
||||||
|
<div class="padding-gap">
|
||||||
|
<mat-card>
|
||||||
|
<mat-card-content class="table-card-content">
|
||||||
|
<div fxLayout="row" fxLayoutAlign="start start">
|
||||||
|
<mat-form-field fxFlex="30">
|
||||||
|
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div perfectScrollbar class="table-container mat-elevation-z8">
|
||||||
|
<mat-progress-bar *ngIf="flgLoading[0]===true" mode="indeterminate"></mat-progress-bar>
|
||||||
|
<table mat-table #table [dataSource]="channels" matSort [ngClass]="{'mat-elevation-z8 overflow-x-auto error-border': flgLoading[0]==='error','mat-elevation-z8 overflow-x-auto': true}">
|
||||||
|
<ng-container matColumnDef="chan_id">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Channel ID </th>
|
||||||
|
<td mat-cell *matCellDef="let channel">{{channel?.chan_id}}</td>
|
||||||
|
</ng-container>
|
||||||
|
<ng-container matColumnDef="backup">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Backup</th>
|
||||||
|
<td mat-cell *matCellDef="let channel"><mat-icon color="primary" (click)="onBackupChannels(channel)">save_alt</mat-icon></td>
|
||||||
|
</ng-container>
|
||||||
|
<ng-container matColumnDef="verify">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Verify</th>
|
||||||
|
<td mat-cell *matCellDef="let channel"><mat-icon color="accent" (click)="onVerifyChannels(channel)">verified_user</mat-icon></td>
|
||||||
|
</ng-container>
|
||||||
|
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: flgSticky;"></tr>
|
||||||
|
<tr mat-row *matRowDef="let row; columns: displayedColumns;" (click)="onChannelClick(row, $event)"></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</mat-card-content>
|
||||||
|
</mat-card>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,8 @@
|
|||||||
|
.mat-column-chan_id {
|
||||||
|
flex: 0 0 25%;
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width:100%;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ChannelBackupComponent } from './channel-backup.component';
|
||||||
|
|
||||||
|
describe('ChannelBackupComponent', () => {
|
||||||
|
let component: ChannelBackupComponent;
|
||||||
|
let fixture: ComponentFixture<ChannelBackupComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ ChannelBackupComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ChannelBackupComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,102 @@
|
|||||||
|
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
import { takeUntil, filter } from 'rxjs/operators';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { Actions } from '@ngrx/effects';
|
||||||
|
|
||||||
|
import { MatTableDataSource, MatSort } from '@angular/material';
|
||||||
|
import { Channel } from '../../../shared/models/lndModels';
|
||||||
|
import { LoggerService } from '../../../shared/services/logger.service';
|
||||||
|
|
||||||
|
import { RTLEffects } from '../../../shared/store/rtl.effects';
|
||||||
|
import * as RTLActions from '../../../shared/store/rtl.actions';
|
||||||
|
import * as fromRTLReducer from '../../../shared/store/rtl.reducers';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'rtl-channel-backup',
|
||||||
|
templateUrl: './channel-backup.component.html',
|
||||||
|
styleUrls: ['./channel-backup.component.scss']
|
||||||
|
})
|
||||||
|
export class ChannelBackupComponent implements OnInit, OnDestroy {
|
||||||
|
@ViewChild(MatSort) sort: MatSort;
|
||||||
|
public displayedColumns = ['chan_id', 'backup', 'verify'];
|
||||||
|
public selChannel: Channel;
|
||||||
|
public channels: any;
|
||||||
|
public flgLoading: Array<Boolean | 'error'> = [true]; // 0: channels
|
||||||
|
public flgSticky = false;
|
||||||
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject()];
|
||||||
|
|
||||||
|
constructor(private logger: LoggerService, private store: Store<fromRTLReducer.State>, private rtlEffects: RTLEffects, private actions$: Actions, private router: Router) {}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.store.select('rtlRoot')
|
||||||
|
.pipe(takeUntil(this.unSubs[0]))
|
||||||
|
.subscribe((rtlStore: fromRTLReducer.State) => {
|
||||||
|
rtlStore.effectErrors.forEach(effectsErr => {
|
||||||
|
if (effectsErr.action === 'Fetchchannels') {
|
||||||
|
this.flgLoading[0] = 'error';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.channels = new MatTableDataSource([]);
|
||||||
|
this.channels.data = [];
|
||||||
|
if (undefined !== rtlStore.allChannels) {
|
||||||
|
this.channels = new MatTableDataSource<Channel>([...rtlStore.allChannels]);
|
||||||
|
this.channels.data = rtlStore.allChannels;
|
||||||
|
}
|
||||||
|
this.channels.sort = this.sort;
|
||||||
|
if (this.flgLoading[0] !== 'error') {
|
||||||
|
this.flgLoading[0] = false;
|
||||||
|
}
|
||||||
|
this.logger.info(rtlStore);
|
||||||
|
});
|
||||||
|
this.actions$
|
||||||
|
.pipe(
|
||||||
|
takeUntil(this.unSubs[1]),
|
||||||
|
filter((action) => action.type === RTLActions.SET_CHANNELS)
|
||||||
|
).subscribe((setchannels: RTLActions.SetChannels) => {
|
||||||
|
this.selChannel = undefined;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onBackupChannels(selChannel: Channel) {
|
||||||
|
this.store.dispatch(new RTLActions.OpenSpinner('Backup Channels...'));
|
||||||
|
this.store.dispatch(new RTLActions.BackupChannels({channelPoint: (selChannel.channel_point) ? selChannel.channel_point : 'ALL', showMessage: ''}));
|
||||||
|
}
|
||||||
|
|
||||||
|
onVerifyChannels(selChannel: Channel) {
|
||||||
|
this.store.dispatch(new RTLActions.OpenSpinner('Verify Channels...'));
|
||||||
|
this.store.dispatch(new RTLActions.VerifyChannels({channelPoint: (selChannel.channel_point) ? selChannel.channel_point : 'ALL'}));
|
||||||
|
}
|
||||||
|
|
||||||
|
onChannelClick(selRow: Channel, event: any) {
|
||||||
|
const flgButtonsClicked = event.target.className.includes('mat-icon')
|
||||||
|
|| event.target.className.includes('mat-column-backup')
|
||||||
|
|| event.target.className.includes('mat-column-verify');
|
||||||
|
if (flgButtonsClicked) { return; }
|
||||||
|
const selChannel = this.channels.data.filter(channel => {
|
||||||
|
return channel.chan_id === selRow.chan_id;
|
||||||
|
})[0];
|
||||||
|
const reorderedChannel = JSON.parse(JSON.stringify(selChannel, [
|
||||||
|
'active', 'remote_pubkey', 'remote_alias', 'channel_point', 'chan_id', 'capacity', 'local_balance', 'remote_balance', 'commit_fee', 'commit_weight',
|
||||||
|
'fee_per_kw', 'unsettled_balance', 'total_satoshis_sent', 'total_satoshis_received', 'num_updates', 'pending_htlcs', 'csv_delay', 'private'
|
||||||
|
] , 2));
|
||||||
|
this.store.dispatch(new RTLActions.OpenAlert({ width: '75%', data: {
|
||||||
|
type: 'INFO',
|
||||||
|
message: JSON.stringify(reorderedChannel)
|
||||||
|
}}));
|
||||||
|
}
|
||||||
|
|
||||||
|
applyFilter(selFilter: string) {
|
||||||
|
this.channels.filter = selFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.unSubs.forEach(completeSub => {
|
||||||
|
completeSub.next();
|
||||||
|
completeSub.complete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue