diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index e35b2a62c..a4297e0e7 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -294,7 +294,22 @@ uint64_t BlockchainDB::add_block( const std::pair& blck time1 = epee::misc_utils::get_tick_count(); uint64_t num_rct_outs = 0; - oracle::asset_type_counts num_rct_outs_by_asset_type; + oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; + + // add newly created tokens + for (const std::pair& tx : txs) + { + if (tx.first.type == cryptonote::transaction_type::CREATE_TOKEN) + { + uint32_t asset_type_id = cryptonote::asset_id_from_type("sal" + tx.first.token_metadata.asset_type); + if (!num_rct_outs_by_asset_type.add_asset_type(asset_type_id)) + throw std::runtime_error("Failed to add asset_type 'sal" + tx.first.token_metadata.asset_type + "'"); + } + + if (!is_tx_paid_for(tx.first)) + throw std::runtime_error("TX is not paid for"); + } + blobdata miner_bd = tx_to_blob(blk.miner_tx); add_transaction(blk_hash, std::make_pair(blk.miner_tx, blobdata_ref(miner_bd))); blobdata protocol_bd = tx_to_blob(blk.protocol_tx); @@ -309,12 +324,14 @@ uint64_t BlockchainDB::add_block( const std::pair& blck std::string asset_type; if (!get_output_asset_type(vout, asset_type)) throw std::runtime_error("Failed to get output asset type"); - num_rct_outs_by_asset_type.add(asset_type, 1); + uint32_t asset_type_id = cryptonote::asset_id_from_type(asset_type); + num_rct_outs_by_asset_type.add_asset_type(asset_type_id); + num_rct_outs_by_asset_type.add(asset_type_id, 1); } } std::map slippage_counts; - uint64_t audit_total = 0, yield_total = 0; + uint64_t audit_total = 0, token_total = 0, yield_total = 0; if (blk.protocol_tx.version >= 2) { num_rct_outs += blk.protocol_tx.vout.size(); @@ -326,10 +343,12 @@ uint64_t BlockchainDB::add_block( const std::pair& blck std::string asset_type; if (!get_output_asset_type(vout, asset_type)) throw std::runtime_error("Failed to get output asset type"); + uint32_t asset_type_id = cryptonote::asset_id_from_type(asset_type); + + // Update the RCT outs for the asset_type + num_rct_outs_by_asset_type.add_asset_type(asset_type_id); + num_rct_outs_by_asset_type.add(asset_type_id, 1); - // Update the RCT outs - num_rct_outs_by_asset_type.add(asset_type, 1); - // Update the amount tallies by DEDUCTING the minted amount if (slippage_counts.count(asset_type) == 0) slippage_counts[asset_type] = 0; @@ -350,7 +369,9 @@ uint64_t BlockchainDB::add_block( const std::pair& blck throw std::runtime_error("Failed to get output asset type"); if (vout.amount == 0) { ++num_rct_outs; - num_rct_outs_by_asset_type.add(asset_type, 1); + uint32_t asset_type_id = cryptonote::asset_id_from_type(asset_type); + num_rct_outs_by_asset_type.add_asset_type(asset_type_id); + num_rct_outs_by_asset_type.add(asset_type_id, 1); } // Is this a CONVERT TX? @@ -367,6 +388,16 @@ uint64_t BlockchainDB::add_block( const std::pair& blck audit_total += tx.first.amount_burnt; } + // Is this an create_token TX? + if (tx.first.type == cryptonote::transaction_type::CREATE_TOKEN) { + token_total += tx.first.amount_burnt; + /* + uint32_t asset_type_id = cryptonote::asset_id_from_type(tx.first.token_metadata.asset_type); + if (!num_rct_outs_by_asset_type.add_asset_type(asset_type_id)) + throw std::runtime_error("Failed to add asset_type '" + tx.first.token_metadata.asset_type + "' to RCT outputs"); + */ + } + // Is this a STAKE TX? if (tx.first.type == cryptonote::transaction_type::STAKE) { yield_total += tx.first.amount_burnt; @@ -420,7 +451,7 @@ uint64_t BlockchainDB::add_block( const std::pair& blck // call out to subclass implementation to add the block & metadata time1 = epee::misc_utils::get_tick_count(); - add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, num_rct_outs, num_rct_outs_by_asset_type, blk_hash, slippage_total, yield_total, audit_total, nettype, ybi, abi); + add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, num_rct_outs, num_rct_outs_by_asset_type, blk_hash, slippage_total, yield_total, audit_total, token_total, nettype, ybi, abi); TIME_MEASURE_FINISH(time1); time_add_block1 += time1; diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 2da1559f4..28916fe03 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -218,6 +218,18 @@ typedef struct yield_tx_info_carrot { carrot::encrypted_janus_anchor_t return_anchor_enc; } yield_tx_info_carrot; +typedef struct token_tx_info_carrot { + uint64_t block_height; + uint8_t version; + crypto::hash tx_hash; + uint64_t locked_coins; + crypto::public_key return_address; + crypto::public_key return_pubkey; + carrot::view_tag_t return_view_tag; + carrot::encrypted_janus_anchor_t return_anchor_enc; + uint32_t asset_type_id; +} token_tx_info_carrot; + #define DBF_SAFE 1 #define DBF_FAST 2 #define DBF_FASTEST 4 @@ -437,11 +449,12 @@ private: const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated, uint64_t num_rct_outs, - oracle::asset_type_counts& cum_rct_by_asset_type, + oracle::asset_type_counts_v2& cum_rct_by_asset_type, const crypto::hash& blk_hash, uint64_t slippage_total, uint64_t yield_total, uint64_t audit_total, + uint64_t token_total, const cryptonote::network_type nettype, cryptonote::yield_block_info& ybi, cryptonote::audit_block_info& abi @@ -1212,6 +1225,20 @@ public: virtual std::map get_circulating_supply() const = 0; + /** + * @brief fetch the tokens from the blockchain + * + * @return the current token values + */ + virtual std::map get_tokens() const = 0; + + /** + * @brief determine if a TX has been paid for + * + * @return the current token values + */ + virtual bool is_tx_paid_for(const cryptonote::transaction& tx) const = 0; + /** *