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

Merge deposit() and contract call() into a single call #1333

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 3 additions & 6 deletions crates/phactory/src/contracts/pink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,15 +641,13 @@ impl Cluster {
context::using(&mut ctx, move || {
context::using_entry_contract(contract_id.clone(), || {
let mut runtime = self.runtime_mut(log_handler);
if deposit > 0 {
runtime.deposit(origin.clone(), deposit);
}
let args = TransactionArguments {
origin,
transfer,
gas_limit: WEIGHT_REF_TIME_PER_SECOND * 10,
gas_free: true,
storage_deposit_limit: None,
deposit,
};
let ink_result = runtime.call(contract_id, input_data, mode, args);
let effects = if mode.is_estimating() {
Expand Down Expand Up @@ -721,15 +719,13 @@ impl Cluster {
let log_handler = context.log_handler.clone();
context::using(&mut ctx, move || {
let mut runtime = self.runtime_mut(log_handler);
if deposit > 0 {
runtime.deposit(origin.clone(), deposit);
}
let args = TransactionArguments {
origin,
transfer,
gas_limit: WEIGHT_REF_TIME_PER_SECOND * 10,
gas_free: true,
storage_deposit_limit: None,
deposit,
};
let ink_result = runtime.instantiate(
code_hash,
Expand Down Expand Up @@ -778,6 +774,7 @@ impl Cluster {
gas_limit,
gas_free,
storage_deposit_limit,
deposit: 0,
};

let mut runtime = self.runtime_mut(context.log_handler.clone());
Expand Down
1 change: 1 addition & 0 deletions crates/phactory/src/contracts/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl Contract {
gas_free: false,
storage_deposit_limit: None,
gas_limit,
deposit: 0,
};
let mut handle = env.contract_cluster.runtime_mut(env.log_handler.clone());
_ = handle.call(
Expand Down
1 change: 1 addition & 0 deletions crates/phactory/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,7 @@ impl<Platform: pal::Platform> System<Platform> {
gas_limit,
gas_free: false,
storage_deposit_limit,
deposit: 0,
};
let mut runtime = cluster.runtime_mut(log_handler.clone());
let _result = runtime.instantiate(
Expand Down
1 change: 1 addition & 0 deletions crates/pink/capi/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod ecall {
pub gas_limit: Weight,
pub gas_free: bool,
pub storage_deposit_limit: Option<Balance>,
pub deposit: Balance,
}

#[derive(Encode, Decode, Clone, Debug)]
Expand Down
1 change: 1 addition & 0 deletions crates/pink/runner/tests/test_pink_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn tx_args() -> TransactionArguments {
gas_limit: Weight::MAX,
gas_free: true,
storage_deposit_limit: None,
deposit: 0,
}
}

Expand Down
9 changes: 9 additions & 0 deletions crates/pink/runtime/src/capi/ecall_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl ecall::ECalls for ECallImpl {
gas_limit: Weight::MAX,
gas_free: true,
storage_deposit_limit: None,
deposit: 0,
};
let result = crate::contract::instantiate(
code_hash,
Expand Down Expand Up @@ -191,6 +192,7 @@ impl ecall::ECalls for ECallImpl {
tx_args: TransactionArguments,
) -> Vec<u8> {
let tx_args = sanitize_args(tx_args, mode);
handle_deposit(&tx_args);
let address = PalletPink::contract_address(&tx_args.origin, &code_hash, &input_data, &salt);
let result = crate::contract::instantiate(code_hash, input_data, salt, mode, tx_args);
if !result.debug_message.is_empty() {
Expand Down Expand Up @@ -239,6 +241,7 @@ impl ecall::ECalls for ECallImpl {
tx_args: TransactionArguments,
) -> Vec<u8> {
let tx_args = sanitize_args(tx_args, mode);
handle_deposit(&tx_args);
let result = crate::contract::bare_call(address.clone(), input_data, mode, tx_args);
if !result.debug_message.is_empty() {
let message = String::from_utf8_lossy(&result.debug_message).into_owned();
Expand Down Expand Up @@ -293,3 +296,9 @@ fn sanitize_args(mut args: TransactionArguments, mode: ExecutionMode) -> Transac
args.gas_limit = args.gas_limit.min(gas_limit);
args
}

fn handle_deposit(args: &TransactionArguments) {
if args.deposit > 0 {
let _ = PalletBalances::deposit_creating(&args.origin, args.deposit);
}
}
2 changes: 2 additions & 0 deletions crates/pink/runtime/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub fn instantiate(
gas_limit,
storage_deposit_limit,
gas_free,
deposit: _,
} = args;
let gas_limit = Weight::from_parts(gas_limit, 0).set_proof_size(u64::MAX);
let result = contract_tx(origin.clone(), gas_limit, gas_free, move || {
Expand Down Expand Up @@ -193,6 +194,7 @@ pub fn bare_call(
gas_limit,
gas_free,
storage_deposit_limit,
deposit: _,
} = tx_args;
let gas_limit = Weight::from_parts(gas_limit, 0).set_proof_size(u64::MAX);
let determinism = if mode.deterministic_required() {
Expand Down
Binary file modified standalone/pruntime/pink-runtimes/libpink.so.1.0
Binary file not shown.