FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BitShares/src/wallet_cache.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
/
wallet_cache.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
144 lines (108 loc) · 4.33 KB
Breadcrumbs
BitShares
/
src
/
wallet_cache.cpp
Copy path
File metadata and controls
144 lines (108 loc) · 4.33 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
#
include
<
bts/wallet_cache.hpp
>
#
include
<
bts/blockchain/blockchain_db.hpp
>
#
include
<
bts/db/level_map.hpp
>
#
include
<
fc/filesystem.hpp
>
#
include
<
fc/reflect/variant.hpp
>
#
include
<
unordered_map
>
#
include
<
map
>
struct
output_balance
{
uint8_t
unit;
uint64_t
amount;
};
bool
operator
< (
const
output_balance& a,
const
output_balance& b )
{
if
( a.
unit
< b.
unit
)
return
true
;
if
( a.
unit
> b.
unit
)
return
false
;
if
( a.
amount
< b.
amount
)
return
true
;
return
false
;
}
FC_REFLECT
( output_balance, (unit)(amount) )
namespace
bts
{
using
namespace
blockchain
;
namespace
detail
{
class
wallet_cache_impl
{
public:
blockchain_db_ptr _block_db;
db::level_map<
uint32_t
, extended_public_key> _accounts;
//
these two DB contain all information necessary to
db::level_map<uint160, signed_transaction> _trx_db;
/*
* index to quickly see if a public key is in our set.
*/
db::level_map<bts::address, address_index> _addr_index;
/*
* maps account number to the last trx used by the account
*/
db::level_map<
uint32_t
,
uint32_t
> _account_last_trx_index;
/*
* maps account.trx number to the last recv used
*/
db::level_map<
uint64_t
,
uint32_t
> _trx_last_address_index;
/*
* store all outputs that reference a particular address derived from
* our HD Wallet, in this case the value is the index of the value[i].output_idx
* is really the input idx because the data for an input ref is the same
* as for an output ref.
*/
std::unordered_map<output_reference, std::vector<output_reference> > _spent_outputs;
/*
* stores all unspent outputs that can be claimed by a signature sorted by
* unit & value. This is rebuilt / updated every time a new block is added
*/
std::map<output_balance, output_reference> _unspent_claim_by_sig;
//
TODO: index spendable....
//
TODO: index margin (short) positions
//
TODO: index option positions
//
TODO: index password outputs...
//
TODO: index open orders
};
}
//
namespace detail
wallet_cache::wallet_cache
(
const
blockchain_db_ptr& block_db )
:my(
new
bts::detail::wallet_cache_impl() )
{
my->
_block_db
= block_db;
}
wallet_cache::~wallet_cache
()
{
}
void
wallet_cache::open
(
const
fc::path& wallet_cache_dir )
{
try
{
if
( !
fc::exists
( wallet_cache_dir ) )
{
fc::create_directories
( wallet_cache_dir );
}
my->
_accounts
.
open
( wallet_cache_dir /
"
accounts
"
,
true
);
my->
_trx_db
.
open
( wallet_cache_dir /
"
trx_db
"
,
true
);
my->
_addr_index
.
open
( wallet_cache_dir /
"
addr_index
"
,
true
);
my->
_account_last_trx_index
.
open
( wallet_cache_dir /
"
acnt_last_trx_index
"
,
true
);
my->
_trx_last_address_index
.
open
( wallet_cache_dir /
"
trx_last_address_index
"
,
true
);
//
TODO generate _spent_outputs cache...
//
TODO generate unspent_claim_by_sig cache
}
FC_RETHROW_EXCEPTIONS
( warn,
"
"
, (
"
wallet_cache_dir
"
,wallet_cache_dir) ) }
/*
*
* This method will scan the trx for inputs or outputs
* that belong to this wallet.
*/
void
wallet_cache::cache
(
const
blockchain::signed_transaction& trx )
{
//
TODO: scan trx for addresses that belong to this wallet.
my->
_trx_db
.
store
( trx.
id
(), trx );
}
asset
wallet_cache::get_balance
( asset::type unit )
const
{
return
asset
();
}
void
wallet_cache::add_account
(
uint32_t
account,
const
extended_public_key& pub )
{
try
{
my->
_accounts
.
store
( account, pub );
index_account_trx
( account,
10
,
10
);
//
TODO: don't hardcode these numbers
}
FC_RETHROW_EXCEPTIONS
( warn,
"
error adding account ${a} = ${k}
"
, (
"
a
"
, account)(
"
k
"
,pub) ) }
void
wallet_cache::remove_account
(
uint32_t
account )
{
try
{
my->
_accounts
.
remove
( account );
}
FC_RETHROW_EXCEPTIONS
( warn,
"
error removing account ${a} = ${k}
"
, (
"
a
"
, account) ) }
void
wallet_cache::rescan_chain
()
{
}
void
wallet_cache::index_account_trx
(
uint32_t
account,
uint32_t
trx_limit,
uint32_t
adr_limit )
{
}
void
wallet_cache::index_account_trx_addresses
(
uint32_t
account,
uint32_t
trx,
uint32_t
adr_limit )
{
}
}
//
namespace bts
Back
|
FazBrowse Home
|
New Git URL