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
8c68e983
Commit
8c68e983
authored
5 years ago
by
dmitriy.gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[*] Moved static to ledger
parent
19a17180
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dap_chain_ledger.c
+16
-13
16 additions, 13 deletions
dap_chain_ledger.c
with
16 additions
and
13 deletions
dap_chain_ledger.c
+
16
−
13
View file @
8c68e983
...
...
@@ -86,11 +86,22 @@ typedef struct dap_chain_ledger_tx_bound {
dap_chain_ledger_tx_item_t
*
item_out
;
}
dap_chain_ledger_tx_bound_t
;
// in-memory wallet balance
typedef
struct
dap_ledger_wallet_balance
{
dap_chain_addr_t
addr
;
uint64_t
balance
;
UT_hash_handle
hh
;
}
dap_ledger_wallet_balance_t
;
// dap_ledget_t private section
typedef
struct
dap_ledger_private
{
// List of ledger - unspent transactions cache
dap_chain_ledger_tx_item_t
*
ledger
;
dap_chain_ledger_token_item_t
*
tokens
;
dap_ledger_wallet_balance_t
*
balance_accounts
;
// for separate access to ledger
pthread_rwlock_t
ledger_rwlock
;
// for separate access to tokens
...
...
@@ -103,14 +114,6 @@ typedef struct dap_ledger_private {
}
dap_ledger_private_t
;
#define PVT(a) ( (dap_ledger_private_t* ) a->_internal )
// in-memory wallet balance
typedef
struct
dap_ledger_wallet_balance
{
dap_chain_addr_t
addr
;
uint64_t
balance
;
UT_hash_handle
hh
;
}
dap_ledger_wallet_balance_t
;
static
dap_ledger_wallet_balance_t
*
balance_accounts
=
NULL
;
static
const
dap_chain_ledger_tx_item_t
*
tx_item_find_by_addr
(
dap_ledger_t
*
a_ledger
,
const
dap_chain_addr_t
*
a_addr
,
dap_chain_hash_fast_t
*
a_tx_first_hash
);
...
...
@@ -719,17 +722,17 @@ int dap_chain_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx)
if
(
l_out_item
&&
&
l_out_item
->
addr
)
{
if
(
!
dap_chain_ledger_tx_hash_is_used_out_item
(
a_ledger
,
&
l_item_tmp
->
tx_hash_fast
,
l_index_tmp
))
{
dap_ledger_wallet_balance_t
*
wallet_balance
=
NULL
;
HASH_FIND
(
hh
,
balance_accounts
,
&
l_out_item
->
addr
,
sizeof
(
wallet_balance
->
addr
),
wallet_balance
);
HASH_FIND
(
hh
,
PVT
(
a_ledger
)
->
balance_accounts
,
&
l_out_item
->
addr
,
sizeof
(
wallet_balance
->
addr
),
wallet_balance
);
if
(
wallet_balance
)
{
wallet_balance
->
balance
+=
l_out_item
->
header
.
value
;
dap_ledger_wallet_balance_t
*
dummy
=
NULL
;
HASH_REPLACE
(
hh
,
balance_accounts
,
addr
,
sizeof
(
&
l_out_item
->
addr
),
wallet_balance
,
dummy
);
HASH_REPLACE
(
hh
,
PVT
(
a_ledger
)
->
balance_accounts
,
addr
,
sizeof
(
&
l_out_item
->
addr
),
wallet_balance
,
dummy
);
}
else
{
wallet_balance
=
DAP_NEW_Z
(
dap_ledger_wallet_balance_t
);
memcpy
(
&
wallet_balance
->
addr
,
&
l_out_item
->
addr
,
sizeof
(
l_out_item
->
addr
));
//wallet_balance->addr = l_out_item->addr;
wallet_balance
->
balance
=
l_out_item
->
header
.
value
;
HASH_ADD
(
hh
,
balance_accounts
,
addr
,
sizeof
(
&
l_out_item
->
addr
),
wallet_balance
);
HASH_ADD
(
hh
,
PVT
(
a_ledger
)
->
balance_accounts
,
addr
,
sizeof
(
&
l_out_item
->
addr
),
wallet_balance
);
}
// TODO : put to local db for fast extraction
}
...
...
@@ -747,11 +750,11 @@ int dap_chain_ledger_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx)
if
(
l_tx_prev_out
)
{
//charge_off +=
dap_ledger_wallet_balance_t
*
wallet_balance
=
NULL
;
HASH_FIND
(
hh
,
balance_accounts
,
&
l_tx_prev_out
->
addr
,
sizeof
(
l_tx_prev_out
->
addr
),
wallet_balance
);
HASH_FIND
(
hh
,
PVT
(
a_ledger
)
->
balance_accounts
,
&
l_tx_prev_out
->
addr
,
sizeof
(
l_tx_prev_out
->
addr
),
wallet_balance
);
if
(
wallet_balance
)
{
wallet_balance
->
balance
-=
l_tx_prev_out
->
header
.
value
;
dap_ledger_wallet_balance_t
*
dummy
=
NULL
;
HASH_REPLACE
(
hh
,
balance_accounts
,
addr
,
sizeof
(
&
l_tx_prev_out
->
addr
),
wallet_balance
,
dummy
);
HASH_REPLACE
(
hh
,
PVT
(
a_ledger
)
->
balance_accounts
,
addr
,
sizeof
(
&
l_tx_prev_out
->
addr
),
wallet_balance
,
dummy
);
}
else
{
// impossible
}
...
...
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