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
4ed36aa5
Commit
4ed36aa5
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
New TX Lifecycle
- First remove the dirty patches to handle blockchain rollback from the refresh
parent
2777208d
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/transfer.py
+7
-4
7 additions, 4 deletions
src/cutecoin/core/transfer.py
src/cutecoin/core/txhistory.py
+14
-17
14 additions, 17 deletions
src/cutecoin/core/txhistory.py
with
21 additions
and
21 deletions
src/cutecoin/core/transfer.py
+
7
−
4
View file @
4ed36aa5
...
...
@@ -70,11 +70,13 @@ class Transfer(QObject):
return
cls
(
None
,
Transfer
.
TO_SEND
,
metadata
)
@classmethod
def
create_from_blockchain
(
cls
,
hash
,
st
at
e
,
metadata
):
def
create_from_blockchain
(
cls
,
hash
,
metad
at
a
,
block_number
,
time
,
nb_validation
):
"""
Create a new transfer sent from another cutecoin instance
"""
return
cls
(
hash
,
state
,
metadata
)
tx
=
cls
(
hash
,
Transfer
.
VALIDATING
,
metadata
)
tx
.
check_registered
(
block_number
,
time
,
nb_validation
)
return
tx
@classmethod
def
load
(
cls
,
data
):
...
...
@@ -128,7 +130,7 @@ class Transfer(QObject):
return
result
def
check_registered
(
self
,
txhash
,
block_number
,
time
,
data
_validation
):
def
check_registered
(
self
,
txhash
,
block_number
,
time
,
nb
_validation
):
"""
Check if the transfer was registered in a block.
Update the transfer state to VALIDATED if it was registered.
...
...
@@ -136,6 +138,7 @@ class Transfer(QObject):
:param txhash: A transaction ucoinpy object found in the block
:param int block_number: The block number checked
:param int time: The time of the block
:param int nb_validation: The number of validations needed to become VALIDATED
"""
if
txhash
==
self
.
hash
:
if
self
.
state
==
Transfer
.
AWAITING
:
...
...
@@ -143,7 +146,7 @@ class Transfer(QObject):
self
.
_metadata
[
'
block
'
]
=
block_number
self
.
_metadata
[
'
time
'
]
=
time
if
self
.
state
==
Transfer
.
VALIDATING
and
\
self
.
_metadata
[
'
block
'
]
-
block_number
>=
data
_validation
:
self
.
_metadata
[
'
block
'
]
-
block_number
>=
nb
_validation
:
self
.
state
=
Transfer
.
VALIDATED
def
check_refused
(
self
,
time
,
block_time
,
mediantime_blocks
):
...
...
This diff is collapsed.
Click to expand it.
src/cutecoin/core/txhistory.py
+
14
−
17
View file @
4ed36aa5
...
...
@@ -100,9 +100,7 @@ class TxHistory():
"""
receivers
=
[
o
.
pubkey
for
o
in
tx
.
outputs
if
o
.
pubkey
!=
tx
.
issuers
[
0
]]
state
=
yield
from
TxHistory
.
_validation_state
(
community
,
block_number
,
current_block
)
nb_validations
=
community
.
network
.
fork_window
((
yield
from
community
.
members_pubkeys
()))
if
len
(
receivers
)
==
0
:
receivers
=
[
tx
.
issuers
[
0
]]
...
...
@@ -131,13 +129,13 @@ class TxHistory():
if
i
==
self
.
wallet
.
pubkey
])
>
0
in_outputs
=
len
([
o
for
o
in
tx
.
outputs
if
o
.
pubkey
==
self
.
wallet
.
pubkey
])
>
0
a
wa
iting
=
[
t
for
t
in
self
.
_transfers
wa
tched
=
[
t
for
t
in
self
.
_transfers
if
t
.
state
in
(
Transfer
.
AWAITING
,
Transfer
.
VALIDATING
)]
# We check if the transaction correspond to one we sent
# but not from this cutecoin Instance
tx_hash
=
hashlib
.
sha1
(
tx
.
signed_raw
().
encode
(
"
ascii
"
)).
hexdigest
().
upper
()
if
tx_hash
not
in
[
t
.
hash
for
t
in
a
wa
iting
]:
if
tx_hash
not
in
[
t
.
hash
for
t
in
wa
tched
]:
# If the wallet pubkey is in the issuers we sent this transaction
if
in_issuers
:
outputs
=
[
o
for
o
in
tx
.
outputs
...
...
@@ -147,8 +145,9 @@ class TxHistory():
amount
+=
o
.
amount
metadata
[
'
amount
'
]
=
amount
transfer
=
Transfer
.
create_from_blockchain
(
tx_hash
,
state
,
metadata
.
copy
())
metadata
.
copy
(),
current_block
[
'
number
'
],
mediantime
,
nb_validations
)
return
transfer
# If we are not in the issuers,
# maybe it we are in the recipients of this transaction
...
...
@@ -159,18 +158,16 @@ class TxHistory():
for
o
in
outputs
:
amount
+=
o
.
amount
metadata
[
'
amount
'
]
=
amount
if
tx_hash
not
in
[
t
.
hash
for
t
in
awaiting
]:
transfer
=
Transfer
.
create_from_blockchain
(
tx_hash
,
state
,
metadata
.
copy
())
received_list
.
append
(
transfer
)
return
transfer
transfer
=
Transfer
.
create_from_blockchain
(
tx_hash
,
metadata
.
copy
(),
current_block
[
'
number
'
],
mediantime
,
nb_validations
)
received_list
.
append
(
transfer
)
return
transfer
else
:
transfer
=
[
t
for
t
in
a
wa
iting
if
t
.
hash
==
tx_hash
][
0
]
transfer
=
[
t
for
t
in
wa
tched
if
t
.
hash
==
tx_hash
][
0
]
transfer
.
check_registered
(
tx_hash
,
current_block
[
'
number
'
],
mediantime
,
community
.
network
.
fork_window
(
community
.
members_pubkeys
()))
transfer
.
check_registered
(
tx_hash
,
current_block
[
'
number
'
],
mediantime
,
nb_validations
)
return
None
@asyncio.coroutine
...
...
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