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
41980ff2
Commit
41980ff2
authored
10 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Added caching of individual blocks
parent
ddc30d28
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
+21
-0
21 additions, 0 deletions
src/cutecoin/core/app.py
src/cutecoin/core/community.py
+29
-1
29 additions, 1 deletion
src/cutecoin/core/community.py
with
50 additions
and
1 deletion
src/cutecoin/core/app.py
+
21
−
0
View file @
41980ff2
...
@@ -88,6 +88,18 @@ class Application(object):
...
@@ -88,6 +88,18 @@ class Application(object):
self
.
accounts
[
account_name
]
=
account
self
.
accounts
[
account_name
]
=
account
def
load_cache
(
self
,
account
):
def
load_cache
(
self
,
account
):
for
community
in
account
.
communities
:
community_path
=
os
.
path
.
join
(
config
.
parameters
[
'
home
'
],
account
.
name
,
'
__cache__
'
,
community
.
currency
)
if
os
.
path
.
exists
(
community_path
):
with
open
(
community_path
,
'
r
'
)
as
json_data
:
data
=
json
.
load
(
json_data
)
if
'
version
'
in
data
and
data
[
'
version
'
]
==
__version__
:
community
.
load_cache
(
data
)
else
:
os
.
remove
(
community_path
)
for
wallet
in
account
.
wallets
:
for
wallet
in
account
.
wallets
:
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
)
...
@@ -130,6 +142,15 @@ class Application(object):
...
@@ -130,6 +142,15 @@ class Application(object):
data
[
'
version
'
]
=
__version__
data
[
'
version
'
]
=
__version__
json
.
dump
(
data
,
outfile
,
indent
=
4
,
sort_keys
=
True
)
json
.
dump
(
data
,
outfile
,
indent
=
4
,
sort_keys
=
True
)
for
community
in
account
.
communities
:
community_path
=
os
.
path
.
join
(
config
.
parameters
[
'
home
'
],
account
.
name
,
'
__cache__
'
,
community
.
currency
)
with
open
(
community_path
,
'
w
'
)
as
outfile
:
data
=
community
.
jsonify_cache
()
data
[
'
version
'
]
=
__version__
json
.
dump
(
data
,
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
:
path
=
os
.
path
.
join
(
config
.
parameters
[
'
home
'
],
path
=
os
.
path
.
join
(
config
.
parameters
[
'
home
'
],
...
...
This diff is collapsed.
Click to expand it.
src/cutecoin/core/community.py
+
29
−
1
View file @
41980ff2
...
@@ -22,9 +22,31 @@ class Cache():
...
@@ -22,9 +22,31 @@ class Cache():
self
.
community
=
community
self
.
community
=
community
self
.
data
=
{}
self
.
data
=
{}
def
load_from_json
(
self
,
data
):
self
.
data
=
{}
for
entry
in
data
[
'
cache
'
]:
key
=
entry
[
'
key
'
]
cache_key
=
(
key
[
0
],
key
[
1
],
key
[
2
],
key
[
3
],
key
[
4
])
self
.
data
[
cache_key
]
=
entry
[
'
value
'
]
self
.
latest_block
=
data
[
'
latest_block
'
]
def
jsonify
(
self
):
saved_requests
=
[
hash
(
bma
.
blockchain
.
Block
)]
data
=
{
k
:
self
.
data
[
k
]
for
k
in
self
.
data
.
keys
()
if
k
[
0
]
in
saved_requests
}
entries
=
[]
for
d
in
data
:
entries
.
append
({
'
key
'
:
d
,
'
value
'
:
data
[
d
]})
return
{
'
latest_block
'
:
self
.
latest_block
,
'
cache
'
:
entries
}
def
refresh
(
self
):
def
refresh
(
self
):
self
.
latest_block
=
self
.
community
.
current_blockid
()[
'
number
'
]
self
.
latest_block
=
self
.
community
.
current_blockid
()[
'
number
'
]
self
.
data
=
{}
saved_requests
=
[
hash
(
bma
.
blockchain
.
Block
)]
self
.
data
=
{
k
:
self
.
data
[
k
]
for
k
in
self
.
data
.
keys
()
if
k
[
0
]
in
saved_requests
}
def
request
(
self
,
request
,
req_args
=
{},
get_args
=
{}):
def
request
(
self
,
request
,
req_args
=
{},
get_args
=
{}):
cache_key
=
(
hash
(
request
),
cache_key
=
(
hash
(
request
),
...
@@ -116,6 +138,12 @@ class Community(object):
...
@@ -116,6 +138,12 @@ class Community(object):
community
=
cls
(
currency
,
peers
)
community
=
cls
(
currency
,
peers
)
return
community
return
community
def
load_cache
(
self
,
json_data
):
self
.
_cache
.
load_from_json
(
json_data
)
def
jsonify_cache
(
self
):
return
self
.
_cache
.
jsonify
()
def
name
(
self
):
def
name
(
self
):
return
self
.
currency
return
self
.
currency
...
...
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