From 23bd1ba91c6bd8e61b8fa064d5b75fd2bc8294b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Pobiar=C5=BCyn?= Date: Wed, 10 Apr 2024 11:24:19 +0200 Subject: [PATCH] Add livenet payable example (#398) --- examples/Cargo.toml | 6 ++++++ examples/bin/tlw_on_livenet.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 examples/bin/tlw_on_livenet.rs diff --git a/examples/Cargo.toml b/examples/Cargo.toml index d301caa1..714dc1db 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -36,6 +36,12 @@ path = "bin/erc20_on_livenet.rs" required-features = ["livenet"] test = false +[[bin]] +name = "tlw_on_livenet" +path = "bin/tlw_on_livenet.rs" +required-features = ["livenet"] +test = false + [[bin]] name = "livenet_tests" path = "bin/livenet_tests.rs" diff --git a/examples/bin/tlw_on_livenet.rs b/examples/bin/tlw_on_livenet.rs new file mode 100644 index 00000000..243c24c6 --- /dev/null +++ b/examples/bin/tlw_on_livenet.rs @@ -0,0 +1,30 @@ +//! Deploys an [odra_examples::contracts::tlw::TimeLockWallet] contract, then deposits and withdraw some CSPRs. +use odra::casper_types::{AsymmetricType, PublicKey, U512}; +use odra::host::{Deployer, HostRef}; +use odra::Address; +use odra_examples::contracts::tlw::{TimeLockWalletHostRef, TimeLockWalletInitArgs}; + +const DEPOSIT: u64 = 100; +const WITHDRAWAL: u64 = 99; +const GAS: u64 = 20u64.pow(9); + +fn main() { + let env = odra_casper_livenet_env::env(); + let caller = env.get_account(0); + + env.set_caller(caller); + env.set_gas(GAS); + + let mut contract = TimeLockWalletHostRef::deploy( + &env, + TimeLockWalletInitArgs { + lock_duration: 60 * 60 + } + ); + + contract.with_tokens(U512::from(DEPOSIT)).deposit(); + + println!("Owner's balance: {:?}", contract.get_balance(&caller)); + contract.withdraw(&U512::from(WITHDRAWAL)); + println!("Remaining balance: {:?}", contract.get_balance(&caller)); +}