mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-12 22:45:49 +00:00
Extract SimpleAddressDeterminator (#716)
This commit is contained in:
committed by
Gav Wood
parent
7520d601e3
commit
8fe5aa4c81
@@ -204,28 +204,9 @@ impl treasury::Trait for Runtime {
|
||||
/// Treasury module for this concrete runtime.
|
||||
pub type Treasury = treasury::Module<Runtime>;
|
||||
|
||||
/// Address calculated from the code (of the constructor), input data to the constructor
|
||||
/// and account id which requested the account creation.
|
||||
///
|
||||
/// Formula: `blake2_256(blake2_256(code) + blake2_256(data) + origin)`
|
||||
pub struct DetermineContractAddress;
|
||||
impl contract::ContractAddressFor<AccountId> for DetermineContractAddress {
|
||||
fn contract_address_for(code: &[u8], data: &[u8], origin: &AccountId) -> AccountId {
|
||||
use runtime_primitives::traits::Hash;
|
||||
|
||||
let code_hash = BlakeTwo256::hash(code);
|
||||
let data_hash = BlakeTwo256::hash(data);
|
||||
let mut buf = [0u8, 32 + 32 + 32];
|
||||
&mut buf[0..32].copy_from_slice(&code_hash);
|
||||
&mut buf[32..64].copy_from_slice(&data_hash);
|
||||
&mut buf[64..96].copy_from_slice(origin);
|
||||
AccountId::from(BlakeTwo256::hash(&buf[..]))
|
||||
}
|
||||
}
|
||||
|
||||
impl contract::Trait for Runtime {
|
||||
type Gas = u64;
|
||||
type DetermineContractAddress = DetermineContractAddress;
|
||||
type DetermineContractAddress = contract::SimpleAddressDeterminator<Runtime>;
|
||||
}
|
||||
|
||||
/// Contract module for this concrete runtime.
|
||||
|
||||
Reference in New Issue
Block a user