Struct.fromCell() and Struct.fromSlice()Got tired of parsing Cells and you're certain of their structure?
Now you'll be able to call
YourStruct.fromCell() and automagically get your Cells parsed! And it also works on Slices, with YourStruct.fromSlice()Note, that those functions throw exceptions when the layout of a given Cell or Slice doesn't match the Struct's one.
Let's see them in action:
struct Profit {
big: String?;
dict: map<Int, Int as uint64>;
energy: Int;
}
contract MilkMoney with Deployable {
// 100% sure here
get fun gotProfit(src: Cell): Profit {
let profit = Profit.fromCell(src);
return profit;
}
// not 100% sure here,
// being cautious for good reasons
get fun gotProfitSlice(src: Slice): Profit? {
let profit: Profit? = null;
try {
profit = Profit.fromSlice(src);
catch (e) {
dump("Slice doesn't match Profit!");
}
return profit;
}
}🧑🍳 Contributor: Gusarich
🐙 Implementation: #418
🍽 To be released in: v1.4.0 (right around the corner!)
🍲 You shall just parse!
♨️ @tact_kitchen
