Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Intial commit of UInt*, Fixed8 and neo.IO.Binary* #9

Merged
merged 3 commits into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ target/

# pyenv python configuration file
.python-version
.vscode/
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ install:
- pip install coveralls

script:
- python -m unittest -v
- coverage run --source neocore setup.py test
- pycodestyle neocore tests

after_success: coveralls
after_success:
- coveralls

deploy:
true:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Ready to contribute? Here's how to set up `neo-python-core` for local developmen
1. Fork the `neo-python-core` repo on GitHub.
2. Clone your fork locally::

$ git clone git@github.com:CityOfZion/neo-python-core.git
$ git clone git@github.com:<your-name>/neo-python-core.git

3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::

Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
History
=======


0.1.1 - 0.1.2 (2017-12-30)
--------------------------

Expand Down
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
neo-python-core
===============

Core functionality of `neo-python <https://github.com/CityOfZion/neo-python>`_.
Basic library for working with NEO related data in Python, without database
dependencies.

Includes datatypes like ``UInt160``, ``KeyPair``, and basic string to address and
address to `UInt160` methods.

Used by `neo-python <https://github.com/CityOfZion/neo-python>`_.

Getting started
---------------
Expand Down
55 changes: 55 additions & 0 deletions neocore/BigInteger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class BigInteger(int):
@property
def Sign(self):
if self > 0:
return 1
elif self == 0:
return 0
return -1

@staticmethod
def FromBytes(data, signed=False):
return BigInteger(int.from_bytes(data, 'little', signed=signed))

def Equals(self, other):
return super(BigInteger, self).__eq__(other)

def ToByteArray(self, signed=True):
if self < 0:
return self.to_bytes(1 + ((self.bit_length() + 7) // 8), byteorder='little', signed=True)

try:
return self.to_bytes((self.bit_length() + 7) // 8, byteorder='little', signed=signed)
except OverflowError:
return self.to_bytes(1 + ((self.bit_length() + 7) // 8), byteorder='little', signed=signed)

def __abs__(self, *args, **kwargs): # real signature unknown
return BigInteger(super(BigInteger, self).__abs__(*args, **kwargs))

def __add__(self, *args, **kwargs): # real signature unknown
return BigInteger(super(BigInteger, self).__add__(*args, **kwargs))

def __mod__(self, *args, **kwargs): # real signature unknown
return BigInteger(super(BigInteger, self).__mod__(*args, **kwargs))

def __mul__(self, *args, **kwargs): # real signature unknown
return BigInteger(super(BigInteger, self).__mul__(*args, **kwargs))

def __neg__(self, *args, **kwargs): # real signature unknown
return BigInteger(super(BigInteger, self).__neg__(*args, **kwargs))

def __str__(self, *args, **kwargs): # real signature unknown
return super(BigInteger, self).__str__(*args, **kwargs)

def __sub__(self, *args, **kwargs): # real signature unknown
return BigInteger(super(BigInteger, self).__sub__(*args, **kwargs))

def __floordiv__(self, *args, **kwargs):
return BigInteger(super(BigInteger, self).__floordiv__(*args, **kwargs))

def __truediv__(self, *args, **kwargs): # real signature unknown
return BigInteger(super(BigInteger, self).__truediv__(*args, **kwargs))


ZERO = BigInteger(0)
ONE = BigInteger(1)
131 changes: 131 additions & 0 deletions neocore/Fixed8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# -*- coding:utf-8 -*-
"""
Description:
Fixed8
Usage:
from neo.Fixed8 import Fixed8
"""


class Fixed8:

value = 0

D = 100000000

"""docstring for Fixed8"""

def __init__(self, number):
self.value = number

def GetData(self):
return self.value

@staticmethod
def FD():
return Fixed8(Fixed8.D)

@staticmethod
def FromDecimal(number):
out = int(number * Fixed8.D)
return Fixed8(out)

@staticmethod
def Satoshi():
return Fixed8(1)

@staticmethod
def One():
return Fixed8(Fixed8.D)

@staticmethod
def NegativeSatoshi():
return Fixed8(-1)

@staticmethod
def Zero():
return Fixed8(0)

@staticmethod
def TryParse(value, require_positive=False):
val = None
try:
val = float(value)
except Exception as e:
pass
if not val:
try:
val = int(value)
except Exception as e:
pass
if val:

if require_positive and val < 0:
return None

return Fixed8(int(val * Fixed8.D))

return None

def __add__(self, other):
return Fixed8(self.value + other.value)

def __iadd__(self, other):
return self.__add__(other)

def __sub__(self, other):
return Fixed8(self.value - other.value)

def __isub__(self, other):
return self.__sub__(other)

def __mul__(self, other):
return Fixed8(self.value * other.value)

def __imul__(self, other):
return self.__mul__(other)

def __truediv__(self, other):
return Fixed8(int(self.value / other.value))

def __floordiv__(self, other):
return Fixed8(self.value // other.value)

def __itruediv__(self, other):
return self.__truediv__(other)

def __mod__(self, other):
return Fixed8(int(self.value % other.value))

def __imod__(self, other):
return self.__mod__(other)

def __pow__(self, power, modulo=None):
return Fixed8(pow(self.value, power.value, modulo))

def __neg__(self):
return Fixed8(-1 * self.value)

def __eq__(self, other):
return self.value == other.value

def __lt__(self, other):
return self.value < other.value

def __gt__(self, other):
return self.value > other.value

def __ge__(self, other):
return self.value >= other.value

def __le__(self, other):
return self.value <= other.value

def ToInt(self):
return int(self.value / Fixed8.D)

def ToString(self):
return str(self.value / Fixed8.D)

def __str__(self):
return self.ToString()
Loading