Extract SimpleAddressDeterminator (#716)

This commit is contained in:
Sergey Pepyakin
2018-09-11 19:39:31 +03:00
committed by Gav Wood
parent 7520d601e3
commit 8fe5aa4c81
2 changed files with 28 additions and 21 deletions
+1 -20
View File
@@ -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.