Clean up `read_uint` as in PR #2 (thanks @jkozera)

This commit is contained in:
Andrew Poelstra 2014-08-11 19:20:39 -07:00
parent 3e25134b2f
commit dea6d457f4
1 changed files with 2 additions and 6 deletions

View File

@ -190,14 +190,10 @@ pub fn read_scriptbool(v: &[u8]) -> bool {
/// Read a script-encoded unsigned integer
pub fn read_uint<'a, I:Iterator<(uint, &'a u8)>>(mut iter: I, size: uint)
-> Result<uint, ScriptError> {
let mut sh = 0;
let mut ret = 0;
for _ in range(0, size) {
for i in range(0, size) {
match iter.next() {
Some((_, &n)) => {
ret += n as uint << sh;
sh += 8;
}
Some((_, &n)) => ret += n as uint << (i * 8),
None => { return Err(EarlyEndOfScript); }
}
}