From 4abd2eec857b4820a03029b829efd6568d1f2763 Mon Sep 17 00:00:00 2001 From: Aki Wu Date: Thu, 24 Aug 2023 09:29:16 +0800 Subject: [PATCH] add display name to collator --- Rakefile | 2 ++ src/account.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Rakefile b/Rakefile index cddd9cd..cb9fe1f 100644 --- a/Rakefile +++ b/Rakefile @@ -103,6 +103,7 @@ task :update_nominees, [:network_name] do |_t, args| kton_pool = get_storage(rpc, metadata, 'darwinia_staking', 'kton_pool', nil, nil) collator_commissions = get_collator_commissions(rpc, metadata) # includes active and waiting collators active_collator_addresses = get_active_collators(rpc, metadata) + identities = get_identities(rpc, metadata) # address => name # 1. Get all nominators with their nominees # --------------------------------------- @@ -163,6 +164,7 @@ task :update_nominees, [:network_name] do |_t, args| [ nominee_address, { + name: identities[nominee_address], power: nominee_powers[nominee_address], commission: collator_commissions[nominee_address], status: get_nominee_status(active_collator_addresses, waiting_collator_addresses, nominee_address) diff --git a/src/account.rb b/src/account.rb index 1e03452..3ea9889 100644 --- a/src/account.rb +++ b/src/account.rb @@ -206,11 +206,25 @@ def get_nominee_status(active_collator_addresses, waiting_collator_addresses, no end end +def get_identities(rpc, metadata) + storages = get_storage(rpc, metadata, 'identity', 'identity_of', nil, nil) + storages.map do |storage| + address = "0x#{storage[:storage_key][-40..]}" + name = if storage[:storage][:info][:display].instance_of?(Hash) + storage[:storage][:info][:display].values.first.to_utf8 + end + [address, name] + end.to_h +end + # require_relative '../config/config' # config = get_config # crab_metadata = JSON.parse(File.read(config[:metadata][:crab])) # crab_rpc = config[:crab_rpc] +# # get_identities +# puts get_identities(crab_rpc, crab_metadata) + # # collators # puts collators(crab_rpc, crab_metadata)