Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cellframe-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
16
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
cellframe-sdk
Commits
bc34a0c4
Commit
bc34a0c4
authored
5 years ago
by
alexander.lysikov
Browse files
Options
Downloads
Patches
Plain Diff
added CHAIN_TYPE_XXXX
parent
058cfbd3
No related branches found
No related tags found
1 merge request
!24
Support 3689
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dap_chain.c
+32
-0
32 additions, 0 deletions
dap_chain.c
dap_chain.h
+11
-0
11 additions, 0 deletions
dap_chain.h
dap_chain_cell.c
+5
-2
5 additions, 2 deletions
dap_chain_cell.c
dap_chain_cell.h
+1
-0
1 addition, 0 deletions
dap_chain_cell.h
with
49 additions
and
2 deletions
dap_chain.c
+
32
−
0
View file @
bc34a0c4
...
...
@@ -169,6 +169,8 @@ void dap_chain_delete(dap_chain_t * a_chain)
}
else
log_it
(
L_WARNING
,
"Trying to remove non-existent 0x%16llX:0x%16llX chain"
,
a_chain
->
id
.
uint64
,
a_chain
->
net_id
.
uint64
);
a_chain
->
datum_types_count
=
0
;
DAP_DELETE
(
a_chain
->
datum_types
);
pthread_rwlock_unlock
(
&
s_chain_items_rwlock
);
}
...
...
@@ -243,6 +245,15 @@ dap_chain_t * dap_chain_load_from_cfg(dap_ledger_t* a_ledger, const char * a_cha
return
NULL
;
}
// Read chain datum types
char
**
l_datum_types
=
NULL
;
uint16_t
l_datum_types_count
=
0
;
if
((
l_datum_types
=
dap_config_get_array_str
(
l_cfg
,
"chain"
,
"datum_types"
,
&
l_datum_types_count
))
==
NULL
)
{
log_it
(
L_ERROR
,
"Can't read chain datum types "
,
l_chain_id_str
);
dap_config_close
(
l_cfg
);
return
NULL
;
}
l_chain
=
dap_chain_create
(
a_ledger
,
a_chain_net_name
,
l_chain_name
,
a_chain_net_id
,
l_chain_id
);
if
(
dap_chain_cs_create
(
l_chain
,
l_cfg
)
==
0
)
{
log_it
(
L_NOTICE
,
"Consensus initialized for chain id 0x%016llX"
,
...
...
@@ -252,6 +263,7 @@ dap_chain_t * dap_chain_load_from_cfg(dap_ledger_t* a_ledger, const char * a_cha
DAP_CHAIN_PVT
(
l_chain
)
->
file_storage_dir
=
strdup
(
dap_config_get_item_str
(
l_cfg
,
"files"
,
"storage_dir"
)
)
;
if
(
dap_chain_load_all
(
l_chain
)
!=
0
){
dap_chain_save_all
(
l_chain
);
log_it
(
L_NOTICE
,
"Loaded chain files"
);
}
else
{
dap_chain_save_all
(
l_chain
);
...
...
@@ -268,6 +280,26 @@ dap_chain_t * dap_chain_load_from_cfg(dap_ledger_t* a_ledger, const char * a_cha
dap_chain_delete
(
l_chain
);
l_chain
=
NULL
;
}
// add datum types
if
(
l_chain
&&
l_datum_types_count
>
0
)
{
l_chain
->
datum_types
=
DAP_NEW_SIZE
(
dap_chain_type_t
,
l_datum_types_count
*
sizeof
(
dap_chain_type_t
));
uint16_t
l_count_recognized
=
0
;
for
(
uint16_t
i
=
0
;
i
<
l_datum_types_count
;
i
++
)
{
if
(
!
dap_strcmp
(
l_datum_types
[
i
],
"token"
))
{
l_chain
->
datum_types
[
l_count_recognized
]
=
CHAIN_TYPE_TOKEN
;
l_count_recognized
++
;
}
else
if
(
!
dap_strcmp
(
l_datum_types
[
i
],
"emission"
))
{
l_chain
->
datum_types
[
l_count_recognized
]
=
CHAIN_TYPE_EMISSION
;
l_count_recognized
++
;
}
else
if
(
!
dap_strcmp
(
l_datum_types
[
i
],
"transaction"
))
{
l_chain
->
datum_types
[
l_count_recognized
]
=
CHAIN_TYPE_TX
;
l_count_recognized
++
;
}
}
l_chain
->
datum_types_count
=
l_count_recognized
;
}
dap_config_close
(
l_cfg
);
return
l_chain
;
...
...
This diff is collapsed.
Click to expand it.
dap_chain.h
+
11
−
0
View file @
bc34a0c4
...
...
@@ -75,6 +75,14 @@ typedef size_t (*dap_chain_datum_callback_datum_pool_proc_add_t)(dap_chain_t * ,
typedef
size_t
(
*
dap_chain_datum_callback_datum_pool_proc_add_with_group_t
)(
dap_chain_t
*
,
dap_chain_datum_t
**
,
size_t
,
const
char
*
);
typedef
enum
dap_chain_type
{
CHAIN_TYPE_FIRST
,
CHAIN_TYPE_TOKEN
,
CHAIN_TYPE_EMISSION
,
CHAIN_TYPE_TX
,
CHAIN_TYPE_LAST
}
dap_chain_type_t
;
typedef
struct
dap_chain
{
dap_chain_id_t
id
;
...
...
@@ -87,6 +95,9 @@ typedef struct dap_chain{
// Nested cells (hashtab by cell_id
dap_chain_cell_t
*
cells
;
uint16_t
datum_types_count
;
dap_chain_type_t
*
datum_types
;
// To hold it in double-linked lists
struct
dap_chain
*
next
;
struct
dap_chain
*
prev
;
...
...
This diff is collapsed.
Click to expand it.
dap_chain_cell.c
+
5
−
2
View file @
bc34a0c4
...
...
@@ -53,7 +53,7 @@ typedef struct dap_chain_cell_file_header
}
DAP_ALIGN_PACKED
dap_chain_cell_file_header_t
;
static
const
char
*
s_cells_path
=
NULL
;
//
static const char* s_cells_path = NULL;
/**
* @brief dap_chain_cell_init
...
...
@@ -61,7 +61,7 @@ static const char* s_cells_path = NULL;
*/
int
dap_chain_cell_init
(
void
)
{
s_cells_path
=
dap_config_get_item_str
(
g_config
,
"resources"
,
"cells_storage"
);
//
s_cells_path = dap_config_get_item_str(g_config,"resources","cells_storage");
return
0
;
}
...
...
@@ -112,14 +112,17 @@ int dap_chain_cell_load(dap_chain_t * a_chain, const char * a_cell_file_path)
return
0
;
}
else
{
log_it
(
L_ERROR
,
"Wrong signature in file
\"
%s
\"
, possible file corrupt"
,
l_cell
->
file_storage_path
);
DAP_DELETE
(
l_cell
);
return
-
3
;
}
}
else
{
log_it
(
L_ERROR
,
"Can't read dap_chain file header
\"
%s
\"
"
,
l_cell
->
file_storage_path
);
DAP_DELETE
(
l_cell
);
return
-
2
;
}
}
else
{
log_it
(
L_WARNING
,
"Can't read dap_chain file
\"
%s
\"
"
,
l_cell
->
file_storage_path
);
DAP_DELETE
(
l_cell
);
return
-
1
;
}
...
...
This diff is collapsed.
Click to expand it.
dap_chain_cell.h
+
1
−
0
View file @
bc34a0c4
...
...
@@ -72,6 +72,7 @@ typedef struct dap_chain_cell_decl{
int
dap_chain_cell_init
(
void
);
dap_chain_cell_t
*
dap_chain_cell_create
();
int
dap_chain_cell_load
(
dap_chain_t
*
a_chain
,
const
char
*
a_cell_file_path
);
int
dap_chain_cell_file_update
(
dap_chain_cell_t
*
a_cell
);
int
dap_chain_cell_file_append
(
dap_chain_cell_t
*
a_cell
,
const
void
*
a_atom
,
size_t
a_atom_size
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment