1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: AGPL-3.0-or-later
//! Mock p2panda client.
//!
//! This client mocks functionality which would be implemented in a real world p2panda client. It
//! does so in a simplistic manner and should only be used in a testing or demo environment.
//!
//! ## Example
//!
//! ```
//! # extern crate p2panda_rs;
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use std::convert::TryFrom;
//!
//! use p2panda_rs::operation::AsOperation;
//! use p2panda_rs::operation::{OperationEncoded, OperationValue};
//! use p2panda_rs::test_utils::constants::TEST_SCHEMA_ID;
//! use p2panda_rs::test_utils::mocks::{send_to_node, Client, Node};
//! use p2panda_rs::test_utils::fixtures::{
//! create_operation, schema, random_key_pair, operation_fields, update_operation,
//! };
//!
//! // Instantiate a new mock node
//! let mut node = Node::new();
//!
//! // Instantiate one client named "panda"
//! let panda = Client::new("panda".to_string(), random_key_pair());
//!
//! // Create a new operation to publish
//! let operation = create_operation(
//! &[(
//! "message",
//! OperationValue::Text("Ohh, my first message!".to_string()),
//! )],
//! );
//!
//! // Retrieve the next entry args from the node
//! let entry_args = node.get_next_entry_args(&panda.author(), None, None)?;
//!
//! // Sign and encode an entry
//! let entry_encoded = panda.signed_encoded_entry(operation.to_owned(), entry_args);
//! let operation_encoded = OperationEncoded::try_from(&operation)?;
//!
//! node.publish_entry(&entry_encoded, &operation_encoded)?;
//!
//! # Ok(())
//! # }
//! ```
use crate;
use crate;
use crateOperation;
use crateNextEntryArgs;
/// A helper struct which represents a client in the pandaverse.
///
/// It is a thin wrapper around a [`KeyPair`], it is used when creating, signing and publishing
/// entries.