17
17
18
18
/* Caller is responsible for thread safety */
19
19
static secp256k1_context * global_ctx = NULL ;
20
+ /* Global extended error code. Not thread-safe unless caller-overridden */
21
+ static int global_error = WALLY_OK ;
20
22
21
23
int wally_get_build_version (uint32_t * value )
22
24
{
@@ -378,15 +380,25 @@ struct secp256k1_context_struct *wally_internal_secp_context(void)
378
380
return global_ctx ;
379
381
}
380
382
383
+ int wally_internal_get_error (void ) {
384
+ return global_error ;
385
+ }
386
+
387
+ int wally_internal_set_error (int error_code )
388
+ {
389
+ global_error = error_code ;
390
+ return error_code ;
391
+ }
392
+
381
393
static struct wally_operations _ops = {
382
394
sizeof (struct wally_operations ),
383
395
wally_internal_malloc ,
384
396
wally_internal_free ,
385
397
wally_internal_bzero ,
386
398
wally_internal_ec_nonce_fn ,
387
399
wally_internal_secp_context ,
388
- NULL ,
389
- NULL ,
400
+ wally_internal_get_error ,
401
+ wally_internal_set_error ,
390
402
NULL ,
391
403
NULL
392
404
};
@@ -428,6 +440,15 @@ char *wally_strdup(const char *str)
428
440
return wally_strdup_n (str , strlen (str ));
429
441
}
430
442
443
+ int wally_get_error (void ) {
444
+ return _ops .get_error_fn ();
445
+ }
446
+
447
+ int wally_set_error (int error_code )
448
+ {
449
+ return _ops .set_error_fn (error_code );
450
+ }
451
+
431
452
const struct wally_operations * wally_ops (void )
432
453
{
433
454
return & _ops ;
@@ -447,7 +468,7 @@ int wally_set_operations(const struct wally_operations *ops)
447
468
return WALLY_EINVAL ; /* Null or invalid version of ops */
448
469
/* Reserved pointers must be null so they can be enabled in the
449
470
* future without breaking back compatibility */
450
- if (ops -> reserved_1 || ops -> reserved_2 || ops -> reserved_3 || ops -> reserved_4 )
471
+ if (ops -> reserved_3 || ops -> reserved_4 )
451
472
return WALLY_EINVAL ;
452
473
453
474
#define COPY_FN_PTR (name ) if (ops->name) _ops.name = ops->name
@@ -456,6 +477,8 @@ int wally_set_operations(const struct wally_operations *ops)
456
477
COPY_FN_PTR (bzero_fn );
457
478
COPY_FN_PTR (ec_nonce_fn );
458
479
COPY_FN_PTR (secp_context_fn );
480
+ COPY_FN_PTR (get_error_fn );
481
+ COPY_FN_PTR (set_error_fn );
459
482
#undef COPY_FN_PTR
460
483
return WALLY_OK ;
461
484
}
0 commit comments