Skip to content

Commit

Permalink
Merge branch 'main' into i1810
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Dec 19, 2024
2 parents 61b0e95 + 7b6c5cd commit 6f613dc
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ jobs:
repo: context.repo.repo,
release_id: ${{ github.event.release.id }},
name: '${{ env.STELLAR_CLI_INSTALLER }}',
data: fs.readFileSync('Output/stellar-installer.exe'),
data: fs.readFileSync('${{ env.STELLAR_CLI_INSTALLER }}'),
});
2 changes: 1 addition & 1 deletion .github/workflows/bindings-ts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
NETWORK: local
ENABLE_SOROBAN_RPC: true
options: >-
--health-cmd "curl --no-progress-meter --fail-with-body -X POST \"http://localhost:8000/soroban/rpc\" -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":8675309,\"method\":\"getNetwork\"}' && curl --no-progress-meter \"http://localhost:8000/friendbot\" | grep '\"invalid_field\": \"addr\"'"
--health-cmd "curl --no-progress-meter --fail-with-body -X POST \"http://localhost:8000/rpc\" -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":8675309,\"method\":\"getNetwork\"}' && curl --no-progress-meter \"http://localhost:8000/friendbot\" | grep '\"invalid_field\": \"addr\"'"
--health-interval 10s
--health-timeout 5s
--health-retries 50
Expand Down
6 changes: 3 additions & 3 deletions cmd/crates/soroban-spec-typescript/ts-tests/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
SOROBAN_RPC_URL="http://localhost:8000/soroban/rpc"
SOROBAN_FRIENDBOT_URL="http://localhost:8000/friendbot"
STELLAR_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
STELLAR_RPC_URL="http://localhost:8000/rpc"
STELLAR_FRIENDBOT_URL="http://localhost:8000/friendbot"
18 changes: 9 additions & 9 deletions cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ done
unset IFS

echo Network
echo " RPC: $SOROBAN_RPC_URL"
echo " Passphrase: \"$SOROBAN_NETWORK_PASSPHRASE\""
echo " RPC: $STELLAR_RPC_URL"
echo " Passphrase: \"$STELLAR_NETWORK_PASSPHRASE\""

NETWORK_STATUS=$(curl -s -X POST "http://localhost:8000/soroban/rpc" -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 8675309, "method": "getHealth" }' | sed 's/.*"status":"\([^"]*\)".*/\1/') || { echo "Make sure you're running local RPC network on localhost:8000" && exit 1; }
NETWORK_STATUS=$(curl -s -X POST "http://localhost:8000/rpc" -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 8675309, "method": "getHealth" }' | sed 's/.*"status":"\([^"]*\)".*/\1/') || { echo "Make sure you're running local RPC network on localhost:8000" && exit 1; }
echo " Status: $NETWORK_STATUS"

if [[ "$NETWORK_STATUS" != "healthy" ]]; then
Expand All @@ -22,28 +22,28 @@ if [[ "$NETWORK_STATUS" != "healthy" ]]; then
fi

# Print command before executing, from https://stackoverflow.com/a/23342259/249801
# Discussion: https://github.com/stellar/soroban-tools/pull/1034#pullrequestreview-1690667116
# Discussion: https://github.com/stellar/stellar-tools/pull/1034#pullrequestreview-1690667116
exe() { echo"${@/eval/}" ; "$@" ; }

function fund_all() {
exe eval "./soroban keys generate root"
exe eval "./soroban keys fund root"
exe eval "./stellar keys generate --fund root"
}
function upload() {
exe eval "(./soroban contract $1 --quiet --source root --wasm $2 --ignore-checks) > $3"
exe eval "(./stellar contract $1 --quiet --source root --wasm $2 --ignore-checks) > $3"
}
function deploy_all() {
upload deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm contract-id-custom-types.txt
# TODO: support `--wasm-hash` with `contract bindings`
upload install ../../../../target/wasm32-unknown-unknown/test-wasms/test_constructor.wasm contract-wasm-hash-constructor.txt
exe eval "./stellar contract asset deploy --asset native --source root"
}
function bind() {
exe eval "./soroban contract bindings typescript $1 $2 --output-dir ./node_modules/$3 --overwrite"
exe eval "./stellar contract bindings typescript $1 $2 --output-dir ./node_modules/$3 --overwrite"
exe eval "sh -c \"cd ./node_modules/$3 && npm install && npm run build\""
}
function bind_all() {
bind --contract-id $(cat contract-id-custom-types.txt) test-custom-types
bind --wasm-hash $(cat contract-wasm-hash-constructor.txt) test-constructor
bind --contract-id $(./stellar contract id asset --asset native) xlm
}

fund_all
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from "ava"
import { rpcUrl, root, signer } from "./util.js"
import { Client, networks } from "xlm"

const contract = new Client({
...networks.standalone,
rpcUrl,
allowHttp: true,
publicKey: root.keypair.publicKey(),
...signer,
})

test("can generate a lib from a Stellar Asset Contract", async (t) => {
t.is((await contract.symbol()).result, "native");
});
6 changes: 3 additions & 3 deletions cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Address, Keypair } from "@stellar/stellar-sdk";
import { basicNodeSigner } from "@stellar/stellar-sdk/contract";

const rootKeypair = Keypair.fromSecret(
spawnSync("./soroban", ["keys", "show", "root"], {
spawnSync("./stellar", ["keys", "show", "root"], {
shell: true,
encoding: "utf8",
}).stdout.trim(),
Expand All @@ -14,9 +14,9 @@ export const root = {
address: Address.fromString(rootKeypair.publicKey()),
};

export const rpcUrl = process.env.SOROBAN_RPC_URL ?? "http://localhost:8000/";
export const rpcUrl = process.env.STELLAR_RPC_URL ?? "http://localhost:8000/";
export const networkPassphrase =
process.env.SOROBAN_NETWORK_PASSPHRASE ??
process.env.STELLAR_NETWORK_PASSPHRASE ??
"Standalone Network ; February 2017";

export const signer = basicNodeSigner(root.keypair, networkPassphrase);
43 changes: 27 additions & 16 deletions cmd/soroban-cli/src/commands/contract/bindings/typescript.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{ffi::OsString, fmt::Debug, path::PathBuf};

use clap::{command, Parser};
use soroban_spec_tools::contract as contract_spec;
use soroban_spec_tools::contract as spec_tools;
use soroban_spec_typescript::boilerplate::Project;

use crate::print::Print;
use crate::{
commands::{contract::info::shared as wasm_or_contract, global, NetworkRunnable},
commands::{contract::info::shared as contract_spec, global, NetworkRunnable},
config,
};
use soroban_spec_tools::contract::Spec;
Expand All @@ -15,7 +15,7 @@ use soroban_spec_tools::contract::Spec;
#[group(skip)]
pub struct Cmd {
#[command(flatten)]
pub wasm_or_hash_or_contract_id: wasm_or_contract::Args,
pub wasm_or_hash_or_contract_id: contract_spec::Args,
/// Where to place generated project
#[arg(long)]
pub output_dir: PathBuf,
Expand All @@ -39,11 +39,13 @@ pub enum Error {
NotUtf8(OsString),

#[error(transparent)]
Spec(#[from] contract_spec::Error),
Spec(#[from] spec_tools::Error),
#[error("Failed to get file name from path: {0:?}")]
FailedToGetFileName(PathBuf),
#[error(transparent)]
WasmOrContract(#[from] wasm_or_contract::Error),
WasmOrContract(#[from] contract_spec::Error),
#[error(transparent)]
Xdr(#[from] crate::xdr::Error),
}

#[async_trait::async_trait]
Expand All @@ -58,13 +60,14 @@ impl NetworkRunnable for Cmd {
) -> Result<(), Error> {
let print = Print::new(global_args.is_some_and(|a| a.quiet));

let (spec, contract_address, network) =
wasm_or_contract::fetch_wasm(&self.wasm_or_hash_or_contract_id, &print).await?;
let contract_spec::Fetched { contract, source } =
contract_spec::fetch(&self.wasm_or_hash_or_contract_id, &print).await?;

let spec = if let Some(spec) = spec {
Spec::new(&spec)?
} else {
Spec::new(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?
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())?
}
};

if self.output_dir.is_file() {
Expand All @@ -86,15 +89,23 @@ impl NetworkRunnable for Cmd {
let contract_name = &file_name
.to_str()
.ok_or_else(|| Error::NotUtf8(file_name.to_os_string()))?;
if let Some(contract_address) = contract_address.clone() {
print.infoln(format!("Embedding contract address: {contract_address}"));
}
let (resolved_address, network) = match source {
contract_spec::Source::Contract {
resolved_address,
network,
} => {
print.infoln(format!("Embedding contract address: {resolved_address}"));
(Some(resolved_address), Some(network))
}
contract_spec::Source::Wasm { network, .. } => (None, Some(network)),
contract_spec::Source::File { .. } => (None, None),
};
p.init(
contract_name,
contract_address.as_deref(),
resolved_address.as_deref(),
network.as_ref().map(|n| n.rpc_url.as_ref()),
network.as_ref().map(|n| n.network_passphrase.as_ref()),
&spec.spec,
&spec,
)?;
print.checkln("Generated!");
print.infoln(format!(
Expand Down
10 changes: 5 additions & 5 deletions cmd/soroban-cli/src/commands/contract/info/env_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
commands::{
contract::info::{
env_meta::Error::{NoEnvMetaPresent, NoSACEnvMeta},
shared::{self, fetch_wasm, MetasInfoOutput},
shared::{self, fetch, Fetched, MetasInfoOutput},
},
global,
},
Expand Down Expand Up @@ -43,12 +43,12 @@ pub enum Error {
impl Cmd {
pub async fn run(&self, global_args: &global::Args) -> Result<String, Error> {
let print = Print::new(global_args.quiet);
let (bytes, ..) = fetch_wasm(&self.common, &print).await?;
let Fetched { contract, .. } = fetch(&self.common, &print).await?;

let Some(bytes) = bytes else {
return Err(NoSACEnvMeta());
let spec = match contract {
shared::Contract::Wasm { wasm_bytes } => Spec::new(&wasm_bytes)?,
shared::Contract::StellarAssetContract => return Err(NoSACEnvMeta()),
};
let spec = Spec::new(&bytes)?;

let Some(env_meta_base64) = spec.env_meta_base64 else {
return Err(NoEnvMetaPresent());
Expand Down
24 changes: 13 additions & 11 deletions cmd/soroban-cli/src/commands/contract/info/interface.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fmt::Debug;

use crate::commands::contract::info::interface::Error::NoInterfacePresent;
use crate::commands::contract::info::shared;
use crate::commands::contract::info::shared::fetch_wasm;
use crate::commands::contract::info::shared::{self, fetch, Fetched};
use crate::commands::global;
use crate::print::Print;
use clap::{command, Parser};
Expand Down Expand Up @@ -47,18 +46,21 @@ pub enum Error {
impl Cmd {
pub async fn run(&self, global_args: &global::Args) -> Result<String, Error> {
let print = Print::new(global_args.quiet);
let (bytes, ..) = fetch_wasm(&self.common, &print).await?;
let Fetched { contract, .. } = fetch(&self.common, &print).await?;

let (base64, spec) = if bytes.is_none() {
Spec::spec_to_base64(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?
} else {
let spec = Spec::new(&bytes.unwrap())?;
let (base64, spec) = match contract {
shared::Contract::Wasm { wasm_bytes } => {
let spec = Spec::new(&wasm_bytes)?;

if spec.env_meta_base64.is_none() {
return Err(NoInterfacePresent());
}
if spec.env_meta_base64.is_none() {
return Err(NoInterfacePresent());
}

(spec.spec_base64.unwrap(), spec.spec)
(spec.spec_base64.unwrap(), spec.spec)
}
shared::Contract::StellarAssetContract => {
Spec::spec_to_base64(&soroban_sdk::token::StellarAssetSpec::spec_xdr())?
}
};

let res = match self.output {
Expand Down
11 changes: 5 additions & 6 deletions cmd/soroban-cli/src/commands/contract/info/meta.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fmt::Debug;

use crate::commands::contract::info::meta::Error::{NoMetaPresent, NoSACMeta};
use crate::commands::contract::info::shared;
use crate::commands::contract::info::shared::{fetch_wasm, MetasInfoOutput};
use crate::commands::contract::info::shared::{self, fetch, Fetched, MetasInfoOutput};
use crate::commands::global;
use crate::print::Print;
use clap::{command, Parser};
Expand Down Expand Up @@ -36,12 +35,12 @@ pub enum Error {
impl Cmd {
pub async fn run(&self, global_args: &global::Args) -> Result<String, Error> {
let print = Print::new(global_args.quiet);
let (bytes, ..) = fetch_wasm(&self.common, &print).await?;
let Fetched { contract, .. } = fetch(&self.common, &print).await?;

let Some(bytes) = bytes else {
return Err(NoSACMeta());
let spec = match contract {
shared::Contract::Wasm { wasm_bytes } => Spec::new(&wasm_bytes)?,
shared::Contract::StellarAssetContract => return Err(NoSACMeta()),
};
let spec = Spec::new(&bytes)?;

let Some(meta_base64) = spec.meta_base64 else {
return Err(NoMetaPresent());
Expand Down
Loading

0 comments on commit 6f613dc

Please sign in to comment.