【发布时间】:2021-09-10 05:59:47
【问题描述】:
我试图了解将开发密钥添加到 Substrate 中的本地密钥库以用于开发目的的内部逻辑。例如,我可以看到 Alice 的 session keys 正在生成并添加到 /bin/node/cli/src/chain_spec.rs 文件中的 genesis 配置中,如下所示:
pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary =
WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?;
Ok(ChainSpec::from_genesis(
// Name
"Development",
// ID
"dev",
ChainType::Development,
move || {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
true,
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Properties
None,
// Extensions
None,
))
}
据我了解,用于开发的session keys 还包括ImOnlineId。我的问题是如何将密钥添加到本地密钥库,以便我能够在im-online 托盘中访问我的密钥:
fn local_authority_keys() -> impl Iterator<Item=(u32, T::AuthorityId)> {
// on-chain storage
//
// At index `idx`:
// 1. A (ImOnline) public key to be used by a validator at index `idx` to send im-online
// heartbeats.
let authorities = Keys::<T>::get();
// local keystore
//
// All `ImOnline` public (+private) keys currently in the local keystore.
let mut local_keys = T::AuthorityId::all();
local_keys.sort();
authorities.into_iter()
.enumerate()
.filter_map(move |(index, authority)| {
local_keys.binary_search(&authority)
.ok()
.map(|location| (index as u32, local_keys[location].clone()))
})
}
在调试时,我可以在 local_keys 中找到 Alice 的公钥。
询问是因为我想开发类似的东西,并且通过这种方式在开发中进行测试变得更容易,而不是手动将密钥放入密钥库。
【问题讨论】:
标签: blockchain substrate polkadot