// Copyright (c) 2011-2016 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #pragma once #include #include #include #define TX_EXTRA_PADDING_MAX_COUNT 255 #define TX_EXTRA_NONCE_MAX_COUNT 255 #define TX_EXTRA_TAG_PADDING 0x00 #define TX_EXTRA_TAG_PUBKEY 0x01 #define TX_EXTRA_NONCE 0x02 #define TX_EXTRA_NONCE_PAYMENT_ID 0x00 namespace CryptoNote { struct TransactionExtraPadding { size_t size; }; struct TransactionExtraPublicKey { Crypto::PublicKey publicKey; }; struct TransactionExtraNonce { std::vector nonce; }; // tx_extra_field format, except tx_extra_padding and tx_extra_pub_key: // varint tag; // varint size; // varint data[]; typedef boost::variant TransactionExtraField; template bool findTransactionExtraFieldByType(const std::vector& tx_extra_fields, T& field) { auto it = std::find_if(tx_extra_fields.begin(), tx_extra_fields.end(), [](const TransactionExtraField& f) { return typeid(T) == f.type(); }); if (tx_extra_fields.end() == it) return false; field = boost::get(*it); return true; } bool parseTransactionExtra(const std::vector& tx_extra, std::vector& tx_extra_fields); bool writeTransactionExtra(std::vector& tx_extra, const std::vector& tx_extra_fields); Crypto::PublicKey getTransactionPublicKeyFromExtra(const std::vector& tx_extra); bool addTransactionPublicKeyToExtra(std::vector& tx_extra, const Crypto::PublicKey& tx_pub_key); bool addExtraNonceToTransactionExtra(std::vector& tx_extra, const BinaryArray& extra_nonce); void setPaymentIdToTransactionExtraNonce(BinaryArray& extra_nonce, const Crypto::Hash& payment_id); bool getPaymentIdFromTransactionExtraNonce(const BinaryArray& extra_nonce, Crypto::Hash& payment_id); bool createTxExtraWithPaymentId(const std::string& paymentIdString, std::vector& extra); //returns false if payment id is not found or parse error bool getPaymentIdFromTxExtra(const std::vector& extra, Crypto::Hash& paymentId); bool parsePaymentId(const std::string& paymentIdString, Crypto::Hash& paymentId); }