Skip to content

Commit 408c917

Browse files
committed
MUL-1865: New logic and interface for EOS transaction
Create EOS transfer transaction builder
1 parent a82e766 commit 408c917

10 files changed

Lines changed: 364 additions & 138 deletions

multy_core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ if (MULTY_WITH_EOS)
128128
src/eos/eos_name.cpp
129129
src/eos/eos_transaction.cpp
130130
src/eos/eos_transaction_action.cpp
131-
src/eos/eos_transaction_builder_updateauth.cpp
132131
src/eos/eos_transaction_transfer_action.cpp
132+
src/eos/eos_transaction_builder_updateauth.cpp
133+
src/eos/eos_transaction_builder_transfer.cpp
133134
)
134135
endif()
135136

multy_core/eos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const std::array<uint8_t, 7> EOS_TOKEN_NAME = {0x45, 0x4f, 0x53, 0x00, 0x00, 0x0
2727
enum EosTransactionBuilderType
2828
{
2929
EOS_TRANSACTION_BUILDER_UPDATEAUTH,
30+
EOS_TRANSACTION_BUILDER_TRANSFER,
3031
};
3132

3233
#ifdef __cplusplus

multy_core/src/eos/eos_facade.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "multy_core/src/eos/eos_account.h"
1818
#include "multy_core/src/eos/eos_transaction.h"
1919
#include "multy_core/src/eos/eos_transaction_builder_updateauth.h"
20+
#include "multy_core/src/eos/eos_transaction_builder_transfer.h"
2021

2122
#include <cstring>
2223

@@ -86,6 +87,10 @@ TransactionBuilderPtr EosFacade::make_transaction_builder(
8687
EOS_TRANSACTION_BUILDER_UPDATEAUTH,
8788
&make_eos_transaction_builder_updateauth
8889
},
90+
{
91+
EOS_TRANSACTION_BUILDER_TRANSFER,
92+
&make_eos_transaction_builder_transfer
93+
}
8994
};
9095

9196
const auto builder = BUILDERS.find(type);

multy_core/src/eos/eos_name.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ EosName::EosName()
8282
}
8383

8484
EosName::EosName(const std::string& name)
85-
: m_data(name_string_to_uint64(name))
85+
: m_data(name_string_to_uint64(name)),
86+
m_data_string(name)
8687
{
8788
}
8889

@@ -97,7 +98,8 @@ uint64_t EosName::get_data() const
9798

9899
std::string EosName::get_string() const
99100
{
100-
THROW_EXCEPTION2(ERROR_FEATURE_NOT_IMPLEMENTED_YET, __FUNCTION__);
101+
return m_data_string;
102+
//THROW_EXCEPTION2(ERROR_FEATURE_NOT_IMPLEMENTED_YET, __FUNCTION__);
101103
}
102104

103105
EosName EosName::from_string(const std::string& string)

multy_core/src/eos/eos_name.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class EosName
3232
private:
3333
// Non-const to make it copyable.
3434
uint64_t m_data;
35+
std::string m_data_string;
3536
};
3637

3738
typedef EosName EosAddress;

multy_core/src/eos/eos_transaction.cpp

Lines changed: 111 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ const EosChainId EOS_MAINNET_CHAIN_ID = {0xac, 0xa3, 0x76, 0xf2, 0x06, 0xb8, 0xf
4646
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,
4747
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
4848

49+
void putVariableUInt(EosBinaryStream* stream, uint64_t value)
50+
{
51+
do
52+
{
53+
uint8_t input = static_cast<uint8_t>(value & 0x7f);
54+
value >>= 7;
55+
input |= ((value > 0 ? 1 : 0) << 7);
56+
*stream << input;
57+
} while(value);
58+
}
4959
} // namespace
5060

5161

@@ -95,26 +105,12 @@ class EosTransactionDestination : public TransactionDestinationBase
95105
EosTransaction::EosTransaction(const Account& account)
96106
: TransactionBase(account.get_blockchain_type()),
97107
m_account(account),
98-
m_message(new BinaryData{nullptr, 0}),
99-
m_source(),
100-
m_destination(),
101-
m_explicit_expiration(
102-
get_transaction_properties(),
103-
"expiration",
104-
Property::OPTIONAL,
105-
[this](const std::string& new_expiration)
106-
{
107-
this->set_expiration(new_expiration);
108-
}),
109-
m_ref_block_num(
110-
get_transaction_properties(),
111-
"block_num",
112-
Property::REQUIRED),
113-
m_ref_block_prefix(
114-
get_transaction_properties(),
115-
"ref_block_prefix",
116-
Property::REQUIRED,
117-
verify_smaller_than<BigInt, std::numeric_limits<uint32_t>::max()>)
108+
m_explicit_expiration(""),
109+
m_ref_block_num(0),
110+
m_ref_block_prefix(0),
111+
m_max_net_usage_words(0),
112+
m_max_cpu_usage_ms(0),
113+
m_delay_seconds(0)
118114
{
119115
}
120116

@@ -133,26 +129,28 @@ void EosTransaction::verify()
133129

134130
void EosTransaction::update()
135131
{
132+
// TODO: переделать обновление, и дописать функцию verify там должна быть проверка чтобы был 100% actions и валидный
133+
136134
if (m_external_actions.empty())
137135
{
138-
if (!m_source)
139-
{
140-
THROW_EXCEPTION2(ERROR_TRANSACTION_NO_SOURCES,
141-
"EOS transaction should have one source.");
142-
}
143-
144-
if (!m_destination)
145-
{
146-
THROW_EXCEPTION2(ERROR_TRANSACTION_NO_DESTINATIONS,
147-
"EOS transaction should have one destination.");
148-
}
149-
150-
m_actions.clear();
151-
m_actions.push_back(EosTransactionActionPtr(new EosTransactionTransferAction(
152-
*m_source->address,
153-
*m_destination->address,
154-
*m_destination->amount,
155-
*m_message)));
136+
// if (!m_source)
137+
// {
138+
// THROW_EXCEPTION2(ERROR_TRANSACTION_NO_SOURCES,
139+
// "EOS transaction should have one source.");
140+
// }
141+
142+
// if (!m_destination)
143+
// {
144+
// THROW_EXCEPTION2(ERROR_TRANSACTION_NO_DESTINATIONS,
145+
// "EOS transaction should have one destination.");
146+
// }
147+
148+
// m_actions.clear();
149+
// m_actions.push_back(EosTransactionActionPtr(new EosTransactionTransferAction(
150+
// *m_source->address,
151+
// *m_destination->address,
152+
// *m_destination->amount,
153+
// *m_message)));
156154
}
157155

158156
sign();
@@ -221,13 +219,13 @@ void EosTransaction::serialize_to_stream(EosBinaryStream& stream, SerializationM
221219
}
222220

223221
list << static_cast<uint32_t>(m_expiration); // time as uint32_t
224-
list << static_cast<uint16_t>(static_cast<uint32_t>(*m_ref_block_num));
222+
list << m_ref_block_num;
225223
uint32_t ref_block_prefix;
226-
ref_block_prefix = static_cast<uint32_t>(m_ref_block_prefix.get_value().get_value_as_uint64());
224+
ref_block_prefix = static_cast<uint32_t>(m_ref_block_prefix.get_value_as_uint64());
227225
list << ref_block_prefix;
228-
list << static_cast<uint8_t>(0x00); // max_net_usage_words, we set zero byte
229-
list << static_cast<uint8_t>(0x00); // max_cpu_usage_ms, we set zero byte
230-
list << static_cast<uint8_t>(0x00); // delay_seconds, we set zero byte
226+
putVariableUInt(&list, m_max_net_usage_words);
227+
putVariableUInt(&list, m_max_cpu_usage_ms);
228+
putVariableUInt(&list, m_delay_seconds);
231229
list << static_cast<uint8_t>(0x00); // size array context_free_actions and context_free_actions
232230

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

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

242241
if (mode == SERIALIZE_FOR_SIGN)
243242
{
@@ -254,13 +253,15 @@ BigInt EosTransaction::get_total_fee() const
254253

255254
BigInt EosTransaction::get_total_spent() const
256255
{
257-
if (!m_destination)
258-
{
259-
THROW_EXCEPTION("Failed to calculate total spent.")
260-
<< " Transaction has no destinations.";
261-
}
262-
263-
return *m_destination->amount;
256+
THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED,
257+
"Don't implimented yat.");
258+
// if (!m_destination)
259+
// {
260+
// THROW_EXCEPTION("Failed to calculate total spent.")
261+
// << " Transaction has no destinations.";
262+
// }
263+
264+
// return *m_destination->amount;
264265
}
265266

266267
BigInt EosTransaction::estimate_total_fee(
@@ -272,30 +273,36 @@ BigInt EosTransaction::estimate_total_fee(
272273

273274
Properties& EosTransaction::add_source()
274275
{
275-
if (m_source)
276-
{
277-
THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_SOURCES,
278-
"EOS transaction can have only one source.");
279-
}
276+
THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED,
277+
"EOS transaction don't have destination.");
278+
279+
// if (m_source)
280+
// {
281+
// THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_SOURCES,
282+
// "EOS transaction can have only one source.");
283+
// }
280284

281-
m_source = EosTransactionSourcePtr(new EosTransactionSource(
282-
get_blockchain_type()));
285+
// m_source = EosTransactionSourcePtr(new EosTransactionSource(
286+
// get_blockchain_type()));
283287

284-
return m_source->get_properties();
288+
// return m_source->get_properties();
285289
}
286290

287291
Properties& EosTransaction::add_destination()
288292
{
289-
if (m_destination)
290-
{
291-
THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_DESTINATIONS,
292-
"EOS transaction can have only one destination.");
293-
}
293+
THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED,
294+
"EOS transaction don't have destination.");
294295

295-
m_destination = EosTransactionDestinationPtr(
296-
new EosTransactionDestination(get_blockchain_type()));
296+
// if (m_destination)
297+
// {
298+
// THROW_EXCEPTION2(ERROR_TRANSACTION_TOO_MANY_DESTINATIONS,
299+
// "EOS transaction can have only one destination.");
300+
// }
297301

298-
return m_destination->get_properties();
302+
// m_destination = EosTransactionDestinationPtr(
303+
// new EosTransactionDestination(get_blockchain_type()));
304+
305+
// return m_destination->get_properties();
299306
}
300307

301308
Properties& EosTransaction::get_fee()
@@ -306,23 +313,51 @@ Properties& EosTransaction::get_fee()
306313

307314
void EosTransaction::set_message(const BinaryData& payload)
308315
{
309-
INVARIANT(payload.data != nullptr);
310-
if (payload.len > 255)
311-
{
312-
THROW_EXCEPTION2(ERROR_TRANSACTION_PAYLOAD_TO_BIG, "Message is to big.")
313-
<< " Max message size is 255 bytes,"
314-
<< " got: " << payload.len << " bytes.";
315-
}
316-
317-
m_message = make_clone(payload);
316+
THROW_EXCEPTION2(ERROR_FEATURE_NOT_SUPPORTED,
317+
"Use actions to set message in transaction.");
318+
//) INVARIANT(payload.data != nullptr);
319+
// if (payload.len > 255)
320+
// {
321+
// THROW_EXCEPTION2(ERROR_TRANSACTION_PAYLOAD_TO_BIG, "Message is to big.")
322+
// << " Max message size is 255 bytes,"
323+
// << " got: " << payload.len << " bytes.";
324+
// }
325+
326+
// m_message = make_clone(payload);
318327
}
319328

320329
void EosTransaction::set_action(EosTransactionActionPtr action)
321330
{
322331
INVARIANT(action != nullptr);
323332

333+
// Now we implimented only with one action
324334
m_external_actions.emplace_back(std::move(action));
325335
}
326336

337+
void EosTransaction::set_max_net_usage(const uint64_t max_net_usage_words)
338+
{
339+
m_max_net_usage_words = max_net_usage_words;
340+
}
341+
342+
void EosTransaction::set_max_cpu_usage(const uint64_t max_cpu_usage_ms)
343+
{
344+
m_max_cpu_usage_ms = max_cpu_usage_ms;
345+
}
346+
347+
void EosTransaction::set_delay_seconds(const uint64_t delay_seconds)
348+
{
349+
m_delay_seconds = delay_seconds;
350+
}
351+
352+
void EosTransaction::set_ref_block_num(const uint16_t ref_block_num)
353+
{
354+
m_ref_block_num = ref_block_num;
355+
}
356+
357+
void EosTransaction::set_ref_block_prefix(const BigInt ref_block_prefix)
358+
{
359+
m_ref_block_prefix = ref_block_prefix;
360+
}
361+
327362
} // namespace internal
328363
} // namespace multy_core

multy_core/src/eos/eos_transaction.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ class EosTransaction : public TransactionBase
5151
Properties& add_destination() override;
5252
Properties& get_fee() override;
5353
void set_message(const BinaryData& payload) override;
54+
void add_action();
5455

5556
// Ownership is transferred from caller to EosTransaction.
57+
void set_ref_block_num(const uint16_t ref_block_num);
58+
void set_ref_block_prefix(const BigInt ref_block_prefix);
5659
void set_action(EosTransactionActionPtr action);
60+
void set_max_net_usage(const uint64_t max_net_usage_words);
61+
void set_max_cpu_usage(const uint64_t max_cpu_usage_ms);
62+
void set_delay_seconds(const uint64_t delay_seconds);
63+
void set_expiration(const std::string& new_expiration);
5764

5865
private:
5966
enum SerializationMode
@@ -62,24 +69,29 @@ class EosTransaction : public TransactionBase
6269
SERIALIZE_FOR_SIGN
6370
};
6471
void verify();
65-
void set_expiration(const std::string&);
6672
void serialize_to_stream(EosBinaryStream& stream, SerializationMode mode) const;
6773

6874
private:
6975
const Account& m_account;
7076

71-
BinaryDataPtr m_message;
72-
EosTransactionSourcePtr m_source;
73-
EosTransactionDestinationPtr m_destination;
77+
std::string m_explicit_expiration;
78+
uint16_t m_ref_block_num;
79+
BigInt m_ref_block_prefix;
80+
81+
uint64_t m_max_net_usage_words;
82+
uint64_t m_max_cpu_usage_ms;
83+
uint64_t m_delay_seconds;
84+
85+
std::vector<EosTransactionActionPtr> context_free_action;
86+
87+
// BinaryDataPtr m_message;
88+
// EosTransactionSourcePtr m_source;
89+
// EosTransactionDestinationPtr m_destination;
7490
std::vector<EosTransactionActionPtr> m_external_actions;
7591
// TODO: make a TxBuilder for transfer operation and get rid of this,
7692
// since it is going to be set from TX builder as external_action.
7793
std::vector<EosTransactionActionPtr> m_actions;
7894

79-
PropertyT<std::string> m_explicit_expiration;
80-
PropertyT<int32_t> m_ref_block_num;
81-
PropertyT<BigInt> m_ref_block_prefix;
82-
8395
std::time_t m_expiration;
8496
BinaryDataPtr m_signature;
8597
};

0 commit comments

Comments
 (0)