Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 84b9f84

Browse files
committed
convert to safe but extremely verbose type conversion.
@rphmeier any more concise way of doing this?
1 parent 13dcd89 commit 84b9f84

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

state_machine/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ keccak-hash = "0.1.0"
1111
patricia-trie = "0.1.0"
1212
memorydb = "0.1.1"
1313
triehash = "0.1"
14+
byteorder = "1.1"

state_machine/src/backend.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,14 @@ impl Backend for InMemory {
8282
self.inner.update(changes);
8383

8484
// fully recalculate trie roots.
85-
use std::mem::transmute;
8685
let storage_roots = self.inner.storage.iter().map(|(object, storage)| {
8786
let flat_trie = storage.iter().map(|(k, v)| (k.to_vec(), v.clone())).collect();
88-
(unsafe { transmute::<u64, [u8; 8]>(object.to_be()) }.to_vec(), sec_trie_root(flat_trie).to_vec())
87+
({
88+
use byteorder::{BigEndian, ByteOrder};
89+
let mut r = [0u8; 8];
90+
BigEndian::write_u64(&mut r, *object);
91+
r.to_vec()
92+
}, sec_trie_root(flat_trie).to_vec())
8993
}).collect();
9094

9195
let storage_tree_root = H256(sec_trie_root(storage_roots).0);

state_machine/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ extern crate keccak_hash;
2727
extern crate patricia_trie;
2828
extern crate triehash;
2929

30+
extern crate byteorder;
31+
3032
use std::collections::HashMap;
3133
use std::fmt;
3234

0 commit comments

Comments
 (0)