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

As Smart Contract, I should an accompanying WASM proxy to collect user payments #30

Open
melpadden opened this issue Mar 25, 2024 · 0 comments
Assignees
Labels

Comments

@melpadden
Copy link
Collaborator

Since purchasing a ticket requires transferring CSPR from the account main purse to the contract, we would need to use a WASM-proxy implementing the reusable purse approach.

#[no_mangle]
pub extern "C" fn call() {
    let amount: U512 = runtime::get_named_arg(ARG_AMOUNT);
    let lottery_contract_hash: ContractHash =
        runtime::get_named_arg(ARG_LOTTERY_CONTRACT_HASH);
    let lottery_contract_entry_point: String =
        runtime::get_named_arg(ARG_LOTTERY_CONTRACT_HASH);

    let contract_treasure_purse: URef = runtime::call_contract(
        lottery_contract_hash,
        LOTTERY_CONTRACT_GET_TREASURY_PURSE_ENTRY_POINT_NAME,
        runtime_args! {},
    );

    system::transfer_from_purse_to_purse(
        account::get_main_purse(),
        contract_treasure_purse,
        amount,
        None,
    )
    .unwrap_or_revert();

    runtime::call_contract(
        lottery_contract_hash,
        lottery_contract_entry_point,
        runtime_args! {}
    )
}

For this implementation, the contract has to implement the get_treasure_purse entry point that returns the purse with the ADD access only:

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

No branches or pull requests

2 participants