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
7fe07870
Commit
7fe07870
authored
5 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#798
add all sources without filtering complex condition
parent
a0627ee3
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!778
Release 0.51.0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/sakia/services/sources.py
+51
-35
51 additions, 35 deletions
src/sakia/services/sources.py
tests/unit/services/test_sources.py
+64
-0
64 additions, 0 deletions
tests/unit/services/test_sources.py
with
115 additions
and
35 deletions
src/sakia/services/sources.py
+
51
−
35
View file @
7fe07870
from
PyQt5.QtCore
import
QObject
from
PyQt5.QtCore
import
QObject
from
duniterpy.api
import
bma
,
errors
from
duniterpy.api
import
bma
,
errors
from
duniterpy.documents
import
Transaction
as
TransactionDoc
from
duniterpy.documents
import
Transaction
as
TransactionDoc
from
duniterpy.grammars
import
output
from
duniterpy.grammars.output
import
Condition
from
duniterpy.grammars.output
import
Condition
from
duniterpy.documents
import
BlockUID
from
duniterpy.documents
import
BlockUID
import
logging
import
logging
...
@@ -106,25 +107,10 @@ class SourcesServices(QObject):
...
@@ -106,25 +107,10 @@ class SourcesServices(QObject):
self
.
currency
,
bma
.
tx
.
sources
,
req_args
=
{
"
pubkey
"
:
pubkey
}
self
.
currency
,
bma
.
tx
.
sources
,
req_args
=
{
"
pubkey
"
:
pubkey
}
)
)
nb_sources
=
len
(
sources_data
[
"
sources
"
])
nb_sources
=
len
(
sources_data
[
"
sources
"
])
for
i
,
s
in
enumerate
(
sources_data
[
"
sources
"
]):
for
i
ndex
,
source
in
enumerate
(
sources_data
[
"
sources
"
]):
log_stream
(
"
Parsing source ud/tx {:}/{:}
"
.
format
(
i
,
nb_sources
))
log_stream
(
"
Parsing source ud/tx {:}/{:}
"
.
format
(
i
ndex
,
nb_sources
))
progress
(
1
/
nb_sources
)
progress
(
1
/
nb_sources
)
conditions
=
pypeg2
.
parse
(
s
[
"
conditions
"
],
Condition
)
self
.
add_source
(
pubkey
,
source
)
if
conditions
.
left
.
pubkey
==
pubkey
:
try
:
if
conditions
.
left
.
pubkey
==
pubkey
:
source
=
Source
(
currency
=
self
.
currency
,
pubkey
=
pubkey
,
identifier
=
s
[
"
identifier
"
],
type
=
s
[
"
type
"
],
noffset
=
s
[
"
noffset
"
],
amount
=
s
[
"
amount
"
],
base
=
s
[
"
base
"
],
)
self
.
_sources_processor
.
insert
(
source
)
except
AttributeError
as
e
:
self
.
_logger
.
error
(
str
(
e
))
async
def
check_destruction
(
self
,
pubkey
,
block_number
,
unit_base
):
async
def
check_destruction
(
self
,
pubkey
,
block_number
,
unit_base
):
amount
=
self
.
_sources_processor
.
amount
(
self
.
currency
,
pubkey
)
amount
=
self
.
_sources_processor
.
amount
(
self
.
currency
,
pubkey
)
...
@@ -177,23 +163,8 @@ class SourcesServices(QObject):
...
@@ -177,23 +163,8 @@ class SourcesServices(QObject):
self
.
currency
,
bma
.
tx
.
sources
,
req_args
=
{
"
pubkey
"
:
pubkey
}
self
.
currency
,
bma
.
tx
.
sources
,
req_args
=
{
"
pubkey
"
:
pubkey
}
)
)
self
.
_sources_processor
.
drop_all_of
(
self
.
currency
,
pubkey
)
self
.
_sources_processor
.
drop_all_of
(
self
.
currency
,
pubkey
)
for
i
,
s
in
enumerate
(
sources_data
[
"
sources
"
]):
for
source
in
sources_data
[
"
sources
"
]:
conditions
=
pypeg2
.
parse
(
s
[
"
conditions
"
],
Condition
)
self
.
add_source
(
pubkey
,
source
)
if
conditions
.
left
.
pubkey
==
pubkey
:
try
:
if
conditions
.
left
.
pubkey
==
pubkey
:
source
=
Source
(
currency
=
self
.
currency
,
pubkey
=
pubkey
,
identifier
=
s
[
"
identifier
"
],
type
=
s
[
"
type
"
],
noffset
=
s
[
"
noffset
"
],
amount
=
s
[
"
amount
"
],
base
=
s
[
"
base
"
],
)
self
.
_sources_processor
.
insert
(
source
)
except
AttributeError
as
e
:
self
.
_logger
.
error
(
str
(
e
))
async
def
refresh_sources
(
self
,
connections
):
async
def
refresh_sources
(
self
,
connections
):
"""
"""
...
@@ -241,3 +212,48 @@ class SourcesServices(QObject):
...
@@ -241,3 +212,48 @@ class SourcesServices(QObject):
)
)
if
source
.
pubkey
==
pubkey
:
if
source
.
pubkey
==
pubkey
:
self
.
_sources_processor
.
insert
(
source
)
self
.
_sources_processor
.
insert
(
source
)
def
find_signature_in_condition
(
self
,
_condition
,
pubkey
,
result
=
False
):
"""
Recursive function to find a SIG(pubkey) in a Condition object
:param output.Condition _condition: Condition instance
:param str pubkey: Pubkey to find
:param bool result: True if found
:return:
"""
if
isinstance
(
_condition
.
left
,
output
.
Condition
):
result
|=
self
.
find_signature_in_condition
(
_condition
.
left
,
pubkey
,
result
)
if
isinstance
(
_condition
.
right
,
output
.
Condition
):
result
|=
self
.
find_signature_in_condition
(
_condition
.
right
,
pubkey
,
result
)
if
(
isinstance
(
_condition
.
left
,
output
.
SIG
)
and
_condition
.
left
.
pubkey
==
pubkey
or
isinstance
(
_condition
.
right
,
output
.
SIG
)
and
_condition
.
right
.
pubkey
==
pubkey
):
result
|=
True
return
result
def
add_source
(
self
,
pubkey
,
source
):
"""
Add a new source for the pubkey
:param str pubkey: Pubkey concerned
:param dict source: Source dict from api
:return:
"""
try
:
entity
=
Source
(
currency
=
self
.
currency
,
pubkey
=
pubkey
,
identifier
=
source
[
"
identifier
"
],
type
=
source
[
"
type
"
],
noffset
=
source
[
"
noffset
"
],
amount
=
source
[
"
amount
"
],
base
=
source
[
"
base
"
],
conditions
=
source
[
"
conditions
"
],
)
self
.
_sources_processor
.
insert
(
entity
)
except
AttributeError
as
e
:
self
.
_logger
.
error
(
str
(
e
))
This diff is collapsed.
Click to expand it.
tests/unit/services/test_sources.py
0 → 100644
+
64
−
0
View file @
7fe07870
import
pytest
from
duniterpy.documents.transaction
import
output
def
test_parse_source_condition
(
application_with_one_connection
,
alice
,
bob
):
application_with_one_connection
.
instanciate_services
()
issuer
=
alice
.
key
.
pubkey
receiver
=
bob
.
key
.
pubkey
condition
=
output
.
Condition
.
token
(
output
.
SIG
.
token
(
receiver
),
output
.
Operator
.
token
(
"
||
"
),
output
.
Condition
.
token
(
output
.
SIG
.
token
(
issuer
),
output
.
Operator
.
token
(
"
&&
"
),
output
.
CSV
.
token
(
604800
),
),
)
assert
(
application_with_one_connection
.
sources_service
.
find_signature_in_condition
(
condition
,
receiver
)
is
True
)
assert
(
application_with_one_connection
.
sources_service
.
find_signature_in_condition
(
condition
,
issuer
)
is
True
)
assert
(
application_with_one_connection
.
sources_service
.
find_signature_in_condition
(
condition
,
"
badpubkey
"
)
is
False
)
condition
=
output
.
Condition
.
token
(
output
.
Condition
.
token
(
output
.
CSV
.
token
(
604800
),
output
.
Operator
.
token
(
"
&&
"
),
output
.
SIG
.
token
(
issuer
),
),
output
.
Operator
.
token
(
"
||
"
),
output
.
SIG
.
token
(
receiver
),
)
assert
(
application_with_one_connection
.
sources_service
.
find_signature_in_condition
(
condition
,
receiver
)
is
True
)
assert
(
application_with_one_connection
.
sources_service
.
find_signature_in_condition
(
condition
,
issuer
)
is
True
)
assert
(
application_with_one_connection
.
sources_service
.
find_signature_in_condition
(
condition
,
"
badpubkey
"
)
is
False
)
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