Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-chain-wallet
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-wallet
Commits
fcc74f44
Unverified
Commit
fcc74f44
authored
6 years ago
by
Dmitriy A. Gerasimov
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #3 from kelvinblockchain/feature-2151
Feature 2151
parents
466e6bfc
bbd0b317
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dap_chain_wallet.c
+24
-7
24 additions, 7 deletions
dap_chain_wallet.c
with
24 additions
and
7 deletions
dap_chain_wallet.c
+
24
−
7
View file @
fcc74f44
...
...
@@ -24,6 +24,8 @@
#include
<string.h>
#include
<errno.h>
#include
<stdint.h>
#include
<stdio.h>
#include
"dap_common.h"
#include
"dap_chain_cert_file.h"
#include
"dap_chain_wallet.h"
...
...
@@ -93,7 +95,7 @@ void dap_chain_wallet_close( dap_chain_wallet_t * a_wallet)
DAP_CHAIN_WALLET_INTERNAL_LOCAL
(
a_wallet
);
if
(
a_wallet
->
name
)
DAP_DELETE
(
a_wallet
->
name
);
// TODO Make clean struct dap_chain_wallet_internal_t
DAP_DELETE
(
l_wallet_internal
);
DAP_DELETE
(
a_wallet
);
}
...
...
@@ -157,7 +159,7 @@ int dap_chain_wallet_save(dap_chain_wallet_t * a_wallet)
{
if
(
a_wallet
){
DAP_CHAIN_WALLET_INTERNAL_LOCAL
(
a_wallet
);
FILE
*
l_file
=
fopen
(
l_wallet_internal
->
file_name
,
"w"
);
FILE
*
l_file
=
fopen
(
l_wallet_internal
->
file_name
,
"w
b
"
);
if
(
l_file
){
dap_chain_wallet_file_hdr_t
l_file_hdr
=
{
0
};
l_file_hdr
.
signature
=
DAP_CHAIN_WALLETS_FILE_SIGNATURE
;
...
...
@@ -165,7 +167,13 @@ int dap_chain_wallet_save(dap_chain_wallet_t * a_wallet)
l_file_hdr
.
version
=
1
;
l_file_hdr
.
net_id
=
l_wallet_internal
->
addr
->
net_id
;
size_t
i
;
// write header
fwrite
(
&
l_file_hdr
,
1
,
sizeof
(
l_file_hdr
),
l_file
);
// write name
uint16_t
name_len
=
(
a_wallet
->
name
)
?
(
uint16_t
)
strlen
(
a_wallet
->
name
)
:
0
;
fwrite
(
&
name_len
,
1
,
sizeof
(
uint16_t
),
l_file
);
fwrite
(
a_wallet
->
name
,
1
,
name_len
,
l_file
);
// write certs
for
(
i
=
0
;
i
<
l_wallet_internal
->
certs_count
;
i
++
)
{
dap_chain_wallet_cert_hdr_t
l_wallet_cert_hdr
=
{
0
};
l_wallet_cert_hdr
.
version
=
1
;
...
...
@@ -199,22 +207,27 @@ int dap_chain_wallet_save(dap_chain_wallet_t * a_wallet)
*/
dap_chain_wallet_t
*
dap_chain_wallet_open_file
(
const
char
*
a_file_name
)
{
FILE
*
l_file
=
fopen
(
a_file_name
,
"r"
);
FILE
*
l_file
=
fopen
(
a_file_name
,
"r
b
"
);
fseek
(
l_file
,
0L
,
SEEK_END
);
uint64_t
l_file_size
=
ftell
(
l_file
);
rewind
(
l_file
);
if
(
l_file
){
dap_chain_wallet_file_hdr_t
l_file_hdr
=
{
0
};
// read header
if
(
fread
(
&
l_file_hdr
,
1
,
sizeof
(
l_file_hdr
),
l_file
)
==
sizeof
(
l_file_hdr
)
)
{
if
(
l_file_hdr
.
signature
==
DAP_CHAIN_WALLETS_FILE_SIGNATURE
)
{
dap_chain_wallet_t
*
l_wallet
=
DAP_NEW_Z
(
dap_chain_wallet_t
);
DAP_CHAIN_WALLET_INTERNAL_LOCAL_NEW
(
l_wallet
);
// read name
uint16_t
name_len
=
0
;
fread
(
&
name_len
,
1
,
sizeof
(
uint16_t
),
l_file
);
l_wallet
->
name
=
DAP_NEW_Z_SIZE
(
char
,
name_len
+
1
);
fread
(
l_wallet
->
name
,
1
,
name_len
,
l_file
);
l_wallet_internal
->
file_name
=
strdup
(
a_file_name
);
size_t
i
=
sizeof
(
l_file_hdr
);
size_t
i
=
sizeof
(
l_file_hdr
)
+
sizeof
(
uint16_t
)
+
name_len
;
// calculate certs count
while
(
i
<
l_file_size
){
dap_chain_wallet_cert_hdr_t
l_cert_hdr
=
{
0
};
fread
(
&
l_cert_hdr
,
1
,
sizeof
(
l_cert_hdr
),
l_file
);
...
...
@@ -232,7 +245,8 @@ dap_chain_wallet_t * dap_chain_wallet_open_file(const char * a_file_name)
break
;
}
}
fseek
(
l_file
,
sizeof
(
l_file_hdr
),
SEEK_SET
);
// read certs
fseek
(
l_file
,
sizeof
(
l_file_hdr
)
+
sizeof
(
uint16_t
)
+
name_len
,
SEEK_SET
);
l_wallet_internal
->
certs
=
DAP_NEW_Z_SIZE
(
dap_chain_cert_t
*
,
l_wallet_internal
->
certs_count
);
for
(
i
=
0
;
i
<
l_wallet_internal
->
certs_count
;
i
++
){
dap_chain_wallet_cert_hdr_t
l_cert_hdr
=
{
0
};
...
...
@@ -243,6 +257,9 @@ dap_chain_wallet_t * dap_chain_wallet_open_file(const char * a_file_name)
DAP_DELETE
(
l_data
);
}
fclose
(
l_file
);
// make addr
if
(
l_wallet_internal
->
certs_count
>
0
)
l_wallet_internal
->
addr
=
dap_chain_cert_to_addr
(
l_wallet_internal
->
certs
[
0
],
l_file_hdr
.
net_id
);
return
l_wallet
;
}
else
{
log_it
(
L_ERROR
,
"Wrong wallet file signature: corrupted file or wrong format"
);
...
...
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