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
392d410d
"runtime/src/lib.rs" did not exist on "2d0ddabed3211570b8857235782c9872fccd5835"
Commit
392d410d
authored
10 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Transactions wrappers adapted to new format
parent
f3340a71
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ucoin/wrappers/transactions.py
+29
-92
29 additions, 92 deletions
ucoin/wrappers/transactions.py
with
29 additions
and
92 deletions
ucoin/wrappers/transactions.py
+
29
−
92
View file @
392d410d
...
@@ -24,29 +24,36 @@ logger = logging.getLogger("transactions")
...
@@ -24,29 +24,36 @@ logger = logging.getLogger("transactions")
class
Transaction
(
Wrapper
):
class
Transaction
(
Wrapper
):
def
__init__
(
self
,
type
,
pgp_fingerprint
,
message
=
''
,
keyid
=
None
,
peering
=
None
,
server
=
None
,
port
=
None
):
def
__init__
(
self
,
pgp_fingerprint
,
message
=
''
,
keyid
=
None
,
peering
=
None
,
server
=
None
,
port
=
None
):
super
().
__init__
(
server
,
port
)
super
().
__init__
(
server
,
port
)
self
.
keyid
=
keyid
self
.
keyid
=
keyid
self
.
pgp_fingerprint
=
pgp_fingerprint
self
.
pgp_fingerprint
=
pgp_fingerprint
self
.
message
=
message
self
.
message
=
message
self
.
type
=
type
self
.
error
=
None
self
.
error
=
None
self
.
peering
=
peering
self
.
peering
=
peering
def
__call__
(
self
):
def
__call__
(
self
):
try
:
try
:
last_tx
=
hdc
.
transactions
.
sender
.
Last
(
self
.
pgp_fingerprint
,
server
=
self
.
server
,
port
=
self
.
port
).
get
()
last_tx
=
hdc
.
transactions
.
sender
.
Last
(
count
=
1
,
pgp_fingerprint
=
self
.
pgp_fingerprint
,
server
=
self
.
server
,
port
=
self
.
port
).
get
()
last_tx
=
last_tx
[
'
transactions
'
][
0
]
last_tx
=
hdc
.
transactions
.
sender
.
View
(
self
.
pgp_fingerprint
,
tx_number
=
last_tx
[
'
number
'
],
server
=
self
.
server
,
port
=
self
.
port
).
get
()
except
ValueError
:
except
ValueError
:
last_tx
=
None
last_tx
=
None
if
last_tx
:
previous_hash
=
hashlib
.
sha1
((
"
%s%s
"
%
(
last_tx
[
'
raw
'
],
last_tx
[
'
transaction
'
][
'
signature
'
])).
encode
(
'
ascii
'
)).
hexdigest
().
upper
()
else
:
previous_hash
=
None
context_data
=
{}
context_data
=
{}
context_data
.
update
(
settings
)
context_data
.
update
(
settings
)
context_data
.
update
(
self
.
peering
if
self
.
peering
else
network
.
Peering
().
get
())
context_data
.
update
(
self
.
peering
if
self
.
peering
else
network
.
Peering
(
server
=
self
.
server
,
port
=
self
.
port
).
get
())
context_data
[
'
version
'
]
=
1
context_data
[
'
version
'
]
=
1
context_data
[
'
number
'
]
=
0
if
not
last_tx
else
last_tx
[
'
transaction
'
][
'
number
'
]
+
1
context_data
[
'
number
'
]
=
0
if
not
last_tx
else
last_tx
[
'
transaction
'
][
'
number
'
]
+
1
context_data
[
'
previousHash
'
]
=
hashlib
.
sha1
((
"
%(raw)s%(signature)s
"
%
last_tx
).
encode
(
'
ascii
'
)).
hexdigest
().
upper
()
if
last_tx
else
None
context_data
[
'
previousHash
'
]
=
previous_hash
context_data
[
'
message
'
]
=
self
.
message
context_data
[
'
message
'
]
=
self
.
message
context_data
[
'
type
'
]
=
self
.
type
context_data
[
'
fingerprint
'
]
=
self
.
pgp_fingerprint
context_data
[
'
fingerprint
'
]
=
self
.
pgp_fingerprint
context_data
.
update
(
self
.
get_context_data
())
context_data
.
update
(
self
.
get_context_data
())
...
@@ -67,12 +74,14 @@ Number: %(number)d
...
@@ -67,12 +74,14 @@ Number: %(number)d
tx
+=
"""
\
tx
+=
"""
\
Comment:
Comment:
%(message)s
%(message)s
"""
%
context_data
"""
%
context_data
tx
=
tx
.
replace
(
"
\n
"
,
"
\r\n
"
)
tx
=
tx
.
replace
(
"
\n
"
,
"
\r\n
"
)
print
(
self
.
keyid
)
print
(
tx
)
txs
=
settings
[
'
gpg
'
].
sign
(
tx
,
keyid
=
self
.
keyid
,
detach
=
True
)
txs
=
settings
[
'
gpg
'
].
sign
(
tx
,
keyid
=
self
.
keyid
,
detach
=
True
)
print
(
txs
)
print
(
tx
)
return
self
.
process
(
tx
,
txs
)
return
self
.
process
(
tx
,
txs
)
def
get_context_data
(
self
):
def
get_context_data
(
self
):
...
@@ -94,104 +103,32 @@ Comment:
...
@@ -94,104 +103,32 @@ Comment:
return
False
return
False
def
parse_coins
(
self
,
coins_message
):
coins
=
[]
for
coin
in
coins_message
.
split
(
'
,
'
):
data
=
coin
.
split
(
'
:
'
)
issuer
,
numbers
=
data
[
0
],
data
[
1
:]
for
number
in
numbers
:
view
=
hdc
.
coins
.
view
.
Owner
(
issuer
,
int
(
number
),
self
.
server
,
self
.
port
).
get
()
if
view
[
'
owner
'
]
!=
self
.
pgp_fingerprint
:
raise
ValueError
(
'
Trying to divide a coin you do not own (%s)
'
%
view
[
'
id
'
])
coins
.
append
(
view
)
return
coins
def
get_coins_sum
(
self
,
coins
):
__sum
=
0
for
coin
in
coins
:
base
,
power
=
coin
[
'
id
'
].
split
(
'
-
'
)[
2
:
4
]
__sum
+=
int
(
base
)
*
10
**
int
(
power
)
return
__sum
def
check_coins_sum
(
self
,
__sum
):
m
=
re
.
match
(
r
'
^(\d)(0*)$
'
,
str
(
__sum
))
if
not
m
:
raise
ValueError
(
'
bad sum value %d
'
%
__sum
)
class
Transfer
(
Transaction
):
def
__init__
(
self
,
pgp_fingerprint
,
recipient
,
coins
,
message
=
''
,
keyid
=
None
,
server
=
None
,
port
=
None
):
super
().
__init__
(
'
TRANSFER
'
,
pgp_fingerprint
,
message
,
keyid
=
keyid
,
server
=
server
,
port
=
port
)
self
.
recipient
=
recipient
self
.
coins
=
coins
def
get_message
(
self
,
context_data
,
tx
=
''
):
context_data
[
'
recipient
'
]
=
self
.
recipient
tx
+=
"""
\
Recipient: %(recipient)s
Type: %(type)s
Coins:
"""
%
context_data
for
coin
in
self
.
coins
.
split
(
'
,
'
):
data
=
coin
.
split
(
'
:
'
)
issuer
=
data
[
0
]
for
number
in
data
[
1
:]:
context_data
.
update
(
hdc
.
coins
.
view
.
Owner
(
issuer
,
int
(
number
),
self
.
server
,
self
.
port
).
get
())
tx
+=
'
%(id)s, %(transaction)s
\n
'
%
context_data
return
tx
class
RawTransfer
(
Transaction
):
class
RawTransfer
(
Transaction
):
def
__init__
(
self
,
pgp_fingerprint
,
recipient
,
coins
,
message
=
''
,
keyid
=
None
,
server
=
None
,
port
=
None
):
def
__init__
(
self
,
pgp_fingerprint
,
recipient
,
coins
,
message
=
''
,
super
().
__init__
(
'
TRANSFER
'
,
pgp_fingerprint
,
message
,
keyid
=
keyid
,
server
=
server
,
port
=
port
)
keyid
=
None
,
server
=
None
,
port
=
None
):
super
().
__init__
(
pgp_fingerprint
,
message
,
keyid
=
keyid
,
server
=
server
,
port
=
port
)
self
.
recipient
=
recipient
self
.
recipient
=
recipient
self
.
coins
=
coins
self
.
coins
=
coins
self
.
coins
.
sort
()
def
get_message
(
self
,
context_data
,
tx
=
''
):
def
get_message
(
self
,
context_data
,
tx
=
''
):
context_data
[
'
recipient
'
]
=
self
.
recipient
context_data
[
'
recipient
'
]
=
self
.
recipient
tx
+=
"""
\
tx
+=
"""
\
Recipient: %(recipient)s
Recipient: %(recipient)s
Type: %(type)s
Coins:
Coins:
"""
%
context_data
"""
%
context_data
for
coin
in
self
.
coins
:
for
coin
in
self
.
coins
:
data
=
coin
.
split
(
'
-
'
)
tx
+=
'
%s
'
%
coin
context_data
.
update
(
hdc
.
coins
.
view
.
Owner
(
data
[
0
],
int
(
data
[
1
]),
self
.
server
,
self
.
port
).
get
())
context_data
.
update
(
hdc
.
coins
.
view
.
Owner
(
coin
,
self
.
server
,
self
.
port
).
get
())
tx
+=
'
%(id)s, %(transaction)s
\n
'
%
context_data
if
'
transaction
'
in
context_data
:
tx
+=
'
:%(transaction)s
\n
'
%
context_data
else
:
tx
+=
"
\n
"
return
tx
return
tx
class
MonoTransaction
(
Transaction
):
def
get_next_coin_number
(
self
,
coins
):
number
=
0
for
c
in
coins
:
candidate
=
int
(
c
[
'
id
'
].
split
(
'
-
'
)[
1
])
if
candidate
>
number
:
number
=
candidate
return
number
+
1
def
get_message
(
self
,
context_data
,
tx
=
''
):
tx
+=
"""
\
Recipient: %(fingerprint)s
Type: %(type)s
Coins:
"""
%
context_data
try
:
last_issuance
=
hdc
.
transactions
.
sender
.
Last
(
self
.
pgp_fingerprint
,
self
.
server
,
self
.
port
).
get
()
except
ValueError
:
last_issuance
=
None
context_data
[
'
previous_idx
'
]
=
0
if
not
last_issuance
else
self
.
get_next_coin_number
(
last_issuance
[
'
transaction
'
][
'
coins
'
])
tx
+=
self
.
get_mono_message
(
context_data
)
return
tx
def
get_mono_message
(
self
,
context_data
,
tx
=
''
):
return
tx
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