Skip to content

Commit

Permalink
adding burn feature
Browse files Browse the repository at this point in the history
note: I removed decay from sub_balance - that was a bug. add_balance also shouldn't have decay built in... it's a weird side effect
  • Loading branch information
n13 committed Mar 12, 2024
1 parent 4705172 commit ab2a4c9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.28)
project(voice.hypha)

include(ExternalProject)
Expand Down
14 changes: 14 additions & 0 deletions include/voice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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);
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmake_minimum_required(VERSION 3.28)
project(voice-hypha-build)
set(EOSIO_WASM_OLD_BEHAVIOR "Off")
find_package(eosio.cdt)
Expand Down
23 changes: 22 additions & 1 deletion src/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ 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<name("bykey")>();
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 );
}


void voice::decay(const name& tenant, const name& owner, symbol symbol) {
stats statstable( get_self(), symbol.code().raw() );
Expand Down Expand Up @@ -209,7 +231,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<name("bykey")>();

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cmake_minimum_required(VERSION 3.28)
project(voice.hypha.tests)
find_package(eosio.cdt)

Expand Down

0 comments on commit ab2a4c9

Please sign in to comment.