57 lines
2 KiB
C++
57 lines
2 KiB
C++
#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(boost::multiprecision::uint256_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;
|
|
}
|
|
|
|
//! withdrawal_encoder
|
|
std::string withdrawal_encoder::encode(const std::string& to, boost::multiprecision::uint256_t amount, const std::string& object_id) const
|
|
{
|
|
std::string data = "0x" + function_signature;
|
|
data += base_encoder::encode_address(to);
|
|
data += base_encoder::encode_uint256(amount);
|
|
data += base_encoder::encode_uint256(32*3);
|
|
data += base_encoder::encode_string(object_id);
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
}}} // namespace graphene::peerplays_sidechain::ethereum
|