1111
1212#include " api/api.hpp"
1313#include " api/rpc/json_errors.hpp"
14+ #include " common/enum.hpp"
1415#include " primitives/address/address_codec.hpp"
1516
1617#define COMMA ,
@@ -26,6 +27,7 @@ namespace fc::api {
2627 using crypto::signature::Signature;
2728 using primitives::BigInt;
2829 using primitives::block::BlockHeader;
30+ using primitives::sector::PoStProof;
2931 using primitives::ticket::EPostProof;
3032 using primitives::ticket::EPostTicket;
3133 using primitives::ticket::Ticket;
@@ -35,6 +37,8 @@ namespace fc::api {
3537 using vm::actor::builtin::payment_channel::Merge;
3638 using vm::actor::builtin::payment_channel::ModularVerificationParameter;
3739 using base64 = cppcodec::base64_rfc4648;
40+ using SignatureType = crypto::signature::Type;
41+ using primitives::sector::RegisteredProof;
3842
3943 struct Request {
4044 uint64_t id;
@@ -82,7 +86,10 @@ namespace fc::api {
8286 Set (j, key, encode (v));
8387 }
8488
85- static auto decodeBase64 (const Value &j) {
89+ static std::vector<uint8_t > decodeBase64 (const Value &j) {
90+ if (j.IsNull ()) {
91+ return {};
92+ }
8693 return base64::decode (AsString (j));
8794 }
8895
@@ -229,16 +236,16 @@ namespace fc::api {
229236 }
230237
231238 ENCODE (Signature) {
232- const char * type;
239+ uint64_t type;
233240 gsl::span<const uint8_t > data;
234241 visit_in_place (
235242 v,
236243 [&](const BlsSignature &bls) {
237- type = " bls " ;
244+ type = SignatureType::BLS ;
238245 data = gsl::make_span (bls);
239246 },
240247 [&](const Secp256k1Signature &secp) {
241- type = " secp256k1 " ;
248+ type = SignatureType::SECP256K1 ;
242249 data = gsl::make_span (secp);
243250 });
244251 Value j{rapidjson::kObjectType };
@@ -248,11 +255,12 @@ namespace fc::api {
248255 }
249256
250257 DECODE (Signature) {
251- auto type = AsString (Get (j, " Type" ));
258+ uint64_t type;
259+ decode (type, Get (j, " Type" ));
252260 auto &data = Get (j, " Data" );
253- if (type == " bls " ) {
261+ if (type == SignatureType::BLS ) {
254262 v = decode<BlsSignature>(data);
255- } else if (type == " secp256k1 " ) {
263+ } else if (type == SignatureType::SECP256K1 ) {
256264 v = decode<Secp256k1Signature>(data);
257265 } else {
258266 outcome::raise (JsonError::WRONG_ENUM);
@@ -273,16 +281,30 @@ namespace fc::api {
273281 decode (v.challenge_index , Get (j, " ChallengeIndex" ));
274282 }
275283
284+ ENCODE (PoStProof) {
285+ Value j{rapidjson::kObjectType };
286+ Set (j, " RegisteredProof" , common::to_int (v.registered_proof ));
287+ Set (j, " ProofBytes" , gsl::make_span (v.proof ));
288+ return j;
289+ }
290+
291+ DECODE (PoStProof) {
292+ std::underlying_type_t <RegisteredProof> registered_proof;
293+ decode (registered_proof, Get (j, " RegisteredProof" ));
294+ v.registered_proof = RegisteredProof{registered_proof};
295+ decode (v.proof , Get (j, " ProofBytes" ));
296+ }
297+
276298 ENCODE (EPostProof) {
277299 Value j{rapidjson::kObjectType };
278- Set (j, " Proof " , gsl::make_span (v. proof ) );
300+ Set (j, " Proofs " , v. proofs );
279301 Set (j, " PostRand" , gsl::make_span (v.post_rand ));
280302 Set (j, " Candidates" , v.candidates );
281303 return j;
282304 }
283305
284306 DECODE (EPostProof) {
285- decode (v.proof , Get (j, " Proof " ));
307+ decode (v.proofs , Get (j, " Proofs " ));
286308 decode (v.post_rand , Get (j, " PostRand" ));
287309 decode (v.candidates , Get (j, " Candidates" ));
288310 }
0 commit comments