Merge branch 'master' of https://repo.or.cz/libcoin
[libcoin.git] / include / libcoin / ether.h
blobd7a451214fc63208c0aed47ac035b57223de2b1f
1 #ifndef __ETHEREUM_H__
2 #define __ETHEREUM_H__
4 #include <stdarg.h>
5 #include <stdint.h>
6 #include <gmp.h>
7 #include <curl/curl.h>
8 #include <libex/str.h>
9 #include <libex/json.h>
10 #include <libex/array.h>
11 #include "conf.h"
13 #define ETH_DSCALE 18
14 #define ETH_UNLOCK_TIMEOUT 1500
16 extern mpz_t eth_gwei;
17 extern mpz_t eth_fast_price;
18 extern mpz_t eth_average_price;
19 extern mpz_t eth_slow_price;
21 static inline str_t *ether_str_to_int_str (const char *ether_amount) {
22 return str_to_int_str(ether_amount, ETH_DSCALE);
25 char *ether_hex_to_int_str (const char *amount);
27 typedef enum { ST_NONE, ST_NONPAYABLE, ST_VIEW } eth_method_state_t;
28 typedef struct {
29 char *proto;
30 char *sign;
31 eth_method_state_t state;
32 int8_t is_payable;
33 char **outputs;
34 size_t output_len;
35 } eth_method_t;
37 DEFINE_SORTED_ARRAY(eth_method_list_t, eth_method_t);
39 typedef struct {
40 char *address;
41 eth_method_list_t *methods;
42 } eth_contract_t;
44 typedef enum { ETH_CALL, ETH_SENDTRAN } eth_call_type_t;
46 typedef struct {
47 eth_contract_t *contract;
48 eth_method_t *method;
49 strbuf_t buf;
50 json_t *json;
51 eth_call_type_t call_type;
52 str_t *result;
53 } eth_ctx_t;
54 void eth_ctx_clear (eth_ctx_t *ctx);
56 eth_contract_t *eth_declare_contract (const char *address);
57 eth_contract_t *eth_load_contract (const char *address, const char *intf, size_t intf_len);
58 eth_method_t *eth_declare_method (eth_contract_t *contract, const char *proto, size_t proto_len);
59 void eth_free_contract (eth_contract_t *contract);
61 int eth_unlock_account (const char *account, const char *passwd, int timeout);
62 char *eth_get_coinbase (char *address, size_t address_len);
63 char *eth_coinbase ();
64 char *eth_new_account (const char *pass, char *address, size_t address_len);
65 str_t *eth_sha3 (const char *param, size_t param_len);
67 int eth_prepare_exec (eth_contract_t *contract, const char *from, const char *proto, eth_ctx_t *ctx);
68 void eth_param_address (eth_ctx_t *ctx, const char *address);
69 void eth_param_int (eth_ctx_t *ctx, mpz_t x);
70 int eth_exec (eth_ctx_t *ctx, const char *value, const char *gas, const char *gas_price);
72 void eth_rawstr_to_wei (const char *rawstr, mpz_t amount);
73 void eth_rawstr_to_ether (const char *rawstr, mpf_t amount);
75 char *eth_send (const char *from, const char *to, const char *amount, const char *gas, const char *gas_price);
76 char *eth_send_wei (const char *from, const char *to, mpz_srcptr amount, mpz_srcptr gas, mpz_srcptr gas_price);
77 char *eth_send_ether (const char *from, const char *to, mpq_srcptr amount, mpz_srcptr gas, mpz_srcptr gas_price);
78 char *eth_newaccount (const char *passwd);
79 char *eth_getbalance (const char *address, size_t address_len);
80 int eth_accounts (json_item_h fn, void *userdata, int flags);
81 int eth_gettransaction_by_hash (const char *hash, size_t hash_len, json_item_h fn, void *userdata);
83 void eth_mine ();
85 #endif // __ETHEREUM_H__