Browse Source

new api full/light test and get_cache()

- Adding new api full and light client test

- Moving the test for the old API into a deprecated section. Will get
  deleted along with that API.

- Adding 2 new functions for light/full clients. One to get the pointer
  to the cache and one to move it out of the client
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
5394bd6834
  1. 33
      ethash.h
  2. 35
      internal.c

33
ethash.h

@ -143,6 +143,23 @@ bool ethash_light_compute(ethash_return_value *ret,
ethash_params const *params,
const ethash_h256_t *header_hash,
const uint64_t nonce);
/**
* Get a pointer to the cache object held by the light client
*
* @param light The light client whose cache to request
* @return A pointer to the cache held by the light client or NULL if
* there was no cache in the first place
*/
ethash_cache *ethash_light_get_cache(ethash_light_t light);
/**
* Move the memory ownership of the cache somewhere else
*
* @param light The light client whose cache's memory ownership to acquire.
* After this function concludes it will no longer have a cache.
* @return A pointer to the moved cache or NULL if there was no cache in the first place
*/
ethash_cache *ethash_light_acquire_cache(ethash_light_t light);
/**
* Allocate and initialize a new ethash_full handler
*
@ -186,6 +203,22 @@ bool ethash_full_compute(ethash_return_value *ret,
ethash_params const *params,
const ethash_h256_t *header_hash,
const uint64_t nonce);
/**
* Get a pointer to the cache object held by the full client
*
* @param full The full client whose cache to request
* @return A pointer to the cache held by the full client or NULL
* if there was no cache in the first place
*/
ethash_cache *ethash_full_get_cache(ethash_full_t full);
/**
* Move the memory ownership of the cache somewhere else
*
* @param full The full client whose cache's memory ownership to acquire.
* After this function concludes it will no longer have a cache.
* @return A pointer to the moved cache or NULL if there was no cache in the first place
*/
ethash_cache *ethash_full_acquire_cache(ethash_full_t full);
void ethash_get_seedhash(ethash_h256_t *seedhash, const uint32_t block_number);

35
internal.c

@ -331,7 +331,7 @@ int ethash_quick_check_difficulty(ethash_h256_t const *header_hash,
ethash_light_t ethash_light_new(ethash_params const *params, ethash_h256_t const *seed)
{
struct ethash_light *ret;
ret = malloc(sizeof(*ret));
ret = calloc(sizeof(*ret), 1);
if (!ret) {
return NULL;
}
@ -348,7 +348,9 @@ fail_free_light:
void ethash_light_delete(ethash_light_t light)
{
ethash_cache_delete(light->cache);
if (light->cache) {
ethash_cache_delete(light->cache);
}
free(light);
}
@ -361,13 +363,25 @@ bool ethash_light_compute(ethash_return_value *ret,
return ethash_hash(ret, NULL, light->cache, params, header_hash, nonce, NULL);
}
ethash_cache *ethash_light_get_cache(ethash_light_t light)
{
return light->cache;
}
ethash_cache *ethash_light_acquire_cache(ethash_light_t light)
{
ethash_cache* ret = light->cache;
light->cache = 0;
return ret;
}
ethash_full_t ethash_full_new(ethash_params const* params,
ethash_cache const* cache,
const ethash_h256_t *seed,
ethash_callback_t callback)
{
struct ethash_full *ret;
ret = malloc(sizeof(*ret));
ret = calloc(sizeof(*ret), 1);
if (!ret) {
return NULL;
}
@ -392,7 +406,9 @@ fail_free_full:
void ethash_full_delete(ethash_full_t full)
{
ethash_cache_delete(full->cache);
if (full->cache) {
ethash_cache_delete(full->cache);
}
free(full->data);
free(full);
}
@ -412,6 +428,17 @@ bool ethash_full_compute(ethash_return_value *ret,
full->callback);
}
ethash_cache *ethash_full_get_cache(ethash_full_t full)
{
return full->cache;
}
ethash_cache *ethash_full_acquire_cache(ethash_full_t full)
{
ethash_cache* ret = full->cache;
full->cache = 0;
return ret;
}
/**
* =========================

Loading…
Cancel
Save