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
17
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
db9b382d
Commit
db9b382d
authored
4 years ago
by
Roman Khlopkov
🔜
Browse files
Options
Downloads
Patches
Plain Diff
[*] Exchange with rate debugged
parent
0591e7d8
No related branches found
No related tags found
1 merge request
!92
features-2844
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/net/dap_chain_node.c
+3
-7
3 additions, 7 deletions
modules/net/dap_chain_node.c
modules/service/xchange/dap_chain_net_srv_xchange.c
+19
-7
19 additions, 7 deletions
modules/service/xchange/dap_chain_net_srv_xchange.c
with
22 additions
and
14 deletions
modules/net/dap_chain_node.c
+
3
−
7
View file @
db9b382d
...
@@ -263,15 +263,11 @@ int dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_node_role_t a
...
@@ -263,15 +263,11 @@ int dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_node_role_t a
if
(
l_datum
->
header
.
type_id
==
DAP_CHAIN_DATUM_TX
)
{
if
(
l_datum
->
header
.
type_id
==
DAP_CHAIN_DATUM_TX
)
{
dap_chain_datum_tx_t
*
l_tx
=
(
dap_chain_datum_tx_t
*
)
l_datum
->
data
;
dap_chain_datum_tx_t
*
l_tx
=
(
dap_chain_datum_tx_t
*
)
l_datum
->
data
;
dap_chain_tx_in_t
*
l_tx_in
=
(
dap_chain_tx_in_t
*
)
dap_chain_datum_tx_item_get
(
l_tx
,
NULL
,
TX_ITEM_TYPE_IN
,
NULL
);
dap_chain_tx_in_t
*
l_tx_in
=
(
dap_chain_tx_in_t
*
)
dap_chain_datum_tx_item_get
(
l_tx
,
NULL
,
TX_ITEM_TYPE_IN
,
NULL
);
// Is it a base transaction?
// Is not it a base transaction?
if
(
dap_hash_fast_is_blank
(
&
l_tx_in
->
header
.
tx_prev_hash
))
{
if
(
l_tx_in
&&
!
dap_hash_fast_is_blank
(
&
l_tx_in
->
header
.
tx_prev_hash
))
{
dap_chain_tx_token_t
*
l_tx_token
=
(
dap_chain_tx_token_t
*
)
dap_chain_datum_tx_item_get
(
l_tx
,
NULL
,
TX_ITEM_TYPE_TOKEN
,
NULL
);
if
(
a_role
.
enums
==
NODE_ROLE_ROOT
)
{
if
(
l_tx_token
&&
!
dap_chain_ledger_token_emission_find
(
a_chain
->
ledger
,
l_tx_token
->
header
.
ticker
,
&
l_tx_token
->
header
.
token_emission_hash
))
{
continue
;
continue
;
}
}
}
else
if
(
a_role
.
enums
==
NODE_ROLE_ROOT
)
{
continue
;
}
}
}
}
if
(
a_chain
->
callback_datums_pool_proc
(
a_chain
,
&
l_datum
,
1
)
!=
1
)
{
if
(
a_chain
->
callback_datums_pool_proc
(
a_chain
,
&
l_datum
,
1
)
!=
1
)
{
...
...
This diff is collapsed.
Click to expand it.
modules/service/xchange/dap_chain_net_srv_xchange.c
+
19
−
7
View file @
db9b382d
...
@@ -90,6 +90,7 @@ void dap_chain_net_srv_xchange_deinit()
...
@@ -90,6 +90,7 @@ void dap_chain_net_srv_xchange_deinit()
dap_chain_net_srv_xchange_price_t
*
l_price
=
NULL
,
*
l_tmp
;
dap_chain_net_srv_xchange_price_t
*
l_price
=
NULL
,
*
l_tmp
;
HASH_ITER
(
hh
,
s_srv_xchange
->
pricelist
,
l_price
,
l_tmp
)
{
HASH_ITER
(
hh
,
s_srv_xchange
->
pricelist
,
l_price
,
l_tmp
)
{
HASH_DEL
(
s_srv_xchange
->
pricelist
,
l_price
);
HASH_DEL
(
s_srv_xchange
->
pricelist
,
l_price
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
);
DAP_DELETE
(
l_price
);
}
}
...
@@ -334,8 +335,7 @@ static bool s_xchange_tx_put(dap_chain_datum_tx_t *a_tx, dap_chain_net_t *a_net)
...
@@ -334,8 +335,7 @@ static bool s_xchange_tx_put(dap_chain_datum_tx_t *a_tx, dap_chain_net_t *a_net)
return
false
;
return
false
;
}
}
// Processing will be made according to autoprocess policy
// Processing will be made according to autoprocess policy
size_t
l_datums_number
=
dap_chain_mempool_datum_add
(
l_datum
,
l_chain
);
if
(
dap_chain_mempool_datum_add
(
l_datum
,
l_chain
))
{
if
(
!
l_datums_number
)
{
DAP_DELETE
(
l_datum
);
DAP_DELETE
(
l_datum
);
return
false
;
return
false
;
}
}
...
@@ -450,7 +450,7 @@ static dap_chain_net_srv_xchange_price_t *s_xchange_db_load(char *a_key, uint8_t
...
@@ -450,7 +450,7 @@ static dap_chain_net_srv_xchange_price_t *s_xchange_db_load(char *a_key, uint8_t
{
{
dap_chain_net_srv_xchange_db_item_t
*
l_item
=
(
dap_chain_net_srv_xchange_db_item_t
*
)
a_item
;
dap_chain_net_srv_xchange_db_item_t
*
l_item
=
(
dap_chain_net_srv_xchange_db_item_t
*
)
a_item
;
dap_chain_net_srv_xchange_price_t
*
l_price
=
DAP_NEW_Z
(
dap_chain_net_srv_xchange_price_t
);
dap_chain_net_srv_xchange_price_t
*
l_price
=
DAP_NEW_Z
(
dap_chain_net_srv_xchange_price_t
);
strcpy
(
l_price
->
key_ptr
,
a_key
);
l_price
->
key_ptr
=
dap_strdup
(
a_key
);
strcpy
(
l_price
->
token_sell
,
l_item
->
token_sell
);
strcpy
(
l_price
->
token_sell
,
l_item
->
token_sell
);
strcpy
(
l_price
->
token_buy
,
l_item
->
token_buy
);
strcpy
(
l_price
->
token_buy
,
l_item
->
token_buy
);
dap_chain_net_id_t
l_id
=
{
.
uint64
=
l_item
->
net_sell_id
};
dap_chain_net_id_t
l_id
=
{
.
uint64
=
l_item
->
net_sell_id
};
...
@@ -461,7 +461,7 @@ static dap_chain_net_srv_xchange_price_t *s_xchange_db_load(char *a_key, uint8_t
...
@@ -461,7 +461,7 @@ static dap_chain_net_srv_xchange_price_t *s_xchange_db_load(char *a_key, uint8_t
l_price
->
rate
=
l_item
->
rate
;
l_price
->
rate
=
l_item
->
rate
;
memcpy
(
&
l_price
->
tx_hash
,
&
l_item
->
tx_hash
,
sizeof
(
dap_chain_hash_fast_t
));
memcpy
(
&
l_price
->
tx_hash
,
&
l_item
->
tx_hash
,
sizeof
(
dap_chain_hash_fast_t
));
memcpy
(
&
l_price
->
order_hash
,
&
l_item
->
order_hash
,
sizeof
(
dap_chain_hash_fast_t
));
memcpy
(
&
l_price
->
order_hash
,
&
l_item
->
order_hash
,
sizeof
(
dap_chain_hash_fast_t
));
strcpy
(
l_price
->
wallet_str
,
l_item
->
wallet_str
);
l_price
->
wallet_str
=
dap_strdup
(
l_item
->
wallet_str
);
return
l_price
;
return
l_price
;
}
}
...
@@ -597,6 +597,8 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
...
@@ -597,6 +597,8 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
dap_chain_wallet_close
(
l_wallet
);
dap_chain_wallet_close
(
l_wallet
);
if
(
!
l_tx
)
{
if
(
!
l_tx
)
{
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't compose the conditional transaction"
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't compose the conditional transaction"
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
);
DAP_DELETE
(
l_price
);
return
-
14
;
return
-
14
;
}
}
...
@@ -608,12 +610,18 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
...
@@ -608,12 +610,18 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't put transaction to mempool"
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't put transaction to mempool"
);
dap_chain_net_srv_order_delete_by_hash_str
(
l_net_buy
,
l_order_hash_str
);
dap_chain_net_srv_order_delete_by_hash_str
(
l_net_buy
,
l_order_hash_str
);
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
);
return
-
15
;
return
-
15
;
}
}
if
(
!
s_xchange_db_add
(
l_price
))
{
if
(
!
s_xchange_db_add
(
l_price
))
{
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't save price in database"
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't save price in database"
);
dap_chain_net_srv_order_delete_by_hash_str
(
l_net_buy
,
l_order_hash_str
);
dap_chain_net_srv_order_delete_by_hash_str
(
l_net_buy
,
l_order_hash_str
);
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
);
return
-
16
;
return
-
16
;
}
}
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Successfully created order %s"
,
l_order_hash_str
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Successfully created order %s"
,
l_order_hash_str
);
...
@@ -623,7 +631,9 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
...
@@ -623,7 +631,9 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
}
else
{
}
else
{
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't compose the order"
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't compose the order"
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
);
DAP_DELETE
(
l_price
);
return
-
18
;
}
}
}
break
;
}
break
;
case
CMD_REMOVE
:
case
CMD_REMOVE
:
...
@@ -652,6 +662,7 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
...
@@ -652,6 +662,7 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
}
}
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
);
DAP_DELETE
(
l_price
);
if
(
!
l_str_reply
->
len
)
{
if
(
!
l_str_reply
->
len
)
{
dap_string_append
(
l_str_reply
,
"Price successfully removed"
);
dap_string_append
(
l_str_reply
,
"Price successfully removed"
);
...
@@ -745,6 +756,7 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
...
@@ -745,6 +756,7 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_order_hash_str
);
}
else
{
}
else
{
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't compose the order"
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Can't compose the order"
);
DAP_DELETE
(
l_price
->
wallet_str
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
->
key_ptr
);
DAP_DELETE
(
l_price
);
DAP_DELETE
(
l_price
);
return
-
18
;
return
-
18
;
...
@@ -758,7 +770,7 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
...
@@ -758,7 +770,7 @@ static int s_cli_srv_xchange_price(int a_argc, char **a_argv, int a_arg_index, c
dap_string_t
*
l_reply_str
=
dap_string_new
(
""
);
dap_string_t
*
l_reply_str
=
dap_string_new
(
""
);
HASH_ITER
(
hh
,
s_srv_xchange
->
pricelist
,
l_price
,
l_tmp
)
{
HASH_ITER
(
hh
,
s_srv_xchange
->
pricelist
,
l_price
,
l_tmp
)
{
char
*
l_order_hash_str
=
dap_chain_hash_fast_to_str_new
(
&
l_price
->
order_hash
);
char
*
l_order_hash_str
=
dap_chain_hash_fast_to_str_new
(
&
l_price
->
order_hash
);
dap_string_append_printf
(
l_reply_str
,
"%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%lu
\t
%ld
\t
%s
\n
"
,
l_order_hash_str
,
l_price
->
token_sell
,
dap_string_append_printf
(
l_reply_str
,
"%s
%s %s %s %s %lu %llf
%s
\n
"
,
l_order_hash_str
,
l_price
->
token_sell
,
l_price
->
net_sell
->
pub
.
name
,
l_price
->
token_buy
,
l_price
->
net_buy
->
pub
.
name
,
l_price
->
net_sell
->
pub
.
name
,
l_price
->
token_buy
,
l_price
->
net_buy
->
pub
.
name
,
l_price
->
datoshi_sell
,
l_price
->
rate
,
l_price
->
wallet_str
);
l_price
->
datoshi_sell
,
l_price
->
rate
,
l_price
->
wallet_str
);
DAP_DELETE
(
l_order_hash_str
);
DAP_DELETE
(
l_order_hash_str
);
...
@@ -826,7 +838,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void *a_arg_func, char *
...
@@ -826,7 +838,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void *a_arg_func, char *
continue
;
continue
;
// TODO add filters to list (tokens, network, etc.)
// TODO add filters to list (tokens, network, etc.)
l_price
=
s_xchange_price_from_order
(
l_net
,
l_order
);
l_price
=
s_xchange_price_from_order
(
l_net
,
l_order
);
dap_string_append_printf
(
l_reply_str
,
"%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%lu
\t
%ld
\n
"
,
l_orders
[
i
].
key
,
l_price
->
token_sell
,
dap_string_append_printf
(
l_reply_str
,
"%s
%s %s %s %s %lu %llf
\n
"
,
l_orders
[
i
].
key
,
l_price
->
token_sell
,
l_price
->
net_sell
->
pub
.
name
,
l_price
->
token_buy
,
l_price
->
net_buy
->
pub
.
name
,
l_price
->
net_sell
->
pub
.
name
,
l_price
->
token_buy
,
l_price
->
net_buy
->
pub
.
name
,
l_price
->
datoshi_sell
,
l_price
->
rate
);
l_price
->
datoshi_sell
,
l_price
->
rate
);
DAP_DELETE
(
l_price
);
DAP_DELETE
(
l_price
);
...
@@ -868,7 +880,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void *a_arg_func, char *
...
@@ -868,7 +880,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, void *a_arg_func, char *
}
}
dap_chain_node_cli_find_option_val
(
a_argv
,
l_arg_index
,
a_argc
,
"-coins"
,
&
l_val_sell_str
);
dap_chain_node_cli_find_option_val
(
a_argv
,
l_arg_index
,
a_argc
,
"-coins"
,
&
l_val_sell_str
);
if
(
!
l_val_sell_str
)
{
if
(
!
l_val_sell_str
)
{
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Command 'p
rice creat
e' required parameter -coins"
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Command 'p
urchas
e' required parameter -coins"
);
return
-
8
;
return
-
8
;
}
}
uint64_t
l_datoshi_sell
=
strtoull
(
l_val_sell_str
,
NULL
,
10
);
uint64_t
l_datoshi_sell
=
strtoull
(
l_val_sell_str
,
NULL
,
10
);
...
...
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