-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5063: GH-5058: Handle payment fix r=EdHastingsCasperAssociation a=mpapierski This change fixes custom payment under `Transaction::Deploy` variant which incorrectly took session bytes, rather than payment field. Additionally, it does properly remove the named key when payment is finalized. Closes #5058 Co-authored-by: Michał Papierski <michal@casper.network>
- Loading branch information
Showing
9 changed files
with
228 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[toolchain] | ||
channel = "1.77.2" | ||
channel = "1.78.0" |
15 changes: 15 additions & 0 deletions
15
smart_contracts/contracts/test/gh-5058-regression/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "gh-5058-regression" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "gh_5058_regression" | ||
path = "src/main.rs" | ||
bench = false | ||
doctest = false | ||
test = false | ||
|
||
[dependencies] | ||
casper-contract = { path = "../../../contract" } | ||
casper-types = { path = "../../../../types" } |
61 changes: 61 additions & 0 deletions
61
smart_contracts/contracts/test/gh-5058-regression/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate alloc; | ||
|
||
use casper_contract::{ | ||
contract_api::{account, runtime, system}, | ||
unwrap_or_revert::UnwrapOrRevert, | ||
}; | ||
|
||
use casper_types::{ | ||
runtime_args, system::handle_payment, ApiError, Phase, RuntimeArgs, URef, U512, | ||
}; | ||
|
||
const ARG_AMOUNT: &str = "amount"; | ||
|
||
#[repr(u16)] | ||
enum Error { | ||
InvalidPhase, | ||
} | ||
|
||
impl From<Error> for ApiError { | ||
fn from(e: Error) -> Self { | ||
ApiError::User(e as u16) | ||
} | ||
} | ||
|
||
fn get_payment_purse() -> URef { | ||
runtime::call_contract( | ||
system::get_handle_payment(), | ||
handle_payment::METHOD_GET_PAYMENT_PURSE, | ||
RuntimeArgs::default(), | ||
) | ||
} | ||
|
||
fn set_refund_purse(new_refund_purse: URef) { | ||
let args = runtime_args! { | ||
handle_payment::ARG_PURSE => new_refund_purse, | ||
}; | ||
|
||
runtime::call_contract( | ||
system::get_handle_payment(), | ||
handle_payment::METHOD_SET_REFUND_PURSE, | ||
args, | ||
) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn call() { | ||
if runtime::get_phase() != Phase::Payment { | ||
runtime::revert(Error::InvalidPhase); | ||
} | ||
|
||
let amount: U512 = runtime::get_named_arg(ARG_AMOUNT); | ||
let payment_purse = get_payment_purse(); | ||
set_refund_purse(account::get_main_purse()); | ||
|
||
// transfer amount from named purse to payment purse, which will be used to pay for execution | ||
system::transfer_from_purse_to_purse(account::get_main_purse(), payment_purse, amount, None) | ||
.unwrap_or_revert(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters