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

feat: improve asset parsing to use named keys as issuer #1762

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 123 additions & 18 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

113 changes: 107 additions & 6 deletions cmd/crates/soroban-test/tests/it/integration/tx/operations.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use soroban_cli::{
config::locator,
tx::{builder, ONE_XLM},
utils::contract_id_hash_from_asset,
xdr::{self, ReadXdr, SequenceNumber},
Expand Down Expand Up @@ -89,6 +90,71 @@ async fn create_account() {
invoke_hello_world(sandbox, &id);
}

#[tokio::test]
async fn create_account_with_alias() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("keys")
.args(["generate", "--no-fund", "new"])
.assert()
.success();
let test = test_address(sandbox);
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let test_account = client.get_account(&test).await.unwrap();
println!("test account has a balance of {}", test_account.balance);
let starting_balance = ONE_XLM * 100;
sandbox
.new_assert_cmd("tx")
.args([
"new",
"create-account",
"--destination",
"new",
"--starting-balance",
starting_balance.to_string().as_str(),
])
.assert()
.success();
let test_account_after = client.get_account(&test).await.unwrap();
assert!(test_account_after.balance < test_account.balance);
let id = deploy_contract(sandbox, HELLO_WORLD, DeployKind::Normal, Some("new")).await;
println!("{id}");
invoke_hello_world(sandbox, &id);
}

#[tokio::test]
async fn payment_with_alias() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let (test, test1) = setup_accounts(sandbox);
let test_account = client.get_account(&test).await.unwrap();
println!("test account has a balance of {}", test_account.balance);

let before = client.get_account(&test).await.unwrap();
let test1_account_entry_before = client.get_account(&test1).await.unwrap();

sandbox
.new_assert_cmd("tx")
.args([
"new",
"payment",
"--destination",
"test1",
"--amount",
ONE_XLM.to_string().as_str(),
])
.assert()
.success();
let test1_account_entry = client.get_account(&test1).await.unwrap();
assert_eq!(
ONE_XLM,
test1_account_entry.balance - test1_account_entry_before.balance,
"Should have One XLM more"
);
let after = client.get_account(&test).await.unwrap();
assert_eq!(before.balance - 10_000_100, after.balance);
}

#[tokio::test]
async fn payment() {
let sandbox = &TestEnv::new();
Expand Down Expand Up @@ -172,22 +238,53 @@ async fn account_merge() {
assert_eq!(before.balance + before1.balance - fee, after.balance);
}

#[tokio::test]
async fn account_merge_with_alias() {
let sandbox = &TestEnv::new();
let client = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap();
let (test, test1) = setup_accounts(sandbox);
let before = client.get_account(&test).await.unwrap();
let before1 = client.get_account(&test1).await.unwrap();
let fee = 100;
sandbox
.new_assert_cmd("tx")
.args([
"new",
"account-merge",
"--source",
"test1",
"--account",
"test",
"--fee",
fee.to_string().as_str(),
])
.assert()
.success();
let after = client.get_account(&test).await.unwrap();
assert!(client.get_account(&test1).await.is_err());
assert_eq!(before.balance + before1.balance - fee, after.balance);
}

#[tokio::test]
async fn set_trustline_flags() {
let sandbox = &TestEnv::new();
let (test, issuer) = setup_accounts(sandbox);
let asset = format!("usdc:{issuer}");
issue_asset(sandbox, &test, &asset, 100_000, 100).await;
let (test, test1) = setup_accounts(sandbox);
let asset = "usdc:test1";
issue_asset(sandbox, &test, asset, 100_000, 100).await;
sandbox
.new_assert_cmd("contract")
.arg("asset")
.arg("deploy")
.arg("--asset")
.arg(&asset)
.arg(asset)
.assert()
.success();
let id = contract_id_hash_from_asset(
asset.parse::<builder::Asset>().unwrap(),
&format!("usdc:{test1}")
.parse::<builder::Asset>()
.unwrap()
.resolve(&locator::Args::default())
.unwrap(),
&sandbox.network_passphrase,
);
// sandbox
Expand Down Expand Up @@ -450,7 +547,11 @@ async fn change_trust() {

// wrap_cmd(&asset).run().await.unwrap();
let id = contract_id_hash_from_asset(
asset.parse::<builder::Asset>().unwrap(),
&asset
.parse::<builder::Asset>()
.unwrap()
.resolve(&locator::Args::default())
.unwrap(),
&sandbox.network_passphrase,
);
sandbox
Expand Down
14 changes: 8 additions & 6 deletions cmd/crates/soroban-test/tests/it/integration/wrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use soroban_cli::{tx::builder, utils::contract_id_hash_from_asset};
use soroban_cli::{config::locator, tx::builder, utils::contract_id_hash_from_asset};
use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE};

#[tokio::test]
Expand All @@ -12,21 +12,23 @@ async fn burn() {
.arg("test")
.assert()
.stdout_as_str();
let asset = format!("native:{address}");
let asset = "native";
sandbox
.new_assert_cmd("contract")
.arg("asset")
.arg("deploy")
.arg("--source=test")
.arg("--asset")
.arg(&asset)
.arg(asset)
.assert()
.success();
// wrap_cmd(&asset).run().await.unwrap();
let asset: builder::Asset = asset.parse().unwrap();
let asset = asset
.parse::<builder::Asset>()
.unwrap()
.resolve(&locator::Args::default())
.unwrap();
let hash = contract_id_hash_from_asset(&asset, &network_passphrase);
let id = stellar_strkey::Contract(hash.0).to_string();
println!("{id}, {address}");
sandbox
.new_assert_cmd("contract")
.args([
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 @@ -124,6 +124,7 @@ fqdn = "0.3.12"
open = "5.3.0"
url = "2.5.2"
wasm-gen = "0.1.4"
serde_with = "3.11.0"

[build-dependencies]
crate-git-revision = "0.0.6"
Expand Down
6 changes: 4 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub enum Error {
Network(#[from] network::Error),
#[error(transparent)]
Builder(#[from] builder::Error),
#[error(transparent)]
Asset(#[from] builder::asset::Error),
}

impl From<Infallible> for Error {
Expand Down Expand Up @@ -85,7 +87,7 @@ impl NetworkRunnable for Cmd {
) -> Result<Self::Result, Error> {
let config = config.unwrap_or(&self.config);
// Parse asset
let asset = &self.asset;
let asset = self.asset.resolve(&config.locator)?;

let network = config.get_network()?;
let client = network.rpc_client()?;
Expand All @@ -100,7 +102,7 @@ impl NetworkRunnable for Cmd {
.await?;
let sequence: i64 = account_details.seq_num.into();
let network_passphrase = &network.network_passphrase;
let contract_id = contract_id_hash_from_asset(asset, network_passphrase);
let contract_id = contract_id_hash_from_asset(&asset, network_passphrase);
let tx = build_wrap_token_tx(
asset,
&contract_id,
Expand Down
7 changes: 6 additions & 1 deletion cmd/soroban-cli/src/commands/contract/id/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum Error {
ConfigError(#[from] config::Error),
#[error(transparent)]
Xdr(#[from] crate::xdr::Error),
#[error(transparent)]
Asset(#[from] builder::asset::Error),
}
impl Cmd {
pub fn run(&self) -> Result<(), Error> {
Expand All @@ -30,7 +32,10 @@ impl Cmd {

pub fn contract_address(&self) -> Result<stellar_strkey::Contract, Error> {
let network = self.config.get_network()?;
let contract_id = contract_id_hash_from_asset(&self.asset, &network.network_passphrase);
let contract_id = contract_id_hash_from_asset(
&self.asset.resolve(&self.config.locator)?,
&network.network_passphrase,
);
Ok(stellar_strkey::Contract(contract_id.0))
}
}
6 changes: 3 additions & 3 deletions cmd/soroban-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use clap::command;

use crate::config::{locator, secret};
use crate::config::{key, locator, secret};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Secret(#[from] secret::Error),
Key(#[from] key::Error),

#[error(transparent)]
Config(#[from] locator::Error),
Expand All @@ -28,6 +28,6 @@ impl Cmd {
pub fn run(&self) -> Result<(), Error> {
Ok(self
.config_locator
.write_identity(&self.name, &self.secrets.read_secret()?)?)
.write_key(&self.name, &self.secrets.read_key()?)?)
}
}
18 changes: 10 additions & 8 deletions cmd/soroban-cli/src/commands/keys/address.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::commands::config::secret;

use super::super::config::locator;
use clap::arg;

use crate::commands::config::{key, locator};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),

#[error(transparent)]
Secret(#[from] secret::Error),
Key(#[from] key::Error),

#[error(transparent)]
StrKey(#[from] stellar_strkey::DecodeError),
Expand All @@ -36,10 +35,13 @@ impl Cmd {
}

pub fn private_key(&self) -> Result<ed25519_dalek::SigningKey, Error> {
Ok(self
.locator
.read_identity(&self.name)?
.key_pair(self.hd_path)?)
Ok(ed25519_dalek::SigningKey::from_bytes(
&self
.locator
.read_identity(&self.name)?
.private_key(self.hd_path)?
.0,
))
}

pub fn public_key(&self) -> Result<stellar_strkey::ed25519::PublicKey, Error> {
Expand Down
7 changes: 2 additions & 5 deletions cmd/soroban-cli/src/commands/keys/show.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use clap::arg;

use crate::config::{locator, secret};
use crate::config::{key, locator};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),

#[error(transparent)]
Secret(#[from] secret::Error),

#[error(transparent)]
StrKey(#[from] stellar_strkey::DecodeError),
Key(#[from] key::Error),
}

#[derive(Debug, clap::Parser, Clone)]
Expand Down
4 changes: 3 additions & 1 deletion cmd/soroban-cli/src/commands/snapshot/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ impl Cmd {
get_name_from_stellar_asset_contract_storage(storage)
{
let asset: builder::Asset = name.parse()?;
if let Some(issuer) = match asset.into() {
if let Some(issuer) = match asset
.resolve(&global_args.locator)?
{
Asset::Native => None,
Asset::CreditAlphanum4(a4) => Some(a4.issuer),
Asset::CreditAlphanum12(a12) => Some(a12.issuer),
Expand Down
Loading
Loading