From e97b92d1ff75288d332c5e21c114a26031442f4b Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 25 Oct 2023 15:00:19 -0600 Subject: [PATCH] add example --- .github/workflows/example.yml | 46 + Cargo.lock | 1096 ++++++++++++++++- Cargo.toml | 34 +- README.md | 28 +- .../contracts/c1.compiled_contract_class.json | 1 + examples/contracts/c1.contract_class.json | 1 + examples/e2e.rs | 115 ++ 7 files changed, 1291 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/example.yml create mode 100644 examples/contracts/c1.compiled_contract_class.json create mode 100644 examples/contracts/c1.contract_class.json create mode 100644 examples/e2e.rs diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml new file mode 100644 index 0000000..17dbcad --- /dev/null +++ b/.github/workflows/example.yml @@ -0,0 +1,46 @@ +name: HTTP Request Action + +on: + push: + branches: + - main # Adjust to your branch name + +jobs: + katana-ci-startup: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 + + - name: Make HTTP Request + env: + API_KEY: ${{ secrets.API_KEY }} + API_URL: ${{ secrets.API_URL }} + run: | + NAME=$(curl -s -H "Authorization: Bearer $KATANA_CI_KEY" $KATANA_CI_URL/start) + echo "Response: $RESPONSE" + echo "API_RESPONSE=$RESPONSE" >> $GITHUB_ENV + + - name: Use Response in Another Job + run: | + echo "The response is $API_RESPONSE" + + test: + runs-on: ubuntu-latest-4-cores + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + - uses: Swatinem/rust-cache@v2 + - uses: arduino/setup-protoc@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - run: | + cargo test --all-features diff --git a/Cargo.lock b/Cargo.lock index 1674cb3..f09e03e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aes" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "ahash" version = "0.8.5" @@ -60,6 +71,82 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-std", + "digest", + "num-bigint", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-trait" version = "0.1.74" @@ -80,6 +167,18 @@ dependencies = [ "num-traits", ] +[[package]] +name = "auto_impl" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -203,6 +302,18 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bigdecimal" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -218,6 +329,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -233,6 +356,12 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + [[package]] name = "byteorder" version = "1.5.0" @@ -281,12 +410,32 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "const-oid" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -345,6 +494,23 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124" +dependencies = [ + "generic-array", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -355,6 +521,50 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.38", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.38", +] + [[package]] name = "der" version = "0.7.8" @@ -366,6 +576,27 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "digest" version = "0.10.7" @@ -393,6 +624,15 @@ dependencies = [ "serde", ] +[[package]] +name = "encoding_rs" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -420,6 +660,55 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "eth-keystore" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" +dependencies = [ + "aes", + "ctr", + "digest", + "hex", + "hmac", + "pbkdf2", + "rand", + "scrypt", + "serde", + "serde_json", + "sha2", + "sha3", + "thiserror", + "uuid 0.8.2", +] + +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-rlp", + "impl-serde", + "tiny-keccak", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-rlp", + "impl-serde", + "primitive-types", + "uint", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -450,6 +739,18 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + [[package]] name = "flate2" version = "1.0.28" @@ -501,6 +802,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.3.28" @@ -630,8 +937,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -838,6 +1147,20 @@ dependencies = [ "tower-layer", ] +[[package]] +name = "hyper-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" +dependencies = [ + "futures-util", + "http", + "hyper", + "rustls", + "tokio", + "tokio-rustls", +] + [[package]] name = "hyperlocal" version = "0.8.0" @@ -874,6 +1197,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.4.0" @@ -884,6 +1213,44 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -892,6 +1259,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", + "serde", ] [[package]] @@ -904,6 +1272,30 @@ dependencies = [ "hashbrown 0.14.2", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.11.0" @@ -929,9 +1321,10 @@ dependencies = [ ] [[package]] -name = "katana-proxifier" +name = "katana-ci" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "axum", "axum-extra", @@ -940,15 +1333,28 @@ dependencies = [ "rand", "regex", "serde", + "serde_json", + "serde_with", "shiplift", "sqlx", + "starknet", "thiserror", "tokio", "tower-http", "tracing", "tracing-log", "tracing-subscriber", - "uuid", + "url", + "uuid 1.5.0", +] + +[[package]] +name = "keccak" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +dependencies = [ + "cpufeatures", ] [[package]] @@ -1103,6 +1509,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-bigint-dig" version = "0.8.4" @@ -1220,6 +1637,32 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "parity-scale-codec" +version = "3.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dec8a8073036902368c2cdc0387e85ff9a37054d7e7c98e592145e0c92cd4fb" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "312270ee71e1cd70289dacf597cab7b207aa107d2f28191c2ae45b2ece18a260" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1249,6 +1692,15 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -1343,12 +1795,65 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.69" @@ -1367,6 +1872,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -1459,6 +1970,80 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "reqwest" +version = "0.11.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +dependencies = [ + "base64 0.21.5", + "bytes 1.5.0", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "system-configuration", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "ring" +version = "0.17.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" +dependencies = [ + "cc", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted", + "windows-sys", +] + +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes 1.5.0", + "rustc-hex", +] + [[package]] name = "rsa" version = "0.9.2" @@ -1487,6 +2072,21 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.20" @@ -1500,6 +2100,37 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustls" +version = "0.21.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446e14c5cda4f3f30fe71863c34ec70f5ac79d6087097ad0bb433e1be5edf04c" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +dependencies = [ + "base64 0.21.5", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -1512,12 +2143,49 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scrypt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" +dependencies = [ + "hmac", + "pbkdf2", + "salsa20", + "sha2", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + [[package]] name = "serde" version = "1.0.189" @@ -1539,10 +2207,22 @@ dependencies = [ ] [[package]] -name = "serde_json" -version = "1.0.107" +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "indexmap 2.0.2", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_json_pythonic" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "62212da9872ca2a0cad0093191ee33753eddff9266cbbc1b4a602d13a3a768db" dependencies = [ "itoa", "ryu", @@ -1571,6 +2251,34 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +dependencies = [ + "base64 0.13.1", + "chrono", + "hex", + "indexmap 1.9.3", + "serde", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "sha1" version = "0.10.6" @@ -1593,6 +2301,16 @@ dependencies = [ "digest", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1714,7 +2432,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" dependencies = [ - "itertools", + "itertools 0.11.0", "nom", "unicode_categories", ] @@ -1913,6 +2631,176 @@ dependencies = [ "url", ] +[[package]] +name = "starknet" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0623b045f3dc10aef030c9ddd4781cff9cbe1188b71063cc510b75d1f96be6" +dependencies = [ + "starknet-accounts", + "starknet-contract", + "starknet-core", + "starknet-crypto", + "starknet-ff", + "starknet-macros", + "starknet-providers", + "starknet-signers", +] + +[[package]] +name = "starknet-accounts" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68e97edc480348dca300e5a8234e6c4e6f2f1ac028f2b16fcce294ebe93d07f4" +dependencies = [ + "async-trait", + "auto_impl", + "starknet-core", + "starknet-providers", + "starknet-signers", + "thiserror", +] + +[[package]] +name = "starknet-contract" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b86e3f6b3ca9a5c45271ab10871c99f7dc82fee3199d9f8c7baa2a1829947d" +dependencies = [ + "serde", + "serde_json", + "serde_with", + "starknet-accounts", + "starknet-core", + "starknet-providers", + "thiserror", +] + +[[package]] +name = "starknet-core" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14139b1c39bdc2f1e663c12090ff5108fe50ebe62c09e15e32988dfaf445a7e4" +dependencies = [ + "base64 0.21.5", + "flate2", + "hex", + "serde", + "serde_json", + "serde_json_pythonic", + "serde_with", + "sha3", + "starknet-crypto", + "starknet-ff", +] + +[[package]] +name = "starknet-crypto" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dbb308033b5c60c5677645f7ba3b012b4e3e81f773480d27fb5f342d50621e6" +dependencies = [ + "crypto-bigint", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits", + "rfc6979", + "sha2", + "starknet-crypto-codegen", + "starknet-curve", + "starknet-ff", + "zeroize", +] + +[[package]] +name = "starknet-crypto-codegen" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af6527b845423542c8a16e060ea1bc43f67229848e7cd4c4d80be994a84220ce" +dependencies = [ + "starknet-curve", + "starknet-ff", + "syn 2.0.38", +] + +[[package]] +name = "starknet-curve" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68a0d87ae56572abf83ddbfd44259a7c90dbeeee1629a1ffe223e7f9a8f3052" +dependencies = [ + "starknet-ff", +] + +[[package]] +name = "starknet-ff" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2cb1d9c0a50380cddab99cb202c6bfb3332728a2769bd0ca2ee80b0b390dd4" +dependencies = [ + "ark-ff", + "bigdecimal", + "crypto-bigint", + "getrandom", + "hex", + "num-bigint", + "serde", +] + +[[package]] +name = "starknet-macros" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef846b6bb48fc8c3e9a2aa9b5b037414f04a908d9db56493a3ae69a857eb2506" +dependencies = [ + "starknet-core", + "syn 2.0.38", +] + +[[package]] +name = "starknet-providers" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b136c26b72ff1756f0844e0aa80bab680ceb99d63921826facbb8e7340ff82" +dependencies = [ + "async-trait", + "auto_impl", + "ethereum-types", + "flate2", + "log", + "reqwest", + "serde", + "serde_json", + "serde_with", + "starknet-core", + "thiserror", + "url", +] + +[[package]] +name = "starknet-signers" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9386015d2e6dc3df285bfb33a3afd8ad7596c70ed38ab57019de4d2dfc7826f" +dependencies = [ + "async-trait", + "auto_impl", + "crypto-bigint", + "eth-keystore", + "rand", + "starknet-core", + "starknet-crypto", + "thiserror", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "stringprep" version = "0.1.4" @@ -1924,6 +2812,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.5.0" @@ -1958,6 +2852,33 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tar" version = "0.4.40" @@ -2012,6 +2933,44 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +dependencies = [ + "deranged", + "itoa", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +dependencies = [ + "time-core", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2069,6 +3028,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.14" @@ -2094,6 +3063,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.0.2", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -2214,6 +3200,18 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unicode-bidi" version = "0.3.13" @@ -2247,6 +3245,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.4.1" @@ -2258,6 +3262,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "uuid" version = "1.5.0" @@ -2338,6 +3352,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.87" @@ -2367,6 +3393,22 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" + [[package]] name = "whoami" version = "1.4.1" @@ -2470,6 +3512,34 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "winnow" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "xattr" version = "1.0.1" @@ -2504,3 +3574,17 @@ name = "zeroize" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] diff --git a/Cargo.toml b/Cargo.toml index 2be8d13..a8f3fe7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,25 +1,33 @@ [package] -name = "katana-proxifier" +name = "katana-ci" +description = "A docker container manager to start/stop Katana instances." version = "0.1.0" edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +license = "MIT" [dependencies] async-trait = "0.1.73" +axum = { version = "0.6.20", features = ["macros", "headers"] } +axum-extra = "0.7.7" +futures-util = "0.3" +hyper = { version = "0.14", features = ["full"] } +rand = "0.8" +regex = "1.10" +serde = "1.0" shiplift = "0.7" +sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio"] } +thiserror = "1.0.40" tokio = { version = "1", features = ["full"] } +tower-http = { version = "0.4.4", features = ["cors"] } tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing = "0.1" tracing-log = "0.1" uuid = { version = "1.5.0", features = ["v4", "fast-rng", "macro-diagnostics"] } -thiserror = "1.0.40" -regex = "1.10" -futures-util = "0.3" -tower-http = { version = "0.4.4", features = ["cors"] } -axum = { version = "0.6.20", features = ["macros", "headers"] } -axum-extra = "0.7.7" -hyper = { version = "0.14", features = ["full"] } -rand = "0.8" -sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio"] } -serde = "1.0" + +[dev-dependencies] +anyhow = "1.0" +serde = { version = "1.0.164", features = ["derive"] } +serde_json = { version = "1.0.99", features = ["preserve_order"] } +serde_with = "2.3.3" +starknet = "0.6.0" +url = "2.4" \ No newline at end of file diff --git a/README.md b/README.md index 235c071..f99f41a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Katana-CI This repository contains a tool that helps starting Katana sequencer on demand (mostly for CI purposes). -To work, the `katana-proxifier` binary must be deployed on a server with docker installed. +To work, the `katana-ci` binary must be deployed on a server with docker installed. ## Design -To keep things simple and flexible for CI, the `katana-proxifier` uses docker under the hood. +To keep things simple and flexible for CI, the `katana-ci` uses docker under the hood. With an `in-memory` database for now, each user have an `api-key` that allows the `start` and `stop` of a Katana instance. When a user starts an instance, a new container is created and started. @@ -13,13 +13,16 @@ The database trait `ProxifierDb` is for now targetting `Sqlite`, but may be rewo ## Usage +The idea is to have the least overhead possible to spawn and interact with a Katana instance. So no client is designed for now, +and you can use very common tools like `curl`. + 1. Start an instance ```bash curl -H 'Content-Type: application/json' \ -H 'Authorization: Bearer my-key' \ - https://katana-ci.arkproject.dev/start + https:///start - # Returns a name: + # Returns a simple string with the name of the created instance. 4f2b3c60ae32 ``` The start will return an instance `name`, that can then be used to target Katana for this specific instance. @@ -27,24 +30,27 @@ The database trait `ProxifierDb` is for now targetting `Sqlite`, but may be rewo 2. Use `starkli` to interact with the instance, for example: ```bash - starkli block --full --rpc https://katana-ci.arkproject.dev//katana + starkli block --full --rpc https:////katana ``` 3. To check the logs, you can hit the endpoint `/logs` of your instance, by default it returns `25` tail lines. You can use `all` or any number you like using the query parameter `n`. ```bash curl -H 'Content-Type: application/json' \ -H 'Authorization: Bearer my-key' \ - https://katana-ci.arkproject.dev//logs + https:////logs + + curl -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer my-key' \ + https:////logs?n=100 ``` -4. Then, you can stop the instance if it's not needed. +4. Then, you can stop the instance if it's no longer needed. ```bash curl -H 'Content-Type: application/json' \ -H 'Authorization: Bearer my-key' \ - https://katana-ci.arkproject.dev//stop + https:////stop ``` -# Work in progress - -- [ ] Add an endpoint to register a user with a system of `whitelist-admins`. +## GitHub CI +Work in progress. diff --git a/examples/contracts/c1.compiled_contract_class.json b/examples/contracts/c1.compiled_contract_class.json new file mode 100644 index 0000000..a63eeca --- /dev/null +++ b/examples/contracts/c1.compiled_contract_class.json @@ -0,0 +1 @@ +{"prime":"0x800000000000011000000000000000000000000000000000000000000000001","compiler_version":"2.3.0","bytecode":["0xa0680017fff8000","0x7","0x482680017ffa8000","0x100000000000000000000000000000000","0x400280007ff97fff","0x10780017fff7fff","0x4d","0x4825800180007ffa","0x0","0x400280007ff97fff","0x48297ffc80007ffd","0x482680017ff98000","0x1","0x4824800180007ffe","0x0","0x20680017fff7fff","0x4","0x10780017fff7fff","0x10","0x40780017fff7fff","0x1","0x480680017fff8000","0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473","0x400080007ffe7fff","0x48127ffc7fff8000","0x48127ff97fff8000","0x480a7ffb7fff8000","0x480680017fff8000","0x1","0x48127ffa7fff8000","0x482480017ff98000","0x1","0x208b7fff7fff7ffe","0x1104800180018000","0x45","0x482480017fff8000","0x44","0x480080007fff8000","0xa0680017fff8000","0x9","0x4824800180007ff7","0x0","0x482480017fff8000","0x100000000000000000000000000000000","0x400080007ff77fff","0x10780017fff7fff","0x16","0x4824800180007ff7","0x0","0x400080007ff87fff","0x40780017fff7fff","0x1","0x480680017fff8000","0x68656c6c6f","0x48127ffe7fff8000","0x48127ffd7fff8000","0x1104800180018000","0x29","0x482480017ff08000","0x1","0x48127ff67fff8000","0x480a7ffb7fff8000","0x480680017fff8000","0x0","0x48127ffa7fff8000","0x48127ffa7fff8000","0x208b7fff7fff7ffe","0x40780017fff7fff","0x1","0x480680017fff8000","0x4f7574206f6620676173","0x400080007ffe7fff","0x482480017ff58000","0x1","0x48127ff27fff8000","0x480a7ffb7fff8000","0x480680017fff8000","0x1","0x48127ffa7fff8000","0x482480017ff98000","0x1","0x208b7fff7fff7ffe","0x40780017fff7fff","0x1","0x480680017fff8000","0x4f7574206f6620676173","0x400080007ffe7fff","0x482680017ff98000","0x1","0x480a7ffa7fff8000","0x480a7ffb7fff8000","0x480680017fff8000","0x1","0x48127ffa7fff8000","0x482480017ff98000","0x1","0x208b7fff7fff7ffe","0x400380007ffd7ffb","0x480a7ffc7fff8000","0x482680017ffd8000","0x1","0x208b7fff7fff7ffe"],"hints":[[0,[{"TestLessThanOrEqual":{"lhs":{"Immediate":"0x0"},"rhs":{"Deref":{"register":"FP","offset":-6}},"dst":{"register":"AP","offset":0}}}]],[19,[{"AllocSegment":{"dst":{"register":"AP","offset":0}}}]],[38,[{"TestLessThanOrEqual":{"lhs":{"Immediate":"0x0"},"rhs":{"Deref":{"register":"AP","offset":-8}},"dst":{"register":"AP","offset":0}}}]],[50,[{"AllocSegment":{"dst":{"register":"AP","offset":0}}}]],[67,[{"AllocSegment":{"dst":{"register":"AP","offset":0}}}]],[82,[{"AllocSegment":{"dst":{"register":"AP","offset":0}}}]]],"entry_points_by_type":{"EXTERNAL":[{"selector":"0x2e4ad76613f67be4df62830e485c06afe143ff1d3dc068788a6705aeac8b747","offset":0,"builtins":["range_check"]}],"L1_HANDLER":[],"CONSTRUCTOR":[]}} \ No newline at end of file diff --git a/examples/contracts/c1.contract_class.json b/examples/contracts/c1.contract_class.json new file mode 100644 index 0000000..04b3650 --- /dev/null +++ b/examples/contracts/c1.contract_class.json @@ -0,0 +1 @@ +{"sierra_program":["0x1","0x3","0x0","0x2","0x3","0x0","0x73","0x8d","0xe","0x52616e6765436865636b","0x800000000000000100000000000000000000000000000000","0x4172726179","0x800000000000000300000000000000000000000000000001","0x1","0xb","0x536e617073686f74","0x800000000000000700000000000000000000000000000001","0x537472756374","0x800000000000000700000000000000000000000000000002","0x0","0x1baeba72e79e9db2587cf44fedb2f3700b2075a5e8e39a562584862c4b71f62","0x2","0x2ee1e2b1b89f8c495f200e4956278a4d47395fe262f27b52e5865c9524c08c3","0x3","0x800000000000000f00000000000000000000000000000001","0x4275696c74696e436f737473","0x800000000000000700000000000000000000000000000000","0x53797374656d","0x16a4c8d7c05909052238a862d8cc3e7975bf05a07b3a69c6b28951083a6d672","0x800000000000000300000000000000000000000000000003","0x8","0x456e756d","0x9931c641b913035ae674b400b61a51476d506bbe8bba2ff8a6272790aba9e6","0x4","0x9","0x66656c74323532","0x753332","0x4761734275696c74696e","0x29","0x7265766f6b655f61705f747261636b696e67","0x77697468647261775f676173","0x6272616e63685f616c69676e","0x7374727563745f6465636f6e737472756374","0x61727261795f6c656e","0x736e617073686f745f74616b65","0xc","0x64726f70","0x7533325f636f6e7374","0x72656e616d65","0x73746f72655f74656d70","0x7533325f6571","0x61727261795f6e6577","0x66656c743235325f636f6e7374","0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473","0x61727261795f617070656e64","0x7374727563745f636f6e737472756374","0x656e756d5f696e6974","0xa","0xd","0x7","0x6765745f6275696c74696e5f636f737473","0x6","0x77697468647261775f6761735f616c6c","0x68656c6c6f","0x66756e6374696f6e5f63616c6c","0x5","0x4f7574206f6620676173","0x54","0xffffffffffffffff","0x40","0xf","0x10","0x1c","0x11","0x12","0x13","0x14","0x15","0x16","0x17","0x18","0x19","0x1a","0x1b","0x1d","0x33","0x1e","0x1f","0x20","0x21","0x22","0x23","0x26","0x27","0x24","0x25","0x28","0x2a","0x2b","0x2c","0x2d","0x2e","0x2f","0x30","0x31","0x32","0x34","0x35","0x36","0x37","0x38","0x39","0x3a","0x3b","0x3c","0x3d","0x3e","0x3f","0x41","0x42","0x43","0x44","0x4e","0x37e","0x21312110e0b10090f050e0b0a090d050c0b0a090505080706050403020100","0xb200b1f1e021d121c121b1a051905180b1517050516050e0b1509140b1009","0x2925050529250505280b0d05272505052625050524060505230f0505220b21","0xd301a05052f1605052f0605052e060505292d0d052c0605052b0b2a0b0505","0x50524370d052c0b36350505290b34310505293305052932050529050d3105","0x52f0f05052f050505260505052439050526050f0538050505290605052606","0xb0b3b390505293905052f060505280f0505263a0d052c0b0d31050d301905","0x53c050f050f0b0b3c050b0d0b33350d3d39190d3c0d050b0d050b0b3c050b","0x53c050b330b0b3c053105350b06310d3c051a05390b1a053c051605190b16","0x3c050005160b3e053c050605160b0b3c053205350b00320d3c052505390b25","0xb0d0b0b400b3c0d3f3e0d060b19053c051905310b3e053c053e051a0b3f05","0x542410d3e0b42053c054205000b42053c050b320b41053c050b250b0b3c05","0x1905310b46053c054505420b45053c0543440d410b44053c050b3f0b43053c","0x4719054a053c054605450b49053c050d05440b48053c053905430b47053c05","0xd4b39190f480b4b053c054b05470b4b053c050b460b0b3c050b0d0b4a4948","0x54a0b51053c050b490b50053c050b250b0b3c050b0d0b4f4e0d4d4c400d3c","0x4c0b55053c055005400b54053c055305000b0b3c0552054b0b53520d3c0551","0xb3c055805500b1e580d3c0556054f0b0b3c0557054e0b57560d3c0555540d","0x53c054005310b5b053c055a05530b5a053c055905520b59053c051e05510b","0x5f5e5d5c19055f053c055b05450b5e053c050d05440b5d053c054c05430b5c","0xd3e0b61053c056105000b61053c050b560b60053c050b250b0b3c050b0d0b","0xb64053c056305420b63053c054d620d410b62053c050b3f0b4d053c056160","0x68053c056405450b67053c050d05440b66053c054f05430b65053c054e0531","0x3c050b560b69053c050b250b0b3c050f05570b0b3c050b0d0b686766651905","0x6b6c0d410b6c053c050b3f0b6b053c056a690d3e0b6a053c056a05000b6a05","0x5440b6f053c053305430b6e053c053505310b3d053c056d05420b6d053c05","0x50d3e0b0d053c050b05540b71706f6e190571053c053d05450b70053c050d","0x390d0535053c051905580b39053c050f05400b19053c050b550b0f053c050d","0x72050b39050d05060d0b0f0d050b3133320b190f33320b190d35"],"sierra_program_debug_info":{"type_names":[[0,"RangeCheck"],[1,"Array"],[2,"Snapshot>"],[3,"core::array::Span::"],[4,"Tuple>"],[5,"Unit"],[6,"BuiltinCosts"],[7,"System"],[8,"core::panics::Panic"],[9,"Tuple>"],[10,"core::panics::PanicResult::<(core::array::Span::,)>"],[11,"felt252"],[12,"u32"],[13,"GasBuiltin"]],"libfunc_names":[[0,"revoke_ap_tracking"],[1,"withdraw_gas"],[2,"branch_align"],[3,"struct_deconstruct>"],[4,"array_len"],[5,"snapshot_take"],[6,"drop"],[7,"u32_const<0>"],[8,"rename"],[9,"store_temp"],[10,"store_temp"],[11,"u32_eq"],[12,"array_new"],[13,"felt252_const<7733229381460288120802334208475838166080759535023995805565484692595>"],[14,"store_temp"],[15,"array_append"],[16,"struct_construct"],[17,"struct_construct>>"],[18,"enum_init,)>, 1>"],[19,"store_temp"],[20,"store_temp"],[21,"store_temp,)>>"],[22,"get_builtin_costs"],[23,"store_temp"],[24,"withdraw_gas_all"],[25,"felt252_const<448378203247>"],[26,"snapshot_take"],[27,"drop"],[28,"store_temp>"],[29,"function_call"],[30,"drop"],[31,"snapshot_take>"],[32,"drop>"],[33,"struct_construct>"],[34,"struct_construct>>"],[35,"enum_init,)>, 0>"],[36,"felt252_const<375233589013918064796019>"],[37,"drop>"],[38,"rename"],[39,"struct_construct"],[40,"store_temp"]],"user_func_names":[[0,"scarb_pg::simple::simple::__wrapper__say_hello"],[1,"core::Felt252Serde::serialize"]]},"contract_class_version":"0.1.0","entry_points_by_type":{"EXTERNAL":[{"selector":"0x2e4ad76613f67be4df62830e485c06afe143ff1d3dc068788a6705aeac8b747","function_idx":0}],"L1_HANDLER":[],"CONSTRUCTOR":[]},"abi":[{"type":"function","name":"say_hello","inputs":[],"outputs":[{"type":"core::felt252"}],"state_mutability":"view"},{"type":"event","name":"scarb_pg::simple::simple::Event","kind":"enum","variants":[]}]} \ No newline at end of file diff --git a/examples/e2e.rs b/examples/e2e.rs new file mode 100644 index 0000000..63d7c1a --- /dev/null +++ b/examples/e2e.rs @@ -0,0 +1,115 @@ +use anyhow::Result; +use std::{env, sync::Arc}; + +use starknet::{ + accounts::{Account, ExecutionEncoding, SingleOwnerAccount}, + contract::ContractFactory, + core::types::{contract::SierraClass, BlockId, BlockTag, FieldElement, FunctionCall}, + macros::{felt, selector}, + providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient, Provider}, + signers::{LocalWallet, SigningKey}, +}; +use tokio::time::{sleep, Duration}; +use url::Url; + +#[tokio::main] +async fn main() -> Result<()> { + let rpc_url = env::var("STARKNET_RPC").expect("STARKNET_RPC must be set"); + let rpc_url = Url::parse(&rpc_url).expect("Invalid STARKNET_RPC URL"); + + let provider = + AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc_url.clone()))); + + // KATANA-0 account with default seed. + let katana_chain_id = felt!("0x4b4154414e41"); + let katana_0_addr = FieldElement::from_hex_be( + "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973", + ) + .unwrap(); + let katana_0_key = + FieldElement::from_hex_be("0x1800000000300000180000000000030000000000003006001800006600") + .unwrap(); + + let signer = LocalWallet::from(SigningKey::from_secret_scalar(katana_0_key)); + + let account = SingleOwnerAccount::new( + provider, + signer, + katana_0_addr, + katana_chain_id, + ExecutionEncoding::Legacy, + ); + + println!("Declaring"); + let casm_class_hash = FieldElement::from_hex_be( + "0x025dbb58db5071c88292cb25c81be128f2f47ccd8e3bd86260187f9937d181bb", + ) + .unwrap(); + + let class = serde_json::from_reader::<_, SierraClass>(std::fs::File::open( + "./examples/contracts/c1.contract_class.json", + )?) + .expect("Failed to read sierra class"); + + let class_hash = class.class_hash().unwrap(); + + let declaration = account.declare(Arc::new(class.flatten()?), casm_class_hash); + + let _tx = match declaration.send().await { + Ok(d) => Some(d.transaction_hash), + Err(_e) => { + // maybe already declared, skip for this example. + None + } + }; + + // Wait katana to process this tx, fairly quick. In production code + // it's more reliable to poll the tx receipt with the tx hash. + sleep(Duration::from_millis(2000)).await; + + println!("Deploying"); + let factory = ContractFactory::new(class_hash, account); + + let args = vec![]; + // Using a fix salt is usefull to have reproducible addresses + // for testing. + let salt = FieldElement::ZERO; + let is_unique = false; + let contract_deployment = factory.deploy(args, salt, is_unique); + let deployed_address = contract_deployment.deployed_address(); + + let _tx = contract_deployment.send().await?.transaction_hash; + + sleep(Duration::from_millis(2000)).await; + + let calldata = vec![]; + let block = BlockId::Tag(BlockTag::Pending); + + // account is for now consumed by the factory, and the provider + // by the account and for now we can't get account from ContractFactory. + println!("Calling"); + let provider = + AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc_url.clone()))); + + let r = provider + .call( + FunctionCall { + contract_address: deployed_address, + entry_point_selector: selector!("say_hello"), + calldata, + }, + block, + ) + .await?; + + assert_eq!( + r[0], + felt!("0x00000000000000000000000000000000000000000000000000000068656c6c6f") + ); + + println!("Call result: {:?}", r); + + // r[0] should be: 0x00000000000000000000000000000000000000000000000000000068656c6c6f, which is 'hello'. + + Ok(()) +}