remove hardcodes, implementation build_transaction safe_transaction_encoder
This commit is contained in:
parent
647a5369fc
commit
6e213fcfad
2 changed files with 1139 additions and 1097 deletions
|
|
@ -21,194 +21,217 @@
|
|||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
|
||||
// pull out the type of messages sent by our config
|
||||
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;
|
||||
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
|
||||
typedef client::connection_ptr connection_ptr;
|
||||
// pull out the type of messages sent by our config
|
||||
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;
|
||||
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
|
||||
typedef client::connection_ptr connection_ptr;
|
||||
|
||||
class eth_rpc_client {
|
||||
public:
|
||||
typedef eth_rpc_client type;
|
||||
class eth_rpc_client {
|
||||
public:
|
||||
typedef eth_rpc_client type;
|
||||
|
||||
enum req_t {
|
||||
ETH_CHAIN_ID,
|
||||
ETH_GET_TRANSACTION_RECEIPT,
|
||||
ETH_CALL,
|
||||
ETH_SEND_TRANSACTION,
|
||||
ETH_SEND_RAW_TRANSACTION,
|
||||
ETH_GET_CODE,
|
||||
ETH_GET_BALANCE,
|
||||
ETH_SIGN,
|
||||
ETH_COINBASE,
|
||||
GET_LIST_OWNERS,
|
||||
ADD_OWNER,
|
||||
REMOVE_OWNER
|
||||
};
|
||||
enum req_t {
|
||||
ETH_CHAIN_ID,
|
||||
ETH_GET_TRANSACTION_RECEIPT,
|
||||
ETH_CALL,
|
||||
ETH_SEND_TRANSACTION,
|
||||
ETH_SEND_RAW_TRANSACTION,
|
||||
ETH_GET_CODE,
|
||||
ETH_GET_BALANCE,
|
||||
ETH_SIGN,
|
||||
ETH_COINBASE,
|
||||
GET_LIST_OWNERS,
|
||||
ADD_OWNER,
|
||||
REMOVE_OWNER
|
||||
};
|
||||
|
||||
enum class multi_type {
|
||||
script,
|
||||
address
|
||||
};
|
||||
struct multi_params {
|
||||
multi_params(multi_type _type, const std::string &_address_or_script, const std::string &_label = "") :
|
||||
type{_type},
|
||||
address_or_script{_address_or_script},
|
||||
label{_label} {
|
||||
}
|
||||
enum class multi_type {
|
||||
script,
|
||||
address
|
||||
};
|
||||
struct multi_params {
|
||||
multi_params(multi_type _type, const std::string &_address_or_script, const std::string &_label = "") :
|
||||
type{_type},
|
||||
address_or_script{_address_or_script},
|
||||
label{_label} {
|
||||
}
|
||||
|
||||
multi_type type;
|
||||
std::string address_or_script;
|
||||
std::string label;
|
||||
};
|
||||
multi_type type;
|
||||
std::string address_or_script;
|
||||
std::string label;
|
||||
};
|
||||
|
||||
eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls);
|
||||
eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void on_socket_init(websocketpp::connection_hdl);
|
||||
void on_fail(websocketpp::connection_hdl hdl);
|
||||
void on_open(websocketpp::connection_hdl hdl);
|
||||
void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
|
||||
void on_close(websocketpp::connection_hdl);
|
||||
void start();
|
||||
void stop();
|
||||
void on_socket_init(websocketpp::connection_hdl);
|
||||
void on_fail(websocketpp::connection_hdl hdl);
|
||||
void on_open(websocketpp::connection_hdl hdl);
|
||||
void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
|
||||
void on_close(websocketpp::connection_hdl);
|
||||
|
||||
uint64_t get_chain_id();
|
||||
uint64_t eth_getTransactionReceipt(const std::string& tx_id);
|
||||
uint64_t eth_call(const std::string& to, const std::string& data);
|
||||
uint64_t eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data);
|
||||
uint64_t eth_sendRawTransaction(const std::string& params);
|
||||
uint64_t eth_getCode(const std::string& addr);
|
||||
uint64_t eth_getBalance(const std::string& addr);
|
||||
uint64_t eth_sign(const string& addr, const string& message);
|
||||
uint64_t eth_coinbase();
|
||||
uint64_t get_chain_id();
|
||||
uint64_t eth_getTransactionReceipt(const std::string& tx_id);
|
||||
uint64_t eth_call(const std::string& to, const std::string& data);
|
||||
uint64_t eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data);
|
||||
uint64_t eth_sendRawTransaction(const std::string& params);
|
||||
uint64_t eth_getCode(const std::string& addr);
|
||||
uint64_t eth_getBalance(const std::string& addr);
|
||||
uint64_t eth_sign(const string& addr, const string& message);
|
||||
uint64_t eth_coinbase();
|
||||
|
||||
uint64_t get_list_owners(const std::string& safe_account);
|
||||
uint64_t add_owner(const std::string& addr );
|
||||
uint64_t remove_owner(const std::string& addr, uint32_t threshold);
|
||||
uint64_t get_list_owners(const std::string& safe_account);
|
||||
uint64_t add_owner(const std::string& addr );
|
||||
uint64_t remove_owner(const std::string& addr, uint32_t threshold);
|
||||
|
||||
std::string addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys);
|
||||
std::string combinepsbt(const vector<std::string> &psbts);
|
||||
std::string addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys);
|
||||
std::string combinepsbt(const vector<std::string> &psbts);
|
||||
|
||||
uint64_t createmultisig(const uint32_t nrequired, const std::vector<std::string> owner_addresses, const std::string &private_key);
|
||||
uint64_t createmultisig(const uint32_t nrequired, const std::vector<std::string> owner_addresses, const std::string &private_key);
|
||||
|
||||
std::string createpsbt();
|
||||
std::string createrawtransaction();
|
||||
std::string createwallet(const std::string &wallet_name);
|
||||
std::string decodepsbt(std::string const &tx_psbt);
|
||||
std::string decoderawtransaction(std::string const &tx_hex);
|
||||
std::string encryptwallet(const std::string &passphrase);
|
||||
uint64_t estimatesmartfee(uint16_t conf_target = 128);
|
||||
std::string finalizepsbt(std::string const &tx_psbt);
|
||||
std::string getaddressinfo(const std::string &address);
|
||||
std::string getblock(const std::string &block_hash, int32_t verbosity = 2);
|
||||
std::string getrawtransaction(const std::string &txid, const bool verbose = false);
|
||||
std::string getnetworkinfo();
|
||||
std::string gettransaction(const std::string &txid, const bool include_watch_only = false);
|
||||
std::string getblockchaininfo();
|
||||
void importaddress(const std::string &address_or_script, const std::string &label = "", const bool rescan = true, const bool p2sh = false);
|
||||
void importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan = true);
|
||||
std::string loadwallet(const std::string &filename);
|
||||
std::string sendrawtransaction(const std::string &tx_hex);
|
||||
std::string signrawtransactionwithwallet(const std::string &tx_hash);
|
||||
std::string unloadwallet(const std::string &filename);
|
||||
std::string walletlock();
|
||||
std::string walletprocesspsbt(std::string const &tx_psbt);
|
||||
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
|
||||
std::string createpsbt();
|
||||
std::string createrawtransaction();
|
||||
std::string createwallet(const std::string &wallet_name);
|
||||
std::string decodepsbt(std::string const &tx_psbt);
|
||||
std::string decoderawtransaction(std::string const &tx_hex);
|
||||
std::string encryptwallet(const std::string &passphrase);
|
||||
uint64_t estimatesmartfee(uint16_t conf_target = 128);
|
||||
std::string finalizepsbt(std::string const &tx_psbt);
|
||||
std::string getaddressinfo(const std::string &address);
|
||||
std::string getblock(const std::string &block_hash, int32_t verbosity = 2);
|
||||
std::string getrawtransaction(const std::string &txid, const bool verbose = false);
|
||||
std::string getnetworkinfo();
|
||||
std::string gettransaction(const std::string &txid, const bool include_watch_only = false);
|
||||
std::string getblockchaininfo();
|
||||
void importaddress(const std::string &address_or_script, const std::string &label = "", const bool rescan = true, const bool p2sh = false);
|
||||
void importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan = true);
|
||||
std::string loadwallet(const std::string &filename);
|
||||
std::string sendrawtransaction(const std::string &tx_hex);
|
||||
std::string signrawtransactionwithwallet(const std::string &tx_hash);
|
||||
std::string unloadwallet(const std::string &filename);
|
||||
std::string walletlock();
|
||||
std::string walletprocesspsbt(std::string const &tx_psbt);
|
||||
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
|
||||
|
||||
std::string chain_id;//256 bit value
|
||||
std::vector<std::string> owners;
|
||||
std::string safe_account_addr;
|
||||
private:
|
||||
class ethereum_function_call_encoder {
|
||||
public:
|
||||
std::string encode_function_signature(const std::string& function_signature);
|
||||
std::string encode_address(const std::string& addr);
|
||||
std::string encode_uint256(const std::string& value);
|
||||
std::string encode_uint8(uint8_t value);
|
||||
std::string encode_bytes(const std::string& values);
|
||||
};
|
||||
std::string chain_id;//256 bit value
|
||||
std::vector<std::string> owners;
|
||||
std::string safe_account_addr;
|
||||
private:
|
||||
class ethereum_function_call_encoder {
|
||||
public:
|
||||
enum operation_t {
|
||||
OPERATION_CALL,
|
||||
OPERATION_DELEGATE_CALL
|
||||
};
|
||||
|
||||
ethereum_function_call_encoder m_ethereum_function_call_encoder;
|
||||
static constexpr const char*const default_prev_addr = "0000000000000000000000000000000000000001";
|
||||
|
||||
std::shared_ptr<fc::thread> _thread;
|
||||
std::string signature;
|
||||
std::string geth_url;
|
||||
uint64_t t_id;
|
||||
std::string account_address;
|
||||
std::string transaction_id;
|
||||
uint32_t threshold;
|
||||
std::unordered_map<uint64_t, req_t> m_requests;
|
||||
std::string balance;
|
||||
std::string code;
|
||||
std::string encode_function_signature(const std::string& function_signature);
|
||||
std::string encode_address(const std::string& addr);
|
||||
std::string encode_uint256(const std::string& value);
|
||||
std::string encode_uint8(uint8_t value);
|
||||
std::string encode_bytes(const std::string& values);
|
||||
};
|
||||
|
||||
std::string ip;
|
||||
uint32_t rpc_port;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string wallet;
|
||||
std::string wallet_password;
|
||||
bool debug_rpc_calls;
|
||||
class safe_transaction_encoder {
|
||||
public:
|
||||
static constexpr const char*const default_safe_tx_gas = "0";
|
||||
static constexpr const char*const default_data_gas = "0";
|
||||
static constexpr const char*const default_gas_price = "0";
|
||||
static constexpr const char*const default_gas_token = "0000000000000000000000000000000000000000";
|
||||
static constexpr const char*const default_refund_receiver = "0000000000000000000000000000000000000000";
|
||||
|
||||
fc::http::header authorization;
|
||||
std::string create_safe_address(const std::vector<std::string> owner_addresses, uint32_t threshold);
|
||||
std::string build_transaction(const std::string& safe_account_addr, const std::string& value, const std::string& data, uint8_t operation, const std::string& safeTxGas, const std::string& dataGas, const std::string& gasPrice, const std::string& gasToken, const std::string& refundReceiver);
|
||||
|
||||
client m_endpoint;
|
||||
websocketpp::connection_hdl m_hdl;
|
||||
};
|
||||
private:
|
||||
ethereum_function_call_encoder m_ethereum_function_call_encoder;
|
||||
};
|
||||
|
||||
// =============================================================================
|
||||
ethereum_function_call_encoder m_ethereum_function_call_encoder;
|
||||
safe_transaction_encoder m_safe_transaction_encoder;
|
||||
|
||||
class sidechain_net_handler_eth : public sidechain_net_handler {
|
||||
public:
|
||||
sidechain_net_handler_eth(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
|
||||
virtual ~sidechain_net_handler_eth();
|
||||
std::shared_ptr<fc::thread> _thread;
|
||||
std::string signature;
|
||||
std::string geth_url;
|
||||
uint64_t t_id;
|
||||
std::string account_address;
|
||||
std::string transaction_id;
|
||||
uint32_t threshold;
|
||||
std::unordered_map<uint64_t, req_t> m_requests;
|
||||
std::string balance;
|
||||
std::string code;
|
||||
|
||||
bool process_proposal(const proposal_object &po);
|
||||
void process_primary_wallet();
|
||||
void process_sidechain_addresses();
|
||||
bool process_deposit(const son_wallet_deposit_object &swdo);
|
||||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
|
||||
std::string ip;
|
||||
uint32_t rpc_port;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string wallet;
|
||||
std::string wallet_password;
|
||||
bool debug_rpc_calls;
|
||||
|
||||
private:
|
||||
std::string url;
|
||||
uint32_t rpc_port;
|
||||
fc::http::header authorization;
|
||||
|
||||
std::string rpc_user;
|
||||
std::string rpc_password;
|
||||
std::string wallet;
|
||||
std::string wallet_password;
|
||||
client m_endpoint;
|
||||
websocketpp::connection_hdl m_hdl;
|
||||
};
|
||||
|
||||
std::unique_ptr<eth_rpc_client> eth_client;
|
||||
// =============================================================================
|
||||
|
||||
fc::future<void> on_changed_objects_task;
|
||||
class sidechain_net_handler_eth : public sidechain_net_handler {
|
||||
public:
|
||||
sidechain_net_handler_eth(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
|
||||
virtual ~sidechain_net_handler_eth();
|
||||
|
||||
std::mutex event_handler_mutex;
|
||||
typedef std::lock_guard<decltype(event_handler_mutex)> scoped_lock;
|
||||
bool process_proposal(const proposal_object &po);
|
||||
void process_primary_wallet();
|
||||
void process_sidechain_addresses();
|
||||
bool process_deposit(const son_wallet_deposit_object &swdo);
|
||||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
|
||||
|
||||
std::string create_primary_wallet_address(const std::vector<son_info> &son_pubkeys);
|
||||
private:
|
||||
std::string url;
|
||||
uint32_t rpc_port;
|
||||
|
||||
std::string create_primary_wallet_transaction(const son_wallet_object &prev_swo, std::string new_sw_address);
|
||||
std::string create_deposit_transaction(const son_wallet_deposit_object &swdo);
|
||||
std::string create_withdrawal_transaction(const son_wallet_withdraw_object &swwo);
|
||||
std::string rpc_user;
|
||||
std::string rpc_password;
|
||||
std::string wallet;
|
||||
std::string wallet_password;
|
||||
|
||||
std::string create_transaction();
|
||||
std::string sign_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_transaction(const sidechain_transaction_object &sto);
|
||||
std::unique_ptr<eth_rpc_client> eth_client;
|
||||
|
||||
void handle_event(const std::string &event_data);
|
||||
std::vector<info_for_vin> extract_info_from_block(const std::string &_block);
|
||||
void on_changed_objects(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
|
||||
void on_changed_objects_cb(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
|
||||
fc::future<void> on_changed_objects_task;
|
||||
|
||||
std::vector<char> parse_hex(const std::string &str);
|
||||
fc::ecc::public_key_data create_public_key_data(const std::vector<char> &public_key);
|
||||
};
|
||||
std::mutex event_handler_mutex;
|
||||
typedef std::lock_guard<decltype(event_handler_mutex)> scoped_lock;
|
||||
|
||||
std::string create_primary_wallet_address(const std::vector<son_info> &son_pubkeys);
|
||||
|
||||
std::string create_primary_wallet_transaction(const son_wallet_object &prev_swo, std::string new_sw_address);
|
||||
std::string create_deposit_transaction(const son_wallet_deposit_object &swdo);
|
||||
std::string create_withdrawal_transaction(const son_wallet_withdraw_object &swwo);
|
||||
|
||||
std::string create_transaction();
|
||||
std::string sign_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_transaction(const sidechain_transaction_object &sto);
|
||||
|
||||
void handle_event(const std::string &event_data);
|
||||
std::vector<info_for_vin> extract_info_from_block(const std::string &_block);
|
||||
void on_changed_objects(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
|
||||
void on_changed_objects_cb(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
|
||||
|
||||
std::vector<char> parse_hex(const std::string &str);
|
||||
fc::ecc::public_key_data create_public_key_data(const std::vector<char> &public_key);
|
||||
};
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue