From 59b03ceff23734943be311ae81b2d32691cc41aa Mon Sep 17 00:00:00 2001 From: Gevorg Voskanyan Date: Mon, 17 Feb 2025 23:37:35 +0400 Subject: [PATCH] remembering the original block hash upon asset unregistration and restoring it with the asset whenever that unregistration gets unprocessed --- src/spats/registry.cpp | 8 ++++---- src/spats/registry.hpp | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/spats/registry.cpp b/src/spats/registry.cpp index fc4265d496..6b2744b1f1 100644 --- a/src/spats/registry.cpp +++ b/src/spats/registry.cpp @@ -117,7 +117,7 @@ bool Registry::process( const UnregisterAssetParameters &p, int block_height, co const auto it = fungible_assets_.find( p.asset_type() ); if ( it != fungible_assets_.end() ) { if ( block_height >= 0 ) - unregistered_assets_.push_back( { block_height, std::move( it->second ) } ); + unregistered_assets_.emplace_back( block_height, std::move( it->second ) ); fungible_assets_.erase( it ); return true; } @@ -132,7 +132,7 @@ bool Registry::process( const UnregisterAssetParameters &p, int block_height, co if ( nft_it == it->second.end() ) return false; if ( block_height >= 0 ) - unregistered_assets_.push_back( { block_height, std::move( nft_it->second ) } ); + unregistered_assets_.emplace_back( block_height, std::move( nft_it->second ) ); it->second.erase( nft_it ); if ( it->second.empty() ) nft_lines_.erase( it ); @@ -141,7 +141,7 @@ bool Registry::process( const UnregisterAssetParameters &p, int block_height, co if ( block_height >= 0 ) for ( auto &[ t, a ] : it->second ) - unregistered_assets_.push_back( { block_height, std::move( a ) } ); + unregistered_assets_.emplace_back( block_height, std::move( a ) ); nft_lines_.erase( it ); return true; } @@ -212,7 +212,7 @@ bool Registry::unprocess( const UnregisterAssetParameters &p, int block_height, unregistered_identifier_match( get_identifier( x.asset ), p.identifier() ); } ), it != unregistered_assets_.end() ) { - process( it->asset, -1, {}, wlp ); + process( it->asset, -1, it->block_annotation.block_hash, wlp ); it = unregistered_assets_.erase( it ); any_changes = true; } diff --git a/src/spats/registry.hpp b/src/spats/registry.hpp index d18beb7ad7..e29cfe3a05 100644 --- a/src/spats/registry.hpp +++ b/src/spats/registry.hpp @@ -62,18 +62,37 @@ class Registry { #endif }; - struct UnregisteredAsset { - int block_height_unregistered_at; - SparkAsset asset; - // BlockAnnotation block_annotation;//TODO - }; - template < typename T > struct BlockAnnotated : T, BlockAnnotation { BlockAnnotated( T t, std::optional< block_hash_t > blockhash ) : T( std::move( t ) ) , BlockAnnotation{ std::move( blockhash ) } {} + + T &asset() noexcept { return *this; } + const T &asset() const noexcept { return *this; } + + BlockAnnotation &annotation() noexcept { return *this; } + const BlockAnnotation &annotation() const noexcept { return *this; } + }; + + struct UnregisteredAsset { + int block_height_unregistered_at; + SparkAsset asset; + BlockAnnotation block_annotation; + + UnregisteredAsset( int block_height, SparkAsset asset, BlockAnnotation block_annotation ) + : block_height_unregistered_at( block_height ) + , asset( std::move( asset ) ) + , block_annotation( std::move( block_annotation ) ) + {} + + template < typename T > + UnregisteredAsset( int block_height, BlockAnnotated< T > &&asset ) + : block_height_unregistered_at( block_height ) + , asset( std::move( asset.asset() ) ) + , block_annotation( std::move( asset.annotation() ) ) + {} }; mutable std::shared_mutex mutex_;