forked from bytemaster/bitshares
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitshared.cpp
113 lines (100 loc) · 3.05 KB
/
bitshared.cpp
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
#include <fc/log/logger.hpp>
#include <fc/exception/exception.hpp>
#include <fc/filesystem.hpp>
#include <fc/io/json.hpp>
#include <fc/io/stdio.hpp>
#include <fc/io/fstream.hpp>
#include <fc/crypto/base58.hpp>
#include <fc/reflect/variant.hpp>
#include <fc/thread/thread.hpp>
#include <bts/network/server.hpp>
#include <bts/network/get_public_ip.hpp>
#include <bts/bitmessage.hpp>
#include <bts/wallet.hpp>
#include <bts/db/peer_ram.hpp>
#include <iostream>
#include <sstream>
struct bitshared_config
{
bitshared_config()
{
server_config.port = 9876;
}
bts::network::server::config server_config;
};
FC_REFLECT( bitshared_config, (server_config) )
int main( int argc, char** argv )
{
try
{
ilog( "my ip: ${ip}", ("ip",bts::network::get_public_ip()) );
if( argc != 2 )
{
fc::cerr<<"Usage "<<argv[0]<<" CONFIG\n";
return -1;
}
fc::path cfile(argv[1]);
if( !fc::exists( cfile ) )
{
auto default_str = fc::json::to_pretty_string( bitshared_config() );
fc::ofstream out(cfile);
out.write( default_str.c_str(), default_str.size() );
}
auto cfg = fc::json::from_file( cfile ).as<bitshared_config>();
auto peerdb = std::make_shared<bts::db::peer_ram>();
bts::network::server netw(peerdb);
ilog( "configuring node" );
netw.configure( cfg.server_config );
ilog( "connecting to peers" );
// fc::future<void> connect_complete = fc::async( [&]() { netw.connect_to_peers( 8 ); } );
ilog( "ready for commands" );
bts::wallet wal;
fc::thread _cin("cin");
std::string line;
while( _cin.async([&](){ return !std::getline( std::cin, line ).eof(); } ).wait() )
{
std::string cmd;
std::stringstream ss(line);
ss >> cmd;
if( cmd == "q" ) break;
if( cmd== "login" )
{
std::string pass;
ss >> pass;
ilog( "logging into your wallet..." );
wal.set_seed( fc::sha256::hash( pass.c_str(), pass.size() ) );
auto s = wal.get_public_key(1).serialize();
auto id = fc::to_base58( s.data, sizeof(s.data) );
ilog( "logged in as: ${id}", ("id", id) );
}
if( cmd== "send" )
{
std::string pubkey;
ss>>pubkey;
std::string subject;
std::string message;
fc::cout<<"subject: ";
_cin.async([&](){ return !std::getline( std::cin, subject ).eof(); } ).wait();
fc::cout<<"----------------------------------------------\n";
while( _cin.async([&](){ return !std::getline( std::cin, line ).eof(); } ).wait() )
{
if( line == "." )
{
fc::cout<<"----------------------------------------------\n";
break;
}
message += line + "\n";
}
}
}
ilog( "waiting for connect to complete" );
netw.close();
// connect_complete.wait();
}
catch ( fc::exception& e )
{
elog( "${e}", ("e",e.to_detail_string()) );
return -1;
}
return 0;
}