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 ...@@ -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) AmountSend.create(from: a.taddress, to: Setting.stk_node_address, amount: listunspent["#{b}"].to_f - 0.0001, node_id: a.id)
end end
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 end
redirect_to nodes_path, notice: 'Transaction is create.' redirect_to nodes_path, notice: 'Transaction is create.'
end end
...@@ -97,6 +104,11 @@ class AmountSendsController < ApplicationController ...@@ -97,6 +104,11 @@ class AmountSendsController < ApplicationController
if balance > 0 if balance > 0
AmountSend.create(from: Setting.stk_node_address, to: a.taddress, amount: a.start_balance_t + 0.0001, status: 'return') AmountSend.create(from: Setting.stk_node_address, to: a.taddress, amount: a.start_balance_t + 0.0001, status: 'return')
end 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 end
redirect_to nodes_path, notice: 'Preparation return.' redirect_to nodes_path, notice: 'Preparation return.'
end end
...@@ -135,6 +147,20 @@ class AmountSendsController < ApplicationController ...@@ -135,6 +147,20 @@ class AmountSendsController < ApplicationController
end end
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. # Use callbacks to share common setup or constraints between actions.
def set_amount_send def set_amount_send
@amount_send = AmountSend.find(params[:id]) @amount_send = AmountSend.find(params[:id])
......
...@@ -15,6 +15,9 @@ class NodesController < AdminController ...@@ -15,6 +15,9 @@ class NodesController < AdminController
# GET /nodes/1.json # GET /nodes/1.json
def show def show
listunspent(@node) listunspent(@node)
if @address.present?
z_listaddresses(@node)
end
end end
# GET /nodes/new # GET /nodes/new
...@@ -82,6 +85,21 @@ class NodesController < AdminController ...@@ -82,6 +85,21 @@ class NodesController < AdminController
redirect_to nodes_url redirect_to nodes_url
end 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 def z_gettotalbalance
Node.all.each do |a| Node.all.each do |a|
h = BitcoinRPC.new("http://#{a.node_username}:#{a.node_password}@#{a.ipv4}:8231") h = BitcoinRPC.new("http://#{a.node_username}:#{a.node_password}@#{a.ipv4}:8231")
...@@ -126,6 +144,20 @@ class NodesController < AdminController ...@@ -126,6 +144,20 @@ class NodesController < AdminController
end end
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 def sync_node
@params = { @params = {
from: params[:sync_to_sheet][:from], from: params[:sync_to_sheet][:from],
......
...@@ -25,10 +25,12 @@ ...@@ -25,10 +25,12 @@
%br %br
= link_to 'create transaction', set_transaction_url, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-primary' = 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 'preparation return', preparation_return_url, class: 'btn btn-primary'
= link_to 'return amount', return_amount_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 @@ ...@@ -40,7 +42,7 @@
%th Ipv4 %th Ipv4
%th Ipv6 %th Ipv6
%th Taddress %th Taddress
-#%th Zaddress %th Zaddress
%th Start balance t %th Start balance t
%th Start balance z %th Start balance z
%th Balance t %th Balance t
...@@ -56,7 +58,7 @@ ...@@ -56,7 +58,7 @@
%td= node.ipv4 %td= node.ipv4
%td= node.ipv6 %td= node.ipv6
%td= node.taddress %td= node.taddress
-#%td= node.zaddress %td= node.zaddress.present? ? "present" : "blank"
%td= node.start_balance_t %td= node.start_balance_t
%td= node.start_balance_z %td= node.start_balance_z
%td= node.balance_t %td= node.balance_t
......
...@@ -45,6 +45,14 @@ ...@@ -45,6 +45,14 @@
%b= a + ':' %b= a + ':'
= @address[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 # config valid only for current version of Capistrano
lock '3.11.0' lock '3.7.2'
# DEPLOY # DEPLOY
set :application, 'node-statistic' set :application, 'node-statistic'
# set :deploy_to, '/var/www/amaox' # Default deploy_to directory is /var/www/my_app_name # 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 :format, :pretty # Default value for :format is :pretty
# set :log_level, :debug # Default value for :log_level is :debug # set :log_level, :debug # Default value for :log_level is :debug
# set :pty, true # Default value for :pty is false # set :pty, true # Default value for :pty is false
......
...@@ -15,6 +15,7 @@ Rails.application.routes.draw do ...@@ -15,6 +15,7 @@ Rails.application.routes.draw do
resources :nodes resources :nodes
controller :nodes do controller :nodes do
get 'set_t_address' => :set_t_address, as: 'set_t_address' 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 'z_gettotalbalance' => :z_gettotalbalance, as: 'z_gettotalbalance'
get 'sync_node' => :sync_node, as: 'sync_node' get 'sync_node' => :sync_node, as: 'sync_node'
get 'return_amount' => :return_amount, as: 'return_amount' 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