From 6808a3b1128eafac5f1c276e0bb55d398aea4783 Mon Sep 17 00:00:00 2001 From: tamirms Date: Tue, 5 Dec 2023 08:38:16 +0000 Subject: [PATCH 01/11] all: Bump core, Rust dependencies --- .github/workflows/soroban-rpc.yml | 2 +- Cargo.lock | 87 ++++++++++--------- Cargo.toml | 24 +++-- cmd/soroban-cli/Cargo.toml | 2 +- .../internal/test/docker-compose.yml | 2 +- go.mod | 4 +- go.sum | 4 + 7 files changed, 67 insertions(+), 58 deletions(-) diff --git a/.github/workflows/soroban-rpc.yml b/.github/workflows/soroban-rpc.yml index d590916f4..aded4ba28 100644 --- a/.github/workflows/soroban-rpc.yml +++ b/.github/workflows/soroban-rpc.yml @@ -112,7 +112,7 @@ jobs: env: SOROBAN_RPC_INTEGRATION_TESTS_ENABLED: true SOROBAN_RPC_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core - PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.14.1-1590.b6b730a0c.focal + PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 20.0.0-1615.617729910.focal steps: - uses: actions/checkout@v3 with: diff --git a/Cargo.lock b/Cargo.lock index b4d9a25bc..36817a6e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -841,16 +841,15 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.1.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f628eaec48bfd21b865dc2950cfa014450c01d2fa2b69a86c2fd5844ec523c0" +checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" dependencies = [ "curve25519-dalek 4.1.1", "ed25519 2.2.3", "rand_core 0.6.4", "serde", "sha2 0.10.8", - "subtle", "zeroize", ] @@ -895,6 +894,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "escape-bytes" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfcf67fea2815c2fc3b90873fae90957be12ff417335dfadc7f52927feb03b2" + [[package]] name = "ethnum" version = "1.5.0" @@ -1452,9 +1457,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f01b677d82ef7a676aa37e099defd83a28e15687112cafdd112d60236b6115b" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" dependencies = [ "cfg-if", "ecdsa", @@ -1936,9 +1941,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -2286,9 +2291,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.193" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" dependencies = [ "serde_derive", ] @@ -2306,9 +2311,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", @@ -2477,8 +2482,8 @@ dependencies = [ [[package]] name = "soroban-builtin-sdk-macros" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-env?rev=be04cf31e925ba5bacd9b22db7caf7b4f6dd8372#be04cf31e925ba5bacd9b22db7caf7b4f6dd8372" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-env?rev=9c5394083725bacf32a56107d7fa2adf643dc7b5#9c5394083725bacf32a56107d7fa2adf643dc7b5" dependencies = [ "itertools 0.11.0", "proc-macro2", @@ -2502,7 +2507,7 @@ dependencies = [ "csv", "dirs", "dotenvy", - "ed25519-dalek 2.1.0", + "ed25519-dalek 2.0.0", "ethnum", "heck", "hex", @@ -2551,8 +2556,8 @@ dependencies = [ [[package]] name = "soroban-env-common" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-env?rev=be04cf31e925ba5bacd9b22db7caf7b4f6dd8372#be04cf31e925ba5bacd9b22db7caf7b4f6dd8372" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-env?rev=9c5394083725bacf32a56107d7fa2adf643dc7b5#9c5394083725bacf32a56107d7fa2adf643dc7b5" dependencies = [ "arbitrary", "crate-git-revision 0.0.6", @@ -2568,8 +2573,8 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-env?rev=be04cf31e925ba5bacd9b22db7caf7b4f6dd8372#be04cf31e925ba5bacd9b22db7caf7b4f6dd8372" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-env?rev=9c5394083725bacf32a56107d7fa2adf643dc7b5#9c5394083725bacf32a56107d7fa2adf643dc7b5" dependencies = [ "soroban-env-common", "static_assertions", @@ -2577,12 +2582,12 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-env?rev=be04cf31e925ba5bacd9b22db7caf7b4f6dd8372#be04cf31e925ba5bacd9b22db7caf7b4f6dd8372" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-env?rev=9c5394083725bacf32a56107d7fa2adf643dc7b5#9c5394083725bacf32a56107d7fa2adf643dc7b5" dependencies = [ "backtrace", "curve25519-dalek 4.1.1", - "ed25519-dalek 2.1.0", + "ed25519-dalek 2.0.0", "getrandom", "hex-literal", "hmac 0.12.1", @@ -2603,8 +2608,8 @@ dependencies = [ [[package]] name = "soroban-env-macros" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-env?rev=be04cf31e925ba5bacd9b22db7caf7b4f6dd8372#be04cf31e925ba5bacd9b22db7caf7b4f6dd8372" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-env?rev=9c5394083725bacf32a56107d7fa2adf643dc7b5#9c5394083725bacf32a56107d7fa2adf643dc7b5" dependencies = [ "itertools 0.11.0", "proc-macro2", @@ -2621,8 +2626,8 @@ version = "20.0.0-rc4" [[package]] name = "soroban-ledger-snapshot" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=e35bace9de5addae7c32f405cdc11bb459cb1d61#e35bace9de5addae7c32f405cdc11bb459cb1d61" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=822ce6cc3e461ccc925275b472d77b6ca35b2cd9#822ce6cc3e461ccc925275b472d77b6ca35b2cd9" dependencies = [ "serde", "serde_json", @@ -2634,13 +2639,13 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=e35bace9de5addae7c32f405cdc11bb459cb1d61#e35bace9de5addae7c32f405cdc11bb459cb1d61" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=822ce6cc3e461ccc925275b472d77b6ca35b2cd9#822ce6cc3e461ccc925275b472d77b6ca35b2cd9" dependencies = [ "arbitrary", "bytes-lit", "ctor", - "ed25519-dalek 2.1.0", + "ed25519-dalek 2.0.0", "rand", "serde", "serde_json", @@ -2653,8 +2658,8 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=e35bace9de5addae7c32f405cdc11bb459cb1d61#e35bace9de5addae7c32f405cdc11bb459cb1d61" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=822ce6cc3e461ccc925275b472d77b6ca35b2cd9#822ce6cc3e461ccc925275b472d77b6ca35b2cd9" dependencies = [ "crate-git-revision 0.0.6", "darling", @@ -2672,8 +2677,8 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=e35bace9de5addae7c32f405cdc11bb459cb1d61#e35bace9de5addae7c32f405cdc11bb459cb1d61" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=822ce6cc3e461ccc925275b472d77b6ca35b2cd9#822ce6cc3e461ccc925275b472d77b6ca35b2cd9" dependencies = [ "base64 0.13.1", "stellar-xdr", @@ -2697,8 +2702,8 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "20.0.0-rc2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=e35bace9de5addae7c32f405cdc11bb459cb1d61#e35bace9de5addae7c32f405cdc11bb459cb1d61" +version = "20.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=822ce6cc3e461ccc925275b472d77b6ca35b2cd9#822ce6cc3e461ccc925275b472d77b6ca35b2cd9" dependencies = [ "prettyplease", "proc-macro2", @@ -2774,8 +2779,8 @@ dependencies = [ [[package]] name = "soroban-wasmi" -version = "0.31.0-soroban1" -source = "git+https://github.com/stellar/wasmi?rev=7e63b4c9e08c4163f417d118d81f7ea34789d0be#7e63b4c9e08c4163f417d118d81f7ea34789d0be" +version = "0.31.1-soroban.20.0.0" +source = "git+https://github.com/stellar/wasmi?rev=ab29800224d85ee64d4ac127bac84cdbb0276721#ab29800224d85ee64d4ac127bac84cdbb0276721" dependencies = [ "smallvec", "spin", @@ -2829,12 +2834,14 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "20.0.0-rc1" -source = "git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b#d6f8ece2c89809d5e2800b9df64ae60787ee492b" +version = "20.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9595b775539e475da4179fa46212b11e4575f526d57b13308989a8c1dd59238c" dependencies = [ "arbitrary", "base64 0.13.1", "crate-git-revision 0.0.6", + "escape-bytes", "hex", "serde", "serde_with", @@ -3443,12 +3450,12 @@ dependencies = [ [[package]] name = "wasmi_arena" version = "0.4.0" -source = "git+https://github.com/stellar/wasmi?rev=7e63b4c9e08c4163f417d118d81f7ea34789d0be#7e63b4c9e08c4163f417d118d81f7ea34789d0be" +source = "git+https://github.com/stellar/wasmi?rev=ab29800224d85ee64d4ac127bac84cdbb0276721#ab29800224d85ee64d4ac127bac84cdbb0276721" [[package]] name = "wasmi_core" version = "0.13.0" -source = "git+https://github.com/stellar/wasmi?rev=7e63b4c9e08c4163f417d118d81f7ea34789d0be#7e63b4c9e08c4163f417d118d81f7ea34789d0be" +source = "git+https://github.com/stellar/wasmi?rev=ab29800224d85ee64d4ac127bac84cdbb0276721#ab29800224d85ee64d4ac127bac84cdbb0276721" dependencies = [ "downcast-rs", "libm", diff --git a/Cargo.toml b/Cargo.toml index 934113819..8f00a3fce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,20 +14,20 @@ exclude = ["cmd/crates/soroban-test/tests/fixtures/hello"] version = "20.0.0-rc4" [workspace.dependencies.soroban-env-host] -version = "20.0.0-rc2" +version = "20.0.0" git = "https://github.com/stellar/rs-soroban-env" -rev = "be04cf31e925ba5bacd9b22db7caf7b4f6dd8372" +rev = "9c5394083725bacf32a56107d7fa2adf643dc7b5" [workspace.dependencies.soroban-spec] -version = "20.0.0-rc2" +version = "20.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "e35bace9de5addae7c32f405cdc11bb459cb1d61" +rev = "822ce6cc3e461ccc925275b472d77b6ca35b2cd9" # path = "../rs-soroban-sdk/soroban-spec" [workspace.dependencies.soroban-spec-rust] -version = "20.0.0-rc2" +version = "20.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "e35bace9de5addae7c32f405cdc11bb459cb1d61" +rev = "822ce6cc3e461ccc925275b472d77b6ca35b2cd9" # path = "../rs-soroban-sdk/soroban-spec-rust" [workspace.dependencies.soroban-spec-json] @@ -43,23 +43,21 @@ version = "20.0.0-rc4" path = "./cmd/crates/soroban-spec-tools" [workspace.dependencies.soroban-sdk] -version = "20.0.0-rc2" +version = "20.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "e35bace9de5addae7c32f405cdc11bb459cb1d61" +rev = "822ce6cc3e461ccc925275b472d77b6ca35b2cd9" [workspace.dependencies.soroban-ledger-snapshot] -version = "20.0.0-rc2" +version = "20.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "e35bace9de5addae7c32f405cdc11bb459cb1d61" +rev = "822ce6cc3e461ccc925275b472d77b6ca35b2cd9" [workspace.dependencies.soroban-cli] version = "20.0.0-rc4" path = "cmd/soroban-cli" [workspace.dependencies.stellar-xdr] -version = "20.0.0-rc1" -git = "https://github.com/stellar/rs-stellar-xdr" -rev = "d6f8ece2c89809d5e2800b9df64ae60787ee492b" +version = "20.0.0" default-features = true [workspace.dependencies] diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index f6f6c757e..5e60959e5 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -66,7 +66,7 @@ rand = "0.8.5" wasmparser = { workspace = true } sha2 = { workspace = true } csv = "1.1.6" -ed25519-dalek = "2.0.0" +ed25519-dalek = "=2.0.0" jsonrpsee-http-client = "0.20.1" jsonrpsee-core = "0.20.1" hyper = "0.14.27" diff --git a/cmd/soroban-rpc/internal/test/docker-compose.yml b/cmd/soroban-rpc/internal/test/docker-compose.yml index c214b5875..9c9a4ac5c 100644 --- a/cmd/soroban-rpc/internal/test/docker-compose.yml +++ b/cmd/soroban-rpc/internal/test/docker-compose.yml @@ -15,7 +15,7 @@ services: # Note: Please keep the image pinned to an immutable tag matching the Captive Core version. # This avoids implicit updates which break compatibility between # the Core container and captive core. - image: ${CORE_IMAGE:-stellar/unsafe-stellar-core:19.14.1-1590.b6b730a0c.focal} + image: ${CORE_IMAGE:-stellar/stellar-core:20.0.0-1615.617729910.focal} depends_on: - core-postgres restart: on-failure diff --git a/go.mod b/go.mod index eb69da288..8c5d3c31f 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 - github.com/stellar/go v0.0.0-20231114175958-eb2984b58392 + github.com/stellar/go v0.0.0-20231204183605-af6f4ebad728 github.com/stretchr/testify v1.8.4 golang.org/x/mod v0.13.0 gotest.tools/v3 v3.5.0 @@ -83,7 +83,7 @@ require ( github.com/spf13/afero v1.10.0 // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/viper v1.17.0 // indirect - github.com/stellar/go-xdr v0.0.0-20230919160922-6c7b68458206 // indirect + github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 // indirect github.com/stretchr/objx v0.5.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.14.0 // indirect diff --git a/go.sum b/go.sum index 1daea539c..e398b0172 100644 --- a/go.sum +++ b/go.sum @@ -335,8 +335,12 @@ github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI= github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= github.com/stellar/go v0.0.0-20231114175958-eb2984b58392 h1:sYxHgLDT3z6cJrWuf0O9Fbs/E2UNGh3PPoOlM8DJ2vk= github.com/stellar/go v0.0.0-20231114175958-eb2984b58392/go.mod h1:g78pyZyDFnKMJUaBIXxH7xyQ7PdDrvrJTFCxdGMMb3c= +github.com/stellar/go v0.0.0-20231204183605-af6f4ebad728 h1:lyATpWxLxhZSZIGP3MfCs+C5bVJWvX/FcvQCslknK4E= +github.com/stellar/go v0.0.0-20231204183605-af6f4ebad728/go.mod h1:3wMphjCZGi42wsrrKknendsozw7g9FVBm4YSlI1LpA4= github.com/stellar/go-xdr v0.0.0-20230919160922-6c7b68458206 h1:UFuvvpbWL8+jqO1QmKYWSVhiMp4MRiIFd8/zQlUINH0= github.com/stellar/go-xdr v0.0.0-20230919160922-6c7b68458206/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps= +github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 h1:OzCVd0SV5qE3ZcDeSFCmOWLZfEWZ3Oe8KtmSOYKEVWE= +github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= From 1e6623afee9ff34f5f42a9536168dd56341ab5f6 Mon Sep 17 00:00:00 2001 From: tamirms Date: Tue, 5 Dec 2023 10:23:11 +0000 Subject: [PATCH 02/11] fix rust errors --- cmd/crates/soroban-spec-json/src/types.rs | 44 +++++++------- cmd/crates/soroban-spec-tools/src/lib.rs | 60 +++++++++---------- cmd/crates/soroban-spec-tools/src/utils.rs | 18 +++--- .../soroban-spec-typescript/src/types.rs | 50 ++++++++-------- .../src/commands/contract/install.rs | 4 +- .../src/commands/contract/invoke.rs | 8 +-- cmd/soroban-cli/src/utils/contract_spec.rs | 18 +++--- 7 files changed, 101 insertions(+), 101 deletions(-) diff --git a/cmd/crates/soroban-spec-json/src/types.rs b/cmd/crates/soroban-spec-json/src/types.rs index 6fcc483e1..0fc75c401 100644 --- a/cmd/crates/soroban-spec-json/src/types.rs +++ b/cmd/crates/soroban-spec-json/src/types.rs @@ -15,8 +15,8 @@ pub struct StructField { impl From<&ScSpecUdtStructFieldV0> for StructField { fn from(f: &ScSpecUdtStructFieldV0) -> Self { StructField { - doc: f.doc.to_string_lossy(), - name: f.name.to_string_lossy(), + doc: f.doc.to_utf8_string_lossy(), + name: f.name.to_utf8_string_lossy(), value: (&f.type_).into(), } } @@ -33,8 +33,8 @@ pub struct FunctionInput { impl From<&ScSpecFunctionInputV0> for FunctionInput { fn from(f: &ScSpecFunctionInputV0) -> Self { FunctionInput { - doc: f.doc.to_string_lossy(), - name: f.name.to_string_lossy(), + doc: f.doc.to_utf8_string_lossy(), + name: f.name.to_utf8_string_lossy(), value: (&f.type_).into(), } } @@ -52,11 +52,11 @@ impl From<&ScSpecUdtUnionCaseV0> for UnionCase { fn from(c: &ScSpecUdtUnionCaseV0) -> Self { let (doc, name, values) = match c { ScSpecUdtUnionCaseV0::VoidV0(v) => { - (v.doc.to_string_lossy(), v.name.to_string_lossy(), vec![]) + (v.doc.to_utf8_string_lossy(), v.name.to_utf8_string_lossy(), vec![]) } ScSpecUdtUnionCaseV0::TupleV0(t) => ( - t.doc.to_string_lossy(), - t.name.to_string_lossy(), + t.doc.to_utf8_string_lossy(), + t.name.to_utf8_string_lossy(), t.type_.iter().map(Type::from).collect(), ), }; @@ -75,8 +75,8 @@ pub struct EnumCase { impl From<&ScSpecUdtEnumCaseV0> for EnumCase { fn from(c: &ScSpecUdtEnumCaseV0) -> Self { EnumCase { - doc: c.doc.to_string_lossy(), - name: c.name.to_string_lossy(), + doc: c.doc.to_utf8_string_lossy(), + name: c.name.to_utf8_string_lossy(), value: c.value, } } @@ -93,8 +93,8 @@ pub struct ErrorEnumCase { impl From<&ScSpecUdtErrorEnumCaseV0> for EnumCase { fn from(c: &ScSpecUdtErrorEnumCaseV0) -> Self { EnumCase { - doc: c.doc.to_string_lossy(), - name: c.name.to_string_lossy(), + doc: c.doc.to_utf8_string_lossy(), + name: c.name.to_utf8_string_lossy(), value: c.value, } } @@ -184,7 +184,7 @@ impl From<&ScSpecTypeDef> for Type { element: Box::new(Type::from(vec.element_type.as_ref())), }, ScSpecTypeDef::Udt(udt) => Type::Custom { - name: udt.name.to_string_lossy(), + name: udt.name.to_utf8_string_lossy(), }, ScSpecTypeDef::BytesN(b) => Type::BytesN { n: b.n }, ScSpecTypeDef::Val => Type::Val, @@ -213,29 +213,29 @@ impl From<&ScSpecEntry> for Entry { fn from(spec: &ScSpecEntry) -> Self { match spec { ScSpecEntry::FunctionV0(f) => Entry::Function { - doc: f.doc.to_string_lossy(), - name: f.name.to_string_lossy(), + doc: f.doc.to_utf8_string_lossy(), + name: f.name.to_utf8_string_lossy(), inputs: f.inputs.iter().map(FunctionInput::from).collect(), outputs: f.outputs.iter().map(Type::from).collect(), }, ScSpecEntry::UdtStructV0(s) => Entry::Struct { - doc: s.doc.to_string_lossy(), - name: s.name.to_string_lossy(), + doc: s.doc.to_utf8_string_lossy(), + name: s.name.to_utf8_string_lossy(), fields: s.fields.iter().map(StructField::from).collect(), }, ScSpecEntry::UdtUnionV0(u) => Entry::Union { - doc: u.doc.to_string_lossy(), - name: u.name.to_string_lossy(), + doc: u.doc.to_utf8_string_lossy(), + name: u.name.to_utf8_string_lossy(), cases: u.cases.iter().map(UnionCase::from).collect(), }, ScSpecEntry::UdtEnumV0(e) => Entry::Enum { - doc: e.doc.to_string_lossy(), - name: e.name.to_string_lossy(), + doc: e.doc.to_utf8_string_lossy(), + name: e.name.to_utf8_string_lossy(), cases: e.cases.iter().map(EnumCase::from).collect(), }, ScSpecEntry::UdtErrorEnumV0(e) => Entry::Enum { - doc: e.doc.to_string_lossy(), - name: e.name.to_string_lossy(), + doc: e.doc.to_utf8_string_lossy(), + name: e.name.to_utf8_string_lossy(), cases: e.cases.iter().map(EnumCase::from).collect(), }, } diff --git a/cmd/crates/soroban-spec-tools/src/lib.rs b/cmd/crates/soroban-spec-tools/src/lib.rs index a95bc9454..69571ab3c 100644 --- a/cmd/crates/soroban-spec-tools/src/lib.rs +++ b/cmd/crates/soroban-spec-tools/src/lib.rs @@ -124,7 +124,7 @@ impl Spec { ), ScType::Option(type_) => return self.doc(name, &type_.value_type), ScType::Udt(ScSpecTypeUdt { name }) => { - let spec_type = self.find(&name.to_string_lossy())?; + let spec_type = self.find(&name.to_utf8_string_lossy())?; match spec_type { ScSpecEntry::FunctionV0(ScSpecFunctionV0 { doc, .. }) | ScSpecEntry::UdtStructV0(ScSpecUdtStructV0 { doc, .. }) @@ -132,7 +132,7 @@ impl Spec { | ScSpecEntry::UdtEnumV0(ScSpecUdtEnumV0 { doc, .. }) | ScSpecEntry::UdtErrorEnumV0(ScSpecUdtErrorEnumV0 { doc, .. }) => doc, } - .to_string_lossy() + .to_utf8_string_lossy() } }; if let Some(mut ex) = self.example(type_) { @@ -164,11 +164,11 @@ impl Spec { .and_then(|specs| { specs.iter().find(|e| { let entry_name = match e { - ScSpecEntry::FunctionV0(x) => x.name.to_string_lossy(), - ScSpecEntry::UdtStructV0(x) => x.name.to_string_lossy(), - ScSpecEntry::UdtUnionV0(x) => x.name.to_string_lossy(), - ScSpecEntry::UdtEnumV0(x) => x.name.to_string_lossy(), - ScSpecEntry::UdtErrorEnumV0(x) => x.name.to_string_lossy(), + ScSpecEntry::FunctionV0(x) => x.name.to_utf8_string_lossy(), + ScSpecEntry::UdtStructV0(x) => x.name.to_utf8_string_lossy(), + ScSpecEntry::UdtUnionV0(x) => x.name.to_utf8_string_lossy(), + ScSpecEntry::UdtEnumV0(x) => x.name.to_utf8_string_lossy(), + ScSpecEntry::UdtErrorEnumV0(x) => x.name.to_utf8_string_lossy(), }; name == entry_name }) @@ -248,7 +248,7 @@ impl Spec { | ScType::Address => Ok(Value::String(s.to_owned())), ScType::Udt(ScSpecTypeUdt { name }) if matches!( - self.find(&name.to_string_lossy())?, + self.find(&name.to_utf8_string_lossy())?, ScSpecEntry::UdtUnionV0(_) | ScSpecEntry::UdtStructV0(_) ) => { @@ -321,13 +321,13 @@ impl Spec { } fn parse_udt(&self, name: &StringM<60>, value: &Value) -> Result { - let name = &name.to_string_lossy(); + let name = &name.to_utf8_string_lossy(); match (self.find(name)?, value) { (ScSpecEntry::UdtStructV0(strukt), Value::Object(map)) => { if strukt .fields .iter() - .any(|f| f.name.to_string_lossy() == "0") + .any(|f| f.name.to_utf8_string_lossy() == "0") { self.parse_tuple_strukt( strukt, @@ -379,7 +379,7 @@ impl Spec { .to_vec() .iter() .map(|f| { - let name = &f.name.to_string_lossy(); + let name = &f.name.to_utf8_string_lossy(); let v = map .get(name) .ok_or_else(|| Error::MissingKey(name.clone()))?; @@ -422,9 +422,9 @@ impl Spec { ScSpecUdtUnionCaseV0::VoidV0(v) => &v.name, ScSpecUdtUnionCaseV0::TupleV0(v) => &v.name, }; - enum_case == &name.to_string_lossy() + enum_case == &name.to_utf8_string_lossy() }) - .ok_or_else(|| Error::EnumCase(enum_case.to_string(), union.name.to_string_lossy()))?; + .ok_or_else(|| Error::EnumCase(enum_case.to_string(), union.name.to_utf8_string_lossy()))?; let mut res = vec![ScVal::Symbol(ScSymbol( enum_case.try_into().map_err(Error::Xdr)?, @@ -583,7 +583,7 @@ impl Spec { /// /// May panic pub fn udt_to_json(&self, name: &StringM<60>, sc_obj: &ScVal) -> Result { - let name = &name.to_string_lossy(); + let name = &name.to_utf8_string_lossy(); let udt = self.find(name)?; Ok(match (sc_obj, udt) { (ScVal::Map(Some(map)), ScSpecEntry::UdtStructV0(strukt)) => serde_json::Value::Object( @@ -593,7 +593,7 @@ impl Spec { .zip(map.iter()) .map(|(field, entry)| { let val = self.xdr_to_json(&entry.val, &field.type_)?; - Ok((field.name.to_string_lossy(), val)) + Ok((field.name.to_utf8_string_lossy(), val)) }) .collect::, Error>>()?, ), @@ -611,7 +611,7 @@ impl Spec { let (first, rest) = match v.split_at(1) { ([first], []) => (first, None), ([first], rest) => (first, Some(rest)), - _ => return Err(Error::IllFormedEnum(union.name.to_string_lossy())), + _ => return Err(Error::IllFormedEnum(union.name.to_utf8_string_lossy())), }; let ScVal::Symbol(case_name) = first else { @@ -627,14 +627,14 @@ impl Spec { }; name.as_vec() == case_name.as_vec() }) - .ok_or_else(|| Error::FailedToFindEnumCase(case_name.to_string_lossy()))?; + .ok_or_else(|| Error::FailedToFindEnumCase(case_name.to_utf8_string_lossy()))?; - let case_name = case_name.to_string_lossy(); + let case_name = case_name.to_utf8_string_lossy(); match case { ScSpecUdtUnionCaseV0::TupleV0(v) => { let rest = rest.ok_or_else(|| { Error::EnumMissingSecondValue( - union.name.to_string_lossy(), + union.name.to_utf8_string_lossy(), case_name.clone(), ) })?; @@ -1130,11 +1130,11 @@ impl Spec { } ScType::BytesN(t) => Some(format!("{}_hex_bytes", t.n)), ScType::Udt(ScSpecTypeUdt { name }) => { - match self.find(&name.to_string_lossy()).ok()? { + match self.find(&name.to_utf8_string_lossy()).ok()? { ScSpecEntry::UdtStructV0(ScSpecUdtStructV0 { fields, .. }) if fields .get(0) - .map(|f| f.name.to_string_lossy() == "0") + .map(|f| f.name.to_utf8_string_lossy() == "0") .unwrap_or_default() => { let fields = fields @@ -1159,7 +1159,7 @@ impl Spec { let inner = strukt .fields .iter() - .map(|f| (f.name.to_string_lossy(), &f.type_)) + .map(|f| (f.name.to_utf8_string_lossy(), &f.type_)) .map(|(name, type_)| { let type_ = self.arg_value_name(type_, depth + 1)?; Some(format!("{name}: {type_}")) @@ -1176,7 +1176,7 @@ impl Spec { .map(|f| { Some(match f { ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 { name, .. }) => { - name.to_string_lossy() + name.to_utf8_string_lossy() } ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 { name, @@ -1184,7 +1184,7 @@ impl Spec { .. }) => format!( "{}({})", - name.to_string_lossy(), + name.to_utf8_string_lossy(), type_ .iter() .map(|type_| self.arg_value_name(type_, depth + 1)) @@ -1283,7 +1283,7 @@ impl Spec { Some(format!("\"{res}\"")) } ScType::Udt(ScSpecTypeUdt { name }) => { - self.example_udts(name.to_string_lossy().as_ref()) + self.example_udts(name.to_utf8_string_lossy().as_ref()) } // No specific value name for these yet. ScType::Val => None, @@ -1294,7 +1294,7 @@ impl Spec { match self.find(name).ok() { Some(ScSpecEntry::UdtStructV0(strukt)) => { // Check if a tuple strukt - if !strukt.fields.is_empty() && strukt.fields[0].name.to_string_lossy() == "0" { + if !strukt.fields.is_empty() && strukt.fields[0].name.to_utf8_string_lossy() == "0" { let value_types = strukt .fields .iter() @@ -1307,7 +1307,7 @@ impl Spec { let inner = strukt .fields .iter() - .map(|f| (f.name.to_string_lossy(), &f.type_)) + .map(|f| (f.name.to_utf8_string_lossy(), &f.type_)) .map(|(name, type_)| { let type_ = self.example(type_)?; let name = format!(r#""{name}""#); @@ -1331,21 +1331,21 @@ impl Spec { .iter() .map(|case| match case { ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 { name, .. }) => { - Some(format!("\"{}\"", name.to_string_lossy())) + Some(format!("\"{}\"", name.to_utf8_string_lossy())) } ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 { name, type_, .. }) => { if type_.len() == 1 { let single = self.example(&type_[0])?; - Some(format!("{{\"{}\":{single}}}", name.to_string_lossy())) + Some(format!("{{\"{}\":{single}}}", name.to_utf8_string_lossy())) } else { let names = type_ .iter() .map(|t| self.example(t)) .collect::>>()? .join(", "); - Some(format!("{{\"{}\":[{names}]}}", name.to_string_lossy())) + Some(format!("{{\"{}\":[{names}]}}", name.to_utf8_string_lossy())) } } }) diff --git a/cmd/crates/soroban-spec-tools/src/utils.rs b/cmd/crates/soroban-spec-tools/src/utils.rs index d0780d3e2..504bc428e 100644 --- a/cmd/crates/soroban-spec-tools/src/utils.rs +++ b/cmd/crates/soroban-spec-tools/src/utils.rs @@ -146,12 +146,12 @@ impl Display for ContractSpec { } fn write_func(f: &mut std::fmt::Formatter<'_>, func: &ScSpecFunctionV0) -> std::fmt::Result { - writeln!(f, " • Function: {}", func.name.to_string_lossy())?; + writeln!(f, " • Function: {}", func.name.to_utf8_string_lossy())?; if func.doc.len() > 0 { writeln!( f, " Docs: {}", - &indent(&func.doc.to_string_lossy(), 11).trim() + &indent(&func.doc.to_utf8_string_lossy(), 11).trim() )?; } writeln!( @@ -174,7 +174,7 @@ fn write_union(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtUnionV0) -> std:: writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Cases:")?; @@ -191,7 +191,7 @@ fn write_struct(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtStructV0) -> std writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Fields:")?; @@ -199,7 +199,7 @@ fn write_struct(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtStructV0) -> std writeln!( f, " • {}: {}", - field.name.to_string_lossy(), + field.name.to_utf8_string_lossy(), indent(&format!("{:#?}", field.type_), 8).trim() )?; if field.doc.len() > 0 { @@ -216,7 +216,7 @@ fn write_enum(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtEnumV0) -> std::fm writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Cases:")?; @@ -233,7 +233,7 @@ fn write_error(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtErrorEnumV0) -> s writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Cases:")?; @@ -254,9 +254,9 @@ fn indent(s: &str, n: usize) -> String { fn format_name(lib: &StringM<80>, name: &StringM<60>) -> String { if lib.len() > 0 { - format!("{}::{}", lib.to_string_lossy(), name.to_string_lossy()) + format!("{}::{}", lib.to_utf8_string_lossy(), name.to_utf8_string_lossy()) } else { - name.to_string_lossy() + name.to_utf8_string_lossy() } } diff --git a/cmd/crates/soroban-spec-typescript/src/types.rs b/cmd/crates/soroban-spec-typescript/src/types.rs index 350d41296..11f5b83c9 100644 --- a/cmd/crates/soroban-spec-typescript/src/types.rs +++ b/cmd/crates/soroban-spec-typescript/src/types.rs @@ -15,8 +15,8 @@ pub struct StructField { impl From<&ScSpecUdtStructFieldV0> for StructField { fn from(f: &ScSpecUdtStructFieldV0) -> Self { StructField { - doc: f.doc.to_string_lossy(), - name: f.name.to_string_lossy(), + doc: f.doc.to_utf8_string_lossy(), + name: f.name.to_utf8_string_lossy(), value: (&f.type_).into(), } } @@ -33,8 +33,8 @@ pub struct FunctionInput { impl From<&ScSpecFunctionInputV0> for FunctionInput { fn from(f: &ScSpecFunctionInputV0) -> Self { FunctionInput { - doc: f.doc.to_string_lossy(), - name: f.name.to_string_lossy(), + doc: f.doc.to_utf8_string_lossy(), + name: f.name.to_utf8_string_lossy(), value: (&f.type_).into(), } } @@ -52,11 +52,11 @@ impl From<&ScSpecUdtUnionCaseV0> for UnionCase { fn from(c: &ScSpecUdtUnionCaseV0) -> Self { let (doc, name, values) = match c { ScSpecUdtUnionCaseV0::VoidV0(v) => { - (v.doc.to_string_lossy(), v.name.to_string_lossy(), vec![]) + (v.doc.to_utf8_string_lossy(), v.name.to_utf8_string_lossy(), vec![]) } ScSpecUdtUnionCaseV0::TupleV0(t) => ( - t.doc.to_string_lossy(), - t.name.to_string_lossy(), + t.doc.to_utf8_string_lossy(), + t.name.to_utf8_string_lossy(), t.type_.iter().map(Type::from).collect(), ), }; @@ -75,8 +75,8 @@ pub struct EnumCase { impl From<&ScSpecUdtEnumCaseV0> for EnumCase { fn from(c: &ScSpecUdtEnumCaseV0) -> Self { EnumCase { - doc: c.doc.to_string_lossy(), - name: c.name.to_string_lossy(), + doc: c.doc.to_utf8_string_lossy(), + name: c.name.to_utf8_string_lossy(), value: c.value, } } @@ -93,8 +93,8 @@ pub struct ErrorEnumCase { impl From<&ScSpecUdtErrorEnumCaseV0> for ErrorEnumCase { fn from(c: &ScSpecUdtErrorEnumCaseV0) -> Self { ErrorEnumCase { - doc: c.doc.to_string_lossy(), - name: c.name.to_string_lossy(), + doc: c.doc.to_utf8_string_lossy(), + name: c.name.to_utf8_string_lossy(), value: c.value, } } @@ -189,7 +189,7 @@ impl From<&ScSpecTypeDef> for Type { element: Box::new(Type::from(vec.element_type.as_ref())), }, ScSpecTypeDef::Udt(udt) => Type::Custom { - name: udt.name.to_string_lossy(), + name: udt.name.to_utf8_string_lossy(), }, ScSpecTypeDef::BytesN(b) => Type::BytesN { n: b.n }, ScSpecTypeDef::Val => Type::Val, @@ -218,34 +218,34 @@ impl From<&ScSpecEntry> for Entry { fn from(spec: &ScSpecEntry) -> Self { match spec { ScSpecEntry::FunctionV0(f) => Entry::Function { - doc: f.doc.to_string_lossy(), - name: f.name.to_string_lossy(), + doc: f.doc.to_utf8_string_lossy(), + name: f.name.to_utf8_string_lossy(), inputs: f.inputs.iter().map(Into::into).collect(), outputs: f.outputs.iter().map(Into::into).collect(), }, ScSpecEntry::UdtStructV0(s) if is_tuple_strukt(s) => Entry::TupleStruct { - doc: s.doc.to_string_lossy(), - name: s.name.to_string_lossy(), + doc: s.doc.to_utf8_string_lossy(), + name: s.name.to_utf8_string_lossy(), fields: s.fields.iter().map(|f| &f.type_).map(Into::into).collect(), }, ScSpecEntry::UdtStructV0(s) => Entry::Struct { - doc: s.doc.to_string_lossy(), - name: s.name.to_string_lossy(), + doc: s.doc.to_utf8_string_lossy(), + name: s.name.to_utf8_string_lossy(), fields: s.fields.iter().map(Into::into).collect(), }, ScSpecEntry::UdtUnionV0(u) => Entry::Union { - doc: u.doc.to_string_lossy(), - name: u.name.to_string_lossy(), + doc: u.doc.to_utf8_string_lossy(), + name: u.name.to_utf8_string_lossy(), cases: u.cases.iter().map(Into::into).collect(), }, ScSpecEntry::UdtEnumV0(e) => Entry::Enum { - doc: e.doc.to_string_lossy(), - name: e.name.to_string_lossy(), + doc: e.doc.to_utf8_string_lossy(), + name: e.name.to_utf8_string_lossy(), cases: e.cases.iter().map(Into::into).collect(), }, ScSpecEntry::UdtErrorEnumV0(e) => Entry::ErrorEnum { - doc: e.doc.to_string_lossy(), - name: e.name.to_string_lossy(), + doc: e.doc.to_utf8_string_lossy(), + name: e.name.to_utf8_string_lossy(), cases: e.cases.iter().map(Into::into).collect(), }, } @@ -253,5 +253,5 @@ impl From<&ScSpecEntry> for Entry { } fn is_tuple_strukt(s: &ScSpecUdtStructV0) -> bool { - !s.fields.is_empty() && s.fields[0].name.to_string_lossy() == "0" + !s.fields.is_empty() && s.fields[0].name.to_utf8_string_lossy() == "0" } diff --git a/cmd/soroban-cli/src/commands/contract/install.rs b/cmd/soroban-cli/src/commands/contract/install.rs index ea5719140..d2f307103 100644 --- a/cmd/soroban-cli/src/commands/contract/install.rs +++ b/cmd/soroban-cli/src/commands/contract/install.rs @@ -150,7 +150,7 @@ fn get_contract_meta_sdk_version(wasm_spec: &utils::contract_spec::ContractSpec) let rs_sdk_version_option = if let Some(_meta) = &wasm_spec.meta_base64 { wasm_spec.meta.iter().find(|entry| match entry { ScMetaEntry::ScMetaV0(ScMetaV0 { key, .. }) => { - key.to_string_lossy().contains(CONTRACT_META_SDK_KEY) + key.to_utf8_string_lossy().contains(CONTRACT_META_SDK_KEY) } }) } else { @@ -159,7 +159,7 @@ fn get_contract_meta_sdk_version(wasm_spec: &utils::contract_spec::ContractSpec) if let Some(rs_sdk_version_entry) = &rs_sdk_version_option { match rs_sdk_version_entry { ScMetaEntry::ScMetaV0(ScMetaV0 { val, .. }) => { - return Some(val.to_string_lossy()); + return Some(val.to_utf8_string_lossy()); } } } diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index 2d4c77c61..78be7b381 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -164,7 +164,7 @@ impl Cmd { .max_term_width(300); for ScSpecFunctionV0 { name, .. } in spec.find_functions()? { - cmd = cmd.subcommand(build_custom_cmd(&name.to_string_lossy(), &spec)?); + cmd = cmd.subcommand(build_custom_cmd(&name.to_utf8_string_lossy(), &spec)?); } cmd.build(); let long_help = cmd.render_long_help(); @@ -181,7 +181,7 @@ impl Cmd { .inputs .iter() .map(|i| { - let name = i.name.to_string()?; + let name = i.name.to_utf8_string()?; if let Some(mut val) = matches_.get_raw(&name) { let mut s = val.next().unwrap().to_string_lossy().to_string(); if matches!(i.type_, ScSpecTypeDef::Address) { @@ -410,7 +410,7 @@ fn build_custom_cmd(name: &str, spec: &Spec) -> Result { let inputs_map = &func .inputs .iter() - .map(|i| (i.name.to_string().unwrap(), i.type_.clone())) + .map(|i| (i.name.to_utf8_string().unwrap(), i.type_.clone())) .collect::>(); let name: &'static str = Box::leak(name.to_string().into_boxed_str()); let mut cmd = clap::Command::new(name) @@ -421,7 +421,7 @@ fn build_custom_cmd(name: &str, spec: &Spec) -> Result { if kebab_name != name { cmd = cmd.alias(kebab_name); } - let doc: &'static str = Box::leak(func.doc.to_string_lossy().into_boxed_str()); + let doc: &'static str = Box::leak(func.doc.to_utf8_string_lossy().into_boxed_str()); let long_doc: &'static str = Box::leak(arg_file_help(doc).into_boxed_str()); cmd = cmd.about(Some(doc)).long_about(long_doc); diff --git a/cmd/soroban-cli/src/utils/contract_spec.rs b/cmd/soroban-cli/src/utils/contract_spec.rs index 6d34e2a63..27f4d1e61 100644 --- a/cmd/soroban-cli/src/utils/contract_spec.rs +++ b/cmd/soroban-cli/src/utils/contract_spec.rs @@ -157,12 +157,12 @@ impl Display for ContractSpec { } fn write_func(f: &mut std::fmt::Formatter<'_>, func: &ScSpecFunctionV0) -> std::fmt::Result { - writeln!(f, " • Function: {}", func.name.to_string_lossy())?; + writeln!(f, " • Function: {}", func.name.to_utf8_string_lossy())?; if func.doc.len() > 0 { writeln!( f, " Docs: {}", - &indent(&func.doc.to_string_lossy(), 11).trim() + &indent(&func.doc.to_utf8_string_lossy(), 11).trim() )?; } writeln!( @@ -185,7 +185,7 @@ fn write_union(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtUnionV0) -> std:: writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Cases:")?; @@ -202,7 +202,7 @@ fn write_struct(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtStructV0) -> std writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Fields:")?; @@ -210,7 +210,7 @@ fn write_struct(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtStructV0) -> std writeln!( f, " • {}: {}", - field.name.to_string_lossy(), + field.name.to_utf8_string_lossy(), indent(&format!("{:#?}", field.type_), 8).trim() )?; if field.doc.len() > 0 { @@ -227,7 +227,7 @@ fn write_enum(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtEnumV0) -> std::fm writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Cases:")?; @@ -244,7 +244,7 @@ fn write_error(f: &mut std::fmt::Formatter<'_>, udt: &ScSpecUdtErrorEnumV0) -> s writeln!( f, " Docs: {}", - indent(&udt.doc.to_string_lossy(), 10).trim() + indent(&udt.doc.to_utf8_string_lossy(), 10).trim() )?; } writeln!(f, " Cases:")?; @@ -265,8 +265,8 @@ fn indent(s: &str, n: usize) -> String { fn format_name(lib: &StringM<80>, name: &StringM<60>) -> String { if lib.len() > 0 { - format!("{}::{}", lib.to_string_lossy(), name.to_string_lossy()) + format!("{}::{}", lib.to_utf8_string_lossy(), name.to_utf8_string_lossy()) } else { - name.to_string_lossy() + name.to_utf8_string_lossy() } } From 887556a72a6283ebe989dd2dafcd87dc5dbeb36a Mon Sep 17 00:00:00 2001 From: tamirms Date: Tue, 5 Dec 2023 10:24:59 +0000 Subject: [PATCH 03/11] run cargo fmt --all --- cmd/crates/soroban-spec-json/src/types.rs | 8 +++++--- cmd/crates/soroban-spec-tools/src/lib.rs | 7 +++++-- cmd/crates/soroban-spec-tools/src/utils.rs | 6 +++++- cmd/crates/soroban-spec-typescript/src/types.rs | 8 +++++--- cmd/soroban-cli/src/utils/contract_spec.rs | 6 +++++- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cmd/crates/soroban-spec-json/src/types.rs b/cmd/crates/soroban-spec-json/src/types.rs index 0fc75c401..8e3b2177e 100644 --- a/cmd/crates/soroban-spec-json/src/types.rs +++ b/cmd/crates/soroban-spec-json/src/types.rs @@ -51,9 +51,11 @@ pub struct UnionCase { impl From<&ScSpecUdtUnionCaseV0> for UnionCase { fn from(c: &ScSpecUdtUnionCaseV0) -> Self { let (doc, name, values) = match c { - ScSpecUdtUnionCaseV0::VoidV0(v) => { - (v.doc.to_utf8_string_lossy(), v.name.to_utf8_string_lossy(), vec![]) - } + ScSpecUdtUnionCaseV0::VoidV0(v) => ( + v.doc.to_utf8_string_lossy(), + v.name.to_utf8_string_lossy(), + vec![], + ), ScSpecUdtUnionCaseV0::TupleV0(t) => ( t.doc.to_utf8_string_lossy(), t.name.to_utf8_string_lossy(), diff --git a/cmd/crates/soroban-spec-tools/src/lib.rs b/cmd/crates/soroban-spec-tools/src/lib.rs index 69571ab3c..e7b72d1b0 100644 --- a/cmd/crates/soroban-spec-tools/src/lib.rs +++ b/cmd/crates/soroban-spec-tools/src/lib.rs @@ -424,7 +424,9 @@ impl Spec { }; enum_case == &name.to_utf8_string_lossy() }) - .ok_or_else(|| Error::EnumCase(enum_case.to_string(), union.name.to_utf8_string_lossy()))?; + .ok_or_else(|| { + Error::EnumCase(enum_case.to_string(), union.name.to_utf8_string_lossy()) + })?; let mut res = vec![ScVal::Symbol(ScSymbol( enum_case.try_into().map_err(Error::Xdr)?, @@ -1294,7 +1296,8 @@ impl Spec { match self.find(name).ok() { Some(ScSpecEntry::UdtStructV0(strukt)) => { // Check if a tuple strukt - if !strukt.fields.is_empty() && strukt.fields[0].name.to_utf8_string_lossy() == "0" { + if !strukt.fields.is_empty() && strukt.fields[0].name.to_utf8_string_lossy() == "0" + { let value_types = strukt .fields .iter() diff --git a/cmd/crates/soroban-spec-tools/src/utils.rs b/cmd/crates/soroban-spec-tools/src/utils.rs index 504bc428e..66b153a11 100644 --- a/cmd/crates/soroban-spec-tools/src/utils.rs +++ b/cmd/crates/soroban-spec-tools/src/utils.rs @@ -254,7 +254,11 @@ fn indent(s: &str, n: usize) -> String { fn format_name(lib: &StringM<80>, name: &StringM<60>) -> String { if lib.len() > 0 { - format!("{}::{}", lib.to_utf8_string_lossy(), name.to_utf8_string_lossy()) + format!( + "{}::{}", + lib.to_utf8_string_lossy(), + name.to_utf8_string_lossy() + ) } else { name.to_utf8_string_lossy() } diff --git a/cmd/crates/soroban-spec-typescript/src/types.rs b/cmd/crates/soroban-spec-typescript/src/types.rs index 11f5b83c9..025118431 100644 --- a/cmd/crates/soroban-spec-typescript/src/types.rs +++ b/cmd/crates/soroban-spec-typescript/src/types.rs @@ -51,9 +51,11 @@ pub struct UnionCase { impl From<&ScSpecUdtUnionCaseV0> for UnionCase { fn from(c: &ScSpecUdtUnionCaseV0) -> Self { let (doc, name, values) = match c { - ScSpecUdtUnionCaseV0::VoidV0(v) => { - (v.doc.to_utf8_string_lossy(), v.name.to_utf8_string_lossy(), vec![]) - } + ScSpecUdtUnionCaseV0::VoidV0(v) => ( + v.doc.to_utf8_string_lossy(), + v.name.to_utf8_string_lossy(), + vec![], + ), ScSpecUdtUnionCaseV0::TupleV0(t) => ( t.doc.to_utf8_string_lossy(), t.name.to_utf8_string_lossy(), diff --git a/cmd/soroban-cli/src/utils/contract_spec.rs b/cmd/soroban-cli/src/utils/contract_spec.rs index 27f4d1e61..b4f24abec 100644 --- a/cmd/soroban-cli/src/utils/contract_spec.rs +++ b/cmd/soroban-cli/src/utils/contract_spec.rs @@ -265,7 +265,11 @@ fn indent(s: &str, n: usize) -> String { fn format_name(lib: &StringM<80>, name: &StringM<60>) -> String { if lib.len() > 0 { - format!("{}::{}", lib.to_utf8_string_lossy(), name.to_utf8_string_lossy()) + format!( + "{}::{}", + lib.to_utf8_string_lossy(), + name.to_utf8_string_lossy() + ) } else { name.to_utf8_string_lossy() } From 3c22cc4599fe8841d6a5ce8a0c515286419f92c9 Mon Sep 17 00:00:00 2001 From: tamirms Date: Tue, 5 Dec 2023 21:05:55 +0000 Subject: [PATCH 04/11] add huge fudge factor to get tests to pass --- cmd/soroban-rpc/internal/preflight/preflight_test.go | 2 +- cmd/soroban-rpc/lib/preflight/src/fees.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/soroban-rpc/internal/preflight/preflight_test.go b/cmd/soroban-rpc/internal/preflight/preflight_test.go index 1dca591b4..57a2e82b0 100644 --- a/cmd/soroban-rpc/internal/preflight/preflight_test.go +++ b/cmd/soroban-rpc/internal/preflight/preflight_test.go @@ -21,7 +21,7 @@ var mockContractHash = xdr.Hash{0xd, 0xe, 0xf} var contractCostParams = func() *xdr.ContractCostParams { var result xdr.ContractCostParams - for i := 0; i < 22; i++ { + for i := 0; i < 23; i++ { result = append(result, xdr.ContractCostParamEntry{ Ext: xdr.ExtensionPoint{}, ConstTerm: 0, diff --git a/cmd/soroban-rpc/lib/preflight/src/fees.rs b/cmd/soroban-rpc/lib/preflight/src/fees.rs index 6d6124f7a..fe4c5f2fb 100644 --- a/cmd/soroban-rpc/lib/preflight/src/fees.rs +++ b/cmd/soroban-rpc/lib/preflight/src/fees.rs @@ -138,11 +138,11 @@ fn calculate_host_function_soroban_resources( .map(|c| c.encoded_new_value.as_ref().map_or(0, Vec::len) as u32) .sum(); - // Add a 20% leeway with a minimum of 50k instructions + // Add a 20% leeway with a minimum of 800k instructions let budget_instructions = budget .get_cpu_insns_consumed() .context("cannot get instructions consumed")?; - let instructions = max(budget_instructions + 50000, budget_instructions * 120 / 100); + let instructions = max(budget_instructions + 800000, budget_instructions * 120 / 100); Ok(SorobanResources { footprint: ledger_footprint, instructions: u32::try_from(instructions)?, From 6176d3146b0b931e7b17be1a1cbf2e4ae9a74dc0 Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 6 Dec 2023 09:50:15 +0000 Subject: [PATCH 05/11] fix integration tests --- cmd/soroban-rpc/internal/test/simulate_transaction_test.go | 6 +++--- cmd/soroban-rpc/lib/preflight/src/fees.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go index 08f934a14..22a88487e 100644 --- a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go +++ b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go @@ -232,11 +232,11 @@ func TestSimulateTransactionSucceeds(t *testing.T) { }, }, }, - Instructions: 6262706, + Instructions: 4378462, ReadBytes: 0, WriteBytes: 7048, }, - ResourceFee: 130498, + ResourceFee: 113910, } // First, decode and compare the transaction data so we get a decent diff if it fails. @@ -1122,7 +1122,7 @@ func TestSimulateSystemEvent(t *testing.T) { require.NoError(t, err) assert.InDelta(t, 7464, uint32(transactionData.Resources.ReadBytes), 200) - assert.InDelta(t, 98339, int64(transactionData.ResourceFee), 2000) + assert.InDelta(t, 78927, int64(transactionData.ResourceFee), 2000) assert.InDelta(t, 104, uint32(transactionData.Resources.WriteBytes), 15) require.GreaterOrEqual(t, len(response.Events), 3) } diff --git a/cmd/soroban-rpc/lib/preflight/src/fees.rs b/cmd/soroban-rpc/lib/preflight/src/fees.rs index fe4c5f2fb..1cad9c975 100644 --- a/cmd/soroban-rpc/lib/preflight/src/fees.rs +++ b/cmd/soroban-rpc/lib/preflight/src/fees.rs @@ -142,7 +142,7 @@ fn calculate_host_function_soroban_resources( let budget_instructions = budget .get_cpu_insns_consumed() .context("cannot get instructions consumed")?; - let instructions = max(budget_instructions + 800000, budget_instructions * 120 / 100); + let instructions = max(budget_instructions + 1000000, budget_instructions * 120 / 100); Ok(SorobanResources { footprint: ledger_footprint, instructions: u32::try_from(instructions)?, From 0b9607070cdc8e481c0933fc28c1ccf77957d455 Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 6 Dec 2023 10:11:33 +0000 Subject: [PATCH 06/11] use unsafe stellar-core image --- cmd/soroban-rpc/internal/test/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/soroban-rpc/internal/test/docker-compose.yml b/cmd/soroban-rpc/internal/test/docker-compose.yml index 9c9a4ac5c..58e1a5c64 100644 --- a/cmd/soroban-rpc/internal/test/docker-compose.yml +++ b/cmd/soroban-rpc/internal/test/docker-compose.yml @@ -15,7 +15,7 @@ services: # Note: Please keep the image pinned to an immutable tag matching the Captive Core version. # This avoids implicit updates which break compatibility between # the Core container and captive core. - image: ${CORE_IMAGE:-stellar/stellar-core:20.0.0-1615.617729910.focal} + image: ${CORE_IMAGE:-stellar/unsafe-stellar-core:20.0.0-1615.617729910.focal} depends_on: - core-postgres restart: on-failure From b5cceb64676001e284d7a2299e12317bff410705 Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 6 Dec 2023 11:25:21 +0000 Subject: [PATCH 07/11] fix TestGetPreflightDebug --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 8f00a3fce..50037df6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ version = "20.0.0-rc4" version = "20.0.0" git = "https://github.com/stellar/rs-soroban-env" rev = "9c5394083725bacf32a56107d7fa2adf643dc7b5" +features = ["testutils"] [workspace.dependencies.soroban-spec] version = "20.0.0" From feb43528a1a8083da65367582c99e6c13f831421 Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 6 Dec 2023 11:26:36 +0000 Subject: [PATCH 08/11] cargo fmt --all --- cmd/soroban-rpc/lib/preflight/src/fees.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/soroban-rpc/lib/preflight/src/fees.rs b/cmd/soroban-rpc/lib/preflight/src/fees.rs index 1cad9c975..5e6858b70 100644 --- a/cmd/soroban-rpc/lib/preflight/src/fees.rs +++ b/cmd/soroban-rpc/lib/preflight/src/fees.rs @@ -142,7 +142,10 @@ fn calculate_host_function_soroban_resources( let budget_instructions = budget .get_cpu_insns_consumed() .context("cannot get instructions consumed")?; - let instructions = max(budget_instructions + 1000000, budget_instructions * 120 / 100); + let instructions = max( + budget_instructions + 1000000, + budget_instructions * 120 / 100, + ); Ok(SorobanResources { footprint: ledger_footprint, instructions: u32::try_from(instructions)?, From ddf485e2e813b62eff544d5c0eb57b3279439f8d Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 6 Dec 2023 12:08:39 +0000 Subject: [PATCH 09/11] only use testutils for preflight lib --- Cargo.toml | 1 - cmd/soroban-rpc/lib/preflight/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 50037df6d..8f00a3fce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ version = "20.0.0-rc4" version = "20.0.0" git = "https://github.com/stellar/rs-soroban-env" rev = "9c5394083725bacf32a56107d7fa2adf643dc7b5" -features = ["testutils"] [workspace.dependencies.soroban-spec] version = "20.0.0" diff --git a/cmd/soroban-rpc/lib/preflight/Cargo.toml b/cmd/soroban-rpc/lib/preflight/Cargo.toml index 6fb710f72..11cbb48aa 100644 --- a/cmd/soroban-rpc/lib/preflight/Cargo.toml +++ b/cmd/soroban-rpc/lib/preflight/Cargo.toml @@ -12,5 +12,5 @@ base64 = { workspace = true } thiserror = { workspace = true } libc = "0.2.147" sha2 = { workspace = true } -soroban-env-host = { workspace = true, features = ["recording_auth"]} +soroban-env-host = { workspace = true, features = ["recording_auth", "testutils"]} rand = "0.8.5" From 811bdd911f1591cf67995dee5fa2aed466397a61 Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 6 Dec 2023 12:25:11 +0000 Subject: [PATCH 10/11] add comment explaining testutils feature --- cmd/soroban-rpc/lib/preflight/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/soroban-rpc/lib/preflight/Cargo.toml b/cmd/soroban-rpc/lib/preflight/Cargo.toml index 11cbb48aa..936ecc2f0 100644 --- a/cmd/soroban-rpc/lib/preflight/Cargo.toml +++ b/cmd/soroban-rpc/lib/preflight/Cargo.toml @@ -12,5 +12,7 @@ base64 = { workspace = true } thiserror = { workspace = true } libc = "0.2.147" sha2 = { workspace = true } +# we need the testutils feature in order to get backtraces in the preflight library +# when soroban rpc is configured to run with --preflight-enable-debug soroban-env-host = { workspace = true, features = ["recording_auth", "testutils"]} rand = "0.8.5" From 4ae9ca400058e3804432007c54b0fd29e5ad1d76 Mon Sep 17 00:00:00 2001 From: tamirms Date: Wed, 6 Dec 2023 12:26:52 +0000 Subject: [PATCH 11/11] add extra fudge factor to TestSimulateSystemEvent --- cmd/soroban-rpc/internal/test/simulate_transaction_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go index 22a88487e..2ec2b414e 100644 --- a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go +++ b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go @@ -1122,7 +1122,7 @@ func TestSimulateSystemEvent(t *testing.T) { require.NoError(t, err) assert.InDelta(t, 7464, uint32(transactionData.Resources.ReadBytes), 200) - assert.InDelta(t, 78927, int64(transactionData.ResourceFee), 2000) + assert.InDelta(t, 80980, int64(transactionData.ResourceFee), 5000) assert.InDelta(t, 104, uint32(transactionData.Resources.WriteBytes), 15) require.GreaterOrEqual(t, len(response.Events), 3) }