-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
stellar_asset!
macro. Resolves a token client at compile (#…
…133) Currently you need to hard code the contract ids of existing SAC contracts like "native". This allows this to be resolved at compile time. It does currently require that STELLAR_NETWORK be `local`, `testnet`, `futurenet` or `mainnet` and defaults to `local`.
- Loading branch information
1 parent
a73bc23
commit db2414f
Showing
13 changed files
with
299 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "example-wallet" | ||
version = "0.0.0" | ||
authors = ["Stellar Development Foundation <[email protected]>"] | ||
license = "Apache-2.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
doctest = false | ||
|
||
[dependencies] | ||
loam-sdk = { workspace = true, features = ["loam-soroban-sdk"] } | ||
loam-subcontract-core = { workspace = true } | ||
|
||
|
||
[dev_dependencies] | ||
loam-sdk = { workspace = true, features = ["soroban-sdk-testutils"] } |
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,9 @@ | ||
use loam_sdk::soroban_sdk::{self, contracterror}; | ||
|
||
#[contracterror] | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
#[repr(u32)] | ||
pub enum Error { | ||
/// The operation results in an integer overflow | ||
Overflow = 1, | ||
} |
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,11 @@ | ||
#![no_std] | ||
use loam_subcontract_core::{admin::Admin, Core}; | ||
|
||
pub mod error; | ||
pub mod subcontract; | ||
|
||
pub use error::Error; | ||
use subcontract::{Calculator, Token}; | ||
|
||
#[loam_sdk::derive_contract(Core(Admin), Token(Calculator))] | ||
pub struct Contract; |
36 changes: 36 additions & 0 deletions
36
crates/loam-cli/examples/soroban/wallet/src/subcontract.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,36 @@ | ||
use loam_sdk::{ | ||
soroban_sdk::{env, token, Address, Lazy}, | ||
stellar_asset, subcontract, | ||
}; | ||
|
||
#[derive(Lazy, Default)] | ||
pub struct Calculator; | ||
|
||
#[subcontract] | ||
pub trait IsToken { | ||
/// Get contract's xlm balance | ||
#[allow(clippy::missing_errors_doc)] | ||
fn balance(&self) -> i128; | ||
|
||
/// Puts two into into a vector | ||
fn transfer(&self, to: loam_sdk::soroban_sdk::Address, amount: i128); | ||
|
||
fn addr(&self) -> loam_sdk::soroban_sdk::Address; | ||
} | ||
|
||
fn native() -> token::Client<'static> { | ||
stellar_asset!("native") | ||
} | ||
|
||
impl IsToken for Calculator { | ||
fn balance(&self) -> i128 { | ||
native().balance(&env().current_contract_address()) | ||
} | ||
|
||
fn transfer(&self, to: Address, amount: i128) { | ||
native().transfer(&env().current_contract_address(), &to, &amount); | ||
} | ||
fn addr(&self) -> loam_sdk::soroban_sdk::Address { | ||
native().address | ||
} | ||
} |
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
Oops, something went wrong.