Skip to content

Commit 29b6188

Browse files
authored
feat: update resolution of contract id to prepare for deploying to main net (#74)
1 parent 2d00190 commit 29b6188

File tree

17 files changed

+229
-223
lines changed

17 files changed

+229
-223
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ jobs:
2929
- run: sudo apt-get update && sudo apt-get install -y libudev-dev libdbus-1-dev pkg-config # required for the machine to build properly
3030
- uses: taiki-e/install-action@nextest
3131
- uses: taiki-e/install-action@just
32+
- uses: cargo-bins/cargo-binstall@main
3233
- name: Run cargo fmt
3334
run: cargo fmt --all -- --check
35+
- run: just setup
3436
- name: build since clippy needs contracts to be built
3537
run: just build
3638
- name: Run cargo clippy

Cargo.lock

Lines changed: 24 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ lto = true
3737

3838

3939
[workspace.lints.clippy]
40-
unexpected_cfgs = "allow"
40+

contracts/registry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "stellar-registry-contract"
2+
name = "registry"
33
description = "A crate for managing and deploying smart contracts on the Soroban blockchain."
44
version = "0.1.0"
55
authors = ["Aha Labs <hello@ahalabs.dev>"]

contracts/registry/src/test.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ fn default_version() -> soroban_sdk::String {
1111
to_string("0.0.0")
1212
}
1313

14-
stellar_registry::import_contract_client!(stellar_registry_contract);
14+
stellar_registry::import_contract_client!(registry);
1515
// Equivalent to:
1616

17-
// mod stellar_registry_contract {
17+
// mod registry {
1818
// use super::soroban_sdk;
19-
// soroban_sdk::contractimport!(file = "../../../../target/stellar/stellar_registry_contract.wasm");
19+
// soroban_sdk::contractimport!(file = "../../../../target/stellar/registry.wasm");
2020
// }
2121

2222
fn init() -> (SorobanContractClient<'static>, Address) {
@@ -26,11 +26,7 @@ fn init() -> (SorobanContractClient<'static>, Address) {
2626
let address = Address::generate(env);
2727
let client = SorobanContractClient::new(
2828
env,
29-
&env.register_at(
30-
&contract_id,
31-
stellar_registry_contract::WASM,
32-
(address.clone(),),
33-
),
29+
&env.register_at(&contract_id, registry::WASM, (address.clone(),)),
3430
);
3531
(client, address)
3632
}
@@ -46,16 +42,14 @@ fn handle_error_cases() {
4642
Ok(Error::NoSuchContractPublished)
4743
);
4844

49-
let wasm_hash = env
50-
.deployer()
51-
.upload_contract_wasm(stellar_registry_contract::WASM);
45+
let wasm_hash = env.deployer().upload_contract_wasm(registry::WASM);
5246

5347
assert_matches!(
5448
client.try_fetch_hash(name, &None).unwrap_err(),
5549
Ok(Error::NoSuchContractPublished)
5650
);
5751

58-
let bytes = Bytes::from_slice(env, stellar_registry_contract::WASM);
52+
let bytes = Bytes::from_slice(env, registry::WASM);
5953
env.mock_all_auths();
6054
let version = default_version();
6155
client.publish(name, address, &bytes, &version);
@@ -81,14 +75,12 @@ fn returns_most_recent_version() {
8175
let env = env();
8276
let name = &to_string("publisher");
8377
// client.register_name(address, name);
84-
let bytes = Bytes::from_slice(env, stellar_registry_contract::WASM);
78+
let bytes = Bytes::from_slice(env, registry::WASM);
8579
env.mock_all_auths();
8680
let version = default_version();
8781
client.publish(name, address, &bytes, &version);
8882
let fetched_hash = client.fetch_hash(name, &None);
89-
let wasm_hash = env
90-
.deployer()
91-
.upload_contract_wasm(stellar_registry_contract::WASM);
83+
let wasm_hash = env.deployer().upload_contract_wasm(registry::WASM);
9284
assert_eq!(fetched_hash, wasm_hash);
9385

9486
let second_hash: BytesN<32> = BytesN::random(env);
@@ -137,16 +129,21 @@ fn validate_version() {
137129
let (client, address) = &init();
138130
let env = env();
139131
let name = &to_string("registry");
140-
let bytes = Bytes::from_slice(env, stellar_registry_contract::WASM);
132+
let bytes = Bytes::from_slice(env, registry::WASM);
141133
env.mock_all_auths();
142134
let version = default_version();
143135
client.publish(name, address, &bytes, &version);
144136
assert_eq!(
145-
client.try_publish(name, address, &bytes, &to_string("0.0.0"),),
137+
client.try_publish(name, address, &bytes, &version),
146138
Err(Ok(Error::VersionMustBeGreaterThanCurrent))
147139
);
148140
assert_eq!(
149141
client.try_publish(name, address, &bytes, &to_string("0. 0.0"),),
150142
Err(Ok(Error::InvalidVersion))
151143
);
144+
client.publish(name, address, &bytes, &to_string("0.0.1"));
145+
assert_eq!(
146+
client.try_publish(name, address, &bytes, &version),
147+
Err(Ok(Error::VersionMustBeGreaterThanCurrent))
148+
);
152149
}

crates/stellar-registry-cli/src/bin/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
use clap::{CommandFactory, Parser};
22

3-
use stellar_registry_cli::{testnet, Root};
3+
use stellar_registry_cli::Root;
44

55
#[tokio::main]
66
async fn main() {
77
let _ = dotenvy::dotenv().unwrap_or_default();
8-
let contract_id = testnet::contract_id_strkey();
9-
std::env::set_var("STELLAR_CONTRACT_ID", contract_id.to_string());
10-
// std::env::set_var("SOROBAN_RPC_URL", testnet::rpc_url());
11-
// std::env::set_var("SOROBAN_NETWORK_PASSPHRASE", testnet::network_passphrase());
12-
// std::env::remove_var("SOROBAN_NETWORK");
138
let mut root = Root::try_parse().unwrap_or_else(|e| {
149
let mut cmd = Root::command();
1510
e.format(&mut cmd).exit();

crates/stellar-registry-cli/src/commands/deploy.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ use soroban_sdk::xdr::{
1010
Transaction, TransactionExt, Uint256, VecM,
1111
};
1212
use stellar_cli::{
13-
assembled::simulate_and_assemble_transaction, commands::contract::invoke, config, fee,
13+
assembled::simulate_and_assemble_transaction,
14+
commands::contract::{arg_parsing, invoke},
15+
config, fee,
1416
utils::rpc::get_remote_wasm_from_hash,
1517
};
1618

1719
use soroban_rpc as rpc;
1820
pub use soroban_spec_tools::contract as contract_spec;
1921

20-
use crate::testnet::{self, contract_address, invoke_registry};
22+
use crate::contract::NetworkContract;
2123

2224
#[derive(Parser, Debug, Clone)]
2325
pub struct Cmd {
@@ -85,18 +87,20 @@ impl Cmd {
8587
}
8688

8789
pub async fn hash(&self) -> Result<xdr::Hash, Error> {
88-
let res = invoke_registry(
89-
&["fetch_hash", "--wasm_name", &self.wasm_name],
90-
&self.config,
91-
&self.fee,
92-
)
93-
.await?;
90+
let res = self
91+
.config
92+
.invoke_registry(
93+
&["fetch_hash", "--wasm_name", &self.wasm_name],
94+
Some(&self.fee),
95+
true,
96+
)
97+
.await?;
9498
let res = res.trim_matches('"');
9599
Ok(res.parse().unwrap())
96100
}
97101

98102
pub async fn wasm(&self) -> Result<Vec<u8>, Error> {
99-
Ok(get_remote_wasm_from_hash(&testnet::client()?, &self.hash().await?).await?)
103+
Ok(get_remote_wasm_from_hash(&self.config.rpc_client()?, &self.hash().await?).await?)
100104
}
101105

102106
pub async fn spec_entries(&self) -> Result<Vec<ScSpecEntry>, Error> {
@@ -106,22 +110,22 @@ impl Cmd {
106110
}
107111

108112
async fn invoke(&self) -> Result<(), Error> {
109-
let client = testnet::client()?;
113+
let client = self.config.rpc_client()?;
110114
let key = self.config.key_pair()?;
111115
let config = &self.config;
112116

113117
// Get the account sequence number
114118
let public_strkey =
115119
stellar_strkey::ed25519::PublicKey(key.verifying_key().to_bytes()).to_string();
116120

117-
let contract_address = contract_address();
118-
let contract_id = &testnet::contract_id_strkey();
121+
let contract_address = self.config.contract_sc_address()?;
122+
let contract_id = &self.config.contract_id()?;
119123
let spec_entries = self.spec_entries().await?;
120124

121125
let (args, signers) = if self.slop.is_empty() {
122126
(ScVal::Void, vec![])
123127
} else {
124-
let res = stellar_cli::commands::contract::arg_parsing::build_host_function_parameters(
128+
let res = arg_parsing::build_host_function_parameters(
125129
contract_id,
126130
&self.slop,
127131
&spec_entries,
@@ -144,7 +148,7 @@ impl Cmd {
144148
));
145149
(args, signers)
146150
}
147-
Err(stellar_cli::commands::contract::arg_parsing::Error::HelpMessage(help)) => {
151+
Err(arg_parsing::Error::HelpMessage(help)) => {
148152
println!("{help}");
149153
return Ok(());
150154
}

crates/stellar-registry-cli/src/commands/install.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use clap::Parser;
33
use stellar_cli::{
44
commands::contract::{fetch, invoke},
55
config,
6-
fee::Args,
76
};
87
use stellar_strkey::Contract;
98

10-
use crate::testnet;
9+
use crate::contract::NetworkContract;
1110

1211
#[derive(Parser, Debug, Clone)]
1312
pub struct Cmd {
@@ -66,12 +65,7 @@ impl Cmd {
6665

6766
// Use this.config directly
6867
eprintln!("Fetching contract ID via registry...");
69-
let raw = testnet::invoke_registry(
70-
&slop,
71-
&self.config,
72-
&Args::default(), // fee::Args::default()
73-
)
74-
.await?;
68+
let raw = self.config.invoke_registry(&slop, None, true).await?;
7569

7670
let contract_id = raw.trim_matches('"').to_string();
7771
Ok(contract_id.parse()?)

0 commit comments

Comments
 (0)