Skip to content
This repository has been archived by the owner on Feb 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #12 from paritytech/kip4
Browse files Browse the repository at this point in the history
Add create2 under kip4 feature flag
  • Loading branch information
NikVolf authored Aug 6, 2018
2 parents e6c2055 + 232ba7c commit 5001ccd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ default-features = false

[features]
default = []
kip4 = []
std = ["pwasm-std/std", "parity-hash/std", "bigint/std", "byteorder/std"]
44 changes: 42 additions & 2 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,28 @@ mod external {

pub fn origin(dest: *mut u8);

pub fn elog(topic_ptr: *const u8, topic_count: u32, data_ptr: *const u8, data_len: u32);
pub fn elog(
topic_ptr: *const u8,
topic_count: u32,
data_ptr: *const u8,
data_len: u32
);

pub fn create(
endowment: *const u8,
code_ptr: *const u8,
code_len: u32,
result_ptr: *mut u8
) -> i32;

pub fn create(endowment: *const u8, code_ptr: *const u8, code_len: u32, result_ptr: *mut u8) -> i32;
#[cfg(feature = "kip4")]
pub fn create2(
endowment: *const u8,
salt: *const u8,
code_ptr: *const u8,
code_len: u32,
result_ptr: *mut u8
) -> i32;

pub fn suicide(refund: *const u8) -> !;

Expand Down Expand Up @@ -118,6 +137,27 @@ pub fn create(endowment: U256, code: &[u8]) -> Result<Address, Error> {
}
}

#[cfg(feature = "kip4")]
/// Create a new account with the given code and salt, requires KIP-4.
///
/// # Errors
///
/// Returns [`Error`] in case contract constructor failed.
///
/// [`Error`]: struct.Error.html
pub fn create2(endowment: U256, salt: H256, code: &[u8]) -> Result<Address, Error> {
let mut endowment_arr = [0u8; 32];
endowment.to_big_endian(&mut endowment_arr);
let mut result = Address::new();
unsafe {
if external::create2(endowment_arr.as_ptr(), salt.as_ptr(), code.as_ptr(), code.len() as u32, (&mut result).as_mut_ptr()) == 0 {
Ok(result)
} else {
Err(Error)
}
}
}

/// Message-call into an account
///
/// # Arguments:
Expand Down

0 comments on commit 5001ccd

Please sign in to comment.