Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix: make label its own type (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelm41 authored Feb 28, 2023
1 parent e46b858 commit 93e91bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion contracts/v0.8/cbor/MarketCbor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ library MarketCBOR {
buf.startFixedArray(uint64(params.deals.length));

for (uint64 i = 0; i < params.deals.length; i++) {
bool isLabelStr = bytes(params.deals[i].proposal.label.dataStr).length > 0;
bool isLabelBts = params.deals[i].proposal.label.dataBts.length > 0;
require((!isLabelStr && isLabelBts) || (!isLabelBts && isLabelStr), "deal label must be either string or bytes");

buf.startFixedArray(2);

buf.startFixedArray(11);
Expand All @@ -139,7 +143,9 @@ library MarketCBOR {
buf.writeBool(params.deals[i].proposal.verified_deal);
buf.writeBytes(params.deals[i].proposal.client.data);
buf.writeBytes(params.deals[i].proposal.provider.data);
buf.writeString(params.deals[i].proposal.label);

isLabelStr ? buf.writeString(params.deals[i].proposal.label.dataStr) : buf.writeBytes(params.deals[i].proposal.label.dataBts);

buf.writeInt64(params.deals[i].proposal.start_epoch);
buf.writeInt64(params.deals[i].proposal.end_epoch);
buf.writeBytes(params.deals[i].proposal.storage_price_per_epoch.serializeBigInt());
Expand Down
6 changes: 6 additions & 0 deletions contracts/v0.8/types/CommonTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ library CommonTypes {
bytes data;
}

/// @param dataBytes deal proposal label in bytes format (it can be utf8 string or arbitray bytes string)
struct DealLabel {
bytes dataBts;
string dataStr;
}

type FilActorId is uint64;
}
2 changes: 1 addition & 1 deletion contracts/v0.8/types/MarketTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ library MarketTypes {
bool verified_deal;
CommonTypes.FilAddress client;
CommonTypes.FilAddress provider;
string label;
CommonTypes.DealLabel label;
int64 start_epoch;
int64 end_epoch;
CommonTypes.BigInt storage_price_per_epoch;
Expand Down
4 changes: 2 additions & 2 deletions testing/tests/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ fn market_tests() {
method_num: EvmMethods::InvokeContract as u64,
sequence: 2,
params: RawBytes::new(
// [[[[["0x000181E203922020B51BCC94BB0977C984C093770289DEA4E83EF08C355145D412C6673E06152A09"], 8388608, false, ["0x0390A40613DFB06445DFC3759EC22146D66B832AFE57B4AC441E5209D154131B1540E937CB837831855553E17EEFEEEED1"], ["0x0068"], "mAXCg5AIg8YBXbFjtdBy1iZjpDYAwRSt0elGLF5GvTqulEii1VcM", 25245, 545150, ["0x01001D1BF800", false], ["0x038D7EA4C68000", false], ["0x038D7EA4C68000", false]], "0x02B7E4AD239896D5DF3491AFE01F9A6F9D5C4A1E59C16E6B386CE16797C00A1224D5ABB8EFE0EDC7B052FC0AB5772BA4DA10C064537320FEFCADA4167017508D882207B23DD457966DAF21393710A26CC5509AC079EC9A0846028B279435BD5F22" ]]]
// [[[[["0x000181E203922020B51BCC94BB0977C984C093770289DEA4E83EF08C355145D412C6673E06152A09"], 8388608, false, ["0x0390A40613DFB06445DFC3759EC22146D66B832AFE57B4AC441E5209D154131B1540E937CB837831855553E17EEFEEEED1"], ["0x0068"], ["0x", "mAXCg5AIg8YBXbFjtdBy1iZjpDYAwRSt0elGLF5GvTqulEii1VcM"], 25245, 545150, ["0x01001D1BF800", false], ["0x038D7EA4C68000", false], ["0x038D7EA4C68000", false]], "0x02B7E4AD239896D5DF3491AFE01F9A6F9D5C4A1E59C16E6B386CE16797C00A1224D5ABB8EFE0EDC7B052FC0AB5772BA4DA10C064537320FEFCADA4167017508D882207B23DD457966DAF21393710A26CC5509AC079EC9A0846028B279435BD5F22" ]]]
hex::decode(
"590604D21C49F10000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000004E000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002C0000000000000000000000000000000000000000000000000000000000000629D000000000000000000000000000000000000000000000000000000000008517E000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000003A0000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028000181E203922020B51BCC94BB0977C984C093770289DEA4E83EF08C355145D412C6673E06152A09000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000310390A40613DFB06445DFC3759EC22146D66B832AFE57B4AC441E5209D154131B1540E937CB837831855553E17EEFEEEED100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002006800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000346D41584367354149673859425862466A7464427931695A6A704459417752537430656C474C463547765471756C4569693156634D00000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000601001D1BF8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007038D7EA4C6800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007038D7EA4C6800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006102B7E4AD239896D5DF3491AFE01F9A6F9D5C4A1E59C16E6B386CE16797C00A1224D5ABB8EFE0EDC7B052FC0AB5772BA4DA10C064537320FEFCADA4167017508D882207B23DD457966DAF21393710A26CC5509AC079EC9A0846028B279435BD5F2200000000000000000000000000000000000000000000000000000000000000",
"590664610F3BB100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000054000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001E0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002C0000000000000000000000000000000000000000000000000000000000000629D000000000000000000000000000000000000000000000000000000000008517E00000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028000181E203922020B51BCC94BB0977C984C093770289DEA4E83EF08C355145D412C6673E06152A09000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000310390A40613DFB06445DFC3759EC22146D66B832AFE57B4AC441E5209D154131B1540E937CB837831855553E17EEFEEEED100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002006800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000346D41584367354149673859425862466A7464427931695A6A704459417752537430656C474C463547765471756C4569693156634D00000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000601001D1BF8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007038D7EA4C6800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007038D7EA4C6800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006102B7E4AD239896D5DF3491AFE01F9A6F9D5C4A1E59C16E6B386CE16797C00A1224D5ABB8EFE0EDC7B052FC0AB5772BA4DA10C064537320FEFCADA4167017508D882207B23DD457966DAF21393710A26CC5509AC079EC9A0846028B279435BD5F2200000000000000000000000000000000000000000000000000000000000000",
)
.unwrap(),
),
Expand Down

0 comments on commit 93e91bf

Please sign in to comment.