Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Sep 9, 2020
2 parents b3d70b9 + 931fc96 commit 3260c51
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/1.4.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Add Hash160",
"type": "minor"
}
]
5 changes: 3 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
777 Fabian Schuh <[email protected]>
164 Fabian Schuh <[email protected]>
782 Fabian Schuh <[email protected]>
167 Fabian Schuh <[email protected]>
104 Vladimir Kamarzin <[email protected]>
100 Fabian Schuh <[email protected]>
60 pyup-bot <[email protected]>
Expand All @@ -13,6 +13,7 @@
3 Boombastic <[email protected]>
3 Holger Nahrstaedt <[email protected]>
3 abitmore <[email protected]>
2 Christopher Sanborn <[email protected]>
2 Nicolas Wack <[email protected]>
2 Scott Howard <[email protected]>
2 alt <[email protected]>
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
Note: version releases in the 0.x.y range may introduce breaking changes.

## 1.4.0

- minor: Add Hash160

## 1.3.4

- patch: Fix an issue with vesting balances raising exceptions
Expand Down
37 changes: 35 additions & 2 deletions graphenebase/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,19 @@ def variable_buffer(s):


def JsonObj(data):
""" Returns json object from data
""" Return json object from data
If data has a __json__() method, use that, else assume it follows the
convention that its string representation is interprettable as valid json.
(The latter can be problematic if str(data) returns, e.g., "1234". Was
this supposed to be the string "1234" or the number 1234? If this
ambiguity exists, the data type must implement __json__().)
"""
return json.loads(str(data))
try:
return data.__json__()
except Exception:
return json.loads(str(data))


class Uint8:
Expand Down Expand Up @@ -139,13 +149,30 @@ def __str__(self):


class Bytes:
"""Bytes
Initializes from and stores internally as a string of hex digits.
Byte-serializes as a length-prefixed series of bytes represented
by those hex digits.
Ex: len(str(Bytes("deadbeef")) == 8 # Eight hex chars
len(bytes(Bytes("deadbeef")) == 5 # Four data bytes plus varint length
Implements __json__() method to disambiguate between string and numeric in
event where hex digits include only numeric digits and no alpha digits.
"""

def __init__(self, d):
self.data = d

def __bytes__(self):
d = unhexlify(bytes(self.data, "utf-8"))
return varint(len(d)) + d

def __json__(self):
return str(self.data)

def __str__(self):
return str(self.data)

Expand Down Expand Up @@ -176,6 +203,12 @@ def __init__(self, a):
super().__init__(a)


class Hash160(Hash):
def __init__(self, a):
assert len(a) == 40, "Require 40 char long hex"
super().__init__(a)


class Void:
def __init__(self):
pass
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import setup

__version__ = "1.3.4"
__version__ = "1.4.0"
URL = "https://github.com/xeroc/python-graphenelib"

setup(
Expand Down

0 comments on commit 3260c51

Please sign in to comment.