Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
beem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
hive
beem
Commits
eb2eb252
Commit
eb2eb252
authored
8 years ago
by
Fabian Schuh
Browse files
Options
Downloads
Patches
Plain Diff
[Amount] prevent different assets from adding up
parent
87652ed0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bitshares/amount.py
+39
-17
39 additions, 17 deletions
bitshares/amount.py
with
39 additions
and
17 deletions
bitshares/amount.py
+
39
−
17
View file @
eb2eb252
...
...
@@ -46,54 +46,51 @@ class Amount(object):
return
int
(
self
.
amount
*
10
**
self
.
asset
[
"
precision
"
])
def
__add__
(
self
,
other
):
a
=
Amount
(
s
elf
.
amount
,
self
.
symbol
)
a
=
Amount
(
s
tr
(
self
)
)
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
a
.
amount
+=
other
.
amount
else
:
a
.
amount
+=
float
(
other
)
return
a
def
__sub__
(
self
,
other
):
a
=
Amount
(
s
elf
.
amount
,
self
.
symbol
)
a
=
Amount
(
s
tr
(
self
)
)
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
a
.
amount
-=
other
.
amount
else
:
a
.
amount
-=
float
(
other
)
return
a
def
__mul__
(
self
,
other
):
a
=
Amount
(
s
elf
.
amount
,
self
.
symbol
)
a
=
Amount
(
s
tr
(
self
)
)
a
.
amount
*=
other
return
a
def
__floordiv__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
return
self
.
amount
//
other
.
amount
else
:
a
=
Amount
(
self
.
amount
,
self
.
symbol
)
a
.
amount
//=
other
return
a
a
=
Amount
(
str
(
self
))
a
.
amount
//=
other
return
a
def
__div__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
return
self
.
amount
/
other
.
amount
else
:
a
=
Amount
(
self
.
amount
,
self
.
symbol
)
a
.
amount
/=
other
return
a
a
=
Amount
(
str
(
self
))
a
.
amount
/=
other
return
a
def
__mod__
(
self
,
other
):
a
=
Amount
(
s
elf
.
amount
,
self
.
symbol
)
a
=
Amount
(
s
tr
(
self
)
)
a
.
amount
%=
other
return
a
def
__pow__
(
self
,
other
):
a
=
Amount
(
s
elf
.
amount
,
self
.
symbol
)
a
=
Amount
(
s
tr
(
self
)
)
a
.
amount
**=
other
return
a
def
__iadd__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
self
.
amount
+=
other
.
amount
else
:
self
.
amount
+=
other
...
...
@@ -101,6 +98,7 @@ class Amount(object):
def
__isub__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
self
.
amount
-=
other
.
amount
else
:
self
.
amount
-=
other
...
...
@@ -112,6 +110,7 @@ class Amount(object):
def
__idiv__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
return
self
.
amount
/
other
.
amount
else
:
self
.
amount
/=
other
...
...
@@ -131,39 +130,62 @@ class Amount(object):
def
__lt__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
return
self
.
amount
<
other
.
amount
else
:
return
self
.
amount
<
float
(
other
)
def
__le__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
return
self
.
amount
<=
other
.
amount
else
:
return
self
.
amount
<=
float
(
other
)
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
return
self
.
amount
==
other
.
amount
else
:
return
self
.
amount
==
float
(
other
)
def
__ne__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
return
self
.
amount
!=
other
.
amount
else
:
return
self
.
amount
!=
float
(
other
)
def
__ge__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
return
self
.
amount
>=
other
.
amount
else
:
return
self
.
amount
>=
float
(
other
)
def
__gt__
(
self
,
other
):
if
isinstance
(
other
,
Amount
):
assert
other
.
asset
==
self
.
asset
return
self
.
amount
>
other
.
amount
else
:
return
self
.
amount
>
float
(
other
)
__repr__
=
__str__
__truediv__
=
__div__
if
__name__
==
"
__main__
"
:
a
=
Amount
(
"
2 SBD
"
)
b
=
Amount
(
"
9 SBD
"
)
print
(
a
+
b
)
print
(
b
)
b
**=
2
b
+=
.
5
print
(
b
)
print
(
b
>
a
)
c
=
Amount
(
"
100 STEEM
"
)
print
(
c
*
.
10
)
#print(a + c)
#print(a < c)
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