From 415088fcbbb427410c2989dee81046635686efd3 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Fri, 16 Aug 2019 18:03:15 +0200 Subject: [PATCH] [ref] whole: split crate documents: create new crate dubp-common-doc --- Cargo.lock | 237 ++++++++++----- Cargo.toml | 1 + lib/core/message/Cargo.toml | 3 +- lib/core/message/src/events.rs | 2 +- lib/core/message/src/requests.rs | 2 +- lib/core/message/src/responses.rs | 4 +- lib/core/network/Cargo.toml | 5 +- lib/core/network/events.rs | 2 +- lib/core/network/requests.rs | 2 +- lib/dubp/common-doc/Cargo.toml | 32 +++ lib/dubp/common-doc/README.md | 9 + .../src/blockstamp.rs | 38 ++- .../src/currencies_codes.rs | 0 .../src/documents_grammar.pest | 0 lib/dubp/common-doc/src/errors.rs | 30 ++ lib/dubp/common-doc/src/lib.rs | 88 ++++++ lib/dubp/common-doc/src/parser.rs | 93 ++++++ lib/dubp/common-doc/src/traits.rs | 164 +++++++++++ .../src/traits/text.rs} | 5 +- lib/dubp/currency-params/Cargo.toml | 1 + lib/dubp/currency-params/src/lib.rs | 20 +- lib/dubp/documents/Cargo.toml | 5 +- lib/dubp/documents/src/documents/block.rs | 9 +- lib/dubp/documents/src/documents/block/v10.rs | 23 +- .../documents/src/documents/certification.rs | 13 +- .../src/documents/certification/v10.rs | 11 +- lib/dubp/documents/src/documents/identity.rs | 8 +- .../documents/src/documents/identity/v10.rs | 11 +- .../documents/src/documents/membership.rs | 10 +- .../documents/src/documents/membership/v10.rs | 11 +- lib/dubp/documents/src/documents/mod.rs | 10 +- .../documents/src/documents/revocation.rs | 13 +- .../documents/src/documents/revocation/v10.rs | 8 +- .../documents/src/documents/transaction.rs | 13 +- lib/dubp/documents/src/lib.rs | 269 +----------------- lib/dubp/documents/src/parsers/blocks.rs | 1 + .../documents/src/parsers/certifications.rs | 4 +- lib/dubp/documents/src/parsers/identities.rs | 4 +- lib/dubp/documents/src/parsers/memberships.rs | 4 +- lib/dubp/documents/src/parsers/mod.rs | 5 +- lib/dubp/documents/src/parsers/revoked.rs | 2 +- .../documents/src/parsers/transactions.rs | 4 +- lib/dunp/network-documents/Cargo.toml | 5 +- lib/dunp/network-documents/src/lib.rs | 2 +- .../network-documents/src/network_head.rs | 2 +- .../network-documents/src/network_head_v2.rs | 2 +- .../network-documents/src/network_head_v3.rs | 5 +- .../network-documents/src/network_peer.rs | 6 +- .../blockchain/blockchain-dal/Cargo.toml | 1 + .../blockchain-dal/src/entities/block.rs | 4 +- .../blockchain-dal/src/entities/fork_tree.rs | 2 +- .../blockchain-dal/src/entities/identity.rs | 2 +- .../blockchain-dal/src/entities/sources.rs | 2 +- .../blockchain-dal/src/filters/mod.rs | 2 +- .../blockchain/blockchain-dal/src/lib.rs | 2 +- .../blockchain-dal/src/readers/block.rs | 4 +- .../blockchain-dal/src/readers/certs.rs | 2 +- .../src/readers/currency_params.rs | 2 +- .../blockchain-dal/src/readers/fork_tree.rs | 2 +- .../blockchain-dal/src/readers/identity.rs | 5 +- .../blockchain-dal/src/writers/block.rs | 2 +- .../src/writers/certification.rs | 2 +- .../blockchain-dal/src/writers/dividend.rs | 2 +- .../blockchain-dal/src/writers/fork_tree.rs | 2 +- .../blockchain-dal/src/writers/identity.rs | 4 +- .../blockchain-dal/src/writers/requests.rs | 2 +- .../blockchain-dal/src/writers/transaction.rs | 2 +- lib/modules/blockchain/blockchain/Cargo.toml | 3 +- lib/modules/blockchain/blockchain/src/dbex.rs | 3 +- .../blockchain/src/dubp/apply/mod.rs | 3 +- .../blockchain/src/dubp/check/mod.rs | 3 +- .../blockchain/blockchain/src/dubp/mod.rs | 4 +- .../blockchain/blockchain/src/dunp/queries.rs | 1 + .../blockchain/src/dunp/receiver.rs | 1 + .../blockchain/src/fork/fork_algo.rs | 4 +- .../blockchain/src/fork/revert_block.rs | 3 +- .../blockchain/src/fork/rollback.rs | 3 +- .../blockchain/src/fork/stackable_blocks.rs | 1 + lib/modules/blockchain/blockchain/src/lib.rs | 3 +- .../blockchain/src/requests/sent.rs | 1 + .../blockchain/src/sync/apply/mod.rs | 5 +- .../src/sync/download/json_reader_worker.rs | 3 +- .../blockchain/blockchain/src/sync/mod.rs | 3 +- lib/modules/ws2p-v1-legacy/Cargo.toml | 5 +- .../ws2p-v1-legacy/src/events/received.rs | 2 +- lib/modules/ws2p-v1-legacy/src/heads.rs | 2 +- lib/modules/ws2p-v1-legacy/src/lib.rs | 4 +- .../ws2p-v1-legacy/src/requests/received.rs | 2 +- .../src/ws_connections/requests/mod.rs | 2 +- .../src/ws_connections/responses/mod.rs | 2 +- lib/modules/ws2p/ws2p-messages/Cargo.toml | 3 +- lib/modules/ws2p/ws2p-messages/lib.rs | 2 +- lib/modules/ws2p/ws2p-messages/v2/connect.rs | 4 +- lib/modules/ws2p/ws2p-messages/v2/ok.rs | 4 +- .../ws2p/ws2p-messages/v2/req_responses.rs | 4 +- lib/modules/ws2p/ws2p-messages/v2/requests.rs | 5 +- lib/modules/ws2p/ws2p-protocol/Cargo.toml | 5 +- .../src/controller/meta_datas.rs | 2 +- lib/modules/ws2p/ws2p/Cargo.toml | 5 +- lib/modules/ws2p/ws2p/src/controllers/mod.rs | 2 +- lib/modules/ws2p/ws2p/src/generate_peer.rs | 2 +- .../ws2p/ws2p/tests/connection_negociation.rs | 4 +- .../documents-tests-tools/Cargo.toml | 3 +- .../src/mocks/identity.rs | 4 +- .../documents-tests-tools/src/mocks/mod.rs | 3 +- 105 files changed, 823 insertions(+), 536 deletions(-) create mode 100644 lib/dubp/common-doc/Cargo.toml create mode 100644 lib/dubp/common-doc/README.md rename lib/dubp/{documents => common-doc}/src/blockstamp.rs (82%) rename lib/dubp/{currency-params => common-doc}/src/currencies_codes.rs (100%) rename lib/dubp/{documents => common-doc}/src/documents_grammar.pest (100%) create mode 100644 lib/dubp/common-doc/src/errors.rs create mode 100644 lib/dubp/common-doc/src/lib.rs create mode 100644 lib/dubp/common-doc/src/parser.rs create mode 100644 lib/dubp/common-doc/src/traits.rs rename lib/dubp/{documents/src/text_document_traits.rs => common-doc/src/traits/text.rs} (97%) diff --git a/Cargo.lock b/Cargo.lock index 5fcdc43a..13417b4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -289,15 +289,46 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dubp-common-doc" +version = "0.1.0" +dependencies = [ + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "json-pest-parser 0.2.0", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", + "shrinkwraprs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unwrap 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dubp-currency-params" +version = "0.2.0" +dependencies = [ + "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dubp-common-doc 0.1.0", + "durs-common-tools 0.2.0", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dubp-documents" -version = "0.13.0" +version = "0.14.0" dependencies = [ - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "json-pest-parser 0.1.0", + "json-pest-parser 0.2.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -312,10 +343,11 @@ dependencies = [ name = "dubp-documents-tests-tools" version = "0.1.0" dependencies = [ - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", "dup-crypto-tests-tools 0.1.0", - "dup-currency-params 0.1.0", ] [[package]] @@ -335,12 +367,12 @@ dependencies = [ [[package]] name = "dup-crypto" -version = "0.6.0" +version = "0.7.0" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "durs-common-tools 0.1.0", + "durs-common-tools 0.2.0", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -354,17 +386,7 @@ dependencies = [ name = "dup-crypto-tests-tools" version = "0.1.0" dependencies = [ - "dup-crypto 0.6.0", -] - -[[package]] -name = "dup-currency-params" -version = "0.1.0" -dependencies = [ - "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "durs-common-tools 0.1.0", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", + "dup-crypto 0.7.0", ] [[package]] @@ -372,13 +394,14 @@ name = "durs-blockchain" version = "0.2.0-a" dependencies = [ "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "dubp-documents 0.13.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", "dubp-documents-tests-tools 0.1.0", - "dup-crypto 0.6.0", + "dup-crypto 0.7.0", "dup-crypto-tests-tools 0.1.0", - "dup-currency-params 0.1.0", "durs-blockchain-dal 0.2.0-a", - "durs-common-tools 0.1.0", + "durs-common-tools 0.2.0", "durs-conf 0.2.0-a", "durs-message 0.2.0-a", "durs-module 0.2.0-a", @@ -386,7 +409,7 @@ dependencies = [ "durs-network-documents 0.4.0", "durs-wot 0.8.0-a0.9", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "json-pest-parser 0.1.0", + "json-pest-parser 0.2.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -401,13 +424,14 @@ dependencies = [ name = "durs-blockchain-dal" version = "0.2.0-a" dependencies = [ - "dubp-documents 0.13.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", "dubp-documents-tests-tools 0.1.0", - "dup-crypto 0.6.0", + "dup-crypto 0.7.0", "dup-crypto-tests-tools 0.1.0", - "dup-currency-params 0.1.0", "durs-common-tests-tools 0.1.0", - "durs-common-tools 0.1.0", + "durs-common-tools 0.2.0", "durs-conf 0.2.0-a", "durs-module 0.2.0-a", "durs-wot 0.8.0-a0.9", @@ -431,7 +455,7 @@ dependencies = [ [[package]] name = "durs-common-tools" -version = "0.1.0" +version = "0.2.0" dependencies = [ "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -441,10 +465,10 @@ name = "durs-conf" version = "0.2.0-a" dependencies = [ "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-module 0.2.0-a", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -460,10 +484,10 @@ name = "durs-core" version = "0.2.0-a" dependencies = [ "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", + "dubp-currency-params 0.2.0", + "dup-crypto 0.7.0", "durs-blockchain 0.2.0-a", - "durs-common-tools 0.1.0", + "durs-common-tools 0.2.0", "durs-conf 0.2.0-a", "durs-message 0.2.0-a", "durs-module 0.2.0-a", @@ -484,9 +508,10 @@ dependencies = [ name = "durs-message" version = "0.2.0-a" dependencies = [ - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", "durs-blockchain-dal 0.2.0-a", "durs-module 0.2.0-a", "durs-network 0.2.0-a", @@ -500,10 +525,10 @@ dependencies = [ name = "durs-module" version = "0.2.0-a" dependencies = [ - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-network-documents 0.4.0", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -517,9 +542,10 @@ dependencies = [ name = "durs-network" version = "0.2.0-a" dependencies = [ - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "durs-common-tools 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-module 0.2.0-a", "durs-network-documents 0.4.0", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -535,10 +561,11 @@ version = "0.4.0" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -556,10 +583,10 @@ dependencies = [ name = "durs-skeleton" version = "0.1.0" dependencies = [ - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-conf 0.2.0-a", "durs-message 0.2.0-a", "durs-module 0.2.0-a", @@ -576,10 +603,10 @@ dependencies = [ name = "durs-tui" version = "0.2.0-a" dependencies = [ - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-conf 0.2.0-a", "durs-message 0.2.0-a", "durs-module 0.2.0-a", @@ -600,7 +627,7 @@ version = "0.8.0-a0.9" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "durs-common-tools 0.1.0", + "durs-common-tools 0.2.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)", @@ -612,11 +639,12 @@ name = "durs-ws2p" version = "0.2.0-a" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", "durs-common-tests-tools 0.1.0", - "durs-common-tools 0.1.0", + "durs-common-tools 0.2.0", "durs-conf 0.2.0-a", "durs-message 0.2.0-a", "durs-module 0.2.0-a", @@ -640,10 +668,11 @@ version = "0.2.0-a" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-network-documents 0.4.0", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -657,10 +686,11 @@ dependencies = [ name = "durs-ws2p-protocol" version = "0.2.0-a" dependencies = [ - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-module 0.2.0-a", "durs-network-documents 0.4.0", "durs-ws2p-messages 0.2.0-a", @@ -678,10 +708,11 @@ version = "0.2.0-a" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "dubp-documents 0.13.0", - "dup-crypto 0.6.0", - "dup-currency-params 0.1.0", - "durs-common-tools 0.1.0", + "dubp-common-doc 0.1.0", + "dubp-currency-params 0.2.0", + "dubp-documents 0.14.0", + "dup-crypto 0.7.0", + "durs-common-tools 0.2.0", "durs-conf 0.2.0-a", "durs-message 0.2.0-a", "durs-module 0.2.0-a", @@ -854,6 +885,14 @@ dependencies = [ "winapi 0.2.8 (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.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itoa" version = "0.4.3" @@ -861,7 +900,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "json-pest-parser" -version = "0.1.0" +version = "0.2.0" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1120,6 +1159,14 @@ dependencies = [ "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "proc-macro2" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.27" @@ -1128,6 +1175,14 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "0.6.11" @@ -1484,6 +1539,17 @@ dependencies = [ "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "shrinkwraprs" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.12.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "simplelog" version = "0.5.3" @@ -1537,6 +1603,16 @@ dependencies = [ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.4.2 (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.26" @@ -1868,6 +1944,7 @@ dependencies = [ "checksum id_tree 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c265a4e397174ac4e22b5e923ad2905858aa5f1512e3b5b4942ee4ff56d146f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" +"checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d" "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" @@ -1900,7 +1977,9 @@ dependencies = [ "checksum pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5a3492a4ed208ffc247adcdcc7ba2a95be3104f58877d0d02f0df39bf3efb5e" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6" +"checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" +"checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" @@ -1940,6 +2019,7 @@ dependencies = [ "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum sha2-asm 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8aba8afb8bba3f5d433ede1d036c46e122a7b75a67c92a6b7b5f11d87e2e4478" +"checksum shrinkwraprs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7d5f047b90b2ca2d1526ff73d67cba61f86f4cf9a8afddc99dd96702ded8e684" "checksum simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e95345f185d5adeb8ec93459d2dc99654e294cc6ccf5b75414d8ea262de9a13" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "88aea073965ab29f6edb5493faf96ad662fb18aa9eeb186a3b7057951605ed15" @@ -1947,6 +2027,7 @@ dependencies = [ "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum structopt 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "670ad348dc73012fcf78c71f06f9d942232cdd4c859d4b6975e27836c3efc0c3" "checksum structopt-derive 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ef98172b1a00b0bec738508d3726540edcbd186d50dfd326f2b1febbb3559f04" +"checksum syn 0.12.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c97c05b8ebc34ddd6b967994d5c6e9852fa92f8b82b3858c39451f97346dcce5" "checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" diff --git a/Cargo.toml b/Cargo.toml index ddfa3422..47f6588f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "lib/core/module", "lib/core/network", "lib/crypto", + "lib/dubp/common-doc", "lib/dubp/currency-params", "lib/dubp/documents", "lib/dubp/wot", diff --git a/lib/core/message/Cargo.toml b/lib/core/message/Cargo.toml index 6494bc93..b97bf7af 100644 --- a/lib/core/message/Cargo.toml +++ b/lib/core/message/Cargo.toml @@ -10,9 +10,10 @@ edition = "2018" path = "src/lib.rs" [dependencies] -dup-crypto = { path = "../../crypto" } +dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" } dubp-currency-params = { path = "../../dubp/currency-params" } dubp-documents= { path = "../../dubp/documents" } +dup-crypto = { path = "../../crypto" } durs-module = { path = "../module" } durs-network = { path = "../network" } durs-blockchain-dal = { path = "../../modules/blockchain/blockchain-dal" } diff --git a/lib/core/message/src/events.rs b/lib/core/message/src/events.rs index f3b9df2e..c89ac18f 100644 --- a/lib/core/message/src/events.rs +++ b/lib/core/message/src/events.rs @@ -14,9 +14,9 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; +use dubp_common_doc::Blockstamp; use dubp_documents::documents::block::BlockDocument; use dubp_documents::documents::UserDocumentDUBP; -use dubp_documents::Blockstamp; use durs_network::events::NetworkEvent; /// The DURS event message. diff --git a/lib/core/message/src/requests.rs b/lib/core/message/src/requests.rs index e6a49ed1..96411b6a 100644 --- a/lib/core/message/src/requests.rs +++ b/lib/core/message/src/requests.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; -use dubp_documents::BlockNumber; +use dubp_common_doc::BlockNumber; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_blockchain_dal::filters::identities::IdentitiesFilter; diff --git a/lib/core/message/src/responses.rs b/lib/core/message/src/responses.rs index eb5db0ca..e04778d6 100644 --- a/lib/core/message/src/responses.rs +++ b/lib/core/message/src/responses.rs @@ -13,13 +13,13 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use dubp_common_doc::BlockNumber; +use dubp_common_doc::Blockstamp; use dubp_documents::documents::block::BlockDocument; use dubp_documents::documents::certification::CertificationDocument; use dubp_documents::documents::identity::IdentityDocument; use dubp_documents::documents::membership::MembershipDocument; use dubp_documents::documents::revocation::RevocationDocumentV10; -use dubp_documents::BlockNumber; -use dubp_documents::Blockstamp; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_module::ModuleReqId; diff --git a/lib/core/network/Cargo.toml b/lib/core/network/Cargo.toml index f0bd0b77..448287c6 100644 --- a/lib/core/network/Cargo.toml +++ b/lib/core/network/Cargo.toml @@ -10,9 +10,10 @@ edition = "2018" path = "lib.rs" [dependencies] -durs-common-tools = { path = "../../tools/common-tools" } -dup-crypto = { path = "../../crypto" } +dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" } dubp-documents= { path = "../../dubp/documents" } +dup-crypto = { path = "../../crypto" } +durs-common-tools = { path = "../../tools/common-tools" } durs-module = { path = "../module" } durs-network-documents = { path = "../../dunp/network-documents" } failure = "0.1.5" diff --git a/lib/core/network/events.rs b/lib/core/network/events.rs index f917cf39..954ed019 100644 --- a/lib/core/network/events.rs +++ b/lib/core/network/events.rs @@ -18,9 +18,9 @@ use crate::network_head::NetworkHead; use crate::network_peer::PeerCard; use crate::NodeFullId; +use dubp_common_doc::blockstamp::Blockstamp; use dubp_documents::documents::block::BlockDocument; use dubp_documents::documents::UserDocumentDUBP; -use dubp_documents::Blockstamp; use durs_common_tools::Percent; #[derive(Debug, Clone)] diff --git a/lib/core/network/requests.rs b/lib/core/network/requests.rs index f9b00059..0dad6800 100644 --- a/lib/core/network/requests.rs +++ b/lib/core/network/requests.rs @@ -16,9 +16,9 @@ //! Defined network requests. use crate::*; +use dubp_common_doc::blockstamp::Blockstamp; use dubp_documents::documents::block::BlockDocument; use dubp_documents::documents::UserDocumentDUBP; -use dubp_documents::Blockstamp; #[derive(Debug, Copy, Clone)] /// Type containing a request addressed to the network module diff --git a/lib/dubp/common-doc/Cargo.toml b/lib/dubp/common-doc/Cargo.toml new file mode 100644 index 00000000..77106f7d --- /dev/null +++ b/lib/dubp/common-doc/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "dubp-common-doc" +version = "0.1.0" +authors = ["elois <elois@ifee.fr>"] +description = "Provide common tools for DUBP (DUniter Blockhain Protocol)." +repository = "https://git.duniter.org/nodes/rust/duniter-rs" +readme = "README.md" +keywords = ["duniter", "dunitrust", "blockchain", "cryptocurrency"] +license = "AGPL-3.0" +edition = "2018" + +[lib] +path = "src/lib.rs" + +[dependencies] +dup-crypto = { path = "../../crypto", version = "0.7.0" } +durs-common-tools = { path = "../../tools/common-tools", version = "0.2.0" } +failure = "0.1.5" +json-pest-parser = { path = "../../tools/json-pest-parser", version = "0.2.0" } +pest = "2.1.0" +pest_derive = "2.1.0" +serde = "1.0.*" +serde_derive = "1.0.*" +serde_json = "1.0.*" +shrinkwraprs = "0.2.*" +log = "0.4.*" +unwrap = "1.2.1" + +[dev-dependencies] +pretty_assertions = "0.5.1" + +[features] \ No newline at end of file diff --git a/lib/dubp/common-doc/README.md b/lib/dubp/common-doc/README.md new file mode 100644 index 00000000..3d1323b9 --- /dev/null +++ b/lib/dubp/common-doc/README.md @@ -0,0 +1,9 @@ +# DUBP common doc + +`dubp-common-doc` is a crate provide common tools To handle [DUBP](dubp-latest-rfc) documents. + +[dubp-latest-rfc]: https://git.duniter.org/nodes/common/doc/blob/master/rfc/0009_Duniter_Blockchain_Protocol_V11.md + +## How to use it + +You can add `dubp-common-doc` as a `cargo` dependency in your Rust project. diff --git a/lib/dubp/documents/src/blockstamp.rs b/lib/dubp/common-doc/src/blockstamp.rs similarity index 82% rename from lib/dubp/documents/src/blockstamp.rs rename to lib/dubp/common-doc/src/blockstamp.rs index 83123615..9ca3cc8c 100644 --- a/lib/dubp/documents/src/blockstamp.rs +++ b/lib/dubp/common-doc/src/blockstamp.rs @@ -15,11 +15,17 @@ //! Wrapper for blockstamp -use crate::*; - -/// Type of errors for [`BlockUId`] parsing. +use crate::{BlockHash, BlockNumber}; +use dup_crypto::bases::BaseConvertionError; +use dup_crypto::hashs::Hash; +use failure::Fail; +use serde::{Deserialize, Serialize}; +use std::cmp::Ordering; +use std::fmt::{Debug, Display, Error, Formatter}; + +/// Type of errors for [`Blockstamp`] parsing. /// -/// [`BlockUId`]: struct.BlockUId.html +/// [`Blockstamp`]: struct.Blockstamp.html #[derive(Debug, Copy, Clone, PartialEq, Eq, Fail)] pub enum BlockstampParseError { /// Given string have invalid format @@ -30,7 +36,13 @@ pub enum BlockstampParseError { InvalidBlockNumber(), /// [`BlockHash`](struct.BlockHash.html) part is not a valid hex number. #[fail(display = "BlockHash part is not a valid hex number.")] - InvalidBlockHash(), + InvalidBlockHash(BaseConvertionError), +} + +impl From<BaseConvertionError> for BlockstampParseError { + fn from(e: BaseConvertionError) -> Self { + BlockstampParseError::InvalidBlockHash(e) + } } /// A blockstamp (Unique ID). @@ -105,17 +117,17 @@ pub enum ReadBytesBlockstampError { /// Bytes vector is too long TooLong(), /// IoError - IoError(::std::io::Error), + IoError(std::io::Error), } -impl From<::std::io::Error> for ReadBytesBlockstampError { - fn from(e: ::std::io::Error) -> Self { +impl From<std::io::Error> for ReadBytesBlockstampError { + fn from(e: std::io::Error) -> Self { ReadBytesBlockstampError::IoError(e) } } impl Blockstamp { - /// Create a `BlockUId` from a text. + /// Create a `Blockstamp` from a text. pub fn from_string(src: &str) -> Result<Blockstamp, BlockstampParseError> { let mut split = src.split('-'); @@ -123,18 +135,14 @@ impl Blockstamp { Err(BlockstampParseError::InvalidFormat()) } else { let id = split.next().unwrap().parse::<u32>(); - let hash = Hash::from_hex(split.next().unwrap()); + let hash = Hash::from_hex(split.next().unwrap())?; if id.is_err() { Err(BlockstampParseError::InvalidBlockNumber()) - } else if hash.is_err() { - Err(BlockstampParseError::InvalidBlockHash()) } else { Ok(Blockstamp { id: BlockNumber(id.unwrap()), - hash: BlockHash( - hash.expect("Try to get hash of an uncompleted or reduce block !"), - ), + hash: BlockHash(hash), }) } } diff --git a/lib/dubp/currency-params/src/currencies_codes.rs b/lib/dubp/common-doc/src/currencies_codes.rs similarity index 100% rename from lib/dubp/currency-params/src/currencies_codes.rs rename to lib/dubp/common-doc/src/currencies_codes.rs diff --git a/lib/dubp/documents/src/documents_grammar.pest b/lib/dubp/common-doc/src/documents_grammar.pest similarity index 100% rename from lib/dubp/documents/src/documents_grammar.pest rename to lib/dubp/common-doc/src/documents_grammar.pest diff --git a/lib/dubp/common-doc/src/errors.rs b/lib/dubp/common-doc/src/errors.rs new file mode 100644 index 00000000..bdd1d2af --- /dev/null +++ b/lib/dubp/common-doc/src/errors.rs @@ -0,0 +1,30 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Define DUBP Documents errors types. + +use dup_crypto::keys::SigError; +use std::collections::HashMap; + +/// List of possible errors for document signatures verification. +#[derive(Debug, Eq, PartialEq)] +pub enum DocumentSigsErr { + /// Not same amount of issuers and signatures. + /// (issuers count, signatures count) + IncompletePairs(usize, usize), + /// Signatures don't match. + /// List of mismatching pairs indexes. + Invalid(HashMap<usize, SigError>), +} diff --git a/lib/dubp/common-doc/src/lib.rs b/lib/dubp/common-doc/src/lib.rs new file mode 100644 index 00000000..5cb11952 --- /dev/null +++ b/lib/dubp/common-doc/src/lib.rs @@ -0,0 +1,88 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Provide common tools for DUBP. + +#![deny( + missing_debug_implementations, + missing_copy_implementations, + trivial_casts, + trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces +)] + +#[macro_use] +extern crate pest_derive; + +pub mod blockstamp; +pub mod currencies_codes; +pub mod errors; +pub mod parser; +pub mod traits; + +use dup_crypto::hashs::Hash; +use serde::{Deserialize, Serialize}; +use shrinkwraprs::Shrinkwrap; +use std::fmt::{Debug, Display, Error, Formatter}; + +pub use blockstamp::{Blockstamp, PreviousBlockstamp}; + +/// Currency name +#[derive(Debug, Clone, Eq, Hash, PartialEq, Deserialize, Serialize, Shrinkwrap)] +pub struct CurrencyName(pub String); + +impl Display for CurrencyName { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { + write!(f, "{}", self.0) + } +} + +impl From<&str> for CurrencyName { + fn from(s: &str) -> Self { + CurrencyName(s.to_owned()) + } +} + +/// A block number. +#[derive( + Copy, Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Shrinkwrap, +)] +pub struct BlockNumber(pub u32); + +impl Display for BlockNumber { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { + write!(f, "{}", self.0) + } +} + +/// Wrapper of a block hash. +#[derive( + Copy, Clone, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Shrinkwrap, +)] +pub struct BlockHash(pub Hash); + +impl Display for BlockHash { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { + write!(f, "{}", self.0.to_hex()) + } +} + +impl Debug for BlockHash { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { + write!(f, "BlockHash({})", self) + } +} diff --git a/lib/dubp/common-doc/src/parser.rs b/lib/dubp/common-doc/src/parser.rs new file mode 100644 index 00000000..25e6ad7e --- /dev/null +++ b/lib/dubp/common-doc/src/parser.rs @@ -0,0 +1,93 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Provide parser for DUBP documents. + +use failure::Fail; +use pest::iterators::Pair; +use pest::RuleType; +use std::net::AddrParseError; + +#[derive(Debug, Clone, Copy, Parser)] +#[grammar = "documents_grammar.pest"] +/// Parser for Documents +pub struct DocumentsParser; + +pub trait TextDocumentParser<R: RuleType> { + /// Type of document generated by the parser + type DocumentType; + + /// Parse text document from raw format + fn parse(doc: &str) -> Result<Self::DocumentType, TextDocumentParseError>; + /// Parse text document from pest pairs + fn from_pest_pair(pairs: Pair<R>) -> Result<Self::DocumentType, TextDocumentParseError>; + /// Parse text document from versioned pest pairs + fn from_versioned_pest_pair( + version: u16, + pairs: Pair<R>, + ) -> Result<Self::DocumentType, TextDocumentParseError>; +} + +/// Error with pest parser (grammar) +#[derive(Debug, Clone, Eq, Fail, PartialEq)] +#[fail(display = "Grammar error: {}", _0)] +pub struct PestError(pub String); + +impl<T: pest::RuleType> From<pest::error::Error<T>> for PestError { + fn from(e: pest::error::Error<T>) -> Self { + PestError(format!("{}", e)) + } +} + +/// List of possible errors while parsing a text document. +#[derive(Debug, Clone, Eq, Fail, PartialEq)] +pub enum TextDocumentParseError { + /// The given source don't have a valid specific document format (document type). + #[fail(display = "TextDocumentParseError: Invalid inner format: {}", _0)] + InvalidInnerFormat(String), + /// Ip address parse error + #[fail(display = "TextDocumentParseError: invalid ip: {}", _0)] + IpAddrError(AddrParseError), + /// Error with pest parser + #[fail(display = "TextDocumentParseError: {}", _0)] + PestError(PestError), + /// Unexpected rule + #[fail(display = "TextDocumentParseError: Unexpected rule: '{}'", _0)] + UnexpectedRule(String), + /// Unexpected version + #[fail(display = "TextDocumentParseError: Unexpected version: '{}'", _0)] + UnexpectedVersion(String), + /// Unknown type + #[fail(display = "TextDocumentParseError: UnknownType.")] + UnknownType, +} + +impl From<AddrParseError> for TextDocumentParseError { + fn from(e: AddrParseError) -> Self { + TextDocumentParseError::IpAddrError(e) + } +} + +impl From<PestError> for TextDocumentParseError { + fn from(e: PestError) -> Self { + TextDocumentParseError::PestError(e) + } +} + +impl<T: pest::RuleType> From<pest::error::Error<T>> for TextDocumentParseError { + fn from(e: pest::error::Error<T>) -> Self { + TextDocumentParseError::PestError(e.into()) + } +} diff --git a/lib/dubp/common-doc/src/traits.rs b/lib/dubp/common-doc/src/traits.rs new file mode 100644 index 00000000..1a0c46b4 --- /dev/null +++ b/lib/dubp/common-doc/src/traits.rs @@ -0,0 +1,164 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Define DUBP Documents Traits. + +pub mod text; + +use crate::blockstamp::Blockstamp; +use crate::errors::DocumentSigsErr; +use dup_crypto::keys::*; +use serde::Serialize; +use std::collections::HashMap; +use std::fmt::Debug; + +/// trait providing commun methods for any documents of any protocol version. +/// +/// # Design choice +/// +/// Allow only ed25519 for protocol 10 and many differents +/// schemes for protocol 11 through a proxy type. +pub trait Document: Debug + Clone + PartialEq + Eq { + /// Type of the `PublicKey` used by the document. + type PublicKey: PublicKey; + + /// Get document as bytes for signature verification. + fn as_bytes(&self) -> &[u8]; + + /// Get document blockstamp + fn blockstamp(&self) -> Blockstamp; + + /// Get document currency name. + fn currency(&self) -> &str; + + /// Iterate over document issuers. + fn issuers(&self) -> &Vec<Self::PublicKey>; + + /// Some documents do not directly store the sequence of bytes that will be signed but generate + // it on request, so these types of documents cannot provide a reference to the signed bytes. + fn no_as_bytes(&self) -> bool { + false + } + + /// Get document to bytes for signature verification. + fn to_bytes(&self) -> Vec<u8> { + self.as_bytes().to_vec() + } + + /// Iterate over document signatures. + fn signatures(&self) -> &Vec<<Self::PublicKey as PublicKey>::Signature>; + + /// Verify one signature + #[inline] + fn verify_one_signature( + &self, + public_key: &Self::PublicKey, + signature: &<Self::PublicKey as PublicKey>::Signature, + ) -> Result<(), SigError> { + if self.no_as_bytes() { + public_key.verify(&self.to_bytes(), signature) + } else { + public_key.verify(self.as_bytes(), signature) + } + } + + /// Verify signatures of document content + fn verify_signatures(&self) -> Result<(), DocumentSigsErr> { + let issuers_count = self.issuers().len(); + let signatures_count = self.signatures().len(); + + if issuers_count != signatures_count { + Err(DocumentSigsErr::IncompletePairs( + issuers_count, + signatures_count, + )) + } else { + let issuers = self.issuers(); + let signatures = self.signatures(); + let mismatches: HashMap<usize, SigError> = issuers + .iter() + .zip(signatures) + .enumerate() + .filter_map(|(i, (key, signature))| { + if let Err(e) = self.verify_one_signature(key, signature) { + Some((i, e)) + } else { + None + } + }) + .collect(); + + if mismatches.is_empty() { + Ok(()) + } else { + Err(DocumentSigsErr::Invalid(mismatches)) + } + } + } + + /// Get document version. + fn version(&self) -> u16; +} + +/// Trait helper for building new documents. +pub trait DocumentBuilder { + /// Type of the builded document. + type Document: Document; + + /// Type of the private keys signing the documents. + type PrivateKey: PrivateKey< + Signature = <<Self::Document as Document>::PublicKey as PublicKey>::Signature, + >; + + /// Build a document with provided signatures. + fn build_with_signature( + &self, + signatures: Vec<<<Self::Document as Document>::PublicKey as PublicKey>::Signature>, + ) -> Self::Document; + + /// Build a document and sign it with the private key. + fn build_and_sign(&self, private_keys: Vec<Self::PrivateKey>) -> Self::Document; +} + +/// Trait for a document parser from a `S` source +/// format to a `D` document. Will return the +/// parsed document or an `E` error. +pub trait DocumentParser<S, D, E> { + /// Parse a source and return a document or an error. + fn parse(source: S) -> Result<D, E>; +} + +/// Stringify a document +pub trait ToStringObject { + /// Generated string object + type StringObject: Serialize; + + /// Transforms object fields into string + fn to_string_object(&self) -> Self::StringObject; +} + +/// Jsonify a document +pub trait ToJsonObject: ToStringObject { + /// Convert to JSON String + fn to_json_string(&self) -> Result<String, serde_json::Error> { + Ok(serde_json::to_string(&self.to_string_object())?) + } + /// Convert to JSON String pretty + fn to_json_string_pretty(&self) -> Result<String, serde_json::Error> { + Ok(serde_json::to_string_pretty(&self.to_string_object())?) + } +} + +impl<T: ToStringObject> ToJsonObject for T {} diff --git a/lib/dubp/documents/src/text_document_traits.rs b/lib/dubp/common-doc/src/traits/text.rs similarity index 97% rename from lib/dubp/documents/src/text_document_traits.rs rename to lib/dubp/common-doc/src/traits/text.rs index 40529680..e3c721e1 100644 --- a/lib/dubp/documents/src/text_document_traits.rs +++ b/lib/dubp/common-doc/src/traits/text.rs @@ -15,10 +15,11 @@ //! Define the Text Document Traits. +use super::{Document, DocumentBuilder}; use crate::*; use dup_crypto::keys::*; -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] /// Contains a document in full or compact format pub enum TextDocumentFormat<D: TextDocument> { /// Complete format (Allows to check the validity of the signature) @@ -56,7 +57,7 @@ impl<D: TextDocument> CompactTextDocument for TextDocumentFormat<D> { } } -/// Trait for a V10 document. +/// Trait for a text document. pub trait TextDocument: Document<PublicKey = PubKey> { /// Type of associated compact document. type CompactTextDocument_: CompactTextDocument; diff --git a/lib/dubp/currency-params/Cargo.toml b/lib/dubp/currency-params/Cargo.toml index a0027c9f..38c5e097 100644 --- a/lib/dubp/currency-params/Cargo.toml +++ b/lib/dubp/currency-params/Cargo.toml @@ -13,6 +13,7 @@ path = "src/lib.rs" [dependencies] bincode = "1.0.1" +dubp-common-doc = { path = "../common-doc" } #, version = "0.1.0" } durs-common-tools = { path = "../../tools/common-tools", version = "0.2.0" } failure = "0.1.5" serde = { version = "1.0.*", features = ["derive"] } diff --git a/lib/dubp/currency-params/src/lib.rs b/lib/dubp/currency-params/src/lib.rs index 258fb7f0..1eeb05b0 100644 --- a/lib/dubp/currency-params/src/lib.rs +++ b/lib/dubp/currency-params/src/lib.rs @@ -27,30 +27,12 @@ )] pub mod constants; -pub mod currencies_codes; pub mod db; pub mod genesis_block_params; use crate::constants::*; +pub use dubp_common_doc::CurrencyName; use genesis_block_params::v10::BlockV10Parameters; -use serde::{Deserialize, Serialize}; -use std::fmt::{Display, Error, Formatter}; - -/// Currency name -#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Hash)] -pub struct CurrencyName(pub String); - -impl Display for CurrencyName { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{}", self.0) - } -} - -impl From<&str> for CurrencyName { - fn from(s: &str) -> Self { - CurrencyName(s.to_owned()) - } -} #[derive(Debug, Copy, Clone)] /// Currency parameters diff --git a/lib/dubp/documents/Cargo.toml b/lib/dubp/documents/Cargo.toml index 11d05423..2742315f 100644 --- a/lib/dubp/documents/Cargo.toml +++ b/lib/dubp/documents/Cargo.toml @@ -13,9 +13,10 @@ edition = "2018" path = "src/lib.rs" [dependencies] -durs-common-tools = { path = "../../tools/common-tools", version = "0.2.0" } -dup-crypto = { path = "../../crypto", version = "0.7.0" } +dubp-common-doc = { path = "../common-doc"} #, version = "0.1.0" } dubp-currency-params = { path = "../currency-params", version = "0.2.0" } +dup-crypto = { path = "../../crypto", version = "0.7.0" } +durs-common-tools = { path = "../../tools/common-tools", version = "0.2.0" } failure = "0.1.5" json-pest-parser = { path = "../../tools/json-pest-parser", version = "0.2.0" } pest = "2.1.0" diff --git a/lib/dubp/documents/src/documents/block.rs b/lib/dubp/documents/src/documents/block.rs index 73f732f2..4bb62449 100644 --- a/lib/dubp/documents/src/documents/block.rs +++ b/lib/dubp/documents/src/documents/block.rs @@ -17,13 +17,14 @@ pub mod v10; -pub use v10::{BlockDocumentV10, BlockDocumentV10Stringified}; - -use crate::blockstamp::Blockstamp; -use crate::{BlockHash, BlockNumber, Document, ToStringObject}; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::traits::{Document, ToStringObject}; +use dubp_common_doc::{BlockHash, BlockNumber}; use dup_crypto::hashs::Hash; use dup_crypto::keys::{PrivKey, PubKey, PublicKey}; +pub use v10::{BlockDocumentV10, BlockDocumentV10Stringified}; + /// Wrap a Block document. /// /// Must be created by parsing a text document or using a builder. diff --git a/lib/dubp/documents/src/documents/block/v10.rs b/lib/dubp/documents/src/documents/block/v10.rs index 2a30f302..73832fce 100644 --- a/lib/dubp/documents/src/documents/block/v10.rs +++ b/lib/dubp/documents/src/documents/block/v10.rs @@ -15,16 +15,7 @@ //! Wrappers around Block document V10. -use dubp_currency_params::genesis_block_params::v10::BlockV10Parameters; -use dubp_currency_params::CurrencyName; -use dup_crypto::hashs::Hash; -use dup_crypto::keys::*; -use durs_common_tools::fatal_error; -use std::ops::Deref; -use unwrap::unwrap; - use super::{BlockDocumentTrait, VerifyBlockHashError}; -use crate::blockstamp::Blockstamp; use crate::documents::certification::v10::CompactCertificationDocumentV10Stringified; use crate::documents::identity::IdentityDocumentV10; use crate::documents::membership::v10::{MembershipDocumentV10, MembershipDocumentV10Stringified}; @@ -32,7 +23,17 @@ use crate::documents::revocation::v10::CompactRevocationDocumentV10Stringified; use crate::documents::revocation::RevocationDocumentV10; use crate::documents::transaction::TransactionDocument; use crate::documents::*; -use crate::text_document_traits::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::traits::text::*; +use dubp_common_doc::traits::{Document, ToStringObject}; +use dubp_common_doc::{BlockHash, BlockNumber}; +use dubp_currency_params::genesis_block_params::v10::BlockV10Parameters; +use dubp_currency_params::CurrencyName; +use dup_crypto::hashs::Hash; +use dup_crypto::keys::*; +use durs_common_tools::fatal_error; +use std::ops::Deref; +use unwrap::unwrap; /// Store a transaction document or just its hash. #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] @@ -622,7 +623,7 @@ mod tests { use super::certification::CertificationDocumentParser; use super::transaction::TransactionDocumentParser; use super::*; - use crate::Document; + use dubp_common_doc::traits::Document; #[test] fn generate_and_verify_empty_block() { diff --git a/lib/dubp/documents/src/documents/certification.rs b/lib/dubp/documents/src/documents/certification.rs index e50e3ffe..7b4afc1f 100644 --- a/lib/dubp/documents/src/documents/certification.rs +++ b/lib/dubp/documents/src/documents/certification.rs @@ -17,17 +17,18 @@ pub mod v10; -pub use v10::{ - CertificationDocumentV10, CertificationDocumentV10Stringified, CompactCertificationDocumentV10, -}; - -use crate::blockstamp::Blockstamp; use crate::documents::*; - +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::{DocumentsParser, TextDocumentParseError, TextDocumentParser}; +use dubp_common_doc::traits::{Document, ToStringObject}; use dup_crypto::keys::*; use durs_common_tools::fatal_error; use pest::Parser; +pub use v10::{ + CertificationDocumentV10, CertificationDocumentV10Stringified, CompactCertificationDocumentV10, +}; + /// Wrap an Certification document. /// /// Must be created by parsing a text document or using a builder. diff --git a/lib/dubp/documents/src/documents/certification/v10.rs b/lib/dubp/documents/src/documents/certification/v10.rs index 20740f89..d125639d 100644 --- a/lib/dubp/documents/src/documents/certification/v10.rs +++ b/lib/dubp/documents/src/documents/certification/v10.rs @@ -15,13 +15,16 @@ //! Wrappers around Certification documents V10. +use crate::documents::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::TextDocumentParseError; +use dubp_common_doc::traits::text::*; +use dubp_common_doc::traits::{Document, DocumentBuilder, ToStringObject}; +use dubp_common_doc::{BlockHash, BlockNumber}; +use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_common_tools::fatal_error; -use crate::blockstamp::Blockstamp; -use crate::documents::*; -use crate::text_document_traits::*; - #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] /// Wrap an Compact Revocation document (in block content) pub struct CompactCertificationDocumentV10 { diff --git a/lib/dubp/documents/src/documents/identity.rs b/lib/dubp/documents/src/documents/identity.rs index 032c0a00..1544481e 100644 --- a/lib/dubp/documents/src/documents/identity.rs +++ b/lib/dubp/documents/src/documents/identity.rs @@ -17,9 +17,13 @@ pub mod v10; -pub use v10::{IdentityDocumentV10, IdentityDocumentV10Stringified}; - use crate::documents::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::{DocumentsParser, TextDocumentParseError, TextDocumentParser}; +use dubp_common_doc::traits::{Document, ToStringObject}; +use dup_crypto::keys::*; + +pub use v10::{IdentityDocumentV10, IdentityDocumentV10Stringified}; /// Identity document #[derive(Clone, Debug, Deserialize, Hash, Serialize, PartialEq, Eq)] diff --git a/lib/dubp/documents/src/documents/identity/v10.rs b/lib/dubp/documents/src/documents/identity/v10.rs index f2f8fc3c..b26c078f 100644 --- a/lib/dubp/documents/src/documents/identity/v10.rs +++ b/lib/dubp/documents/src/documents/identity/v10.rs @@ -18,8 +18,13 @@ use durs_common_tools::fatal_error; use crate::documents::*; -use crate::text_document_traits::*; -use crate::Blockstamp; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::TextDocumentParseError; +use dubp_common_doc::traits::text::*; +use dubp_common_doc::traits::{Document, DocumentBuilder, ToStringObject}; +use dubp_common_doc::{BlockHash, BlockNumber}; +use dup_crypto::hashs::Hash; +use dup_crypto::keys::*; /// Wrap an Identity document. /// @@ -262,7 +267,7 @@ Timestamp: {blockstamp} #[cfg(test)] mod tests { use super::*; - use crate::Document; + use dubp_common_doc::traits::Document; use dup_crypto::keys::{PrivateKey, PublicKey, Signature}; #[test] diff --git a/lib/dubp/documents/src/documents/membership.rs b/lib/dubp/documents/src/documents/membership.rs index cf58aa8e..515d7f79 100644 --- a/lib/dubp/documents/src/documents/membership.rs +++ b/lib/dubp/documents/src/documents/membership.rs @@ -17,10 +17,14 @@ pub mod v10; -pub use v10::{MembershipDocumentV10, MembershipDocumentV10Stringified}; - use crate::documents::*; -use crate::text_document_traits::{CompactTextDocument, TextDocument}; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::{DocumentsParser, TextDocumentParseError, TextDocumentParser}; +use dubp_common_doc::traits::text::*; +use dubp_common_doc::traits::{Document, ToStringObject}; +use dup_crypto::keys::*; + +pub use v10::{MembershipDocumentV10, MembershipDocumentV10Stringified}; /// Wrap an Membership document. /// diff --git a/lib/dubp/documents/src/documents/membership/v10.rs b/lib/dubp/documents/src/documents/membership/v10.rs index bcf11786..25ecc0b0 100644 --- a/lib/dubp/documents/src/documents/membership/v10.rs +++ b/lib/dubp/documents/src/documents/membership/v10.rs @@ -15,13 +15,16 @@ //! Wrappers around Membership documents v10. +use crate::documents::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::TextDocumentParseError; +use dubp_common_doc::traits::text::*; +use dubp_common_doc::traits::{Document, DocumentBuilder, ToStringObject}; +use dubp_common_doc::{BlockHash, BlockNumber}; +use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_common_tools::fatal_error; -use crate::blockstamp::Blockstamp; -use crate::documents::*; -use crate::text_document_traits::*; - /// Type of a Membership. #[derive(Debug, Deserialize, Clone, Copy, Hash, Serialize, PartialEq, Eq)] pub enum MembershipType { diff --git a/lib/dubp/documents/src/documents/mod.rs b/lib/dubp/documents/src/documents/mod.rs index 2b5c96b6..16d48f81 100644 --- a/lib/dubp/documents/src/documents/mod.rs +++ b/lib/dubp/documents/src/documents/mod.rs @@ -21,9 +21,8 @@ use crate::documents::identity::*; use crate::documents::membership::*; use crate::documents::revocation::*; use crate::documents::transaction::*; -use crate::Rule; -use crate::*; - +use dubp_common_doc::parser::{DocumentsParser, Rule, TextDocumentParseError, TextDocumentParser}; +use dubp_common_doc::traits::ToStringObject; use durs_common_tools::fatal_error; use pest::iterators::Pair; use pest::Parser; @@ -194,8 +193,9 @@ impl UserDocumentDUBP { #[cfg(test)] mod tests { - use crate::blockstamp::Blockstamp; - use crate::*; + use dubp_common_doc::parser::TextDocumentParser; + use dubp_common_doc::traits::Document; + use dubp_common_doc::Blockstamp; use super::certification::CertificationDocumentParser; use super::identity::IdentityDocumentParser; diff --git a/lib/dubp/documents/src/documents/revocation.rs b/lib/dubp/documents/src/documents/revocation.rs index 992bce71..23b5ec49 100644 --- a/lib/dubp/documents/src/documents/revocation.rs +++ b/lib/dubp/documents/src/documents/revocation.rs @@ -17,17 +17,18 @@ pub mod v10; +use crate::documents::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::{DocumentsParser, TextDocumentParseError, TextDocumentParser}; +use dubp_common_doc::traits::{Document, ToStringObject}; +use dup_crypto::keys::*; +use pest::Parser; + pub use v10::{ CompactRevocationDocumentV10, CompactRevocationDocumentV10Stringified, RevocationDocumentV10, RevocationDocumentV10Stringified, }; -use crate::blockstamp::Blockstamp; -use crate::documents::*; - -use dup_crypto::keys::*; -use pest::Parser; - /// Wrap an Revocation document. /// /// Must be created by parsing a text document or using a builder. diff --git a/lib/dubp/documents/src/documents/revocation/v10.rs b/lib/dubp/documents/src/documents/revocation/v10.rs index b2350847..d58118e8 100644 --- a/lib/dubp/documents/src/documents/revocation/v10.rs +++ b/lib/dubp/documents/src/documents/revocation/v10.rs @@ -32,9 +32,13 @@ use dup_crypto::keys::*; -use crate::blockstamp::Blockstamp; use crate::documents::*; -use crate::text_document_traits::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::TextDocumentParseError; +use dubp_common_doc::traits::text::*; +use dubp_common_doc::traits::{Document, DocumentBuilder, ToStringObject}; +use dubp_common_doc::{BlockHash, BlockNumber}; +use dup_crypto::hashs::Hash; #[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq, Eq)] /// Wrap an Compact Revocation document (in block content) diff --git a/lib/dubp/documents/src/documents/transaction.rs b/lib/dubp/documents/src/documents/transaction.rs index 162ab058..48c9720a 100644 --- a/lib/dubp/documents/src/documents/transaction.rs +++ b/lib/dubp/documents/src/documents/transaction.rs @@ -15,7 +15,14 @@ //! Wrappers around Transaction documents. +use crate::documents::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::{DocumentsParser, TextDocumentParseError, TextDocumentParser}; +use dubp_common_doc::traits::text::*; +use dubp_common_doc::traits::{Document, DocumentBuilder, ToStringObject}; +use dubp_common_doc::{BlockHash, BlockNumber}; use dup_crypto::hashs::*; +use dup_crypto::keys::*; use durs_common_tools::fatal_error; use pest::iterators::Pair; use pest::iterators::Pairs; @@ -24,10 +31,6 @@ use std::ops::{Add, Deref, Sub}; use std::str::FromStr; use unwrap::unwrap; -use crate::blockstamp::Blockstamp; -use crate::documents::*; -use crate::text_document_traits::*; - /// Wrap a transaction amount #[derive(Debug, Copy, Clone, Eq, Ord, PartialEq, PartialOrd, Deserialize, Hash, Serialize)] pub struct TxAmount(pub isize); @@ -944,7 +947,7 @@ impl TextDocumentParser<Rule> for TransactionDocumentParser { #[cfg(test)] mod tests { use super::*; - use crate::Document; + use dubp_common_doc::traits::Document; #[test] fn generate_real_document() { diff --git a/lib/dubp/documents/src/lib.rs b/lib/dubp/documents/src/lib.rs index 18a5b7d2..56608e3e 100644 --- a/lib/dubp/documents/src/lib.rs +++ b/lib/dubp/documents/src/lib.rs @@ -29,286 +29,19 @@ extern crate log; #[macro_use] extern crate failure; -#[macro_use] -extern crate pest_derive; #[cfg(test)] #[macro_use] extern crate pretty_assertions; #[macro_use] extern crate serde_derive; -pub mod blockstamp; pub mod documents; pub mod parsers; -pub mod text_document_traits; - -use dup_crypto::hashs::Hash; -use dup_crypto::keys::*; -use pest::iterators::Pair; -use pest::RuleType; -use serde::Serialize; -use std::cmp::Ordering; -use std::fmt::{Debug, Display, Error, Formatter}; -use std::net::AddrParseError; - -pub use crate::blockstamp::{Blockstamp, PreviousBlockstamp}; - -#[derive(Parser)] -#[grammar = "documents_grammar.pest"] -/// Parser for Documents -struct DocumentsParser; - -pub trait TextDocumentParser<R: RuleType> { - /// Type of document generated by the parser - type DocumentType; - - /// Parse text document from raw format - fn parse(doc: &str) -> Result<Self::DocumentType, TextDocumentParseError>; - /// Parse text document from pest pairs - fn from_pest_pair(pairs: Pair<R>) -> Result<Self::DocumentType, TextDocumentParseError>; - /// Parse text document from versioned pest pairs - fn from_versioned_pest_pair( - version: u16, - pairs: Pair<R>, - ) -> Result<Self::DocumentType, TextDocumentParseError>; -} - -/// Error with pest parser (grammar) -#[derive(Debug, Clone, Eq, Fail, PartialEq)] -#[fail(display = "Grammar error: {}", _0)] -pub struct PestError(pub String); - -impl<T: pest::RuleType> From<pest::error::Error<T>> for PestError { - fn from(e: pest::error::Error<T>) -> Self { - PestError(format!("{}", e)) - } -} - -/// List of possible errors while parsing a text document. -#[derive(Debug, Clone, Eq, Fail, PartialEq)] -pub enum TextDocumentParseError { - /// The given source don't have a valid specific document format (document type). - #[fail(display = "TextDocumentParseError: Invalid inner format: {}", _0)] - InvalidInnerFormat(String), - /// Ip address parse error - #[fail(display = "TextDocumentParseError: invalid ip: {}", _0)] - IpAddrError(AddrParseError), - /// Error with pest parser - #[fail(display = "TextDocumentParseError: {}", _0)] - PestError(PestError), - /// Unexpected rule - #[fail(display = "TextDocumentParseError: Unexpected rule: '{}'", _0)] - UnexpectedRule(String), - /// Unexpected version - #[fail(display = "TextDocumentParseError: Unexpected version: '{}'", _0)] - UnexpectedVersion(String), - /// Unknown type - #[fail(display = "TextDocumentParseError: UnknownType.")] - UnknownType, -} - -impl From<AddrParseError> for TextDocumentParseError { - fn from(e: AddrParseError) -> Self { - TextDocumentParseError::IpAddrError(e) - } -} - -impl From<PestError> for TextDocumentParseError { - fn from(e: PestError) -> Self { - TextDocumentParseError::PestError(e) - } -} - -impl<T: pest::RuleType> From<pest::error::Error<T>> for TextDocumentParseError { - fn from(e: pest::error::Error<T>) -> Self { - TextDocumentParseError::PestError(e.into()) - } -} - -/// A block Id. -#[derive(Copy, Clone, Debug, Deserialize, Ord, PartialEq, PartialOrd, Eq, Hash, Serialize)] -pub struct BlockNumber(pub u32); - -impl Display for BlockNumber { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{}", self.0) - } -} - -/// Wrapper of a block hash. -#[derive(Copy, Clone, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Hash, Serialize)] -pub struct BlockHash(pub Hash); - -impl Display for BlockHash { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{}", self.0.to_hex()) - } -} - -impl Debug for BlockHash { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "BlockHash({})", self) - } -} - -/// trait providing commun methods for any documents of any protocol version. -/// -/// # Design choice -/// -/// Allow only ed25519 for protocol 10 and many differents -/// schemes for protocol 11 through a proxy type. -pub trait Document: Debug + Clone + PartialEq + Eq { - /// Type of the `PublicKey` used by the document. - type PublicKey: PublicKey; - - /// Get document as bytes for signature verification. - fn as_bytes(&self) -> &[u8]; - - /// Get document blockstamp - fn blockstamp(&self) -> Blockstamp; - - /// Get document currency name. - fn currency(&self) -> &str; - - /// Iterate over document issuers. - fn issuers(&self) -> &Vec<Self::PublicKey>; - - /// Some documents do not directly store the sequence of bytes that will be signed but generate - // it on request, so these types of documents cannot provide a reference to the signed bytes. - fn no_as_bytes(&self) -> bool { - false - } - - /// Get document to bytes for signature verification. - fn to_bytes(&self) -> Vec<u8> { - self.as_bytes().to_vec() - } - - /// Iterate over document signatures. - fn signatures(&self) -> &Vec<<Self::PublicKey as PublicKey>::Signature>; - - /// Verify one signature - #[inline] - fn verify_one_signature( - &self, - public_key: &Self::PublicKey, - signature: &<Self::PublicKey as PublicKey>::Signature, - ) -> Result<(), SigError> { - if self.no_as_bytes() { - public_key.verify(&self.to_bytes(), signature) - } else { - public_key.verify(self.as_bytes(), signature) - } - } - - /// Verify signatures of document content (as text format) - fn verify_signatures(&self) -> Result<(), DocumentSigsErr> { - let issuers_count = self.issuers().len(); - let signatures_count = self.signatures().len(); - - if issuers_count != signatures_count { - Err(DocumentSigsErr::IncompletePairs( - issuers_count, - signatures_count, - )) - } else { - let issuers = self.issuers(); - let signatures = self.signatures(); - let mismatches: HashMap<usize, SigError> = issuers - .iter() - .zip(signatures) - .enumerate() - .filter_map(|(i, (key, signature))| { - if let Err(e) = self.verify_one_signature(key, signature) { - Some((i, e)) - } else { - None - } - }) - .collect(); - - if mismatches.is_empty() { - Ok(()) - } else { - Err(DocumentSigsErr::Invalid(mismatches)) - } - } - } - - /// Get document version. - fn version(&self) -> u16; -} - -use std::collections::HashMap; - -// todo: à mon avis faudrait pas que y ait de Valid() dans cette enum -// et du coup faudrait que les fonctions qui renvoient un DocumentSigsErr renvoie Result<(), DocumentSigsErr> -// du coup SignatureError dans la local verif sert plus à rien. - -/// List of possible errors for document signatures verification. -#[derive(Debug, Eq, PartialEq)] -pub enum DocumentSigsErr { - /// Not same amount of issuers and signatures. - /// (issuers count, signatures count) - IncompletePairs(usize, usize), - /// Signatures don't match. - /// List of mismatching pairs indexes. - Invalid(HashMap<usize, SigError>), -} - -/// Trait helper for building new documents. -pub trait DocumentBuilder { - /// Type of the builded document. - type Document: Document; - - /// Type of the private keys signing the documents. - type PrivateKey: PrivateKey< - Signature = <<Self::Document as Document>::PublicKey as PublicKey>::Signature, - >; - - /// Build a document with provided signatures. - fn build_with_signature( - &self, - signatures: Vec<<<Self::Document as Document>::PublicKey as PublicKey>::Signature>, - ) -> Self::Document; - - /// Build a document and sign it with the private key. - fn build_and_sign(&self, private_keys: Vec<Self::PrivateKey>) -> Self::Document; -} - -/// Trait for a document parser from a `S` source -/// format to a `D` document. Will return the -/// parsed document or an `E` error. -pub trait DocumentParser<S, D, E> { - /// Parse a source and return a document or an error. - fn parse(source: S) -> Result<D, E>; -} - -/// Stringify a document -pub trait ToStringObject { - type StringObject: Serialize; - /// Transforms object fields into string - fn to_string_object(&self) -> Self::StringObject; -} - -/// Jsonify a document -pub trait ToJsonObject: ToStringObject { - /// Convert to JSON String - fn to_json_string(&self) -> Result<String, serde_json::Error> { - Ok(serde_json::to_string(&self.to_string_object())?) - } - /// Convert to JSON String pretty - fn to_json_string_pretty(&self) -> Result<String, serde_json::Error> { - Ok(serde_json::to_string_pretty(&self.to_string_object())?) - } -} - -impl<T: ToStringObject> ToJsonObject for T {} #[cfg(test)] mod tests { - use super::*; use crate::documents::UserDocumentDUBP; + use dubp_common_doc::parser::TextDocumentParser; #[test] fn parse_dubp_document() { diff --git a/lib/dubp/documents/src/parsers/blocks.rs b/lib/dubp/documents/src/parsers/blocks.rs index 5070a5f3..c7d7f168 100644 --- a/lib/dubp/documents/src/parsers/blocks.rs +++ b/lib/dubp/documents/src/parsers/blocks.rs @@ -17,6 +17,7 @@ use crate::documents::block::{v10::TxDocOrTxHash, BlockDocument, BlockDocumentV1 use crate::documents::membership::v10::MembershipType; use crate::parsers::{serde_json_value_to_pest_json_value, DefaultHasher}; use crate::*; +use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_currency_params::genesis_block_params::v10::BlockV10Parameters; use dubp_currency_params::CurrencyName; use dup_crypto::bases::BaseConvertionError; diff --git a/lib/dubp/documents/src/parsers/certifications.rs b/lib/dubp/documents/src/parsers/certifications.rs index 6cafaf7a..424e8fec 100644 --- a/lib/dubp/documents/src/parsers/certifications.rs +++ b/lib/dubp/documents/src/parsers/certifications.rs @@ -14,8 +14,8 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::documents::certification::{CertificationDocumentV10, CompactCertificationDocumentV10}; -use crate::text_document_traits::TextDocumentFormat; -use crate::BlockNumber; +use dubp_common_doc::traits::text::TextDocumentFormat; +use dubp_common_doc::BlockNumber; use dup_crypto::keys::*; /// Parse array of certification json documents into vector of `CompactCertificationDocument` diff --git a/lib/dubp/documents/src/parsers/identities.rs b/lib/dubp/documents/src/parsers/identities.rs index 28106cda..1955290b 100644 --- a/lib/dubp/documents/src/parsers/identities.rs +++ b/lib/dubp/documents/src/parsers/identities.rs @@ -14,8 +14,8 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::documents::identity::v10::*; -use crate::Blockstamp; -use crate::DocumentBuilder; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::traits::DocumentBuilder; use dup_crypto::keys::*; #[derive(Debug, Fail)] diff --git a/lib/dubp/documents/src/parsers/memberships.rs b/lib/dubp/documents/src/parsers/memberships.rs index 9540bfe5..67662056 100644 --- a/lib/dubp/documents/src/parsers/memberships.rs +++ b/lib/dubp/documents/src/parsers/memberships.rs @@ -14,8 +14,8 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::documents::membership::v10::*; -use crate::Blockstamp; -use crate::DocumentBuilder; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::traits::DocumentBuilder; use dup_crypto::keys::*; use failure::Error; diff --git a/lib/dubp/documents/src/parsers/mod.rs b/lib/dubp/documents/src/parsers/mod.rs index 8b75c402..c9b80fb0 100644 --- a/lib/dubp/documents/src/parsers/mod.rs +++ b/lib/dubp/documents/src/parsers/mod.rs @@ -80,9 +80,10 @@ fn serde_json_value_to_pest_json_value( #[cfg(test)] mod tests { - use crate::blockstamp::Blockstamp; use crate::documents::transaction::*; - use crate::*; + use dubp_common_doc::traits::DocumentBuilder; + use dubp_common_doc::Blockstamp; + use dup_crypto::keys::*; use std::str::FromStr; pub fn first_g1_tx_doc() -> TransactionDocument { diff --git a/lib/dubp/documents/src/parsers/revoked.rs b/lib/dubp/documents/src/parsers/revoked.rs index edc82aa0..72d6b04b 100644 --- a/lib/dubp/documents/src/parsers/revoked.rs +++ b/lib/dubp/documents/src/parsers/revoked.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::documents::revocation::{CompactRevocationDocumentV10, RevocationDocumentV10}; -use crate::text_document_traits::TextDocumentFormat; +use dubp_common_doc::traits::text::TextDocumentFormat; use dup_crypto::keys::*; /// Parse array of revocations json documents into vector of `CompactRevocationDocumentV10` diff --git a/lib/dubp/documents/src/parsers/transactions.rs b/lib/dubp/documents/src/parsers/transactions.rs index bdda03b0..ba282dd6 100644 --- a/lib/dubp/documents/src/parsers/transactions.rs +++ b/lib/dubp/documents/src/parsers/transactions.rs @@ -15,8 +15,10 @@ use crate::documents::transaction::*; use crate::parsers::DefaultHasher; -use crate::TextDocumentParseError; use crate::*; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::parser::TextDocumentParseError; +use dubp_common_doc::traits::DocumentBuilder; use dup_crypto::bases::BaseConvertionError; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; diff --git a/lib/dunp/network-documents/Cargo.toml b/lib/dunp/network-documents/Cargo.toml index 755dd902..1c272107 100644 --- a/lib/dunp/network-documents/Cargo.toml +++ b/lib/dunp/network-documents/Cargo.toml @@ -13,10 +13,11 @@ path = "src/lib.rs" [dependencies] base58 = "0.1.*" -durs-common-tools = { path = "../../tools/common-tools" } -dup-crypto = { path = "../../crypto" } +dubp-common-doc = { path = "../../dubp/common-doc" } #, version = "0.1.0" } dubp-currency-params = { path = "../../dubp/currency-params" } dubp-documents= { path = "../../dubp/documents" } +dup-crypto = { path = "../../crypto" } +durs-common-tools = { path = "../../tools/common-tools" } failure = "0.1.5" hex = "0.3.*" log = "0.4.*" diff --git a/lib/dunp/network-documents/src/lib.rs b/lib/dunp/network-documents/src/lib.rs index a1435843..bc409616 100644 --- a/lib/dunp/network-documents/src/lib.rs +++ b/lib/dunp/network-documents/src/lib.rs @@ -45,7 +45,7 @@ use crate::network_head::NetworkHead; use crate::network_head_v3::NetworkHeadV3; use crate::network_peer::PeerCard; use crate::network_peer::PeerCardV11; -use dubp_documents::{TextDocumentParseError, TextDocumentParser}; +use dubp_common_doc::parser::{TextDocumentParseError, TextDocumentParser}; use dup_crypto::hashs::*; use dup_crypto::keys::*; use durs_common_tools::fatal_error; diff --git a/lib/dunp/network-documents/src/network_head.rs b/lib/dunp/network-documents/src/network_head.rs index 659e919e..130920e4 100644 --- a/lib/dunp/network-documents/src/network_head.rs +++ b/lib/dunp/network-documents/src/network_head.rs @@ -18,7 +18,7 @@ use crate::network_head_v2::*; use crate::network_head_v3::*; use crate::{NodeFullId, NodeId}; -use dubp_documents::blockstamp::*; +use dubp_common_doc::blockstamp::*; use dup_crypto::bases::BaseConvertionError; use dup_crypto::keys::*; use durs_common_tools::fatal_error; diff --git a/lib/dunp/network-documents/src/network_head_v2.rs b/lib/dunp/network-documents/src/network_head_v2.rs index 348fac67..3cfcdd73 100644 --- a/lib/dunp/network-documents/src/network_head_v2.rs +++ b/lib/dunp/network-documents/src/network_head_v2.rs @@ -16,7 +16,7 @@ //! Module defining the format of network heads v2 and how to handle them. use crate::NodeId; -use dubp_documents::blockstamp::*; +use dubp_common_doc::blockstamp::*; use dup_crypto::bases::BaseConvertionError; use dup_crypto::keys::*; use durs_common_tools::fatal_error; diff --git a/lib/dunp/network-documents/src/network_head_v3.rs b/lib/dunp/network-documents/src/network_head_v3.rs index 17d7ab26..859be116 100644 --- a/lib/dunp/network-documents/src/network_head_v3.rs +++ b/lib/dunp/network-documents/src/network_head_v3.rs @@ -18,9 +18,10 @@ use crate::network_head::NetworkHead; use crate::*; use base58::ToBase58; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::traits::ToStringObject; +use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_currency_params::CurrencyName; -use dubp_documents::blockstamp::Blockstamp; -use dubp_documents::{BlockHash, BlockNumber, ToStringObject}; use dup_crypto::keys::text_signable::TextSignable; use dup_crypto::keys::*; use pest::iterators::Pair; diff --git a/lib/dunp/network-documents/src/network_peer.rs b/lib/dunp/network-documents/src/network_peer.rs index 851495dc..6b9d63f6 100644 --- a/lib/dunp/network-documents/src/network_peer.rs +++ b/lib/dunp/network-documents/src/network_peer.rs @@ -18,10 +18,10 @@ use crate::network_endpoint::*; use crate::*; use base58::ToBase58; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::traits::ToStringObject; +use dubp_common_doc::BlockNumber; use dubp_currency_params::CurrencyName; -use dubp_documents::blockstamp::Blockstamp; -use dubp_documents::BlockNumber; -use dubp_documents::ToStringObject; use dup_crypto::keys::text_signable::TextSignable; use dup_crypto::keys::*; use pest::iterators::Pair; diff --git a/lib/modules/blockchain/blockchain-dal/Cargo.toml b/lib/modules/blockchain/blockchain-dal/Cargo.toml index 536a7da6..f6d40bde 100644 --- a/lib/modules/blockchain/blockchain-dal/Cargo.toml +++ b/lib/modules/blockchain/blockchain-dal/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" path = "src/lib.rs" [dependencies] +dubp-common-doc = { path = "../../../dubp/common-doc"} #, version = "0.1.0" } dup-crypto = { path = "../../../crypto" } dubp-currency-params = { path = "../../../dubp/currency-params" } dubp-documents= { path = "../../../dubp/documents" } diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/block.rs b/lib/modules/blockchain/blockchain-dal/src/entities/block.rs index f360d1cd..059260fe 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/block.rs @@ -14,9 +14,9 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; +use dubp_common_doc::traits::Document; +use dubp_common_doc::BlockNumber; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait}; -use dubp_documents::Document; -use dubp_documents::{BlockNumber, Blockstamp}; use durs_wot::NodeId; use std::collections::HashMap; diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs index 4a0f6303..69abeffe 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs @@ -15,7 +15,7 @@ //! Describe fork tree -use dubp_documents::{BlockHash, BlockNumber, Blockstamp}; +use dubp_common_doc::{BlockHash, BlockNumber, Blockstamp}; use serde::de::{self, Deserialize, Deserializer, Visitor}; use serde::{Serialize, Serializer}; use std::collections::{HashMap, HashSet}; diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs b/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs index f52baa07..6bc7d8f6 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/identity.rs @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_documents::documents::identity::IdentityDocumentV10; -use dubp_documents::{BlockNumber, Blockstamp}; use durs_wot::NodeId; #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs b/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs index c9401e0b..defd3a43 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/sources.rs @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use dubp_common_doc::BlockNumber; use dubp_documents::documents::transaction::*; -use dubp_documents::BlockNumber; use dup_crypto::hashs::Hash; use dup_crypto::keys::PubKey; use durs_common_tools::fatal_error; diff --git a/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs b/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs index 8f60a2a4..ff4bee88 100644 --- a/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs +++ b/lib/modules/blockchain/blockchain-dal/src/filters/mod.rs @@ -15,7 +15,7 @@ pub mod identities; -use dubp_documents::BlockNumber; +use dubp_common_doc::BlockNumber; #[derive(Debug, Copy, Clone, PartialEq, Eq)] /// Pagination parameters diff --git a/lib/modules/blockchain/blockchain-dal/src/lib.rs b/lib/modules/blockchain/blockchain-dal/src/lib.rs index 7fa796ea..5057cf08 100644 --- a/lib/modules/blockchain/blockchain-dal/src/lib.rs +++ b/lib/modules/blockchain/blockchain-dal/src/lib.rs @@ -51,8 +51,8 @@ pub mod tools; /// Contains all write databases functions pub mod writers; +use dubp_common_doc::{BlockNumber, Blockstamp, PreviousBlockstamp}; use dubp_documents::documents::transaction::*; -use dubp_documents::{BlockNumber, Blockstamp, PreviousBlockstamp}; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_common_tools::fatal_error; diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/block.rs b/lib/modules/blockchain/blockchain-dal/src/readers/block.rs index 48bf4fbd..670467af 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/block.rs @@ -14,9 +14,9 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; +use dubp_common_doc::traits::Document; +use dubp_common_doc::{BlockHash, BlockNumber, Blockstamp}; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait}; -use dubp_documents::Document; -use dubp_documents::{BlockHash, BlockNumber, Blockstamp}; use dup_crypto::keys::*; use std::collections::HashMap; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs index ea8eaca2..f745d953 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::{BinDB, CertsExpirV10Datas, DALError}; -use dubp_documents::BlockNumber; +use dubp_common_doc::BlockNumber; use durs_wot::NodeId; use std::collections::HashMap; diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs b/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs index f061dab2..bf047f0d 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/currency_params.rs @@ -14,11 +14,11 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; +use dubp_common_doc::traits::Document; use dubp_currency_params::db::write_currency_params; use dubp_currency_params::genesis_block_params::GenesisBlockParams; use dubp_currency_params::CurrencyParameters; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait}; -use dubp_documents::Document; use unwrap::unwrap; /// Get and write currency params diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs index 8e8ad800..a61a9a2a 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; -use dubp_documents::Blockstamp; +use dubp_common_doc::Blockstamp; /// Get stackables blocks pub fn get_stackables_blocks( diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs index 485e37b6..04db9db5 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs @@ -16,7 +16,8 @@ use crate::entities::identity::DALIdentity; use crate::filters::identities::IdentitiesFilter; use crate::{BinDB, DALError, IdentitiesV10Datas}; -use dubp_documents::{BlockNumber, Document}; +use dubp_common_doc::traits::Document; +use dubp_common_doc::BlockNumber; use dup_crypto::keys::*; use durs_wot::NodeId; use std::collections::HashMap; @@ -120,7 +121,7 @@ mod test { use crate::entities::identity::*; use crate::filters::PagingFilter; use crate::*; - use dubp_documents::Blockstamp; + use dubp_common_doc::Blockstamp; use dup_crypto_tests_tools::mocks::pubkey; use durs_common_tests_tools::collections::slice_same_elems; diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/block.rs b/lib/modules/blockchain/blockchain-dal/src/writers/block.rs index 0abdab82..c2b9640c 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/block.rs @@ -16,8 +16,8 @@ use crate::entities::block::DALBlock; use crate::*; use crate::{BinDB, DALError, LocalBlockchainV10Datas}; +use dubp_common_doc::traits::Document; use dubp_documents::documents::block::BlockDocumentTrait; -use dubp_documents::Document; use unwrap::unwrap; /// Insert new head Block in databases diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs index a42cecb8..92a6790d 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs @@ -14,9 +14,9 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::{BinDB, CertsExpirV10Datas, DALError, IdentitiesV10Datas}; +use dubp_common_doc::BlockNumber; use dubp_currency_params::CurrencyParameters; use dubp_documents::documents::certification::CompactCertificationDocumentV10; -use dubp_documents::BlockNumber; use dup_crypto::keys::*; use durs_wot::NodeId; diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs b/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs index d49aa41b..96c6b987 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs @@ -15,8 +15,8 @@ use crate::entities::sources::SourceAmount; use crate::*; +use dubp_common_doc::BlockNumber; use dubp_documents::documents::transaction::*; -use dubp_documents::BlockNumber; use dup_crypto::keys::PubKey; use std::collections::{HashMap, HashSet}; diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs index d26b3810..7fc62d5d 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs @@ -15,7 +15,7 @@ use crate::entities::fork_tree::ForkTree; use crate::*; -use dubp_documents::*; +use dubp_common_doc::BlockHash; /// Insert new head Block in fork tree, /// return vector of removed blockstamps diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs index 8db1a90f..bc3b5c10 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs @@ -15,10 +15,10 @@ use crate::entities::identity::{DALIdentity, DALIdentityState}; use crate::{BinDB, DALError, IdentitiesV10Datas, MsExpirV10Datas}; +use dubp_common_doc::traits::Document; +use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_currency_params::CurrencyParameters; use dubp_documents::documents::identity::IdentityDocumentV10; -use dubp_documents::Document; -use dubp_documents::{BlockNumber, Blockstamp}; use dup_crypto::keys::PubKey; use durs_common_tools::fatal_error; use durs_wot::NodeId; diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs index 1fcb68f9..ca6bf3d2 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs @@ -17,11 +17,11 @@ use crate::entities::block::DALBlock; use crate::entities::sources::SourceAmount; use crate::writers::transaction::DALTxV10; use crate::*; +use dubp_common_doc::Blockstamp; use dubp_currency_params::CurrencyParameters; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait}; use dubp_documents::documents::certification::CompactCertificationDocumentV10; use dubp_documents::documents::identity::IdentityDocumentV10; -use dubp_documents::Blockstamp; use dup_crypto::keys::PubKey; use durs_wot::NodeId; use std::ops::Deref; diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs index ce5728fb..12e5d1e0 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs @@ -425,7 +425,7 @@ pub fn apply_and_write_tx( #[cfg(test)] mod tests { use super::*; - use dubp_documents::{Document, DocumentBuilder}; + use dubp_common_doc::traits::{Document, DocumentBuilder}; use std::str::FromStr; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain/Cargo.toml b/lib/modules/blockchain/blockchain/Cargo.toml index 5c2cad60..4dd46f12 100644 --- a/lib/modules/blockchain/blockchain/Cargo.toml +++ b/lib/modules/blockchain/blockchain/Cargo.toml @@ -12,9 +12,10 @@ path = "src/lib.rs" [dependencies] dirs = "1.0.2" durs-conf = { path = "../../../core/conf" } -dup-crypto = { path = "../../../crypto" } +dubp-common-doc = { path = "../../../dubp/common-doc"} #, version = "0.1.0" } dubp-currency-params = { path = "../../../dubp/currency-params" } durs-blockchain-dal = { path = "../blockchain-dal" } +dup-crypto = { path = "../../../crypto" } dubp-documents= { path = "../../../dubp/documents" } durs-common-tools = { path = "../../../tools/common-tools" } durs-network-documents = { path = "../../../dunp/network-documents" } diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index ebe8c92b..24c8cc07 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -14,6 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; +use dubp_common_doc::BlockNumber; use dubp_documents::documents::block::BlockDocumentTrait; use dubp_documents::documents::transaction::*; use dup_crypto::keys::*; @@ -290,7 +291,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DBExWotQuery) { .read(|db| { let mut expire_dates = Vec::new(); for (block_id, nodes_ids) in db { - let created_ms_time = blocks_times[&block_id]; + let created_ms_time = blocks_times[&block_id.0]; if created_ms_time > min_created_ms_time { for node_id in nodes_ids { expire_dates.push(( diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index da929784..797f03b2 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -15,9 +15,10 @@ //! Sub-module that applies the content of a block to the indexes of the local blockchain. +use dubp_common_doc::traits::Document; +use dubp_common_doc::BlockNumber; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait, BlockDocumentV10}; use dubp_documents::documents::transaction::{TxAmount, TxBase}; -use dubp_documents::{BlockNumber, Document}; use dup_crypto::keys::*; use durs_blockchain_dal::entities::block::DALBlock; use durs_blockchain_dal::entities::sources::SourceAmount; diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs index 874deecf..e93eb882 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs @@ -18,8 +18,9 @@ pub mod hashs; use crate::dubp::BlockError; +use dubp_common_doc::traits::Document; +use dubp_common_doc::BlockNumber; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait}; -use dubp_documents::*; use dup_crypto::keys::PubKey; use durs_blockchain_dal::*; use durs_wot::*; diff --git a/lib/modules/blockchain/blockchain/src/dubp/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/mod.rs index b0d07500..974daff5 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/mod.rs @@ -21,9 +21,9 @@ pub mod check; use crate::*; use apply::*; use check::*; +use dubp_common_doc::traits::Document; +use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_documents::documents::block::{BlockDocumentTrait, VerifyBlockHashError}; -use dubp_documents::Blockstamp; -use dubp_documents::Document; use durs_blockchain_dal::entities::block::DALBlock; use durs_blockchain_dal::*; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain/src/dunp/queries.rs b/lib/modules/blockchain/blockchain/src/dunp/queries.rs index a4179395..eb7e905c 100644 --- a/lib/modules/blockchain/blockchain/src/dunp/queries.rs +++ b/lib/modules/blockchain/blockchain/src/dunp/queries.rs @@ -16,6 +16,7 @@ //! Sub-module that sends requests to the inter-node network layer. use crate::*; +use dubp_common_doc::BlockNumber; use durs_message::*; use durs_module::ModuleReqId; use durs_network::requests::OldNetworkRequest; diff --git a/lib/modules/blockchain/blockchain/src/dunp/receiver.rs b/lib/modules/blockchain/blockchain/src/dunp/receiver.rs index 44f5af92..d304eb13 100644 --- a/lib/modules/blockchain/blockchain/src/dunp/receiver.rs +++ b/lib/modules/blockchain/blockchain/src/dunp/receiver.rs @@ -17,6 +17,7 @@ //! (received by the intermediaries of events transmitted by the network module). use crate::*; +use dubp_common_doc::traits::Document; use dubp_documents::documents::UserDocumentDUBP; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs index bb422240..8a8db8e3 100644 --- a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs +++ b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use dubp_common_doc::Blockstamp; use dubp_documents::documents::block::BlockDocumentTrait; -use dubp_documents::Blockstamp; use durs_blockchain_dal::entities::fork_tree::ForkTree; use durs_blockchain_dal::{DALError, ForksDBs}; use std::collections::HashSet; @@ -100,8 +100,8 @@ mod tests { use super::*; use crate::*; + use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_documents::documents::block::BlockDocument; - use dubp_documents::BlockHash; use durs_blockchain_dal::entities::block::DALBlock; #[test] diff --git a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs index e22bc118..47924b69 100644 --- a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs +++ b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs @@ -15,10 +15,11 @@ //! Sub-module that applies a block backwards. +use dubp_common_doc::traits::Document; +use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_documents::documents::block::v10::TxDocOrTxHash; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait, BlockDocumentV10}; use dubp_documents::documents::transaction::{TxAmount, TxBase}; -use dubp_documents::{BlockNumber, Blockstamp, Document}; use dup_crypto::keys::*; use durs_blockchain_dal::entities::block::DALBlock; use durs_blockchain_dal::entities::sources::SourceAmount; diff --git a/lib/modules/blockchain/blockchain/src/fork/rollback.rs b/lib/modules/blockchain/blockchain/src/fork/rollback.rs index 351c7474..a4bbf763 100644 --- a/lib/modules/blockchain/blockchain/src/fork/rollback.rs +++ b/lib/modules/blockchain/blockchain/src/fork/rollback.rs @@ -15,7 +15,8 @@ use crate::fork::revert_block::ValidBlockRevertReqs; use crate::*; -use dubp_documents::Blockstamp; +use dubp_common_doc::traits::Document; +use dubp_common_doc::Blockstamp; use durs_common_tools::fatal_error; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs index f165eb55..1628a282 100644 --- a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs +++ b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs @@ -16,6 +16,7 @@ //! Sub-module that finds and applies the orphaned blocks that have become stackable on the local blockchain. use crate::*; +use dubp_common_doc::traits::Document; use dubp_documents::documents::block::BlockDocumentTrait; use unwrap::unwrap; diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs index 34d6c67a..ef8c0802 100644 --- a/lib/modules/blockchain/blockchain/src/lib.rs +++ b/lib/modules/blockchain/blockchain/src/lib.rs @@ -54,9 +54,10 @@ pub use crate::dbex::{DBExQuery, DBExTxQuery, DBExWotQuery}; use crate::dubp::apply::ValidBlockApplyReqs; use crate::dubp::*; use crate::fork::*; +use dubp_common_doc::traits::Document; +use dubp_common_doc::Blockstamp; use dubp_currency_params::{CurrencyName, CurrencyParameters}; use dubp_documents::documents::block::BlockDocument; -use dubp_documents::*; use dup_crypto::keys::*; use durs_blockchain_dal::*; use durs_common_tools::fatal_error; diff --git a/lib/modules/blockchain/blockchain/src/requests/sent.rs b/lib/modules/blockchain/blockchain/src/requests/sent.rs index 4ed53650..9be294d2 100644 --- a/lib/modules/blockchain/blockchain/src/requests/sent.rs +++ b/lib/modules/blockchain/blockchain/src/requests/sent.rs @@ -16,6 +16,7 @@ //! Sub-module managing the inter-modules requests sent. use crate::*; +use dubp_common_doc::{BlockNumber, Blockstamp}; use durs_network::requests::OldNetworkRequest; pub fn request_network_consensus(bc: &mut BlockchainModule) { diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs index 227fce99..8529764f 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs @@ -21,9 +21,10 @@ use crate::dubp; use crate::dubp::apply::apply_valid_block; use crate::dubp::apply::ValidBlockApplyReqs; use crate::sync::SyncJobsMess; +use dubp_common_doc::traits::Document; +use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_currency_params::{CurrencyName, CurrencyParameters}; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait}; -use dubp_documents::{BlockNumber, Blockstamp, Document}; use dup_crypto::keys::PubKey; use durs_blockchain_dal::writers::requests::WotsDBsWriteQuery; use durs_blockchain_dal::{BinDB, CertsExpirV10Datas, WotsV10DBs}; @@ -136,7 +137,7 @@ impl BlockApplicator { self.certs_db .write(|db| { let mut created_certs = - db.get(&created_block_id).cloned().unwrap_or_default(); + db.get(&created_block_id.0).cloned().unwrap_or_default(); created_certs.insert((*source, *target)); db.insert(*created_block_id, created_certs); }) diff --git a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs index 69d4b661..e10df647 100644 --- a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs +++ b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs @@ -14,8 +14,9 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::sync::*; +use dubp_common_doc::traits::Document; +use dubp_common_doc::Blockstamp; use dubp_documents::parsers::blocks::parse_json_block; -use dubp_documents::Blockstamp; use durs_common_tools::fatal_error; use failure::Error; use rayon::prelude::*; diff --git a/lib/modules/blockchain/blockchain/src/sync/mod.rs b/lib/modules/blockchain/blockchain/src/sync/mod.rs index 24473a87..7fe6c503 100644 --- a/lib/modules/blockchain/blockchain/src/sync/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/mod.rs @@ -18,9 +18,10 @@ mod download; use crate::*; use apply::BlockApplicator; +use dubp_common_doc::Blockstamp; +use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_currency_params::{CurrencyName, CurrencyParameters}; use dubp_documents::documents::block::BlockDocumentTrait; -use dubp_documents::{BlockHash, BlockNumber}; use dup_crypto::keys::*; use durs_blockchain_dal::writers::requests::*; use durs_blockchain_dal::{open_memory_db, CertsExpirV10Datas}; diff --git a/lib/modules/ws2p-v1-legacy/Cargo.toml b/lib/modules/ws2p-v1-legacy/Cargo.toml index e749c815..e2d923dc 100644 --- a/lib/modules/ws2p-v1-legacy/Cargo.toml +++ b/lib/modules/ws2p-v1-legacy/Cargo.toml @@ -12,12 +12,13 @@ path = "src/lib.rs" [dependencies] bincode = "1.0.1" byteorder = "1.2.3" +dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" } +dubp-currency-params = { path = "../../dubp/currency-params" } dubp-documents= { path = "../../dubp/documents" } +dup-crypto = { path = "../../crypto" } durs-conf = { path = "../../core/conf" } durs-module = { path = "../../core/module" } durs-network = { path = "../../core/network" } -dup-crypto = { path = "../../crypto" } -dubp-currency-params = { path = "../../dubp/currency-params" } durs-network-documents = { path = "../../dunp/network-documents" } durs-message = { path = "../../core/message" } durs-common-tools = { path = "../../tools/common-tools" } diff --git a/lib/modules/ws2p-v1-legacy/src/events/received.rs b/lib/modules/ws2p-v1-legacy/src/events/received.rs index 6ecdfae4..377f1150 100644 --- a/lib/modules/ws2p-v1-legacy/src/events/received.rs +++ b/lib/modules/ws2p-v1-legacy/src/events/received.rs @@ -17,7 +17,7 @@ use crate::serializers::IntoWS2Pv1Json; use crate::*; -use dubp_documents::Document; +use dubp_common_doc::traits::Document; use durs_message::events::DursEvent; use durs_module::*; use std::ops::Deref; diff --git a/lib/modules/ws2p-v1-legacy/src/heads.rs b/lib/modules/ws2p-v1-legacy/src/heads.rs index 219977be..40b17925 100644 --- a/lib/modules/ws2p-v1-legacy/src/heads.rs +++ b/lib/modules/ws2p-v1-legacy/src/heads.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::*; -use dubp_documents::Blockstamp; +use dubp_common_doc::Blockstamp; use durs_network_documents::network_head_v2::*; pub fn generate_my_head( diff --git a/lib/modules/ws2p-v1-legacy/src/lib.rs b/lib/modules/ws2p-v1-legacy/src/lib.rs index b57126be..045561e4 100644 --- a/lib/modules/ws2p-v1-legacy/src/lib.rs +++ b/lib/modules/ws2p-v1-legacy/src/lib.rs @@ -58,10 +58,10 @@ use crate::ws_connections::messages::WS2Pv1Msg; use crate::ws_connections::requests::{WS2Pv1ReqBody, WS2Pv1ReqFullId, WS2Pv1ReqId, WS2Pv1Request}; use crate::ws_connections::states::WS2PConnectionState; use crate::ws_connections::*; +use dubp_common_doc::Blockstamp; use dubp_currency_params::CurrencyName; use dubp_documents::documents::block::BlockDocument; use dubp_documents::documents::UserDocumentDUBP; -use dubp_documents::Blockstamp; use dup_crypto::keys::*; use durs_common_tools::fatal_error; use durs_common_tools::traits::merge::Merge; @@ -887,9 +887,9 @@ mod tests { use super::*; use crate::ws_connections::requests::sent::network_request_to_json; use crate::ws_connections::requests::*; + use dubp_common_doc::BlockNumber; use dubp_documents::documents::block::{BlockDocument, BlockDocumentTrait}; use dubp_documents::parsers::blocks::parse_json_block_from_serde_value; - use dubp_documents::BlockNumber; #[test] fn test_parse_json_block() { diff --git a/lib/modules/ws2p-v1-legacy/src/requests/received.rs b/lib/modules/ws2p-v1-legacy/src/requests/received.rs index 69adb631..bfc4e98a 100644 --- a/lib/modules/ws2p-v1-legacy/src/requests/received.rs +++ b/lib/modules/ws2p-v1-legacy/src/requests/received.rs @@ -19,7 +19,7 @@ use crate::ws2p_db::DbEndpoint; use crate::ws_connections::requests::{WS2Pv1ReqBody, WS2Pv1ReqId, WS2Pv1Request}; use crate::ws_connections::states::WS2PConnectionState; use crate::WS2Pv1Module; -use dubp_documents::BlockNumber; +use dubp_common_doc::BlockNumber; use durs_message::requests::DursReqContent; use durs_network::requests::OldNetworkRequest; diff --git a/lib/modules/ws2p-v1-legacy/src/ws_connections/requests/mod.rs b/lib/modules/ws2p-v1-legacy/src/ws_connections/requests/mod.rs index 200a8ee3..56a9e548 100644 --- a/lib/modules/ws2p-v1-legacy/src/ws_connections/requests/mod.rs +++ b/lib/modules/ws2p-v1-legacy/src/ws_connections/requests/mod.rs @@ -18,7 +18,7 @@ pub mod received; pub mod sent; -use dubp_documents::BlockNumber; +use dubp_common_doc::BlockNumber; use durs_network_documents::NodeFullId; use serde::Serialize; use std::convert::TryFrom; diff --git a/lib/modules/ws2p-v1-legacy/src/ws_connections/responses/mod.rs b/lib/modules/ws2p-v1-legacy/src/ws_connections/responses/mod.rs index 5acc620e..a44eea52 100644 --- a/lib/modules/ws2p-v1-legacy/src/ws_connections/responses/mod.rs +++ b/lib/modules/ws2p-v1-legacy/src/ws_connections/responses/mod.rs @@ -20,8 +20,8 @@ pub mod sent; use crate::serializers::IntoWS2Pv1Json; use crate::ws_connections::requests::WS2Pv1ReqId; +use dubp_common_doc::traits::ToStringObject; use dubp_documents::documents::block::BlockDocument; -use dubp_documents::ToStringObject; use dup_crypto::keys::PubKey; /// WS2Pv1 request response diff --git a/lib/modules/ws2p/ws2p-messages/Cargo.toml b/lib/modules/ws2p/ws2p-messages/Cargo.toml index fea57971..ea5a66f0 100644 --- a/lib/modules/ws2p/ws2p-messages/Cargo.toml +++ b/lib/modules/ws2p/ws2p-messages/Cargo.toml @@ -12,11 +12,12 @@ path = "lib.rs" [dependencies] bincode = "1.0.*" byteorder = "1.2.3" -dup-crypto = { path = "../../../crypto" } +dubp-common-doc = { path = "../../../dubp/common-doc"} #, version = "0.1.0" } dubp-currency-params = { path = "../../../dubp/currency-params" } dubp-documents= { path = "../../../dubp/documents" } durs-network-documents = { path = "../../../dunp/network-documents" } durs-common-tools = { path = "../../../tools/common-tools" } +dup-crypto = { path = "../../../crypto" } failure = "0.1.5" log = "0.4.*" serde = "1.0.*" diff --git a/lib/modules/ws2p/ws2p-messages/lib.rs b/lib/modules/ws2p/ws2p-messages/lib.rs index 1441f460..349b1b3a 100644 --- a/lib/modules/ws2p/ws2p-messages/lib.rs +++ b/lib/modules/ws2p/ws2p-messages/lib.rs @@ -166,9 +166,9 @@ mod tests { use crate::v2::WS2Pv2Message; use bincode; use bincode::{deserialize, serialize}; + use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_currency_params::CurrencyName; use dubp_documents::documents::certification::*; - use dubp_documents::{BlockNumber, Blockstamp}; use dup_crypto::keys::bin_signable::BinSignable; use dup_crypto::keys::*; use durs_network_documents::network_endpoint::*; diff --git a/lib/modules/ws2p/ws2p-messages/v2/connect.rs b/lib/modules/ws2p/ws2p-messages/v2/connect.rs index a9d28c54..4f45a524 100644 --- a/lib/modules/ws2p/ws2p-messages/v2/connect.rs +++ b/lib/modules/ws2p/ws2p-messages/v2/connect.rs @@ -15,7 +15,7 @@ //use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use super::api_features::WS2PFeatures; -use dubp_documents::Blockstamp; +use dubp_common_doc::blockstamp::Blockstamp; use dup_crypto::hashs::Hash; use durs_network_documents::network_peer::PeerCardV11; @@ -163,7 +163,7 @@ mod tests { use super::super::*; use super::*; use crate::tests::*; - use dubp_documents::Blockstamp; + use dubp_common_doc::Blockstamp; use dup_crypto::keys::text_signable::TextSignable; #[test] diff --git a/lib/modules/ws2p/ws2p-messages/v2/ok.rs b/lib/modules/ws2p/ws2p-messages/v2/ok.rs index 358c59e7..5701efc4 100644 --- a/lib/modules/ws2p/ws2p-messages/v2/ok.rs +++ b/lib/modules/ws2p/ws2p-messages/v2/ok.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use dubp_documents::Blockstamp; +use dubp_common_doc::blockstamp::Blockstamp; use dup_crypto::hashs::Hash; use std::num::NonZeroU16; @@ -49,7 +49,7 @@ mod tests { use super::super::*; use super::*; use crate::tests::*; - use dubp_documents::Blockstamp; + use dubp_common_doc::Blockstamp; use std::num::NonZeroU16; #[test] diff --git a/lib/modules/ws2p/ws2p-messages/v2/req_responses.rs b/lib/modules/ws2p/ws2p-messages/v2/req_responses.rs index bbb1d4f2..f734f8fc 100644 --- a/lib/modules/ws2p/ws2p-messages/v2/req_responses.rs +++ b/lib/modules/ws2p/ws2p-messages/v2/req_responses.rs @@ -13,11 +13,11 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use dubp_common_doc::blockstamp::Blockstamp; use dubp_documents::documents::block::BlockDocument; use dubp_documents::documents::certification::CompactCertificationDocumentV10; use dubp_documents::documents::identity::v10::CompactIdentityDocumentV10; use dubp_documents::documents::membership::v10::CompactPoolMembershipDoc; -use dubp_documents::Blockstamp; use dup_crypto::hashs::Hash; use std::str; @@ -63,7 +63,7 @@ mod tests { use super::super::*; use super::*; use crate::tests::*; - use dubp_documents::Blockstamp; + use dubp_common_doc::Blockstamp; #[test] fn test_ws2p_message_req_res_none() { diff --git a/lib/modules/ws2p/ws2p-messages/v2/requests.rs b/lib/modules/ws2p/ws2p-messages/v2/requests.rs index 136a9050..4d7cb689 100644 --- a/lib/modules/ws2p/ws2p-messages/v2/requests.rs +++ b/lib/modules/ws2p/ws2p-messages/v2/requests.rs @@ -13,7 +13,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use dubp_documents::{BlockNumber, Blockstamp}; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::BlockNumber; /// WS2Pv2Request #[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)] @@ -75,7 +76,7 @@ mod tests { use super::super::*; use super::*; use crate::tests::*; - use dubp_documents::Blockstamp; + use dubp_common_doc::Blockstamp; #[test] fn test_ws2p_message_request() { diff --git a/lib/modules/ws2p/ws2p-protocol/Cargo.toml b/lib/modules/ws2p/ws2p-protocol/Cargo.toml index 50df6ef8..0c44f5fb 100644 --- a/lib/modules/ws2p/ws2p-protocol/Cargo.toml +++ b/lib/modules/ws2p/ws2p-protocol/Cargo.toml @@ -10,10 +10,11 @@ edition = "2018" path = "src/lib.rs" [dependencies] -dup-crypto = { path = "../../../crypto" } +dubp-common-doc = { path = "../../../dubp/common-doc"} #, version = "0.1.0" } dubp-currency-params = { path = "../../../dubp/currency-params" } -durs-common-tools = { path = "../../../tools/common-tools" } dubp-documents= { path = "../../../dubp/documents" } +durs-common-tools = { path = "../../../tools/common-tools" } +dup-crypto = { path = "../../../crypto" } durs-module = { path = "../../../core/module" } durs-network-documents = { path = "../../../dunp/network-documents" } durs-ws2p-messages = { path = "../ws2p-messages" } diff --git a/lib/modules/ws2p/ws2p-protocol/src/controller/meta_datas.rs b/lib/modules/ws2p/ws2p-protocol/src/controller/meta_datas.rs index 25166ab3..1ba32077 100644 --- a/lib/modules/ws2p/ws2p-protocol/src/controller/meta_datas.rs +++ b/lib/modules/ws2p/ws2p-protocol/src/controller/meta_datas.rs @@ -17,8 +17,8 @@ use crate::connection_state::WS2PConnectionState; use crate::MySelfWs2pNode; +use dubp_common_doc::Blockstamp; use dubp_currency_params::CurrencyName; -use dubp_documents::Blockstamp; use dup_crypto::hashs::Hash; use durs_network_documents::network_peer::PeerCardV11; use durs_network_documents::NodeFullId; diff --git a/lib/modules/ws2p/ws2p/Cargo.toml b/lib/modules/ws2p/ws2p/Cargo.toml index b7fad259..00ac8968 100644 --- a/lib/modules/ws2p/ws2p/Cargo.toml +++ b/lib/modules/ws2p/ws2p/Cargo.toml @@ -11,12 +11,13 @@ path = "src/lib.rs" [dependencies] bincode = "1.0.*" -durs-conf= { path = "../../../core/conf" } -dup-crypto = { path = "../../../crypto" } +dubp-common-doc = { path = "../../../dubp/common-doc"} #, version = "0.1.0" } dubp-currency-params = { path = "../../../dubp/currency-params" } dubp-documents= { path = "../../../dubp/documents" } durs-network-documents = { path = "../../../dunp/network-documents" } durs-common-tools = { path = "../../../tools/common-tools" } +dup-crypto = { path = "../../../crypto" } +durs-conf= { path = "../../../core/conf" } durs-ws2p-messages = { path = "../ws2p-messages" } durs-ws2p-protocol = { path = "../ws2p-protocol" } durs-message= { path = "../../../core/message" } diff --git a/lib/modules/ws2p/ws2p/src/controllers/mod.rs b/lib/modules/ws2p/ws2p/src/controllers/mod.rs index a23bc927..45483e40 100644 --- a/lib/modules/ws2p/ws2p/src/controllers/mod.rs +++ b/lib/modules/ws2p/ws2p/src/controllers/mod.rs @@ -16,7 +16,7 @@ //! WS2P connections controllers. //use constants::*; -use dubp_documents::Blockstamp; +use dubp_common_doc::Blockstamp; use dup_crypto::hashs::Hash; use ws::Sender; //use dup_crypto::keys::*; diff --git a/lib/modules/ws2p/ws2p/src/generate_peer.rs b/lib/modules/ws2p/ws2p/src/generate_peer.rs index 20de0562..d013268e 100644 --- a/lib/modules/ws2p/ws2p/src/generate_peer.rs +++ b/lib/modules/ws2p/ws2p/src/generate_peer.rs @@ -16,8 +16,8 @@ //! Generate self peer card use bincode; +use dubp_common_doc::BlockNumber; use dubp_currency_params::CurrencyName; -use dubp_documents::BlockNumber; use dup_crypto::keys::text_signable::TextSignable; use dup_crypto::keys::{KeyPair, KeyPairEnum, SignError}; use durs_common_tools::fatal_error; diff --git a/lib/modules/ws2p/ws2p/tests/connection_negociation.rs b/lib/modules/ws2p/ws2p/tests/connection_negociation.rs index 681a0d4a..b4994640 100644 --- a/lib/modules/ws2p/ws2p/tests/connection_negociation.rs +++ b/lib/modules/ws2p/ws2p/tests/connection_negociation.rs @@ -16,7 +16,7 @@ use dubp_currency_params::CurrencyName; use dup_crypto::keys::KeyPair; use dup_crypto::keys::*; -//use durs_common_tests_tools::logger::init_logger_stdout; +use durs_common_tests_tools::logger::init_logger_stdout; use durs_message::DursMsg; use durs_network_documents::network_endpoint::*; use durs_network_documents::*; @@ -150,7 +150,7 @@ fn test_connection_negociation_denial() { #[test] #[cfg(unix)] fn test_connection_negociation_success() { - //init_logger_stdout(); + init_logger_stdout(); // ===== initialization ===== // client and server are initialized and launched in separate threads diff --git a/lib/tests-tools/documents-tests-tools/Cargo.toml b/lib/tests-tools/documents-tests-tools/Cargo.toml index fb2c3cee..3e4251bb 100644 --- a/lib/tests-tools/documents-tests-tools/Cargo.toml +++ b/lib/tests-tools/documents-tests-tools/Cargo.toml @@ -13,9 +13,10 @@ edition = "2018" path = "src/lib.rs" [dependencies] -dup-crypto = { path = "../../crypto" } +dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" } dubp-currency-params = { path = "../../dubp/currency-params" } dubp-documents = { path = "../../dubp/documents" } +dup-crypto = { path = "../../crypto" } dup-crypto-tests-tools = { path = "../crypto-tests-tools" } [dev-dependencies] diff --git a/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs b/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs index 49f40a23..cd3c19fe 100644 --- a/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs +++ b/lib/tests-tools/documents-tests-tools/src/mocks/identity.rs @@ -15,9 +15,11 @@ //! Mocks for projects use dubp-documents +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::traits::DocumentBuilder; +use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_documents::documents::identity::v10::IdentityDocumentV10Builder; use dubp_documents::documents::identity::*; -use dubp_documents::*; use dup_crypto::hashs::Hash; use dup_crypto::keys::PubKey; diff --git a/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs b/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs index 0856ef94..ec6f1915 100644 --- a/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs +++ b/lib/tests-tools/documents-tests-tools/src/mocks/mod.rs @@ -17,9 +17,10 @@ pub mod identity; +use dubp_common_doc::blockstamp::Blockstamp; +use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_currency_params::CurrencyName; use dubp_documents::documents::block::{BlockDocument, BlockDocumentV10}; -use dubp_documents::*; use dup_crypto::hashs::Hash; /// Generate n mock blockstamps -- GitLab