Skip to content

Commit

Permalink
optional H160 and U256 values that are 0, serialize as None
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Oct 12, 2021
1 parent 3830cf6 commit f4d4cce
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions chain-impl-mockchain/src/smartcontract/mod.rs
Expand Up @@ -105,22 +105,50 @@ impl Readable for Contract {
let from = AccountAddress::from_slice(buf.get_slice(20)?);
let to = match buf.get_u8()? {
0 => None,
1 => Some(AccountAddress::from_slice(buf.get_slice(20)?)),
1 => {
let a = AccountAddress::from_slice(buf.get_slice(20)?);
if a.is_zero() {
None
} else {
Some(a)
}
}
_ => return Err(ReadError::StructureInvalid("Invalid byte sequence".into())),
};
let gas = match buf.get_u8()? {
0 => None,
1 => Some(Gas::from(buf.get_slice(32)?)),
1 => {
let g = Gas::from(buf.get_slice(32)?);
if g.is_zero() {
None
} else {
Some(g)
}
}
_ => return Err(ReadError::StructureInvalid("Invalid byte sequence".into())),
};
let gas_price = match buf.get_u8()? {
0 => None,
1 => Some(GasPrice::from(buf.get_slice(32)?)),
1 => {
let gp = GasPrice::from(buf.get_slice(32)?);
if gp.is_zero() {
None
} else {
Some(gp)
}
}
_ => return Err(ReadError::StructureInvalid("Invalid byte sequence".into())),
};
let value = match buf.get_u8()? {
0 => None,
1 => Some(GasPrice::from(buf.get_slice(32)?)),
1 => {
let val = Value::from(buf.get_slice(32)?);
if val.is_zero() {
None
} else {
Some(val)
}
}
_ => return Err(ReadError::StructureInvalid("Invalid byte sequence".into())),
};
let data = match buf.get_u8()? {
Expand Down

0 comments on commit f4d4cce

Please sign in to comment.