Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ struct Asset {
oracle: AztecAddress,
}

global SERIALIZED_LEN: Field = 4;
global SERIALIZED_LEN: Field = 6;

impl Serialize<SERIALIZED_LEN> for Asset {
fn serialize(Asset: Asset) -> [Field; SERIALIZED_LEN] {
[
Asset.interest_accumulator.to_integer(),
Asset.interest_accumulator.lo,
Asset.interest_accumulator.hi,
Asset.last_updated_ts as Field,
Asset.loan_to_value.to_integer(),
Asset.loan_to_value.lo,
Asset.loan_to_value.hi,
Asset.oracle.to_field()
]
}
Expand All @@ -30,10 +32,10 @@ impl Deserialize<SERIALIZED_LEN> for Asset {
// Right now we are wasting so many writes. If changing last_updated_ts
// we will end up rewriting all of them, wasting writes.
fn deserialize(fields: [Field; SERIALIZED_LEN]) -> Asset {
let interest_accumulator = U128::from_integer(fields[0]);
let last_updated_ts = fields[1] as u64;
let loan_to_value = U128::from_integer(fields[2]);
let oracle = AztecAddress::from_field(fields[3]);
let interest_accumulator = U128 { lo: fields[0], hi: fields[1] };
let last_updated_ts = fields[2] as u64;
let loan_to_value = U128 { lo: fields[3], hi: fields[4] };
let oracle = AztecAddress::from_field(fields[5]);

Asset {
interest_accumulator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ struct Asset {
price: U128,
}

global ASSET_SERIALIZED_LEN: Field = 1;
global ASSET_SERIALIZED_LEN: Field = 2;

impl Serialize<ASSET_SERIALIZED_LEN> for Asset {
fn serialize(asset: Asset) -> [Field; ASSET_SERIALIZED_LEN] {
[asset.price.to_integer()]
[asset.price.lo, asset.price.hi]
}
}

impl Deserialize<ASSET_SERIALIZED_LEN> for Asset {
fn deserialize(fields: [Field; ASSET_SERIALIZED_LEN]) -> Asset {
let price = U128::from_integer(fields[0]);
let price = U128 { lo: fields[0], hi: fields[1] };
Asset { price }
}
}