Clean up `read_uint` as in PR #2 (thanks @jkozera)
This commit is contained in:
parent
3e25134b2f
commit
dea6d457f4
|
@ -190,14 +190,10 @@ pub fn read_scriptbool(v: &[u8]) -> bool {
|
||||||
/// Read a script-encoded unsigned integer
|
/// Read a script-encoded unsigned integer
|
||||||
pub fn read_uint<'a, I:Iterator<(uint, &'a u8)>>(mut iter: I, size: uint)
|
pub fn read_uint<'a, I:Iterator<(uint, &'a u8)>>(mut iter: I, size: uint)
|
||||||
-> Result<uint, ScriptError> {
|
-> Result<uint, ScriptError> {
|
||||||
let mut sh = 0;
|
|
||||||
let mut ret = 0;
|
let mut ret = 0;
|
||||||
for _ in range(0, size) {
|
for i in range(0, size) {
|
||||||
match iter.next() {
|
match iter.next() {
|
||||||
Some((_, &n)) => {
|
Some((_, &n)) => ret += n as uint << (i * 8),
|
||||||
ret += n as uint << sh;
|
|
||||||
sh += 8;
|
|
||||||
}
|
|
||||||
None => { return Err(EarlyEndOfScript); }
|
None => { return Err(EarlyEndOfScript); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue