Merge pull request #19 from ryo-currency/dev
Prepare for ryo-wallet-libre
This commit is contained in:
commit
9ce31d6ea3
|
@ -16,6 +16,7 @@
|
|||
"electron-window-state": "^5.0.2",
|
||||
"object-assign-deep": "^0.4.0",
|
||||
"portscanner": "^2.2.0",
|
||||
"promise-queue": "^2.2.5",
|
||||
"qrcode.vue": "^1.6.0",
|
||||
"request": "^2.87.0",
|
||||
"request-promise": "^4.2.2",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import child_process from "child_process";
|
||||
import request from "request-promise";
|
||||
const fs = require('fs');
|
||||
const request = require("request-promise");
|
||||
const queue = require("promise-queue");
|
||||
const http = require("http");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
export class Daemon {
|
||||
|
@ -11,6 +13,10 @@ export class Daemon {
|
|||
this.id = 0
|
||||
this.testnet = false
|
||||
this.local = false // do we have a local daemon ?
|
||||
|
||||
this.agent = new http.Agent({keepAlive: true, maxSockets: 1})
|
||||
this.queue = new queue(1, Infinity)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,42 +347,46 @@ export class Daemon {
|
|||
sendRPC(method, params={}) {
|
||||
let id = this.id++
|
||||
let options = {
|
||||
forever: true,
|
||||
uri: `${this.protocol}${this.hostname}:${this.port}/json_rpc`,
|
||||
method: "POST",
|
||||
json: {
|
||||
jsonrpc: "2.0",
|
||||
id: id,
|
||||
method: method
|
||||
},
|
||||
agent: this.agent
|
||||
};
|
||||
if (Object.keys(params).length !== 0) {
|
||||
if(Object.keys(params).length !== 0) {
|
||||
options.json.params = params;
|
||||
}
|
||||
|
||||
return request.post(`${this.protocol}${this.hostname}:${this.port}/json_rpc`, options)
|
||||
.then((response) => {
|
||||
if(response.hasOwnProperty("error")) {
|
||||
return this.queue.add(() => {
|
||||
return request(options)
|
||||
.then((response) => {
|
||||
if(response.hasOwnProperty("error")) {
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: response.error
|
||||
}
|
||||
}
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: response.error
|
||||
result: response.result
|
||||
}
|
||||
}
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
result: response.result
|
||||
}
|
||||
}).catch(error => {
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: {
|
||||
code: -1,
|
||||
message: "Cannot connect to daemon-rpc",
|
||||
cause: error.cause
|
||||
}).catch(error => {
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: {
|
||||
code: -1,
|
||||
message: "Cannot connect to daemon-rpc",
|
||||
cause: error.cause
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -391,6 +401,7 @@ export class Daemon {
|
|||
return new Promise((resolve, reject) => {
|
||||
if (this.daemonProcess) {
|
||||
this.daemonProcess.on("close", code => {
|
||||
this.agent.destroy()
|
||||
resolve()
|
||||
})
|
||||
this.daemonProcess.kill()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import child_process from "child_process";
|
||||
const request = require("request-promise");
|
||||
const queue = require("promise-queue");
|
||||
const http = require("http");
|
||||
const os = require("os");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
@ -28,6 +30,8 @@ export class WalletRPC {
|
|||
this.height_regex2 = /Skipped block by height: (\d+)/
|
||||
this.height_regex3 = /Skipped block by timestamp, height: (\d+)/
|
||||
|
||||
this.agent = new http.Agent({keepAlive: true, maxSockets: 1})
|
||||
this.queue = new queue(1, Infinity)
|
||||
|
||||
}
|
||||
|
||||
|
@ -52,8 +56,7 @@ export class WalletRPC {
|
|||
]
|
||||
|
||||
const args = [
|
||||
//"--rpc-login", this.auth[0]+":"+this.auth[1],
|
||||
"--disable-rpc-login",
|
||||
"--rpc-login", this.auth[0]+":"+this.auth[1],
|
||||
"--rpc-bind-port", options.wallet.rpc_bind_port,
|
||||
"--daemon-address", daemon_address,
|
||||
//"--log-level", options.wallet.log_level,
|
||||
|
@ -1228,52 +1231,54 @@ export class WalletRPC {
|
|||
sendRPC(method, params={}, timeout=0) {
|
||||
let id = this.id++
|
||||
let options = {
|
||||
forever: true,
|
||||
uri: `${this.protocol}${this.hostname}:${this.port}/json_rpc`,
|
||||
method: "POST",
|
||||
json: {
|
||||
jsonrpc: "2.0",
|
||||
id: id,
|
||||
method: method
|
||||
},
|
||||
/*
|
||||
auth: {
|
||||
user: this.auth[0],
|
||||
pass: this.auth[1],
|
||||
sendImmediately: false
|
||||
}
|
||||
*/
|
||||
},
|
||||
agent: this.agent
|
||||
};
|
||||
if (Object.keys(params).length !== 0) {
|
||||
if(Object.keys(params).length !== 0) {
|
||||
options.json.params = params
|
||||
}
|
||||
if(timeout) {
|
||||
options.timeout = timeout
|
||||
}
|
||||
|
||||
return request.post(`${this.protocol}${this.hostname}:${this.port}/json_rpc`, options)
|
||||
.then((response) => {
|
||||
if(response.hasOwnProperty("error")) {
|
||||
return this.queue.add(() => {
|
||||
return request(options)
|
||||
.then((response) => {
|
||||
if(response.hasOwnProperty("error")) {
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: response.error
|
||||
}
|
||||
}
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: response.error
|
||||
result: response.result
|
||||
}
|
||||
}
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
result: response.result
|
||||
}
|
||||
}).catch(error => {
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: {
|
||||
code: -1,
|
||||
message: "Cannot connect to wallet-rpc",
|
||||
cause: error.cause
|
||||
}).catch(error => {
|
||||
return {
|
||||
method: method,
|
||||
params: params,
|
||||
error: {
|
||||
code: -1,
|
||||
message: "Cannot connect to wallet-rpc",
|
||||
cause: error.cause
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
getRPC(parameter, params={}) {
|
||||
|
@ -1290,6 +1295,7 @@ export class WalletRPC {
|
|||
})
|
||||
setTimeout(() => {
|
||||
this.walletRPCProcess.on("close", code => {
|
||||
this.agent.destroy()
|
||||
resolve()
|
||||
})
|
||||
this.walletRPCProcess.kill()
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<template>
|
||||
<div>
|
||||
|
||||
<template v-if="tx_list.length === 0">
|
||||
<template v-if="tx_list_paged.length === 0">
|
||||
<p class="q-pa-md q-mb-none">No transactions found</p>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<q-infinite-scroll :handler="loadMore" ref="scroller">
|
||||
<q-list link no-border :dark="theme=='dark'" class="tx-list">
|
||||
<q-item v-for="(tx, index) in tx_list" :key="tx.txid"
|
||||
<q-item v-for="(tx, index) in tx_list_paged" :key="tx.txid"
|
||||
@click.native="details(tx)" :class="'tx-'+tx.type">
|
||||
<q-item-side>
|
||||
<TxTypeIcon :type="tx.type" />
|
||||
</q-item-side>
|
||||
<q-item-main>
|
||||
<q-item-tile class="monospace ellipsis" label>{{ tx.txid }}</q-item-tile>
|
||||
<q-item-tile sublabel>{{ formatHeight(tx.height) }}</q-item-tile>
|
||||
<q-item-tile sublabel>{{ formatHeight(tx) }}</q-item-tile>
|
||||
</q-item-main>
|
||||
<q-item-side>
|
||||
<q-item-tile label>
|
||||
|
@ -67,11 +67,6 @@ import TxDetails from "components/tx_details"
|
|||
import FormatRyo from "components/format_ryo"
|
||||
export default {
|
||||
name: "TxList",
|
||||
data () {
|
||||
return {
|
||||
page: 0
|
||||
}
|
||||
},
|
||||
props: {
|
||||
limit: {
|
||||
type: Number,
|
||||
|
@ -99,12 +94,68 @@ export default {
|
|||
default: -1
|
||||
},
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
page: 0,
|
||||
tx_list_filtered: [],
|
||||
tx_list_paged: []
|
||||
}
|
||||
},
|
||||
computed: mapState({
|
||||
theme: state => state.gateway.app.config.appearance.theme,
|
||||
current_height: state => state.gateway.daemon.info.height,
|
||||
tx_list_all: state => state.gateway.wallet.transactions.tx_list,
|
||||
tx_list (state) {
|
||||
let tx_list_filter = this.tx_list_all.filter((tx) => {
|
||||
wallet_height: state => state.gateway.wallet.info.height,
|
||||
tx_list: state => state.gateway.wallet.transactions.tx_list
|
||||
}),
|
||||
created () {
|
||||
this.filterTxList()
|
||||
this.pageTxList()
|
||||
},
|
||||
watch: {
|
||||
wallet_height: {
|
||||
handler(val, old){
|
||||
if(val == old) return
|
||||
this.filterTxList()
|
||||
this.pageTxList()
|
||||
}
|
||||
},
|
||||
tx_list: {
|
||||
handler(val, old){
|
||||
if(val.length == old.length) return
|
||||
this.filterTxList()
|
||||
this.pageTxList()
|
||||
}
|
||||
},
|
||||
type: {
|
||||
handler(val, old){
|
||||
if(val == old) return
|
||||
if(this.$refs.scroller) {
|
||||
this.$refs.scroller.stop()
|
||||
this.page = 0
|
||||
this.$refs.scroller.reset()
|
||||
this.$refs.scroller.resume()
|
||||
}
|
||||
this.filterTxList()
|
||||
this.pageTxList()
|
||||
}
|
||||
},
|
||||
txid: {
|
||||
handler(val, old){
|
||||
if(val == old) return
|
||||
if(this.$refs.scroller) {
|
||||
this.$refs.scroller.stop()
|
||||
this.page = 0
|
||||
this.$refs.scroller.reset()
|
||||
this.$refs.scroller.resume()
|
||||
}
|
||||
this.filterTxList()
|
||||
this.pageTxList()
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
filterTxList () {
|
||||
this.tx_list_filtered = this.tx_list.filter((tx) => {
|
||||
let valid = true
|
||||
if(this.type !== "all" && this.type !== tx.type) {
|
||||
valid = false
|
||||
|
@ -132,37 +183,35 @@ export default {
|
|||
|
||||
return valid
|
||||
})
|
||||
|
||||
if(this.limit !== -1) {
|
||||
tx_list_filter = tx_list_filter.slice(0, this.limit)
|
||||
} else {
|
||||
tx_list_filter = tx_list_filter.slice(0, this.page * 24 + 24)
|
||||
}
|
||||
|
||||
return tx_list_filter
|
||||
},
|
||||
}),
|
||||
methods: {
|
||||
pageTxList () {
|
||||
this.tx_list_paged = this.tx_list_filtered.slice(0, this.limit !== -1 ? this.limit : this.page * 24 + 24)
|
||||
},
|
||||
loadMore: function(index, done) {
|
||||
this.page = index
|
||||
if(this.limit !== -1 || this.tx_list_filtered.length < this.page * 24 + 24) {
|
||||
this.$refs.scroller.stop()
|
||||
}
|
||||
this.pageTxList()
|
||||
this.$nextTick(() => {
|
||||
done()
|
||||
})
|
||||
},
|
||||
details (tx) {
|
||||
this.$refs.txDetails.tx = tx;
|
||||
this.$refs.txDetails.txNotes = tx.note;
|
||||
this.$refs.txDetails.isVisible = true;
|
||||
},
|
||||
formatHeight(height) {
|
||||
let confirms = this.current_height - height;
|
||||
formatHeight(tx) {
|
||||
let height = tx.height;
|
||||
let confirms = Math.max(0, this.wallet_height - height);
|
||||
if(height == 0)
|
||||
return "Pending"
|
||||
if(confirms < 10)
|
||||
if(confirms < Math.max(10, tx.unlock_time - height))
|
||||
return `Height: ${height} (${confirms} confirm${confirms==1?'':'s'})`
|
||||
else
|
||||
return `Height: ${height} (confirmed)`
|
||||
},
|
||||
loadMore: function(index, done) {
|
||||
this.page = index
|
||||
if(this.limit !== -1 || this.tx_list.length < this.page * 24 + 24)
|
||||
this.$refs.scroller.stop()
|
||||
done()
|
||||
},
|
||||
copyTxid (txid, event) {
|
||||
event.stopPropagation()
|
||||
for(let i = 0; i < event.path.length; i++) {
|
||||
|
@ -180,30 +229,6 @@ export default {
|
|||
},
|
||||
openExplorer (txid) {
|
||||
this.$gateway.send("core", "open_explorer", {type: "tx", id: txid})
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
type: {
|
||||
handler(val, old){
|
||||
if(val == old) return
|
||||
if(this.$refs.scroller) {
|
||||
this.$refs.scroller.stop()
|
||||
this.page = 0
|
||||
this.$refs.scroller.reset()
|
||||
this.$refs.scroller.resume()
|
||||
}
|
||||
}
|
||||
},
|
||||
txid: {
|
||||
handler(val, old){
|
||||
if(val == old) return
|
||||
if(this.$refs.scroller) {
|
||||
this.$refs.scroller.stop()
|
||||
this.page = 0
|
||||
this.$refs.scroller.reset()
|
||||
this.$refs.scroller.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
|
Loading…
Reference in New Issue