Skip to content
Open
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
3 changes: 2 additions & 1 deletion multy_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions multy_core/eos.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const std::array<uint8_t, 7> EOS_TOKEN_NAME = {0x45, 0x4f, 0x53, 0x00, 0x00, 0x0
enum EosTransactionBuilderType
{
EOS_TRANSACTION_BUILDER_UPDATEAUTH,
EOS_TRANSACTION_BUILDER_TRANSFER,
};

#ifdef __cplusplus
Expand Down
12 changes: 3 additions & 9 deletions multy_core/src/eos/eos_binary_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ EosBinaryStream::EosBinaryStream()
EosBinaryStream::~EosBinaryStream()
{}

template <typename T>
EosBinaryStream& write_as_data(const T& data, EosBinaryStream& stream)
{
stream.write_data(
reinterpret_cast<const uint8_t*>(&data), sizeof(data));
return stream;
}

EosBinaryStream& operator<<(EosBinaryStream& stream, const EosTransactionAction& op)
{
op.write_to_stream(&stream);
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions multy_core/src/eos/eos_binary_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class EosBinaryStream : public BinaryStream
~EosBinaryStream();
};

template <typename T>
EosBinaryStream& write_as_data(const T& data, EosBinaryStream& stream)
{
stream.write_data(
reinterpret_cast<const uint8_t*>(&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);
Expand Down
5 changes: 5 additions & 0 deletions multy_core/src/eos/eos_facade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstring>

Expand Down Expand Up @@ -86,6 +87,10 @@ TransactionBuilderPtr EosFacade::make_transaction_builder(
EOS_TRANSACTION_BUILDER_UPDATEAUTH,
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, we now have an additional overload that takes string as builder name, please add it here.

&make_eos_transaction_builder_updateauth
},
{
EOS_TRANSACTION_BUILDER_TRANSFER,
&make_eos_transaction_builder_transfer
}
};

const auto builder = BUILDERS.find(type);
Expand Down
6 changes: 4 additions & 2 deletions multy_core/src/eos/eos_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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__);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented out code

}

EosName EosName::from_string(const std::string& string)
Expand Down
1 change: 1 addition & 0 deletions multy_core/src/eos/eos_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
189 changes: 112 additions & 77 deletions multy_core/src/eos/eos_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ const EosChainId EOS_MAINNET_CHAIN_ID = {0xac, 0xa3, 0x76, 0xf2, 0x06, 0xb8, 0xf
const std::array<uint8_t, 32> 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update signature:

WriteToStream(uint64_t value, EosBinaryStream* stream)

{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put a link to reference documentation here

do
{
uint8_t input = static_cast<uint8_t>(value & 0x7f);
Copy link
Contributor

Choose a reason for hiding this comment

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

const uint8_t

value >>= 7;
input |= ((value > 0 ? 1 : 0) << 7);
*stream << input;
} while(value);
}
} // namespace


Expand Down Expand Up @@ -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<BigInt, std::numeric_limits<uint32_t>::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)
{
}

Expand All @@ -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();
Expand Down Expand Up @@ -221,13 +219,13 @@ void EosTransaction::serialize_to_stream(EosBinaryStream& stream, SerializationM
}

list << static_cast<uint32_t>(m_expiration); // time as uint32_t
list << static_cast<uint16_t>(static_cast<uint32_t>(*m_ref_block_num));
list << m_ref_block_num;
uint32_t ref_block_prefix;
ref_block_prefix = static_cast<uint32_t>(m_ref_block_prefix.get_value().get_value_as_uint64());
ref_block_prefix = static_cast<uint32_t>(m_ref_block_prefix.get_value_as_uint64());
list << ref_block_prefix;
list << static_cast<uint8_t>(0x00); // max_net_usage_words, we set zero byte
list << static_cast<uint8_t>(0x00); // max_cpu_usage_ms, we set zero byte
list << static_cast<uint8_t>(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<uint8_t>(0x00); // size array context_free_actions and context_free_actions

const auto& actions = m_external_actions.empty() ? m_actions : m_external_actions;
Expand All @@ -237,7 +235,8 @@ void EosTransaction::serialize_to_stream(EosBinaryStream& stream, SerializationM
list << *action;
}

list << static_cast<uint8_t>(0x00);
// TODO: implement transaction_extensions wher EOS will be suported it.
list << static_cast<uint8_t>(0x00); // transaction_extensions It seems like that EOS deos not support any extensions yet.

if (mode == SERIALIZE_FOR_SIGN)
{
Expand All @@ -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(
Expand All @@ -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()
Expand All @@ -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
Loading