Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 99 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,25 @@ version = "23.0.0-rc.2"

# Dependencies from the rs-soroban-sdk repo:
[workspace.dependencies.soroban-spec]
version = "23.0.0-rc.2"
version = "23.0.0-rc.3"

[workspace.dependencies.soroban-spec-rust]
version = "23.0.0-rc.2"
version = "23.0.0-rc.3"

[workspace.dependencies.soroban-sdk]
version = "23.0.0-rc.2.1"
version = "23.0.0-rc.3"

[workspace.dependencies.soroban-env-host]
version = "23.0.0-rc.2"
version = "23.0.0-rc.3"

[workspace.dependencies.soroban-token-sdk]
version = "23.0.0-rc.2"
version = "23.0.0-rc.3"

[workspace.dependencies.soroban-ledger-snapshot]
version = "23.0.0-rc.2"
version = "23.0.0-rc.3"

[workspace.dependencies.stellar-asset-spec]
version = "23.0.0-rc.3"

# Dependencies from the rs-stellar-rpc-client repo:
[workspace.dependencies.soroban-rpc]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ Find issues to contribute to [here](https://github.com/stellar/stellar-cli/contr
- Video Tutorial on `network container`, `keys`, and `contract init`: https://developers.stellar.org/meetings/2024/06/27
- Video Tutorial on `alias` and `snapshot`: https://developers.stellar.org/meetings/2024/09/12

<!-- CI system test comment -->

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to remove this


9 changes: 8 additions & 1 deletion cmd/crates/soroban-spec-json/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ pub enum Entry {
name: String,
cases: Vec<ErrorEnumCase>,
},
Event {
doc: String,
name: String,
},
}

impl From<&ScSpecTypeDef> for Type {
Expand Down Expand Up @@ -240,7 +244,10 @@ impl From<&ScSpecEntry> for Entry {
name: e.name.to_utf8_string_lossy(),
cases: e.cases.iter().map(EnumCase::from).collect(),
},
ScSpecEntry::EventV0(_) => todo!("EventV0 is not implemented yet"),
ScSpecEntry::EventV0(e) => Entry::Event {
doc: e.doc.to_utf8_string_lossy(),
name: e.name.to_utf8_string_lossy(),
},
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
#![no_std]
use soroban_sdk::{
contract, contractimpl, log, symbol_short, vec, Address, BytesN, Env, String, Symbol, Vec,
contract, contractevent, contractimpl, log, symbol_short, vec, Address, BytesN, Env, String,
Symbol, Vec,
};

const COUNTER: Symbol = symbol_short!("COUNTER");

#[contractevent]
pub struct AuthEvent {
pub world: Symbol,
}

#[contractevent]
pub struct HelloEvent {
pub str: Symbol,
}

#[contract]
pub struct Contract;

Expand All @@ -25,7 +36,7 @@ impl Contract {
pub fn auth(env: Env, addr: Address, world: Symbol) -> Address {
addr.require_auth();
// Emit test event
env.events().publish(("auth",), world);
AuthEvent { world }.publish(&env);

addr
}
Expand Down Expand Up @@ -61,10 +72,7 @@ impl Contract {

/// Logs a string with `hello ` in front.
pub fn log(env: Env, str: Symbol) {
env.events().publish(
(Symbol::new(&env, "hello"), Symbol::new(&env, "")),
str.clone(),
);
HelloEvent { str: str.clone() }.publish(&env);
log!(&env, "hello {}", str);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
use crate::storage_types::{INSTANCE_BUMP_AMOUNT, INSTANCE_LIFETIME_THRESHOLD};
use crate::{admin, allowance, balance, metadata};
use soroban_sdk::token::{self, Interface as _};
use soroban_sdk::{contract, contractimpl, Address, Env, String};
use soroban_sdk::{contract, contractevent, contractimpl, Address, Env, MuxedAddress, String};
use soroban_token_sdk::events::{Approve, Burn, MintWithAmountOnly, TransferWithAmountOnly};
use soroban_token_sdk::metadata::TokenMetadata;
use soroban_token_sdk::TokenUtils;

#[contractevent(data_format = "single-value")]
pub struct SetAdmin {
#[topic]
admin: Address,
new_admin: Address,
}

fn check_nonnegative_amount(amount: i128) {
assert!(amount >= 0, "negative amount is not allowed: {amount}");
Expand Down Expand Up @@ -41,7 +48,11 @@ impl Token {
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);

balance::receive(&e, to.clone(), amount);
TokenUtils::new(&e).events().mint(admin, to, amount);
MintWithAmountOnly {
to: to.clone(),
amount,
}
.publish(&e);
}

pub fn set_admin(e: Env, new_admin: Address) {
Expand All @@ -53,7 +64,11 @@ impl Token {
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);

admin::write_administrator(&e, &new_admin);
TokenUtils::new(&e).events().set_admin(admin, new_admin);
SetAdmin {
admin: admin.clone(),
new_admin: new_admin.clone(),
}
.publish(&e);
}
}

Expand All @@ -76,9 +91,13 @@ impl token::Interface for Token {
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);

allowance::write(&e, from.clone(), spender.clone(), amount, expiration_ledger);
TokenUtils::new(&e)
.events()
.approve(from, spender, amount, expiration_ledger);
Approve {
from: from.clone(),
spender: spender.clone(),
amount,
expiration_ledger,
}
.publish(&e);
}

fn balance(e: Env, id: Address) -> i128 {
Expand All @@ -88,7 +107,7 @@ impl token::Interface for Token {
balance::read(&e, id)
}

fn transfer(e: Env, from: Address, to: Address, amount: i128) {
fn transfer(e: Env, from: Address, to: MuxedAddress, amount: i128) {
from.require_auth();

check_nonnegative_amount(amount);
Expand All @@ -97,9 +116,15 @@ impl token::Interface for Token {
.instance()
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);

let to_address = to.address();
balance::spend(&e, from.clone(), amount);
balance::receive(&e, to.clone(), amount);
TokenUtils::new(&e).events().transfer(from, to, amount);
balance::receive(&e, to_address.clone(), amount);
TransferWithAmountOnly {
from: from.clone(),
to: to_address,
amount,
}
.publish(&e);
}

fn transfer_from(e: Env, spender: Address, from: Address, to: Address, amount: i128) {
Expand All @@ -114,7 +139,12 @@ impl token::Interface for Token {
allowance::spend(&e, from.clone(), spender, amount);
balance::spend(&e, from.clone(), amount);
balance::receive(&e, to.clone(), amount);
TokenUtils::new(&e).events().transfer(from, to, amount);
TransferWithAmountOnly {
from: from.clone(),
to: to.clone(),
amount,
}
.publish(&e);
}

fn burn(e: Env, from: Address, amount: i128) {
Expand All @@ -127,7 +157,11 @@ impl token::Interface for Token {
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);

balance::spend(&e, from.clone(), amount);
TokenUtils::new(&e).events().burn(from, amount);
Burn {
from: from.clone(),
amount,
}
.publish(&e);
}

fn burn_from(e: Env, spender: Address, from: Address, amount: i128) {
Expand All @@ -141,7 +175,11 @@ impl token::Interface for Token {

allowance::spend(&e, from.clone(), spender, amount);
balance::spend(&e, from.clone(), amount);
TokenUtils::new(&e).events().burn(from, amount);
Burn {
from: from.clone(),
amount,
}
.publish(&e);
}

fn decimals(e: Env) -> u32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ fn invoke_log(sandbox: &TestEnv, id: &str) {
.assert()
.success()
.stderr(predicates::str::contains(
r#"Event: [{"symbol":"hello"},{"symbol":""}] = {"symbol":"world"}"#,
r#"Event: [{"symbol":"hello_event"}] = {"map":[{"key":{"symbol":"str"},"val":{"symbol":"world"}}]}"#,
))
.stderr(predicates::str::contains(
r#"Log: {"vec":[{"string":"hello {}"},{"symbol":"world"}]}"#,
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ soroban-spec-tools = { workspace = true }
soroban-spec-typescript = { workspace = true }
soroban-ledger-snapshot = { workspace = true }
stellar-strkey = { workspace = true }
stellar-asset-spec = { workspace = true }
soroban-sdk = { workspace = true }
soroban-rpc = { workspace = true }
stellar-ledger = { workspace = true, optional = true }
Expand Down
5 changes: 4 additions & 1 deletion cmd/soroban-cli/src/commands/contract/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ pub fn build_host_function_parameters(
.to_string_lossy()
.trim_matches('"')
.to_string();
if matches!(i.type_, ScSpecTypeDef::Address) {
if matches!(
i.type_,
ScSpecTypeDef::Address | ScSpecTypeDef::MuxedAddress
) {
let addr = resolve_address(&s, config)?;
let signer = resolve_signer(&s, config);
s = addr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl NetworkRunnable for Cmd {
let spec = match contract {
contract_spec::Contract::Wasm { wasm_bytes } => Spec::new(&wasm_bytes)?.spec,
contract_spec::Contract::StellarAssetContract => {
soroban_spec::read::parse_raw(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?
soroban_spec::read::parse_raw(stellar_asset_spec::xdr())?
}
};

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/info/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Cmd {
(spec.spec_base64.unwrap(), spec.spec)
}
shared::Contract::StellarAssetContract => {
Spec::spec_to_base64(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?
Spec::spec_to_base64(stellar_asset_spec::xdr())?
}
};

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/get_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub async fn get_remote_contract_spec(
}
}
ContractExecutable::StellarAsset => {
soroban_spec::read::parse_raw(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?
soroban_spec::read::parse_raw(stellar_asset_spec::xdr())?
}
})
}
2 changes: 1 addition & 1 deletion cookbook/payments-and-assets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ stellar keys use alice
```

```bash
stellar contract invoke --id <ASSET_CONTRACT_ID> -- transfer --to bob --from alice --amount 100
stellar contract invoke --id <ASSET_CONTRACT_ID> -- transfer --from alice --to bob --amount 100
```

6. Check account balance:
Expand Down
Loading