From 1e28544519e62ff17e2cc2949f745e3739d7876b Mon Sep 17 00:00:00 2001 From: Doris Benda Date: Wed, 3 Jan 2024 19:54:38 +0100 Subject: [PATCH] Clean up server --- .../backend/Cargo.lock | 523 +----------------- .../backend/Cargo.toml | 12 +- .../backend/src/main.rs | 99 ++-- .../backend/src/types.rs | 66 ++- 4 files changed, 105 insertions(+), 595 deletions(-) diff --git a/sponsoredTransactionsAuction/backend/Cargo.lock b/sponsoredTransactionsAuction/backend/Cargo.lock index 76d55fa3..1f7b4068 100644 --- a/sponsoredTransactionsAuction/backend/Cargo.lock +++ b/sponsoredTransactionsAuction/backend/Cargo.lock @@ -159,12 +159,6 @@ version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" -[[package]] -name = "array-init" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc" - [[package]] name = "arrayvec" version = "0.7.4" @@ -173,9 +167,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "async-compression" -version = "0.4.2" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d495b6dc0184693324491a5ac05f559acc97bf937ab31d7a1c33dd0016be6d2b" +checksum = "bc2d0cfb2a7388d34f590e76686704c494ed7aaceed62ee1ba35cbf363abc2a5" dependencies = [ "brotli", "futures-core", @@ -417,9 +411,9 @@ dependencies = [ [[package]] name = "brotli" -version = "3.3.4" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68" +checksum = "516074a47ef4bce09577a3b379392300159ce5b1ba2e501ff1c819950066100f" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -428,9 +422,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "2.3.4" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6561fd3f895a11e8f72af2cb7d22e08366bebc2b6b57f7744c4bda27034744" +checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -956,15 +950,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "encoding_rs" -version = "0.8.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -992,18 +977,6 @@ dependencies = [ "libc", ] -[[package]] -name = "fallible-iterator" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" - -[[package]] -name = "fastrand" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" - [[package]] name = "ff" version = "0.5.2" @@ -1035,21 +1008,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.0" @@ -1232,20 +1190,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "handlebars" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c39b3bc2a8f715298032cf5087e58573809374b08160aa7d750582bdb82d2683" -dependencies = [ - "log", - "pest", - "pest_derive", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "hashbrown" version = "0.11.2" @@ -1360,7 +1304,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "socket2", "tokio", "tower-service", "tracing", @@ -1379,19 +1323,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "iana-time-zone" version = "0.1.57" @@ -1421,16 +1352,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "indexmap" version = "1.9.3" @@ -1462,12 +1383,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "ipnet" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" - [[package]] name = "is-terminal" version = "0.4.9" @@ -1496,9 +1411,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -1545,16 +1460,6 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" -[[package]] -name = "lock_api" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.19" @@ -1567,15 +1472,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" -[[package]] -name = "md-5" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "memchr" version = "2.5.0" @@ -1633,24 +1529,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nom" version = "7.1.3" @@ -1810,50 +1688,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.28", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "overload" version = "0.1.1" @@ -1872,29 +1712,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "password-hash" version = "0.4.2" @@ -1924,69 +1741,6 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" -[[package]] -name = "pest" -version = "2.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a4d085fd991ac8d5b05a147b437791b4260b76326baf0fc60cf7c9c27ecd33" -dependencies = [ - "memchr", - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bee7be22ce7918f641a33f08e3f43388c7656772244e2bbb2477f44cc9021a" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1511785c5e98d79a05e8a6bc34b4ac2168a0e3e92161862030ad84daa223141" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn 2.0.28", -] - -[[package]] -name = "pest_meta" -version = "2.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42f0394d3123e33353ca5e1e89092e533d2cc490389f2bd6131c43c634ebc5f" -dependencies = [ - "once_cell", - "pest", - "sha2 0.10.7", -] - -[[package]] -name = "phf" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_shared" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" -dependencies = [ - "siphasher", -] - [[package]] name = "pin-project" version = "1.1.2" @@ -2021,9 +1775,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "polyval" @@ -2037,38 +1791,6 @@ dependencies = [ "universal-hash", ] -[[package]] -name = "postgres-protocol" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b7fa9f396f51dffd61546fd8573ee20592287996568e6175ceb0f8699ad75d" -dependencies = [ - "base64 0.21.2", - "byteorder", - "bytes", - "fallible-iterator", - "hmac", - "md-5", - "memchr", - "rand 0.8.5", - "sha2 0.10.7", - "stringprep", -] - -[[package]] -name = "postgres-types" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f028f05971fe20f512bcc679e2c10227e57809a3af86a7606304435bc8896cd6" -dependencies = [ - "array-init", - "bytes", - "fallible-iterator", - "postgres-protocol", - "serde", - "serde_json", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2273,15 +1995,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "rend" version = "0.4.0" @@ -2291,43 +2004,6 @@ dependencies = [ "bytecheck", ] -[[package]] -name = "reqwest" -version = "0.11.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" -dependencies = [ - "base64 0.21.2", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "ring" version = "0.16.20" @@ -2656,9 +2332,9 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" dependencies = [ "lazy_static", ] @@ -2684,12 +2360,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - [[package]] name = "slab" version = "0.4.8" @@ -2701,9 +2371,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "socket2" @@ -2715,16 +2385,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "socket2" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" -dependencies = [ - "libc", - "windows-sys", -] - [[package]] name = "spin" version = "0.5.2" @@ -2738,35 +2398,19 @@ dependencies = [ "anyhow", "axum", "axum-macros", - "chrono", "clap", "concordium-rust-sdk", "futures", - "handlebars", "hex", "http", - "reqwest", "serde", "serde_json", - "sha2 0.10.7", "thiserror", "tokio", - "tokio-postgres", "tonic", "tower-http", "tracing", "tracing-subscriber", - "url", -] - -[[package]] -name = "stringprep" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3737bde7edce97102e0e2b15365bf7a20bfdb5f60f4f9e8d7004258a51a8da" -dependencies = [ - "unicode-bidi", - "unicode-normalization", ] [[package]] @@ -2815,19 +2459,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "tempfile" -version = "3.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall", - "rustix", - "windows-sys", -] - [[package]] name = "thiserror" version = "1.0.44" @@ -2926,7 +2557,7 @@ dependencies = [ "num_cpus", "pin-project-lite", "signal-hook-registry", - "socket2 0.4.9", + "socket2", "tokio-macros", "windows-sys", ] @@ -2952,40 +2583,6 @@ dependencies = [ "syn 2.0.28", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-postgres" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e89f6234aa8fd43779746012fcf53603cdb91fdd8399aa0de868c2d56b6dde1" -dependencies = [ - "async-trait", - "byteorder", - "bytes", - "fallible-iterator", - "futures-channel", - "futures-util", - "log", - "parking_lot", - "percent-encoding", - "phf", - "pin-project-lite", - "postgres-protocol", - "postgres-types", - "socket2 0.5.3", - "tokio", - "tokio-util", -] - [[package]] name = "tokio-rustls" version = "0.23.4" @@ -3187,20 +2784,20 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ - "lazy_static", "log", + "once_cell", "tracing-core", ] [[package]] name = "tracing-subscriber" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ "nu-ansi-term", "sharded-slab", @@ -3222,42 +2819,21 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" -[[package]] -name = "ucd-trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" - [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - [[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - [[package]] name = "universal-hash" version = "0.5.1" @@ -3274,18 +2850,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" -[[package]] -name = "url" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - [[package]] name = "utf8parse" version = "0.2.1" @@ -3304,12 +2868,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -3368,18 +2926,6 @@ 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" @@ -3535,15 +3081,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "wyz" version = "0.5.1" @@ -3575,30 +3112,28 @@ dependencies = [ [[package]] name = "zstd" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +checksum = "bffb3309596d527cfcba7dfc6ed6052f1d39dfbd7c867aa2e865e4a449c10110" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "6.0.6" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +checksum = "43747c7422e2924c11144d5229878b98180ef8b06cca4ab5af37afc8a8d8ea3e" dependencies = [ - "libc", "zstd-sys", ] [[package]] name = "zstd-sys" -version = "2.0.8+zstd.1.5.5" +version = "2.0.9+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" dependencies = [ "cc", - "libc", "pkg-config", ] diff --git a/sponsoredTransactionsAuction/backend/Cargo.toml b/sponsoredTransactionsAuction/backend/Cargo.toml index eaf649fa..c6f5b62a 100644 --- a/sponsoredTransactionsAuction/backend/Cargo.toml +++ b/sponsoredTransactionsAuction/backend/Cargo.toml @@ -12,21 +12,15 @@ anyhow = "1.0" axum = "0.6" clap = { version = "4.3", features = ["derive", "env"] } serde_json = "1.0" -tokio = { version = "1.29", features = ["rt-multi-thread", "macros", "signal"] } -tokio-postgres = { version = "0.7", features = [ - "with-serde_json-1", - "array-impls", -] } +tokio = { version = "1.29", features = ["rt-multi-thread", "signal"] } tracing = "0.1" tracing-subscriber = "0.3" serde = { version = "1.0", features = ["derive"] } futures = "0.3" axum-macros = "0.3" -reqwest = { version = "0.11", features = ["json"] } tower-http = { version = "0.4", features = [ "trace", "limit", - "cors", "timeout", "fs", "compression-br", @@ -35,10 +29,6 @@ tower-http = { version = "0.4", features = [ http = "0.2" tonic = { version = "0.8", features = ["tls-roots", "tls"] } thiserror = "1.0" -chrono = { version = "0.4", features = ["serde"] } -sha2 = "0.10" -handlebars = "4.4" -url = { version = "2.4.1", features = ["serde"] } hex = "0.4.3" [dependencies.concordium-rust-sdk] diff --git a/sponsoredTransactionsAuction/backend/src/main.rs b/sponsoredTransactionsAuction/backend/src/main.rs index 4e8a7f65..1ac9d802 100644 --- a/sponsoredTransactionsAuction/backend/src/main.rs +++ b/sponsoredTransactionsAuction/backend/src/main.rs @@ -22,10 +22,7 @@ use concordium_rust_sdk::{ transactions, Energy, WalletAccount, }, v2::{self, BlockIdentifier}, - web3id::did::Network, }; -use handlebars::Handlebars; -use serde_json::json; use std::{ collections::{BTreeMap, HashMap}, fs, @@ -35,16 +32,15 @@ use tokio::sync::Mutex; use tonic::transport::ClientTlsConfig; use tower_http::services::ServeDir; -const CONTRACT_NAME: &str = "cis2_multi"; -const ENERGY: u64 = 60000; -const RATE_LIMIT_PER_ACCOUNT: u8 = 30; - // Before submitting a transaction we simulate/dry-run the transaction to get an // estimate of the energy needed for executing the transaction. In addition, we // allow an additional small amount of energy `EPSILON_ENERGY` to be consumed by // the transaction to cover small variations (e.g. changes to the smart contract // state) caused by transactions that have been executed meanwhile. const EPSILON_ENERGY: u64 = 1000; +const CONTRACT_NAME: &str = "cis2_multi"; +const ENERGY: u64 = 60000; +const RATE_LIMIT_PER_ACCOUNT: u8 = 30; #[derive(clap::Parser, Debug)] #[clap(version, author)] @@ -56,13 +52,6 @@ struct App { env = "NODE" )] endpoint: v2::Endpoint, - #[clap( - long = "network", - help = "Network to which the verifier is connected.", - default_value = "testnet", - env = "NETWORK" - )] - network: Network, #[clap( long = "log-level", default_value = "info", @@ -163,54 +152,42 @@ async fn main() -> anyhow::Result<()> { .await .context("Unable to establish connection to the node.")?; - let http_client = reqwest::Client::new(); - - let crypto_params = node_client - .get_cryptographic_parameters(BlockIdentifier::LastFinal) - .await - .context("Unable to get cryptographic parameters.")? - .response; - - // load account keys and sender address from a file + // Load account keys and sender address from a file let keys: WalletAccount = serde_json::from_str( &std::fs::read_to_string(app.keys_path).context("Could not read the keys file.")?, ) .context("Could not parse the keys file.")?; - let key_transfer = Arc::new(keys); - - // log::debug!("Acquire nonce of wallet account."); + let sponsorer_key = Arc::new(keys); let nonce_response = node_client - .get_next_account_sequence_number(&key_transfer.address) + .get_next_account_sequence_number(&sponsorer_key.address) .await .context("NonceQueryError.")?; + tracing::debug!( + "Starting server with sponsorer {:?}. Current sponsorer nonce: {:?}.", + sponsorer_key.address, + nonce_response + ); + let state = Server { - http_client, node_client, nonce: Arc::new(Mutex::new(nonce_response.nonce)), rate_limits: Arc::new(Mutex::new(HashMap::new())), auction_smart_contract: ContractAddress::new(app.auction_smart_contract_index, 0), cis2_token_smart_contract: ContractAddress::new(app.cis2_token_smart_contract_index, 0), - key: key_transfer, - network: app.network, - crypto_params: Arc::new(crypto_params), + key: sponsorer_key, }; - // Render index.html with config + // Render index.html let index_template = fs::read_to_string(app.frontend_assets.join("index.html")) - .context("Frontend was not built.")?; - let mut reg = Handlebars::new(); - // Prevent handlebars from escaping inserted object - reg.register_escape_fn(|s| s.into()); - - let index_html = reg.render_template(&index_template, &json!(""))?; + .context("Frontend was not built or wrong path to the frontend files.")?; tracing::info!("Starting server..."); let serve_dir_service = ServeDir::new(app.frontend_assets.join("assets")); let router = Router::new() - .route("/", get(|| async { Html(index_html) })) + .route("/", get(|| async { Html(index_template) })) .nest_service("/assets", serve_dir_service) .route("/api/bid", post(handle_signature_bid)) .route("/health", get(health)) @@ -243,7 +220,7 @@ async fn handle_signature_bid( State(mut state): State, request: Result, JsonRejection>, ) -> Result, ServerError> { - let request = request.map_err(ServerError::InvalidRequest)?; + let Json(request) = request?; tracing::debug!("Request: {:?}", request); @@ -255,8 +232,8 @@ async fn handle_signature_bid( state.auction_smart_contract, OwnedReceiveName::new_unchecked("bid".to_owned()), ), - token_id: request.token_id.clone(), - amount: request.token_amount.clone(), + token_id: request.token_id, + amount: request.token_amount, data: AdditionalData::new_unchecked(to_bytes(&request.item_index_auction)), }; @@ -264,7 +241,7 @@ async fn handle_signature_bid( tracing::debug!("Created payload: {:?}", payload); - tracing::debug!("Create PermitMessage ..."); + tracing::debug!("Create permitMessage ..."); let message: PermitMessage = PermitMessage { contract_address: state.cis2_token_smart_contract, @@ -274,13 +251,12 @@ async fn handle_signature_bid( payload: concordium_rust_sdk::smart_contracts::common::to_bytes(&payload), }; - tracing::debug!("Create message {:?}", message); + tracing::debug!("Created {:?}", message); tracing::debug!("Create signature map ..."); let mut signature = [0; 64]; - hex::decode_to_slice(request.signature.clone(), &mut signature) - .map_err(ServerError::SignatureError)?; + hex::decode_to_slice(request.signature, &mut signature).map_err(ServerError::SignatureError)?; let mut inner_signature_map = BTreeMap::new(); inner_signature_map.insert(0, Signature::Ed25519(SignatureEd25519(signature))); @@ -305,18 +281,18 @@ async fn handle_signature_bid( let parameter = smart_contracts::OwnedParameter::from_serial(¶m) .map_err(|_| ServerError::ParameterError)?; - tracing::debug!("Created parameter {:?}", parameter); - - let receive_name = - smart_contracts::OwnedReceiveName::new_unchecked(format!("{}.permit", CONTRACT_NAME)); + tracing::debug!("Created {:?}", parameter); tracing::debug!("Simulate transaction to check its validity ..."); let payload = transactions::UpdateContractPayload { - amount: Amount::from_micro_ccd(0), - address: state.cis2_token_smart_contract, - receive_name, - message: parameter, + amount: Amount::from_micro_ccd(0), + address: state.cis2_token_smart_contract, + receive_name: smart_contracts::OwnedReceiveName::new_unchecked(format!( + "{}.permit", + CONTRACT_NAME + )), + message: parameter, }; let context = ContractContext::new_from_payload( @@ -344,7 +320,10 @@ async fn handle_signature_bid( events: _, used_energy, } => { - tracing::debug!("TransactionSimulationSuccess with used energy: {:#?}.", used_energy); + tracing::debug!( + "TransactionSimulationSuccess with used energy: {:#?}.", + used_energy + ); used_energy } InvokeContractResult::Failure { @@ -359,8 +338,6 @@ async fn handle_signature_bid( } }; - tracing::debug!("Create transaction ..."); - // Transaction should expiry after one hour. let transaction_expiry = TransactionTime::hours_after(1); @@ -384,7 +361,7 @@ async fn handle_signature_bid( // that the server can be restarted and reload the rate_limit values from the // database. - tracing::debug!("Check rate limit ..."); + tracing::debug!("Check rate limit of account {} ...", request.signer); let mut rate_limits = state.rate_limits.lock().await; @@ -397,6 +374,8 @@ async fn handle_signature_bid( *limit += 1; + tracing::debug!("Create transaction ..."); + let tx = transactions::send::make_and_sign_transaction( &state.key.keys, state.key.address, @@ -411,9 +390,9 @@ async fn handle_signature_bid( concordium_rust_sdk::types::transactions::Payload::Update { payload }, ); - let bi = transactions::BlockItem::AccountTransaction(tx); + tracing::debug!("Submit transaction {:?} ...", tx.clone()); - tracing::debug!("Submit transaction ..."); + let bi = transactions::BlockItem::AccountTransaction(tx); match state.node_client.send_block_item(&bi).await { Ok(hash) => { diff --git a/sponsoredTransactionsAuction/backend/src/types.rs b/sponsoredTransactionsAuction/backend/src/types.rs index 9160d5e7..2f15d957 100644 --- a/sponsoredTransactionsAuction/backend/src/types.rs +++ b/sponsoredTransactionsAuction/backend/src/types.rs @@ -8,9 +8,8 @@ use concordium_rust_sdk::{ Timestamp, }, }, - types::{CryptographicParameters, Nonce, RejectReason, WalletAccount}, + types::{Nonce, RejectReason, WalletAccount}, v2::{self, QueryError, RPCError}, - web3id::did::Network, }; use hex::FromHexError; use http::StatusCode; @@ -21,31 +20,44 @@ use tokio::sync::Mutex; pub enum ServerError { #[error("Unable to parse request: {0}")] InvalidRequest(#[from] JsonRejection), - #[error("The passed signature from the front end is in a wrong format: {0}")] + #[error("Unable to parse signature into a hex string: {0}")] SignatureError(#[from] FromHexError), - #[error("TODO:ParameterError.")] + #[error("Unable to create parameter.")] ParameterError, - #[error("TODO: SimulationInvokeError: {0}")] + #[error("Unable to invoke the node to simulate the transaction: {0}")] SimulationInvokeError(#[from] QueryError), - #[error("TODO: Transaction simulation error.")] + #[error("Simulation of transaction reverted in smart contract with reason: {0:?}")] TransactionSimulationError(RevertReason), - #[error("TODO: RateLimitError.")] + #[error("The signer account reached its rate limit.")] RateLimitError, - #[error("TODO: SubmitSponsoredTransactionError: {0}")] + #[error("Unable to submit transaction on chain successfully: {0}")] SubmitSponsoredTransactionError(#[from] RPCError), } -// TODO: Assign correct error codes to errors. impl axum::response::IntoResponse for ServerError { fn into_response(self) -> axum::response::Response { let r = match self { - // Error::CredentialLookup(e) => { - // tracing::debug!("Failed to look up credential: {e}"); - // ( - // StatusCode::NOT_FOUND, - // Json(format!("One or more credentials were not found: {e}")), - // ) - // } + ServerError::ParameterError => { + tracing::error!("Internal error: Unable to create parameter."); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json("Unable to create parameter.".to_string()), + ) + } + ServerError::SimulationInvokeError(error) => { + tracing::error!("Internal error: {error}"); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(format!("{}", error)), + ) + } + ServerError::SubmitSponsoredTransactionError(error) => { + tracing::error!("Internal error: {error}"); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(format!("{}", error)), + ) + } error => { tracing::debug!("Bad request: {error}"); (StatusCode::BAD_REQUEST, Json(format!("{}", error))) @@ -55,21 +67,13 @@ impl axum::response::IntoResponse for ServerError { } } +/// Struct to store the revert reason. #[derive(serde::Serialize, Debug)] pub struct RevertReason { + /// Smart contract revert reason. pub reason: RejectReason, } -#[derive(serde::Serialize)] -/// Response in case of an error. This is going to be encoded as a JSON body -/// with fields 'code' and 'message'. -pub struct ErrorResponse { - /// Code of the error. - pub code: u16, - /// Error message. - pub message: String, -} - /// Paramters passed from the front end to this back end when calling the API /// endpoint `/bid`. #[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] @@ -133,16 +137,18 @@ pub struct PermitMessage { pub payload: Vec, } -/// Server struct to keep track of the nonce of the sponsorer account and the +/// Server struct to store the contract addresses, the node client, +/// the nonce and key of the sponsorer account, and the /// rate_limits of user accounts. #[derive(Clone, Debug)] pub struct Server { - pub http_client: reqwest::Client, + /// Client to interact with the node. pub node_client: v2::Client, - pub network: Network, + /// Key and address of the sponsorer account. pub key: Arc, - pub crypto_params: Arc, + /// Contract address of the auction contract. pub auction_smart_contract: ContractAddress, + /// Contract address of the token contract. pub cis2_token_smart_contract: ContractAddress, /// Nonce of the sponsorer account. pub nonce: Arc>,