From d4f35c9e665fddeff8326a9a2de6d3b6d606c8b6 Mon Sep 17 00:00:00 2001 From: Louis Thiery Date: Tue, 29 Jun 2021 11:53:02 -1000 Subject: [PATCH] Multi-stake tested (#5) --- Cargo.lock | 341 +++++++++++++++++---------------- Cargo.toml | 10 +- src/error.rs | 2 + src/main.rs | 28 +-- src/txns/validator/stake.rs | 159 ++++++++++----- src/txns/validator/transfer.rs | 1 + src/txns/validator/unstake.rs | 1 + 7 files changed, 312 insertions(+), 230 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 835b8c7..cc9ec83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,9 +26,9 @@ dependencies = [ [[package]] name = "aes" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbda1ffd586ec58bdbc3290f9243c1d05bec1abf49ec15e4bc3d60070b7d9d11" +checksum = "495ee669413bfbe9e8cace80f4d3d78e6d8c8d99579f97fb93bde351b185f2d4" dependencies = [ "cfg-if 1.0.0", "cipher 0.3.0", @@ -38,9 +38,9 @@ dependencies = [ [[package]] name = "aes-gcm" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee2263805ba4537ccbb19db28525a7b1ebc7284c228eb5634c3124ca63eb03f" +checksum = "bc3be92e19a7ef47457b8e6f90707e12b6ac5d20c6f3866584fa3be0787d839f" dependencies = [ "aead 0.4.1", "aes", @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" +checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61" [[package]] name = "approx" @@ -198,18 +198,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "bitvec" -version = "0.20.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "blake2b_simd" version = "0.5.11" @@ -253,9 +241,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "byteorder" @@ -302,6 +290,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17cc5e6b5ab06331c33589842070416baa137e8b0eb912b008cfd4a78ada7919" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "serde", + "time", + "winapi", +] + [[package]] name = "cipher" version = "0.2.5" @@ -378,9 +380,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cpufeatures" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" dependencies = [ "libc", ] @@ -402,11 +404,10 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "autocfg", "cfg-if 1.0.0", "lazy_static", ] @@ -436,6 +437,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "crypto-bigint" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32a398eb1ccfbe7e4f452bc749c44d38dd732e9a253f19da224c416f00ee7f4" +dependencies = [ + "generic-array 0.14.4", + "rand_core 0.6.3", + "subtle", + "zeroize", +] + [[package]] name = "crypto-mac" version = "0.11.0" @@ -492,12 +505,9 @@ dependencies = [ [[package]] name = "der" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eeb9d92785d1facb50567852ce75d0858630630e7eabea59cf7eb7474051087" -dependencies = [ - "typenum", -] +checksum = "49f215f706081a44cb702c71c39a52c05da637822e9c1645a50b7202689e982d" [[package]] name = "dialoguer" @@ -533,9 +543,9 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.11.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d33b390ab82f2e1481e331dbd0530895640179d2128ef9a79cc690b78d1eba" +checksum = "05cb0ed2d2ce37766ac86c05f66973ace8c51f7f1533bedce8fb79e2b54b3f14" dependencies = [ "der", "elliptic-curve", @@ -573,14 +583,15 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "elliptic-curve" -version = "0.9.12" -source = "git+https://github.com/helium/traits.git?branch=rg/compact#e539e35961b3fd29bb072d1d28b553bb8b5b281e" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd035cb119cbc25e91bb6f1abbfe341388ddb47a1fe5e77ca6bcbe231e87580b" dependencies = [ - "bitvec", + "crypto-bigint", "ff", "generic-array 0.14.4", "group", - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", "zeroize", ] @@ -602,9 +613,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", "humantime", @@ -615,12 +626,11 @@ dependencies = [ [[package]] name = "ff" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72a4d941a5b7c2a75222e2d44fcdf634a67133d9db31e177ae5ff6ecda852bfe" +checksum = "63eec06c61e487eecf0f7e6e6372e596a81922c28d33e645d6983ca6493a1af0" dependencies = [ - "bitvec", - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", ] @@ -658,12 +668,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "funty" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" - [[package]] name = "futures" version = "0.3.15" @@ -843,9 +847,9 @@ dependencies = [ [[package]] name = "ghash" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6fb2a26dd2ebd268a68bc8e9acc9e67e487952f33384055a1cbe697514c64e" +checksum = "7bbd60caa311237d508927dbba7594b483db3ef05faa55172fcf89b1bcda7853" dependencies = [ "opaque-debug", "polyval", @@ -859,12 +863,12 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "group" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b3c1e8b4f1ca07e6605ea1be903a5f6956aec5c8a67fd44d56076631675ed8" +checksum = "1c363a5301b8f153d80747126a04b3c82073b9fe3130571a9d170cacdeaf7912" dependencies = [ "ff", - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", ] @@ -896,7 +900,7 @@ dependencies = [ "geo", "geo-types", "h3ron-h3-sys", - "itertools 0.10.0", + "itertools 0.10.1", "serde", "svgbobdoc", "thiserror", @@ -924,9 +928,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.9.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "heapless" @@ -942,21 +946,22 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] [[package]] name = "helium-api" -version = "2.0.6" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cde7697193dfee4c7d20612a18578f1e217c36004c6db762a3ffed7e39bd13d" +checksum = "54e90ae27bf5f3220976ecc200aff558cbb160561beb46cf1188d0a963a42496" dependencies = [ "async-trait", "base64 0.13.0", + "chrono", "futures", "reqwest", "rust_decimal", @@ -967,13 +972,13 @@ dependencies = [ [[package]] name = "helium-crypto" -version = "0.0.8" -source = "git+https://github.com/helium/helium-crypto-rs?tag=v0.0.8#353ad62d22f7e8eb6a6bb12a2e14a2d41ec1eb14" +version = "0.1.0" +source = "git+https://github.com/helium/helium-crypto-rs?tag=v0.1.0#22bb781a950e07500301cca1b130efb161ee5e70" dependencies = [ "bs58", "ed25519-dalek", "p256", - "rand_core 0.6.2", + "rand_core 0.6.3", "serde", "signature", "thiserror", @@ -996,6 +1001,8 @@ dependencies = [ "prost", "qr2term", "rust_decimal", + "serde", + "serde_json", "structopt", "thiserror", "tokio", @@ -1004,7 +1011,7 @@ dependencies = [ [[package]] name = "helium-proto" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#0c5f7926a446c737ffb16183e922b0cff32361c6" +source = "git+https://github.com/helium/proto?branch=master#69a6452a682bf2e1e2f20cdde15368459c50166a" dependencies = [ "bytes", "prost", @@ -1016,8 +1023,8 @@ dependencies = [ [[package]] name = "helium-wallet" -version = "1.5.5-dev" -source = "git+https://github.com/helium/helium-wallet-rs#bc1a9e13453186ce2bb231bec23cabf1d524ce41" +version = "1.6.4-dev" +source = "git+https://github.com/helium/helium-wallet-rs#2e92b87312ad2d4d3908cd30a6a816eaf56a8ecd" dependencies = [ "aes-gcm", "angry-purple-tiger", @@ -1052,9 +1059,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -1128,9 +1135,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.8" +version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3f71a7eea53a3f8257a7b4795373ff886397178cd634430ea94e12d7fe4fe34" +checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" dependencies = [ "bytes", "futures-channel", @@ -1142,7 +1149,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project", + "pin-project-lite", "socket2", "tokio", "tower-service", @@ -1178,9 +1185,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg", "hashbrown", @@ -1197,9 +1204,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" [[package]] name = "itertools" @@ -1212,9 +1219,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" dependencies = [ "either", ] @@ -1303,9 +1310,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libloading" @@ -1319,13 +1326,14 @@ dependencies = [ [[package]] name = "libsodium-sys" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a685b64f837b339074115f2e7f7b431ac73681d08d75b389db7498b8892b8a58" +checksum = "6b779387cd56adfbc02ea4a668e704f729be8d6a6abd2c27ca5ee537849a92fd" dependencies = [ "cc", "libc", "pkg-config", + "walkdir", ] [[package]] @@ -1382,9 +1390,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.11" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", "log", @@ -1440,6 +1448,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -1461,9 +1479,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "opaque-debug" @@ -1473,8 +1491,8 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "p256" -version = "0.8.1" -source = "git+https://github.com/helium/elliptic-curves?branch=rg/compact#1c360bddb599db9af19ded0be493a79e7748bc1e" +version = "0.9.0" +source = "git+https://github.com/helium/elliptic-curves?branch=madninja/compact_point_impl#c7fe19baf31e6d26aa6d56f89f5f00899bb996c7" dependencies = [ "ecdsa", "elliptic-curve", @@ -1501,7 +1519,7 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall 0.2.8", + "redox_syscall 0.2.9", "smallvec", "winapi", ] @@ -1543,31 +1561,11 @@ dependencies = [ "indexmap", ] -[[package]] -name = "pin-project" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -1593,10 +1591,11 @@ dependencies = [ [[package]] name = "polyval" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864231b0b86ce05168a8e6da0fea2e67275dacf25f75b00a62cfd341aab904a9" +checksum = "e597450cbf209787f0e6de80bf3795c6b2356a380ee87837b545aded8dbc1823" dependencies = [ + "cfg-if 1.0.0", "cpufeatures", "opaque-debug", "universal-hash", @@ -1752,32 +1751,26 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" - [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.2", + "rand_core 0.6.3", "rand_hc", ] [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -1791,20 +1784,20 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom 0.2.3", ] [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -1815,9 +1808,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] @@ -1846,12 +1839,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -dependencies = [ - "byteorder", -] +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" @@ -1870,9 +1860,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" +checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" dependencies = [ "async-compression", "base64 0.13.0", @@ -1953,9 +1943,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.14.1" +version = "1.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52f6513cf330c84095570b1f3ac073d718a50541c8392a98eaac9c6333324bf" +checksum = "01127cb8617e5e21bcf2e19b5eb48317735ca677f1d0a94833c21c331c446582" dependencies = [ "arrayvec", "num-traits", @@ -1997,6 +1987,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -2099,21 +2098,21 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" dependencies = [ "libc", ] [[package]] name = "signature" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0242b8e50dd9accdd56170e94ca1ebd223b098eb9c83539a6e367d0f36ae68" +checksum = "c19772be3c4dd2ceaacf03cb41d5885f2a02c4d8804884918e3a258480803335" dependencies = [ "digest", - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -2140,10 +2139,11 @@ dependencies = [ [[package]] name = "sodiumoxide" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7038b67c941e23501573cb7242ffb08709abe9b11eb74bceff875bbda024a6a8" +checksum = "e26be3acb6c2d9a7aac28482586a7856436af4cfe7100031d219de2d2ecb0028" dependencies = [ + "ed25519", "libc", "libsodium-sys", "serde", @@ -2233,9 +2233,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -2254,12 +2254,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tempfile" version = "3.2.0" @@ -2269,7 +2263,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "rand", - "redox_syscall 0.2.8", + "redox_syscall 0.2.9", "remove_dir_all", "winapi", ] @@ -2333,6 +2327,16 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "tinyvec" version = "1.2.0" @@ -2350,9 +2354,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" +checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2" dependencies = [ "autocfg", "bytes", @@ -2464,9 +2468,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ "tinyvec", ] @@ -2535,6 +2539,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + [[package]] name = "want" version = "0.3.0" @@ -2713,12 +2728,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wyz" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" - [[package]] name = "xsalsa20poly1305" version = "0.6.0" diff --git a/Cargo.toml b/Cargo.toml index 00be31a..f85a723 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ anyhow = "1.0" thiserror = "1" byteorder = "1" structopt = "0" -helium-api = "2.0.4" +helium-api = "3" helium-wallet = { git = "https://github.com/helium/helium-wallet-rs" } -helium-crypto = {git = "https://github.com/helium/helium-crypto-rs", tag="v0.0.8"} +helium-crypto = {git = "https://github.com/helium/helium-crypto-rs", tag="v0.1.0"} helium-proto = { git = "https://github.com/helium/proto", branch="master"} prettytable-rs = "0" bs58 = {version = "0", features=["check"]} @@ -20,12 +20,12 @@ base64 = "0" rust_decimal = "1" prost = "0" qr2term = "0" +serde = { version = "1", features = ["derive"] } +serde_json = "1" tokio = {version = "1.2", features = ["full"]} + [dependencies.ledger-transport] git = "https://github.com/helium/ledger-rs" branch = "lthiery/tcp-transport" default-features = false features = ["transport-hid", "transport-tcp"] - -[patch.crates-io] -elliptic-curve = { git = "https://github.com/helium/traits.git", branch = "rg/compact" } diff --git a/src/error.rs b/src/error.rs index 30e7adf..d93a37d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -32,6 +32,8 @@ pub enum Error { IntoEnvelope, #[error("FromB64 Error")] FromB64, + #[error("From Json Parsing Error")] + SerdeJson(#[from] serde_json::Error), } impl Error { diff --git a/src/main.rs b/src/main.rs index 1baa07e..1513b4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate prettytable; -use helium_api::{pending_transactions::PendingTxnStatus, Hnt}; +use helium_api::{models::PendingTxnStatus, Hnt}; use helium_crypto::Network; use helium_proto::BlockchainTxn; use ledger_transport::exchange::Exchange as LedgerTransport; @@ -56,7 +56,7 @@ enum Cmd { /// Pay a given address. Pay(txns::pay::Cmd), /// Stake a validator - Validator(txns::validator::Cmd), + Validators(txns::validator::Cmd), } #[tokio::main] @@ -99,23 +99,27 @@ async fn run(cli: Cli) -> Result { let result = match cli.cmd { Cmd::Balance(balance) => balance.run(cli.opts, version).await?, Cmd::Pay(pay) => pay.run(cli.opts, version).await?, - Cmd::Validator(validator) => validator.run(cli.opts, version).await?, + Cmd::Validators(validator) => validator.run(cli.opts, version).await?, }; if let Some((hash, network)) = result { - println!("\nSuccessfully submitted transaction to API:"); - - let mut table = Table::new(); - table.add_row(row!["Network", "Hash"]); - table.add_row(row![network, hash]); - table.printstd(); - - println!("To check on transaction status, monitor the following URL:"); - println!(" {}/pending_transactions/{}", api_url(network), hash); + print_txn(hash, network); } Ok(()) } +fn print_txn(hash: String, network: Network) { + println!("\nSuccessfully submitted transaction to API:"); + + let mut table = Table::new(); + table.add_row(row!["Network", "Hash"]); + table.add_row(row![network, hash]); + table.printstd(); + + println!("To check on transaction status, monitor the following URL:"); + println!(" {}/pending_transactions/{}", api_url(network), hash); +} + use helium_api::Client; use prettytable::{format, Table}; diff --git a/src/txns/validator/stake.rs b/src/txns/validator/stake.rs index 1ad55e2..2613f22 100644 --- a/src/txns/validator/stake.rs +++ b/src/txns/validator/stake.rs @@ -1,11 +1,46 @@ use crate::txns::*; +use rust_decimal::Decimal; +use serde::Deserialize; +use std::path::PathBuf; #[derive(Debug, StructOpt)] -pub struct Cmd { - /// Amount to stake - pub amount: Hnt, - /// Address of the validator to stake - pub address: PublicKey, +/// Onboard one (or more) validators with this wallet. +/// +/// The payment is not submitted to the system unless the '--commit' option is +/// given. +/// +/// Note that multiple staking transactions are submitted individually and not as a +/// single transaction. Any failures will abort the remaining staking entries. +pub enum Cmd { + /// Stake a single validator + One(Validator), + /// Stake multiple validators via file import + Multi(Multi), +} + +#[derive(Debug, StructOpt)] +/// The input file for multiple validator stakes is expected to be json file +/// with a list of address and staking amounts. For example: +/// +/// [ +/// { +/// "address": "", +/// "stake": 10000 +/// }, +/// { +/// "address": "", +/// "stake": 10000 +/// } +/// ] +pub struct Multi { + /// File to read multiple stakes from + path: PathBuf, +} + +pub enum Response { + Success, + InsufficientBalance(Hnt, Hnt), // provides balance and send request + UserDeniedTransaction, } impl Cmd { @@ -14,8 +49,8 @@ impl Cmd { opts: Opts, _version: Version, ) -> Result> { - match ledger(opts, self).await? { - Response::Txn(_txn, hash, network) => Ok(Some((hash, network))), + match self.ledger(opts).await? { + Response::Success => Ok(None), Response::InsufficientBalance(balance, send_request) => { println!( "Account balance insufficient. {} HNT on account but attempting to stake {}", @@ -29,54 +64,76 @@ impl Cmd { } } } -} -pub(crate) async fn ledger( - opts: Opts, - stake: Cmd, -) -> Result> { - let ledger_transport = get_ledger_transport(&opts).await?; + fn collect_validators(&self) -> Result> { + match &self { + Self::One(validator) => Ok(vec![validator.clone()]), + Self::Multi(multi) => { + let file = std::fs::File::open(multi.path.clone())?; + let validators: Vec = serde_json::from_reader(file)?; + Ok(validators) + } + } + } - // get account from API so we can get nonce and balance - let owner = get_pubkey(opts.account, &ledger_transport, PubkeyDisplay::Off).await?; + pub(crate) async fn ledger(self, opts: Opts) -> Result { + let validators = self.collect_validators()?; - let client = Client::new_with_base_url(api_url(owner.network)); + let ledger_transport = get_ledger_transport(&opts).await?; - let account = accounts::get(&client, &owner.to_string()).await?; + // get account from API so we can get nonce and balance + let owner = get_pubkey(opts.account, &ledger_transport, PubkeyDisplay::Off).await?; - if account.balance.get_decimal() < stake.amount.get_decimal() { - return Ok(Response::InsufficientBalance(account.balance, stake.amount)); - } + let client = Client::new_with_base_url(api_url(owner.network)); - let mut txn = BlockchainTxnStakeValidatorV1 { - owner: owner.to_vec(), - address: stake.address.to_vec(), - stake: u64::from(stake.amount), - fee: 0, - owner_signature: vec![], - }; - txn.fee = txn - .txn_fee( - &get_txn_fees(&client) - .await - .map_err(|_| Error::getting_fees())?, - ) - .map_err(|_| Error::getting_fees())?; - print_proposed_transaction(&txn)?; - - let cmd = txn.apdu_serialize(opts.account)?; - let exchange_pay_tx_result = read_from_ledger(&ledger_transport, cmd).await?; - - if exchange_pay_tx_result.data.len() == 1 { - return Ok(Response::UserDeniedTransaction); - } + let account = accounts::get(&client, &owner.to_string()).await?; - let txn = BlockchainTxnStakeValidatorV1::decode(exchange_pay_tx_result.data.as_slice())?; - let envelope = txn.in_envelope(); - // submit the signed tansaction to the API - let pending_txn_status = submit_txn(&client, &envelope).await?; + let total_stake_amount = validators + .iter() + .map(|v| v.stake.get_decimal()) + .sum::(); - Ok(Response::Txn(txn, pending_txn_status.hash, owner.network)) + if account.balance.get_decimal() < total_stake_amount { + return Ok(Response::InsufficientBalance( + account.balance, + Hnt::new(total_stake_amount), + )); + } + + for validator in validators { + let mut txn = BlockchainTxnStakeValidatorV1 { + owner: owner.to_vec(), + address: validator.address.to_vec(), + stake: u64::from(validator.stake), + fee: 0, + owner_signature: vec![], + }; + txn.fee = txn + .txn_fee( + &get_txn_fees(&client) + .await + .map_err(|_| Error::getting_fees())?, + ) + .map_err(|_| Error::getting_fees())?; + print_proposed_transaction(&txn)?; + + let cmd = txn.apdu_serialize(opts.account)?; + let exchange_pay_tx_result = read_from_ledger(&ledger_transport, cmd).await?; + + if exchange_pay_tx_result.data.len() == 1 { + return Ok(Response::UserDeniedTransaction); + } + + let txn = + BlockchainTxnStakeValidatorV1::decode(exchange_pay_tx_result.data.as_slice())?; + let envelope = txn.in_envelope(); + // submit the signed tansaction to the API + let pending_txn_status = submit_txn(&client, &envelope).await?; + + print_txn(pending_txn_status.hash, owner.network) + } + Ok(Response::Success) + } } fn print_proposed_transaction(stake: &BlockchainTxnStakeValidatorV1) -> Result { @@ -101,3 +158,11 @@ fn print_proposed_transaction(stake: &BlockchainTxnStakeValidatorV1) -> Result { ); Ok(()) } + +#[derive(Debug, Deserialize, StructOpt, Clone)] +pub struct Validator { + /// The validator address to stake + address: PublicKey, + /// The amount of HNT to stake + stake: Hnt, +} diff --git a/src/txns/validator/transfer.rs b/src/txns/validator/transfer.rs index 8d2d36a..e8af902 100644 --- a/src/txns/validator/transfer.rs +++ b/src/txns/validator/transfer.rs @@ -138,6 +138,7 @@ pub(crate) async fn ledger_create( helium_api::validators::get(&client, &txfer_stake.old_address.to_string()) .await? .stake + .into() }, new_owner_signature: vec![], old_owner_signature: vec![], diff --git a/src/txns/validator/unstake.rs b/src/txns/validator/unstake.rs index d6219c2..f121381 100644 --- a/src/txns/validator/unstake.rs +++ b/src/txns/validator/unstake.rs @@ -64,6 +64,7 @@ pub(crate) async fn ledger( helium_api::validators::get(&client, &unstake.address.to_string()) .await? .stake + .into() }, stake_release_height: unstake.stake_release_height, fee: 0,