Skip to content

Commit

Permalink
manual merge much of identity and master
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Feb 1, 2018
1 parent 57b8283 commit 0826700
Show file tree
Hide file tree
Showing 15 changed files with 1,152 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*.wasm
*.s
*.dot
*.abi.hpp
*.cmake
\#*
\.#*
CMakeCache.txt
Expand Down
1 change: 1 addition & 0 deletions CMakeModules/wasm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ macro(add_wast_target target INCLUDE_FOLDERS DESTINATION_FOLDER)
# NOTE: Setting SOURCE_FILE and looping over it to avoid cmake issue with compilation ${target}.bc's rule colliding with
# linking ${target}.bc's rule
set(SOURCE_FILE ${target}.cpp)
set(outfiles "")
foreach(srcfile ${SOURCE_FILE})

get_filename_component(outfile ${srcfile} NAME)
Expand Down
1 change: 1 addition & 0 deletions contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(eosio.system)
add_subdirectory(identity)
add_subdirectory(currency)
#add_subdirectory(bancor)
#add_subdirectory(eosio.system)
Expand Down
1 change: 1 addition & 0 deletions contracts/eosiolib/dispatcher.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <eosiolib/print.hpp>
#include <eosiolib/action.hpp>

namespace eosio {
template<typename Contract, typename FirstAction>
Expand Down
6 changes: 3 additions & 3 deletions contracts/eosiolib/singleton.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <eosiolib/db.hpp>
#include <eosiolib/raw.hpp>
#include <eosiolib/datastream.hpp>

namespace eosio {

Expand Down Expand Up @@ -31,7 +31,7 @@ namespace eosio {
datastream<const char*> ds(temp + sizeof(SingletonName), read);

T result;
raw::unpack( ds, result );
unpack( ds, result );
return result;
}

Expand All @@ -53,7 +53,7 @@ namespace eosio {
}

static void set( const T& value = T(), scope_name scope = Code ) {
auto size = raw::pack_size( value );
auto size = pack_size( value );
char buf[size+ sizeof(SingletonName)];

assert( sizeof(buf) <= 1024 + 8, "singleton too big to store" );
Expand Down
82 changes: 81 additions & 1 deletion contracts/eosiolib/table.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <eosiolib/db.h>

namespace eosio {

Expand Down Expand Up @@ -44,6 +45,21 @@ namespace eosio {
return result;
}

static T get_or_default( uint64_t key, scope_name scope = DefaultScope, const T& def = T() ) {
char temp[1024];
*reinterpret_cast<uint64_t *>(temp) = key;

auto read = load_i64( scope, DefaultScope, TableName, temp, sizeof(temp) );
if( read < 0 ) {
return def;
}

datastream<const char*> ds(temp, read);
T result;
ds >> result;
return result;
}

static void set( const T& value = T(), scope_name scope = DefaultScope ) {
auto size = pack_size( value );
char buf[size];
Expand All @@ -52,8 +68,72 @@ namespace eosio {
datastream<char*> ds( buf, size );
ds << value;

store_i64( scope, TableName, buf, sizeof(buf) );
store_i64( scope, TableName, buf, ds.tellp() );
}

static void remove( uint64_t key, scope_name scope = DefaultScope ) {
remove_i64(scope, TableName, &key);
}
};


template<uint64_t Code, uint64_t TableName, typename T>
class table_i64i64i64 {
public:
table_i64i64i64( uint64_t scope = Code )
:_scope(scope){}

bool primary_lower_bound( T& result,
uint64_t primary = 0,
uint64_t secondary = 0,
uint64_t tertiary = 0 ) {

uint64_t temp[1024/8];
temp[0] = primary;
temp[1] = secondary;
temp[2] = tertiary;

auto read = lower_bound_primary_i64i64i64( Code, _scope, TableName,
(char*)temp, sizeof(temp) );
if( read <= 0 ) {
return false;
}

datastream<const char*> ds( (char*)temp, sizeof(temp) );
ds >> result;
return true;
}

bool next_primary( T& result, const T& current ) {
uint64_t temp[1024/8];
memcpy( temp, (const char*)&current, 3*sizeof(uint64_t) );

auto read = next_primary_i64i64i64( Code, _scope, TableName,
(char*)temp, sizeof(temp) );
if( read <= 0 ) {
return false;
}

datastream<const char*> ds( (char*)temp, sizeof(temp) );
ds >> result;
return true;
}

void store( const T& value, account_name bill_to ) {
char temp[1024];
datastream<char*> ds(temp, sizeof(temp) );
ds << value;

store_i64i64i64( _scope, TableName, temp, ds.tellp() );
}

void remove(uint64_t primary_key, uint64_t seconday_key, uint64_t tertiary_key) {
uint64_t temp[3] = { primary_key, seconday_key, tertiary_key };
remove_i64i64i64(_scope, TableName, temp);
}

private:
uint64_t _scope;
};

}
5 changes: 5 additions & 0 deletions contracts/identity/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file(GLOB ABI_FILES "*.abi")
configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
add_wast_target(identity "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_BINARY_DIR})

add_subdirectory(test)
119 changes: 119 additions & 0 deletions contracts/identity/identity.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"types": [{
"new_type_name": "account_name",
"type": "name"
},{
"new_type_name": "identity_name",
"type": "name"
},{
"new_type_name": "property_name",
"type": "name"
}
],
"structs": [{
"name": "create",
"base": "",
"fields": [
{"name":"creator", "type":"account_name"},
{"name":"identity", "type":"uint64"}
]
},{
"name": "certvalue",
"base": "",
"fields": [
{"name":"property", "type":"name"},
{"name":"type", "type":"string"},
{"name":"data", "type":"uint8[]"},
{"name":"memo", "type":"string"},
{"name":"confidence", "type":"uint8"},
]
},{
"name": "certprop",
"base": "",
"fields": [
{"name":"bill_storage_to", "type":"account_name"},
{"name":"certifier", "type":"account_name"},
{"name":"identity", "type":"uint64"},
{"name":"value", "type":"certvalue[]"}
]
},{
"name": "settrust",
"base": "",
"fields": [
{"name":"trustor", "type":"account_name"},
{"name":"trusting", "type":"account_name"},
{"name":"trust", "type":"uint8"}
]
},{
"name": "certrow",
"base": "",
"fields": [
{"name":"property", "type":"property_name"},
{"name":"trusted", "type":"uint64"},
{"name":"certifier", "type":"account_name"},
{"name":"confidence", "type":"uint8"},
{"name":"type", "type":"string"},
{"name":"data", "type":"uint8[]"}
]
},{
"name": "identrow",
"base": "",
"fields": [
{"name":"identity", "type":"uint64"},
{"name":"creator", "type":"account_name"}
]
},{
"name": "trustrow",
"base": "",
"fields": [
{"name":"account", "type":"account_name"},
{"name":"trusted", "type":"uint8"}
]
},{
"name": "accountrow",
"base": "",
"fields": [
{"name":"account", "type":"account_name"}
]
}
],
"actions": [{
"name": "create",
"type": "create"
},{
"name": "certprop",
"type": "certprop"
},{
"name": "settrust",
"type": "settrust"
}
],
"tables": [{
"name": "certs",
"type": "certrow",
"index_type": "i64i64i64",
"key_names" : [
"property",
"trusted",
"certifier"
],
" key_types": [
"uint64",
"uint64",
"uint64"
]
},{
"name": "idents",
"type": "identrow",
"index_type": "i64",
"key_names" : [ "identity" ],
"key_types": [ "uint64" ]
},{
"name": "trust",
"type": "trustrow",
"index_type": "i64",
"key_names" : [ "account" ],
"key_types": [ "account_name" ]
}
]
}
9 changes: 9 additions & 0 deletions contracts/identity/identity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "identity.hpp"

extern "C" {
/// The apply method implements the dispatch of events to this contract
void apply( uint64_t code, uint64_t action ) {
identity::contract< N(identity) >::apply( code, action );
}
}

Loading

0 comments on commit 0826700

Please sign in to comment.