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
40c2513e
Commit
40c2513e
authored
10 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Fixing transactions from / to raw
parent
37b5405b
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
_ucoinpy_test/documents/test_transaction.py
+89
-2
89 additions, 2 deletions
_ucoinpy_test/documents/test_transaction.py
ucoinpy/documents/transaction.py
+23
-21
23 additions, 21 deletions
ucoinpy/documents/transaction.py
with
112 additions
and
23 deletions
_ucoinpy_test/documents/test_transaction.py
+
89
−
2
View file @
40c2513e
...
...
@@ -8,7 +8,7 @@ from ucoinpy.documents.transaction import Transaction
from
mock
import
Mock
compact
_transaction
=
"""
TX:1:1:3:1:0
tx_
compact
=
"""
TX:1:1:3:1:0
HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY
0:T:65:D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8:4
0:T:77:F80993776FB55154A60B3E58910C942A347964AD:15
...
...
@@ -17,11 +17,60 @@ BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30
42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r
"""
tx_raw
=
"""
Version: 1
Type: Transaction
Currency: beta_brousouf
Issuers:
HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY
Inputs:
0:T:65:D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8:4
0:T:77:F80993776FB55154A60B3E58910C942A347964AD:15
0:D:88:F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B:11
Outputs:
BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30
Comment:
42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r
"""
class
Test_Transaction
:
def
test_fromcompact
(
self
):
tx
=
Transaction
.
from_compact
(
"
zeta_brousouf
"
,
tx_compact
)
assert
tx
.
version
==
1
assert
tx
.
currency
==
"
zeta_brousouf
"
assert
len
(
tx
.
issuers
)
==
1
assert
len
(
tx
.
inputs
)
==
3
assert
len
(
tx
.
outputs
)
==
1
assert
tx
.
issuers
[
0
]
==
"
HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY
"
assert
tx
.
inputs
[
0
].
index
==
0
assert
tx
.
inputs
[
0
].
source
==
'
T
'
assert
tx
.
inputs
[
0
].
number
==
65
assert
tx
.
inputs
[
0
].
txhash
==
"
D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8
"
assert
tx
.
inputs
[
0
].
amount
==
4
assert
tx
.
inputs
[
1
].
index
==
0
assert
tx
.
inputs
[
1
].
source
==
'
T
'
assert
tx
.
inputs
[
1
].
number
==
77
assert
tx
.
inputs
[
1
].
txhash
==
"
F80993776FB55154A60B3E58910C942A347964AD
"
assert
tx
.
inputs
[
1
].
amount
==
15
assert
tx
.
inputs
[
2
].
index
==
0
assert
tx
.
inputs
[
2
].
source
==
'
D
'
assert
tx
.
inputs
[
2
].
number
==
88
assert
tx
.
inputs
[
2
].
txhash
==
"
F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B
"
assert
tx
.
inputs
[
2
].
amount
==
11
assert
tx
.
outputs
[
0
].
pubkey
==
"
BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g
"
assert
tx
.
outputs
[
0
].
amount
==
30
assert
tx
.
signatures
[
0
]
==
"
42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r
"
def
test_fromraw
(
self
):
tx
=
Transaction
.
from_
compact
(
"
zeta_brousouf
"
,
2
,
compact_transaction
)
tx
=
Transaction
.
from_
signed_raw
(
tx_raw
)
assert
tx
.
version
==
1
assert
tx
.
currency
==
"
beta_brousouf
"
assert
len
(
tx
.
issuers
)
==
1
assert
len
(
tx
.
inputs
)
==
3
assert
len
(
tx
.
outputs
)
==
1
...
...
@@ -50,3 +99,41 @@ class Test_Transaction:
assert
tx
.
outputs
[
0
].
amount
==
30
assert
tx
.
signatures
[
0
]
==
"
42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r
"
def
test_fromraw_toraw
(
self
):
tx
=
Transaction
.
from_signed_raw
(
tx_raw
)
rendered_tx
=
tx
.
signed_raw
()
from_rendered_tx
=
Transaction
.
from_signed_raw
(
rendered_tx
)
assert
from_rendered_tx
.
version
==
1
assert
len
(
from_rendered_tx
.
issuers
)
==
1
assert
len
(
from_rendered_tx
.
inputs
)
==
3
assert
len
(
from_rendered_tx
.
outputs
)
==
1
assert
from_rendered_tx
.
issuers
[
0
]
==
"
HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY
"
assert
from_rendered_tx
.
inputs
[
0
].
index
==
0
assert
from_rendered_tx
.
inputs
[
0
].
source
==
'
T
'
assert
from_rendered_tx
.
inputs
[
0
].
number
==
65
assert
from_rendered_tx
.
inputs
[
0
].
txhash
==
"
D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8
"
assert
from_rendered_tx
.
inputs
[
0
].
amount
==
4
assert
from_rendered_tx
.
inputs
[
1
].
index
==
0
assert
from_rendered_tx
.
inputs
[
1
].
source
==
'
T
'
assert
from_rendered_tx
.
inputs
[
1
].
number
==
77
assert
from_rendered_tx
.
inputs
[
1
].
txhash
==
"
F80993776FB55154A60B3E58910C942A347964AD
"
assert
from_rendered_tx
.
inputs
[
1
].
amount
==
15
assert
from_rendered_tx
.
inputs
[
2
].
index
==
0
assert
from_rendered_tx
.
inputs
[
2
].
source
==
'
D
'
assert
from_rendered_tx
.
inputs
[
2
].
number
==
88
assert
from_rendered_tx
.
inputs
[
2
].
txhash
==
"
F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B
"
assert
from_rendered_tx
.
inputs
[
2
].
amount
==
11
assert
from_rendered_tx
.
outputs
[
0
].
pubkey
==
"
BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g
"
assert
from_rendered_tx
.
outputs
[
0
].
amount
==
30
assert
from_rendered_tx
.
signatures
[
0
]
==
"
42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r
"
This diff is collapsed.
Click to expand it.
ucoinpy/documents/transaction.py
+
23
−
21
View file @
40c2513e
...
...
@@ -40,13 +40,13 @@ SIGNATURE
...
'''
re_type
=
re
.
compile
(
"
Type: Transaction
\n
"
)
re_type
=
re
.
compile
(
"
Type:
(
Transaction
)
\n
"
)
re_header
=
re
.
compile
(
"
TX:([0-9])+:([0-9])+:([0-9])+:([0-9])+:(0|1)
\n
"
)
re_issuers
=
re
.
compile
(
"
Issuers:
\n
"
)
re_inputs
=
re
.
compile
(
"
Inputs:
\n
"
)
re_outputs
=
re
.
compile
(
"
Outputs:
\n
"
)
re_compact_comment
=
re
.
compile
(
"
-----@@@-----([^
\n
]+)
\n
"
)
re_comment
=
re
.
compile
(
"
Comment:
([^
\n
]
+
)
\n
"
)
re_comment
=
re
.
compile
(
"
Comment:
(?:)?
([^
\n
]
*
)
\n
"
)
re_pubkey
=
re
.
compile
(
"
([1-9A-Za-z][^OIl]{42,45})
\n
"
)
def
__init__
(
self
,
version
,
currency
,
issuers
,
inputs
,
outputs
,
...
...
@@ -65,7 +65,7 @@ SIGNATURE
self
.
comment
=
comment
@classmethod
def
from_compact
(
cls
,
currency
,
number
,
compact
):
def
from_compact
(
cls
,
currency
,
compact
):
lines
=
compact
.
splitlines
(
True
)
n
=
0
...
...
@@ -112,7 +112,7 @@ SIGNATURE
lines
=
raw
.
splitlines
(
True
)
n
=
0
version
=
Transaction
.
re_version
.
match
(
lines
[
n
]).
group
(
1
)
version
=
int
(
Transaction
.
re_version
.
match
(
lines
[
n
]).
group
(
1
)
)
n
=
n
+
1
Transaction
.
re_type
.
match
(
lines
[
n
]).
group
(
1
)
...
...
@@ -127,42 +127,44 @@ SIGNATURE
signatures
=
[]
if
Transaction
.
re_issuers
.
match
(
lines
[
n
]):
lines
=
lines
+
1
n
=
n
+
1
while
Transaction
.
re_inputs
.
match
(
lines
[
n
])
is
None
:
issuer
=
Transaction
.
re_pubkey
.
match
(
lines
[
n
]).
group
(
1
)
issuers
.
append
(
issuer
)
lines
=
lines
+
1
n
=
n
+
1
if
Transaction
.
re_inputs
.
match
(
lines
[
n
]):
lines
=
lines
+
1
n
=
n
+
1
while
Transaction
.
re_outputs
.
match
(
lines
[
n
])
is
None
:
input_source
=
InputSource
.
from_inline
(
lines
[
n
])
inputs
.
append
(
input_source
)
lines
=
lines
+
1
n
=
n
+
1
if
Transaction
.
re_outputs
.
match
(
lines
[
n
])
is
not
None
:
n
=
n
+
1
while
not
Transaction
.
re_comment
.
match
(
lines
[
n
]):
output
=
OutputSource
.
from_inline
(
lines
[
n
])
outputs
.
append
(
output
)
lines
=
lines
+
1
n
=
n
+
1
comment
=
Transaction
.
re_comment
.
match
(
lines
[
n
]).
group
(
1
)
n
=
n
+
1
if
Transaction
.
re_sign
.
match
(
lines
[
n
])
is
not
None
:
while
n
<
l
ines
.
len
:
sign
=
Transaction
.
re_sign
.
match
(
lines
[
n
]).
group
(
1
)
if
Transaction
.
re_sign
ature
.
match
(
lines
[
n
])
is
not
None
:
while
n
<
l
en
(
lines
)
:
sign
=
Transaction
.
re_sign
ature
.
match
(
lines
[
n
]).
group
(
1
)
signatures
.
append
(
sign
)
lines
=
lines
+
1
n
=
n
+
1
return
cls
(
version
,
currency
,
issuers
,
inputs
,
outputs
,
comment
,
signatures
)
def
raw
(
self
):
doc
=
"""
Version: {0}
doc
=
"""
Version: {0}
Type: Transaction
Currency: {1}
Issuers:
"""
.
format
(
self
.
version
,
Issuers:
"""
.
format
(
self
.
version
,
self
.
currency
)
for
p
in
self
.
issuers
:
...
...
@@ -176,10 +178,10 @@ Issuers:""".format(self.version,
for
o
in
self
.
outputs
:
doc
+=
"
{0}
\n
"
.
format
(
o
.
inline
())
doc
+=
"
"
"
COMMENT
:
{0}
"""
.
format
(
self
.
comment
)
doc
+=
"
Comment:
"
if
self
.
comment
:
doc
+=
"
{0}
"
.
format
(
self
.
comment
)
doc
+=
"
\n
"
for
signature
in
self
.
signatures
:
doc
+=
"
{0}
\n
"
.
format
(
signature
)
...
...
@@ -211,7 +213,7 @@ COMMENT
for
o
in
self
.
outputs
:
doc
+=
"
{0}
\n
"
.
format
(
o
.
inline
())
if
self
.
comment
:
doc
+=
"
{0}
\n
"
.
format
(
self
.
comment
)
doc
+=
"
-----@@@-----
{0}
\n
"
.
format
(
self
.
comment
)
for
s
in
self
.
signatures
:
doc
+=
"
{0}
\n
"
.
format
(
s
)
...
...
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