Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-chain-net-srv
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-net-srv
Commits
c98d8d30
Commit
c98d8d30
authored
5 years ago
by
Dmitriy A. Gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[*] Lot of fixes
parent
f843ed78
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dap_chain_net_srv.c
+13
-9
13 additions, 9 deletions
dap_chain_net_srv.c
dap_chain_net_srv_common.h
+10
-12
10 additions, 12 deletions
dap_chain_net_srv_common.h
dap_chain_net_srv_order.c
+16
-8
16 additions, 8 deletions
dap_chain_net_srv_order.c
with
39 additions
and
29 deletions
dap_chain_net_srv.c
+
13
−
9
View file @
c98d8d30
...
...
@@ -91,8 +91,8 @@ int dap_chain_net_srv_init(void)
"net_srv -net <chain net name> order dump -hash <Order hash>
\n
"
"
\t
Order dump info
\n
"
"net_srv -net <chain net name> order create -direction <sell|buy> -srv_uid <Service UID> -srv_class <Service Class> -price <Price>
\\\n
"
" -price_unit <Price Unit> -price_token <Token ticker> -node_addr <Node Address>
-tx_cond <TX Cond Hash>
\\\n
"
" [-expires <Unix time when expires>]
\\\n
"
" -price_unit <Price Unit> -price_token <Token ticker>
[
-node_addr <Node Address>
] [
-tx_cond <TX Cond Hash>
]
\\\n
"
" [-expires <Unix time when expires>]
[-ext <Extension with params>]
\\\n
"
"
\t
Order create
\n
"
);
return
0
;
...
...
@@ -217,7 +217,7 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply)
}
}
else
{
dap_chain_net_srv_order_t
*
l_orders
;
dap_chain_net_srv_order_t
*
l_orders
=
NULL
;
size_t
l_orders_size
=
0
;
dap_chain_net_srv_uid_t
l_srv_uid
=
{{
0
}};
dap_chain_net_srv_class_t
l_srv_class
=
SERV_CLASS_UNDEFINED
;
...
...
@@ -228,7 +228,7 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply)
if
(
dap_chain_net_srv_order_find_all_by
(
l_net
,
l_direction
,
l_srv_uid
,
l_srv_class
,
l_price_unit
,
NULL
,
l_price_min
,
l_price_max
,
&
l_orders
,
&
l_orders_size
)
==
0
){
dap_string_append_printf
(
l_string_ret
,
"Found %zd orders:
\n
"
,
l_orders_size
);
for
(
size_t
i
=
0
;
i
<
l_orders_size
;
i
++
){
dap_chain_net_srv_order_dump_to_string
(
l_orders
+
i
,
l_string_ret
);
dap_chain_net_srv_order_dump_to_string
(
&
l_orders
[
i
]
,
l_string_ret
);
dap_string_append
(
l_string_ret
,
"
\n
"
);
}
ret
=
0
;
...
...
@@ -282,8 +282,8 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply)
const
char
*
l_price_token_str
=
NULL
;
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-price_token"
,
&
l_price_token_str
);
const
char
*
l_
comments
=
NULL
;
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-
comments"
,
&
l_comments
);
const
char
*
l_
ext
=
NULL
;
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-
ext"
,
&
l_ext
);
if
(
l_srv_uid_str
&&
l_srv_class_str
&&
l_price_str
&&
l_price_token_str
&&
l_price_unit_str
)
{
dap_chain_net_srv_uid_t
l_srv_uid
=
{{
0
}};
...
...
@@ -296,10 +296,14 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply)
dap_chain_net_srv_price_unit_uid_t
l_price_unit
=
{{
0
}};
dap_chain_net_srv_order_direction_t
l_direction
=
SERV_DIR_UNDEFINED
;
if
(
l_direction_str
){
if
(
strcmp
(
l_direction_str
,
"sell"
)
==
0
)
if
(
strcmp
(
l_direction_str
,
"sell"
)
==
0
){
l_direction
=
SERV_DIR_SELL
;
else
if
(
strcmp
(
l_direction_str
,
"buy"
)
==
0
)
log_it
(
L_DEBUG
,
"Created order to sell"
);
}
else
if
(
strcmp
(
l_direction_str
,
"buy"
)
==
0
){
l_direction
=
SERV_DIR_BUY
;
log_it
(
L_DEBUG
,
"Created order to buy"
);
}
else
log_it
(
L_WARNING
,
"Undefined order direction"
);
}
...
...
@@ -316,7 +320,7 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply)
char
*
l_order_new_hash_str
=
dap_chain_net_srv_order_create
(
l_net
,
l_direction
,
l_srv_uid
,
l_srv_class
,
l_node_addr
,
l_tx_cond_hash
,
l_price
,
l_price_unit
,
l_price_token
,
l_expires
,
l_
comments
);
l_price_token
,
l_expires
,
l_
ext
);
if
(
l_order_new_hash_str
)
dap_string_append_printf
(
l_string_ret
,
"Created order %s
\n
"
,
l_order_new_hash_str
);
else
{
...
...
This diff is collapsed.
Click to expand it.
dap_chain_net_srv_common.h
+
10
−
12
View file @
c98d8d30
...
...
@@ -44,10 +44,6 @@ typedef union {
#endif
}
dap_chain_net_srv_uid_t
;
#define DAP_CHAIN_NET_SRV_PRICE_UNIT_UNDEFINED 0x00000000
#define DAP_CHAIN_NET_SRV_PRICE_UNIT_BYTE 0x00000001
#define DAP_CHAIN_NET_SRV_PRICE_UNIT_SECOND 0x00000010
#define DAP_CHAIN_NET_SRV_PRICE_UNIT_BYTE_PER_SECOND 0x00000100
typedef
union
{
uint8_t
raw
[
4
];
...
...
@@ -64,19 +60,20 @@ typedef enum {
//Service direction
typedef
enum
dap_chain_net_srv_order_direction
{
SERV_DIR_BUY
=
0x0
1
,
SERV_DIR_SELL
=
0x0
2
,
SERV_DIR_UNDEFINED
=
0
x00
SERV_DIR_BUY
=
1
,
SERV_DIR_SELL
=
2
,
SERV_DIR_UNDEFINED
=
0
}
dap_chain_net_srv_order_direction_t
;
//Types of services
enum
{
SERV_ID_UNDEFINED
=
0x0000000
0
,
SERV_ID_VPN
=
0x0000000
1
,
SERV_ID_UNDEFINED
=
0
,
SERV_ID_VPN
=
1
,
};
//Units of service
enum
{
SERV_UNIT_UNDEFINED
=
0
,
SERV_UNIT_MB
=
1
,
// megabytes
SERV_UNIT_SEC
=
2
,
// seconds
SERV_UNIT_DAY
=
3
// days
...
...
@@ -120,9 +117,10 @@ typedef struct dap_chain_net_srv
DAP_STATIC_INLINE
const
char
*
dap_chain_net_srv_price_unit_uid_to_str
(
dap_chain_net_srv_price_unit_uid_t
a_uid
)
{
switch
(
a_uid
.
uint32
)
{
case
DAP_CHAIN_NET_SRV_PRICE_UNIT_BYTE
:
return
"BYTE"
;
case
DAP_CHAIN_NET_SRV_PRICE_UNIT_SECOND
:
return
"SECOND"
;
case
DAP_CHAIN_NET_SRV_PRICE_UNIT_BYTE_PER_SECOND
:
return
"BYTE_PER_SECOND"
;
case
SERV_UNIT_UNDEFINED
:
return
"BYTE"
;
case
SERV_UNIT_MB
:
return
"MEGABYTE"
;
case
SERV_UNIT_SEC
:
return
"SECOND"
;
case
SERV_UNIT_DAY
:
return
"DAY"
;
default:
return
"UNKNOWN"
;
}
}
...
...
This diff is collapsed.
Click to expand it.
dap_chain_net_srv_order.c
+
16
−
8
View file @
c98d8d30
...
...
@@ -67,13 +67,20 @@ char* dap_chain_net_srv_order_create(
dap_chain_hash_fast_t
*
l_order_hash
=
DAP_NEW_Z
(
dap_chain_hash_fast_t
);
l_order
->
version
=
1
;
l_order
->
srv_uid
=
a_srv_uid
;
l_order
->
direction
=
a_direction
;
l_order
->
ts_created
=
(
dap_chain_time_t
)
time
(
NULL
);
l_order
->
srv_class
=
a_srv_class
;
l_order
->
node_addr
.
uint64
=
a_node_addr
.
uint64
;
if
(
l_order
->
node_addr
.
uint64
)
l_order
->
node_addr
.
uint64
=
a_node_addr
.
uint64
;
memcpy
(
&
l_order
->
tx_cond_hash
,
&
a_tx_cond_hash
,
DAP_CHAIN_HASH_FAST_SIZE
);
l_order
->
price
=
a_price
;
l_order
->
price_unit
=
a_price_unit
;
strncpy
(
l_order
->
price_ticker
,
a_price_ticker
,
sizeof
(
l_order
->
price_ticker
)
-
1
);
l_order
->
price_unit
.
uint32
=
a_price_unit
.
uint32
;
if
(
a_price_ticker
)
strncpy
(
l_order
->
price_ticker
,
a_price_ticker
,
sizeof
(
l_order
->
price_ticker
)
-
1
);
if
(
a_ext
)
strncpy
(
l_order
->
ext
,
a_ext
,
sizeof
(
l_order
->
ext
)
-
1
);
...
...
@@ -177,10 +184,11 @@ lb_order_pass:
if
(
a_price_ticker
)
if
(
strcmp
(
l_order
->
price_ticker
,
a_price_ticker
)
!=
0
)
continue
;
if
(
!
l_order_pass_first
){
memcpy
(
a_output_orders
[
l_order_passed_index
],
l_order
,
sizeof
(
dap_chain_net_srv_order_t
));
}
else
l_order_passed_index
++
;
if
(
!
l_order_pass_first
)
memcpy
(
*
a_output_orders
+
l_order_passed_index
,
l_order
,
sizeof
(
dap_chain_net_srv_order_t
));
l_order_passed_index
++
;
}
// Dirty goto usage ho ho ho
if
(
l_order_pass_first
)
{
...
...
@@ -243,7 +251,7 @@ void dap_chain_net_srv_order_dump_to_string(dap_chain_net_srv_order_t *a_order,d
//default: dap_string_append_printf(a_str_out, " srv_class: UNKNOWN\n" );
}
dap_string_append_printf
(
a_str_out
,
" srv_uid: 0x%016llX
\n
"
,
a_order
->
srv_uid
.
uint64
);
dap_string_append_printf
(
a_str_out
,
" price: \u00a0%.
3
Lf (%llu)
\n
"
,
dap_chain_balance_to_coins
(
a_order
->
price
)
,
a_order
->
price
);
dap_string_append_printf
(
a_str_out
,
" price: \u00a0%.
7
Lf (%llu)
\n
"
,
dap_chain_balance_to_coins
(
a_order
->
price
)
,
a_order
->
price
);
if
(
a_order
->
price_unit
.
uint32
)
dap_string_append_printf
(
a_str_out
,
" price_unit: 0x%016llX
\n
"
,
dap_chain_net_srv_price_unit_uid_to_str
(
a_order
->
price_unit
)
);
if
(
a_order
->
node_addr
.
uint64
)
...
...
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