1 #include <libex/array.h>
2 #include <libex/file.h>
6 int mint (const char *to
, const char *amount_str
) {
8 dprintf(STDERR_FILENO
, "destination address expected\n");
12 dprintf(STDERR_FILENO
, "amount expected\n");
16 str_t
*contract_def
= load_all_file(contract_file
, 64, 65535);
19 eth_contract_t
*contract
= eth_load_contract(contract_addr
, contract_def
->ptr
, contract_def
->len
);
21 int unlocked
= eth_unlock_account(auth_addr
, pass
);
24 dprintf(STDERR_FILENO
, "%d: %s\n", eth_errcode
, eth_errmsg
);
27 dprintf(STDERR_FILENO
, "illegal password\n");
32 mpz_init_set_str(amount
, amount_str
, 10);
33 memset(&ctx
, 0, sizeof(eth_ctx_t
));
34 if (-1 == eth_prepare_exec(contract
, from_addr
, "mint(address,uint256)", &ctx
))
36 eth_param_address(&ctx
, to
);
37 eth_param_int(&ctx
, amount
);
38 if (-1 == (rc
= eth_exec(&ctx
, ETH_NULL
, NULL
, ETH_NULL
)))
39 dprintf(STDERR_FILENO
, "%d: %s\n", eth_errcode
, eth_errmsg
);
41 dprintf(STDOUT_FILENO
, "%s\n", ctx
.result
->ptr
);
44 eth_free_contract(contract
);
51 static void linenoise_ac (char *buf
, int *posp
, int len
, size_t cols
) {
52 static const char *cstr
= "quit";
53 if (len
> 0 && len
< 4 && *posp
> 0) {
54 for (int i
= 0; i
< *posp
; ++i
)
55 if (buf
[i
] != cstr
[i
]) return;
61 int main (int argc
, const char *argv
[]) {
63 curl_global_init(CURL_GLOBAL_ALL
);
64 linenoiseHistoryLoadFile("history.txt");
65 linenoiseACHook
= linenoise_ac
;
66 while ((line
= linenoise("> "))) {
71 if (!strcmp(line
, "quit"))
74 if (0 == strntok(&ptr
, &len
, CONST_STR_LEN(STR_SPACES
), &tok
)) {
75 if (0 == cmpstr(tok
.ptr
, tok
.len
, CONST_STR_LEN("new_account"))) {
76 if (0 == strntok(&ptr
, &len
, CONST_STR_LEN(STR_SPACES
), &tok
)) {
77 char address
[65], *pass
= strndup(tok
.ptr
, tok
.len
);
78 if (eth_new_account(pass
, address
, sizeof(address
)))
79 printf("%s\n", address
);
81 printf("%d: %s\n", coin_errcode
, coin_errmsg
);
86 linenoiseHistoryAdd(line
);
89 linenoiseHistorySaveFile("history.txt");
90 curl_global_cleanup();