@@ -46,6 +46,16 @@ const EosChainId EOS_MAINNET_CHAIN_ID = {0xac, 0xa3, 0x76, 0xf2, 0x06, 0xb8, 0xf
4646const 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
95105EosTransaction::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
134130void 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
255254BigInt 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
266267BigInt EosTransaction::estimate_total_fee (
@@ -272,30 +273,36 @@ BigInt EosTransaction::estimate_total_fee(
272273
273274Properties& 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
287291Properties& 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
301308Properties& EosTransaction::get_fee ()
@@ -306,23 +313,51 @@ Properties& EosTransaction::get_fee()
306313
307314void 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
320329void 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
0 commit comments