2017-09-13 17:40:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-28 21:13:46 +00:00
|
|
|
/**
|
|
|
|
* Some code to help with the datastore / blockstore interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2017-09-13 17:40:48 +00:00
|
|
|
#include "ipfs/blocks/block.h"
|
|
|
|
#include "libp2p/db/datastore.h"
|
2016-11-28 21:13:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a key based on the passed in binary_array
|
|
|
|
* @param binary_array what to base the key on
|
|
|
|
* @param array_length the size of the binary array
|
|
|
|
* @param results where the key will be put
|
|
|
|
* @param max_results_length the size of the results buffer
|
|
|
|
* @param results_length the length of the generated key
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
2016-12-21 11:40:19 +00:00
|
|
|
int ipfs_datastore_helper_ds_key_from_binary(const unsigned char* binary_array, size_t array_length,
|
2016-12-14 11:25:09 +00:00
|
|
|
unsigned char* results, size_t max_results_length, size_t* results_length);
|
2016-11-28 21:13:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a binary array based on the passed in datastore key
|
|
|
|
* @param ds_key the base32 encoded key
|
|
|
|
* @param key_length the length of the base32 "string"
|
|
|
|
* @param binary_array where to put the decoded value
|
|
|
|
* @param max_binary_array_length the memory size of binary_array
|
|
|
|
* @param completed_binary_array_length the length of what was written to the binary_array
|
|
|
|
* @returns true(1) on success
|
|
|
|
*/
|
2016-12-21 11:40:19 +00:00
|
|
|
int ipfs_datastore_helper_binary_from_ds_key(const unsigned char* ds_key, size_t key_length, unsigned char* binary_array,
|
2016-11-28 21:13:46 +00:00
|
|
|
size_t max_binary_array_length, size_t* completed_binary_array_length);
|
|
|
|
|
2017-09-13 17:40:48 +00:00
|
|
|
/***
|
|
|
|
* Add a record in the datastore based on a block
|
|
|
|
* @param block the block
|
|
|
|
* @param datastore the Datastore
|
|
|
|
* @reutrns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
|
|
|
int ipfs_datastore_helper_add_block_to_datastore(struct Block* block, struct Datastore* datastore);
|