diff --git a/.gitignore b/.gitignore index 00946fda6..b50cebd18 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # IDE .vscode .idea +/tags # TODOR .todor diff --git a/Cargo.lock b/Cargo.lock index ee6e62ac2..86a23f556 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -187,6 +187,15 @@ dependencies = [ "constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "block-buffer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block-buffer" version = "0.7.3" @@ -232,6 +241,11 @@ name = "byte-slice-cast" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "byte-tools" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byte-tools" version = "0.3.1" @@ -375,6 +389,14 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clear_on_drop" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cli-table" version = "0.2.0" @@ -426,6 +448,7 @@ dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "sled 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tendermint 0.10.0 (git+https://github.com/crypto-com/tendermint-rs.git?rev=bb27fdc5dd0ce59767badab246d1d4c203cf3d23)", "websocket 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -659,6 +682,18 @@ dependencies = [ "stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "curve25519-dalek" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dbl" version = "0.2.1" @@ -687,6 +722,14 @@ dependencies = [ "structopt 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "digest" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "digest" version = "0.8.1" @@ -715,6 +758,18 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ed25519-dalek" +version = "1.0.0-pre.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "either" version = "1.5.3" @@ -975,6 +1030,14 @@ dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "generic-array" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "generic-array" version = "0.12.3" @@ -1210,6 +1273,14 @@ dependencies = [ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "itertools" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itertools" version = "0.8.1" @@ -1866,6 +1937,29 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "prost-amino" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "prost-amino-derive" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "protobuf" version = "2.8.1" @@ -2438,6 +2532,17 @@ name = "sha1" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "sha2" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", + "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha2" version = "0.8.0" @@ -2461,6 +2566,37 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "signatory" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "signature 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle-encoding 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "signatory-dalek" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "signatory 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "signature" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "skeptic" version = "0.4.0" @@ -2574,6 +2710,26 @@ name = "subtle" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "subtle-encoding" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syn" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "syn" version = "0.15.44" @@ -2594,6 +2750,17 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "synstructure" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "synstructure" version = "0.12.3" @@ -2605,6 +2772,14 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tai64" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tempdir" version = "0.3.7" @@ -2627,6 +2802,31 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tendermint" +version = "0.10.0" +source = "git+https://github.com/crypto-com/tendermint-rs.git?rev=bb27fdc5dd0ce59767badab246d1d4c203cf3d23#bb27fdc5dd0ce59767badab246d1d4c203cf3d23" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)", + "prost-amino 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "prost-amino-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "signatory 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "signatory-dalek 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle-encoding 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tai64 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termcolor" version = "1.0.5" @@ -2999,6 +3199,11 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "uuid" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "uuid" version = "0.8.1" @@ -3239,11 +3444,30 @@ name = "zeroize" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "zeroize" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize_derive" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "zmq" version = "0.9.2" @@ -3289,12 +3513,14 @@ dependencies = [ "checksum bitvec 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9633b74910e1870f50f5af189b08487195cdb83c0e27a71d6f64d5e09dd0538b" "checksum blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" "checksum blake2b_simd 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b83b7baab1e671718d78204225800d6b170e648188ac7dc992e9d6bddf87d0c0" +"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" "checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" "checksum bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708" "checksum byte-slice-cast 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f6209f3b2c1edea170002e016d5ead6903d3bb0a846477f53bbeb614967a52a9" +"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" @@ -3303,6 +3529,7 @@ dependencies = [ "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cli-table 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6fe7bde9ea2c89a08ae0f5b75de12a5afbedb424dc09d9f58a9d850a348f60e0" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmac 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f4a435124bcc292eba031f1f725d7abacdaf13cbf9f935450e8c45aa9e96cad" @@ -3321,10 +3548,13 @@ dependencies = [ "checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" +"checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" "checksum dbl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28dc203b75decc900220c4d9838e738d08413e663c26826ba92b669bed1d0795" +"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" "checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" +"checksum ed25519-dalek 1.0.0-pre.2 (registry+https://github.com/rust-lang/crates.io-index)" = "845aaacc16f01178f33349e7c992ecd0cee095aa5e577f0f4dee35971bd36455" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "073be79b6538296faf81c631872676600616073817dd9a440c477ad09b408983" "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" @@ -3356,6 +3586,7 @@ dependencies = [ "checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" "checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" "checksum getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" @@ -3379,6 +3610,7 @@ dependencies = [ "checksum integer-encoding 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1aec89c15e2cfa0f0eae8ca60e03cb10b30d25ea2c0ad7d6be60a95e32729994" "checksum interleaved-ordered 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "141340095b15ed7491bd3d4ced9d20cebfb826174b6bb03386381f62b01e3d77" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d" "checksum itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "87fa75c9dea7b07be3138c49abbb83fd4bea199b5cdc76f9804458edc5da0d6e" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum js-sys 0.3.31 (registry+https://github.com/rust-lang/crates.io-index)" = "d8657b7ca06a6044ece477f6900bf7670f8b5fd0cce177a1d7094eef51e0adf4" @@ -3451,6 +3683,8 @@ dependencies = [ "checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" +"checksum prost-amino 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04c5c4189b6c3e054c064a0c88d51f9379db268d5f8f6ea6afffd3849aeca1a7" +"checksum prost-amino-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6376b995db84c9791ab5d3f7bc3e315f8bc1a55fe139a0a2da24aa24e27de809" "checksum protobuf 2.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40361836defdd5871ff7e84096c6f6444af7fc157f8ef1789f54f147687caa20" "checksum protobuf-codegen 2.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "12c6abd78435445fc86898ebbd0521a68438063d4a73e23527b7134e6bf58b4a" "checksum protobuf-codegen-pure 2.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c1646acda5319f5b28b0bff4a484324df43ddae2c0f5a3f3e63c0b26095cd600" @@ -3518,8 +3752,12 @@ dependencies = [ "checksum sgx_types 1.0.9 (git+https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.9)" = "" "checksum sgx_unwind 0.0.1 (git+https://github.com/baidu/rust-sgx-sdk.git?rev=v1.0.9)" = "" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" +"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" +"checksum signatory 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92785dea71e4d1d2b2c5dceee9cdaf809a177e3865b29d246b0314f4ecc110b0" +"checksum signatory-dalek 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3891c134888db96183ebfa6d1f6bf5b4c566b3a43d40d219cd5959620bbcdd" +"checksum signature 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "144b5d1138a4339c839603f15f69ffe3195e51b5caa92f815b47d4553db47337" "checksum skeptic 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24ebf8a06f5f8bae61ae5bbc7af7aac4ef6907ae975130faba1199e5fe82256a" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum sled 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d7c3453de0f6a77abdd17cc9f68d6650214abd088b052b13302f86fa9a5b286e" @@ -3535,11 +3773,16 @@ dependencies = [ "checksum structopt-derive 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "519621841414165d2ad0d4c92be8f41844203f2b67e245f9345a5a12d40c69d7" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab3af2eb31c42e8f0ccf43548232556c42737e01a96db6e1777b0be108e79799" +"checksum subtle-encoding 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "661a0cd6c74eca6fab1a5b452d9f2201fbac9004e958bd70d5b4f288b1aed479" +"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" "checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" +"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +"checksum tai64 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4014289c3d2b8168880ae86633247e73712fcc579969aff0ca7c5dcd17456b82" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +"checksum tendermint 0.10.0 (git+https://github.com/crypto-com/tendermint-rs.git?rev=bb27fdc5dd0ce59767badab246d1d4c203cf3d23)" = "" "checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" "checksum termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8fb22f7cde82c8220e5aeacb3258ed7ce996142c77cba193f203515e26c330" "checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" @@ -3580,6 +3823,7 @@ dependencies = [ "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" "checksum vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" @@ -3607,6 +3851,8 @@ dependencies = [ "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum yasna 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a563d10ead87e2d798e357d44f40f495ad70bcee4d5c0d3f77a5b1b7376645d9" "checksum zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ddfeb6eee2fb3b262ef6e0898a52b7563bb8e0d5955a313b3cf2f808246ea14" +"checksum zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" "checksum zeroize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdc979d9b5ead18184c357c4d8a3f81b579aae264e32507223032e64715462d3" +"checksum zeroize_derive 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "080616bd0e31f36095288bb0acdf1f78ef02c2fa15527d7e993f2a6c7591643e" "checksum zmq 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aad98a7a617d608cd9e1127147f630d24af07c7cd95ba1533246d96cbdd76c66" "checksum zmq-sys 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d33a2c51dde24d5b451a2ed4b488266df221a5eaee2ee519933dc46b9a9b3648" diff --git a/client-cli/src/command.rs b/client-cli/src/command.rs index c95550177..45b9c9a49 100644 --- a/client-cli/src/command.rs +++ b/client-cli/src/command.rs @@ -16,6 +16,7 @@ use structopt::StructOpt; use chain_core::init::coin::Coin; use chain_core::state::account::StakedStateAddress; use client_common::storage::SledStorage; +use client_common::tendermint::types::GenesisExt; use client_common::tendermint::{Client, WebsocketRpcClient}; use client_common::{ErrorKind, Result, ResultExt, Storage}; #[cfg(not(feature = "mock-enc-dec"))] diff --git a/client-common/Cargo.toml b/client-common/Cargo.toml index 639f4fdc5..5dcd1b51f 100644 --- a/client-common/Cargo.toml +++ b/client-common/Cargo.toml @@ -23,6 +23,7 @@ jsonrpc = { version = "0.11", optional = true } serde_json = { version = "1.0", optional = true } parity-scale-codec = { features = ["derive"], version = "1.0" } websocket = { version = "0.24", default-features = false, features = ["sync"], optional = true } +tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", rev = "bb27fdc5dd0ce59767badab246d1d4c203cf3d23" } [features] default = ["sled", "websocket-rpc"] diff --git a/client-common/src/block_header.rs b/client-common/src/block_header.rs index 952baec09..dbec4dc8b 100644 --- a/client-common/src/block_header.rs +++ b/client-common/src/block_header.rs @@ -1,8 +1,7 @@ -use chrono::{DateTime, Utc}; - use chain_core::tx::data::TxId; use chain_tx_filter::BlockFilter; +use crate::tendermint::types::Time; use crate::Transaction; /// Structure for representing a block header on Crypto.com Chain @@ -13,7 +12,7 @@ pub struct BlockHeader { /// Block height pub block_height: u64, /// Block time - pub block_time: DateTime, + pub block_time: Time, /// List of successfully committed transaction ids in this block pub transaction_ids: Vec, /// Bloom filter for view keys and staking addresses diff --git a/client-common/src/error.rs b/client-common/src/error.rs index be10810d6..84f904eaa 100644 --- a/client-common/src/error.rs +++ b/client-common/src/error.rs @@ -54,7 +54,15 @@ impl Error { impl fmt::Display for Error { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}: {}", self.kind, self.message) + write!( + f, + "{}: {}, {}", + self.kind, + self.message, + self.origin + .as_ref() + .map_or("".to_owned(), |err| err.to_string()) + ) } } diff --git a/client-common/src/tendermint/client.rs b/client-common/src/tendermint/client.rs index cab3e0d80..c2a316348 100644 --- a/client-common/src/tendermint/client.rs +++ b/client-common/src/tendermint/client.rs @@ -1,4 +1,3 @@ -use crate::tendermint::types::QueryResult; use crate::tendermint::types::*; use crate::Result; @@ -26,8 +25,8 @@ pub trait Client: Send + Sync { ) -> Result>; /// Makes `broadcast_tx_sync` call to tendermint - fn broadcast_transaction(&self, transaction: &[u8]) -> Result; + fn broadcast_transaction(&self, transaction: &[u8]) -> Result; /// Makes `abci_query` call to tendermint - fn query(&self, path: &str, data: &[u8]) -> Result; + fn query(&self, path: &str, data: &[u8]) -> Result; } diff --git a/client-common/src/tendermint/http_rpc_client.rs b/client-common/src/tendermint/http_rpc_client.rs index d73fb9dcc..c246f952f 100644 --- a/client-common/src/tendermint/http_rpc_client.rs +++ b/client-common/src/tendermint/http_rpc_client.rs @@ -106,7 +106,9 @@ impl RpcClient { impl Client for RpcClient { fn genesis(&self) -> Result { - self.call("genesis", Default::default()) + Ok(self + .call::("genesis", Default::default())? + .genesis) } fn status(&self) -> Result { @@ -115,18 +117,20 @@ impl Client for RpcClient { fn block(&self, height: u64) -> Result { let params = [json!(height.to_string())]; - self.call("block", ¶ms) + Ok(self.call::("block", ¶ms)?.block) } fn block_batch<'a, T: Iterator>(&self, heights: T) -> Result> { let params = heights .map(|height| ("block", vec![json!(height.to_string())])) .collect::)>>(); - let response = self.call_batch::(¶ms)?; - response - .into_iter() - .map(|block| block.chain(|| (ErrorKind::InvalidInput, "Block information not found"))) + let mut rsps = self.call_batch::(¶ms)?; + rsps.drain(..) + .map(|rsp| { + rsp.chain(|| (ErrorKind::InvalidInput, "Block information not found")) + .map(|rsp_| rsp_.block) + }) .collect::>>() } @@ -157,29 +161,37 @@ impl Client for RpcClient { .collect::>>() } - fn broadcast_transaction(&self, transaction: &[u8]) -> Result { + fn broadcast_transaction(&self, transaction: &[u8]) -> Result { let params = [json!(transaction)]; - self.call::("broadcast_tx_sync", ¶ms) + self.call::("broadcast_tx_sync", ¶ms) .and_then(|result| { - if result.code != 0 { - Err(Error::new(ErrorKind::TendermintRpcError, result.log)) + if result.code.is_err() { + Err(Error::new( + ErrorKind::TendermintRpcError, + result.log.to_string(), + )) } else { Ok(result) } }) } - fn query(&self, path: &str, data: &[u8]) -> Result { + fn query(&self, path: &str, data: &[u8]) -> Result { let params = [ json!(path), json!(hex::encode(data)), json!(null), json!(null), ]; - let result = self.call::("abci_query", ¶ms)?; + let result = self + .call::("abci_query", ¶ms)? + .response; - if result.code() != 0 { - return Err(Error::new(ErrorKind::TendermintRpcError, result.log())); + if result.code.is_err() { + return Err(Error::new( + ErrorKind::TendermintRpcError, + result.log.to_string(), + )); } Ok(result) diff --git a/client-common/src/tendermint/types.rs b/client-common/src/tendermint/types.rs index d8b0bb6c9..6aa5d081f 100644 --- a/client-common/src/tendermint/types.rs +++ b/client-common/src/tendermint/types.rs @@ -1,13 +1,98 @@ -//! Structures used in Tendermint RPC (auto-generated) -mod block; +//! Structures used in Tendermint RPC mod block_results; -mod broadcast_tx_result; -mod genesis; -mod query; -mod status; -pub use block::*; -pub use block_results::*; -pub use broadcast_tx_result::*; -pub use genesis::*; -pub use query::*; -pub use status::*; +pub mod mock; + +use base64::decode; +use parity_scale_codec::Decode; +use serde::{Deserialize, Serialize}; + +use crate::{ErrorKind, Result, ResultExt, Transaction}; +use chain_core::init::config::InitConfig; +use chain_core::tx::fee::LinearFee; +use chain_core::tx::{TxAux, TxEnclaveAux}; + +pub use self::block_results::*; +pub use tendermint::rpc::endpoint::{ + abci_query::AbciQuery, abci_query::Response as AbciQueryResponse, + block::Response as BlockResponse, broadcast::tx_sync::Response as BroadcastTxResponse, + status::Response as Status, +}; +pub use tendermint::rpc::endpoint::{broadcast, status}; +pub use tendermint::{ + abci, abci::transaction::Data, abci::Code, block::Header, block::Height, Block, + Genesis as GenericGenesis, Hash, Time, +}; + +/// crypto-com instantiated genesis type +pub type Genesis = GenericGenesis; + +/// crypto-com instantiated genesis type +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct GenesisResponse { + /// Genesis data + pub genesis: Genesis, +} + +/// crypto-chain specific methods. +pub trait BlockExt { + /// Returns un-encrypted transactions in a block (this may also contain invalid transactions) + fn unencrypted_transactions(&self) -> Result>; +} + +impl BlockExt for Block { + /// NOTE: Un-encrypted transactions only contain deposit stake and unbond stake transactions + fn unencrypted_transactions(&self) -> Result> { + self.data + .iter() + .map(|raw| -> Result { + TxAux::decode(&mut raw.clone().into_vec().as_slice()).chain(|| { + ( + ErrorKind::DeserializationError, + "Unable to decode transactions from bytes in a block", + ) + }) + }) + .filter_map(|tx_aux_result| match tx_aux_result { + Err(e) => Some(Err(e)), + Ok(tx_aux) => match tx_aux { + TxAux::EnclaveTx(TxEnclaveAux::DepositStakeTx { tx, .. }) => { + Some(Ok(Transaction::DepositStakeTransaction(tx))) + } + TxAux::UnbondStakeTx(tx, _) => { + Some(Ok(Transaction::UnbondStakeTransaction(tx))) + } + _ => None, + }, + }) + .collect::>>() + } +} + +/// crypto-chain specific methods. +pub trait GenesisExt { + /// get fee policy + fn fee_policy(&self) -> LinearFee; +} + +impl GenesisExt for Genesis { + fn fee_policy(&self) -> LinearFee { + self.app_state.network_params.initial_fee_policy + } +} + +/// crypto-chain specific methods. +pub trait AbciQueryExt { + /// decode query result with base64 + fn bytes(&self) -> Result>; +} + +impl AbciQueryExt for AbciQuery { + fn bytes(&self) -> Result> { + Ok(decode(&self.value).chain(|| { + ( + ErrorKind::DeserializationError, + "Unable to decode base64 bytes on query result", + ) + })?) + } +} diff --git a/client-common/src/tendermint/types/block.rs b/client-common/src/tendermint/types/block.rs deleted file mode 100644 index d36da9ba3..000000000 --- a/client-common/src/tendermint/types/block.rs +++ /dev/null @@ -1,222 +0,0 @@ -#![allow(missing_docs)] -use base64::decode; -use chrono::offset::Utc; -use chrono::DateTime; -use parity_scale_codec::Decode; -use serde::Deserialize; - -use chain_core::tx::{TxAux, TxEnclaveAux}; - -use crate::{ErrorKind, Result, ResultExt, Transaction}; - -#[derive(Debug, Deserialize)] -pub struct Block { - pub block: BlockInner, -} - -#[derive(Debug, Deserialize)] -pub struct BlockInner { - pub header: Header, - pub data: Data, -} - -#[derive(Debug, Deserialize)] -pub struct Data { - pub txs: Option>, -} - -#[derive(Debug, Deserialize)] -pub struct Header { - pub app_hash: String, - pub height: String, - pub time: DateTime, -} - -impl Block { - /// Returns un-encrypted transactions in a block (this may also contain invalid transactions) - /// - /// NOTE: Un-encrypted transactions only contain deposit stake and unbond stake transactions - pub fn unencrypted_transactions(&self) -> Result> { - match &self.block.data.txs { - None => Ok(Vec::new()), - Some(transactions) => transactions - .iter() - .map(|raw_transaction| -> Result { - let decoded = decode(&raw_transaction).chain(|| { - ( - ErrorKind::DeserializationError, - "Unable to decode raw base64 bytes of transactions from block", - ) - })?; - TxAux::decode(&mut decoded.as_slice()).chain(|| { - ( - ErrorKind::DeserializationError, - "Unable to decode transactions from bytes in a block", - ) - }) - }) - .filter_map(|tx_aux_result| match tx_aux_result { - Err(e) => Some(Err(e)), - Ok(tx_aux) => match tx_aux { - TxAux::EnclaveTx(TxEnclaveAux::DepositStakeTx { tx, .. }) => { - Some(Ok(Transaction::DepositStakeTransaction(tx))) - } - TxAux::UnbondStakeTx(tx, _) => { - Some(Ok(Transaction::UnbondStakeTransaction(tx))) - } - _ => None, - }, - }) - .collect::>>(), - } - } - - /// Returns height of this block - pub fn height(&self) -> Result { - self.block.header.height.parse::().chain(|| { - ( - ErrorKind::DeserializationError, - "Unable to convert block height into integer", - ) - }) - } - - /// Returns time of this block - #[inline] - pub fn time(&self) -> DateTime { - self.block.header.time - } - - /// Returns app hash of this block - #[inline] - pub fn app_hash(&self) -> String { - self.block.header.app_hash.clone() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use std::str::FromStr; - - use base64::encode; - use parity_scale_codec::Encode; - use secp256k1::recovery::{RecoverableSignature, RecoveryId}; - - use chain_core::init::address::RedeemAddress; - use chain_core::init::coin::Coin; - use chain_core::state::account::{ - StakedStateAddress, StakedStateOpAttributes, StakedStateOpWitness, UnbondTx, - }; - use chain_core::tx::TxObfuscated; - - fn unbond_transaction() -> TxAux { - let addr = StakedStateAddress::from( - RedeemAddress::from_str("0x0e7c045110b8dbf29765047380898919c5cb56f4").unwrap(), - ); - TxAux::UnbondStakeTx( - UnbondTx::new( - addr, - 0, - Coin::new(100).unwrap(), - StakedStateOpAttributes::new(0), - ), - StakedStateOpWitness::BasicRedeem( - RecoverableSignature::from_compact( - &[ - 0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f, 0x04, 0x77, 0x2b, 0x6f, - 0x92, 0x1f, 0x0b, 0xa6, 0xaf, 0x0c, 0x1e, 0x77, 0xfc, 0x43, 0x9e, 0x65, - 0xc3, 0x6d, 0xed, 0xf4, 0x09, 0x2e, 0x88, 0x98, 0x4c, 0x1a, 0x97, 0x16, - 0x52, 0xe0, 0xad, 0xa8, 0x80, 0x12, 0x0e, 0xf8, 0x02, 0x5e, 0x70, 0x9f, - 0xff, 0x20, 0x80, 0xc4, 0xa3, 0x9a, 0xae, 0x06, 0x8d, 0x12, 0xee, 0xd0, - 0x09, 0xb6, 0x8c, 0x89, - ], - RecoveryId::from_i32(1).unwrap(), - ) - .unwrap(), - ), - ) - } - - fn transfer_transaction() -> TxAux { - TxAux::EnclaveTx(TxEnclaveAux::TransferTx { - inputs: Vec::new(), - no_of_outputs: 0, - payload: TxObfuscated { - txid: [0; 32], - key_from: 0, - init_vector: [0; 12], - txpayload: Vec::new(), - }, - }) - } - - #[test] - fn check_unencrypted_transactions() { - let transaction = unbond_transaction(); - let transfer_transaction = transfer_transaction(); - - let block = Block { - block: BlockInner { - header: Header { - app_hash: "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_owned(), - height: "1".to_owned(), - time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - }, - data: Data { - txs: Some(vec![ - encode(&transaction.encode()), - encode(&transfer_transaction.encode()), - ]), - }, - }, - }; - - let unencrypted_transactions = block.unencrypted_transactions().unwrap(); - assert_eq!(1, unencrypted_transactions.len()); - - match (transaction, &unencrypted_transactions[0]) { - ( - TxAux::UnbondStakeTx(ref unbond_transaction, _), - Transaction::UnbondStakeTransaction(ref unencrypted_unbond_transaction), - ) => assert_eq!(unencrypted_unbond_transaction, unbond_transaction), - _ => unreachable!(), - } - } - - #[test] - fn check_height() { - let block = Block { - block: BlockInner { - header: Header { - app_hash: "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_owned(), - height: "1".to_owned(), - time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - }, - data: Data { txs: None }, - }, - }; - - assert_eq!(1, block.height().unwrap()); - } - - #[test] - fn check_wrong_height() { - let block = Block { - block: BlockInner { - header: Header { - app_hash: "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_owned(), - height: "a".to_owned(), - time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - }, - data: Data { txs: None }, - }, - }; - - assert!(block.height().is_err()); - } -} diff --git a/client-common/src/tendermint/types/block_results.rs b/client-common/src/tendermint/types/block_results.rs index 703057004..75e3c6223 100644 --- a/client-common/src/tendermint/types/block_results.rs +++ b/client-common/src/tendermint/types/block_results.rs @@ -8,11 +8,12 @@ use chain_core::common::TendermintEventType; use chain_core::tx::data::TxId; use chain_tx_filter::BlockFilter; +use crate::tendermint::types::Height; use crate::{Error, ErrorKind, Result, ResultExt}; #[derive(Debug, Deserialize)] pub struct BlockResults { - pub height: String, + pub height: Height, pub results: Results, } @@ -145,7 +146,7 @@ mod tests { #[test] fn check_ids() { let block_results = BlockResults { - height: "2".to_owned(), + height: Height::default().increment(), results: Results { deliver_tx: Some(vec![DeliverTx { events: vec![Event { @@ -165,7 +166,7 @@ mod tests { #[test] fn check_block_filter() { let block_results = BlockResults { - height: "2".to_owned(), + height: Height::default().increment(), results: Results { deliver_tx: None, end_block: Some(EndBlock { @@ -185,7 +186,7 @@ mod tests { #[test] fn check_wrong_id() { let block_results = BlockResults { - height: "2".to_owned(), + height: Height::default().increment(), results: Results { deliver_tx: Some(vec![DeliverTx { events: vec![Event { @@ -206,7 +207,7 @@ mod tests { #[test] fn check_null_deliver_tx() { let block_results = BlockResults { - height: "2".to_owned(), + height: Height::default().increment(), results: Results { deliver_tx: None, end_block: None, diff --git a/client-common/src/tendermint/types/broadcast_tx_result.rs b/client-common/src/tendermint/types/broadcast_tx_result.rs deleted file mode 100644 index 8ffc73d7d..000000000 --- a/client-common/src/tendermint/types/broadcast_tx_result.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(missing_docs)] -use serde::Deserialize; - -#[derive(Debug, Deserialize)] -pub struct BroadcastTxResult { - pub code: u8, - pub data: String, - pub hash: String, - pub log: String, -} diff --git a/client-common/src/tendermint/types/genesis.rs b/client-common/src/tendermint/types/genesis.rs deleted file mode 100644 index 0753133db..000000000 --- a/client-common/src/tendermint/types/genesis.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![allow(missing_docs)] - -use chrono::offset::Utc; -use chrono::DateTime; -use serde::Deserialize; - -use chain_core::init::config::InitConfig; -use chain_core::tx::fee::LinearFee; - -#[derive(Debug, Deserialize)] -pub struct Genesis { - pub genesis: GenesisInner, -} - -#[derive(Debug, Deserialize)] -pub struct GenesisInner { - pub genesis_time: DateTime, - pub chain_id: String, - pub app_state: InitConfig, -} - -impl Genesis { - /// Returns time of genesis - pub fn time(&self) -> DateTime { - self.genesis.genesis_time - } - - /// Returns initial_fee_policy - pub fn fee_policy(&self) -> LinearFee { - self.genesis.app_state.network_params.initial_fee_policy - } -} diff --git a/client-common/src/tendermint/types/mock.rs b/client-common/src/tendermint/types/mock.rs new file mode 100644 index 000000000..aeaf31f7c --- /dev/null +++ b/client-common/src/tendermint/types/mock.rs @@ -0,0 +1,121 @@ +#![allow(missing_docs)] +use super::*; +use serde_json; +use std::str::FromStr; +use tendermint::{ + account, block, chain, channel, net, node, validator, vote, Moniker, PrivateKey, PublicKey, + Version, +}; + +static DEFAULT_VALIDATOR_KEY: &str = "{ + \"type\": \"tendermint/PrivKeyEd25519\", + \"value\": \"gJWgIetdLxRc/C2t/XjV65NCqZLTqHS9pU69kBzRmyOKCHDqT/6bKPmKajdBp+KCbYtu9ttTX7+MXrEQOw8Kqg==\" +}"; +static BLOCK_VERSION: u64 = 10; +static APP_VERSION: u64 = 0; +static APP_HASH: &str = "93E6C15E5A52CAAB971A810E5F6F9C4965AA102C81120FCEDCB7F8A112270380"; + +pub fn validator_priv_key() -> PrivateKey { + serde_json::from_str(DEFAULT_VALIDATOR_KEY).unwrap() +} + +pub fn validator_pub_key() -> PublicKey { + validator_priv_key().public_key() +} + +pub fn validator_account_id() -> account::Id { + validator_pub_key().into() +} + +pub fn default_chain_id() -> chain::Id { + chain::Id::from_str("test-chain-ktDVXo-AB").unwrap() +} + +pub fn validator_info() -> validator::Info { + validator::Info { + address: validator_account_id(), + pub_key: validator_pub_key(), + voting_power: vote::Power::new(12500000000), + proposer_priority: None, + } +} + +pub fn node_info() -> node::Info { + node::Info { + protocol_version: node::info::ProtocolVersionInfo { + p2p: 7, + block: BLOCK_VERSION, + app: APP_VERSION, + }, + id: node::Id::from_str("7edc638f79308dfdfcd77b743e1375b8e1cea6f2").unwrap(), + listen_addr: node::info::ListenAddress::new("tcp://0.0.0.0:26656".to_owned()), + network: default_chain_id(), + version: Version::default(), + channels: channel::Channels::default(), + moniker: Moniker::from_str("test").unwrap(), + other: node::info::OtherInfo { + tx_index: node::info::TxIndexStatus::On, + rpc_address: net::Address::from_str("tcp://127.0.0.1:26657").unwrap(), + }, + } +} + +pub fn default_header() -> Header { + Header { + version: block::header::Version { + block: BLOCK_VERSION, + app: APP_VERSION, + }, + chain_id: default_chain_id(), + height: Height::default(), + time: Time::default(), + num_txs: 0, + total_txs: 0, + last_block_id: block::Id::default(), + last_commit_hash: Hash::default(), + data_hash: Hash::default(), + validators_hash: Hash::default(), + next_validators_hash: Hash::default(), + consensus_hash: Hash::default(), + app_hash: Hash::from_str(APP_HASH).unwrap(), + last_results_hash: Hash::default(), + evidence_hash: Hash::default(), + proposer_address: validator_account_id(), + } +} + +pub fn default_block() -> Block { + Block { + header: default_header(), + data: Default::default(), + evidence: Default::default(), + last_commit: block::Commit { + block_id: Default::default(), + precommits: Default::default(), + }, + } +} + +pub fn status_response() -> Status { + Status { + node_info: node_info(), + sync_info: status::SyncInfo::default(), + validator_info: validator_info(), + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json; + + #[test] + fn check_status_response() { + println!("{}", serde_json::to_string(&status_response()).unwrap()); + } + + #[test] + fn check_default_header() { + println!("{}", serde_json::to_string(&default_header()).unwrap()); + } +} diff --git a/client-common/src/tendermint/types/query.rs b/client-common/src/tendermint/types/query.rs deleted file mode 100644 index 276a53b90..000000000 --- a/client-common/src/tendermint/types/query.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![allow(missing_docs)] -use base64::decode; -use serde::Deserialize; - -use crate::{ErrorKind, Result, ResultExt}; - -#[derive(Debug, Deserialize)] -pub struct QueryResult { - pub response: Response, -} - -#[derive(Debug, Deserialize)] -pub struct Response { - #[serde(default)] - pub code: u8, - #[serde(default)] - pub value: String, - #[serde(default)] - pub log: String, -} - -impl QueryResult { - pub fn bytes(&self) -> Result> { - Ok(decode(&self.response.value).chain(|| { - ( - ErrorKind::DeserializationError, - "Unable to decode base64 bytes on query result", - ) - })?) - } - - #[inline] - pub fn code(&self) -> u8 { - self.response.code - } - - #[inline] - pub fn log(&self) -> &str { - &self.response.log - } -} diff --git a/client-common/src/tendermint/types/status.rs b/client-common/src/tendermint/types/status.rs deleted file mode 100644 index 0e4116feb..000000000 --- a/client-common/src/tendermint/types/status.rs +++ /dev/null @@ -1,75 +0,0 @@ -#![allow(missing_docs)] -use serde::Deserialize; - -use crate::{ErrorKind, Result, ResultExt}; - -#[derive(Debug, Deserialize)] -pub struct Status { - pub sync_info: SyncInfo, -} - -#[derive(Debug, Deserialize)] -pub struct SyncInfo { - pub latest_block_height: String, - pub latest_app_hash: String, -} - -impl Status { - /// Returns last block height - pub fn last_block_height(&self) -> Result { - Ok(self - .sync_info - .latest_block_height - .parse::() - .chain(|| { - ( - ErrorKind::DeserializationError, - "Unable to convert last block height into integer", - ) - })?) - } - - /// Returns last app hash - #[inline] - pub fn last_app_hash(&self) -> String { - self.sync_info.latest_app_hash.clone() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn check_last_block_height() { - let status = Status { - sync_info: SyncInfo { - latest_block_height: "1".to_owned(), - latest_app_hash: "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), - }, - }; - assert_eq!(1, status.last_block_height().unwrap()); - assert_eq!( - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C".to_string(), - status.last_app_hash() - ); - } - - #[test] - fn check_wrong_last_block_height() { - let status = Status { - sync_info: SyncInfo { - latest_block_height: "a".to_owned(), - latest_app_hash: "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), - }, - }; - - assert!(status.last_block_height().is_err()); - assert_eq!( - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C".to_string(), - status.last_app_hash() - ); - } -} diff --git a/client-common/src/tendermint/unauthorized_client.rs b/client-common/src/tendermint/unauthorized_client.rs index af083348b..da105bbcb 100644 --- a/client-common/src/tendermint/unauthorized_client.rs +++ b/client-common/src/tendermint/unauthorized_client.rs @@ -35,11 +35,11 @@ impl Client for UnauthorizedClient { Err(ErrorKind::PermissionDenied.into()) } - fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { + fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { Err(ErrorKind::PermissionDenied.into()) } - fn query(&self, _path: &str, _data: &[u8]) -> Result { + fn query(&self, _path: &str, _data: &[u8]) -> Result { Err(ErrorKind::PermissionDenied.into()) } } diff --git a/client-common/src/tendermint/websocket_rpc_client.rs b/client-common/src/tendermint/websocket_rpc_client.rs index 54eed6272..a337594e8 100644 --- a/client-common/src/tendermint/websocket_rpc_client.rs +++ b/client-common/src/tendermint/websocket_rpc_client.rs @@ -268,7 +268,9 @@ impl WebsocketRpcClient { impl Client for WebsocketRpcClient { #[inline] fn genesis(&self) -> Result { - self.call("genesis", Default::default()) + Ok(self + .call::("genesis", Default::default())? + .genesis) } #[inline] @@ -279,7 +281,7 @@ impl Client for WebsocketRpcClient { #[inline] fn block(&self, height: u64) -> Result { let params = [json!(height.to_string())]; - self.call("block", ¶ms) + Ok(self.call::("block", ¶ms)?.block) } #[inline] @@ -287,7 +289,8 @@ impl Client for WebsocketRpcClient { let params = heights .map(|height| ("block", vec![json!(height.to_string())])) .collect::)>>(); - self.call_batch::(params) + let mut rsps = self.call_batch::(params)?; + Ok(rsps.drain(..).map(|rsp| rsp.block).collect()) } #[inline] @@ -307,31 +310,33 @@ impl Client for WebsocketRpcClient { self.call_batch::(params) } - fn broadcast_transaction(&self, transaction: &[u8]) -> Result { + fn broadcast_transaction(&self, transaction: &[u8]) -> Result { let params = [json!(transaction)]; - let broadcast_tx_result: BroadcastTxResult = self.call("broadcast_tx_sync", ¶ms)?; + let rsp = self.call::("broadcast_tx_sync", ¶ms)?; - if broadcast_tx_result.code != 0 { - Err(Error::new( - ErrorKind::TendermintRpcError, - broadcast_tx_result.log, - )) + if rsp.code.is_err() { + Err(Error::new(ErrorKind::TendermintRpcError, rsp.log.as_ref())) } else { - Ok(broadcast_tx_result) + Ok(rsp) } } - fn query(&self, path: &str, data: &[u8]) -> Result { + fn query(&self, path: &str, data: &[u8]) -> Result { let params = [ json!(path), json!(hex::encode(data)), json!(null), json!(null), ]; - let result: QueryResult = self.call("abci_query", ¶ms)?; + let result = self + .call::("abci_query", ¶ms)? + .response; - if result.code() != 0 { - return Err(Error::new(ErrorKind::TendermintRpcError, result.log())); + if result.code.is_err() { + return Err(Error::new( + ErrorKind::TendermintRpcError, + result.log.to_string(), + )); } Ok(result) diff --git a/client-core/src/cipher/mock_abci_transaction_obfuscation.rs b/client-core/src/cipher/mock_abci_transaction_obfuscation.rs index bc8d1bedf..ff7e0fb76 100644 --- a/client-core/src/cipher/mock_abci_transaction_obfuscation.rs +++ b/client-core/src/cipher/mock_abci_transaction_obfuscation.rs @@ -2,6 +2,7 @@ use parity_scale_codec::{Decode, Encode}; use chain_core::tx::data::TxId; use chain_core::tx::{TxAux, TxWithOutputs}; +use client_common::tendermint::types::AbciQueryExt; use client_common::tendermint::Client; use client_common::{ ErrorKind, PrivateKey, Result, ResultExt, SignedTransaction, Transaction, SECP, @@ -163,11 +164,11 @@ mod tests { unreachable!() } - fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { + fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { unreachable!() } - fn query(&self, path: &str, _data: &[u8]) -> Result { + fn query(&self, path: &str, _data: &[u8]) -> Result { match path { "mockdecrypt" => { let response = DecryptionResponse { @@ -175,12 +176,9 @@ mod tests { } .encode(); - Ok(QueryResult { - response: Response { - code: 0, - value: encode(&response), - log: "".to_owned(), - }, + Ok(AbciQuery { + value: encode(&response), + ..Default::default() }) } "mockencrypt" => { @@ -189,12 +187,9 @@ mod tests { } .encode(); - Ok(QueryResult { - response: Response { - code: 0, - value: encode(&response), - log: "".to_owned(), - }, + Ok(AbciQuery { + value: encode(&response), + ..Default::default() }) } _ => Err(ErrorKind::InvalidInput.into()), diff --git a/client-core/src/handler.rs b/client-core/src/handler.rs index 5379bb559..7f59c68de 100644 --- a/client-core/src/handler.rs +++ b/client-core/src/handler.rs @@ -5,9 +5,9 @@ mod default_transaction_handler; pub use default_block_handler::DefaultBlockHandler; pub use default_transaction_handler::DefaultTransactionHandler; -use chrono::{DateTime, Utc}; use secstr::SecUtf8; +use client_common::tendermint::types::Time; use client_common::{BlockHeader, Result, Transaction}; /// Interface for handling stream of transactions in Crypto.com Chain @@ -19,7 +19,7 @@ pub trait TransactionHandler: Send + Sync { passphrase: &SecUtf8, transaction: Transaction, block_height: u64, - block_time: DateTime, + block_time: Time, ) -> Result<()>; } diff --git a/client-core/src/handler/default_block_handler.rs b/client-core/src/handler/default_block_handler.rs index f25c8b75a..ed6f05526 100644 --- a/client-core/src/handler/default_block_handler.rs +++ b/client-core/src/handler/default_block_handler.rs @@ -108,8 +108,6 @@ mod tests { use std::str::FromStr; - use chrono::{DateTime, Utc}; - use chain_core::init::address::RedeemAddress; use chain_core::init::coin::Coin; use chain_core::state::account::{StakedStateAddress, StakedStateOpAttributes, UnbondTx}; @@ -120,6 +118,7 @@ mod tests { use chain_core::tx::{TransactionId, TxAux}; use chain_tx_filter::BlockFilter; use client_common::storage::MemoryStorage; + use client_common::tendermint::types::Time; use client_common::{PrivateKey, PublicKey, SignedTransaction, Transaction}; use crate::types::WalletKind; @@ -153,14 +152,14 @@ mod tests { _passphrase: &SecUtf8, transaction: Transaction, block_height: u64, - block_time: DateTime, + block_time: Time, ) -> Result<()> { if transaction != transfer_transaction() && transaction != unbond_transaction() { panic!("Invalid transaction") } assert_eq!(1, block_height); assert_eq!( - >::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), block_time ); Ok(()) @@ -198,10 +197,9 @@ mod tests { block_filter.add_view_key(&view_key.into()); BlockHeader { - app_hash: "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), + app_hash: "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C".to_owned(), block_height: 1, - block_time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + block_time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), transaction_ids, block_filter, unencrypted_transactions: vec![unbond_transaction()], diff --git a/client-core/src/handler/default_transaction_handler.rs b/client-core/src/handler/default_transaction_handler.rs index fdab023c4..602415711 100644 --- a/client-core/src/handler/default_transaction_handler.rs +++ b/client-core/src/handler/default_transaction_handler.rs @@ -1,6 +1,5 @@ use std::collections::BTreeSet; -use chrono::{DateTime, Utc}; use secstr::SecUtf8; use chain_core::init::coin::Coin; @@ -9,6 +8,7 @@ use chain_core::tx::data::input::TxoPointer; use chain_core::tx::data::output::TxOut; use chain_core::tx::data::TxId; use chain_core::tx::TransactionId; +use client_common::tendermint::types::Time; use client_common::{Error, ErrorKind, Result, ResultExt, Storage, Transaction}; use crate::service::{WalletService, WalletStateService}; @@ -49,7 +49,7 @@ where passphrase: &SecUtf8, transaction: Transaction, block_height: u64, - block_time: DateTime, + block_time: Time, ) -> Result<()> { let transaction_id = transaction.id(); let inputs = self.decorate_inputs(name, passphrase, transaction.inputs().to_vec())?; @@ -278,7 +278,6 @@ fn get_total_output_amount(outputs: &[TxOut]) -> Result { #[cfg(test)] mod tests { use super::*; - use std::str::FromStr; use chain_core::tx::data::attribute::TxAttributes; @@ -336,7 +335,7 @@ mod tests { passphrase1, transactions[0].clone(), 0, - DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), ) .unwrap(); @@ -361,7 +360,7 @@ mod tests { passphrase1, transactions[1].clone(), 1, - DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), ) .unwrap(); @@ -385,7 +384,7 @@ mod tests { passphrase2, transactions[0].clone(), 0, - DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), ) .unwrap(); @@ -410,7 +409,7 @@ mod tests { passphrase2, transactions[1].clone(), 1, - DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), ) .unwrap(); diff --git a/client-core/src/service/wallet_state_service.rs b/client-core/src/service/wallet_state_service.rs index 3eb0baab5..2d1aee584 100644 --- a/client-core/src/service/wallet_state_service.rs +++ b/client-core/src/service/wallet_state_service.rs @@ -262,13 +262,11 @@ impl WalletStateMemento { #[cfg(test)] mod tests { use super::*; - use std::str::FromStr; - use chrono::DateTime; - use chain_core::tx::data::address::ExtendedAddr; use client_common::storage::MemoryStorage; + use client_common::tendermint::types::Time; use crate::types::{BalanceChange, TransactionType}; @@ -360,7 +358,7 @@ mod tests { }, transaction_type: TransactionType::Transfer, block_height: 0, - block_time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + block_time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), }); assert!(wallet_state_service @@ -404,7 +402,7 @@ mod tests { }, transaction_type: TransactionType::Transfer, block_height: 0, - block_time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + block_time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), }); assert!(wallet_state_service diff --git a/client-core/src/synchronizer/auto_sync_core.rs b/client-core/src/synchronizer/auto_sync_core.rs index 504641aec..1477ee5ed 100644 --- a/client-core/src/synchronizer/auto_sync_core.rs +++ b/client-core/src/synchronizer/auto_sync_core.rs @@ -3,7 +3,7 @@ //! change wallets and continue syncing use chain_core::state::account::StakedStateAddress; use chain_tx_filter::BlockFilter; -use client_common::tendermint::types::Block; +use client_common::tendermint::types::{Block, BlockExt}; use client_common::tendermint::Client; use client_common::{BlockHeader, ErrorKind, Result, ResultExt, Storage, Transaction}; use futures::sink::Sink; @@ -148,7 +148,7 @@ where return Ok(()); } // restore as object - let height: u64 = block.height()?; + let height: u64 = block.header.height.value(); let current = self.get_current_height(); if height != current + 1 { log::info!( @@ -202,10 +202,10 @@ where /// low level block processing pub fn write_block(&self, block_height: u64, block: &Block) -> Result<()> { - let app_hash = block.app_hash(); + let app_hash = block.header.app_hash.to_string(); let block_results = self.client.block_results(block_height)?; - let block_time = block.time(); + let block_time = block.header.time; let transaction_ids = block_results.transaction_ids()?; let block_filter = block_results.block_filter()?; @@ -545,11 +545,10 @@ mod tests { use std::sync::Arc; use std::sync::Mutex; + use super::super::auto_sync_data::{AutoSyncData, AutoSyncSendQueue}; use client_common::storage::MemoryStorage; use client_common::tendermint::types::*; - use super::super::auto_sync_data::{AutoSyncData, AutoSyncSendQueue}; - struct MockClient; impl Client for MockClient { @@ -580,16 +579,11 @@ mod tests { unreachable!() } - fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { - Ok(BroadcastTxResult { - code: 0, - data: String::from(""), - hash: String::from(""), - log: String::from(""), - }) + fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { + Ok(BroadcastTxResponse::default()) } - fn query(&self, _path: &str, _data: &[u8]) -> Result { + fn query(&self, _path: &str, _data: &[u8]) -> Result { unreachable!() } } diff --git a/client-core/src/synchronizer/manual_synchronizer.rs b/client-core/src/synchronizer/manual_synchronizer.rs index f4f60790f..212eac719 100644 --- a/client-core/src/synchronizer/manual_synchronizer.rs +++ b/client-core/src/synchronizer/manual_synchronizer.rs @@ -6,7 +6,7 @@ use secstr::SecUtf8; use chain_core::state::account::StakedStateAddress; use chain_tx_filter::BlockFilter; -use client_common::tendermint::types::{Block, BlockResults, Status}; +use client_common::tendermint::types::{Block, BlockExt, BlockResults, Status}; use client_common::tendermint::Client; use client_common::{BlockHeader, Result, Storage, Transaction}; @@ -84,7 +84,7 @@ where let last_block_height = self .global_state_service .last_block_height(name, passphrase)?; - let current_block_height = status.last_block_height()?; + let current_block_height = status.sync_info.latest_block_height.value(); if let Some(ref sender) = &progress_reporter { let _ = sender.send(ProgressReport::Init { @@ -147,7 +147,7 @@ where if let Some(ref sender) = &progress_reporter { let _ = sender.send(ProgressReport::Update { - current_block_height: block.height()?, + current_block_height: block.header.height.value(), }); } } @@ -182,10 +182,10 @@ where progress_reporter: &Option>, ) -> Result { let last_app_hash = self.global_state_service.last_app_hash(name, passphrase)?; - let current_app_hash = status.last_app_hash(); + let current_app_hash = status.sync_info.latest_app_hash.to_string(); if current_app_hash == last_app_hash { - let current_block_height = status.last_block_height()?; + let current_block_height = status.sync_info.latest_block_height.value(); let block = self.client.block(current_block_height)?; let block_result = self.client.block_results(current_block_height)?; @@ -215,10 +215,10 @@ where progress_reporter: &Option>, ) -> Result { let last_app_hash = self.global_state_service.last_app_hash(name, passphrase)?; - let current_app_hash = block.app_hash(); + let current_app_hash = block.header.app_hash.to_string(); if current_app_hash == last_app_hash { - let current_block_height = block.height()?; + let current_block_height = block.header.height.value(); let block_result = self.client.block_results(current_block_height)?; @@ -257,9 +257,9 @@ fn prepare_block_header( block: &Block, block_result: &BlockResults, ) -> Result { - let app_hash = block.app_hash(); - let block_height = block.height()?; - let block_time = block.time(); + let app_hash = block.header.app_hash.to_string(); + let block_height = block.header.height.value(); + let block_time = block.header.time; let transaction_ids = block_result.transaction_ids()?; let block_filter = block_result.block_filter()?; @@ -284,7 +284,6 @@ mod tests { use std::str::FromStr; use base64::encode; - use chrono::DateTime; use parity_scale_codec::Encode; use secp256k1::recovery::{RecoverableSignature, RecoveryId}; @@ -296,6 +295,7 @@ mod tests { }; use chain_core::tx::TxAux; use client_common::storage::MemoryStorage; + use client_common::tendermint::types::mock::*; use client_common::tendermint::types::*; use client_common::ErrorKind; @@ -354,43 +354,45 @@ mod tests { fn status(&self) -> Result { Ok(Status { - sync_info: SyncInfo { - latest_block_height: "2".to_owned(), - latest_app_hash: - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), + sync_info: status::SyncInfo { + latest_block_height: Height::default().increment(), + latest_app_hash: Hash::from_str( + "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C", + ) + .unwrap(), + ..Default::default() }, + ..status_response() }) } fn block(&self, height: u64) -> Result { if height == 1 { Ok(Block { - block: BlockInner { - header: Header { - app_hash: - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3D" - .to_string(), - height: "1".to_owned(), - time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - }, - data: Data { txs: None }, + header: Header { + app_hash: Hash::from_str( + "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3D", + ) + .unwrap(), + height: height.into(), + time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + ..default_header() }, + ..default_block() }) } else if height == 2 { Ok(Block { - block: BlockInner { - header: Header { - app_hash: - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), - height: "2".to_owned(), - time: DateTime::from_str("2019-04-10T09:38:41.735577Z").unwrap(), - }, - data: Data { - txs: Some(vec![encode(&unbond_transaction().encode())]), - }, + header: Header { + app_hash: Hash::from_str( + "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C", + ) + .unwrap(), + height: height.into(), + time: Time::from_str("2019-04-10T09:38:41.735577Z").unwrap(), + ..default_header() }, + data: Data::new(vec![abci::Transaction::new(unbond_transaction().encode())]), + ..default_block() }) } else { Err(ErrorKind::InvalidInput.into()) @@ -404,7 +406,7 @@ mod tests { fn block_results(&self, height: u64) -> Result { if height == 1 { Ok(BlockResults { - height: "1".to_string(), + height: Height::default(), results: Results { deliver_tx: None, end_block: Some(EndBlock { @@ -423,7 +425,7 @@ mod tests { block_filter.add_staked_state_address(&self.staking_address); Ok(BlockResults { - height: "2".to_string(), + height: Height::default().increment(), results: Results { deliver_tx: Some(vec![DeliverTx { events: vec![Event { @@ -460,11 +462,11 @@ mod tests { heights.map(|height| self.block_results(*height)).collect() } - fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { + fn broadcast_transaction(&self, _transaction: &[u8]) -> Result { unreachable!() } - fn query(&self, _path: &str, _data: &[u8]) -> Result { + fn query(&self, _path: &str, _data: &[u8]) -> Result { unreachable!() } } diff --git a/client-core/src/types/transaction_change.rs b/client-core/src/types/transaction_change.rs index 7e35cd706..81a2b2c16 100644 --- a/client-core/src/types/transaction_change.rs +++ b/client-core/src/types/transaction_change.rs @@ -1,7 +1,7 @@ //! Types for tracking balance change in a wallet -use std::{ops::Add, str::FromStr}; +use std::ops::Add; +use std::str::FromStr; -use chrono::{DateTime, Utc}; use parity_scale_codec::{Decode, Encode, Error, Input, Output}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; @@ -9,6 +9,7 @@ use chain_core::{ init::coin::{Coin, CoinError}, tx::data::{input::TxoPointer, output::TxOut, TxId}, }; +use client_common::tendermint::types::Time; use client_common::{ErrorKind, Result, ResultExt, Transaction}; /// Transaction data with attached metadata @@ -30,7 +31,7 @@ pub struct TransactionChange { /// Height of block which has this transaction pub block_height: u64, /// Time of block which has this transaction - pub block_time: DateTime, + pub block_time: Time, } /// Transaction input @@ -132,7 +133,7 @@ impl Decode for TransactionChange { let balance_change = BalanceChange::decode(input)?; let transaction_type = TransactionType::decode(input)?; let block_height = u64::decode(input)?; - let block_time = DateTime::from_str(&String::decode(input)?) + let block_time = Time::from_str(&String::decode(input)?) .map_err(|_| Error::from("Unable to parse block time"))?; Ok(TransactionChange { transaction_id, @@ -195,9 +196,6 @@ impl From<&Transaction> for TransactionType { #[cfg(test)] mod tests { use super::*; - - use std::time::SystemTime; - use chain_core::{init::coin::Coin, tx::data::txid_hash}; #[test] @@ -211,7 +209,7 @@ mod tests { }, transaction_type: TransactionType::Transfer, block_height: 0, - block_time: DateTime::from(SystemTime::now()), + block_time: Time::now(), }; let encoded = transaction_change.encode(); diff --git a/client-core/src/wallet.rs b/client-core/src/wallet.rs index 41d3714ca..060b55021 100644 --- a/client-core/src/wallet.rs +++ b/client-core/src/wallet.rs @@ -20,7 +20,7 @@ use chain_core::tx::data::output::TxOut; use chain_core::tx::data::Tx; use chain_core::tx::witness::tree::RawPubkey; use chain_core::tx::TxAux; -use client_common::tendermint::types::BroadcastTxResult; +use client_common::tendermint::types::BroadcastTxResponse; use client_common::{PrivateKey, PublicKey, Result}; use crate::types::{AddressType, TransactionChange, WalletKind}; @@ -184,7 +184,7 @@ pub trait WalletClient: Send + Sync { ) -> Result; /// Broadcasts a transaction to Crypto.com Chain - fn broadcast_transaction(&self, tx_aux: &TxAux) -> Result; + fn broadcast_transaction(&self, tx_aux: &TxAux) -> Result; } /// Interface for a generic wallet for multi-signature transactions diff --git a/client-core/src/wallet/default_wallet_client.rs b/client-core/src/wallet/default_wallet_client.rs index 523f3ba57..4ad8891bb 100644 --- a/client-core/src/wallet/default_wallet_client.rs +++ b/client-core/src/wallet/default_wallet_client.rs @@ -17,7 +17,7 @@ use chain_core::tx::data::Tx; use chain_core::tx::witness::tree::RawPubkey; use chain_core::tx::witness::{TxInWitness, TxWitness}; use chain_core::tx::TxAux; -use client_common::tendermint::types::BroadcastTxResult; +use client_common::tendermint::types::BroadcastTxResponse; use client_common::tendermint::{Client, UnauthorizedClient}; use client_common::{ Error, ErrorKind, PrivateKey, PublicKey, Result, ResultExt, SignedTransaction, Storage, @@ -448,7 +448,7 @@ where } #[inline] - fn broadcast_transaction(&self, tx_aux: &TxAux) -> Result { + fn broadcast_transaction(&self, tx_aux: &TxAux) -> Result { self.tendermint_client .broadcast_transaction(&tx_aux.encode()) } diff --git a/client-network/src/network_ops/default_network_ops_client.rs b/client-network/src/network_ops/default_network_ops_client.rs index 43f4d9c66..5b9c414b2 100644 --- a/client-network/src/network_ops/default_network_ops_client.rs +++ b/client-network/src/network_ops/default_network_ops_client.rs @@ -13,6 +13,7 @@ use chain_core::tx::data::input::TxoPointer; use chain_core::tx::data::output::TxOut; use chain_core::tx::fee::FeeAlgorithm; use chain_core::tx::{TransactionId, TxAux}; +use client_common::tendermint::types::AbciQueryExt; use client_common::tendermint::Client; use client_common::{Error, ErrorKind, Result, ResultExt, SignedTransaction}; use client_core::signer::{DummySigner, Signer}; @@ -478,11 +479,11 @@ mod tests { unreachable!() } - fn broadcast_transaction(&self, _: &[u8]) -> Result { + fn broadcast_transaction(&self, _: &[u8]) -> Result { unreachable!() } - fn query(&self, _path: &str, _data: &[u8]) -> Result { + fn query(&self, _path: &str, _data: &[u8]) -> Result { let staked_state = StakedState::new( 0, Coin::zero(), @@ -496,12 +497,9 @@ mod tests { }), ); - Ok(QueryResult { - response: Response { - code: 0, - value: base64::encode(&staked_state.encode()), - log: "".to_owned(), - }, + Ok(AbciQuery { + value: base64::encode(&staked_state.encode()), + ..Default::default() }) } } diff --git a/client-rpc/src/rpc/multisig_rpc.rs b/client-rpc/src/rpc/multisig_rpc.rs index fb60cc2f2..0d165571f 100644 --- a/client-rpc/src/rpc/multisig_rpc.rs +++ b/client-rpc/src/rpc/multisig_rpc.rs @@ -254,7 +254,7 @@ where self.client .broadcast_transaction(&tx_aux) - .map(|result| result.data) + .map(|result| result.data.to_string()) .map_err(to_rpc_error) } } @@ -459,11 +459,11 @@ mod test { unreachable!("block_results_batch") } - fn broadcast_transaction(&self, _transaction: &[u8]) -> CommonResult { + fn broadcast_transaction(&self, _transaction: &[u8]) -> CommonResult { unreachable!("broadcast_transaction") } - fn query(&self, _path: &str, _data: &[u8]) -> CommonResult { + fn query(&self, _path: &str, _data: &[u8]) -> CommonResult { unreachable!("query") } } diff --git a/client-rpc/src/rpc/wallet_rpc.rs b/client-rpc/src/rpc/wallet_rpc.rs index 523585f31..145ccf3e4 100644 --- a/client-rpc/src/rpc/wallet_rpc.rs +++ b/client-rpc/src/rpc/wallet_rpc.rs @@ -273,7 +273,6 @@ pub mod tests { use secstr::SecUtf8; - use chrono::DateTime; use parity_scale_codec::Encode; use chain_core::init::coin::CoinError; @@ -282,6 +281,7 @@ pub mod tests { use chain_core::tx::fee::{Fee, FeeAlgorithm}; use chain_core::tx::{PlainTxAux, TransactionId, TxAux, TxObfuscated}; use client_common::storage::MemoryStorage; + use client_common::tendermint::types::mock::*; use client_common::tendermint::types::*; use client_common::tendermint::Client; use client_common::{ @@ -377,27 +377,29 @@ pub mod tests { fn status(&self) -> CommonResult { Ok(Status { - sync_info: SyncInfo { - latest_block_height: "1".to_string(), - latest_app_hash: - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), + sync_info: status::SyncInfo { + latest_block_height: Height::default(), + latest_app_hash: Hash::from_str( + "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C", + ) + .unwrap(), + ..Default::default() }, + ..status_response() }) } fn block(&self, _height: u64) -> CommonResult { Ok(Block { - block: BlockInner { - header: Header { - app_hash: - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), - height: "1".to_string(), - time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - }, - data: Data { txs: None }, + header: Header { + app_hash: Hash::from_str( + "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C", + ) + .unwrap(), + time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + ..default_header() }, + ..default_block() }) } @@ -406,22 +408,21 @@ pub mod tests { _heights: T, ) -> CommonResult> { Ok(vec![Block { - block: BlockInner { - header: Header { - app_hash: - "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C" - .to_string(), - height: "1".to_string(), - time: DateTime::from_str("2019-04-09T09:38:41.735577Z").unwrap(), - }, - data: Data { txs: None }, + header: Header { + app_hash: Hash::from_str( + "3891040F29C6A56A5E36B17DCA6992D8F91D1EAAB4439D008D19A9D703271D3C", + ) + .unwrap(), + time: Time::from_str("2019-04-09T09:38:41.735577Z").unwrap(), + ..default_header() }, + ..default_block() }]) } fn block_results(&self, _height: u64) -> CommonResult { Ok(BlockResults { - height: "1".to_string(), + height: Height::default(), results: Results { deliver_tx: None, end_block: None, @@ -434,7 +435,7 @@ pub mod tests { _heights: T, ) -> CommonResult> { Ok(vec![BlockResults { - height: "1".to_string(), + height: Height::default(), results: Results { deliver_tx: None, end_block: None, @@ -442,11 +443,11 @@ pub mod tests { }]) } - fn broadcast_transaction(&self, _transaction: &[u8]) -> CommonResult { + fn broadcast_transaction(&self, _transaction: &[u8]) -> CommonResult { unreachable!("broadcast_transaction") } - fn query(&self, _path: &str, _data: &[u8]) -> CommonResult { + fn query(&self, _path: &str, _data: &[u8]) -> CommonResult { unreachable!("query") } } diff --git a/client-rpc/src/server.rs b/client-rpc/src/server.rs index 29a005409..36a1ea78e 100644 --- a/client-rpc/src/server.rs +++ b/client-rpc/src/server.rs @@ -9,6 +9,7 @@ use std::net::SocketAddr; use chain_core::init::network::{get_network, get_network_id, init_chain_id}; use chain_core::tx::fee::LinearFee; use client_common::storage::SledStorage; +use client_common::tendermint::types::GenesisExt; use client_common::tendermint::{Client, WebsocketRpcClient}; use client_common::{Error, Result}; use client_core::cipher::MockAbciTransactionObfuscation;