Adding work generation to c API.
This commit is contained in:
parent
7baff45552
commit
cddddf98f1
3 changed files with 42 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <rai/lib/blocks.hpp>
|
||||
#include <rai/lib/numbers.hpp>
|
||||
#include <rai/lib/interface.h>
|
||||
#include <rai/lib/work.hpp>
|
||||
|
||||
TEST (interface, xrb_uint256_to_string)
|
||||
{
|
||||
|
@ -98,3 +99,21 @@ TEST (interface, sign_transaction)
|
|||
ASSERT_FALSE (rai::validate_message (pub, send.hash (), send1->signature));
|
||||
free (transaction);
|
||||
}
|
||||
|
||||
TEST (interface, work_transaction)
|
||||
{
|
||||
rai::raw_key key;
|
||||
xrb_generate_random (key.data.bytes.data ());
|
||||
rai::uint256_union pub;
|
||||
xrb_key_account (key.data.bytes.data (), pub.bytes.data ());
|
||||
rai::send_block send (1, 0, 0, key, pub, 0);
|
||||
auto transaction (xrb_work_transaction (send.to_json ().c_str ()));
|
||||
boost::property_tree::ptree block_l;
|
||||
std::string transaction_l (transaction);
|
||||
std::stringstream block_stream (transaction_l);
|
||||
boost::property_tree::read_json (block_stream, block_l);
|
||||
auto block (rai::deserialize_block_json (block_l));
|
||||
ASSERT_NE (nullptr, block);
|
||||
ASSERT_FALSE (rai::work_validate (*block));
|
||||
free (transaction);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <rai/lib/blocks.hpp>
|
||||
#include <rai/lib/numbers.hpp>
|
||||
#include <rai/lib/work.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
@ -96,6 +97,26 @@ char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private
|
|||
return result;
|
||||
}
|
||||
|
||||
char * xrb_work_transaction (const char * transaction)
|
||||
{
|
||||
char * result (nullptr);
|
||||
boost::property_tree::ptree block_l;
|
||||
std::string transaction_l (transaction);
|
||||
std::stringstream block_stream (transaction_l);
|
||||
boost::property_tree::read_json (block_stream, block_l);
|
||||
auto block (rai::deserialize_block_json (block_l));
|
||||
if (block != nullptr)
|
||||
{
|
||||
rai::work_pool pool (std::thread::hardware_concurrency ());
|
||||
auto work (pool.generate (block->root ()));
|
||||
block->block_work_set (work);
|
||||
auto json (block->to_json ());
|
||||
result = reinterpret_cast <char *> (malloc (json.size () + 1));
|
||||
strncpy (result, json.c_str (), json.size () + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#include <ed25519-donna/ed25519-hash-custom.h>
|
||||
void ed25519_randombytes_unsafe (void * out, size_t outlen)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,8 @@ void xrb_key_account (xrb_uint256 key, xrb_uint256 pub);
|
|||
|
||||
// Sign 'transaction' using 'private_key' and write to 'signature'
|
||||
char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private_key);
|
||||
// Generate work for 'transaction'
|
||||
char * xrb_work_transaction (const char * transaction);
|
||||
|
||||
#if __cplusplus
|
||||
} // extern "C"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue