Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
clients
python
sakia
Commits
4772c227
Commit
4772c227
authored
10 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Fixing cache not managing multiple currencies
parent
9b26ea0f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cutecoin/core/app.py
+3
-3
3 additions, 3 deletions
src/cutecoin/core/app.py
src/cutecoin/core/wallet.py
+25
-9
25 additions, 9 deletions
src/cutecoin/core/wallet.py
with
28 additions
and
12 deletions
src/cutecoin/core/app.py
+
3
−
3
View file @
4772c227
...
@@ -92,9 +92,9 @@ class Application(object):
...
@@ -92,9 +92,9 @@ class Application(object):
if
os
.
path
.
exists
(
wallet_path
):
if
os
.
path
.
exists
(
wallet_path
):
json_data
=
open
(
wallet_path
,
'
r
'
)
json_data
=
open
(
wallet_path
,
'
r
'
)
data
=
json
.
load
(
json_data
)
data
=
json
.
load
(
json_data
)
wallet
.
cache
.
load_from_json
(
data
)
wallet
.
load_caches
(
data
)
for
community
in
account
.
communities
:
for
community
in
account
.
communities
:
wallet
.
cache
.
refresh
(
community
)
wallet
.
refresh
_cache
(
community
)
def
save
(
self
,
account
):
def
save
(
self
,
account
):
with
open
(
config
.
parameters
[
'
data
'
],
'
w
'
)
as
outfile
:
with
open
(
config
.
parameters
[
'
data
'
],
'
w
'
)
as
outfile
:
...
@@ -114,7 +114,7 @@ class Application(object):
...
@@ -114,7 +114,7 @@ class Application(object):
wallet_path
=
os
.
path
.
join
(
config
.
parameters
[
'
home
'
],
wallet_path
=
os
.
path
.
join
(
config
.
parameters
[
'
home
'
],
account
.
name
,
'
__cache__
'
,
wallet
.
pubkey
)
account
.
name
,
'
__cache__
'
,
wallet
.
pubkey
)
with
open
(
wallet_path
,
'
w
'
)
as
outfile
:
with
open
(
wallet_path
,
'
w
'
)
as
outfile
:
json
.
dump
(
wallet
.
cache
.
jsonify
(),
outfile
,
indent
=
4
,
sort_keys
=
True
)
json
.
dump
(
wallet
.
jsonify
_caches
(),
outfile
,
indent
=
4
,
sort_keys
=
True
)
def
import_account
(
self
,
file
,
name
):
def
import_account
(
self
,
file
,
name
):
with
tarfile
.
open
(
file
,
"
r
"
)
as
tar
:
with
tarfile
.
open
(
file
,
"
r
"
)
as
tar
:
...
...
This diff is collapsed.
Click to expand it.
src/cutecoin/core/wallet.py
+
25
−
9
View file @
4772c227
...
@@ -17,6 +17,7 @@ class Cache():
...
@@ -17,6 +17,7 @@ class Cache():
def
__init__
(
self
,
wallet
):
def
__init__
(
self
,
wallet
):
self
.
latest_block
=
0
self
.
latest_block
=
0
self
.
wallet
=
wallet
self
.
wallet
=
wallet
self
.
tx_sent
=
[]
self
.
tx_sent
=
[]
self
.
awaiting_tx
=
[]
self
.
awaiting_tx
=
[]
self
.
tx_received
=
[]
self
.
tx_received
=
[]
...
@@ -131,7 +132,7 @@ class Wallet(object):
...
@@ -131,7 +132,7 @@ class Wallet(object):
self
.
walletid
=
walletid
self
.
walletid
=
walletid
self
.
pubkey
=
pubkey
self
.
pubkey
=
pubkey
self
.
name
=
name
self
.
name
=
name
self
.
cache
=
Cache
(
self
)
self
.
cache
s
=
{}
@classmethod
@classmethod
def
create
(
cls
,
walletid
,
salt
,
password
,
name
):
def
create
(
cls
,
walletid
,
salt
,
password
,
name
):
...
@@ -151,6 +152,20 @@ class Wallet(object):
...
@@ -151,6 +152,20 @@ class Wallet(object):
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
self
.
keyid
==
other
.
keyid
)
return
(
self
.
keyid
==
other
.
keyid
)
def
load_caches
(
self
,
json_data
):
for
currency
in
json_data
:
self
.
caches
[
currency
]
=
Cache
(
self
)
self
.
caches
[
currency
].
load_from_json
(
json_data
[
currency
])
def
jsonify_caches
(
self
):
for
currency
in
self
.
caches
:
return
{
currency
:
self
.
caches
[
currency
].
jsonify
()}
def
refresh_cache
(
self
,
community
):
if
community
.
currency
not
in
self
.
caches
:
self
.
caches
[
community
.
currency
]
=
Cache
(
self
)
self
.
caches
[
community
.
currency
].
refresh
(
community
)
def
check_password
(
self
,
salt
,
password
):
def
check_password
(
self
,
salt
,
password
):
key
=
None
key
=
None
if
self
.
walletid
==
0
:
if
self
.
walletid
==
0
:
...
@@ -174,16 +189,17 @@ class Wallet(object):
...
@@ -174,16 +189,17 @@ class Wallet(object):
def
tx_inputs
(
self
,
amount
,
community
):
def
tx_inputs
(
self
,
amount
,
community
):
value
=
0
value
=
0
inputs
=
[]
inputs
=
[]
cache
=
self
.
caches
[
community
.
currency
]
logging
.
debug
(
"
Available inputs : {0}
"
.
format
(
self
.
cache
.
available_sources
))
logging
.
debug
(
"
Available inputs : {0}
"
.
format
(
cache
.
available_sources
))
buf_inputs
=
list
(
self
.
cache
.
available_sources
)
buf_inputs
=
list
(
cache
.
available_sources
)
for
s
in
self
.
cache
.
available_sources
:
for
s
in
cache
.
available_sources
:
value
+=
s
.
amount
value
+=
s
.
amount
s
.
index
=
0
s
.
index
=
0
inputs
.
append
(
s
)
inputs
.
append
(
s
)
buf_inputs
.
remove
(
s
)
buf_inputs
.
remove
(
s
)
if
value
>=
amount
:
if
value
>=
amount
:
self
.
cache
.
available_sources
=
buf_inputs
cache
.
available_sources
=
buf_inputs
return
inputs
return
inputs
raise
NotEnoughMoneyError
(
value
,
community
.
currency
,
raise
NotEnoughMoneyError
(
value
,
community
.
currency
,
...
@@ -226,7 +242,7 @@ class Wallet(object):
...
@@ -226,7 +242,7 @@ class Wallet(object):
try
:
try
:
community
.
broadcast
(
bma
.
tx
.
Process
,
community
.
broadcast
(
bma
.
tx
.
Process
,
post_args
=
{
'
transaction
'
:
tx
.
signed_raw
()})
post_args
=
{
'
transaction
'
:
tx
.
signed_raw
()})
self
.
cache
.
awaiting_tx
.
append
(
tx
)
self
.
cache
s
[
community
.
currency
]
.
awaiting_tx
.
append
(
tx
)
except
:
except
:
raise
raise
...
@@ -239,13 +255,13 @@ class Wallet(object):
...
@@ -239,13 +255,13 @@ class Wallet(object):
return
tx
return
tx
def
transactions_awaiting
(
self
,
community
):
def
transactions_awaiting
(
self
,
community
):
return
self
.
cache
.
awaiting
(
community
)
return
self
.
cache
s
[
community
.
currency
]
.
awaiting
(
community
)
def
transactions_sent
(
self
,
community
):
def
transactions_sent
(
self
,
community
):
return
self
.
cache
.
latest_sent
(
community
)
return
self
.
cache
s
[
community
.
currency
]
.
latest_sent
(
community
)
def
transactions_received
(
self
,
community
):
def
transactions_received
(
self
,
community
):
return
self
.
cache
.
latest_received
(
community
)
return
self
.
cache
s
[
community
.
currency
]
.
latest_received
(
community
)
def
get_text
(
self
,
community
):
def
get_text
(
self
,
community
):
return
"
%s :
\n
\
return
"
%s :
\n
\
...
...
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