Skip to content

Commit

Permalink
#122 - Further simplify automated Ghost Node setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro committed Dec 24, 2018
1 parent c23775f commit 34ed7be
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ <h5 fxFlex="50">Start Ghostnode</h5>
</div>
</div>

<div class="item">
<p class="htxt">GhostNode Key</p>
<div fxLayout.gt-md="row">
<input class="modalinput" placeholder="Enter ghostnode key" fxFlex="100" [type]="'text'" [(ngModel)]="ghostnodeInfo.ghostnode_key">
</div>
</div>

<div class="item">
<p class="htxt">AliasName</p>
<div fxLayout.gt-md="row">
Expand All @@ -34,14 +27,10 @@ <h5 fxFlex="50">Start Ghostnode</h5>
<div class="item">
<p class="htxt">TransactionHash</p>
<div fxLayout.gt-md="row">
<input class="modalinput" placeholder="Enter transaction hash" fxFlex="100" [type]="'text'" [(ngModel)]="ghostnodeInfo.transactionHash">
</div>
</div>

<div class="item">
<p class="htxt">TransactionOutput</p>
<div fxLayout.gt-md="row">
<input class="modalinput" placeholder="Enter transaction output" fxFlex="100" [type]="'text'" [(ngModel)]="ghostnodeInfo.transactionOutput">
<select class="modalinput" fxFlex="100" [(ngModel)]="ghostnodeInfo.transactionHash">
<option value="">Select TransactionHash</option>
<option *ngFor="let item of objectKeys(ghostnodeOutput)" [value]="item">{{item}}</option>
</select>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
margin-bottom: 0px;
border-radius: 5px;
background-color: #ffffff;

&:first-child option{
color: gray !important;
}

> option {
font-size: 15px;
padding-left: 12px;
height: 35px;
border: 1px solid #CBCBCB;
margin-bottom: 0px;
border-radius: 5px;
background-color: #ffffff;
}
}

.item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material';
import { RpcService } from '../../../core/core.module';
import { Log } from 'ng2-logger';
import { WalletService } from '../../wallet.service';

@Component({
selector: 'app-ghostnode-info-input',
Expand All @@ -11,11 +12,13 @@ import { Log } from 'ng2-logger';
export class GhostnodeInfoInputComponent implements OnInit {

ghostnodeInfo: any;
ghostnodeOutput: any;
private log: any = Log.create('ghostnode-info-input.component');

constructor(
public _dialogRef: MatDialogRef<GhostnodeInfoInputComponent>,
private _rpc: RpcService
private _rpc: RpcService,
private _walletService: WalletService
) { }

ngOnInit() {
Expand All @@ -27,6 +30,11 @@ export class GhostnodeInfoInputComponent implements OnInit {
transactionHash: '',
transactionOutput: ''
}

this._walletService.ghostnodeOutputs().subscribe(res => {
this.ghostnodeOutput = res;
}, error => {
})
}

close(): void {
Expand All @@ -36,22 +44,33 @@ export class GhostnodeInfoInputComponent implements OnInit {
isValid() {
if (this.ghostnodeInfo.ip_address == '' || this.ghostnodeInfo.ip_address == null) return false;
if (this.ghostnodeInfo.password == '' || this.ghostnodeInfo.password == null) return false;
if (this.ghostnodeInfo.ghostnode_key == '' || this.ghostnodeInfo.ghostnode_key == null) return false;
if (this.ghostnodeInfo.transactionHash == '' || this.ghostnodeInfo.transactionHash == null) return false;
return true;
}

objectKeys(obj) {
if (obj == undefined || obj == null) return {}
return Object.keys(obj)
}

start(): void {
if (this.isValid()) {
this.log.d(this.ghostnodeInfo);
this._rpc.call('setup-new-ghostnode', [
this.ghostnodeInfo.ip_address,
this.ghostnodeInfo.password,
this.ghostnodeInfo.ghostnode_key,
this.ghostnodeInfo.aliasName,
this.ghostnodeInfo.transactionHash,
this.ghostnodeInfo.transactionOutput]).subscribe(res => {
}, err => {});
this.close();
this._walletService.ghostnodeKey().subscribe(res => {
this.ghostnodeInfo.ghostnode_key = res;
this.ghostnodeInfo.transactionOutput = this.ghostnodeOutput[this.ghostnodeInfo.transactionHash];
console.log(this.ghostnodeInfo, '========');
this._rpc.call('setup-new-ghostnode', [
this.ghostnodeInfo.ip_address,
this.ghostnodeInfo.password,
this.ghostnodeInfo.ghostnode_key,
this.ghostnodeInfo.aliasName,
this.ghostnodeInfo.transactionHash,
this.ghostnodeInfo.transactionOutput]).subscribe(res => {
}, err => {});
this.close();
}, error => {

})
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/app/wallet/wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export class WalletService {
node => node);
}

// generate ghostnode key
public ghostnodeKey(): Observable<any> {
return this._rpc.call(ApiEndpoints.Ghostnode, ['genkey']);
}

// get ghostnode count
public ghostnodeCount(): Observable<any> {
return this._rpc.call(ApiEndpoints.Ghostnode, ['count']).map(
Expand All @@ -124,6 +129,11 @@ export class WalletService {
count => count);
}

// get ghostnode outputs
public ghostnodeOutputs(): Observable<any> {
return this._rpc.call(ApiEndpoints.Ghostnode, ['outputs']);
}

// start a ghostnode
public startGhostnode(alias: string): Observable<any> {
return this._rpc.call(ApiEndpoints.Ghostnode, ['start-alias', alias]).map(
Expand Down

0 comments on commit 34ed7be

Please sign in to comment.