diff --git a/Cargo.lock b/Cargo.lock index c7130d4..1ec33de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -597,6 +597,18 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +[[package]] +name = "bounded-collections" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a071c348a5ef6da1d3a87166b408170b46002382b1dda83992b5c2208cefb370" +dependencies = [ + "log", + "parity-scale-codec 3.4.0", + "scale-info", + "serde", +] + [[package]] name = "bs58" version = "0.4.0" @@ -964,7 +976,7 @@ version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52056f6d0584484b57fa6c1a65c1fcb15f3780d8b6a758426d9e3084169b2ddd" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.88.2", ] [[package]] @@ -978,7 +990,7 @@ dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", - "cranelift-entity", + "cranelift-entity 0.88.2", "cranelift-isle", "gimli 0.26.2", "log", @@ -1011,6 +1023,15 @@ dependencies = [ "serde", ] +[[package]] +name = "cranelift-entity" +version = "0.92.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9e39cfc857e7e539aa623e03bb6bec11f54aef3dfdef41adcfa7b594af3b54" +dependencies = [ + "serde", +] + [[package]] name = "cranelift-frontend" version = "0.88.2" @@ -1047,13 +1068,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80fc2288957a94fd342a015811479de1837850924166d1f1856d8406e6f3609b" dependencies = [ "cranelift-codegen", - "cranelift-entity", + "cranelift-entity 0.88.2", "cranelift-frontend", "itertools", "log", "smallvec", - "wasmparser", - "wasmtime-types", + "wasmparser 0.89.1", + "wasmtime-types 1.0.2", ] [[package]] @@ -1374,6 +1395,17 @@ dependencies = [ "rusticata-macros", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "derive-syn-parse" version = "0.1.5" @@ -1648,19 +1680,6 @@ dependencies = [ "syn", ] -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.10.0" @@ -1768,7 +1787,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84f2e425d9790201ba4af4630191feac6dcc98765b118d4d18e91d23c2353866" dependencies = [ - "env_logger 0.10.0", + "env_logger", "log", ] @@ -2099,6 +2118,39 @@ dependencies = [ "tt-call", ] +[[package]] +name = "frame-support" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65a607f6869bc1b0294906d2dc3a9959992f9e6a4db91b262da85266f8b15e94" +dependencies = [ + "bitflags", + "frame-metadata", + "frame-support-procedural 11.0.0", + "impl-trait-for-tuples", + "k256", + "log", + "once_cell", + "parity-scale-codec 3.4.0", + "paste 1.0.12", + "scale-info", + "serde", + "smallvec", + "sp-api 14.0.0", + "sp-arithmetic 12.0.0", + "sp-core 16.0.0", + "sp-core-hashing-proc-macro 6.0.0", + "sp-inherents 14.0.0", + "sp-io 17.0.0", + "sp-runtime 18.0.0", + "sp-staking 14.0.0", + "sp-state-machine 0.22.0", + "sp-std 6.0.0", + "sp-tracing 8.0.0", + "sp-weights 14.0.0", + "tt-call", +] + [[package]] name = "frame-support-procedural" version = "4.0.0-dev" @@ -2128,6 +2180,22 @@ dependencies = [ "syn", ] +[[package]] +name = "frame-support-procedural" +version = "11.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a45eed853d66d7d14d7ad65a740f62c67c1b0bb8bdf3594073fe40979c1aeea3" +dependencies = [ + "Inflector", + "cfg-expr", + "derive-syn-parse", + "frame-support-procedural-tools 4.0.0", + "itertools", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" @@ -2152,6 +2220,19 @@ dependencies = [ "syn", ] +[[package]] +name = "frame-support-procedural-tools" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4272f469300e22c33f15502980016e876669a93080f21e0bd2da1bc7cefc87f" +dependencies = [ + "frame-support-procedural-tools-derive 4.0.0", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" @@ -2172,6 +2253,17 @@ dependencies = [ "syn", ] +[[package]] +name = "frame-support-procedural-tools-derive" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a881492b8dfdd6065d7d8537b8f79cd27aff8c501c759ac12b0295d139ff3d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "frame-system" version = "4.0.0-dev" @@ -2208,6 +2300,25 @@ dependencies = [ "sp-weights 4.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", ] +[[package]] +name = "frame-system" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4afe7a289497c4d694a9fdbfdd57ba54ef75a44e06dd67772c2afed2c66675c" +dependencies = [ + "frame-support 16.0.0", + "log", + "parity-scale-codec 3.4.0", + "scale-info", + "serde", + "sp-core 16.0.0", + "sp-io 17.0.0", + "sp-runtime 18.0.0", + "sp-std 6.0.0", + "sp-version 16.0.0", + "sp-weights 14.0.0", +] + [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" @@ -2440,8 +2551,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -2759,6 +2872,7 @@ dependencies = [ "rustls-native-certs", "tokio", "tokio-rustls", + "webpki-roots", ] [[package]] @@ -3018,7 +3132,9 @@ version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" dependencies = [ + "jsonrpsee-client-transport", "jsonrpsee-core", + "jsonrpsee-http-client", "jsonrpsee-proc-macros", "jsonrpsee-server", "jsonrpsee-types", @@ -3075,6 +3191,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "jsonrpsee-http-client" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc345b0a43c6bc49b947ebeb936e886a419ee3d894421790c969cc56040542ad" +dependencies = [ + "async-trait", + "hyper", + "hyper-rustls", + "jsonrpsee-core", + "jsonrpsee-types", + "rustc-hash", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "jsonrpsee-proc-macros" version = "0.16.2" @@ -4626,7 +4761,7 @@ dependencies = [ name = "pallet-dao" version = "0.1.0" dependencies = [ - "env_logger 0.9.3", + "env_logger", "frame-benchmarking 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "frame-support 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "frame-system 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", @@ -4708,7 +4843,7 @@ dependencies = [ name = "pallet-grid-contracts" version = "0.1.0" dependencies = [ - "env_logger 0.9.3", + "env_logger", "frame-benchmarking 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "frame-support 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "frame-system 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", @@ -4899,7 +5034,7 @@ dependencies = [ name = "pallet-tfgrid" version = "0.1.0" dependencies = [ - "env_logger 0.9.3", + "env_logger", "frame-benchmarking 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "frame-support 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "frame-system 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", @@ -6501,7 +6636,7 @@ dependencies = [ "sc-executor-common", "sp-runtime-interface 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "sp-wasm-interface 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", - "wasmtime", + "wasmtime 1.0.2", ] [[package]] @@ -7121,6 +7256,29 @@ dependencies = [ "prometheus", ] +[[package]] +name = "scale-bits" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd7aca73785181cc41f0bbe017263e682b585ca660540ba569133901d013ecf" +dependencies = [ + "parity-scale-codec 3.4.0", + "scale-info", + "serde", +] + +[[package]] +name = "scale-decode" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d823d4be477fc33321f93d08fb6c2698273d044f01362dc27573a750deb7c233" +dependencies = [ + "parity-scale-codec 3.4.0", + "scale-bits", + "scale-info", + "thiserror", +] + [[package]] name = "scale-info" version = "2.3.1" @@ -7147,6 +7305,23 @@ dependencies = [ "syn", ] +[[package]] +name = "scale-value" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a5e7810815bd295da73e4216d1dfbced3c7c7c7054d70fa5f6e4c58123fff4" +dependencies = [ + "either", + "frame-metadata", + "parity-scale-codec 3.4.0", + "scale-bits", + "scale-decode", + "scale-info", + "serde", + "thiserror", + "yap", +] + [[package]] name = "schannel" version = "0.1.21" @@ -7577,6 +7752,25 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sp-api" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2907bc9290f2a5bf2e8817b221ccc6a572b8f2fb7523266f34b048bb979568db" +dependencies = [ + "hash-db", + "log", + "parity-scale-codec 3.4.0", + "sp-api-proc-macro 4.0.0", + "sp-core 16.0.0", + "sp-runtime 18.0.0", + "sp-state-machine 0.22.0", + "sp-std 6.0.0", + "sp-trie 16.0.0", + "sp-version 16.0.0", + "thiserror", +] + [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" @@ -7601,6 +7795,19 @@ dependencies = [ "syn", ] +[[package]] +name = "sp-api-proc-macro" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74e620b045c0a4fa640fa50623d7da6575115d8a70c54926cfd99f3f7727d323" +dependencies = [ + "blake2", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sp-application-crypto" version = "7.0.0" @@ -7627,6 +7834,20 @@ dependencies = [ "sp-std 5.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", ] +[[package]] +name = "sp-application-crypto" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f08604ba4bd856311946722958711a08bded5c929e1227f7a697c58deb09468" +dependencies = [ + "parity-scale-codec 3.4.0", + "scale-info", + "serde", + "sp-core 16.0.0", + "sp-io 17.0.0", + "sp-std 6.0.0", +] + [[package]] name = "sp-arithmetic" version = "6.0.0" @@ -7656,6 +7877,21 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "sp-arithmetic" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7796939f2e3b68a3b9410ea17a2063b78038cd366f57fa772dd3be0798bd3412" +dependencies = [ + "integer-sqrt", + "num-traits", + "parity-scale-codec 3.4.0", + "scale-info", + "serde", + "sp-std 6.0.0", + "static_assertions", +] + [[package]] name = "sp-block-builder" version = "4.0.0-dev" @@ -7821,6 +8057,50 @@ dependencies = [ "zeroize", ] +[[package]] +name = "sp-core" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c96dc3debbe5c22ebf18f99e6a53199efe748e6e584a1902adb88cbad66ae7c" +dependencies = [ + "array-bytes", + "base58", + "bitflags", + "blake2", + "bounded-collections", + "dyn-clonable", + "ed25519-zebra", + "futures", + "hash-db", + "hash256-std-hasher", + "impl-serde", + "lazy_static", + "libsecp256k1", + "log", + "merlin", + "parity-scale-codec 3.4.0", + "parking_lot 0.12.1", + "primitive-types", + "rand 0.8.5", + "regex", + "scale-info", + "schnorrkel", + "secp256k1", + "secrecy", + "serde", + "sp-core-hashing 6.0.0", + "sp-debug-derive 6.0.0", + "sp-externalities 0.17.0", + "sp-runtime-interface 13.0.0", + "sp-std 6.0.0", + "sp-storage 11.0.0", + "ss58-registry", + "substrate-bip39", + "thiserror", + "tiny-bip39 1.0.0", + "zeroize", +] + [[package]] name = "sp-core-hashing" version = "5.0.0" @@ -7849,6 +8129,21 @@ dependencies = [ "twox-hash", ] +[[package]] +name = "sp-core-hashing" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc2d1947252b7a4e403b0a260f596920443742791765ec111daa2bbf98eff25" +dependencies = [ + "blake2", + "byteorder", + "digest 0.10.6", + "sha2 0.10.6", + "sha3", + "sp-std 6.0.0", + "twox-hash", +] + [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" @@ -7871,6 +8166,18 @@ dependencies = [ "syn", ] +[[package]] +name = "sp-core-hashing-proc-macro" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5833921310f9883f2093849d3f5e9e57e9890f6b60839498b08d4c72572cc602" +dependencies = [ + "proc-macro2", + "quote", + "sp-core-hashing 6.0.0", + "syn", +] + [[package]] name = "sp-database" version = "4.0.0-dev" @@ -7901,10 +8208,21 @@ dependencies = [ ] [[package]] -name = "sp-externalities" -version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51" -dependencies = [ +name = "sp-debug-derive" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fb9dc63d54de7d7bed62a505b6e0bd66c122525ea1abb348f6564717c3df2d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sp-externalities" +version = "0.13.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51" +dependencies = [ "environmental", "parity-scale-codec 3.4.0", "sp-std 5.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", @@ -7922,6 +8240,18 @@ dependencies = [ "sp-storage 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", ] +[[package]] +name = "sp-externalities" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57052935c9c9b070ea6b339ef0da3bf241b7e065fc37f9c551669ee83ecfc3c1" +dependencies = [ + "environmental", + "parity-scale-codec 3.4.0", + "sp-std 6.0.0", + "sp-storage 11.0.0", +] + [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" @@ -7968,6 +8298,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sp-inherents" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "241a4961e0add07b0d17f6f68de812649c9c5c2832618fd5dc1b82475dbaf771" +dependencies = [ + "async-trait", + "impl-trait-for-tuples", + "parity-scale-codec 3.4.0", + "scale-info", + "sp-core 16.0.0", + "sp-runtime 18.0.0", + "sp-std 6.0.0", + "thiserror", +] + [[package]] name = "sp-io" version = "7.0.0" @@ -8020,6 +8366,32 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "sp-io" +version = "17.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578959f9a7e44fd2dd96e8b8bc893cea04fcd7c00a4ffbb0b91c5013899dd02b" +dependencies = [ + "bytes", + "ed25519", + "ed25519-dalek", + "futures", + "libsecp256k1", + "log", + "parity-scale-codec 3.4.0", + "secp256k1", + "sp-core 16.0.0", + "sp-externalities 0.17.0", + "sp-keystore 0.22.0", + "sp-runtime-interface 13.0.0", + "sp-state-machine 0.22.0", + "sp-std 6.0.0", + "sp-tracing 8.0.0", + "sp-trie 16.0.0", + "tracing", + "tracing-core", +] + [[package]] name = "sp-keyring" version = "7.0.0" @@ -8064,6 +8436,23 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sp-keystore" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "480dbd54b281c638209fbcfce69902b82a0a1af0e22219d46825eadced3136b6" +dependencies = [ + "async-trait", + "futures", + "merlin", + "parity-scale-codec 3.4.0", + "parking_lot 0.12.1", + "schnorrkel", + "sp-core 16.0.0", + "sp-externalities 0.17.0", + "thiserror", +] + [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" @@ -8117,6 +8506,17 @@ dependencies = [ "regex", ] +[[package]] +name = "sp-panic-handler" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4abed79c3d5b3622f65ab065676addd9923b9b122cd257df23e2757ce487c6d2" +dependencies = [ + "backtrace", + "lazy_static", + "regex", +] + [[package]] name = "sp-rpc" version = "6.0.0" @@ -8171,6 +8571,29 @@ dependencies = [ "sp-weights 4.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", ] +[[package]] +name = "sp-runtime" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8ab2fd44668d3e8674e2253a43852857a47d49be7db737e98bf157e4bcebefd" +dependencies = [ + "either", + "hash256-std-hasher", + "impl-trait-for-tuples", + "log", + "parity-scale-codec 3.4.0", + "paste 1.0.12", + "rand 0.8.5", + "scale-info", + "serde", + "sp-application-crypto 17.0.0", + "sp-arithmetic 12.0.0", + "sp-core 16.0.0", + "sp-io 17.0.0", + "sp-std 6.0.0", + "sp-weights 14.0.0", +] + [[package]] name = "sp-runtime-interface" version = "7.0.0" @@ -8207,6 +8630,25 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "sp-runtime-interface" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb7707246cee4967a8cc71e3ef0e82f562e8b1020606447a6a12b99c7c1b443" +dependencies = [ + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec 3.4.0", + "primitive-types", + "sp-externalities 0.17.0", + "sp-runtime-interface-proc-macro 9.0.0", + "sp-std 6.0.0", + "sp-storage 11.0.0", + "sp-tracing 8.0.0", + "sp-wasm-interface 10.0.0", + "static_assertions", +] + [[package]] name = "sp-runtime-interface-proc-macro" version = "6.0.0" @@ -8231,6 +8673,19 @@ dependencies = [ "syn", ] +[[package]] +name = "sp-runtime-interface-proc-macro" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2773c90e5765847c5e8b4a24b553d38a9ca52ded47c142cfcfb7948f42827af9" +dependencies = [ + "Inflector", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sp-session" version = "4.0.0-dev" @@ -8269,6 +8724,19 @@ dependencies = [ "sp-std 5.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", ] +[[package]] +name = "sp-staking" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf0d4447b73a53f8c36915b5710914ea82d303fc880e264e241046ae5baca08" +dependencies = [ + "parity-scale-codec 3.4.0", + "scale-info", + "sp-core 16.0.0", + "sp-runtime 18.0.0", + "sp-std 6.0.0", +] + [[package]] name = "sp-state-machine" version = "0.13.0" @@ -8311,6 +8779,27 @@ dependencies = [ "tracing", ] +[[package]] +name = "sp-state-machine" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c957b8b4c252507c12674948db427c5e34fd1760ce256922f1ec5f89f781a4f" +dependencies = [ + "hash-db", + "log", + "parity-scale-codec 3.4.0", + "parking_lot 0.12.1", + "rand 0.8.5", + "smallvec", + "sp-core 16.0.0", + "sp-externalities 0.17.0", + "sp-panic-handler 6.0.0", + "sp-std 6.0.0", + "sp-trie 16.0.0", + "thiserror", + "tracing", +] + [[package]] name = "sp-std" version = "5.0.0" @@ -8321,6 +8810,12 @@ name = "sp-std" version = "5.0.0" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38#18bb7c7c841b101c19a8d1881b893ae8e37de460" +[[package]] +name = "sp-std" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af0ee286f98455272f64ac5bb1384ff21ac029fbb669afbaf48477faff12760e" + [[package]] name = "sp-storage" version = "7.0.0" @@ -8347,6 +8842,20 @@ dependencies = [ "sp-std 5.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", ] +[[package]] +name = "sp-storage" +version = "11.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c20cb0c562d1a159ecb2c7ca786828c81e432c535474967d2df3a484977cea4" +dependencies = [ + "impl-serde", + "parity-scale-codec 3.4.0", + "ref-cast", + "serde", + "sp-debug-derive 6.0.0", + "sp-std 6.0.0", +] + [[package]] name = "sp-timestamp" version = "4.0.0-dev" @@ -8386,6 +8895,19 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "sp-tracing" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e46bd547da89a9cda69b4ce4c91a5b7e1f86915190d83cd407b715d0c6bac042" +dependencies = [ + "parity-scale-codec 3.4.0", + "sp-std 6.0.0", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" @@ -8457,6 +8979,30 @@ dependencies = [ "trie-root", ] +[[package]] +name = "sp-trie" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8efbe5b6d29a18fea7c2f52e0098135f2f864b31d335d5105b40a349866ba874" +dependencies = [ + "ahash 0.8.3", + "hash-db", + "hashbrown 0.12.3", + "lazy_static", + "memory-db", + "nohash-hasher", + "parity-scale-codec 3.4.0", + "parking_lot 0.12.1", + "scale-info", + "schnellru", + "sp-core 16.0.0", + "sp-std 6.0.0", + "thiserror", + "tracing", + "trie-db", + "trie-root", +] + [[package]] name = "sp-version" version = "5.0.0" @@ -8491,6 +9037,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sp-version" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01f705c5c6c6dad760355df0b870dd8e510f720ae6adde3eeba069c116248024" +dependencies = [ + "impl-serde", + "parity-scale-codec 3.4.0", + "parity-wasm", + "scale-info", + "serde", + "sp-core-hashing-proc-macro 6.0.0", + "sp-runtime 18.0.0", + "sp-std 6.0.0", + "sp-version-proc-macro 6.0.0", + "thiserror", +] + [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" @@ -8513,6 +9077,18 @@ dependencies = [ "syn", ] +[[package]] +name = "sp-version-proc-macro" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61fa10e7a0453c9eb2bfd49067585fe54d530f020e3bfa94bf0a9ce547aa5b3" +dependencies = [ + "parity-scale-codec 3.4.0", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sp-wasm-interface" version = "7.0.0" @@ -8523,7 +9099,7 @@ dependencies = [ "parity-scale-codec 3.4.0", "sp-std 5.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", "wasmi", - "wasmtime", + "wasmtime 1.0.2", ] [[package]] @@ -8536,7 +9112,22 @@ dependencies = [ "parity-scale-codec 3.4.0", "sp-std 5.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", "wasmi", - "wasmtime", + "wasmtime 1.0.2", +] + +[[package]] +name = "sp-wasm-interface" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbc05650b6338808892a7b04f0c56bb1f7f928bfa9ac58e0af2c1e5bef33229" +dependencies = [ + "anyhow", + "impl-trait-for-tuples", + "log", + "parity-scale-codec 3.4.0", + "sp-std 6.0.0", + "wasmi", + "wasmtime 5.0.1", ] [[package]] @@ -8570,6 +9161,22 @@ dependencies = [ "sp-std 5.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", ] +[[package]] +name = "sp-weights" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ebab7696f915aa548494aef3ca8d15217baf10458fe6edb87e60587a47de358" +dependencies = [ + "parity-scale-codec 3.4.0", + "scale-info", + "serde", + "smallvec", + "sp-arithmetic 12.0.0", + "sp-core 16.0.0", + "sp-debug-derive 6.0.0", + "sp-std 6.0.0", +] + [[package]] name = "spin" version = "0.5.2" @@ -8807,6 +9414,84 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[package]] +name = "subxt" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54639dba6a113584083968b6a8f457dedae612abe1bd214762101ca29f12e332" +dependencies = [ + "base58", + "blake2", + "derivative", + "frame-metadata", + "futures", + "getrandom 0.2.8", + "hex", + "impl-serde", + "jsonrpsee", + "parity-scale-codec 3.4.0", + "parking_lot 0.12.1", + "primitive-types", + "scale-bits", + "scale-decode", + "scale-info", + "scale-value", + "serde", + "serde_json", + "sp-core 16.0.0", + "sp-core-hashing 6.0.0", + "sp-runtime 18.0.0", + "subxt-macro", + "subxt-metadata", + "thiserror", + "tracing", +] + +[[package]] +name = "subxt-codegen" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e86cb719003f1cedf2710a6e55ca4c37aba4c989bbd3b81dd1c52af9e4827e" +dependencies = [ + "darling", + "frame-metadata", + "heck", + "hex", + "jsonrpsee", + "parity-scale-codec 3.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "scale-info", + "subxt-metadata", + "syn", + "tokio", +] + +[[package]] +name = "subxt-macro" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74c08de402a78c4c06c3ee3702c80e519efdcb65911348e018b6998d04404916" +dependencies = [ + "darling", + "proc-macro-error", + "subxt-codegen", + "syn", +] + +[[package]] +name = "subxt-metadata" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593ab5f53435e6352675af4f9851342607f37785d84c7a3fb3139550d3c35f0" +dependencies = [ + "frame-metadata", + "parity-scale-codec 3.4.0", + "scale-info", + "sp-core-hashing 6.0.0", +] + [[package]] name = "syn" version = "1.0.109" @@ -8937,6 +9622,23 @@ dependencies = [ "try-runtime-cli", ] +[[package]] +name = "tfchain-client" +version = "0.1.0" +dependencies = [ + "frame-system 16.0.0", + "pallet-balances", + "parity-scale-codec 3.4.0", + "serde", + "sp-core 16.0.0", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", + "sp-runtime 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", + "sp-std 5.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", + "subxt", + "subxt-codegen", + "tokio", +] + [[package]] name = "tfchain-runtime" version = "0.1.0" @@ -9889,6 +10591,16 @@ dependencies = [ "indexmap", ] +[[package]] +name = "wasmparser" +version = "0.96.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adde01ade41ab9a5d10ec8ed0bb954238cf8625b5cd5a13093d6de2ad9c2be1a" +dependencies = [ + "indexmap", + "url", +] + [[package]] name = "wasmtime" version = "1.0.2" @@ -9908,15 +10620,40 @@ dependencies = [ "rayon", "serde", "target-lexicon", - "wasmparser", + "wasmparser 0.89.1", "wasmtime-cache", "wasmtime-cranelift", - "wasmtime-environ", - "wasmtime-jit", - "wasmtime-runtime", + "wasmtime-environ 1.0.2", + "wasmtime-jit 1.0.2", + "wasmtime-runtime 1.0.2", "windows-sys 0.36.1", ] +[[package]] +name = "wasmtime" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49ffcc607adc9da024e87ca814592d4bc67f5c5b58e488f5608d5734a1ebc23e" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "indexmap", + "libc", + "log", + "object 0.29.0", + "once_cell", + "paste 1.0.12", + "psm", + "serde", + "target-lexicon", + "wasmparser 0.96.0", + "wasmtime-environ 5.0.1", + "wasmtime-jit 5.0.1", + "wasmtime-runtime 5.0.1", + "windows-sys 0.42.0", +] + [[package]] name = "wasmtime-asm-macros" version = "1.0.2" @@ -9926,6 +10663,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "wasmtime-asm-macros" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cb5dc4d79cd7b2453c395f64e9013d2ad90bd083be556d5565cb224ebe8d57" +dependencies = [ + "cfg-if", +] + [[package]] name = "wasmtime-cache" version = "1.0.2" @@ -9954,7 +10700,7 @@ checksum = "4bd91339b742ff20bfed4532a27b73c86b5bcbfedd6bea2dcdf2d64471e1b5c6" dependencies = [ "anyhow", "cranelift-codegen", - "cranelift-entity", + "cranelift-entity 0.88.2", "cranelift-frontend", "cranelift-native", "cranelift-wasm", @@ -9963,8 +10709,8 @@ dependencies = [ "object 0.29.0", "target-lexicon", "thiserror", - "wasmparser", - "wasmtime-environ", + "wasmparser 0.89.1", + "wasmtime-environ 1.0.2", ] [[package]] @@ -9974,7 +10720,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebb881c61f4f627b5d45c54e629724974f8a8890d455bcbe634330cc27309644" dependencies = [ "anyhow", - "cranelift-entity", + "cranelift-entity 0.88.2", "gimli 0.26.2", "indexmap", "log", @@ -9982,8 +10728,27 @@ dependencies = [ "serde", "target-lexicon", "thiserror", - "wasmparser", - "wasmtime-types", + "wasmparser 0.89.1", + "wasmtime-types 1.0.2", +] + +[[package]] +name = "wasmtime-environ" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9350c919553cddf14f78f9452119c8004d7ef6bfebb79a41a21819ed0c5604d8" +dependencies = [ + "anyhow", + "cranelift-entity 0.92.1", + "gimli 0.26.2", + "indexmap", + "log", + "object 0.29.0", + "serde", + "target-lexicon", + "thiserror", + "wasmparser 0.96.0", + "wasmtime-types 5.0.1", ] [[package]] @@ -10005,12 +10770,35 @@ dependencies = [ "serde", "target-lexicon", "thiserror", - "wasmtime-environ", - "wasmtime-jit-debug", - "wasmtime-runtime", + "wasmtime-environ 1.0.2", + "wasmtime-jit-debug 1.0.2", + "wasmtime-runtime 1.0.2", "windows-sys 0.36.1", ] +[[package]] +name = "wasmtime-jit" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ba5779ea786386432b94c9fc9ad5597346c319e8239db0d98d5be5cc109a7e" +dependencies = [ + "addr2line 0.17.0", + "anyhow", + "bincode", + "cfg-if", + "cpp_demangle", + "gimli 0.26.2", + "log", + "object 0.29.0", + "rustc-demangle", + "serde", + "target-lexicon", + "wasmtime-environ 5.0.1", + "wasmtime-jit-icache-coherence", + "wasmtime-runtime 5.0.1", + "windows-sys 0.42.0", +] + [[package]] name = "wasmtime-jit-debug" version = "1.0.2" @@ -10022,6 +10810,26 @@ dependencies = [ "rustix 0.35.13", ] +[[package]] +name = "wasmtime-jit-debug" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9841a44c82c74101c10ad4f215392761a2523b3c6c838597962bdb6de75fdb3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd4356c2493002da3b111d470c2ecea65a3017009afce8adc46eaa5758739891" +dependencies = [ + "cfg-if", + "libc", + "windows-sys 0.42.0", +] + [[package]] name = "wasmtime-runtime" version = "1.0.2" @@ -10041,22 +10849,58 @@ dependencies = [ "rand 0.8.5", "rustix 0.35.13", "thiserror", - "wasmtime-asm-macros", - "wasmtime-environ", - "wasmtime-jit-debug", + "wasmtime-asm-macros 1.0.2", + "wasmtime-environ 1.0.2", + "wasmtime-jit-debug 1.0.2", "windows-sys 0.36.1", ] +[[package]] +name = "wasmtime-runtime" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd26efea7a790fcf430e663ba2519f0ab6eb8980adf8b0c58c62b727da77c2ec" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "indexmap", + "libc", + "log", + "mach", + "memfd", + "memoffset 0.6.5", + "paste 1.0.12", + "rand 0.8.5", + "rustix 0.36.9", + "wasmtime-asm-macros 5.0.1", + "wasmtime-environ 5.0.1", + "wasmtime-jit-debug 5.0.1", + "windows-sys 0.42.0", +] + [[package]] name = "wasmtime-types" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d23d61cb4c46e837b431196dd06abb11731541021916d03476a178b54dc07aeb" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.88.2", "serde", "thiserror", - "wasmparser", + "wasmparser 0.89.1", +] + +[[package]] +name = "wasmtime-types" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86e1e4f66a2b9a114f9def450ab9971828c968db6ea6fccd613724b771fa4913" +dependencies = [ + "cranelift-entity 0.92.1", + "serde", + "thiserror", + "wasmparser 0.96.0", ] [[package]] @@ -10616,6 +11460,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "yap" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc77f52dc9e9b10d55d3f4462c3b7fc393c4f17975d641542833ab2d3bc26ef" + [[package]] name = "yasna" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 8a475e2..84532f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,8 @@ members = [ 'runtime', 'pallets/*', 'support', - 'primitives' + 'primitives', + 'tfchain-client' ] [profile.release] diff --git a/tfchain-client/Cargo.toml b/tfchain-client/Cargo.toml new file mode 100644 index 0000000..7c73240 --- /dev/null +++ b/tfchain-client/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "tfchain-client" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +path = "src/lib.rs" +name = "tfchain_client" + +[dependencies] +codec = {package = "parity-scale-codec", workspace = true, features = ["derive"]} +subxt = "0.27.1" +subxt-codegen = "0.27.1" +tokio = { version = "1.8", features = ["rt-multi-thread", "macros", "time"] } +serde = { workspace = true, features = ["derive"] } + +# Substrate stuff +sp-core = { version = "16.0.0", default-features = false } +frame-system = { version = "16.0.0", default-features = false } +sp-std.workspace = true +sp-runtime.workspace = true +sp-io.workspace = true +pallet-balances.workspace = true + +[features] +default = ['std'] +std = [ + 'sp-std/std', + 'sp-runtime/std', + 'sp-io/std', + 'sp-core/std', + 'frame-system/std', + 'pallet-balances/std' +] \ No newline at end of file diff --git a/tfchain-client/artifacts/mainnet.scale b/tfchain-client/artifacts/mainnet.scale new file mode 100644 index 0000000..62af7d3 Binary files /dev/null and b/tfchain-client/artifacts/mainnet.scale differ diff --git a/tfchain-client/src/lib.rs b/tfchain-client/src/lib.rs new file mode 100644 index 0000000..66643ab --- /dev/null +++ b/tfchain-client/src/lib.rs @@ -0,0 +1,171 @@ +pub mod runtimes; +use crate::runtimes::mainnet; +use crate::runtimes::types::*; +use serde::{Deserialize, Serialize}; +use sp_core::{crypto::SecretStringError, ed25519, sr25519, Pair}; +use std::str::FromStr; +use subxt::config::extrinsic_params::BaseExtrinsicParams; +use subxt::config::polkadot::PlainTip; +use subxt::config::WithExtrinsicParams; +use subxt::SubstrateConfig; +use subxt::{ + tx::{PairSigner, Signer}, + Error, OnlineClient, PolkadotConfig, +}; + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum Runtime { + // Local, + // Devnet, + // Testnet, + Mainnet, +} + +impl FromStr for Runtime { + type Err = &'static str; + + fn from_str(v: &str) -> Result<Self, Self::Err> { + match v { + // "local" => Ok(Self::Local), + // "devnet" => Ok(Self::Devnet), + "mainnet" => Ok(Self::Mainnet), + // "testnet" => Ok(Self::Testnet), + _ => Err("unknown runtime"), + } + } +} + +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +pub enum KeyType { + Sr25519, + Ed25519, +} + +impl FromStr for KeyType { + type Err = &'static str; + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s.to_lowercase().as_str() { + "sr25519" => Ok(Self::Sr25519), + "ed25519" => Ok(Self::Ed25519), + _ => Err("unknown key type"), + } + } +} + +#[derive(Clone)] +pub enum KeyPair { + Sr25519(sr25519::Pair), + Ed25519(ed25519::Pair), +} + +impl KeyPair { + // create a key pair from a seed prefixed with `0x`. or a BIP-39 phrase + pub fn from_phrase<S: AsRef<str>>( + k: KeyType, + phrase: S, + password: Option<&str>, + ) -> Result<Self, SecretStringError> { + let phrase = phrase.as_ref(); + + let pair = match k { + KeyType::Sr25519 => { + let pair: sr25519::Pair = Pair::from_string(phrase, password)?; + Self::Sr25519(pair) + }, + KeyType::Ed25519 => { + let pair: ed25519::Pair = Pair::from_string(phrase, password)?; + Self::Ed25519(pair) + }, + }; + + Ok(pair) + } + + pub fn signer(&self) -> KeypairSigner { + match self { + Self::Ed25519(pair) => KeypairSigner(Box::new(PairSigner::new(pair.clone()))), + Self::Sr25519(pair) => KeypairSigner(Box::new(PairSigner::new(pair.clone()))), + } + } +} + +pub struct KeypairSigner(Box<dyn Signer<PolkadotConfig> + Send + Sync>); + +impl + subxt::tx::Signer< + WithExtrinsicParams<SubstrateConfig, BaseExtrinsicParams<SubstrateConfig, PlainTip>>, + > for KeypairSigner +{ + fn account_id(&self) -> &<WithExtrinsicParams<SubstrateConfig, BaseExtrinsicParams<SubstrateConfig, PlainTip>> as subxt::Config>::AccountId{ + self.0.account_id() + } + + fn address(&self) -> <WithExtrinsicParams<SubstrateConfig, BaseExtrinsicParams<SubstrateConfig, PlainTip>> as subxt::Config>::Address{ + self.0.address() + } + + fn sign(&self, signer_payload: &[u8]) -> <WithExtrinsicParams<SubstrateConfig, BaseExtrinsicParams<SubstrateConfig, PlainTip>> as subxt::Config>::Signature{ + self.0.sign(signer_payload) + } +} + +impl From<sr25519::Pair> for KeyPair { + fn from(value: sr25519::Pair) -> Self { + Self::Sr25519(value) + } +} + +impl From<ed25519::Pair> for KeyPair { + fn from(value: ed25519::Pair) -> Self { + Self::Ed25519(value) + } +} + +#[derive(Clone)] +pub struct Client { + pub runtime: Runtime, + pub api: OnlineClient<PolkadotConfig>, +} + +macro_rules! call { + ($self:ident, $name:ident, $($arg:expr),+) => ( + match $self.runtime { + // Runtime::Local => local::$name($self, $($arg),+).await, + // Runtime::Devnet => devnet::$name($self, $($arg),+).await, + // Runtime::Testnet => testnet::$name($self, $($arg),+).await, + Runtime::Mainnet => mainnet::$name($self, $($arg),+).await, + } + ) +} + +impl Client { + pub async fn new<U: AsRef<str>>(url: U, runtime: Runtime) -> Result<Client, Error> { + let api = OnlineClient::<PolkadotConfig>::from_url(url).await?; + + Ok(Client { api, runtime }) + } + + pub async fn get_balance( + &self, + account: &AccountId32, + at_block: Option<Hash>, + ) -> Result<Option<SystemAccountInfo>, Error> { + call!(self, get_balance, account, at_block) + } + + pub async fn get_block_hash( + &self, + block_number: Option<BlockNumber>, + ) -> Result<Option<Hash>, Error> { + call!(self, get_block_hash, block_number) + } + + pub async fn transfer_native( + &self, + keypair: &KeyPair, + to: AccountId32, + amount: u128, + ) -> Result<Hash, Error> { + call!(self, transfer_native, keypair, to, amount) + } +} diff --git a/tfchain-client/src/runtimes/mainnet.rs b/tfchain-client/src/runtimes/mainnet.rs new file mode 100644 index 0000000..56fc3a7 --- /dev/null +++ b/tfchain-client/src/runtimes/mainnet.rs @@ -0,0 +1,73 @@ +use super::types::*; +use crate::{Client, KeyPair}; +use subxt::{subxt, Error}; + +#[subxt(runtime_metadata_path = "artifacts/mainnet.scale", derive_for_all_types = "Eq, PartialEq")] +pub mod mainnet {} +pub use mainnet::runtime_types::frame_system::AccountInfo; + +pub type AccountData = mainnet::runtime_types::pallet_balances::AccountData<u128>; +pub type SystemAccountInfo = AccountInfo<u32, AccountData>; + +use super::types::SystemAccountInfo as GenericAccountInfo; + +pub async fn get_block_hash( + cl: &Client, + block_number: Option<BlockNumber>, +) -> Result<Option<Hash>, Error> { + cl.api.rpc().block_hash(block_number).await +} + +pub async fn get_balance( + cl: &Client, + account: &AccountId32, + at_block: Option<Hash>, +) -> Result<Option<GenericAccountInfo>, Error> { + Ok(cl + .api + .storage() + .at(at_block) + .await? + .fetch(&mainnet::storage().system().account(account)) + .await? + .map(|t| GenericAccountInfo::from(t))) +} + +// Wrapper around the transfer function of the balances pallet +// This function will wait for the transaction to be finalized and return the block hash +// If the transaction fails, it will return an error +// If the transaction is successful, it will return the block hash +pub async fn transfer_native( + cl: &Client, + kp: &KeyPair, + dest: AccountId32, + amount: u128, +) -> Result<Hash, Error> { + let transfer_tx = mainnet::tx().balances().transfer(dest.clone().into(), amount); + + let s = &kp.signer(); + + let events = cl + .api + .tx() + .sign_and_submit_then_watch_default(&transfer_tx, s) + .await? + .wait_for_finalized_success() + .await?; + + let expected_event = mainnet::balances::events::Transfer { + from: s.0.account_id().clone(), + to: dest.into(), + amount, + }; + + let exists = events + .find::<mainnet::balances::events::Transfer>() + .any(|e| e.map(|x| assert_eq!(x, expected_event)).is_ok()); + + if exists { + Ok(events.block_hash()) + } else { + Err(Error::Other(String::from("failed to transfer"))) + } +} diff --git a/tfchain-client/src/runtimes/mod.rs b/tfchain-client/src/runtimes/mod.rs new file mode 100644 index 0000000..1c60b14 --- /dev/null +++ b/tfchain-client/src/runtimes/mod.rs @@ -0,0 +1,4 @@ +#![allow(clippy::all)] + +pub mod mainnet; +pub mod types; diff --git a/tfchain-client/src/runtimes/types.rs b/tfchain-client/src/runtimes/types.rs new file mode 100644 index 0000000..c447224 --- /dev/null +++ b/tfchain-client/src/runtimes/types.rs @@ -0,0 +1,28 @@ +use subxt::{Config, PolkadotConfig}; + +pub use frame_system::AccountInfo; +pub use pallet_balances::AccountData; +pub type Hash = <PolkadotConfig as Config>::Hash; +pub type BlockNumber = subxt::rpc::types::BlockNumber; +pub use subxt::utils::AccountId32; + +pub type SystemAccountInfo = AccountInfo<u32, AccountData<u128>>; + +use super::mainnet::SystemAccountInfo as MainnetSystemAccountInfo; + +impl From<MainnetSystemAccountInfo> for SystemAccountInfo { + fn from(info: MainnetSystemAccountInfo) -> Self { + SystemAccountInfo { + nonce: info.nonce, + consumers: info.consumers, + providers: info.providers, + sufficients: info.sufficients, + data: pallet_balances::AccountData { + free: info.data.free, + fee_frozen: info.data.fee_frozen, + misc_frozen: info.data.misc_frozen, + reserved: info.data.reserved, + }, + } + } +}