diff --git a/Rakefile b/Rakefile index dd50d39..cddd9cd 100644 --- a/Rakefile +++ b/Rakefile @@ -87,6 +87,7 @@ end # Multi networks ########################################## require 'logger' +# nominee = active collators + waiting collators + other nominees who have nominations backing task :update_nominees, [:network_name] do |_t, args| logger = Logger.new($stdout) logger.level = Logger::DEBUG @@ -100,8 +101,8 @@ task :update_nominees, [:network_name] do |_t, args| ring_pool = get_storage(rpc, metadata, 'darwinia_staking', 'ring_pool', nil, nil) kton_pool = get_storage(rpc, metadata, 'darwinia_staking', 'kton_pool', nil, nil) - nominee_commissions = get_nominee_commissions(rpc, metadata) - collators = get_collators(rpc, metadata) + collator_commissions = get_collator_commissions(rpc, metadata) # includes active and waiting collators + active_collator_addresses = get_active_collators(rpc, metadata) # 1. Get all nominators with their nominees # --------------------------------------- @@ -156,8 +157,17 @@ task :update_nominees, [:network_name] do |_t, args| # 5. Set the collators committee # --------------------------------------- - result = nominee_powers.keys.map do |key| - [key, { power: nominee_powers[key], commission: nominee_commissions[key], is_collator: collators.include?(key) }] + all_nominee_addresses = (nominee_powers.keys + collator_commissions.keys).uniq + waiting_collator_addresses = collator_commissions.keys - active_collator_addresses + result = all_nominee_addresses.map do |nominee_address| + [ + nominee_address, + { + power: nominee_powers[nominee_address], + commission: collator_commissions[nominee_address], + status: get_nominee_status(active_collator_addresses, waiting_collator_addresses, nominee_address) + } + ] end.to_h # logger.debug JSON.pretty_generate(result) diff --git a/src/account.rb b/src/account.rb index f00c17b..1e03452 100644 --- a/src/account.rb +++ b/src/account.rb @@ -183,7 +183,7 @@ def get_nominee_power(rpc, metadata, address) calc_power(total[:staked_ring], total[:staked_kton], ring_pool, kton_pool) end -def get_nominee_commissions(rpc, metadata) +def get_collator_commissions(rpc, metadata) storages = get_storage(rpc, metadata, 'darwinia_staking', 'collators', nil, nil) storages.map do |storage| address = "0x#{storage[:storage_key][-40..]}" @@ -191,13 +191,21 @@ def get_nominee_commissions(rpc, metadata) end.to_h end -def get_collators(rpc, metadata) +def get_active_collators(rpc, metadata) storages = get_storage(rpc, metadata, 'darwinia_staking', 'exposures', nil, nil) storages.map do |storage| "0x#{storage[:storage_key][-40..]}" end end +def get_nominee_status(active_collator_addresses, waiting_collator_addresses, nominee_address) + if active_collator_addresses.include?(nominee_address) + 'working' + else + waiting_collator_addresses.include?(nominee_address) ? 'waiting' : 'quit' + end +end + # require_relative '../config/config' # config = get_config # crab_metadata = JSON.parse(File.read(config[:metadata][:crab]))