#pragma once #include #include using namespace std; /** * Public interface for libmonero-cpp library. */ namespace monero { /** * Base struct which can be serialized. * * TODO: move this to MoneroUtils? */ struct SerializableStruct { /** * Serializes the struct to a json string. * * @return the struct serialized to a json string */ string serialize() const; /** * Convert the struct to a property tree. * * @return the converted property tree */ virtual boost::property_tree::ptree toPropertyTree() const = 0; }; /** * Enumerates Monero network types. */ enum MoneroNetworkType : uint8_t { MAINNET = 0, TESTNET, STAGENET }; /** * Models a connection to a daemon. * * TODO: switch to boost::optional */ struct MoneroRpcConnection { string uri; string username; string password; //MoneroRpcConnection() : uri(""), username(""), password("")) {} MoneroRpcConnection(const string& uri = "", const string& username = "", const string& password = "") : uri(uri), username(username), password(password) {} }; // forward declarations struct MoneroTx; struct MoneroOutput; /** * Models a Monero block header which contains information about the block. */ struct MoneroBlockHeader : public SerializableStruct { boost::optional id; boost::optional height; boost::optional timestamp; boost::optional size; boost::optional weight; boost::optional longTermWeight; boost::optional depth; boost::optional difficulty; boost::optional cumulativeDifficulty; boost::optional majorVersion; boost::optional minorVersion; boost::optional nonce; boost::optional coinbaseTxId; boost::optional numTxs; boost::optional orphanStatus; boost::optional prevId; boost::optional reward; boost::optional powHash; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& header); }; /** * Models a Monero block in the blockchain. */ struct MoneroBlock : public MoneroBlockHeader { boost::optional hex; boost::optional> coinbaseTx; vector> txs; vector txIds; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& block); }; /** * Models a Monero transaction on the blockchain. */ struct MoneroTx : public SerializableStruct { static const string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000" boost::optional> block; boost::optional id; boost::optional version; boost::optional isCoinbase; boost::optional paymentId; boost::optional fee; boost::optional mixin; boost::optional doNotRelay; boost::optional isRelayed; boost::optional isConfirmed; boost::optional inTxPool; boost::optional numConfirmations; boost::optional unlockTime; boost::optional lastRelayedTimestamp; boost::optional receivedTimestamp; boost::optional isDoubleSpend; boost::optional key; boost::optional fullHex; boost::optional prunedHex; boost::optional prunableHex; boost::optional prunableHash; boost::optional size; boost::optional weight; vector> vins; vector> vouts; vector outputIndices; boost::optional metadata; boost::optional commonTxSets; vector extra; boost::optional rctSignatures; // TODO: implement boost::optional rctSigPrunable; // TODO: implement boost::optional isKeptByBlock; boost::optional isFailed; boost::optional lastFailedHeight; boost::optional lastFailedId; boost::optional maxUsedBlockHeight; boost::optional maxUsedBlockId; vector signatures; boost::property_tree::ptree toPropertyTree() const; boost::optional getHeight() const { if (block == boost::none) return boost::none; return *((*block)->height); } void merge(const shared_ptr& self, const shared_ptr& other); }; /** * Models a Monero key image. */ struct MoneroKeyImage { boost::optional hex; boost::optional signature; void merge(const shared_ptr& self, const shared_ptr& other); }; /** * Models a Monero transaction output. */ struct MoneroOutput { shared_ptr tx; boost::optional> keyImage; boost::optional amount; boost::optional index; vector ringOutputIndices; boost::optional stealthPublicKey; void merge(const shared_ptr& self, const shared_ptr& other); }; } //// --------------------------- MODEL SERIALIZATION ---------------------------- // //BOOST_CLASS_VERSION(monero::MoneroTx, 0) //BOOST_CLASS_VERSION(monero::MoneroOutput, 0) //BOOST_CLASS_VERSION(monero::MoneroKeyImage, 0) // //namespace boost { // namespace serialization { // template // inline void serialize(Archive &a, monero::MoneroTx& x, const boost::serialization::version_type ver) // { //// a & x.m_L; //// a & x.m_R; // } // // template // inline void serialize(Archive &a, monero::MoneroOutput& x, const boost::serialization::version_type ver) // { //// a & x.m_signer; //// a & x.m_LR; //// a & x.m_partial_key_images; // } // // template // inline void serialize(Archive &a, monero::MoneroKeyImage& x, const boost::serialization::version_type ver) // { //// a & x.m_signer; //// a & x.m_LR; //// a & x.m_partial_key_images; // } // } // namepsace serialization //} // namespace boost