Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-chain
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap-chain
Commits
60b42d88
Commit
60b42d88
authored
5 years ago
by
dmitriy.gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[*] lock_time changes to ts_create (now locks would be with COND_OUT )
parent
a494537d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dap_chain_datum_tx.c
+1
-1
1 addition, 1 deletion
dap_chain_datum_tx.c
dap_chain_datum_tx.h
+1
-1
1 addition, 1 deletion
dap_chain_datum_tx.h
dap_chain_ledger.c
+47
-5
47 additions, 5 deletions
dap_chain_ledger.c
dap_chain_ledger.h
+3
-1
3 additions, 1 deletion
dap_chain_ledger.h
with
52 additions
and
8 deletions
dap_chain_datum_tx.c
+
1
−
1
View file @
60b42d88
...
...
@@ -39,7 +39,7 @@
dap_chain_datum_tx_t
*
dap_chain_datum_tx_create
(
void
)
{
dap_chain_datum_tx_t
*
tx
=
DAP_NEW_Z
(
dap_chain_datum_tx_t
);
tx
->
header
.
lock_time
=
time
(
NULL
);
tx
->
header
.
ts_created
=
time
(
NULL
);
return
tx
;
}
...
...
This diff is collapsed.
Click to expand it.
dap_chain_datum_tx.h
+
1
−
1
View file @
60b42d88
...
...
@@ -52,7 +52,7 @@ typedef enum dap_chain_tx_cond_type {
*/
typedef
struct
dap_chain_datum_tx
{
struct
{
uint64_t
lock_time
;
uint64_t
ts_created
;
uint32_t
tx_items_size
;
// size of next sequencly lying tx_item sections would be decided to belong this transaction
}
DAP_ALIGN_PACKED
header
;
uint8_t
tx_items
[];
...
...
This diff is collapsed.
Click to expand it.
dap_chain_ledger.c
+
47
−
5
View file @
60b42d88
...
...
@@ -69,6 +69,7 @@ typedef struct dap_chain_ledger_token_item {
typedef
struct
dap_chain_ledger_tx_item
{
dap_chain_hash_fast_t
tx_hash_fast
;
dap_chain_datum_tx_t
*
tx
;
time_t
ts_created
;
int
n_outs
;
int
n_outs_used
;
char
token_tiker
[
10
];
...
...
@@ -399,7 +400,8 @@ static dap_chain_datum_tx_t* s_find_datum_tx_by_hash(dap_ledger_t *a_ledger,
* @param a_tx_hash
* @return
*/
const
dap_chain_datum_tx_t
*
dap_chain_ledger_tx_find_by_hash
(
dap_ledger_t
*
a_ledger
,
dap_chain_hash_fast_t
*
a_tx_hash
)
dap_chain_datum_tx_t
*
dap_chain_ledger_tx_find_by_hash
(
dap_ledger_t
*
a_ledger
,
dap_chain_hash_fast_t
*
a_tx_hash
)
{
return
s_find_datum_tx_by_hash
(
a_ledger
,
a_tx_hash
,
NULL
);
}
...
...
@@ -719,6 +721,7 @@ int dap_chain_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx)
l_item_tmp
=
DAP_NEW_Z
(
dap_chain_ledger_tx_item_t
);
memcpy
(
&
l_item_tmp
->
tx_hash_fast
,
l_tx_hash
,
sizeof
(
dap_chain_hash_fast_t
));
l_item_tmp
->
tx
=
DAP_NEW_SIZE
(
dap_chain_datum_tx_t
,
dap_chain_datum_tx_get_size
(
a_tx
));
l_item_tmp
->
ts_created
=
(
time_t
)
a_tx
->
header
.
ts_created
;
//calculate l_item_tmp->n_outs;
// If debug mode dump the UTXO
...
...
@@ -739,7 +742,7 @@ int dap_chain_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx)
// Try to find tocken ticker if wasn't
if
(
l_token_ticker
==
NULL
){
size_
t
l_base_tx_count
=
0
;
in
t
l_base_tx_count
=
0
;
dap_list_t
*
l_base_tx_list
=
dap_chain_datum_tx_items_get
(
a_tx
,
TX_ITEM_TYPE_TOKEN
,
&
l_base_tx_count
);
if
(
l_base_tx_count
>=
1
&&
l_base_tx_list
){
dap_chain_tx_token_t
*
l_tx_token
=
(
dap_chain_tx_token_t
*
)
l_base_tx_list
->
data
;
...
...
@@ -798,9 +801,10 @@ int dap_chain_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx)
dap_list_t
*
l_list_tmp_in
=
dap_chain_datum_tx_items_get
(
a_tx
,
TX_ITEM_TYPE_IN
,
&
l_prev_count
);
for
(
dap_list_t
*
l_item
=
l_list_tmp_in
;
l_item
;
l_item
=
dap_list_next
(
l_item
))
{
dap_chain_tx_in_t
*
l_in_item
=
l_item
->
data
;
dap_chain_hash_fast_t
tx_prev_hash
=
l_in_item
->
header
.
tx_prev_hash
;
if
(
!
dap_hash_fast_is_blank
(
&
tx_prev_hash
))
{
dap_list_t
*
l_list_prev_out
=
dap_chain_datum_tx_items_get
(
l_in_item
,
TX_ITEM_TYPE_OUT
,
NULL
);
dap_chain_hash_fast_t
l_tx_prev_hash
=
l_in_item
->
header
.
tx_prev_hash
;
if
(
!
dap_hash_fast_is_blank
(
&
l_tx_prev_hash
))
{
dap_chain_datum_tx_t
*
l_tx_prev
=
dap_chain_ledger_tx_find_by_hash
(
a_ledger
,
&
l_tx_prev_hash
);
dap_list_t
*
l_list_prev_out
=
dap_chain_datum_tx_items_get
(
l_tx_prev
,
TX_ITEM_TYPE_OUT
,
NULL
);
dap_chain_tx_out_t
*
l_tx_prev_out
=
dap_list_nth_data
(
l_list_prev_out
,
l_in_item
->
header
.
tx_out_prev_idx
);
if
(
l_tx_prev_out
)
{
//charge_off +=
...
...
@@ -919,6 +923,44 @@ _dap_int128_t dap_chain_ledger_count(dap_ledger_t *a_ledger)
return
l_ret
;
}
/**
* @brief dap_chain_ledger_count_from_to
* @param a_ledger
* @param a_ts_from
* @param a_ts_to
* @return
*/
uint64_t
dap_chain_ledger_count_from_to
(
dap_ledger_t
*
a_ledger
,
time_t
a_ts_from
,
time_t
a_ts_to
)
{
uint64_t
l_ret
=
0
;
dap_ledger_private_t
*
l_ledger_priv
=
PVT
(
a_ledger
);
dap_chain_ledger_tx_item_t
*
l_iter_current
,
*
l_item_tmp
;
pthread_rwlock_rdlock
(
&
l_ledger_priv
->
ledger_rwlock
);
if
(
a_ts_from
&&
a_ts_to
)
{
HASH_ITER
(
hh
,
l_ledger_priv
->
ledger_items
,
l_iter_current
,
l_item_tmp
){
if
(
l_iter_current
->
ts_created
>=
a_ts_from
&&
l_iter_current
->
ts_created
<=
a_ts_to
)
l_ret
++
;
}
}
else
if
(
a_ts_to
){
HASH_ITER
(
hh
,
l_ledger_priv
->
ledger_items
,
l_iter_current
,
l_item_tmp
){
if
(
l_iter_current
->
ts_created
<=
a_ts_to
)
l_ret
++
;
}
}
else
if
(
a_ts_from
){
HASH_ITER
(
hh
,
l_ledger_priv
->
ledger_items
,
l_iter_current
,
l_item_tmp
){
if
(
l_iter_current
->
ts_created
>=
a_ts_from
)
l_ret
++
;
}
}
else
{
HASH_ITER
(
hh
,
l_ledger_priv
->
ledger_items
,
l_iter_current
,
l_item_tmp
){
l_ret
++
;
}
}
pthread_rwlock_unlock
(
&
l_ledger_priv
->
ledger_rwlock
);
return
l_ret
;
}
/**
* Check whether used 'out' items (local function)
*/
...
...
This diff is collapsed.
Click to expand it.
dap_chain_ledger.h
+
3
−
1
View file @
60b42d88
...
...
@@ -113,6 +113,8 @@ void dap_chain_ledger_purge(dap_ledger_t *a_ledger);
*/
_dap_int128_t
dap_chain_ledger_count
(
dap_ledger_t
*
a_ledger
);
uint64_t
dap_chain_ledger_count_from_to
(
dap_ledger_t
*
a_ledger
,
time_t
a_ts_from
,
time_t
a_ts_to
);
/**
* Check whether used 'out' items
*/
...
...
@@ -133,7 +135,7 @@ uint64_t dap_chain_ledger_calc_balance_full(dap_ledger_t *a_ledger, const dap_ch
*
* return transaction, or NULL if transaction not found in the cache
*/
const
dap_chain_datum_tx_t
*
dap_chain_ledger_tx_find_by_hash
(
dap_ledger_t
*
a_ledger
,
dap_chain_hash_fast_t
*
a_tx_hash
);
dap_chain_datum_tx_t
*
dap_chain_ledger_tx_find_by_hash
(
dap_ledger_t
*
a_ledger
,
dap_chain_hash_fast_t
*
a_tx_hash
);
// Get the transaction in the cache by the addr in out item
const
dap_chain_datum_tx_t
*
dap_chain_ledger_tx_find_by_addr
(
dap_ledger_t
*
a_ledger
,
...
...
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