diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f8bbb9..52c5167 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.28) project(voice.hypha) include(ExternalProject) diff --git a/include/voice.hpp b/include/voice.hpp index 3892bbc..354cb38 100644 --- a/include/voice.hpp +++ b/include/voice.hpp @@ -96,6 +96,20 @@ class [[eosio::contract("voice.hypha")]] voice : public eosio::contract { const asset& quantity, const string& memo ); + /** + * Allows `to` account to burn `quantity` tokens. The tokens are destroyed and removed + * from the stats table and the account. + * + * @param from - the account to burn tokens from, + * @param quantity - the quantity of tokens to be transferred, + * @param memo - the memo string to accompany the transaction. + */ + [[eosio::action]] + void burn( const name& tenant, + const name& from, + const asset& quantity, + const string& memo ); + // Runs decaying actions ACTION decay(const name& tenant, const name& owner, symbol symbol); diff --git a/src/voice.cpp b/src/voice.cpp index a4770d2..d656132 100644 --- a/src/voice.cpp +++ b/src/voice.cpp @@ -209,6 +209,30 @@ namespace hypha { sub_balance( tenant, from, quantity ); add_balance( tenant, to, quantity, payer ); } + + void voice::burn( const name& tenant, + const name& from, + const asset& quantity, + const string& memo ) + { + require_auth( from ); + auto sym = quantity.symbol.code(); + stats statstable( get_self(), sym.raw() ); + auto index = statstable.get_index(); + const auto& st = index.get( currency_statsv2::build_key(tenant, sym) ); + + require_recipient( from ); + + check( quantity.is_valid(), "invalid quantity" ); + check( quantity.amount > 0, "must burn positive quantity" ); + check( quantity.symbol == st.supply.symbol, "symbol precision mismatch" ); + check( memo.size() <= 256, "memo has more than 256 bytes" ); + + sub_balance( tenant, from, quantity ); + + update_issued(tenant, -1 * quantity); + } + void voice::decay(const name& tenant, const name& owner, symbol symbol) { stats statstable( get_self(), symbol.code().raw() ); @@ -261,7 +285,6 @@ namespace hypha { } void voice::sub_balance(const name& tenant, const name& owner, const asset& value ) { - this->decay(tenant, owner, value.symbol); accounts from_acnts( get_self(), owner.value ); auto index = from_acnts.get_index(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d7d97d2..741c9f3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,4 @@ +cmake_minimum_required(VERSION 3.28) project(voice.hypha.tests) find_package(eosio.cdt)