Skip to content

Commit

Permalink
deal status protocol with OOP
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Chernyshov <alexey.n.chernyshov@gmail.com>
  • Loading branch information
Alexey-N-Chernyshov committed Nov 25, 2021
1 parent 8a288f5 commit 4771392
Show file tree
Hide file tree
Showing 22 changed files with 994 additions and 356 deletions.
6 changes: 3 additions & 3 deletions core/api/full_node/node_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace fc::api {
using libp2p::multi::Multiaddress;
using libp2p::peer::PeerId;
using markets::retrieval::RetrievalPeer;
using markets::storage::DataRef;
using markets::storage::DataRef0;
using markets::storage::SignedStorageAsk;
using markets::storage::StorageDeal;
using markets::storage::StorageDealStatus;
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace fc::api {
StorageDealStatus state;
std::string message;
Address provider;
DataRef data_ref;
DataRef0 data_ref;
CID piece_cid;
uint64_t size;
TokenAmount price_per_epoch;
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace fc::api {
};

struct StartDealParams {
DataRef data;
DataRef0 data;
Address wallet;
Address miner;
TokenAmount epoch_price;
Expand Down
4 changes: 2 additions & 2 deletions core/api/rpc/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ namespace fc::api {
Get(j, "Signature", v.signature);
}

ENCODE(DataRef) {
ENCODE(DataRef0) {
Value j{rapidjson::kObjectType};
Set(j, "TransferType", v.transfer_type);
Set(j, "Root", v.root);
Expand All @@ -1350,7 +1350,7 @@ namespace fc::api {
return j;
}

DECODE(DataRef) {
DECODE(DataRef0) {
decode(v.transfer_type, Get(j, "TransferType"));
decode(v.root, Get(j, "Root"));
decode(v.piece_cid, Get(j, "PieceCid"));
Expand Down
73 changes: 0 additions & 73 deletions core/codec/cbor/cbor_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,9 @@

#include "codec/cbor/cbor_codec.hpp"
#include "markets/retrieval/protocols/retrieval_protocol.hpp"
#include "markets/storage/ask_protocol.hpp"
#include "primitives/address/address_codec.hpp"
#include "storage/ipfs/graphsync/extension.hpp"

namespace fc::markets::storage {
using codec::cbor::CborDecodeStream;
using codec::cbor::CborEncodeStream;

CBOR2_ENCODE(StorageAsk::Named) {
auto m{CborEncodeStream::map()};
m["Price"] << v.price;
m["VerifiedPrice"] << v.verified_price;
m["MinPieceSize"] << v.min_piece_size;
m["MaxPieceSize"] << v.max_piece_size;
m["Miner"] << v.miner;
m["Timestamp"] << v.timestamp;
m["Expiry"] << v.expiry;
m["SeqNo"] << v.seq_no;
return s << m;
}

CBOR2_DECODE(StorageAsk::Named) {
auto m{s.map()};
CborDecodeStream::named(m, "Price") >> v.price;
CborDecodeStream::named(m, "VerifiedPrice") >> v.verified_price;
CborDecodeStream::named(m, "MinPieceSize") >> v.min_piece_size;
CborDecodeStream::named(m, "MaxPieceSize") >> v.max_piece_size;
CborDecodeStream::named(m, "Miner") >> v.miner;
CborDecodeStream::named(m, "Timestamp") >> v.timestamp;
CborDecodeStream::named(m, "Expiry") >> v.expiry;
CborDecodeStream::named(m, "SeqNo") >> v.seq_no;
return s;
}

CBOR2_ENCODE(SignedStorageAsk::Named) {
auto m{CborEncodeStream::map()};
m["Ask"] << static_cast<const StorageAsk::Named &>(v.ask);
m["Signature"] << v.signature;
return s << m;
}

CBOR2_DECODE(SignedStorageAsk::Named) {
auto m{s.map()};
CborDecodeStream::named(m, "Ask")
>> *(static_cast<StorageAsk::Named *>(&v.ask));
CborDecodeStream::named(m, "Signature") >> v.signature;
return s;
}

CBOR2_ENCODE(AskRequest::Named) {
auto m{CborEncodeStream::map()};
m["Miner"] << v.miner;
return s << m;
}

CBOR2_DECODE(AskRequest::Named) {
auto m{s.map()};

CborDecodeStream::named(m, "Miner") >> v.miner;
return s;
}

CBOR2_ENCODE(AskResponse::Named) {
auto m{CborEncodeStream::map()};
m["Ask"] << static_cast<const SignedStorageAsk::Named &>(v.ask);
return s << m;
}

CBOR2_DECODE(AskResponse::Named) {
auto m{s.map()};
CborDecodeStream::named(m, "Ask")
>> *(static_cast<SignedStorageAsk::Named *>(&v.ask));
return s;
}
} // namespace fc::markets::storage

namespace fc::markets::retrieval {
using codec::cbor::CborDecodeStream;
using codec::cbor::CborEncodeStream;
Expand Down
1 change: 1 addition & 0 deletions core/markets/storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

add_subdirectory(chain_events)
add_subdirectory(client)
add_subdirectory(protocol)
add_subdirectory(provider)
26 changes: 17 additions & 9 deletions core/markets/storage/ask_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ namespace fc::markets::storage {
const libp2p::peer::Protocol kAskProtocolId_v1_0_1 = "/fil/storage/ask/1.0.1";

/** Protocol 1.1.1 uses named cbor */
const libp2p::peer::Protocol kAskProtocolId_v1_1_1 = "/fil/storage/ask/1.1.1";
const libp2p::peer::Protocol kAskProtocolId_v1_1_0 = "/fil/storage/ask/1.1.0";

/**
* StorageAsk defines the parameters by which a miner will choose to accept or
* reject a deal.
*/
struct StorageAsk {
struct Named;

Expand All @@ -40,8 +44,6 @@ namespace fc::markets::storage {
uint64_t seq_no;
};

struct StorageAsk::Named : StorageAsk {};

CBOR_TUPLE(StorageAsk,
price,
verified_price,
Expand All @@ -52,17 +54,21 @@ namespace fc::markets::storage {
expiry,
seq_no)

struct StorageAsk::Named : StorageAsk {};
CBOR2_DECODE_ENCODE(StorageAsk::Named)

struct SignedStorageAsk {
struct Named;

StorageAsk ask;
Signature signature;
};

struct SignedStorageAsk::Named : SignedStorageAsk {};

CBOR_TUPLE(SignedStorageAsk, ask, signature)

struct SignedStorageAsk::Named : SignedStorageAsk {};
CBOR2_DECODE_ENCODE(SignedStorageAsk::Named)

/**
* AskRequest is a request for current ask parameters for a given miner
*/
Expand All @@ -72,10 +78,11 @@ namespace fc::markets::storage {
Address miner;
};

CBOR_TUPLE(AskRequest, miner)

/** Named ask request for named cbor */
struct AskRequest::Named : AskRequest {};

CBOR_TUPLE(AskRequest, miner)
CBOR2_DECODE_ENCODE(AskRequest::Named)

/**
* AskResponse is the response sent over the network in response to an ask
Expand All @@ -87,9 +94,10 @@ namespace fc::markets::storage {
SignedStorageAsk ask;
};

CBOR_TUPLE(AskResponse, ask)

/** Named ask response for named cbor */
struct AskResponse::Named : AskResponse {};

CBOR_TUPLE(AskResponse, ask)
CBOR2_DECODE_ENCODE(AskResponse::Named)

} // namespace fc::markets::storage
Loading

0 comments on commit 4771392

Please sign in to comment.