mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-10 13:27:30 +00:00
Integrate contracts into substrate-demo runtime (#675)
* Introduce data and salt into ContractAddressFor * Accept salt arg in ext_create. * Integrate contracts into the demo runtime * Make libcontract compile to wasm * Remove salt parameter. This now is concern of userspace. * Rebuild binaries.
This commit is contained in:
committed by
Gav Wood
parent
0e1023ae42
commit
6c1b2c27d1
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -29,6 +29,7 @@ pub use std::ops;
|
||||
pub use std::ptr;
|
||||
pub use std::rc;
|
||||
pub use std::slice;
|
||||
pub use std::string;
|
||||
pub use std::vec;
|
||||
pub use std::result;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ extern crate pwasm_alloc;
|
||||
pub use alloc::boxed;
|
||||
pub use alloc::rc;
|
||||
pub use alloc::vec;
|
||||
pub use alloc::string;
|
||||
pub use core::borrow;
|
||||
pub use core::cell;
|
||||
pub use core::clone;
|
||||
|
||||
@@ -123,7 +123,7 @@ impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
return Err("not enough gas to pay base create fee");
|
||||
}
|
||||
|
||||
let dest = T::DetermineContractAddress::contract_address_for(ctor, &self.self_account);
|
||||
let dest = T::DetermineContractAddress::contract_address_for(ctor, data, &self.self_account);
|
||||
if <CodeOf<T>>::exists(&dest) {
|
||||
// TODO: Is it enough?
|
||||
return Err("contract already exists");
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
//! Build the contract module part of the genesis block storage.
|
||||
|
||||
#![cfg(feature = "std")]
|
||||
|
||||
use {Trait, ContractFee, CallBaseFee, CreateBaseFee, GasPrice, MaxDepth, BlockGasLimit};
|
||||
|
||||
use runtime_primitives;
|
||||
|
||||
@@ -66,7 +66,7 @@ extern crate substrate_codec as codec;
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
extern crate substrate_runtime_sandbox as sandbox;
|
||||
|
||||
#[cfg_attr(feature = "std", macro_use)]
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_std as rstd;
|
||||
|
||||
extern crate substrate_runtime_balances as balances;
|
||||
@@ -90,16 +90,19 @@ mod double_map;
|
||||
mod exec;
|
||||
mod vm;
|
||||
mod gas;
|
||||
|
||||
mod genesis_config;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use genesis_config::GenesisConfig;
|
||||
use exec::ExecutionContext;
|
||||
use account_db::{AccountDb, OverlayAccountDb};
|
||||
use double_map::StorageDoubleMap;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::Codec;
|
||||
use runtime_primitives::traits::{As, SimpleArithmetic, OnFinalise};
|
||||
use runtime_support::dispatch::Result;
|
||||
@@ -115,7 +118,7 @@ pub trait Trait: balances::Trait {
|
||||
}
|
||||
|
||||
pub trait ContractAddressFor<AccountId: Sized> {
|
||||
fn contract_address_for(code: &[u8], origin: &AccountId) -> AccountId;
|
||||
fn contract_address_for(code: &[u8], data: &[u8], origin: &AccountId) -> AccountId;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
|
||||
@@ -61,7 +61,7 @@ type Contract = Module<Test>;
|
||||
|
||||
pub struct DummyContractAddressFor;
|
||||
impl ContractAddressFor<u64> for DummyContractAddressFor {
|
||||
fn contract_address_for(_code: &[u8], origin: &u64) -> u64 {
|
||||
fn contract_address_for(_code: &[u8], _data: &[u8], origin: &u64) -> u64 {
|
||||
origin + 1
|
||||
}
|
||||
}
|
||||
@@ -357,6 +357,7 @@ fn contract_create() {
|
||||
|
||||
let derived_address = <Test as Trait>::DetermineContractAddress::contract_address_for(
|
||||
&code_ctor_transfer,
|
||||
&[],
|
||||
&1,
|
||||
);
|
||||
|
||||
@@ -395,6 +396,7 @@ fn top_level_create() {
|
||||
with_externalities(&mut ExtBuilder::default().gas_price(3).build(), || {
|
||||
let derived_address = <Test as Trait>::DetermineContractAddress::contract_address_for(
|
||||
&code_ctor_transfer,
|
||||
&[],
|
||||
&0,
|
||||
);
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ macro_rules! define_env {
|
||||
|
||||
$(
|
||||
env.funcs.insert(
|
||||
stringify!( $name ).to_string(),
|
||||
stringify!( $name ).into(),
|
||||
HostFunction::new(
|
||||
gen_signature!( ( $( $params ),* ) $( -> $returns )* ),
|
||||
{
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
use super::{BalanceOf, CallReceipt, CreateReceipt, Ext, GasMeterResult, Runtime};
|
||||
use codec::Decode;
|
||||
use parity_wasm::elements::{FunctionType, ValueType};
|
||||
use rstd::prelude::*;
|
||||
use rstd::string::String;
|
||||
use rstd::collections::btree_map::BTreeMap;
|
||||
use runtime_primitives::traits::As;
|
||||
use sandbox::{self, TypedValue};
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
use super::env_def::HostFunctionSet;
|
||||
use super::{Config, Error, Ext};
|
||||
use rstd::prelude::*;
|
||||
use parity_wasm::elements::{self, External, MemoryType, Type};
|
||||
use pwasm_utils;
|
||||
use pwasm_utils::rules;
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user