Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TsaAPI
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
Container Registry
Model registry
Operate
Environments
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
Patricio Kumagae
TsaAPI
Commits
391665d0
Commit
391665d0
authored
6 years ago
by
Patricio Kumagae
Browse files
Options
Downloads
Plain Diff
Merge branch 'desarrollo'
parents
83d37373
fab6bf3c
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
app/managers.py
+16
-16
16 additions, 16 deletions
app/managers.py
app/utils.py
+6
-6
6 additions, 6 deletions
app/utils.py
with
22 additions
and
22 deletions
app/managers.py
+
16
−
16
View file @
391665d0
...
@@ -10,8 +10,8 @@ from bitcoin.core.serialize import uint256_from_str
...
@@ -10,8 +10,8 @@ from bitcoin.core.serialize import uint256_from_str
class
TimestampManager
(
models
.
Manager
):
class
TimestampManager
(
models
.
Manager
):
@
class
method
@
static
method
def
get_provider
(
cls
):
def
get_provider
():
try
:
try
:
...
@@ -25,42 +25,42 @@ class TimestampManager(models.Manager):
...
@@ -25,42 +25,42 @@ class TimestampManager(models.Manager):
except
UnhandledRequest
:
except
UnhandledRequest
:
raise
raise
@
class
method
@
static
method
def
get_current_contract
(
cls
):
def
get_current_contract
():
return
TimestampManager
.
get_contract
(
CURRENT_CONTRACT_VERSION
)
return
TimestampManager
.
get_contract
(
CURRENT_CONTRACT_VERSION
)
@
class
method
@
static
method
def
get_contract
(
cls
,
contract_version
):
def
get_contract
(
contract_version
):
web3
=
TimestampManager
.
get_provider
()
web3
=
TimestampManager
.
get_provider
()
return
web3
.
eth
.
contract
(
abi
=
CONTRACTS
[
contract_version
][
'
abi
'
],
address
=
Web3
.
toChecksumAddress
(
CONTRACTS
[
contract_version
][
'
address
'
]))
return
web3
.
eth
.
contract
(
abi
=
CONTRACTS
[
contract_version
][
'
abi
'
],
address
=
Web3
.
toChecksumAddress
(
CONTRACTS
[
contract_version
][
'
address
'
]))
@
class
method
@
static
method
def
get_block
(
cls
,
block_number
):
def
get_block
(
block_number
):
web3
=
TimestampManager
.
get_provider
()
web3
=
TimestampManager
.
get_provider
()
return
web3
.
eth
.
getBlock
(
block_number
)
return
web3
.
eth
.
getBlock
(
block_number
)
@
class
method
@
static
method
def
get_transaction
(
cls
,
tx_hash
):
def
get_transaction
(
tx_hash
):
web3
=
TimestampManager
.
get_provider
()
web3
=
TimestampManager
.
get_provider
()
return
web3
.
eth
.
getTransaction
(
tx_hash
)
return
web3
.
eth
.
getTransaction
(
tx_hash
)
@
class
method
@
static
method
def
stamp
(
cls
,
proof_hash
,
file_hash
):
def
stamp
(
proof_hash
,
file_hash
):
contract
=
TimestampManager
.
get_current_contract
()
contract
=
TimestampManager
.
get_current_contract
()
return
contract
.
functions
.
stamp
(
uint256_from_str
(
proof_hash
.
encode
(
'
utf-8
'
)),
uint256_from_str
(
file_hash
.
encode
(
'
utf-8
'
))).
transact
({
'
from
'
:
Web3
.
toChecksumAddress
(
ACCOUNT_ADDRESS
)})
return
contract
.
functions
.
stamp
(
uint256_from_str
(
proof_hash
.
encode
(
'
utf-8
'
)),
uint256_from_str
(
file_hash
.
encode
(
'
utf-8
'
))).
transact
({
'
from
'
:
Web3
.
toChecksumAddress
(
ACCOUNT_ADDRESS
)})
@
class
method
@
static
method
def
verify
(
cls
,
contract_version
,
proof_hash
,
file_hash
):
def
verify
(
contract_version
,
proof_hash
,
file_hash
):
contract
=
TimestampManager
.
get_contract
(
contract_version
)
contract
=
TimestampManager
.
get_contract
(
contract_version
)
return
contract
.
functions
.
verify
(
uint256_from_str
(
proof_hash
.
encode
(
'
utf-8
'
)),
uint256_from_str
(
file_hash
.
encode
(
'
utf-8
'
))).
call
()
return
contract
.
functions
.
verify
(
uint256_from_str
(
proof_hash
.
encode
(
'
utf-8
'
)),
uint256_from_str
(
file_hash
.
encode
(
'
utf-8
'
))).
call
()
@
class
method
@
static
method
def
get_block_number
(
cls
,
contract_version
,
proof_hash
):
def
get_block_number
(
contract_version
,
proof_hash
):
contract
=
TimestampManager
.
get_contract
(
contract_version
)
contract
=
TimestampManager
.
get_contract
(
contract_version
)
return
contract
.
functions
.
getBlockNumber
(
uint256_from_str
(
proof_hash
.
encode
(
'
utf-8
'
))).
call
()
return
contract
.
functions
.
getBlockNumber
(
uint256_from_str
(
proof_hash
.
encode
(
'
utf-8
'
))).
call
()
This diff is collapsed.
Click to expand it.
app/utils.py
+
6
−
6
View file @
391665d0
...
@@ -5,14 +5,14 @@ from TsaApi.settings import ACCOUNT_ADDRESS, CURRENT_CONTRACT_VERSION
...
@@ -5,14 +5,14 @@ from TsaApi.settings import ACCOUNT_ADDRESS, CURRENT_CONTRACT_VERSION
class
Utils
():
class
Utils
():
@
class
method
@
static
method
def
sha256_encode
(
cls
,
string
):
def
sha256_encode
(
string
):
return
hashlib
.
sha256
(
string
.
encode
(
'
utf-8
'
)).
hexdigest
()
return
hashlib
.
sha256
(
string
.
encode
(
'
utf-8
'
)).
hexdigest
()
@
class
method
@
static
method
def
datetime_from_timestamp
(
cls
,
timestamp
):
def
datetime_from_timestamp
(
timestamp
):
return
datetime
.
datetime
.
fromtimestamp
(
timestamp
).
strftime
(
'
%d/%m/%Y %H:%M:%S
'
)
return
datetime
.
datetime
.
fromtimestamp
(
timestamp
).
strftime
(
'
%d/%m/%Y %H:%M:%S
'
)
@
class
method
@
static
method
def
get_proof_hash
(
cls
,
file_hash
):
def
get_proof_hash
(
file_hash
):
return
Utils
.
sha256_encode
(
str
(
file_hash
+
Utils
.
sha256_encode
(
str
(
int
(
time
.
time
())))
+
Utils
.
sha256_encode
(
ACCOUNT_ADDRESS
)))
+
CURRENT_CONTRACT_VERSION
return
Utils
.
sha256_encode
(
str
(
file_hash
+
Utils
.
sha256_encode
(
str
(
int
(
time
.
time
())))
+
Utils
.
sha256_encode
(
ACCOUNT_ADDRESS
)))
+
CURRENT_CONTRACT_VERSION
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