FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BitShares/src/main.cpp at master · Xenland/BitShares · GitHub
Xenland
BitShares
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
BitShares
/
src
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
144 lines (127 loc) · 3.76 KB
Breadcrumbs
BitShares
/
src
/
main.cpp
Copy path
File metadata and controls
144 lines (127 loc) · 3.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
#include "api.hpp"
#
include
"
miner.hpp
"
#
include
"
account.hpp
"
#
include
"
wallet.hpp
"
#
include
<
fc/io/stdio.hpp
>
#
include
<
fc/io/json.hpp
>
#
include
<
sstream
>
#
include
<
iostream
>
struct
bitshare_config
{
fc::path data_dir;
float
mine_effort;
};
FC_REFLECT
( bitshare_config,
(data_dir)
(mine_effort)
)
/*
*
* Prints out the account with balances and available outputs,
* dividends, etc.
*/
void
print_account
( account& a, block_chain& bc )
{
auto
addrs = a.
get_addresses
();
std::vector<output_cache> outs;
std::cout<<
"
Account: '
"
<<a.
name
()<<
"
'
\n
"
;
std::cout<<
"
----------------------------------------------------------------
\n
"
;
std::cout<<
"
Addresses:
\n
"
;
for
(
auto
itr = addrs.
begin
(); itr != addrs.
end
(); ++itr )
{
std::cout<<
"
"
<<
std::string
(*itr)<<
"
\n
"
;
//
TODO: print whether or not we have the private key
auto
ve = bc.
get_outputs_for_address
( *itr );
outs.
insert
( outs.
end
(), ve.
begin
(), ve.
end
() );
}
std::cout<<
"
Outputs:
\n
"
;
for
(
auto
itr = outs.
begin
(); itr != outs.
end
(); ++itr )
{
std::cout<<
"
"
<< bc.
pretty_print_output
( *itr ) <<
"
\n
"
;
}
}
int
main
(
int
argc,
char
** argv )
{
try
{
if
( argc <
2
)
{
fc::cerr<<
"
Usage:
"
<<argv[
0
]<<
"
config
\n
"
;
return
-
1
;
}
bitshare_config cfg;
try
{
cfg =
fc::json::from_file
(
fc::path
( argv[
1
] ) ).
as
<bitshare_config>();
}
catch
( fc::eof_exception& e )
{
fc::cerr<<
"
Error loading configuration
\n
"
<<e.
to_detail_string
()<<
"
\n
"
;
return
-
1
;
}
//
load the block-chain
block_chain bc;
bc.
load
( cfg.
data_dir
/
"
chain
"
);
//
load my account
account default_acnt;
default_acnt.
load
( cfg.
data_dir
/
"
accounts
"
/
"
default
"
, account::create );
//
bc.output_added.connect( [&]( const output_cache& o ) { default_acnt.add_output(o); } );
//
bc.output_removed.connect( [&]( const output_cache& o ) { default_acnt.remove_output(o); } );
//
start the miner
miner
bc_miner
( bc, default_acnt );
bc_miner.
start
( cfg.
mine_effort
);
//
start the network
//
node bsnode(bc);
//
start the CLI
fc::string line;
fc::getline
( fc::cin, line );
while
( line !=
"
quit
"
)
{
std::string
sline
(line);
std::stringstream
ss
(sline);
std::string cmd;
ss >> cmd;
if
( cmd ==
"
help
"
)
{
fc::cout<<
"
Commands:
\n
"
;
fc::cout<<
"
add_block
\n
"
;
fc::cout<<
"
mine effort
\n
"
;
fc::cout<<
"
print_chain
\n
"
;
fc::cout<<
"
print_account
\n
"
;
fc::cout.
flush
();
}
else
if
( cmd ==
"
add_block
"
)
{
auto
coinbase_addr = default_acnt.
get_new_address
();
block new_block = bc.
generate_next_block
( coinbase_addr );
fc::cout<<
"
Creating new block:
\n
"
<<
fc::json::to_pretty_string
(new_block) <<
"
\n
"
;
bc.
add_block
( new_block );
//
adds the next block without mining...
}
else
if
( cmd ==
"
mine
"
)
{
float
effort =
0
;
ss >> effort;
bc_miner.
start
( effort );
}
else
if
( cmd ==
"
print_chain
"
)
{
bc.
pretty_print_chain
();
}
else
if
( cmd ==
"
print_account
"
)
{
print_account
(default_acnt, bc);
}
fc::getline
( fc::cin, line );
}
}
catch
( fc::eof_exception& e )
{
fc::cerr<<
"
eof
\n
"
;
//
expected end of cin..
return
0
;
}
catch
( fc::exception& e )
{
fc::cerr<<e.
to_detail_string
()<<
"
\n
"
;
return
-
1
;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL