Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Adding memo to transfer type #248 #249

Merged
merged 3 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion libraries/chain/chain_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,17 @@ void chain_controller::check_transaction_authorization(const SignedTransaction&
}

void chain_controller::validate_scope( const Transaction& trx )const {
EOS_ASSERT(trx.scope.size() > 0, transaction_exception, "No scope specified by transaction" );
EOS_ASSERT(trx.scope.size() + trx.readscope.size() > 0, transaction_exception, "No scope specified by transaction" );
for( uint32_t i = 1; i < trx.scope.size(); ++i )
EOS_ASSERT( trx.scope[i-1] < trx.scope[i], transaction_exception, "Scopes must be sorted and unique" );
for( uint32_t i = 1; i < trx.readscope.size(); ++i )
EOS_ASSERT( trx.readscope[i-1] < trx.readscope[i], transaction_exception, "Scopes must be sorted and unique" );

vector<types::AccountName> intersection;
std::set_intersection( trx.scope.begin(), trx.scope.end(),
trx.readscope.begin(), trx.readscope.end(),
std::back_inserter(intersection) );
FC_ASSERT( intersection.size() == 0, "a transaction may not redeclare scope in readscope" );
}

const permission_object& chain_controller::lookup_minimum_permission(types::AccountName authorizer_account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ std::vector<chain::Message> native_contract_chain_initializer::prepare_database(
message = chain::Message(config::EosContractName,
vector<types::AccountPermission>{{config::EosContractName, "active"}},
"transfer", types::transfer(config::EosContractName, acct.name,
acct.liquid_balance.amount/*, "Genesis Allocation"*/));
acct.liquid_balance.amount, "Genesis Allocation"));
messages_to_process.emplace_back(std::move(message));
}
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/types/include/eos/types/Asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <eos/types/native.hpp>

/// eos with 8 digits of precision
#define EOS_SYMBOL (int64_t(8) | (uint64_t('E') << 8) | (uint64_t('O') << 16) | (uint64_t('S') << 24))
#define EOS_SYMBOL (int64_t(5) | (uint64_t('E') << 8) | (uint64_t('O') << 16) | (uint64_t('S') << 24))

/// Defined to be largest power of 10 that fits in 53 bits of precision
#define EOS_MAX_SHARE_SUPPLY int64_t(1000000000000000ll)
#define EOS_MAX_SHARE_SUPPLY int64_t(1'000'000'000'000'000ll)

namespace eos { namespace types {

Expand Down
2 changes: 2 additions & 0 deletions libraries/types/types.eos
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct Transaction
refBlockPrefix UInt32
expiration Time
scope AccountName[] # the data may be accessed while processing this transaction
readscope AccountName[]
messages Message[]

struct SignedTransaction inherits Transaction
Expand Down Expand Up @@ -71,6 +72,7 @@ struct transfer
from AccountName # may not be the message.sender if message.sender has delegated authority by from
to AccountName
amount UInt64
memo String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should limit the size of the string. Currently, this is a std::string.


struct lock
from AccountName
Expand Down
8 changes: 6 additions & 2 deletions programs/eosc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,20 @@ int send_command (const vector<string> &cmd_line)
std::cout << fc::json::to_pretty_string( push_transaction(trx) ) << std::endl;

} else if( command == "transfer" ) {
FC_ASSERT( cmd_line.size() == 4 );
FC_ASSERT( cmd_line.size() >= 4 );

Name sender(cmd_line[1]);
Name recipient(cmd_line[2]);
uint64_t amount = fc::variant(cmd_line[3]).as_uint64();

string memo = "";
if( cmd_line.size() > 4 )
memo = cmd_line[4];

SignedTransaction trx;
trx.scope = sort_names({sender,recipient});
transaction_helpers::emplace_message(trx, config::EosContractName, vector<types::AccountPermission>{{sender,"active"}}, "transfer",
types::transfer{sender, recipient, amount});
types::transfer{sender, recipient, amount, memo});
auto info = get_info();
trx.expiration = info.head_block_time + 100; //chain.head_block_time() + 100;
transaction_helpers::set_reference_block(trx, info.head_block_id);
Expand Down
2 changes: 1 addition & 1 deletion tests/common/macro_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ inline std::vector<Name> sort_names( std::vector<Name>&& names ) {
trx.scope = sort_names({#sender,#recipient}); \
transaction_helpers::emplace_message(trx, config::EosContractName, \
vector<types::AccountPermission>{ {#sender,"active"} }, \
"transfer", types::transfer{#sender, #recipient, Amount.amount}); \
"transfer", types::transfer{#sender, #recipient, Amount.amount, memo}); \
trx.expiration = chain.head_block_time() + 100; \
transaction_helpers::set_reference_block(trx, chain.head_block_id()); \
chain.push_transaction(trx); \
Expand Down
8 changes: 4 additions & 4 deletions tests/slow_tests/slow_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void TransferCurrency( testing_blockchain& chain, AccountName from, AccountName
trx.scope = sort_names({from,to});
transaction_helpers::emplace_message(trx, "currency",
vector<types::AccountPermission>{ {from,"active"} },
"transfer", types::transfer{from, to, amount});
"transfer", types::transfer{from, to, amount,""});

trx.expiration = chain.head_block_time() + 100;
transaction_helpers::set_reference_block(trx, chain.head_block_id());
Expand All @@ -324,7 +324,7 @@ void WithdrawCurrency( testing_blockchain& chain, AccountName from, AccountName
trx.scope = sort_names({from,to});
transaction_helpers::emplace_message(trx, "currency",
vector<types::AccountPermission>{ {from,"active"},{to,"active"} },
"transfer", types::transfer{from, to, amount});
"transfer", types::transfer{from, to, amount,""});
trx.expiration = chain.head_block_time() + 100;
transaction_helpers::set_reference_block(trx, chain.head_block_id());
chain.push_transaction(trx);
Expand Down Expand Up @@ -367,7 +367,7 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
trx.scope = sort_names({"currency","inita"});
transaction_helpers::emplace_message(trx, "currency",
vector<types::AccountPermission>{ {"currency","active"} },
"transfer", types::transfer{"currency", "inita", 1+i});
"transfer", types::transfer{"currency", "inita", 1+i,""});
trx.expiration = chain.head_block_time() + 100;
transaction_helpers::set_reference_block(trx, chain.head_block_id());
//idump((trx));
Expand Down Expand Up @@ -1167,7 +1167,7 @@ BOOST_FIXTURE_TEST_CASE(create_script_w_loop, testing_fixture)
trx.scope = sort_names({"currency","inita"});
transaction_helpers::emplace_message(trx, "currency",
vector<types::AccountPermission>{ {"currency","active"} },
"transfer", types::transfer{"currency", "inita", 1});
"transfer", types::transfer{"currency", "inita", 1,""});
trx.expiration = chain.head_block_time() + 100;
transaction_helpers::set_reference_block(trx, chain.head_block_id());
try
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ BOOST_FIXTURE_TEST_CASE(trx_variant, testing_fixture) {
trx.scope = sort_names({from,to});
transaction_helpers::emplace_message(trx, "eos",
vector<types::AccountPermission>{ {from,"active"} },
"transfer", types::transfer{from, to, amount/*, ""*/});
"transfer", types::transfer{from, to, amount, ""});
trx.expiration = chain.head_block_time() + 100;
transaction_helpers::set_reference_block(trx, chain.head_block_id());

Expand Down Expand Up @@ -180,7 +180,7 @@ BOOST_FIXTURE_TEST_CASE(irrelevant_auth, testing_fixture) {
ProcessedTransaction trx;
trx.scope = sort_names({"joe", "inita"});
transaction_helpers::emplace_message(trx, config::EosContractName, vector<types::AccountPermission>{{"inita", "active"}},
"transfer", types::transfer{"inita", "joe", 50});
"transfer", types::transfer{"inita", "joe", 50,""});
trx.expiration = chain.head_block_time() + 100;
transaction_helpers::set_reference_block(trx, chain.head_block_id());
chain.push_transaction(trx, chain_controller::skip_transaction_signatures);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/native_contract_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture)
trx.expiration = chain.head_block_time() + 100;
trx.scope = sort_names( {"inita", "initb"} );

types::transfer trans = { "inita", "initb", (100) };
types::transfer trans = { "inita", "initb", (100), "" };

UInt64 value(5);
auto packed = fc::raw::pack(value);
Expand Down