Skip to content

Commit

Permalink
remembering the original block hash upon asset unregistration and res…
Browse files Browse the repository at this point in the history
…toring it with the asset whenever that unregistration gets unprocessed
  • Loading branch information
gevorgvoskanyan committed Feb 17, 2025
1 parent 1ac9cfe commit 59b03ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/spats/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 );
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
31 changes: 25 additions & 6 deletions src/spats/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 59b03ce

Please sign in to comment.