9 #include <libex/json.h>
10 #include <libex/array.h>
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
;
31 eth_method_state_t state
;
37 DEFINE_SORTED_ARRAY(eth_method_list_t
, eth_method_t
);
41 eth_method_list_t
*methods
;
44 typedef enum { ETH_CALL
, ETH_SENDTRAN
} eth_call_type_t
;
47 eth_contract_t
*contract
;
51 eth_call_type_t call_type
;
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
);
85 #endif // __ETHEREUM_H__