Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-gateway
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
Agustin Dorda
django-gateway
Commits
4cee6afb
Commit
4cee6afb
authored
5 years ago
by
adorda
Browse files
Options
Downloads
Patches
Plain Diff
Validator, field y arreglo de bug de signers
parent
3971ef15
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
gateway/fields.py
+8
-0
8 additions, 0 deletions
gateway/fields.py
gateway/gateway.py
+4
-1
4 additions, 1 deletion
gateway/gateway.py
gateway/utils.py
+17
-0
17 additions, 0 deletions
gateway/utils.py
gateway/validators.py
+9
-0
9 additions, 0 deletions
gateway/validators.py
setup.py
+3
-2
3 additions, 2 deletions
setup.py
with
41 additions
and
3 deletions
gateway/fields.py
+
8
−
0
View file @
4cee6afb
from
django.db.models.fields
import
CharField
from
gateway.validators
import
validate_address
class
AddressField
(
CharField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
default_validators
.
append
(
validate_address
)
super
().
__init__
(
*
args
,
**
kwargs
)
This diff is collapsed.
Click to expand it.
gateway/gateway.py
+
4
−
1
View file @
4cee6afb
...
...
@@ -159,7 +159,7 @@ class Gateway:
def
block_is_canonical_poa
(
self
,
block_number
):
last_block_number
=
self
.
get_last_blocknumber
()
tx_block_number
=
block_number
required_block_difference
=
math
.
ceil
(
self
.
get_signers
_count
()
/
2
)
+
1
required_block_difference
=
math
.
ceil
(
len
(
self
.
get_signers
(
)
)
/
2
)
+
1
return
(
last_block_number
-
tx_block_number
)
>
required_block_difference
def
pending_transactions
(
self
):
...
...
@@ -171,6 +171,9 @@ class Gateway:
return
txs
def
get_signers_count
(
self
):
return
len
(
self
.
get_signers
())
def
get_signers
(
self
):
return
self
.
w3
.
manager
.
request_blocking
(
"
clique_getSigners
"
,
[])
def
get_smart_contract_bytecode
(
self
,
smart_contract_address
):
...
...
This diff is collapsed.
Click to expand it.
gateway/utils.py
+
17
−
0
View file @
4cee6afb
...
...
@@ -36,3 +36,20 @@ def hex32bytes_string(some_hex32bytes):
return
Web3
.
toText
(
some_hex32bytes
.
decode
().
strip
(
'
\\\u0000
'
))
except
UnicodeDecodeError
as
ude
:
return
some_hex32bytes
class
HexBytesToDict
:
def
dehex_dict
(
self
,
dictionary
):
for
k
,
v
in
dictionary
.
items
():
if
isinstance
(
v
,
dict
):
self
.
dehex_dict
(
dictionary
[
k
])
elif
isinstance
(
v
,
list
):
self
.
dehex_list
(
dictionary
[
k
])
elif
isinstance
(
v
,
HexBytes
):
dictionary
[
k
]
=
v
.
hex
()
def
dehex_list
(
self
,
sequence
):
i
=
0
while
i
<
len
(
sequence
):
sequence
[
i
]
=
sequence
[
i
].
decode
()
i
=
i
+
1
This diff is collapsed.
Click to expand it.
gateway/validators.py
0 → 100644
+
9
−
0
View file @
4cee6afb
from
django.core.exceptions
import
ValidationError
from
django.utils.translation
import
gettext_lazy
as
_
from
gateway.gateway
import
AddressValidation
def
validate_address
(
value
):
validator
=
AddressValidation
()
if
not
validator
.
is_valid
(
value
):
raise
ValidationError
(
_
(
'
%(value)s is not a valid address
'
),
params
=
{
'
value
'
:
value
})
This diff is collapsed.
Click to expand it.
setup.py
+
3
−
2
View file @
4cee6afb
...
...
@@ -9,7 +9,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup
(
name
=
'
django-ethgateway
'
,
version
=
'
0.0.
2
'
,
version
=
'
0.0.
4
'
,
packages
=
find_packages
(),
include_package_data
=
True
,
license
=
'
GNU GPL License
'
,
# example license
...
...
@@ -20,7 +20,8 @@ setup(
author_email
=
'
agustindorda@gmail.com
'
,
install_requires
=
[
'
aiohttp==3.5.4
'
,
'
web3==4.6.0
'
'
web3==4.6.0
'
,
'
Django==2.1.7
'
],
classifiers
=
[
'
Framework :: Django
'
,
...
...
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