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

[Condor-Release]: HandlePayment error: Unable to remove named key #5058

Closed
Adrian-Wrona opened this issue Jan 14, 2025 · 0 comments · Fixed by #5063
Closed

[Condor-Release]: HandlePayment error: Unable to remove named key #5058

Adrian-Wrona opened this issue Jan 14, 2025 · 0 comments · Fixed by #5063
Assignees

Comments

@Adrian-Wrona
Copy link

Category

Bug/Issue

Your email address

[email protected]

Integration Project Name(Optional)

No response

Casper Network

Devnet

Node Functionality

Node

Description

The user is currently working on setting up a transaction that utilizes a custom payment code rather than the standard one. However, the user encounters an error: HandlePayment error: Unable to remove named key.

The user is running their tests via NCTL using the v2-rc5 docker image provided by MAKE.

Below is the payment code I'm using for reference:

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();
}

Date Issue Began(optional)

No response

Attachments (optional)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@mpapierski @devendran-m @EdHastingsCasperAssociation @Adrian-Wrona and others