base_encoder + update_owners_encoder
This commit is contained in:
parent
7f3e7e876a
commit
f6614ab122
4 changed files with 59 additions and 48 deletions
|
|
@ -1,5 +1,45 @@
|
|||
#include <graphene/peerplays_sidechain/ethereum/encoders.hpp>
|
||||
|
||||
#include <boost/algorithm/hex.hpp>
|
||||
#include <boost/format.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
||||
|
||||
//! base_encoder
|
||||
std::string base_encoder::encode_uint256(uint64_t value)
|
||||
{
|
||||
return (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value)).str();
|
||||
}
|
||||
|
||||
std::string base_encoder::encode_address(const std::string& value)
|
||||
{
|
||||
return (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value)).str();
|
||||
}
|
||||
|
||||
std::string base_encoder::encode_string(const std::string& value)
|
||||
{
|
||||
std::string data = (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value.size())).str();
|
||||
data += boost::algorithm::hex(value) + std::string( (64 - value.size() * 2 % 64), '0' );
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
//! update_owners_encoder
|
||||
std::string update_owners_encoder::encode(const std::vector<std::pair<std::string, uint16_t>>& owners_weights, const std::string& object_id) const
|
||||
{
|
||||
std::string data = "0x" + function_signature;
|
||||
data += base_encoder::encode_uint256(64);
|
||||
data += base_encoder::encode_uint256((owners_weights.size() * 2 + 3) * 32);
|
||||
data += base_encoder::encode_uint256(owners_weights.size());
|
||||
for(const auto& owner : owners_weights)
|
||||
{
|
||||
data += base_encoder::encode_address(owner.first);
|
||||
data += base_encoder::encode_uint256(owner.second);
|
||||
}
|
||||
data += base_encoder::encode_string(object_id);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}}} // namespace graphene::peerplays_sidechain::ethereum
|
||||
|
|
|
|||
|
|
@ -5,7 +5,21 @@
|
|||
|
||||
namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
||||
|
||||
class ethereum_function_call_encoder {
|
||||
class base_encoder {
|
||||
public:
|
||||
static std::string encode_uint256(uint64_t value);
|
||||
static std::string encode_address(const std::string& value);
|
||||
static std::string encode_string(const std::string& value);
|
||||
};
|
||||
|
||||
class update_owners_encoder {
|
||||
public:
|
||||
const std::string function_signature = "23ab6adf"; //! updateOwners((address,uint256)[],string)
|
||||
|
||||
std::string encode(const std::vector<std::pair<std::string, uint16_t>>& owners_weights, const std::string& object_id) const;
|
||||
};
|
||||
|
||||
/*class ethereum_function_call_encoder {
|
||||
public:
|
||||
enum operation_t {
|
||||
OPERATION_CALL,
|
||||
|
|
@ -34,6 +48,6 @@ public:
|
|||
|
||||
private:
|
||||
ethereum_function_call_encoder m_ethereum_function_call_encoder;
|
||||
};
|
||||
};*/
|
||||
|
||||
}}} // namespace graphene::peerplays_sidechain::ethereum
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ public:
|
|||
|
||||
std::string send_transaction(const std::string& wallet_contract_address, const std::string& owner_address, const std::string& data);
|
||||
std::string get_transaction_receipt(const std::string& params);
|
||||
//std::string update_owners(const std::string& wallet_contract_address, const std::string& owner_address, const std::vector<std::pair<std::string, uint16_t>>& owners_weights, const std::string& object_id);
|
||||
//std::string withdraw();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
#include <algorithm>
|
||||
#include <thread>
|
||||
|
||||
#include <boost/algorithm/hex.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
|
|
@ -18,8 +16,8 @@
|
|||
#include <graphene/chain/sidechain_transaction_object.hpp>
|
||||
#include <graphene/chain/son_info.hpp>
|
||||
#include <graphene/chain/son_wallet_object.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/encoders.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/transaction.hpp>
|
||||
#include <graphene/utilities/key_conversion.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
|
|
@ -65,29 +63,6 @@ std::string ethereum_rpc_client::get_transaction_receipt(const std::string& para
|
|||
return send_post_request("eth_getTransactionReceipt", "[ \"" + params + "\"]", debug_rpc_calls);
|
||||
}
|
||||
|
||||
/*std::string ethereum_rpc_client::update_owners(const std::string& wallet_contract_address, const std::string& owner_address, const std::vector<std::pair<std::string, uint16_t>>& owners_weights, const std::string& object_id) {
|
||||
const std::string function_hash = "23ab6adf"; //! updateOwners((address,uint256)[],string)
|
||||
|
||||
const std::string data = [&function_hash, &owners_weights, &object_id] {
|
||||
std::string data = "0x" + function_hash;
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), 64)).str();
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), ((owners_weights.size() * 2 + 3) * 32))).str();
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), owners_weights.size())).str();
|
||||
for(const auto& owner : owners_weights)
|
||||
{
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), owner.first)).str();
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), owner.second)).str();
|
||||
}
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), object_id.size())).str();
|
||||
data += boost::algorithm::hex(object_id) + std::string( (64 - object_id.size() * 2 % 64), '0' );
|
||||
|
||||
return data;
|
||||
}();
|
||||
|
||||
const std::string params = "[ { \"from\": \"" + owner_address + "\", \"to\": \"" + wallet_contract_address + "\", \"data\": \"" + data + "\" } ]";
|
||||
return send_post_request("eth_sendTransaction", params, debug_rpc_calls);
|
||||
}*/
|
||||
|
||||
/*std::string ethereum_rpc_client::withdraw() {
|
||||
const std::string params = "[ { \"from\": \"0x5FbBb31BE52608D2F52247E8400B7fCaA9E0bC12\", \"to\": \"0x3E84f248Cd00A2FDaaDfa0dC5c3ff64D8767Fb01\", \"data\": \"0xe088747b00000000000000000000000009ee460834498a4ee361beb819470061b7381b490000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000006312e33362e330000000000000000000000000000000000000000000000000000\" } ]";
|
||||
return send_post_request("eth_sendTransaction", params, debug_rpc_calls);
|
||||
|
|
@ -643,25 +618,8 @@ std::string sidechain_net_handler_ethereum::create_primary_wallet_transaction(co
|
|||
}
|
||||
|
||||
//! Create data of transaction
|
||||
const std::string function_hash = "23ab6adf"; //! updateOwners((address,uint256)[],string)
|
||||
|
||||
const std::string data = [&function_hash, &owners_weights, &object_id] {
|
||||
std::string data = "0x" + function_hash;
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), 64)).str();
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), ((owners_weights.size() * 2 + 3) * 32))).str();
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), owners_weights.size())).str();
|
||||
for(const auto& owner : owners_weights)
|
||||
{
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), owner.first)).str();
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), owner.second)).str();
|
||||
}
|
||||
data += (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), object_id.size())).str();
|
||||
data += boost::algorithm::hex(object_id) + std::string( (64 - object_id.size() * 2 % 64), '0' );
|
||||
|
||||
return data;
|
||||
}();
|
||||
|
||||
return data;
|
||||
ethereum::update_owners_encoder encoder;
|
||||
return encoder.encode(owners_weights, object_id);
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler_ethereum::create_deposit_transaction(const son_wallet_deposit_object &swdo) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue