Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cold address #615

Merged
merged 3 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/chainx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("chainx"),
impl_name: create_runtime_str!("chainx-net"),
authoring_version: 1,
spec_version: 14,
spec_version: 15,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down
2 changes: 1 addition & 1 deletion runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("chainx"),
impl_name: create_runtime_str!("chainx-dev"),
authoring_version: 1,
spec_version: 14,
spec_version: 15,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down
2 changes: 1 addition & 1 deletion runtime/malan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("chainx"),
impl_name: create_runtime_str!("chainx-malan"),
authoring_version: 1,
spec_version: 14,
spec_version: 15,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down
28 changes: 19 additions & 9 deletions xpallets/gateway/bitcoin/src/trustee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ impl<T: Config> TrusteeForChain<T::AccountId, T::BlockNumber, BtcTrusteeType, Bt
.parse()
.map_err(|_| Error::<T>::InvalidAddress)?;

// Set cold address for taproot threshold address
let cold_pks = cold_keys
.into_iter()
.map(|k| k.try_into().map_err(|_| Error::<T>::InvalidPublicKey))
.collect::<Result<Vec<_>, Error<T>>>()?;

let cold_mast = Mast::new(cold_pks, sig_num).map_err(|_| Error::<T>::InvalidAddress)?;

let cold_threshold_addr: Address = cold_mast
.generate_address(&Pallet::<T>::network_id().to_string())
.map_err(|_| Error::<T>::InvalidAddress)?
.parse()
.map_err(|_| Error::<T>::InvalidAddress)?;

// Aggregate public key script and corresponding personal public key index
let mut agg_pubkeys: Vec<Vec<u8>> = vec![];
let mut personal_accounts: Vec<Vec<T::AccountId>> = vec![];
Expand All @@ -243,15 +257,10 @@ impl<T: Config> TrusteeForChain<T::AccountId, T::BlockNumber, BtcTrusteeType, Bt
redeem_script: vec![],
};

let cold_trustee_addr_info: BtcTrusteeAddrInfo =
create_multi_address::<T>(&cold_keys, sig_num).ok_or_else(|| {
log!(
error,
"[generate_trustee_session_info] Create cold_addr error, cold_keys:{:?}",
cold_keys
);
Error::<T>::GenerateMultisigFailed
})?;
let cold_trustee_addr_info: BtcTrusteeAddrInfo = BtcTrusteeAddrInfo {
addr: cold_threshold_addr.to_string().into_bytes(),
redeem_script: vec![],
};

log!(
info,
Expand Down Expand Up @@ -378,6 +387,7 @@ pub fn get_sig_num<T: Config>() -> (u32, u32) {
(two_thirds_unsafe(trustee_num), trustee_num)
}

#[allow(dead_code)]
pub(crate) fn create_multi_address<T: Config>(
pubkeys: &[Public],
sig_num: u32,
Expand Down