From 5df13a73706d2a030011b8ba1472ff3335f17ccc Mon Sep 17 00:00:00 2001 From: Eason Date: Wed, 15 Mar 2023 23:33:17 +0800 Subject: [PATCH 1/6] feat: add abi generator --- Cargo.lock | 248 ++++++++++++++++-- Cargo.toml | 3 +- .../abi/ckb_light_client_abi.json | 2 +- devtools/abi-generator/Cargo.toml | 11 + devtools/abi-generator/abi_generate.py | 28 ++ devtools/abi-generator/src/main.rs | 24 ++ devtools/genesis-generator/Cargo.toml | 4 +- 7 files changed, 297 insertions(+), 23 deletions(-) create mode 100644 devtools/abi-generator/Cargo.toml create mode 100644 devtools/abi-generator/abi_generate.py create mode 100644 devtools/abi-generator/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index b441ea228..85be6fe4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,6 +12,15 @@ dependencies = [ "regex", ] +[[package]] +name = "abi-generator" +version = "0.1.0" +dependencies = [ + "clap 4.1.8", + "ethers-contract 2.0.0", + "serde_json", +] + [[package]] name = "addr2line" version = "0.19.0" @@ -1271,6 +1280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" dependencies = [ "bitflags", + "clap_derive", "clap_lex 0.3.2", "is-terminal", "once_cell", @@ -1278,6 +1288,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "clap_derive" +version = "4.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "clap_lex" version = "0.2.4" @@ -1595,9 +1618,9 @@ dependencies = [ "ethabi 17.2.0", "ethabi-contract", "ethabi-derive", - "ethers-contract", + "ethers-contract 1.0.2", "ethers-core 1.0.2", - "ethers-providers", + "ethers-providers 1.0.2", "futures", "jsonrpc-core", "lazy_static", @@ -1637,7 +1660,7 @@ dependencies = [ "ethabi-contract", "ethabi-derive", "ethers", - "ethers-contract", + "ethers-contract 1.0.2", "ethers-core 1.0.2", "evm", "futures", @@ -1739,9 +1762,9 @@ dependencies = [ "common-apm", "core-executor", "core-storage", - "ethers-contract", + "ethers-contract 1.0.2", "ethers-core 1.0.2", - "ethers-providers", + "ethers-providers 1.0.2", "lazy_static", "parking_lot 0.12.1", "rand 0.7.3", @@ -2312,6 +2335,25 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "enr" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "492a7e5fc2504d5fdce8e124d3e263b244a68b283cac67a69eda0cd43e0aebad" +dependencies = [ + "base64 0.13.1", + "bs58", + "bytes", + "hex", + "k256", + "log", + "rand 0.8.5", + "rlp", + "serde", + "sha3", + "zeroize", +] + [[package]] name = "enum-repr-derive" version = "0.2.0" @@ -2536,11 +2578,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11f26f9d8d80da18ca72aca51804c65eb2153093af3bec74fd5ce32aa0c1f665" dependencies = [ "ethers-addressbook", - "ethers-contract", + "ethers-contract 1.0.2", "ethers-core 1.0.2", - "ethers-etherscan", + "ethers-etherscan 1.0.2", "ethers-middleware", - "ethers-providers", + "ethers-providers 1.0.2", "ethers-signers 1.0.2", ] @@ -2562,10 +2604,29 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9c3c3e119a89f0a9a1e539e7faecea815f74ddcf7c90d0b00d1f524db2fdc9c" dependencies = [ - "ethers-contract-abigen", - "ethers-contract-derive", + "ethers-contract-abigen 1.0.2", + "ethers-contract-derive 1.0.2", "ethers-core 1.0.2", - "ethers-providers", + "ethers-providers 1.0.2", + "futures-util", + "hex", + "once_cell", + "pin-project", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "ethers-contract" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be33fd47a06cc8f97caf614cf7cf91af9dd6dcd767511578895fa884b430c4b8" +dependencies = [ + "ethers-contract-abigen 2.0.0", + "ethers-contract-derive 2.0.0", + "ethers-core 2.0.0", + "ethers-providers 2.0.0", "futures-util", "hex", "once_cell", @@ -2600,13 +2661,41 @@ dependencies = [ "walkdir", ] +[[package]] +name = "ethers-contract-abigen" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60d9f9ecb4a18c1693de954404b66e0c9df31dac055b411645e38c4efebf3dbc" +dependencies = [ + "Inflector", + "cfg-if 1.0.0", + "dunce", + "ethers-core 2.0.0", + "ethers-etherscan 2.0.0", + "eyre", + "getrandom 0.2.8", + "hex", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "reqwest", + "serde", + "serde_json", + "syn", + "tokio", + "toml 0.5.11", + "url", + "walkdir", +] + [[package]] name = "ethers-contract-derive" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f192e8e4cf2b038318aae01e94e7644e0659a76219e94bcd3203df744341d61f" dependencies = [ - "ethers-contract-abigen", + "ethers-contract-abigen 1.0.2", "ethers-core 1.0.2", "hex", "proc-macro2", @@ -2615,6 +2704,22 @@ dependencies = [ "syn", ] +[[package]] +name = "ethers-contract-derive" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "001b33443a67e273120923df18bab907a0744ad4b5fef681a8b0691f2ee0f3de" +dependencies = [ + "ethers-contract-abigen 2.0.0", + "ethers-core 2.0.0", + "eyre", + "hex", + "proc-macro2", + "quote", + "serde_json", + "syn", +] + [[package]] name = "ethers-core" version = "1.0.2" @@ -2654,6 +2759,7 @@ checksum = "d5925cba515ac18eb5c798ddf6069cc33ae00916cb08ae64194364a1b35c100b" dependencies = [ "arrayvec", "bytes", + "cargo_metadata", "chrono", "convert_case 0.6.0", "elliptic-curve", @@ -2663,6 +2769,7 @@ dependencies = [ "hex", "k256", "num_enum", + "once_cell", "open-fastrlp", "proc-macro2", "rand 0.8.5", @@ -2695,6 +2802,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "ethers-etherscan" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d769437fafd0b47ea8b95e774e343c5195c77423f0f54b48d11c0d9ed2148ad" +dependencies = [ + "ethers-core 2.0.0", + "getrandom 0.2.8", + "reqwest", + "semver", + "serde", + "serde-aux", + "serde_json", + "thiserror", + "tracing", +] + [[package]] name = "ethers-middleware" version = "1.0.2" @@ -2703,10 +2827,10 @@ checksum = "e71df7391b0a9a51208ffb5c7f2d068900e99d6b3128d3a4849d138f194778b7" dependencies = [ "async-trait", "auto_impl 0.5.0", - "ethers-contract", + "ethers-contract 1.0.2", "ethers-core 1.0.2", - "ethers-etherscan", - "ethers-providers", + "ethers-etherscan 1.0.2", + "ethers-providers 1.0.2", "ethers-signers 1.0.2", "futures-locks", "futures-util", @@ -2747,7 +2871,45 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "tokio-tungstenite", + "tokio-tungstenite 0.17.2", + "tracing", + "tracing-futures", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-timer", + "web-sys", + "ws_stream_wasm", +] + +[[package]] +name = "ethers-providers" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7174af93619e81844d3d49887106a3721e5caecdf306e0b824bfb4316db3be" +dependencies = [ + "async-trait", + "auto_impl 1.0.1", + "base64 0.21.0", + "enr", + "ethers-core 2.0.0", + "futures-channel", + "futures-core", + "futures-timer", + "futures-util", + "getrandom 0.2.8", + "hashers", + "hex", + "http", + "once_cell", + "parking_lot 0.11.2", + "pin-project", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-tungstenite 0.18.0", "tracing", "tracing-futures", "url", @@ -3173,9 +3335,9 @@ dependencies = [ "common-crypto", "core-executor", "core-metadata", - "ethers-contract", + "ethers-contract 2.0.0", "ethers-core 1.0.2", - "ethers-providers", + "ethers-providers 2.0.0", "ophelia", "rand 0.7.3", "serde", @@ -5844,6 +6006,17 @@ dependencies = [ "digest 0.10.6", ] +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.6", +] + [[package]] name = "sha2" version = "0.8.2" @@ -6452,7 +6625,23 @@ dependencies = [ "rustls", "tokio", "tokio-rustls", - "tungstenite", + "tungstenite 0.17.3", + "webpki", + "webpki-roots", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" +dependencies = [ + "futures-util", + "log", + "rustls", + "tokio", + "tokio-rustls", + "tungstenite 0.18.0", "webpki", "webpki-roots", ] @@ -6680,6 +6869,27 @@ dependencies = [ "webpki", ] +[[package]] +name = "tungstenite" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788" +dependencies = [ + "base64 0.13.1", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "rand 0.8.5", + "rustls", + "sha1", + "thiserror", + "url", + "utf-8", + "webpki", +] + [[package]] name = "typemap-ors" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 5fdb572a4..1eec9feb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,8 +38,9 @@ members = [ "core/rpc-client", "core/run", "core/storage", - "core/tx-assembler", + + "devtools/abi-generator", "devtools/genesis-generator", "devtools/keypair", diff --git a/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.json b/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.json index d7b185ea7..b5acbd078 100644 --- a/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.json +++ b/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.json @@ -3,7 +3,7 @@ "inputs": [ { "internalType": "bytes32[]", - "name": "blockHashs", + "name": "blockHashes", "type": "bytes32[]" } ], diff --git a/devtools/abi-generator/Cargo.toml b/devtools/abi-generator/Cargo.toml new file mode 100644 index 000000000..ec38b4538 --- /dev/null +++ b/devtools/abi-generator/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "abi-generator" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.1", features = ["derive"] } +ethers-contract = { version = "2.0", features = ["abigen"] } +serde_json = "1.0" diff --git a/devtools/abi-generator/abi_generate.py b/devtools/abi-generator/abi_generate.py new file mode 100644 index 000000000..fd86d0978 --- /dev/null +++ b/devtools/abi-generator/abi_generate.py @@ -0,0 +1,28 @@ +import subprocess + + +def main(): + cmd_args = [ + [ + "MetadataContract", + "core/executor/src/system_contract/metadata/abi/metadata_abi.json", + "core/executor/src/system_contract/metadata/abi/metadata_abi.rs", + ], + [ + "CkbLightClientContract", + "core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.json", + "core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.rs", + ], + [ + "ImageCellContract", + "core/executor/src/system_contract/image_cell/abi/image_cell_abi.json", + "core/executor/src/system_contract/image_cell/abi/image_cell_abi.rs", + ], + ] + cargo_run = "cargo run".split(" ") + for args in cmd_args: + subprocess.Popen(cargo_run + ["-c", args[0], "-j", args[1], "-o", args[2]]) + + +if __name__ == "__main__": + main() diff --git a/devtools/abi-generator/src/main.rs b/devtools/abi-generator/src/main.rs new file mode 100644 index 000000000..ef1d5dbb8 --- /dev/null +++ b/devtools/abi-generator/src/main.rs @@ -0,0 +1,24 @@ +use std::error::Error; + +use clap::Parser; +use ethers_contract::Abigen; + +#[derive(Clone, Debug, Parser)] +struct Args { + #[arg(short = 'c', long)] + contract_name: String, + + #[arg(short = 'j', long)] + json_abi_path: String, + + #[arg(short = 'o', long)] + output_file_path: String, +} + +fn main() -> Result<(), Box> { + let args = Args::parse(); + Abigen::new(args.contract_name, args.json_abi_path)? + .generate()? + .write_to_file(args.output_file_path)?; + Ok(()) +} diff --git a/devtools/genesis-generator/Cargo.toml b/devtools/genesis-generator/Cargo.toml index 34bb33f40..e9a6de363 100644 --- a/devtools/genesis-generator/Cargo.toml +++ b/devtools/genesis-generator/Cargo.toml @@ -12,9 +12,9 @@ common-config-parser = { path = "../../common/config-parser" } common-crypto = { path = "../../common/crypto" } core-executor = { path = "../../core/executor" } core-metadata = { path = "../../core/metadata" } -ethers-contract = { version = "1.0", features = ["abigen"] } +ethers-contract = { version = "2.0", features = ["abigen"] } ethers-core = "1.0" -ethers-providers = "1.0" +ethers-providers = "2.0" ophelia = "0.3" protocol = { path = "../../protocol", package = "axon-protocol" } rand = "0.7" From 97c2df2160c2328dc761c29272923fd21e105be2 Mon Sep 17 00:00:00 2001 From: Eason Date: Wed, 15 Mar 2023 23:50:45 +0800 Subject: [PATCH 2/6] feat: re-generate rust abi binding --- Cargo.lock | 107 ++--- core/executor/Cargo.toml | 4 +- .../abi/ckb_light_client_abi.rs | 219 ++++----- .../system_contract/ckb_light_client/mod.rs | 8 +- .../system_contract/ckb_light_client/store.rs | 2 +- .../image_cell/abi/image_cell_abi.rs | 251 ++++++----- .../src/system_contract/image_cell/mod.rs | 8 +- .../metadata/abi/metadata_abi.rs | 418 +++++++++--------- .../tests/system_script/ckb_light_client.rs | 4 +- core/interoperation/Cargo.toml | 2 +- devtools/abi-generator/Cargo.toml | 2 +- devtools/abi-generator/abi_generate.py | 14 +- devtools/abi-generator/src/main.rs | 2 +- 13 files changed, 512 insertions(+), 529 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85be6fe4a..a564247ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,7 +17,7 @@ name = "abi-generator" version = "0.1.0" dependencies = [ "clap 4.1.8", - "ethers-contract 2.0.0", + "ethers", "serde_json", ] @@ -175,18 +175,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "auto_impl" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7862e21c893d65a1650125d157eaeec691439379a1cee17ee49031b79236ada4" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "auto_impl" version = "1.0.1" @@ -1660,8 +1648,6 @@ dependencies = [ "ethabi-contract", "ethabi-derive", "ethers", - "ethers-contract 1.0.2", - "ethers-core 1.0.2", "evm", "futures", "getrandom 0.2.8", @@ -1722,7 +1708,7 @@ dependencies = [ "core-rpc-client", "core-storage", "ed25519-dalek", - "ethers-core 1.0.2", + "ethers-core 2.0.0", "lazy_static", "log", "rand 0.7.3", @@ -1835,7 +1821,7 @@ dependencies = [ "core-rpc-client", "core-storage", "core-tx-assembler", - "ethers-signers 2.0.0", + "ethers-signers", "futures", "log", "rlp", @@ -2573,26 +2559,26 @@ dependencies = [ [[package]] name = "ethers" -version = "1.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11f26f9d8d80da18ca72aca51804c65eb2153093af3bec74fd5ce32aa0c1f665" +checksum = "839a392641e746a1ff365ef7c901238410b5c6285d240cf2409ffaaa7df9a78a" dependencies = [ "ethers-addressbook", - "ethers-contract 1.0.2", - "ethers-core 1.0.2", - "ethers-etherscan 1.0.2", + "ethers-contract 2.0.0", + "ethers-core 2.0.0", + "ethers-etherscan", "ethers-middleware", - "ethers-providers 1.0.2", - "ethers-signers 1.0.2", + "ethers-providers 2.0.0", + "ethers-signers", ] [[package]] name = "ethers-addressbook" -version = "1.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4be54dd2260945d784e06ccdeb5ad573e8f1541838cee13a1ab885485eaa0b" +checksum = "9e1e010165c08a2a3fa43c0bb8bc9d596f079a021aaa2cc4e8d921df09709c95" dependencies = [ - "ethers-core 1.0.2", + "ethers-core 2.0.0", "once_cell", "serde", "serde_json", @@ -2671,7 +2657,7 @@ dependencies = [ "cfg-if 1.0.0", "dunce", "ethers-core 2.0.0", - "ethers-etherscan 2.0.0", + "ethers-etherscan", "eyre", "getrandom 0.2.8", "hex", @@ -2730,7 +2716,6 @@ dependencies = [ "bytes", "cargo_metadata", "chrono", - "convert_case 0.6.0", "elliptic-curve", "ethabi 18.0.0", "generic-array 0.14.6", @@ -2738,7 +2723,6 @@ dependencies = [ "k256", "once_cell", "open-fastrlp", - "proc-macro2", "rand 0.8.5", "rlp", "rlp-derive", @@ -2785,23 +2769,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "ethers-etherscan" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9713f525348e5dde025d09b0a4217429f8074e8ff22c886263cc191e87d8216" -dependencies = [ - "ethers-core 1.0.2", - "getrandom 0.2.8", - "reqwest", - "semver", - "serde", - "serde-aux", - "serde_json", - "thiserror", - "tracing", -] - [[package]] name = "ethers-etherscan" version = "2.0.0" @@ -2821,17 +2788,17 @@ dependencies = [ [[package]] name = "ethers-middleware" -version = "1.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e71df7391b0a9a51208ffb5c7f2d068900e99d6b3128d3a4849d138f194778b7" +checksum = "a7dd311b76eab9d15209e4fd16bb419e25543709cbdf33079e8923dfa597517c" dependencies = [ "async-trait", - "auto_impl 0.5.0", - "ethers-contract 1.0.2", - "ethers-core 1.0.2", - "ethers-etherscan 1.0.2", - "ethers-providers 1.0.2", - "ethers-signers 1.0.2", + "auto_impl", + "ethers-contract 2.0.0", + "ethers-core 2.0.0", + "ethers-etherscan", + "ethers-providers 2.0.0", + "ethers-signers", "futures-locks", "futures-util", "instant", @@ -2852,7 +2819,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1a9e0597aa6b2fdc810ff58bc95e4eeaa2c219b3e615ed025106ecb027407d8" dependencies = [ "async-trait", - "auto_impl 1.0.1", + "auto_impl", "base64 0.13.1", "ethers-core 1.0.2", "futures-channel", @@ -2889,7 +2856,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed7174af93619e81844d3d49887106a3721e5caecdf306e0b824bfb4316db3be" dependencies = [ "async-trait", - "auto_impl 1.0.1", + "auto_impl", "base64 0.21.0", "enr", "ethers-core 2.0.0", @@ -2920,24 +2887,6 @@ dependencies = [ "ws_stream_wasm", ] -[[package]] -name = "ethers-signers" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f41ced186867f64773db2e55ffdd92959e094072a1d09a5e5e831d443204f98" -dependencies = [ - "async-trait", - "coins-bip32", - "coins-bip39", - "elliptic-curve", - "eth-keystore", - "ethers-core 1.0.2", - "hex", - "rand 0.8.5", - "sha2 0.10.6", - "thiserror", -] - [[package]] name = "ethers-signers" version = "2.0.0" @@ -2963,7 +2912,7 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4448c65b71e8e2b9718232d84d09045eeaaccb2320494e6bd6dbf7e58fec8ff" dependencies = [ - "auto_impl 1.0.1", + "auto_impl", "environmental", "ethereum", "evm-core", @@ -3008,7 +2957,7 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c79b9459ce64f1a28688397c4013764ce53cd57bb84efc16b5187fa9b05b13ad" dependencies = [ - "auto_impl 1.0.1", + "auto_impl", "environmental", "evm-core", "primitive-types 0.12.1", @@ -4537,7 +4486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" dependencies = [ "arrayvec", - "auto_impl 1.0.1", + "auto_impl", "bytes", "ethereum-types 0.14.1", "open-fastrlp-derive", @@ -5457,7 +5406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73d84c8f9836efb0f5f5f8de4700a953c4e1f3119e5cfcb0aad8e5be73daf991" dependencies = [ "arrayref", - "auto_impl 1.0.1", + "auto_impl", "bytes", "hashbrown 0.13.2", "num_enum", diff --git a/core/executor/Cargo.toml b/core/executor/Cargo.toml index 060c693d3..9f5fe4da8 100644 --- a/core/executor/Cargo.toml +++ b/core/executor/Cargo.toml @@ -16,7 +16,7 @@ common-config-parser = { path = "../../common/config-parser" } common-crypto = { path = "../../common/crypto" } common-merkle = { path = "../../common/merkle" } core-interoperation = { path = "../interoperation" } -ethers = "1.0" +ethers = "2.0" evm = { version = "0.37", features = ["tracing"] } futures = "0.3" hasher = "0.1" @@ -48,8 +48,6 @@ criterion = "0.4" ethabi = "18.0" ethabi-contract = { git = "https://github.com/rust-ethereum/ethabi.git", rev = "7edf185" } ethabi-derive = { git = "https://github.com/rust-ethereum/ethabi.git", rev = "7edf185" } -ethers-contract = "1.0" -ethers-core = "1.0" getrandom = "0.2" hashbrown = "0.13" rand7 = { package = "rand", version = "0.7" } diff --git a/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.rs b/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.rs index bb098e50f..9381ca142 100644 --- a/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.rs +++ b/core/executor/src/system_contract/ckb_light_client/abi/ckb_light_client_abi.rs @@ -1,131 +1,143 @@ -pub use ckb_light_client::*; -#[allow(clippy::too_many_arguments, non_camel_case_types)] -pub mod ckb_light_client { - #![allow(clippy::enum_variant_names)] - #![allow(dead_code)] - #![allow(clippy::type_complexity)] - #![allow(unused_imports)] - use ethers::contract::{ - builders::{ContractCall, Event}, - Contract, Lazy, - }; - use ethers::core::{ - abi::{Abi, Detokenize, InvalidOutputType, Token, Tokenizable}, - types::*, - }; - use ethers::providers::Middleware; - #[doc = "CkbLightClient was auto-generated with ethers-rs Abigen. More information at: https://github.com/gakonst/ethers-rs"] - use std::sync::Arc; - # [rustfmt :: skip] const __ABI : & str = "[\n {\n \"inputs\": [\n {\n \"internalType\": \"bytes32[]\",\n \"name\": \"blockHashs\",\n \"type\": \"bytes32[]\"\n }\n ],\n \"name\": \"rollback\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"internalType\": \"bool\",\n \"name\": \"allowRead\",\n \"type\": \"bool\"\n }\n ],\n \"name\": \"setState\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"components\": [\n {\n \"internalType\": \"uint32\",\n \"name\": \"version\",\n \"type\": \"uint32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"compactTarget\",\n \"type\": \"uint32\"\n },\n {\n \"internalType\": \"uint64\",\n \"name\": \"timestamp\",\n \"type\": \"uint64\"\n },\n {\n \"internalType\": \"uint64\",\n \"name\": \"number\",\n \"type\": \"uint64\"\n },\n {\n \"internalType\": \"uint64\",\n \"name\": \"epoch\",\n \"type\": \"uint64\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"parentHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"transactionsRoot\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"proposalsHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"unclesHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"dao\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint128\",\n \"name\": \"nonce\",\n \"type\": \"uint128\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"blockHash\",\n \"type\": \"bytes32\"\n }\n ],\n \"internalType\": \"struct CkbType.Header[]\",\n \"name\": \"headers\",\n \"type\": \"tuple[]\"\n }\n ],\n \"name\": \"update\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n }\n]" ; - #[doc = r" The parsed JSON-ABI of the contract."] - pub static CKBLIGHTCLIENT_ABI: ethers::contract::Lazy = - ethers::contract::Lazy::new(|| { - ethers::core::utils::__serde_json::from_str(__ABI).expect("invalid abi") +pub use ckb_light_client_contract::*; +/// This module was auto-generated with ethers-rs Abigen. +/// More information at: +#[allow( + clippy::enum_variant_names, + clippy::too_many_arguments, + clippy::upper_case_acronyms, + clippy::type_complexity, + dead_code, + non_camel_case_types +)] +pub mod ckb_light_client_contract { + #[rustfmt::skip] + const __ABI: &str = "[\n {\n \"inputs\": [\n {\n \"internalType\": \"bytes32[]\",\n \"name\": \"blockHashes\",\n \"type\": \"bytes32[]\"\n }\n ],\n \"name\": \"rollback\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"internalType\": \"bool\",\n \"name\": \"allowRead\",\n \"type\": \"bool\"\n }\n ],\n \"name\": \"setState\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"components\": [\n {\n \"internalType\": \"uint32\",\n \"name\": \"version\",\n \"type\": \"uint32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"compactTarget\",\n \"type\": \"uint32\"\n },\n {\n \"internalType\": \"uint64\",\n \"name\": \"timestamp\",\n \"type\": \"uint64\"\n },\n {\n \"internalType\": \"uint64\",\n \"name\": \"number\",\n \"type\": \"uint64\"\n },\n {\n \"internalType\": \"uint64\",\n \"name\": \"epoch\",\n \"type\": \"uint64\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"parentHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"transactionsRoot\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"proposalsHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"unclesHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"dao\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint128\",\n \"name\": \"nonce\",\n \"type\": \"uint128\"\n },\n {\n \"internalType\": \"bytes32\",\n \"name\": \"blockHash\",\n \"type\": \"bytes32\"\n }\n ],\n \"internalType\": \"struct CkbType.Header[]\",\n \"name\": \"headers\",\n \"type\": \"tuple[]\"\n }\n ],\n \"name\": \"update\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n }\n]\n"; + /// The parsed JSON ABI of the contract. + pub static CKBLIGHTCLIENTCONTRACT_ABI: ::ethers::contract::Lazy<::ethers::core::abi::Abi> = + ::ethers::contract::Lazy::new(|| { + ::ethers::core::utils::__serde_json::from_str(__ABI).expect("ABI is always valid") }); - pub struct CkbLightClient(ethers::contract::Contract); - impl Clone for CkbLightClient { + pub struct CkbLightClientContract(::ethers::contract::Contract); + impl ::core::clone::Clone for CkbLightClientContract { fn clone(&self) -> Self { - CkbLightClient(self.0.clone()) + Self(::core::clone::Clone::clone(&self.0)) } } - impl std::ops::Deref for CkbLightClient { - type Target = ethers::contract::Contract; + impl ::core::ops::Deref for CkbLightClientContract { + type Target = ::ethers::contract::Contract; fn deref(&self) -> &Self::Target { &self.0 } } - impl std::fmt::Debug for CkbLightClient { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_tuple(stringify!(CkbLightClient)) + impl ::core::ops::DerefMut for CkbLightClientContract { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } + } + impl ::core::fmt::Debug for CkbLightClientContract { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_tuple(stringify!(CkbLightClientContract)) .field(&self.address()) .finish() } } - impl CkbLightClient { - #[doc = r" Creates a new contract instance with the specified `ethers`"] - #[doc = r" client at the given `Address`. The contract derefs to a `ethers::Contract`"] - #[doc = r" object"] - pub fn new>( + impl CkbLightClientContract { + /// Creates a new contract instance with the specified `ethers` client + /// at `address`. The contract derefs to a `ethers::Contract` + /// object. + pub fn new>( address: T, client: ::std::sync::Arc, ) -> Self { - ethers::contract::Contract::new(address.into(), CKBLIGHTCLIENT_ABI.clone(), client) - .into() + Self(::ethers::contract::Contract::new( + address.into(), + CKBLIGHTCLIENTCONTRACT_ABI.clone(), + client, + )) } - #[doc = "Calls the contract's `rollback` (0xd32a2285) function"] + /// Calls the contract's `rollback` (0xd32a2285) function pub fn rollback( &self, - block_hashs: ::std::vec::Vec<[u8; 32]>, - ) -> ethers::contract::builders::ContractCall { + block_hashes: ::std::vec::Vec<[u8; 32]>, + ) -> ::ethers::contract::builders::ContractCall { self.0 - .method_hash([211, 42, 34, 133], block_hashs) + .method_hash([211, 42, 34, 133], block_hashes) .expect("method not found (this should never happen)") } - #[doc = "Calls the contract's `setState` (0xac9f0222) function"] + /// Calls the contract's `setState` (0xac9f0222) function pub fn set_state( &self, allow_read: bool, - ) -> ethers::contract::builders::ContractCall { + ) -> ::ethers::contract::builders::ContractCall { self.0 .method_hash([172, 159, 2, 34], allow_read) .expect("method not found (this should never happen)") } - #[doc = "Calls the contract's `update` (0x2b196cf3) function"] + /// Calls the contract's `update` (0x2b196cf3) function pub fn update( &self, headers: ::std::vec::Vec
, - ) -> ethers::contract::builders::ContractCall { + ) -> ::ethers::contract::builders::ContractCall { self.0 .method_hash([43, 25, 108, 243], headers) .expect("method not found (this should never happen)") } } - impl From> for CkbLightClient { - fn from(contract: ethers::contract::Contract) -> Self { - Self(contract) + impl From<::ethers::contract::Contract> + for CkbLightClientContract + { + fn from(contract: ::ethers::contract::Contract) -> Self { + Self::new(contract.address(), contract.client()) } } - #[doc = "Container type for all input parameters for the `rollback` function with signature `rollback(bytes32[])` and selector `[211, 42, 34, 133]`"] + /// Container type for all input parameters for the `rollback` function with + /// signature `rollback(bytes32[])` and selector `0xd32a2285` #[derive( Clone, + ::ethers::contract::EthCall, + ::ethers::contract::EthDisplay, + Default, Debug, - Eq, PartialEq, - ethers::contract::EthCall, - ethers::contract::EthDisplay, - Default, + Eq, + Hash, )] #[ethcall(name = "rollback", abi = "rollback(bytes32[])")] pub struct RollbackCall { - pub block_hashs: ::std::vec::Vec<[u8; 32]>, + pub block_hashes: ::std::vec::Vec<[u8; 32]>, } - #[doc = "Container type for all input parameters for the `setState` function with signature `setState(bool)` and selector `[172, 159, 2, 34]`"] + /// Container type for all input parameters for the `setState` function with + /// signature `setState(bool)` and selector `0xac9f0222` #[derive( Clone, + ::ethers::contract::EthCall, + ::ethers::contract::EthDisplay, + Default, Debug, - Eq, PartialEq, - ethers::contract::EthCall, - ethers::contract::EthDisplay, - Default, + Eq, + Hash, )] #[ethcall(name = "setState", abi = "setState(bool)")] pub struct SetStateCall { pub allow_read: bool, } - #[doc = "Container type for all input parameters for the `update` function with signature `update((uint32,uint32,uint64,uint64,uint64,bytes32,bytes32,bytes32,bytes32,bytes32,uint128,bytes32)[])` and selector `[43, 25, 108, 243]`"] + /// Container type for all input parameters for the `update` function with + /// signature `update((uint32,uint32,uint64,uint64,uint64,bytes32,bytes32, + /// bytes32,bytes32,bytes32,uint128,bytes32)[])` and selector `0x2b196cf3` #[derive( Clone, + ::ethers::contract::EthCall, + ::ethers::contract::EthDisplay, + Default, Debug, - Eq, PartialEq, - ethers::contract::EthCall, - ethers::contract::EthDisplay, - Default, + Eq, + Hash, )] #[ethcall( name = "update", @@ -134,75 +146,74 @@ pub mod ckb_light_client { pub struct UpdateCall { pub headers: ::std::vec::Vec
, } - #[derive(Debug, Clone, PartialEq, Eq, ethers::contract::EthAbiType)] - pub enum CkbLightClientCalls { + /// Container type for all of the contract's call + #[derive(Clone, ::ethers::contract::EthAbiType, Debug, PartialEq, Eq, Hash)] + pub enum CkbLightClientContractCalls { Rollback(RollbackCall), SetState(SetStateCall), Update(UpdateCall), } - impl ethers::core::abi::AbiDecode for CkbLightClientCalls { + impl ::ethers::core::abi::AbiDecode for CkbLightClientContractCalls { fn decode( data: impl AsRef<[u8]>, - ) -> ::std::result::Result { - if let Ok(decoded) = - ::decode(data.as_ref()) - { - return Ok(CkbLightClientCalls::Rollback(decoded)); + ) -> ::core::result::Result { + let data = data.as_ref(); + if let Ok(decoded) = ::decode(data) { + return Ok(Self::Rollback(decoded)); } - if let Ok(decoded) = - ::decode(data.as_ref()) - { - return Ok(CkbLightClientCalls::SetState(decoded)); + if let Ok(decoded) = ::decode(data) { + return Ok(Self::SetState(decoded)); } - if let Ok(decoded) = ::decode(data.as_ref()) - { - return Ok(CkbLightClientCalls::Update(decoded)); + if let Ok(decoded) = ::decode(data) { + return Ok(Self::Update(decoded)); } - Err(ethers::core::abi::Error::InvalidData.into()) + Err(::ethers::core::abi::Error::InvalidData.into()) } } - impl ethers::core::abi::AbiEncode for CkbLightClientCalls { + impl ::ethers::core::abi::AbiEncode for CkbLightClientContractCalls { fn encode(self) -> Vec { match self { - CkbLightClientCalls::Rollback(element) => element.encode(), - CkbLightClientCalls::SetState(element) => element.encode(), - CkbLightClientCalls::Update(element) => element.encode(), + Self::Rollback(element) => ::ethers::core::abi::AbiEncode::encode(element), + Self::SetState(element) => ::ethers::core::abi::AbiEncode::encode(element), + Self::Update(element) => ::ethers::core::abi::AbiEncode::encode(element), } } } - impl ::std::fmt::Display for CkbLightClientCalls { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + impl ::core::fmt::Display for CkbLightClientContractCalls { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { match self { - CkbLightClientCalls::Rollback(element) => element.fmt(f), - CkbLightClientCalls::SetState(element) => element.fmt(f), - CkbLightClientCalls::Update(element) => element.fmt(f), + Self::Rollback(element) => ::core::fmt::Display::fmt(element, f), + Self::SetState(element) => ::core::fmt::Display::fmt(element, f), + Self::Update(element) => ::core::fmt::Display::fmt(element, f), } } } - impl ::std::convert::From for CkbLightClientCalls { - fn from(var: RollbackCall) -> Self { - CkbLightClientCalls::Rollback(var) + impl ::core::convert::From for CkbLightClientContractCalls { + fn from(value: RollbackCall) -> Self { + Self::Rollback(value) } } - impl ::std::convert::From for CkbLightClientCalls { - fn from(var: SetStateCall) -> Self { - CkbLightClientCalls::SetState(var) + impl ::core::convert::From for CkbLightClientContractCalls { + fn from(value: SetStateCall) -> Self { + Self::SetState(value) } } - impl ::std::convert::From for CkbLightClientCalls { - fn from(var: UpdateCall) -> Self { - CkbLightClientCalls::Update(var) + impl ::core::convert::From for CkbLightClientContractCalls { + fn from(value: UpdateCall) -> Self { + Self::Update(value) } } - #[doc = "`Header(uint32,uint32,uint64,uint64,uint64,bytes32,bytes32,bytes32,bytes32,bytes32,uint128,bytes32)`"] + /// `Header(uint32,uint32,uint64,uint64,uint64,bytes32,bytes32,bytes32, + /// bytes32,bytes32,uint128,bytes32)` #[derive( Clone, - Debug, + ::ethers::contract::EthAbiType, + ::ethers::contract::EthAbiCodec, Default, - Eq, + Debug, PartialEq, - ethers::contract::EthAbiType, - ethers::contract::EthAbiCodec, + Eq, + Hash, )] pub struct Header { pub version: u32, diff --git a/core/executor/src/system_contract/ckb_light_client/mod.rs b/core/executor/src/system_contract/ckb_light_client/mod.rs index 0fccc48e1..e102dc3cb 100644 --- a/core/executor/src/system_contract/ckb_light_client/mod.rs +++ b/core/executor/src/system_contract/ckb_light_client/mod.rs @@ -36,23 +36,23 @@ impl SystemContract for CkbLightClientContract { ); let call_abi = exec_try!( - ckb_light_client_abi::CkbLightClientCalls::decode(tx_data), + ckb_light_client_abi::CkbLightClientContractCalls::decode(tx_data), gas_limit, "[ckb light client] invalid tx data" ); match call_abi { - ckb_light_client_abi::CkbLightClientCalls::SetState(data) => { + ckb_light_client_abi::CkbLightClientContractCalls::SetState(data) => { ALLOW_READ.store(data.allow_read, Ordering::Relaxed); } - ckb_light_client_abi::CkbLightClientCalls::Update(data) => { + ckb_light_client_abi::CkbLightClientContractCalls::Update(data) => { exec_try!( store.update(data), gas_limit, "[ckb light client] update error:" ); } - ckb_light_client_abi::CkbLightClientCalls::Rollback(data) => { + ckb_light_client_abi::CkbLightClientContractCalls::Rollback(data) => { exec_try!( store.rollback(data), gas_limit, diff --git a/core/executor/src/system_contract/ckb_light_client/store.rs b/core/executor/src/system_contract/ckb_light_client/store.rs index 7e090e20b..b2c120c15 100644 --- a/core/executor/src/system_contract/ckb_light_client/store.rs +++ b/core/executor/src/system_contract/ckb_light_client/store.rs @@ -45,7 +45,7 @@ impl CkbLightClientStore { } pub fn rollback(&mut self, data: ckb_light_client_abi::RollbackCall) -> ProtocolResult<()> { - for block_hash in data.block_hashs { + for block_hash in data.block_hashes { self.remove_header(&block_hash)?; } diff --git a/core/executor/src/system_contract/image_cell/abi/image_cell_abi.rs b/core/executor/src/system_contract/image_cell/abi/image_cell_abi.rs index 5cd933631..b8220f5c7 100644 --- a/core/executor/src/system_contract/image_cell/abi/image_cell_abi.rs +++ b/core/executor/src/system_contract/image_cell/abi/image_cell_abi.rs @@ -1,105 +1,114 @@ -pub use image_cell::*; -#[allow(clippy::too_many_arguments, non_camel_case_types)] -pub mod image_cell { - #![allow(clippy::enum_variant_names)] - #![allow(dead_code)] - #![allow(clippy::type_complexity)] - #![allow(unused_imports)] - use ethers::contract::{ - builders::{ContractCall, Event}, - Contract, Lazy, - }; - use ethers::core::{ - abi::{Abi, Detokenize, InvalidOutputType, Token, Tokenizable}, - types::*, - }; - use ethers::providers::Middleware; - #[doc = "ImageCell was auto-generated with ethers-rs Abigen. More information at: https://github.com/gakonst/ethers-rs"] - use std::sync::Arc; - # [rustfmt::skip] const __ABI: & str = "[\n {\n \"inputs\": [\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint[]\",\n \"name\": \"inputs\",\n \"type\": \"tuple[]\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint[]\",\n \"name\": \"outputs\",\n \"type\": \"tuple[]\"\n }\n ],\n \"name\": \"rollback\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"internalType\": \"bool\",\n \"name\": \"allowRead\",\n \"type\": \"bool\"\n }\n ],\n \"name\": \"setState\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"internalType\": \"uint64\",\n \"name\": \"blockNumber\",\n \"type\": \"uint64\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint[]\",\n \"name\": \"inputs\",\n \"type\": \"tuple[]\"\n },\n {\n \"components\": [\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint\",\n \"name\": \"outPoint\",\n \"type\": \"tuple\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"uint64\",\n \"name\": \"capacity\",\n \"type\": \"uint64\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"codeHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"enum CkbType.ScriptHashType\",\n \"name\": \"hashType\",\n \"type\": \"uint8\"\n },\n {\n \"internalType\": \"bytes\",\n \"name\": \"args\",\n \"type\": \"bytes\"\n }\n ],\n \"internalType\": \"struct CkbType.Script\",\n \"name\": \"lock\",\n \"type\": \"tuple\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"codeHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"enum CkbType.ScriptHashType\",\n \"name\": \"hashType\",\n \"type\": \"uint8\"\n },\n {\n \"internalType\": \"bytes\",\n \"name\": \"args\",\n \"type\": \"bytes\"\n }\n ],\n \"internalType\": \"struct CkbType.Script[]\",\n \"name\": \"type_\",\n \"type\": \"tuple[]\"\n }\n ],\n \"internalType\": \"struct CkbType.CellOutput\",\n \"name\": \"output\",\n \"type\": \"tuple\"\n },\n {\n \"internalType\": \"bytes\",\n \"name\": \"data\",\n \"type\": \"bytes\"\n }\n ],\n \"internalType\": \"struct CkbType.CellInfo[]\",\n \"name\": \"outputs\",\n \"type\": \"tuple[]\"\n }\n ],\n \"name\": \"update\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n }\n]\n" ; - #[doc = r" The parsed JSON-ABI of the contract."] - pub static IMAGECELL_ABI: ethers::contract::Lazy = - ethers::contract::Lazy::new(|| { - ethers::core::utils::__serde_json::from_str(__ABI).expect("invalid abi") +pub use image_cell_contract::*; +/// This module was auto-generated with ethers-rs Abigen. +/// More information at: +#[allow( + clippy::enum_variant_names, + clippy::too_many_arguments, + clippy::upper_case_acronyms, + clippy::type_complexity, + dead_code, + non_camel_case_types +)] +pub mod image_cell_contract { + #[rustfmt::skip] + const __ABI: &str = "[\n {\n \"inputs\": [\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint[]\",\n \"name\": \"inputs\",\n \"type\": \"tuple[]\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint[]\",\n \"name\": \"outputs\",\n \"type\": \"tuple[]\"\n }\n ],\n \"name\": \"rollback\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"internalType\": \"bool\",\n \"name\": \"allowRead\",\n \"type\": \"bool\"\n }\n ],\n \"name\": \"setState\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n },\n {\n \"inputs\": [\n {\n \"internalType\": \"uint64\",\n \"name\": \"blockNumber\",\n \"type\": \"uint64\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint[]\",\n \"name\": \"inputs\",\n \"type\": \"tuple[]\"\n },\n {\n \"components\": [\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"txHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"uint32\",\n \"name\": \"index\",\n \"type\": \"uint32\"\n }\n ],\n \"internalType\": \"struct CkbType.OutPoint\",\n \"name\": \"outPoint\",\n \"type\": \"tuple\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"uint64\",\n \"name\": \"capacity\",\n \"type\": \"uint64\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"codeHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"enum CkbType.ScriptHashType\",\n \"name\": \"hashType\",\n \"type\": \"uint8\"\n },\n {\n \"internalType\": \"bytes\",\n \"name\": \"args\",\n \"type\": \"bytes\"\n }\n ],\n \"internalType\": \"struct CkbType.Script\",\n \"name\": \"lock\",\n \"type\": \"tuple\"\n },\n {\n \"components\": [\n {\n \"internalType\": \"bytes32\",\n \"name\": \"codeHash\",\n \"type\": \"bytes32\"\n },\n {\n \"internalType\": \"enum CkbType.ScriptHashType\",\n \"name\": \"hashType\",\n \"type\": \"uint8\"\n },\n {\n \"internalType\": \"bytes\",\n \"name\": \"args\",\n \"type\": \"bytes\"\n }\n ],\n \"internalType\": \"struct CkbType.Script[]\",\n \"name\": \"type_\",\n \"type\": \"tuple[]\"\n }\n ],\n \"internalType\": \"struct CkbType.CellOutput\",\n \"name\": \"output\",\n \"type\": \"tuple\"\n },\n {\n \"internalType\": \"bytes\",\n \"name\": \"data\",\n \"type\": \"bytes\"\n }\n ],\n \"internalType\": \"struct CkbType.CellInfo[]\",\n \"name\": \"outputs\",\n \"type\": \"tuple[]\"\n }\n ],\n \"name\": \"update\",\n \"outputs\": [],\n \"stateMutability\": \"view\",\n \"type\": \"function\"\n }\n]\n"; + /// The parsed JSON ABI of the contract. + pub static IMAGECELLCONTRACT_ABI: ::ethers::contract::Lazy<::ethers::core::abi::Abi> = + ::ethers::contract::Lazy::new(|| { + ::ethers::core::utils::__serde_json::from_str(__ABI).expect("ABI is always valid") }); - pub struct ImageCell(ethers::contract::Contract); - impl Clone for ImageCell { + pub struct ImageCellContract(::ethers::contract::Contract); + impl ::core::clone::Clone for ImageCellContract { fn clone(&self) -> Self { - ImageCell(self.0.clone()) + Self(::core::clone::Clone::clone(&self.0)) } } - impl std::ops::Deref for ImageCell { - type Target = ethers::contract::Contract; + impl ::core::ops::Deref for ImageCellContract { + type Target = ::ethers::contract::Contract; fn deref(&self) -> &Self::Target { &self.0 } } - impl std::fmt::Debug for ImageCell { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_tuple(stringify!(ImageCell)) + impl ::core::ops::DerefMut for ImageCellContract { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } + } + impl ::core::fmt::Debug for ImageCellContract { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_tuple(stringify!(ImageCellContract)) .field(&self.address()) .finish() } } - impl ImageCell { - #[doc = r" Creates a new contract instance with the specified `ethers`"] - #[doc = r" client at the given `Address`. The contract derefs to a `ethers::Contract`"] - #[doc = r" object"] - pub fn new>( + impl ImageCellContract { + /// Creates a new contract instance with the specified `ethers` client + /// at `address`. The contract derefs to a `ethers::Contract` + /// object. + pub fn new>( address: T, client: ::std::sync::Arc, ) -> Self { - ethers::contract::Contract::new(address.into(), IMAGECELL_ABI.clone(), client).into() + Self(::ethers::contract::Contract::new( + address.into(), + IMAGECELLCONTRACT_ABI.clone(), + client, + )) } - #[doc = "Calls the contract's `rollback` (0xec5d646a) function"] + /// Calls the contract's `rollback` (0xec5d646a) function pub fn rollback( &self, inputs: ::std::vec::Vec, outputs: ::std::vec::Vec, - ) -> ethers::contract::builders::ContractCall { + ) -> ::ethers::contract::builders::ContractCall { self.0 .method_hash([236, 93, 100, 106], (inputs, outputs)) .expect("method not found (this should never happen)") } - #[doc = "Calls the contract's `setState` (0xac9f0222) function"] + /// Calls the contract's `setState` (0xac9f0222) function pub fn set_state( &self, allow_read: bool, - ) -> ethers::contract::builders::ContractCall { + ) -> ::ethers::contract::builders::ContractCall { self.0 .method_hash([172, 159, 2, 34], allow_read) .expect("method not found (this should never happen)") } - #[doc = "Calls the contract's `update` (0x4d98c254) function"] + /// Calls the contract's `update` (0x4d98c254) function pub fn update( &self, block_number: u64, inputs: ::std::vec::Vec, outputs: ::std::vec::Vec, - ) -> ethers::contract::builders::ContractCall { + ) -> ::ethers::contract::builders::ContractCall { self.0 .method_hash([77, 152, 194, 84], (block_number, inputs, outputs)) .expect("method not found (this should never happen)") } } - impl From> for ImageCell { - fn from(contract: ethers::contract::Contract) -> Self { - Self(contract) + impl From<::ethers::contract::Contract> + for ImageCellContract + { + fn from(contract: ::ethers::contract::Contract) -> Self { + Self::new(contract.address(), contract.client()) } } - #[doc = "Container type for all input parameters for the `rollback` function with signature `rollback((bytes32,uint32)[],(bytes32,uint32)[])` and selector `[236, 93, 100, 106]`"] + /// Container type for all input parameters for the `rollback` function with + /// signature `rollback((bytes32,uint32)[],(bytes32,uint32)[])` and selector + /// `0xec5d646a` #[derive( Clone, + ::ethers::contract::EthCall, + ::ethers::contract::EthDisplay, + Default, Debug, - Eq, PartialEq, - ethers::contract::EthCall, - ethers::contract::EthDisplay, - Default, + Eq, + Hash, )] #[ethcall( name = "rollback", @@ -109,29 +118,35 @@ pub mod image_cell { pub inputs: ::std::vec::Vec, pub outputs: ::std::vec::Vec, } - #[doc = "Container type for all input parameters for the `setState` function with signature `setState(bool)` and selector `[172, 159, 2, 34]`"] + /// Container type for all input parameters for the `setState` function with + /// signature `setState(bool)` and selector `0xac9f0222` #[derive( Clone, + ::ethers::contract::EthCall, + ::ethers::contract::EthDisplay, + Default, Debug, - Eq, PartialEq, - ethers::contract::EthCall, - ethers::contract::EthDisplay, - Default, + Eq, + Hash, )] #[ethcall(name = "setState", abi = "setState(bool)")] pub struct SetStateCall { pub allow_read: bool, } - #[doc = "Container type for all input parameters for the `update` function with signature `update(uint64,(bytes32,uint32)[],((bytes32,uint32),(uint64,(bytes32,uint8,bytes),(bytes32,uint8,bytes)[]),bytes)[])` and selector `[77, 152, 194, 84]`"] + /// Container type for all input parameters for the `update` function with + /// signature `update(uint64,(bytes32,uint32)[],((bytes32,uint32),(uint64, + /// (bytes32,uint8,bytes),(bytes32,uint8,bytes)[]),bytes)[])` and selector + /// `0x4d98c254` #[derive( Clone, + ::ethers::contract::EthCall, + ::ethers::contract::EthDisplay, + Default, Debug, - Eq, PartialEq, - ethers::contract::EthCall, - ethers::contract::EthDisplay, - Default, + Eq, + Hash, )] #[ethcall( name = "update", @@ -142,123 +157,125 @@ pub mod image_cell { pub inputs: ::std::vec::Vec, pub outputs: ::std::vec::Vec, } - #[derive(Debug, Clone, PartialEq, Eq, ethers::contract::EthAbiType)] - pub enum ImageCellCalls { + /// Container type for all of the contract's call + #[derive(Clone, ::ethers::contract::EthAbiType, Debug, PartialEq, Eq, Hash)] + pub enum ImageCellContractCalls { Rollback(RollbackCall), SetState(SetStateCall), Update(UpdateCall), } - impl ethers::core::abi::AbiDecode for ImageCellCalls { + impl ::ethers::core::abi::AbiDecode for ImageCellContractCalls { fn decode( data: impl AsRef<[u8]>, - ) -> ::std::result::Result { - if let Ok(decoded) = - ::decode(data.as_ref()) - { - return Ok(ImageCellCalls::Rollback(decoded)); + ) -> ::core::result::Result { + let data = data.as_ref(); + if let Ok(decoded) = ::decode(data) { + return Ok(Self::Rollback(decoded)); } - if let Ok(decoded) = - ::decode(data.as_ref()) - { - return Ok(ImageCellCalls::SetState(decoded)); + if let Ok(decoded) = ::decode(data) { + return Ok(Self::SetState(decoded)); } - if let Ok(decoded) = ::decode(data.as_ref()) - { - return Ok(ImageCellCalls::Update(decoded)); + if let Ok(decoded) = ::decode(data) { + return Ok(Self::Update(decoded)); } - Err(ethers::core::abi::Error::InvalidData.into()) + Err(::ethers::core::abi::Error::InvalidData.into()) } } - impl ethers::core::abi::AbiEncode for ImageCellCalls { + impl ::ethers::core::abi::AbiEncode for ImageCellContractCalls { fn encode(self) -> Vec { match self { - ImageCellCalls::Rollback(element) => element.encode(), - ImageCellCalls::SetState(element) => element.encode(), - ImageCellCalls::Update(element) => element.encode(), + Self::Rollback(element) => ::ethers::core::abi::AbiEncode::encode(element), + Self::SetState(element) => ::ethers::core::abi::AbiEncode::encode(element), + Self::Update(element) => ::ethers::core::abi::AbiEncode::encode(element), } } } - impl ::std::fmt::Display for ImageCellCalls { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + impl ::core::fmt::Display for ImageCellContractCalls { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { match self { - ImageCellCalls::Rollback(element) => element.fmt(f), - ImageCellCalls::SetState(element) => element.fmt(f), - ImageCellCalls::Update(element) => element.fmt(f), + Self::Rollback(element) => ::core::fmt::Display::fmt(element, f), + Self::SetState(element) => ::core::fmt::Display::fmt(element, f), + Self::Update(element) => ::core::fmt::Display::fmt(element, f), } } } - impl ::std::convert::From for ImageCellCalls { - fn from(var: RollbackCall) -> Self { - ImageCellCalls::Rollback(var) + impl ::core::convert::From for ImageCellContractCalls { + fn from(value: RollbackCall) -> Self { + Self::Rollback(value) } } - impl ::std::convert::From for ImageCellCalls { - fn from(var: SetStateCall) -> Self { - ImageCellCalls::SetState(var) + impl ::core::convert::From for ImageCellContractCalls { + fn from(value: SetStateCall) -> Self { + Self::SetState(value) } } - impl ::std::convert::From for ImageCellCalls { - fn from(var: UpdateCall) -> Self { - ImageCellCalls::Update(var) + impl ::core::convert::From for ImageCellContractCalls { + fn from(value: UpdateCall) -> Self { + Self::Update(value) } } - #[doc = "`CellInfo((bytes32,uint32),(uint64,(bytes32,uint8,bytes),(bytes32,uint8,bytes)[]),bytes)`"] + /// `CellInfo((bytes32,uint32),(uint64,(bytes32,uint8,bytes),(bytes32,uint8, + /// bytes)[]),bytes)` #[derive( Clone, - Debug, + ::ethers::contract::EthAbiType, + ::ethers::contract::EthAbiCodec, Default, - Eq, + Debug, PartialEq, - ethers::contract::EthAbiType, - ethers::contract::EthAbiCodec, + Eq, + Hash, )] pub struct CellInfo { pub out_point: OutPoint, pub output: CellOutput, - pub data: ethers::core::types::Bytes, + pub data: ::ethers::core::types::Bytes, } - #[doc = "`CellOutput(uint64,(bytes32,uint8,bytes),(bytes32,uint8,bytes)[])`"] + /// `CellOutput(uint64,(bytes32,uint8,bytes),(bytes32,uint8,bytes)[])` #[derive( Clone, - Debug, + ::ethers::contract::EthAbiType, + ::ethers::contract::EthAbiCodec, Default, - Eq, + Debug, PartialEq, - ethers::contract::EthAbiType, - ethers::contract::EthAbiCodec, + Eq, + Hash, )] pub struct CellOutput { pub capacity: u64, pub lock: Script, pub type_: ::std::vec::Vec