diff --git a/src/main.cc b/src/main.cc index bdd1401..617f01d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -195,6 +195,38 @@ void construct_block_blob(const Nan::FunctionCallbackInfo& info) { blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf)); blobdata output = ""; + block b = AUTO_VAL_INIT(b); + if (!parse_and_validate_block_from_blob(block_template_blob, b)) + return THROW_ERROR_EXCEPTION("Failed to parse block"); + + if (!block_to_blob(b, output)) + return THROW_ERROR_EXCEPTION("Failed to convert block to blob"); + + v8::Local returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked(); + info.GetReturnValue().Set( + returnValue + ); +} + +void construct_block_blob_fa(const Nan::FunctionCallbackInfo& info) { + + if (info.Length() < 2) + return THROW_ERROR_EXCEPTION("You must provide two arguments."); + + Local block_template_buf = info[0]->ToObject(); + Local nonce_buf = info[1]->ToObject(); + + if (!Buffer::HasInstance(block_template_buf) || !Buffer::HasInstance(nonce_buf)) + return THROW_ERROR_EXCEPTION("Both arguments should be buffer objects."); + + if (Buffer::Length(nonce_buf) != 4) + return THROW_ERROR_EXCEPTION("Nonce buffer has invalid size."); + + uint32_t nonce = *reinterpret_cast(Buffer::Data(nonce_buf)); + + blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf)); + blobdata output = ""; + block b = AUTO_VAL_INIT(b); if (!parse_and_validate_block_from_blob(block_template_blob, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");