Skip to content

Commit

Permalink
adjusting logic, adding fee, adding balance transfer comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pciavald committed Jan 9, 2018
1 parent a56b34d commit 58ad326
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 83 deletions.
76 changes: 75 additions & 1 deletion src/app/wallet/overview/widgets/coldstake/coldstake.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,81 @@ export class ColdstakeComponent implements OnInit {
}

openZapWalletsettingsModal() {
this.dialog.open(ZapWalletsettingsComponent);

/* TODO: use async / await, make return value useful, subscribe errors */
this.log.d('zap called !');

this._rpc.call('walletsettings', ['changeaddress']).subscribe(info => {

this.log.d('zap walletsettings', info);
const pkey = info.changeaddress.coldstakingaddress;
if (pkey === 'default') {
return false;
}

this._rpc.call('deriverangekeys', [1, 1, pkey]).subscribe(info => {

this.log.d('zap deriverangekeys', info);
if (!info || info.length !== 1) {
return false;
}
const stake = info[0];

this._rpc.call('getnewaddress', ['""', 'false', 'false', 'true'])
.subscribe(info => {

this.log.d('zap getnewaddress', info);
const spend = info;
if (!spend || spend === '') {
return false;
}

this._rpc.call('buildscript', [{
recipe: 'ifcoinstake',
addrstake: stake,
addrspend: spend
}]).subscribe(info => {

this.log.d('zap buildscript', info);
if (!info || !info.hex) {
return false;
}
const script = info.hex;

this._rpc.call('listunspent').subscribe(info => {

let sum_inputs = 0;
const inputs = [];

info.map(utxo => {
this.log.d('listunspent utxo', utxo);
sum_inputs += utxo.amount;
inputs.push({tx: utxo.txid, n: utxo.vout});
});

this.log.d('zap params', sum_inputs, inputs);

this._rpc.call('sendtypeto', ['part', 'part', [{
subfee: true,
address: 'script',
amount: sum_inputs,
script: script
}], '', '', 4, 64, true, JSON.stringify({
inputs: inputs
})]).subscribe(info => {

this.log.d('zap sendtypeto simulate', info);

// TODO: ask user to confirm info.fee in a modal
this.dialog.open(ZapWalletsettingsComponent);

});
})

});
});
})
});
}

openUnlockWalletModal(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ <h2 mat-dialog-title>Zap Wallet Settings</h2>

<mat-dialog-content>

<button mat-raised-button color="primary" (click)="zap()">Zap</button>
{{ fee }} PART

<button mat-raised-button color="primary" (click)="zap()">Confirm</button>

</mat-dialog-content>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,19 @@ export class ZapWalletsettingsComponent {

private log: any = Log.create('zap-walletsettings');

fee: number = 42;

constructor(private _rpc: RpcService) {
}

zap() {
/* TODO: use async / await, make return value useful, subscribe errors */
this.log.d('zap called !');

this._rpc.call('walletsettings', ['changeaddress']).subscribe(info => {

this.log.d('zap walletsettings', info);
const pkey = info.changeaddress.coldstakingaddress;
if (pkey === 'default') {
return false;
}

this._rpc.call('deriverangekeys', [1, 1, pkey]).subscribe(info => {

this.log.d('zap deriverangekeys', info);
if (!info || info.length !== 1) {
return false;
}
const stake = info[0];

this._rpc.call('getnewaddress', ['""', 'false', 'false', 'true'])
.subscribe(info => {

this.log.d('zap getnewaddress', info);
const spend = info;
if (!spend || spend === '') {
return false;
}

this._rpc.call('buildscript', [{
recipe: 'ifcoinstake',
addrstake: stake,
addrspend: spend
}]).subscribe(info => {

this.log.d('zap buildscript', info);
if (!info || !info.hex) {
return false;
}
const script = info.hex;

this._rpc.call('listunspent').subscribe(info => {

let sum_inputs = 0;
/* TODO */
const inputs = [];

info.map(utxo => {
this.log.d('listunspent utxo', utxo);
sum_inputs += utxo.amount;
inputs.push({tx: utxo.txid, n: utxo.vout});
});

this.log.d('zap params', sum_inputs, inputs);

this._rpc.call('sendtypeto', ['part', 'part', [{
subfee: true,
address: 'script',
amount: sum_inputs,
script: script
}], '', '', 4, 64, true, JSON.stringify({
inputs: inputs
})]).subscribe(info => {

this.log.d('zap sendtypeto simulate', info);

// TODO: ask user to confirm info.fee in a modal

this.confirmZap(sum_inputs, script);

});
})

});
});
})
});
}
zap(amount: number, script: any) {

confirmZap(amount: number, script: any) {
this._rpc.call('sendtypeto', ['part', 'part', [{
subfee: true,
address: 'script',
amount: amount,
script: script
}], '', '', 4, 64, false]).subscribe(info => {
script: script /* TODO : remove optional args */
}], 'coldstaking zap', '', 4, 64, false]).subscribe(info => {

this.log.d('zap sendtypeto', info);

Expand Down

0 comments on commit 58ad326

Please sign in to comment.