Skip to content

Commit

Permalink
the length of the memo when transferring the box is limited #314
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynarov committed Mar 18, 2020
1 parent ff8aca3 commit 7e8f446
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions common/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ static constexpr int64_t blocks_per_year = int64_t(365)*24*60*60*1000/block_inte

static const std::string retire_memo = "retire";

static constexpr size_t max_memo_size = 384;
static constexpr char memo_error[] = "memo has more than 384 bytes";

} // config

constexpr int64_t time_to_blocks(int64_t time) {
Expand Down
1 change: 1 addition & 0 deletions cyber.box/src/cyber.box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void box::burn(name contract, name treasurer, name title) {

void box::transfer(name contract, name treasurer, name title, name from, name to, std::string memo) {
eosio::check(is_account(to), "to account does not exist");
eosio::check(memo.size() <= config::max_memo_size, config::memo_error);
boxes boxes_table(_self, treasurer.value);
auto boxes_idx = boxes_table.get_index<"bykey"_n>();
auto box_itr = boxes_idx.find({contract, title});
Expand Down
3 changes: 2 additions & 1 deletion cyber.token/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ install_contract(cyber.token)

target_include_directories(cyber.token.wasm
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/..)

set_target_properties(cyber.token.wasm
PROPERTIES
Expand Down
12 changes: 4 additions & 8 deletions cyber.token/src/cyber.token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

#include <eosio/event.hpp>
#include <cyber.token/cyber.token.hpp>
#include <common/config.hpp>
#include <set>

namespace eosio {

namespace config {
static constexpr size_t max_memo_size = 384;
static constexpr char memo_error[] = "memo has more than 384 bytes";
}

void token::send_currency_event(const currency_stats& stat) {
eosio::event(_self, "currency"_n, stat).send();
}
Expand Down Expand Up @@ -52,7 +48,7 @@ void token::issue( name to, asset quantity, string memo )
{
auto sym = quantity.symbol;
eosio::check( sym.is_valid(), "invalid symbol name" );
eosio::check( memo.size() <= config::max_memo_size, config::memo_error );
eosio::check( memo.size() <= cyber::config::max_memo_size, cyber::config::memo_error );

stats statstable( _self, sym.code().raw() );
auto existing = statstable.find( sym.code().raw() );
Expand Down Expand Up @@ -84,7 +80,7 @@ void token::retire( asset quantity, string memo )
{
auto sym = quantity.symbol;
eosio::check( sym.is_valid(), "invalid symbol name" );
eosio::check( memo.size() <= config::max_memo_size, config::memo_error );
eosio::check( memo.size() <= cyber::config::max_memo_size, cyber::config::memo_error );

stats statstable( _self, sym.code().raw() );
auto existing = statstable.find( sym.code().raw() );
Expand Down Expand Up @@ -140,7 +136,7 @@ void token::do_transfer( name from,
eosio::check( quantity.is_valid(), "invalid quantity" );
eosio::check( quantity.amount > 0, "must transfer positive quantity" );
eosio::check( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
eosio::check( memo.size() <= config::max_memo_size, config::memo_error );
eosio::check( memo.size() <= cyber::config::max_memo_size, cyber::config::memo_error );

auto payer = has_auth( to ) ? to : from;

Expand Down

0 comments on commit 7e8f446

Please sign in to comment.