Bugfix for reading u256.
This commit is contained in:
parent
d55e5fdb68
commit
d886e03aa4
5 changed files with 35 additions and 9 deletions
|
@ -65,11 +65,12 @@ impl<'a> Adjacencies<'a> {
|
|||
.entry(from.clone())
|
||||
.or_insert_with(|| {
|
||||
let mut result: HashMap<Node, U256> = HashMap::new();
|
||||
for edge in &self.edges[source_address_of(from)] {
|
||||
// Plain edges are (from, to, token) labeled with capacity
|
||||
for edge in self.edges.get(source_address_of(from)).unwrap_or(&vec![]) {
|
||||
match from {
|
||||
Node::Node(_) => {
|
||||
// One edge from "from" to "from x token" with a capacity
|
||||
// as the max over all contributing edges (the balance of the sender)
|
||||
// as the max over all "to" addresses (the balance of the sender)
|
||||
result
|
||||
.entry(pseudo_node(*edge))
|
||||
.and_modify(|c| {
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
use crate::types::{Address};
|
||||
use crate::types::Address;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
mod adjacencies;
|
||||
mod flow;
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Clone)]
|
||||
enum Node {
|
||||
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
|
||||
pub enum Node {
|
||||
Node(Address),
|
||||
TokenEdge(Address, Address),
|
||||
}
|
||||
|
||||
impl Display for Node {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Node::Node(address) => write!(f, "{address}"),
|
||||
Node::TokenEdge(address, token) => write!(f, "({address} x {token})"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use crate::flow::flow::compute_flow;
|
||||
|
|
|
@ -48,7 +48,7 @@ fn read_u256(file: &mut File) -> Result<U256, io::Error> {
|
|||
let mut bytes = [0u8; 32];
|
||||
file.read_exact(&mut bytes[32 - length..32])?;
|
||||
let high = u128::from_be_bytes(*<&[u8; 16]>::try_from(&bytes[0..16]).unwrap());
|
||||
let low = u128::from_be_bytes(*<&[u8; 16]>::try_from(&bytes[0..16]).unwrap());
|
||||
let low = u128::from_be_bytes(*<&[u8; 16]>::try_from(&bytes[16..32]).unwrap());
|
||||
Ok(U256::new(high, low))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::env;
|
||||
|
||||
|
||||
mod flow;
|
||||
mod io;
|
||||
mod types;
|
||||
|
@ -16,6 +15,10 @@ fn main() {
|
|||
|
||||
println!("Computing flow {from_str} -> {to_str} using {edges_file}");
|
||||
let edges = io::read_edges_binary(edges_file).expect("Error loading edges.");
|
||||
print!("Read {} edges", edges.len());
|
||||
flow::compute_flow(&Address::from(from_str.as_str()), &Address::from(to_str.as_str()), &edges);
|
||||
println!("Read {} edges", edges.len());
|
||||
flow::compute_flow(
|
||||
&Address::from(from_str.as_str()),
|
||||
&Address::from(to_str.as_str()),
|
||||
&edges,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Hash, Eq, PartialEq, PartialOrd)]
|
||||
pub struct Address([u8; 20]);
|
||||
|
||||
|
@ -18,3 +20,13 @@ impl From<&str> for Address {
|
|||
Address(data)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Address {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
write!(f, "0x")?;
|
||||
for b in self.0 {
|
||||
write!(f, "{:02x}", b)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue