monero-c
C ABI for using Monero
Loading...
Searching...
No Matches
monero_c_utils.h
Go to the documentation of this file.
1
55#ifndef MONERO_C_UTILS_H
56#define MONERO_C_UTILS_H
57
58#include <stdbool.h>
59#include <stddef.h>
60#include <stdint.h>
61
62#if defined(_WIN32) || defined(__CYGWIN__)
63 #ifdef MONERO_C_BUILD
64 #define MONERO_EXPORT __declspec(dllexport)
65 #else
66 #define MONERO_EXPORT __declspec(dllimport)
67 #endif
68#else
69 #define MONERO_EXPORT __attribute__((visibility("default")))
70#endif
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76// ------------------------------- RESULT CODES -------------------------------
77
78// returned by every function that can fail. On MONERO_ERROR, call monero_last_error()
79// for a human-readable message. The pointer outputs of a failed call are set to NULL and the
80// counts to 0, even when the failure is a NULL argument. Scalar outputs are left unchanged
85
86// mirrors monero_network_type in monero-cpp (daemon/monero_daemon_model.h):
87// values must stay numerically identical since they're cast directly across the bridge
88// REGTEST has no monero-cpp value. It maps to mainnet, whose address format a regtest node uses, and
89// the wallets on it are created with the regtest flag of monero-cpp
96
97// ---------------------------- ERROR / MEMORY --------------------------------
98
108
115
116// ---------------------------------- VERSION ---------------------------------
117
118// the version of the C ABI, as major.minor.patch like the releases of monero-cpp. While the major
119// version is 0, a change of the minor version can break callers. From 1, only a change of the major
120// version breaks callers, and the minor version grows when functions are added. The patch version
121// changes for fixes that leave the ABI as it is
122#define MONERO_C_ABI_VERSION_MAJOR 0
123#define MONERO_C_ABI_VERSION_MINOR 1
124#define MONERO_C_ABI_VERSION_PATCH 1
125
135MONERO_EXPORT monero_result monero_utils_get_abi_version(uint32_t* out_major, uint32_t* out_minor, uint32_t* out_patch);
136
137// --------------------------------- LOGGING ----------------------------------
138
146
156
163MONERO_EXPORT void monero_utils_configure_logging(const char* path, bool console);
164
165// -------------------------------- VALIDATION --------------------------------
166// pure predicates: never fail, false just means "invalid"
167
175MONERO_EXPORT bool monero_utils_is_valid_address(const char* address, int32_t network_type);
176
183MONERO_EXPORT bool monero_utils_is_valid_private_view_key(const char* private_view_key);
184
191MONERO_EXPORT bool monero_utils_is_valid_private_spend_key(const char* private_spend_key);
192
199MONERO_EXPORT bool monero_utils_is_valid_public_view_key(const char* public_view_key);
200
207MONERO_EXPORT bool monero_utils_is_valid_public_spend_key(const char* public_spend_key);
208
216
224MONERO_EXPORT bool monero_utils_is_valid_mnemonic(const char* mnemonic, const char* language);
225
233
234// same checks as above, but on failure they return MONERO_ERROR and set monero_last_error()
235
244MONERO_EXPORT monero_result monero_utils_validate_address(const char* address, int32_t network_type);
245
254
263
272
281
290
299MONERO_EXPORT monero_result monero_utils_validate_mnemonic(const char* mnemonic, const char* language);
300
301// --------------------------- INTEGRATED ADDRESS / URIS ----------------------
302// structured in/out values cross the bridge as JSON (monero-cpp's own
303// serializable_struct::serialize()/::deserialize() format), so the C side
304// doesn't need to mirror every C++ model struct field by field
305
315MONERO_EXPORT monero_result monero_utils_get_integrated_address(int32_t network_type, const char* standard_address, const char* payment_id, char** out_json);
316
325MONERO_EXPORT monero_result monero_utils_get_payment_uri(const char* tx_config_json, int32_t network_type, char** out_uri);
326
335MONERO_EXPORT monero_result monero_utils_parse_payment_uri(const char* uri, int32_t network_type, char** out_tx_config_json);
336
337// ----------------------------- JSON / BINARY RPC ----------------------------
338// binary payloads (as used by monerod's .bin RPC endpoints) are not
339// null-terminated text, so they cross the bridge as explicit (data, length) pairs
340
349MONERO_EXPORT monero_result monero_utils_json_to_binary(const char* json, uint8_t** out_data, size_t* out_len);
350
359MONERO_EXPORT monero_result monero_utils_binary_to_json(const uint8_t* data, size_t len, char** out_json);
360
369MONERO_EXPORT monero_result monero_utils_binary_blocks_to_json(const uint8_t* data, size_t len, char** out_json);
370
379MONERO_EXPORT monero_result monero_utils_binary_blocks_fast_to_json(const uint8_t* data, size_t len, char** out_json);
380
381// -------------------------------- AMOUNTS / IDS -----------------------------
382
390MONERO_EXPORT monero_result monero_utils_xmr_to_atomic_units(double amount_xmr, uint64_t* out_atomic_units);
391
398MONERO_EXPORT double monero_utils_atomic_units_to_xmr(uint64_t amount_atomic_units);
399
407MONERO_EXPORT bool monero_utils_parse_payment_id_long(const char* payment_id_str, uint8_t out_payment_id[32]);
408
416MONERO_EXPORT bool monero_utils_parse_payment_id_short(const char* payment_id_str, uint8_t out_payment_id[8]);
417
425
433
442
451
458
459#ifdef __cplusplus
460}
461#endif
462
463#endif // MONERO_C_UTILS_H
MONERO_EXPORT bool monero_utils_is_valid_mnemonic(const char *mnemonic, const char *language)
Check whether a mnemonic seed is valid.
MONERO_EXPORT monero_result monero_utils_validate_address(const char *address, int32_t network_type)
Validate an address for a given network, like monero_utils_is_valid_address() but reports the reason ...
MONERO_EXPORT monero_result monero_utils_parse_payment_uri(const char *uri, int32_t network_type, char **out_tx_config_json)
Parse a payment URI into a transaction configuration.
monero_result
Definition monero_c_utils.h:81
@ MONERO_ERROR
Definition monero_c_utils.h:83
@ MONERO_OK
Definition monero_c_utils.h:82
MONERO_EXPORT monero_result monero_utils_validate_payment_id(const char *payment_id)
Validate a payment id, like monero_utils_is_valid_payment_id() but reports the reason through monero_...
MONERO_EXPORT const char * monero_last_error(void)
Return the message of the most recent MONERO_ERROR result on the calling thread, from any monero_c fu...
MONERO_EXPORT bool monero_utils_is_valid_language(const char *language)
Indicates if the given language is valid.
MONERO_EXPORT bool monero_utils_is_valid_payment_id_long(const char *payment_id_str)
Check whether a long payment id is valid.
MONERO_EXPORT monero_result monero_utils_validate_private_view_key(const char *private_view_key)
Validate a private view key, like monero_utils_is_valid_private_view_key() but reports the reason thr...
MONERO_EXPORT monero_result monero_utils_validate_payment_id_long(const char *payment_id_str)
Validate a long payment id, like monero_utils_is_valid_payment_id_long() but reports the reason throu...
MONERO_EXPORT bool monero_utils_is_valid_payment_id(const char *payment_id)
Check whether a payment id is valid.
MONERO_EXPORT bool monero_utils_is_valid_address(const char *address, int32_t network_type)
Check whether an address is valid for a given network.
MONERO_EXPORT monero_result monero_utils_binary_blocks_fast_to_json(const uint8_t *data, size_t len, char **out_json)
Decodes a get_blocks_by_height.bin-style response.
MONERO_EXPORT bool monero_utils_is_valid_private_view_key(const char *private_view_key)
Check whether a private view key is valid.
MONERO_EXPORT monero_result monero_utils_validate_private_spend_key(const char *private_spend_key)
Validate a private spend key, like monero_utils_is_valid_private_spend_key() but reports the reason t...
MONERO_EXPORT bool monero_utils_is_valid_private_spend_key(const char *private_spend_key)
Check whether a private spend key is valid.
MONERO_EXPORT monero_result monero_utils_json_to_binary(const char *json, uint8_t **out_data, size_t *out_len)
Convert a JSON string to its binary-encoded (portable storage format) equivalent.
MONERO_EXPORT void monero_utils_configure_logging(const char *path, bool console)
Configures where log output is written.
MONERO_EXPORT bool monero_utils_parse_payment_id_long(const char *payment_id_str, uint8_t out_payment_id[32])
Parse a long payment ID from a string.
MONERO_EXPORT monero_result monero_utils_validate_public_view_key(const char *public_view_key)
Validate a public view key, like monero_utils_is_valid_public_view_key() but reports the reason throu...
MONERO_EXPORT bool monero_utils_is_valid_public_spend_key(const char *public_spend_key)
Check whether a public spend key is valid.
MONERO_EXPORT void monero_utils_set_log_level(int32_t level)
Set the log level, which picks default category filters (0 = warnings and errors only,...
MONERO_EXPORT monero_result monero_utils_validate_payment_id_short(const char *payment_id_str)
Validate a short payment id, like monero_utils_is_valid_payment_id_short() but reports the reason thr...
MONERO_EXPORT monero_result monero_utils_get_payment_uri(const char *tx_config_json, int32_t network_type, char **out_uri)
Create a payment URI from a transaction configuration.
MONERO_EXPORT monero_result monero_utils_validate_public_spend_key(const char *public_spend_key)
Validate a public spend key, like monero_utils_is_valid_public_spend_key() but reports the reason thr...
#define MONERO_EXPORT
Copyright (c) Libmonero.
Definition monero_c_utils.h:69
MONERO_EXPORT monero_result monero_utils_binary_to_json(const uint8_t *data, size_t len, char **out_json)
Convert a binary-encoded (portable storage format) buffer to its JSON equivalent.
MONERO_EXPORT void monero_utils_free(void *ptr)
Frees a string or byte buffer returned by any monero_utils_* function.
MONERO_EXPORT monero_result monero_utils_binary_blocks_to_json(const uint8_t *data, size_t len, char **out_json)
Decodes a get_blocks.bin-style response.
MONERO_EXPORT monero_result monero_utils_xmr_to_atomic_units(double amount_xmr, uint64_t *out_atomic_units)
Convert an amount in XMR to atomic units.
MONERO_EXPORT int32_t monero_utils_get_ring_size(void)
Return the network-enforced ring size.
MONERO_EXPORT void monero_utils_set_log_categories(const char *categories)
Set the log categories filter directly, overriding whatever monero_utils_set_log_level() last selecte...
MONERO_EXPORT bool monero_utils_is_valid_public_view_key(const char *public_view_key)
Check whether a public view key is valid.
MONERO_EXPORT monero_result monero_utils_get_abi_version(uint32_t *out_major, uint32_t *out_minor, uint32_t *out_patch)
Get the version of the C ABI of the loaded library.
MONERO_EXPORT bool monero_utils_parse_payment_id_short(const char *payment_id_str, uint8_t out_payment_id[8])
Parse a short payment ID from a string.
monero_utils_network_type
Definition monero_c_utils.h:90
@ MONERO_UTILS_NETWORK_MAINNET
Definition monero_c_utils.h:91
@ MONERO_UTILS_NETWORK_REGTEST
Definition monero_c_utils.h:94
@ MONERO_UTILS_NETWORK_TESTNET
Definition monero_c_utils.h:92
@ MONERO_UTILS_NETWORK_STAGENET
Definition monero_c_utils.h:93
MONERO_EXPORT double monero_utils_atomic_units_to_xmr(uint64_t amount_atomic_units)
Convert an amount in atomic units to XMR.
MONERO_EXPORT monero_result monero_utils_validate_mnemonic(const char *mnemonic, const char *language)
Validate a mnemonic seed, like monero_utils_is_valid_mnemonic() but reports the reason through monero...
MONERO_EXPORT bool monero_utils_is_valid_payment_id_short(const char *payment_id_str)
Check whether a short payment id is valid.
MONERO_EXPORT monero_result monero_utils_get_integrated_address(int32_t network_type, const char *standard_address, const char *payment_id, char **out_json)
Builds an integrated address from a standard address and payment id.