Skip to content
Snippets Groups Projects
Commit c5ee4f79 authored by Krzysztof Leśniak's avatar Krzysztof Leśniak Committed by Bartek Wrona
Browse files

Implement operation_to_vote_operation

parent 4f7bdae4
No related branches found
No related tags found
6 merge requests!627merge in fix for get_current_block_age,!626Fix get_current_block_age function to avoid healthcheck fails,!622merge develop to master,!599merge ( with merge commit) develop to master,!597Merge develop to master for release,!264Implement conversion functions from custom operation type to specific sql operation type
......@@ -202,6 +202,31 @@ Datum comment_options_operation_to_sql_tuple(const hive::protocol::comment_optio
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
}
Datum vote_operation_to_sql_tuple(const hive::protocol::vote_operation& vote, FunctionCallInfo fcinfo)
{
TupleDesc desc;
TypeFuncClass cls = get_call_result_type(fcinfo, nullptr, &desc);
if (cls != TYPEFUNC_COMPOSITE)
{
ereport( ERROR, ( errcode( ERRCODE_DATA_EXCEPTION ), errmsg( "function returning record called in context that cannot accept type record." ) ) );
}
BlessTupleDesc(desc);
Datum values[] = {
CStringGetTextDatum(static_cast<std::string>(vote.voter).c_str()),
CStringGetTextDatum(static_cast<std::string>(vote.author).c_str()),
CStringGetTextDatum(vote.permlink.c_str()),
UInt32GetDatum(vote.weight),
};
bool nulls[] = {
false,
false,
false,
false,
};
HeapTuple tuple = heap_form_tuple(desc, values, nulls);
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
}
}
extern "C"
......@@ -259,4 +284,31 @@ extern "C"
ereport( ERROR, ( errcode( ERRCODE_DATA_EXCEPTION ), errmsg( "Could not convert operation to comment_options_operation" ) ) );
}
}
PG_FUNCTION_INFO_V1( operation_to_vote_operation );
Datum operation_to_vote_operation( PG_FUNCTION_ARGS )
{
_operation* op = PG_GETARG_HIVE_OPERATION_PP( 0 );
uint32 data_length = VARSIZE_ANY_EXHDR( op );
const char* raw_data = VARDATA_ANY( op );
try
{
const hive::protocol::operation operation = raw_to_operation( raw_data, data_length );
const hive::protocol::vote_operation options = operation.get<hive::protocol::vote_operation>();
return vote_operation_to_sql_tuple(options, fcinfo);
}
catch( const fc::exception& e )
{
ereport( ERROR, ( errcode( ERRCODE_DATA_EXCEPTION ), errmsg( "%s", e.to_string().c_str() ) ) );
}
catch( const std::exception& e )
{
ereport( ERROR, ( errcode( ERRCODE_DATA_EXCEPTION ), errmsg( "%s", e.what() ) ) );
}
catch( ... )
{
ereport( ERROR, ( errcode( ERRCODE_DATA_EXCEPTION ), errmsg( "Could not convert operation to vote_operation" ) ) );
}
}
}
......@@ -17,3 +17,14 @@ AS 'MODULE_PATHNAME',
CREATE CAST (hive.operation AS hive.comment_options_operation)
WITH FUNCTION hive._operation_to_comment_options_operation
AS ASSIGNMENT;
CREATE OR REPLACE FUNCTION hive._operation_to_vote_operation(
hive.operation
) RETURNS hive.vote_operation LANGUAGE c IMMUTABLE STRICT PARALLEL SAFE
AS 'MODULE_PATHNAME',
'operation_to_vote_operation';
CREATE CAST (hive.operation AS hive.vote_operation)
WITH FUNCTION hive._operation_to_vote_operation
AS ASSIGNMENT;
......@@ -91,3 +91,11 @@ CREATE TYPE hive.comment_options_operation AS (
allow_curation_rewards boolean,
extensions hive.comment_options_extensions_type
);
CREATE TYPE hive.vote_operation AS (
voter hive.account_name_type,
author hive.account_name_type,
permlink hive.permlink,
weight int4 -- uint16_t: 2 byte, but unsigned (4 byte)
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment