This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert to safe but extremely verbose type conversion.
@rphmeier any more concise way of doing this?
- Loading branch information
Showing
4 changed files
with
10 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ keccak-hash = "0.1.0" | |
patricia-trie = "0.1.0" | ||
memorydb = "0.1.1" | ||
triehash = "0.1" | ||
byteorder = "1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,10 +82,14 @@ impl Backend for InMemory { | |
self.inner.update(changes); | ||
|
||
// fully recalculate trie roots. | ||
use std::mem::transmute; | ||
let storage_roots = self.inner.storage.iter().map(|(object, storage)| { | ||
let flat_trie = storage.iter().map(|(k, v)| (k.to_vec(), v.clone())).collect(); | ||
(unsafe { transmute::<u64, [u8; 8]>(object.to_be()) }.to_vec(), sec_trie_root(flat_trie).to_vec()) | ||
({ | ||
use byteorder::{BigEndian, ByteOrder}; | ||
let mut r = [0u8; 8]; | ||
BigEndian::write_u64(&mut r, *object); | ||
r.to_vec() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rphmeier
Contributor
|
||
}, sec_trie_root(flat_trie).to_vec()) | ||
}).collect(); | ||
|
||
let storage_tree_root = H256(sec_trie_root(storage_roots).0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this is about as concise as you can get, UFCS could get you to
<byteorder::BE as byteorder::ByteOrder>::write_u64(&mut r, *object)
and save a line