-
Notifications
You must be signed in to change notification settings - Fork 16
Mul 1865 new logic and interface for eos tx #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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__); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented out code |
||
| } | ||
|
|
||
| EosName EosName::from_string(const std::string& string) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update signature: |
||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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<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) | ||
| { | ||
| } | ||
|
|
||
|
|
@@ -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<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; | ||
|
|
@@ -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) | ||
| { | ||
|
|
@@ -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 | ||
There was a problem hiding this comment.
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.