提交 a484af6f 编写于 作者: M Matias Romeo

Implement missing db functions

上级 f1f42c50
......@@ -20,29 +20,106 @@ class apply_context {
TransactionAuthorizationChecker* authChecker)
:controller(con),db(db),trx(t),msg(m),code(code),mutable_controller(con),mutable_db(db),authChecker(authChecker){}
int32_t store_i64( Name scope, Name table, Name key, const char* data, uint32_t len);
int32_t remove_i64( Name scope, Name table, Name key );
int32_t remove_i128i128( Name scope, Name table, uint128_t primary, uint128_t secondary );
int32_t store_i128i128( Name scope, Name table, uint128_t primary, uint128_t secondary,
const char* data, uint32_t len );
int32_t store_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t len);
int32_t load_i64( Name scope, Name code, Name table, Name Key, char* data, uint32_t maxlen );
int32_t update_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t len);
int32_t remove_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t len);
int32_t load_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t maxlen );
int32_t front_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t maxlen );
int32_t back_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t maxlen );
int32_t next_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t maxlen );
int32_t previous_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t maxlen );
int32_t lower_bound_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t maxlen );
int32_t upper_bound_i64( Name scope, Name code, Name table, uint64_t *key, char* data, uint32_t maxlen );
int32_t store_i128i128( Name scope, Name code, Name table, uint128_t* primary, uint128_t* secondary,
char* data, uint32_t len );
int32_t update_i128i128( Name scope, Name code, Name table, uint128_t* primary, uint128_t* secondary,
char* data, uint32_t len );
int32_t remove_i128i128( Name scope, Name code, Name table, uint128_t *primary, uint128_t *secondary,
char* data, uint32_t len );
template <typename T>
int32_t load_i128i128( Name scope, Name code, Name table, uint128_t* primary,
uint128_t* secondary, char* value, uint32_t valuelen );
template <typename T>
int32_t front_i128i128( Name scope, Name code, Name table, uint128_t* primary,
uint128_t* secondary, char* value, uint32_t valuelen );
template <typename T>
int32_t back_i128i128( Name scope, Name code, Name table, uint128_t* primary,
uint128_t* secondary, char* value, uint32_t valuelen );
template <typename T>
int32_t next_i128i128( Name scope, Name code, Name table, uint128_t* primary,
uint128_t* secondary, char* value, uint32_t valuelen );
template <typename T>
int32_t previous_i128i128( Name scope, Name code, Name table, uint128_t* primary,
uint128_t* secondary, char* value, uint32_t valuelen );
template <typename T>
int32_t lower_bound_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* value, uint32_t valuelen );
template <typename T>
int32_t upper_bound_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* value, uint32_t valuelen );
int32_t load_primary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t front_primary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t back_primary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t next_primary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t previous_primary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t lower_bound_primary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t upper_bound_primary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t load_secondary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t front_secondary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t back_secondary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t load_primary_i128i128( Name scope, Name code, Name table,
int32_t next_secondary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t load_secondary_i128i128( Name scope, Name code, Name table,
int32_t previous_secondary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t lowerbound_primary_i128i128( Name scope, Name code, Name table,
int32_t lower_bound_secondary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
int32_t lowerbound_secondary_i128i128( Name scope, Name code, Name table,
int32_t upper_bound_secondary_i128i128( Name scope, Name code, Name table,
uint128_t* primary, uint128_t* secondary, char* data, uint32_t maxlen );
void require_authorization(const types::AccountName& account);
......
......@@ -8,8 +8,6 @@
namespace eos { namespace chain {
class chain_controller;
typedef int32_t (apply_context::*load_i128i128_fnc)(Name, Name, Name, uint128_t* , uint128_t*, char* , uint32_t);
/**
* @class wasm_interface
*
......@@ -64,7 +62,11 @@ class wasm_interface {
wasm_interface();
int32_t load_i128i128_object( uint64_t scope, uint64_t code, uint64_t table, int32_t valueptr, int32_t valuelen, load_i128i128_fnc function );
template <typename Function>
int32_t validate_i128i128(int32_t valueptr, int32_t valuelen, Function&& func);
template <typename Function>
int32_t validate_i64(int32_t valueptr, int32_t valuelen, Function&& func);
};
......
......@@ -33,15 +33,15 @@ DEFINE_INTRINSIC_FUNCTION0(env,checktime,checktime,none) {
throw checktime_exceeded();
}
}
int32_t load_i128i128_object( uint64_t scope, uint64_t code, uint64_t table, int32_t valueptr, int32_t valuelen, load_i128i128_fnc function ) {
template <typename Function>
int32_t validate_i128i128(int32_t valueptr, int32_t valuelen, Function&& func) {
static const uint32_t keylen = 2*sizeof(uint128_t);
FC_ASSERT( valuelen >= keylen, "insufficient data passed" );
auto& wasm = wasm_interface::get();
FC_ASSERT( wasm.current_validate_context, "no validate context found" );
FC_ASSERT( wasm.current_apply_context, "no apply context found" );
char* value = memoryArrayPtr<char>( wasm.current_memory, valueptr, valuelen );
uint128_t* primary = reinterpret_cast<uint128_t*>(value);
......@@ -50,14 +50,54 @@ DEFINE_INTRINSIC_FUNCTION0(env,checktime,checktime,none) {
valuelen -= keylen;
value += keylen;
auto res = (wasm.current_validate_context->*function)(
Name(scope), Name(code), Name(table),
primary, secondary, value, valuelen
);
return func(wasm.current_apply_context, primary, secondary, value, valuelen);
}
template <typename Function>
int32_t validate_i64(int32_t valueptr, int32_t valuelen, Function&& func) {
static const uint32_t keylen = sizeof(uint64_t);
FC_ASSERT( valuelen >= keylen );
auto& wasm = wasm_interface::get();
FC_ASSERT( wasm.current_apply_context, "no apply context found" );
if(res > 0) res += keylen;
return res;
auto mem = wasm.current_memory;
char* value = memoryArrayPtr<char>( mem, valueptr, valuelen);
uint64_t* key = reinterpret_cast<uint64_t*>(value);
valuelen -= keylen;
value += keylen;
return func(wasm.current_apply_context, key, value, valuelen);
}
#define READ_i64_OBJ(func_name) \
validate_i64(valueptr, valuelen, [&](apply_context* ctx, uint64_t* key, char *data, uint32_t datalen) -> int32_t { \
auto res = ctx->func_name( Name(scope), Name(code), Name(table), key, data, datalen); \
if (res >= 0) res += sizeof(uint64_t); \
return res; \
});
#define UPDATE_i64_OBJ(func_name, data_size) \
validate_i64(valueptr, data_size, [&](apply_context* ctx, uint64_t* key, char *data, uint32_t datalen) -> int32_t { \
return ctx->func_name( Name(scope), Name(ctx->code.value), Name(table), key, data, datalen); \
});
#define READ_i128i128_OBJ(func_name) \
validate_i128i128(valueptr, valuelen, [&](apply_context* ctx, uint128_t* primary, uint128_t* secondary, char *data, uint32_t datalen) -> int32_t { \
auto res = ctx->func_name( Name(scope), Name(code), Name(table), primary, secondary, data, datalen); \
if (res >= 0) res += 2*sizeof(uint128_t); \
return res; \
});
#define UPDATE_i128i128_OBJ(func_name, data_size) \
validate_i128i128(valueptr, data_size, [&](apply_context* ctx, uint128_t* primary, uint128_t* secondary, char *data, uint32_t datalen) -> int32_t { \
return ctx->func_name( Name(scope), Name(ctx->code.value), Name(table), primary, secondary, data, datalen); \
});
DEFINE_INTRINSIC_FUNCTION3(env, assert_sha256,assert_sha256,none,i32,dataptr,i32,datalen,i32,hash) {
FC_ASSERT( datalen > 0 );
......@@ -104,25 +144,44 @@ DEFINE_INTRINSIC_FUNCTION0(env,now,now,i32) {
return wasm_interface::get().current_validate_context->controller.head_block_time().sec_since_epoch();
}
DEFINE_INTRINSIC_FUNCTION4(env,store_i128i128,store_i128i128,i32,i64,scope,i64,table,i32,valueptr,i32,valuelen) {
DEFINE_INTRINSIC_FUNCTION4(env,store_i64,store_i64,i32,i64,scope,i64,table,i32,valueptr,i32,valuelen) {
return UPDATE_i64_OBJ(store_i64, valuelen);
}
static const uint32_t keylen = 2*sizeof(uint128_t);
DEFINE_INTRINSIC_FUNCTION4(env,update_i64,update_i64,i32,i64,scope,i64,table,i32,valueptr,i32,valuelen) {
return UPDATE_i64_OBJ(update_i64, valuelen);
}
FC_ASSERT( valuelen >= keylen, "insufficient data passed" );
DEFINE_INTRINSIC_FUNCTION3(env,remove_i64,remove_i64,i32,i64,scope,i64,table,i32,valueptr) {
return UPDATE_i64_OBJ(remove_i64, sizeof(uint64_t));
}
auto& wasm = wasm_interface::get();
FC_ASSERT( wasm.current_apply_context, "no apply context found" );
DEFINE_INTRINSIC_FUNCTION5(env,load_i64,load_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i64_OBJ(load_i64);
}
char* value = memoryArrayPtr<char>( wasm.current_memory, valueptr, valuelen );
uint128_t* primary = reinterpret_cast<uint128_t*>(value);
uint128_t* secondary = primary + 1;
DEFINE_INTRINSIC_FUNCTION5(env,front_i64,front_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i64_OBJ(front_i64);
}
valuelen -= keylen;
value += keylen;
DEFINE_INTRINSIC_FUNCTION5(env,back_i64,back_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i64_OBJ(back_i64);
}
//wdump((datalen)(valuelen)(result));
return wasm.current_apply_context->store_i128i128( Name(scope), Name(table),
*primary, *secondary, value, valuelen );
DEFINE_INTRINSIC_FUNCTION5(env,next_i64,next_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i64_OBJ(next_i64);
}
DEFINE_INTRINSIC_FUNCTION5(env,previous_i64,previous_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i64_OBJ(previous_i64);
}
DEFINE_INTRINSIC_FUNCTION5(env,lower_bound_i64,lower_bound_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i64_OBJ(lower_bound_i64);
}
DEFINE_INTRINSIC_FUNCTION5(env,upper_bound_i64,upper_bound_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i64_OBJ(upper_bound_i64);
}
struct i128_keys {
......@@ -130,36 +189,72 @@ struct i128_keys {
uint128_t secondary;
};
DEFINE_INTRINSIC_FUNCTION3(env,remove_i128i128,remove_i128i128,i32,i64,scope,i64,table,i32,data) {
auto& wasm = wasm_interface::get();
FC_ASSERT( wasm.current_apply_context, "not a valid apply context" );
DEFINE_INTRINSIC_FUNCTION4(env,store_i128i128,store_i128i128,i32,i64,scope,i64,table,i32,valueptr,i32,valuelen) {
return UPDATE_i128i128_OBJ(store_i128i128, valuelen);
}
DEFINE_INTRINSIC_FUNCTION4(env,update_i128i128,update_i128i128,i32,i64,scope,i64,table,i32,valueptr,i32,valuelen) {
return UPDATE_i128i128_OBJ(update_i128i128, valuelen);
}
const i128_keys& keys = memoryRef<const i128_keys>( wasm.current_memory, data );
return wasm_interface::get().current_apply_context->remove_i128i128( Name(scope), Name(table), keys.primary, keys.secondary );
DEFINE_INTRINSIC_FUNCTION3(env,remove_i128i128,remove_i128i128,i32,i64,scope,i64,table,i32,valueptr) {
return UPDATE_i128i128_OBJ(remove_i128i128, 2*sizeof(uint128_t));
}
DEFINE_INTRINSIC_FUNCTION5(env,load_primary_i128i128,load_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return load_i128i128_object(scope, code, table, valueptr, valuelen, &apply_context::load_primary_i128i128);
return READ_i128i128_OBJ(load_primary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,load_secondary_i128i128,load_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return load_i128i128_object(scope, code, table, valueptr, valuelen, &apply_context::load_secondary_i128i128);
DEFINE_INTRINSIC_FUNCTION5(env,front_primary_i128i128,front_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(front_primary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,back_primary_i128i128,back_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return load_i128i128_object(scope, code, table, valueptr, valuelen, &apply_context::back_primary_i128i128);
return READ_i128i128_OBJ(back_primary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,front_primary_i128i128,front_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return load_i128i128_object(scope, code, table, valueptr, valuelen, &apply_context::front_primary_i128i128);
DEFINE_INTRINSIC_FUNCTION5(env,next_primary_i128i128,next_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(next_primary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,previous_primary_i128i128,previous_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(previous_primary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,upper_bound_primary_i128i128,upper_bound_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(upper_bound_primary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,lower_bound_primary_i128i128,lower_bound_primary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(lower_bound_primary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,load_secondary_i128i128,load_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(load_secondary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,back_secondary_i128i128,back_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return load_i128i128_object(scope, code, table, valueptr, valuelen, &apply_context::back_secondary_i128i128);
return READ_i128i128_OBJ(back_secondary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,front_secondary_i128i128,front_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return load_i128i128_object(scope, code, table, valueptr, valuelen, &apply_context::front_secondary_i128i128);
return READ_i128i128_OBJ(front_secondary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,next_secondary_i128i128,next_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(next_secondary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,previous_secondary_i128i128,previous_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(previous_secondary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,upper_bound_secondary_i128i128,upper_bound_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(upper_bound_secondary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION5(env,lower_bound_secondary_i128i128,lower_bound_secondary_i128i128,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen) {
return READ_i128i128_OBJ(lower_bound_secondary_i128i128);
}
DEFINE_INTRINSIC_FUNCTION0(env,currentCode,currentCode,i64) {
......@@ -182,55 +277,6 @@ DEFINE_INTRINSIC_FUNCTION1(env,requireScope,requireScope,none,i64,scope) {
wasm_interface::get().current_validate_context->require_scope( scope );
}
DEFINE_INTRINSIC_FUNCTION4(env,store_i64,store_i64,i32,i64,scope,i64,table,i32,valueptr,i32,valuelen)
{
static const uint32_t keylen = sizeof(uint64_t);
FC_ASSERT( valuelen >= sizeof(uint64_t) );
auto& wasm = wasm_interface::get();
FC_ASSERT( wasm.current_apply_context, "no apply context found" );
auto mem = wasm.current_memory;
char* value = memoryArrayPtr<char>( mem, valueptr, valuelen);
uint64_t* key = reinterpret_cast<uint64_t*>(value);
valuelen -= keylen;
value += keylen;
//idump((Name(scope))(Name(code))(Name(table))(Name(key))(valuelen) );
return wasm.current_apply_context->store_i64( scope, table, *key, value, valuelen );
}
DEFINE_INTRINSIC_FUNCTION5(env,load_i64,load_i64,i32,i64,scope,i64,code,i64,table,i32,valueptr,i32,valuelen)
{
//idump((Name(scope))(Name(code))(Name(table))(Name(key))(valuelen) );
static const uint32_t keylen = sizeof(uint64_t);
FC_ASSERT( valuelen >= keylen );
auto& wasm = wasm_interface::get();
FC_ASSERT( wasm.current_validate_context, "no validate context found" );
auto mem = wasm.current_memory;
char* value = memoryArrayPtr<char>( mem, valueptr, valuelen);
uint64_t* key = reinterpret_cast<uint64_t*>(value);
valuelen -= keylen;
value += keylen;
auto res = wasm.current_validate_context->load_i64( scope, code, table, *key, value, valuelen );
if(res > 0) res += keylen;
return res;
}
DEFINE_INTRINSIC_FUNCTION3(env,remove_i64,remove_i64,i32,i64,scope,i64,table,i64,key) {
auto& wasm = wasm_interface::get();
FC_ASSERT( wasm.current_apply_context, "no apply context found" );
return wasm.current_apply_context->remove_i64( scope, table, key );
}
DEFINE_INTRINSIC_FUNCTION3(env,memcpy,memcpy,i32,i32,dstp,i32,srcp,i32,len) {
auto& wasm = wasm_interface::get();
auto mem = wasm.current_memory;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册