Commit 747c2624 authored by nazarf's avatar nazarf

add geter to z address

git-svn-id: https://svn.sp-service.com.ua/svnroot/svn/node-stats/trunk@17 320591d9-fe85-4a77-9bad-1a723db14d60
parent addfff36
......@@ -69,6 +69,13 @@ class AmountSendsController < ApplicationController
AmountSend.create(from: a.taddress, to: Setting.stk_node_address, amount: listunspent["#{b}"].to_f - 0.0001, node_id: a.id)
end
end
z_listaddresses = z_listaddresses(a)
z_listaddresses.keys.each do |b|
if z_listaddresses["#{b}"] > a.start_balance_z + 0.001
AmountSend.create(from: a.zaddress, to: Setting.stk_node_address, amount: z_listaddresses["#{b}"].to_f - 0.0001, node_id: a.id)
end
end
end
redirect_to nodes_path, notice: 'Transaction is create.'
end
......@@ -97,6 +104,11 @@ class AmountSendsController < ApplicationController
if balance > 0
AmountSend.create(from: Setting.stk_node_address, to: a.taddress, amount: a.start_balance_t + 0.0001, status: 'return')
end
balance = (a.start_balance_z - a.balance_z).to_f
if balance > 0
AmountSend.create(from: Setting.stk_node_address, to: a.zaddress, amount: a.start_balance_z + 0.0001, status: 'return')
end
end
redirect_to nodes_path, notice: 'Preparation return.'
end
......@@ -135,6 +147,20 @@ class AmountSendsController < ApplicationController
end
end
def z_listaddresses(node)
h = BitcoinRPC.new("http://#{node.node_username}:#{node.node_password}@#{node.ipv4}:8231")
z_listaddresses = h.z_listaddresses
address = Hash.new()
if z_listaddresses.nil?
@zaddress = nil
else
z_listaddresses.each do |a|
address[a] = h.z_getbalance a
end
@zaddress = address
end
end
# Use callbacks to share common setup or constraints between actions.
def set_amount_send
@amount_send = AmountSend.find(params[:id])
......
......@@ -15,6 +15,9 @@ class NodesController < AdminController
# GET /nodes/1.json
def show
listunspent(@node)
if @address.present?
z_listaddresses(@node)
end
end
# GET /nodes/new
......@@ -82,6 +85,21 @@ class NodesController < AdminController
redirect_to nodes_url
end
def set_z_address
Node.all.each do |a|
z_listaddresses = z_listaddresses(a)
if z_listaddresses != nil
z_listaddresses.keys.each do |b|
if z_listaddresses["#{b}"] > a.start_balance_z
a.update(zaddress: b)
end
end
end
end
redirect_to nodes_url
end
def z_gettotalbalance
Node.all.each do |a|
h = BitcoinRPC.new("http://#{a.node_username}:#{a.node_password}@#{a.ipv4}:8231")
......@@ -126,6 +144,20 @@ class NodesController < AdminController
end
end
def z_listaddresses(node)
h = BitcoinRPC.new("http://#{node.node_username}:#{node.node_password}@#{node.ipv4}:8231")
z_listaddresses = h.z_listaddresses
address = Hash.new()
if z_listaddresses.nil?
@zaddress = nil
else
z_listaddresses.each do |a|
address[a] = h.z_getbalance a
end
@zaddress = address
end
end
def sync_node
@params = {
from: params[:sync_to_sheet][:from],
......
......@@ -25,10 +25,12 @@
%br
= link_to 'create transaction', set_transaction_url, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-primary'
= link_to 'pick up amount', pick_up_amount_url, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-primary'
= link_to 'pick up amount', pick_up_amount_url, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger'
= link_to 'preparation return', preparation_return_url, class: 'btn btn-primary'
= link_to 'return amount', return_amount_url, class: 'btn btn-primary'
= link_to 'set t address', set_t_address_url, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-primary'
= link_to 'set t address', set_t_address_url, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-warning'
%br
= link_to 'set z address', set_z_address_url, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-warning'
......@@ -40,7 +42,7 @@
%th Ipv4
%th Ipv6
%th Taddress
-#%th Zaddress
%th Zaddress
%th Start balance t
%th Start balance z
%th Balance t
......@@ -56,7 +58,7 @@
%td= node.ipv4
%td= node.ipv6
%td= node.taddress
-#%td= node.zaddress
%td= node.zaddress.present? ? "present" : "blank"
%td= node.start_balance_t
%td= node.start_balance_z
%td= node.balance_t
......
......@@ -45,6 +45,14 @@
%b= a + ':'
= @address[a]
.page-header
- if @zaddress.nil?
%p Could not connect to server
-else
- @zaddress.keys.each do |a|
%b= a + ':'
= @zaddress[a]
......
# config valid only for current version of Capistrano
lock '3.11.0'
lock '3.7.2'
# DEPLOY
set :application, 'node-statistic'
# set :deploy_to, '/var/www/amaox' # Default deploy_to directory is /var/www/my_app_name
set :repo_url, 'https://svn.sp-service.com.ua/svnroot/svn/node-stats/trunk'
set :repo_url, 'http://svn.sp-service.com.ua/svnroot/svn/node-stats/trunk'
# set :format, :pretty # Default value for :format is :pretty
# set :log_level, :debug # Default value for :log_level is :debug
# set :pty, true # Default value for :pty is false
......
......@@ -15,6 +15,7 @@ Rails.application.routes.draw do
resources :nodes
controller :nodes do
get 'set_t_address' => :set_t_address, as: 'set_t_address'
get 'set_z_address' => :set_z_address, as: 'set_z_address'
get 'z_gettotalbalance' => :z_gettotalbalance, as: 'z_gettotalbalance'
get 'sync_node' => :sync_node, as: 'sync_node'
get 'return_amount' => :return_amount, as: 'return_amount'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment