Skip to content

Commit

Permalink
Merge branch 'master' into feature/modify_decau
Browse files Browse the repository at this point in the history
  • Loading branch information
n13 authored Mar 29, 2024
2 parents 6e2b85a + 585b6ac commit 0c21143
Show file tree
Hide file tree
Showing 4 changed files with 40 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 @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion src/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 );

update_issued(tenant, -1 * quantity);
}


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

Please sign in to comment.