Skip to content

Commit ccb6226

Browse files
committed
rustfmt
1 parent 9cf02f8 commit ccb6226

File tree

279 files changed

+3621
-11570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+3621
-11570
lines changed

accounts/src/accounts.rs

Lines changed: 39 additions & 188 deletions
Large diffs are not rendered by default.

accounts/src/tree/mod.rs

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,12 @@ impl<A: AccountsTreeLeave> AccountsTree<A> {
2121

2222
pub fn new(env: Environment) -> Self {
2323
let db = env.open_database(Self::DB_NAME.to_string());
24-
let tree = AccountsTree {
25-
db,
26-
_account: PhantomData,
27-
};
24+
let tree = AccountsTree { db, _account: PhantomData };
2825

2926
let mut txn = WriteTransaction::new(&env);
3027
if tree.get_root(&txn).is_none() {
3128
let root = AddressNibbles::empty();
32-
txn.put_reserve(
33-
&tree.db,
34-
&root,
35-
&AccountsTreeNode::<A>::new_branch(root.clone(), NO_CHILDREN),
36-
);
29+
txn.put_reserve(&tree.db, &root, &AccountsTreeNode::<A>::new_branch(root.clone(), NO_CHILDREN));
3730
}
3831
txn.commit();
3932
tree
@@ -69,12 +62,11 @@ impl<A: AccountsTreeLeave> AccountsTree<A> {
6962
txn.put_reserve(&self.db, new_child.prefix(), &new_child);
7063

7164
// Insert the new parent node.
72-
let new_parent =
73-
AccountsTreeNode::<A>::new_branch(node_prefix.common_prefix(&prefix), NO_CHILDREN)
74-
.with_child(&node_prefix, Blake2bHash::default())
75-
.unwrap()
76-
.with_child(new_child.prefix(), Blake2bHash::default())
77-
.unwrap();
65+
let new_parent = AccountsTreeNode::<A>::new_branch(node_prefix.common_prefix(&prefix), NO_CHILDREN)
66+
.with_child(&node_prefix, Blake2bHash::default())
67+
.unwrap()
68+
.with_child(new_child.prefix(), Blake2bHash::default())
69+
.unwrap();
7870
txn.put_reserve(&self.db, new_parent.prefix(), &new_parent);
7971

8072
return self.update_keys_batch(txn, new_parent.prefix().clone(), root_path);
@@ -112,20 +104,13 @@ impl<A: AccountsTreeLeave> AccountsTree<A> {
112104
// If no matching child exists, add a new child account node to the current node.
113105
let child = AccountsTreeNode::<A>::new_terminal(prefix, account);
114106
txn.put_reserve(&self.db, child.prefix(), &child);
115-
let node = node
116-
.with_child(child.prefix(), Blake2bHash::default())
117-
.unwrap();
107+
let node = node.with_child(child.prefix(), Blake2bHash::default()).unwrap();
118108
txn.put_reserve(&self.db, node.prefix(), &node);
119109

120110
self.update_keys_batch(txn, node_prefix, root_path)
121111
}
122112

123-
fn prune_batch(
124-
&self,
125-
txn: &mut WriteTransaction,
126-
prefix: AddressNibbles,
127-
mut root_path: Vec<AccountsTreeNode<A>>,
128-
) {
113+
fn prune_batch(&self, txn: &mut WriteTransaction, prefix: AddressNibbles, mut root_path: Vec<AccountsTreeNode<A>>) {
129114
// Walk along the rootPath towards the root node starting with the
130115
// immediate predecessor of the node specified by 'prefix'.
131116
let mut tmp_prefix = prefix;
@@ -153,20 +138,13 @@ impl<A: AccountsTreeLeave> AccountsTree<A> {
153138
}
154139
}
155140

156-
fn update_keys_batch(
157-
&self,
158-
txn: &mut WriteTransaction,
159-
prefix: AddressNibbles,
160-
mut root_path: Vec<AccountsTreeNode<A>>,
161-
) {
141+
fn update_keys_batch(&self, txn: &mut WriteTransaction, prefix: AddressNibbles, mut root_path: Vec<AccountsTreeNode<A>>) {
162142
// Walk along the rootPath towards the root node starting with the
163143
// immediate predecessor of the node specified by 'prefix'.
164144
let mut tmp_prefix = &prefix;
165145
let mut node;
166146
while let Some(path_node) = root_path.pop() {
167-
node = path_node
168-
.with_child(tmp_prefix, Blake2bHash::default())
169-
.unwrap();
147+
node = path_node.with_child(tmp_prefix, Blake2bHash::default()).unwrap();
170148
txn.put_reserve(&self.db, node.prefix(), &node);
171149
tmp_prefix = node.prefix();
172150
}
@@ -206,13 +184,7 @@ impl<A: AccountsTreeLeave> AccountsTree<A> {
206184
AccountsProof::new(nodes)
207185
}
208186

209-
fn get_accounts_proof_rec(
210-
&self,
211-
txn: &Transaction,
212-
node: &AccountsTreeNode<A>,
213-
prefixes: &[AddressNibbles],
214-
nodes: &mut Vec<AccountsTreeNode<A>>,
215-
) -> bool {
187+
fn get_accounts_proof_rec(&self, txn: &Transaction, node: &AccountsTreeNode<A>, prefixes: &[AddressNibbles], nodes: &mut Vec<AccountsTreeNode<A>>) -> bool {
216188
// For each prefix, descend the tree individually.
217189
let mut include_node = false;
218190
let mut i = 0;
@@ -248,8 +220,7 @@ impl<A: AccountsTreeLeave> AccountsTree<A> {
248220
// we continue from there in the next iteration.
249221
i = j;
250222
}
251-
include_node = self.get_accounts_proof_rec(txn, &child_node, &sub_prefixes, nodes)
252-
|| include_node;
223+
include_node = self.get_accounts_proof_rec(txn, &child_node, &sub_prefixes, nodes) || include_node;
253224
} else {
254225
// No child node exists with the requested prefix. Include the current node to prove the absence of the requested account.
255226
include_node = true;
@@ -267,40 +238,24 @@ impl<A: AccountsTreeLeave> AccountsTree<A> {
267238
}
268239

269240
pub fn get(&self, txn: &Transaction, address: &Address) -> Option<A> {
270-
if let AccountsTreeNode::TerminalNode { account, .. } =
271-
txn.get(&self.db, &AddressNibbles::from(address))?
272-
{
241+
if let AccountsTreeNode::TerminalNode { account, .. } = txn.get(&self.db, &AddressNibbles::from(address))? {
273242
return Some(account);
274243
}
275244
None
276245
}
277246

278-
pub(crate) fn get_chunk(
279-
&self,
280-
txn: &Transaction,
281-
start: &str,
282-
size: usize,
283-
) -> Option<AccountsTreeChunk<A>> {
284-
let mut chunk =
285-
self.get_terminal_nodes(txn, &AddressNibbles::from_str(start).ok()?, size)?;
247+
pub(crate) fn get_chunk(&self, txn: &Transaction, start: &str, size: usize) -> Option<AccountsTreeChunk<A>> {
248+
let mut chunk = self.get_terminal_nodes(txn, &AddressNibbles::from_str(start).ok()?, size)?;
286249
let last_node = chunk.pop();
287250
let proof = if let Some(node) = last_node {
288251
self.get_accounts_proof(txn, &[node.prefix().to_address()?])
289252
} else {
290-
self.get_accounts_proof(
291-
txn,
292-
&[Address::from_str("ffffffffffffffffffffffffffffffffffffffff").ok()?],
293-
)
253+
self.get_accounts_proof(txn, &[Address::from_str("ffffffffffffffffffffffffffffffffffffffff").ok()?])
294254
};
295255
Some(AccountsTreeChunk::new(chunk, proof))
296256
}
297257

298-
pub(crate) fn get_terminal_nodes(
299-
&self,
300-
txn: &Transaction,
301-
start: &AddressNibbles,
302-
size: usize,
303-
) -> Option<Vec<AccountsTreeNode<A>>> {
258+
pub(crate) fn get_terminal_nodes(&self, txn: &Transaction, start: &AddressNibbles, size: usize) -> Option<Vec<AccountsTreeNode<A>>> {
304259
let mut vec = Vec::new();
305260
let mut stack = Vec::new();
306261
stack.push(self.get_root(txn)?);
@@ -348,18 +303,15 @@ mod tests {
348303

349304
#[test]
350305
fn it_can_create_valid_chunk() {
351-
let address1 =
352-
Address::from(&hex::decode("0000000000000000000000000000000000000000").unwrap()[..]);
306+
let address1 = Address::from(&hex::decode("0000000000000000000000000000000000000000").unwrap()[..]);
353307
let account1 = Account::Basic(account::BasicAccount {
354308
balance: Coin::try_from(5).unwrap(),
355309
});
356-
let address2 =
357-
Address::from(&hex::decode("1000000000000000000000000000000000000000").unwrap()[..]);
310+
let address2 = Address::from(&hex::decode("1000000000000000000000000000000000000000").unwrap()[..]);
358311
let account2 = Account::Basic(account::BasicAccount {
359312
balance: Coin::try_from(55).unwrap(),
360313
});
361-
let address3 =
362-
Address::from(&hex::decode("1200000000000000000000000000000000000000").unwrap()[..]);
314+
let address3 = Address::from(&hex::decode("1200000000000000000000000000000000000000").unwrap()[..]);
363315
let account3 = Account::Basic(account::BasicAccount {
364316
balance: Coin::try_from(55555555).unwrap(),
365317
});

0 commit comments

Comments
 (0)