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: add tx sign/send and Stellar trait #1406

Closed
wants to merge 86 commits into from
Closed
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
8c080ce
feat: add stellar_ledger as workspace dep
willemneal Jun 24, 2024
e600127
feat: add Stellar; tx sign/send
willemneal Jun 24, 2024
8134f3e
feat: add signer to other commands and ban keys named "ledger"
willemneal Jun 24, 2024
d8f6b6f
feat: use KeyName as a field to make clap parse it
willemneal Jun 25, 2024
b8c6157
fix: fmt
willemneal Jun 25, 2024
b82468e
fix: tests and docs
willemneal Jun 25, 2024
b711e8a
feat: remove stellar-ledger
willemneal Jun 26, 2024
0ba2de9
fix: switch to crossterm for cross platform compatibility
willemneal Jun 26, 2024
c9c8e02
fix: use async_trait to allow older versions of rust
willemneal Jun 26, 2024
9718d07
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jun 26, 2024
46f7272
fix: tx test clippy error
willemneal Jun 26, 2024
1a59b17
Merge branch 'main' into feat/sign_and_send
willemneal Jun 27, 2024
ab62ff0
fix: remove ledger tests
willemneal Jun 27, 2024
934b36b
fix: don't mention ledger
willemneal Jun 27, 2024
c678b7a
fix: no longer assume key used is source key with signing auth entries
willemneal Jun 27, 2024
d6f427e
fix: add Network to Stellar to allow for getting latest ledger
willemneal Jul 2, 2024
fd94b31
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 2, 2024
b8c7ccf
fix: fmt
willemneal Jul 2, 2024
6c69fa4
fix: docs
willemneal Jul 2, 2024
04d1358
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 8, 2024
e061785
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 8, 2024
aacff2c
fix: send does not require a source account
willemneal Jul 9, 2024
71dc74b
chore: initial sign and send test
willemneal Jul 9, 2024
c0d3b61
fix: test
willemneal Jul 9, 2024
cd98038
fix: send output
willemneal Jul 9, 2024
d4ce6e2
fix: crate name
willemneal Jul 9, 2024
bc18cd6
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 9, 2024
e26599a
fix: remove ledger stuff and add comment to tx sign
willemneal Jul 9, 2024
ba8eb74
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 10, 2024
1767197
fix: remove KeyName will be added by ledger PR
willemneal Jul 10, 2024
9df886f
fix: rpc tests
willemneal Jul 11, 2024
ee193cc
feat: add `ledgers-from-now` arg to invoke and auth
willemneal Jul 11, 2024
df18c0a
fix: use correct arg
willemneal Jul 11, 2024
62931d5
fix: use stderr
willemneal Jul 11, 2024
a9f95a7
fix: proper matching of stderr
willemneal Jul 11, 2024
e6a4fb9
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 11, 2024
1e118c1
fix: remove unused code and make transaction hash public
willemneal Jul 12, 2024
62d9a72
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 12, 2024
7409706
Merge branch 'main' into feat/sign_and_send
willemneal Jul 15, 2024
510f2a4
Merge branch 'main' into feat/sign_and_send
willemneal Jul 16, 2024
d17704a
Merge branch 'main' into feat/sign_and_send
willemneal Jul 16, 2024
33fc952
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 23, 2024
6342fd0
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 23, 2024
1369614
Update cmd/soroban-cli/src/commands/tx/sign.rs
willemneal Jul 24, 2024
97e52a8
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 26, 2024
344bf95
feat: add `sign_with::Args` to handle non-source account signing
willemneal Jul 26, 2024
87a85dd
feat: simplify `tx sign` to remove source account
willemneal Jul 29, 2024
bec2474
feat: add `sign_txn_env` to Signer trait
willemneal Jul 29, 2024
f099cbe
fix: remove key_pair since not all signers will expose the private key
willemneal Jul 29, 2024
e6a77aa
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 29, 2024
57ddbe1
fix: use signer with source account
willemneal Jul 29, 2024
de926b8
fix: remove auth test and update --sign-with-key description
willemneal Jul 30, 2024
4853eb1
Merge remote-tracking branch 'origin/main' into feat/txn_auth
willemneal Jul 30, 2024
5b95eb2
Merge remote-tracking branch 'origin/main' into feat/txn_auth
willemneal Jul 30, 2024
8cf9c92
feat: `auth_expires_in_ledgers` & `auth_expires_at_ledger` in auth::Args
willemneal Jul 30, 2024
2277384
fix: --yes in tests and improve its docs
willemneal Jul 30, 2024
9c02bcf
chore: add print for testing
willemneal Jul 30, 2024
2856eab
fix: improve arg name and don't use `self.config`
willemneal Jul 30, 2024
c84f8c2
fix: use better print
willemneal Jul 30, 2024
ea40e24
fix: revert enum to Secret
willemneal Jul 30, 2024
c8dcb9c
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Jul 30, 2024
7c59ed8
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 2, 2024
a3b84e4
Update cmd/soroban-cli/src/config/secret.rs
willemneal Aug 3, 2024
cd884f7
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 5, 2024
47ba14b
fix: hide sign-with-lab
willemneal Aug 6, 2024
c4c6369
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 13, 2024
01c33b2
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 13, 2024
ddb682d
Merge remote-tracking branch 'AhaLabs-PR1311/feat/sign_and_send' into…
willemneal Aug 13, 2024
9f6a3b5
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 13, 2024
8e9fd29
fix: simplify Stellar trait and remove auth methods
willemneal Aug 13, 2024
20d524c
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 13, 2024
ae71c90
fix: don't assume source account is signer
willemneal Aug 13, 2024
80819fe
fix: update comments
willemneal Aug 13, 2024
5b7e5b0
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 13, 2024
df2beba
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 19, 2024
a84f07e
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Aug 22, 2024
1fdc4de
Apply suggestions from code review
willemneal Aug 27, 2024
27137e6
Merge branch 'main' into feat/sign_and_send
willemneal Aug 27, 2024
b853484
fix: docs
willemneal Aug 27, 2024
31da160
Merge remote-tracking branch 'upstream/main' into feat/sign_and_send
elizabethengelman Aug 30, 2024
ce1bbe7
Fix after merging
elizabethengelman Aug 30, 2024
349ba49
Merge branch 'main' into feat/sign_and_send
willemneal Aug 31, 2024
315aca2
Merge branch 'main' into feat/sign_and_send
elizabethengelman Sep 3, 2024
330a61e
Merge branch 'main' into feat/sign_and_send
elizabethengelman Sep 6, 2024
37a48e2
Merge branch 'main' into feat/sign_and_send
willemneal Sep 9, 2024
4f3e1c5
Merge remote-tracking branch 'origin/main' into feat/sign_and_send
willemneal Sep 10, 2024
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
61 changes: 60 additions & 1 deletion Cargo.lock

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

107 changes: 85 additions & 22 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use fs_extra::dir::CopyOptions;

use soroban_cli::{
commands::{contract::invoke, global, keys, NetworkRunnable},
config::{self, network},
config::{self, network, sign_with},
CommandParser,
};

Expand Down Expand Up @@ -222,17 +222,20 @@ impl TestEnv {
pub fn clone_config(&self, account: &str) -> config::Args {
let config_dir = Some(self.dir().to_path_buf());
config::Args {
network: network::Args {
rpc_url: Some(self.rpc_url.clone()),
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
},
source_account: account.to_string(),
locator: config::locator::Args {
global: false,
config_dir,
sign_with: sign_with::Args {
network: network::Args {
rpc_url: Some(self.rpc_url.clone()),
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
},
locator: config::locator::Args {
global: false,
config_dir,
},
yes: true,
..Default::default()
},
hd_path: None,
}
}

Expand All @@ -243,9 +246,10 @@ impl TestEnv {
account: &str,
) -> Result<T::Result, T::Error> {
let config = self.clone_config(account);
eprintln!("Running with config: {config:#?}");
cmd.run_against_rpc_server(
Some(&global::Args {
locator: config.locator.clone(),
locator: config.sign_with.locator.clone(),
filter_logs: Vec::default(),
quiet: false,
verbose: false,
Expand All @@ -264,9 +268,10 @@ impl TestEnv {
}

/// Returns the public key corresponding to the test keys's `hd_path`
pub fn test_address(&self, hd_path: usize) -> String {
pub async fn test_address(&self, hd_path: usize) -> String {
self.cmd::<keys::address::Cmd>(&format!("--hd-path={hd_path}"))
.public_key()
.await
.unwrap()
.to_string()
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/crates/soroban-test/tests/it/integration/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ use super::util::invoke_with_roundtrip;

fn invoke_custom(e: &TestEnv, id: &str, func: &str) -> assert_cmd::Command {
let mut s = e.new_assert_cmd("contract");
s.arg("invoke").arg("--id").arg(id).arg("--").arg(func);
s.env("RUST_LOG", "soroban_cli::log::diagnostic_event=off")
.arg("invoke")
.arg("--id")
.arg(id)
.arg("--is-view")
.arg("--")
.arg(func);
s
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ async fn invoke_auth_with_different_test_account_fail(sandbox: &TestEnv, id: &st
"--hd-path=0",
"--id",
id,
"--fee=1000000",
"--",
"auth",
&format!("--addr={addr}"),
Expand All @@ -227,8 +228,8 @@ async fn invoke_auth_with_different_test_account_fail(sandbox: &TestEnv, id: &st
.await;
let e = res.unwrap_err();
assert!(
matches!(e, contract::invoke::Error::Config(_)),
"Expected config error got {e:?}"
matches!(e, contract::invoke::Error::Rpc(_)),
"Expected rpc error got {e:?}"
);
}

Expand Down
50 changes: 48 additions & 2 deletions cmd/crates/soroban-test/tests/it/integration/tx.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use soroban_sdk::xdr::{Limits, ReadXdr, TransactionEnvelope, WriteXdr};
use soroban_test::{AssertExt, TestEnv};

use crate::integration::util::{deploy_contract, DeployKind, HELLO_WORLD};
use crate::integration::util::{deploy_contract, deploy_hello, DeployKind, HELLO_WORLD};

#[tokio::test]
async fn txn_simulate() {
async fn simulate() {
let sandbox = &TestEnv::new();
let xdr_base64_build_only = deploy_contract(sandbox, HELLO_WORLD, DeployKind::BuildOnly).await;
let xdr_base64_sim_only = deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly).await;
Expand Down Expand Up @@ -49,3 +49,49 @@ async fn txn_hash() {

assert_eq!(hash.trim(), expected_hash);
}

#[tokio::test]
async fn send() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("contract")
.arg("install")
.args(["--wasm", HELLO_WORLD.path().as_os_str().to_str().unwrap()])
.assert()
.success();

let xdr_base64 = deploy_contract(sandbox, HELLO_WORLD, DeployKind::SimOnly).await;
println!("{xdr_base64}");
let tx_env = TransactionEnvelope::from_xdr_base64(&xdr_base64, Limits::none()).unwrap();
let tx_env = sign_manually(sandbox, &tx_env);

println!(
"Transaction to send:\n{}",
tx_env.to_xdr_base64(Limits::none()).unwrap()
);

let assembled_str = sandbox
.new_assert_cmd("tx")
.arg("send")
.write_stdin(tx_env.to_xdr_base64(Limits::none()).unwrap())
.assert()
.success()
.stdout_as_str();
println!("Transaction sent: {assembled_str}");
}

fn sign_manually(sandbox: &TestEnv, tx_env: &TransactionEnvelope) -> TransactionEnvelope {
TransactionEnvelope::from_xdr_base64(
sandbox
.new_assert_cmd("tx")
.arg("sign")
.arg("--sign-with-key=test")
.arg("--yes")
.write_stdin(tx_env.to_xdr_base64(Limits::none()).unwrap().as_bytes())
.assert()
.success()
.stdout_as_str(),
Limits::none(),
)
.unwrap()
}
5 changes: 3 additions & 2 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ soroban-ledger-snapshot = { workspace = true }
stellar-strkey = { workspace = true }
soroban-sdk = { workspace = true }
soroban-rpc = { workspace = true }

clap = { workspace = true, features = [
"derive",
"env",
Expand Down Expand Up @@ -113,15 +114,15 @@ async-compression = { version = "0.4.12", features = [ "tokio", "gzip" ] }
tempfile = "3.8.1"
toml_edit = "0.21.0"
rust-embed = { version = "8.2.0", features = ["debug-embed"] }
bollard = { workspace=true }
bollard = { workspace = true }
futures-util = "0.3.30"
futures = "0.3.30"
home = "0.5.9"
flate2 = "1.0.30"
bytesize = "1.3.0"
humantime = "2.1.0"
phf = { version = "0.11.2", features = ["macros"] }

crossterm = "0.27.0"
# For hyper-tls
[target.'cfg(unix)'.dependencies]
openssl = { version = "=0.10.55", features = ["vendored"] }
Expand Down
15 changes: 6 additions & 9 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@ impl NetworkRunnable for Cmd {
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
let key = config.key_pair()?;

// Get the account sequence number
let public_strkey =
stellar_strkey::ed25519::PublicKey(key.verifying_key().to_bytes()).to_string();
let public_strkey = config.source_account().await?;
// TODO: use symbols for the method names (both here and in serve)
let account_details = client.get_account(&public_strkey).await?;
let account_details = client.get_account(&public_strkey.to_string()).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);
Expand All @@ -113,7 +110,7 @@ impl NetworkRunnable for Cmd {
sequence + 1,
self.fee.fee,
network_passphrase,
&key,
&public_strkey,
)?;
if self.fee.build_only {
return Ok(TxnResult::Txn(tx));
Expand All @@ -124,7 +121,7 @@ impl NetworkRunnable for Cmd {
return Ok(TxnResult::Txn(txn));
}
let get_txn_resp = client
.send_transaction_polling(&self.config.sign_with_local_key(txn).await?)
.send_transaction_polling(&self.config.sign(txn).await?)
.await?
.try_into()?;
if args.map_or(true, |a| !a.no_cache) {
Expand All @@ -141,7 +138,7 @@ fn build_wrap_token_tx(
sequence: i64,
fee: u32,
_network_passphrase: &str,
key: &ed25519_dalek::SigningKey,
key: &stellar_strkey::ed25519::PublicKey,
) -> Result<Transaction, Error> {
let contract = ScAddress::Contract(contract_id.clone());
let mut read_write = vec![
Expand Down Expand Up @@ -180,7 +177,7 @@ fn build_wrap_token_tx(
};

Ok(Transaction {
source_account: MuxedAccount::Ed25519(Uint256(key.verifying_key().to_bytes())),
source_account: MuxedAccount::Ed25519(Uint256(key.0)),
fee,
seq_num: SequenceNumber(sequence),
cond: Preconditions::None,
Expand Down
Loading
Loading