diff --git a/multy_core/CMakeLists.txt b/multy_core/CMakeLists.txt index 94119be..0a03da1 100644 --- a/multy_core/CMakeLists.txt +++ b/multy_core/CMakeLists.txt @@ -128,8 +128,9 @@ if (MULTY_WITH_EOS) src/eos/eos_name.cpp src/eos/eos_transaction.cpp src/eos/eos_transaction_action.cpp - src/eos/eos_transaction_builder_updateauth.cpp src/eos/eos_transaction_transfer_action.cpp + src/eos/eos_transaction_builder_updateauth.cpp + src/eos/eos_transaction_builder_transfer.cpp ) endif() diff --git a/multy_core/eos.h b/multy_core/eos.h index 8534cf8..93961fd 100644 --- a/multy_core/eos.h +++ b/multy_core/eos.h @@ -27,6 +27,7 @@ const std::array EOS_TOKEN_NAME = {0x45, 0x4f, 0x53, 0x00, 0x00, 0x0 enum EosTransactionBuilderType { EOS_TRANSACTION_BUILDER_UPDATEAUTH, + EOS_TRANSACTION_BUILDER_TRANSFER, }; #ifdef __cplusplus diff --git a/multy_core/src/eos/eos_binary_stream.cpp b/multy_core/src/eos/eos_binary_stream.cpp index 356e862..f398e67 100644 --- a/multy_core/src/eos/eos_binary_stream.cpp +++ b/multy_core/src/eos/eos_binary_stream.cpp @@ -29,14 +29,6 @@ EosBinaryStream::EosBinaryStream() EosBinaryStream::~EosBinaryStream() {} -template -EosBinaryStream& write_as_data(const T& data, EosBinaryStream& stream) -{ - stream.write_data( - reinterpret_cast(&data), sizeof(data)); - return stream; -} - EosBinaryStream& operator<<(EosBinaryStream& stream, const EosTransactionAction& op) { op.write_to_stream(&stream); @@ -54,7 +46,9 @@ EosBinaryStream& operator<<(EosBinaryStream& stream, const BinaryData& value) EosBinaryStream& operator<<(EosBinaryStream& stream, const uint8_t& value) { - return write_as_data(value, stream); + stream.write_data(&value, 1); + + return stream; } EosBinaryStream& operator<<(EosBinaryStream& stream, const uint16_t& value) diff --git a/multy_core/src/eos/eos_binary_stream.h b/multy_core/src/eos/eos_binary_stream.h index 0830d28..5bb7635 100644 --- a/multy_core/src/eos/eos_binary_stream.h +++ b/multy_core/src/eos/eos_binary_stream.h @@ -28,6 +28,14 @@ class EosBinaryStream : public BinaryStream ~EosBinaryStream(); }; +template +EosBinaryStream& write_as_data(const T& data, EosBinaryStream& stream) +{ + stream.write_data( + reinterpret_cast(&data), sizeof(data)); + return stream; +} + EosBinaryStream& operator<<(EosBinaryStream& stream, const EosTransactionAction& op); EosBinaryStream& operator<<(EosBinaryStream& stream, const BinaryData& value); EosBinaryStream& operator<<(EosBinaryStream& stream, const uint8_t& value); diff --git a/multy_core/src/eos/eos_facade.cpp b/multy_core/src/eos/eos_facade.cpp index 51dec98..e22c004 100644 --- a/multy_core/src/eos/eos_facade.cpp +++ b/multy_core/src/eos/eos_facade.cpp @@ -17,6 +17,7 @@ #include "multy_core/src/eos/eos_account.h" #include "multy_core/src/eos/eos_transaction.h" #include "multy_core/src/eos/eos_transaction_builder_updateauth.h" +#include "multy_core/src/eos/eos_transaction_builder_transfer.h" #include @@ -86,6 +87,10 @@ TransactionBuilderPtr EosFacade::make_transaction_builder( EOS_TRANSACTION_BUILDER_UPDATEAUTH, &make_eos_transaction_builder_updateauth }, + { + EOS_TRANSACTION_BUILDER_TRANSFER, + &make_eos_transaction_builder_transfer + } }; const auto builder = BUILDERS.find(type); diff --git a/multy_core/src/eos/eos_name.cpp b/multy_core/src/eos/eos_name.cpp index 3b14833..ce52dcc 100644 --- a/multy_core/src/eos/eos_name.cpp +++ b/multy_core/src/eos/eos_name.cpp @@ -82,7 +82,8 @@ EosName::EosName() } EosName::EosName(const std::string& name) - : m_data(name_string_to_uint64(name)) + : m_data(name_string_to_uint64(name)), + m_data_string(name) { } @@ -97,7 +98,8 @@ uint64_t EosName::get_data() const std::string EosName::get_string() const { - THROW_EXCEPTION2(ERROR_FEATURE_NOT_IMPLEMENTED_YET, __FUNCTION__); + return m_data_string; + //THROW_EXCEPTION2(ERROR_FEATURE_NOT_IMPLEMENTED_YET, __FUNCTION__); } EosName EosName::from_string(const std::string& string) diff --git a/multy_core/src/eos/eos_name.h b/multy_core/src/eos/eos_name.h index d9f5503..a2efe54 100644 --- a/multy_core/src/eos/eos_name.h +++ b/multy_core/src/eos/eos_name.h @@ -32,6 +32,7 @@ class EosName private: // Non-const to make it copyable. uint64_t m_data; + std::string m_data_string; }; typedef EosName EosAddress; diff --git a/multy_core/src/eos/eos_transaction.cpp b/multy_core/src/eos/eos_transaction.cpp index 5e8662d..5f79e9f 100644 --- a/multy_core/src/eos/eos_transaction.cpp +++ b/multy_core/src/eos/eos_transaction.cpp @@ -46,6 +46,16 @@ const EosChainId EOS_MAINNET_CHAIN_ID = {0xac, 0xa3, 0x76, 0xf2, 0x06, 0xb8, 0xf const std::array EOS_ZERO_SHA256 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +void putVariableUInt(EosBinaryStream* stream, uint64_t value) +{ + do + { + uint8_t input = static_cast(value & 0x7f); + value >>= 7; + input |= ((value > 0 ? 1 : 0) << 7); + *stream << input; + } while(value); +} } // namespace @@ -95,26 +105,12 @@ class EosTransactionDestination : public TransactionDestinationBase EosTransaction::EosTransaction(const Account& account) : TransactionBase(account.get_blockchain_type()), m_account(account), - m_message(new BinaryData{nullptr, 0}), - m_source(), - m_destination(), - m_explicit_expiration( - get_transaction_properties(), - "expiration", - Property::OPTIONAL, - [this](const std::string& new_expiration) - { - this->set_expiration(new_expiration); - }), - m_ref_block_num( - get_transaction_properties(), - "block_num", - Property::REQUIRED), - m_ref_block_prefix( - get_transaction_properties(), - "ref_block_prefix", - Property::REQUIRED, - verify_smaller_than::max()>) + m_explicit_expiration(""), + m_ref_block_num(0), + m_ref_block_prefix(0), + m_max_net_usage_words(0), + m_max_cpu_usage_ms(0), + m_delay_seconds(0) { } @@ -133,26 +129,28 @@ void EosTransaction::verify() void EosTransaction::update() { + // TODO: переделать обновление, и дописать функцию verify там должна быть проверка чтобы был 100% actions и валидный + if (m_external_actions.empty()) { - if (!m_source) - { - THROW_EXCEPTION2(ERROR_TRANSACTION_NO_SOURCES, - "EOS transaction should have one source."); - } - - if (!m_destination) - { - THROW_EXCEPTION2(ERROR_TRANSACTION_NO_DESTINATIONS, - "EOS transaction should have one destination."); - } - - m_actions.clear(); - m_actions.push_back(EosTransactionActionPtr(new EosTransactionTransferAction( - *m_source->address, - *m_destination->address, - *m_destination->amount, - *m_message))); +// if (!m_source) +// { +// THROW_EXCEPTION2(ERROR_TRANSACTION_NO_SOURCES, +// "EOS transaction should have one source."); +// } + +// if (!m_destination) +// { +// THROW_EXCEPTION2(ERROR_TRANSACTION_NO_DESTINATIONS, +// "EOS transaction should have one destination."); +// } + +// m_actions.clear(); +// m_actions.push_back(EosTransactionActionPtr(new EosTransactionTransferAction( +// *m_source->address, +// *m_destination->address, +// *m_destination->amount, +// *m_message))); } sign(); @@ -221,13 +219,13 @@ void EosTransaction::serialize_to_stream(EosBinaryStream& stream, SerializationM } list << static_cast(m_expiration); // time as uint32_t - list << static_cast(static_cast(*m_ref_block_num)); + list << m_ref_block_num; uint32_t ref_block_prefix; - ref_block_prefix = static_cast(m_ref_block_prefix.get_value().get_value_as_uint64()); + ref_block_prefix = static_cast(m_ref_block_prefix.get_value_as_uint64()); list << ref_block_prefix; - list << static_cast(0x00); // max_net_usage_words, we set zero byte - list << static_cast(0x00); // max_cpu_usage_ms, we set zero byte - list << static_cast(0x00); // delay_seconds, we set zero byte + putVariableUInt(&list, m_max_net_usage_words); + putVariableUInt(&list, m_max_cpu_usage_ms); + putVariableUInt(&list, m_delay_seconds); list << static_cast(0x00); // size array context_free_actions and context_free_actions const auto& actions = m_external_actions.empty() ? m_actions : m_external_actions; @@ -237,7 +235,8 @@ void EosTransaction::serialize_to_stream(EosBinaryStream& stream, SerializationM list << *action; } - list << static_cast(0x00); + // TODO: implement transaction_extensions wher EOS will be suported it. + list << static_cast(0x00); // transaction_extensions It seems like that EOS deos not support any extensions yet. if (mode == SERIALIZE_FOR_SIGN) { @@ -254,13 +253,15 @@ BigInt EosTransaction::get_total_fee() const BigInt EosTransaction::get_total_spent() const { - if (!m_destination) - { - THROW_EXCEPTION("Failed to calculate total spent.") - << " Transaction has no destinations."; - } - - return *m_destination->amount; + THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED, + "Don't implimented yat."); +// if (!m_destination) +// { +// THROW_EXCEPTION("Failed to calculate total spent.") +// << " Transaction has no destinations."; +// } + +// return *m_destination->amount; } BigInt EosTransaction::estimate_total_fee( @@ -272,30 +273,36 @@ BigInt EosTransaction::estimate_total_fee( Properties& EosTransaction::add_source() { - if (m_source) - { - THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_SOURCES, - "EOS transaction can have only one source."); - } + THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED, + "EOS transaction don't have destination."); + +// if (m_source) +// { +// THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_SOURCES, +// "EOS transaction can have only one source."); +// } - m_source = EosTransactionSourcePtr(new EosTransactionSource( - get_blockchain_type())); +// m_source = EosTransactionSourcePtr(new EosTransactionSource( +// get_blockchain_type())); - return m_source->get_properties(); +// return m_source->get_properties(); } Properties& EosTransaction::add_destination() { - if (m_destination) - { - THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_DESTINATIONS, - "EOS transaction can have only one destination."); - } + THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED, + "EOS transaction don't have destination."); - m_destination = EosTransactionDestinationPtr( - new EosTransactionDestination(get_blockchain_type())); +// if (m_destination) +// { +// THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_DESTINATIONS, +// "EOS transaction can have only one destination."); +// } - return m_destination->get_properties(); +// m_destination = EosTransactionDestinationPtr( +// new EosTransactionDestination(get_blockchain_type())); + +// return m_destination->get_properties(); } Properties& EosTransaction::get_fee() @@ -304,25 +311,53 @@ Properties& EosTransaction::get_fee() "EOS transaction fee is not customizable."); } -void EosTransaction::set_message(const BinaryData& payload) +void EosTransaction::set_message(const BinaryData& /*payload*/) { - INVARIANT(payload.data != nullptr); - if (payload.len > 255) - { - THROW_EXCEPTION2(ERROR_TRANSACTION_PAYLOAD_TO_BIG, "Message is to big.") - << " Max message size is 255 bytes," - << " got: " << payload.len << " bytes."; - } - - m_message = make_clone(payload); + THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED, + "Use actions to set message in transaction."); +//) INVARIANT(payload.data != nullptr); +// if (payload.len > 255) +// { +// THROW_EXCEPTION2(ERROR_TRANSACTION_PAYLOAD_TO_BIG, "Message is to big.") +// << " Max message size is 255 bytes," +// << " got: " << payload.len << " bytes."; +// } + +// m_message = make_clone(payload); } void EosTransaction::set_action(EosTransactionActionPtr action) { INVARIANT(action != nullptr); + // Now we implimented only with one action m_external_actions.emplace_back(std::move(action)); } +void EosTransaction::set_max_net_usage(const uint64_t max_net_usage_words) +{ + m_max_net_usage_words = max_net_usage_words; +} + +void EosTransaction::set_max_cpu_usage(const uint64_t max_cpu_usage_ms) +{ + m_max_cpu_usage_ms = max_cpu_usage_ms; +} + +void EosTransaction::set_delay_seconds(const uint64_t delay_seconds) +{ + m_delay_seconds = delay_seconds; +} + +void EosTransaction::set_ref_block_num(const uint16_t ref_block_num) +{ + m_ref_block_num = ref_block_num; +} + +void EosTransaction::set_ref_block_prefix(const BigInt ref_block_prefix) +{ + m_ref_block_prefix = ref_block_prefix; +} + } // namespace internal } // namespace multy_core diff --git a/multy_core/src/eos/eos_transaction.h b/multy_core/src/eos/eos_transaction.h index 30de883..9fb6eaa 100644 --- a/multy_core/src/eos/eos_transaction.h +++ b/multy_core/src/eos/eos_transaction.h @@ -50,10 +50,17 @@ class EosTransaction : public TransactionBase Properties& add_source() override; Properties& add_destination() override; Properties& get_fee() override; - void set_message(const BinaryData& payload) override; + void set_message(const BinaryData& /*payload*/) override; + void add_action(); // Ownership is transferred from caller to EosTransaction. + void set_ref_block_num(const uint16_t ref_block_num); + void set_ref_block_prefix(const BigInt ref_block_prefix); void set_action(EosTransactionActionPtr action); + void set_max_net_usage(const uint64_t max_net_usage_words); + void set_max_cpu_usage(const uint64_t max_cpu_usage_ms); + void set_delay_seconds(const uint64_t delay_seconds); + void set_expiration(const std::string& new_expiration); private: enum SerializationMode @@ -62,24 +69,29 @@ class EosTransaction : public TransactionBase SERIALIZE_FOR_SIGN }; void verify(); - void set_expiration(const std::string&); void serialize_to_stream(EosBinaryStream& stream, SerializationMode mode) const; private: const Account& m_account; - BinaryDataPtr m_message; - EosTransactionSourcePtr m_source; - EosTransactionDestinationPtr m_destination; + std::string m_explicit_expiration; + uint16_t m_ref_block_num; + BigInt m_ref_block_prefix; + + uint64_t m_max_net_usage_words; + uint64_t m_max_cpu_usage_ms; + uint64_t m_delay_seconds; + + std::vector context_free_action; + +// BinaryDataPtr m_message; +// EosTransactionSourcePtr m_source; +// EosTransactionDestinationPtr m_destination; std::vector m_external_actions; // TODO: make a TxBuilder for transfer operation and get rid of this, // since it is going to be set from TX builder as external_action. std::vector m_actions; - PropertyT m_explicit_expiration; - PropertyT m_ref_block_num; - PropertyT m_ref_block_prefix; - std::time_t m_expiration; BinaryDataPtr m_signature; }; diff --git a/multy_core/src/eos/eos_transaction_builder_transfer.cpp b/multy_core/src/eos/eos_transaction_builder_transfer.cpp new file mode 100644 index 0000000..725e5c5 --- /dev/null +++ b/multy_core/src/eos/eos_transaction_builder_transfer.cpp @@ -0,0 +1,146 @@ +/* Copyright 2018 by Multy.io + * Licensed under Multy.io license. + * + * See LICENSE for details + */ + +#include "multy_core/src/eos/eos_transaction_builder_transfer.h" + +#include "multy_core/error.h" + +#include "multy_core/src/eos/eos_name.h" +#include "multy_core/src/eos/eos_transaction_transfer_action.h" +#include "multy_core/src/eos/eos_transaction.h" + +#include "multy_core/src/api/transaction_builder_impl.h" +#include "multy_core/src/api/account_impl.h" +#include "multy_core/src/api/properties_impl.h" +#include "multy_core/src/api/key_impl.h" +#include "multy_core/src/error_utility.h" +#include "multy_core/src/u_ptr.h" +#include "multy_core/src/utility.h" + +#include +#include + +namespace +{ +using namespace multy_core::internal; + +// Makes a transaction that replaces user keys in blockchain. +// takes in new private key, +struct EosTransactionBuilderTransfer : public TransactionBuilder +{ + typedef std::unique_ptr EosTransactionPtr; + + EosTransactionBuilderTransfer(const Account& account) + : m_account(account), + m_properties( + ERROR_SCOPE_TRANSACTION_BUILDER, + "EOS transfer Tx builder"), + m_from( + get_properties(), + "from", + &EosAddress::from_string, + &EosAddress::to_string, + Property::REQUIRED), + m_to( + get_properties(), + "to", + &EosAddress::from_string, + &EosAddress::to_string, + Property::REQUIRED), + m_explicit_expiration( + get_properties(), + "expiration", + Property::OPTIONAL + ), + m_ref_block_num( + get_properties(), + "block_num", + Property::REQUIRED), + m_ref_block_prefix( + get_properties(), + "ref_block_prefix", + Property::REQUIRED), + m_balance( + get_properties(), + "balance", + Property::REQUIRED), + m_amount( + get_properties(), + "amount", + Property::REQUIRED), + m_memo( + BinaryDataPtr(new BinaryData{nullptr, 0}), + get_properties(), + "memo", + Property::OPTIONAL) + //m_new_private_key(m_properties, "", Property::REQUIRED) + {} + + TransactionPtr make_transaction() const override + { + EosTransactionPtr transaction(new EosTransaction(m_account)); + transaction->set_expiration(m_explicit_expiration.get_value()); + + const u_int16_t ref_block_num = static_cast(m_ref_block_num.get_value()); + transaction->set_ref_block_num(ref_block_num); + transaction->set_ref_block_prefix(m_ref_block_prefix.get_value()); + + transaction->set_max_net_usage(0); + transaction->set_max_cpu_usage(0); + transaction->set_delay_seconds(0); + + + { + transaction->set_action(EosTransactionActionPtr(new EosTransactionTransferAction( + EosAddress::to_string(*m_from), + EosAddress::to_string(*m_to), + m_amount.get_value(), + *(m_memo.get_value())))); + } + return TransactionPtr(transaction.release()); + } + + void validate() const override + { + m_properties.validate(MULTY_CODE_LOCATION); + } + + Properties& get_properties() override + { + return m_properties; + } + +public: + const Account& m_account; + + Properties m_properties; + FunctionalPropertyT m_from; + FunctionalPropertyT m_to; + PropertyT m_explicit_expiration; + PropertyT m_ref_block_num; + PropertyT m_ref_block_prefix; + PropertyT m_balance; + PropertyT m_amount; + PropertyT m_memo; + +}; + +} // namespace + +namespace multy_core +{ +namespace internal +{ + +TransactionBuilderPtr make_eos_transaction_builder_transfer( + const Account& account, + const std::string& /*action*/) +{ + return TransactionBuilderPtr{new EosTransactionBuilderTransfer(account)}; +} + +} // namespace internal +} // namespace multy_core diff --git a/multy_core/src/eos/eos_transaction_builder_transfer.h b/multy_core/src/eos/eos_transaction_builder_transfer.h new file mode 100644 index 0000000..0169689 --- /dev/null +++ b/multy_core/src/eos/eos_transaction_builder_transfer.h @@ -0,0 +1,29 @@ +/* Copyright 2018 by Multy.io + * Licensed under Multy.io license. + * + * See LICENSE for details + */ + +#ifndef MULTY_CORE_SRC_EOS_TRANSACTION_BUILDER_TRANSFER_H +#define MULTY_CORE_SRC_EOS_TRANSACTION_BUILDER_TRANSFER_H + +#include "multy_core/src/u_ptr.h" + +#include + +struct Account; + +namespace multy_core +{ +namespace internal +{ + +TransactionBuilderPtr make_eos_transaction_builder_transfer( + const Account& account, + const std::string& action); + +} // namespace internal +} // namespace multy_core + + +#endif // MULTY_CORE_SRC_EOS_TRANSACTION_BUILDER_TRANSFER_H diff --git a/multy_test/test_eos_transaction.cpp b/multy_test/test_eos_transaction.cpp index da35651..9705217 100644 --- a/multy_test/test_eos_transaction.cpp +++ b/multy_test/test_eos_transaction.cpp @@ -7,6 +7,8 @@ #include "multy_core/properties.h" #include "multy_core/transaction.h" #include "multy_core/big_int.h" +#include "multy_core/transaction_builder.h" +#include "multy_core/eos.h" #include "multy_test/supported_blockchains.h" @@ -32,46 +34,42 @@ GTEST_TEST(EosTransactionTest, SmokeTest_testnet_1) "5JViCsGPFdFBUxzsLzXyYX4XdSuovADMFdkucEzTkioMSVK9NPG", reset_sp(account))); - TransactionPtr transaction; - HANDLE_ERROR(make_transaction(account.get(), reset_sp(transaction))); - ASSERT_NE(nullptr, transaction); + TransactionBuilderPtr builder; + HANDLE_ERROR(make_transaction_builder(account.get(), + EOS_TRANSACTION_BUILDER_TRANSFER, + "", + reset_sp(builder))); + EXPECT_NE(nullptr, builder); { - Properties* properties = nullptr; + Properties* builder_properties = nullptr; + HANDLE_ERROR(transaction_builder_get_properties(builder.get(), &builder_properties)); + const int32_t block_num(6432047); BigIntPtr ref_block_prefix; const std::string expiration("2018-07-19T16:35:07Z"); // + 30s - HANDLE_ERROR(make_big_int("262535889", reset_sp(ref_block_prefix))); - HANDLE_ERROR(transaction_get_properties(transaction.get(), &properties)); - HANDLE_ERROR(properties_set_int32_value(properties, "block_num", block_num)); - HANDLE_ERROR(properties_set_big_int_value(properties, "ref_block_prefix", ref_block_prefix.get())); - HANDLE_ERROR(properties_set_string_value(properties, "expiration", expiration.c_str())); - } + HANDLE_ERROR(properties_set_int32_value(builder_properties, "block_num", block_num)); + HANDLE_ERROR(properties_set_big_int_value(builder_properties, "ref_block_prefix", ref_block_prefix.get())); + HANDLE_ERROR(properties_set_string_value(builder_properties, "expiration", expiration.c_str())); - { - Properties* source = nullptr; - HANDLE_ERROR(transaction_add_source(transaction.get(), &source)); - - // Address balance BigIntPtr balance; HANDLE_ERROR(make_big_int("20000", reset_sp(balance))); // balance = 2.0000 EOS - HANDLE_ERROR(properties_set_big_int_value(source, "amount", balance.get())); - HANDLE_ERROR(properties_set_string_value(source, "address", "pasha")); - } - - { - Properties* destination = nullptr; - HANDLE_ERROR(transaction_add_destination(transaction.get(), &destination)); + HANDLE_ERROR(properties_set_big_int_value(builder_properties, "balance", balance.get())); + HANDLE_ERROR(properties_set_string_value(builder_properties, "from", "pasha")); BigIntPtr amount; HANDLE_ERROR(make_big_int("10", reset_sp(amount))); // amount = 0.0010 EOS - HANDLE_ERROR(properties_set_big_int_value(destination, "amount", amount.get())); - HANDLE_ERROR(properties_set_string_value(destination, "address", "test.pasha")); + + HANDLE_ERROR(properties_set_big_int_value(builder_properties, "amount", amount.get())); + HANDLE_ERROR(properties_set_string_value(builder_properties, "to", "test.pasha")); } + TransactionPtr transaction; + HANDLE_ERROR(transaction_builder_make_transaction(builder.get(), reset_sp(transaction))); + // transaction_id = "6b24ce668ff02ecdd438f799012b83b0e8d1904bfb0cbadfce02fda3e78124ec" ConstCharPtr signatures; HANDLE_ERROR(transaction_serialize_encoded(transaction.get(), reset_sp(signatures))); @@ -89,52 +87,48 @@ GTEST_TEST(EosTransactionTest, SmokeTest_testnet_2) "5JViCsGPFdFBUxzsLzXyYX4XdSuovADMFdkucEzTkioMSVK9NPG", reset_sp(account))); - TransactionPtr transaction; - HANDLE_ERROR(make_transaction(account.get(), reset_sp(transaction))); - ASSERT_NE(nullptr, transaction); + TransactionBuilderPtr builder; + HANDLE_ERROR(make_transaction_builder(account.get(), + EOS_TRANSACTION_BUILDER_TRANSFER, + "", + reset_sp(builder))); + EXPECT_NE(nullptr, builder); - // transfer pasha test.pasha "1 EOS" "multy" { - Properties* properties = nullptr; + Properties* builder_propertie = nullptr; + HANDLE_ERROR(transaction_builder_get_properties(builder.get(), &builder_propertie)); + const int32_t block_num(13669); - const std::string expiration("2018-07-23T08:23:04Z"); // + 30s BigIntPtr ref_block_prefix; + const std::string expiration("2018-07-23T08:23:04Z"); // + 30s HANDLE_ERROR(make_big_int("2845038847", reset_sp(ref_block_prefix))); - HANDLE_ERROR(transaction_get_properties(transaction.get(), &properties)); - HANDLE_ERROR(properties_set_int32_value(properties, "block_num", block_num)); - HANDLE_ERROR(properties_set_big_int_value(properties, "ref_block_prefix", ref_block_prefix.get())); - HANDLE_ERROR(properties_set_string_value(properties, "expiration", expiration.c_str())); - } - { - Properties* source = nullptr; - HANDLE_ERROR(transaction_add_source(transaction.get(), &source)); + HANDLE_ERROR(properties_set_int32_value(builder_propertie, "block_num", block_num)); + HANDLE_ERROR(properties_set_big_int_value(builder_propertie, "ref_block_prefix", ref_block_prefix.get())); + HANDLE_ERROR(properties_set_string_value(builder_propertie, "expiration", expiration.c_str())); - // Address balance BigIntPtr balance; HANDLE_ERROR(make_big_int("20000", reset_sp(balance))); // balance = 2.0000 EOS - HANDLE_ERROR(properties_set_big_int_value(source, "amount", balance.get())); - HANDLE_ERROR(properties_set_string_value(source, "address", "pasha")); - } - - { - Properties* destination = nullptr; - HANDLE_ERROR(transaction_add_destination(transaction.get(), &destination)); + HANDLE_ERROR(properties_set_big_int_value(builder_propertie, "balance", balance.get())); + HANDLE_ERROR(properties_set_string_value(builder_propertie, "from", "pasha")); BigIntPtr amount; HANDLE_ERROR(make_big_int("10000", reset_sp(amount))); // amount = 1.0000 EOS - HANDLE_ERROR(properties_set_big_int_value(destination, "amount", amount.get())); - HANDLE_ERROR(properties_set_string_value(destination, "address", "test.pasha")); - } - { + HANDLE_ERROR(properties_set_big_int_value(builder_propertie, "amount", amount.get())); + HANDLE_ERROR(properties_set_string_value(builder_propertie, "to", "test.pasha")); + BinaryDataPtr message; make_binary_data_from_hex("6d756c7479", reset_sp(message)); - transaction_set_message(transaction.get(), message.get()); + HANDLE_ERROR(properties_set_binary_data_value(builder_propertie, "memo", message.get())); } + + TransactionPtr transaction; + HANDLE_ERROR(transaction_builder_make_transaction(builder.get(), reset_sp(transaction))); + // transaction_id = "6981ea5ac7da255c24b939216ca13d9348c483334700fdeba6e1539b7827ec39" ConstCharPtr signatures; HANDLE_ERROR(transaction_serialize_encoded(transaction.get(), reset_sp(signatures)));