Skip to content

Commit

Permalink
Cleaned up PreimageSha256 a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
sbellem committed Jun 21, 2017
1 parent 3e04904 commit 45a15ad
Showing 1 changed file with 3 additions and 60 deletions.
63 changes: 3 additions & 60 deletions cryptoconditions/types/preimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PreimageSha256(BaseSha256):
TYPE_ASN1_FULFILLMENT = 'preimageSha256Fulfillment'
TYPE_CATEGORY = 'simple'

def __init__(self, preimage=None, asn1=None):
def __init__(self, preimage=None):
"""
PREIMAGE-SHA-256: Hashlock condition using SHA-256.
Expand Down Expand Up @@ -43,62 +43,6 @@ def __init__(self, preimage=None, asn1=None):
if preimage and (not isinstance(preimage, bytes)):
raise TypeError('Preimage must be bytes, was: {}'.format(preimage))
self.preimage = preimage
self.asn1 = asn1

@property
def bitmask(self):
return self.FEATURE_BITMASK

#def write_hash_payload(self, hasher):
# """
# Generate the contents of the condition hash.

# Writes the contents of the condition hash to a Hasher. Used internally by `getCondition`.

# HASH = SHA256(PREIMAGE)

# Args:
# hasher (Hasher): Destination where the hash payload will be written.
# """
# if not isinstance(hasher, Hasher):
# raise TypeError('hasher must be a Hasher instance')
# if self.preimage is None:
# raise ValueError('Could not calculate hash, no preimage provided')
# hasher.write(self.preimage)

#def parse_payload(self, reader, payload_size):
# """
# Parse the payload of a SHA256 hashlock fulfillment.

# Read a fulfillment payload from a Reader and populate this object with that fulfillment.

# FULFILLMENT_PAYLOAD =
# VARBYTES PREIMAGE

# Args:
# reader (Reader): Source to read the fulfillment payload from.
# payload_size (int): Total size of the fulfillment payload.
# """
# if not isinstance(reader, Reader):
# raise TypeError('reader must be a Reader instance')
# self.preimage = reader.read(payload_size)

#def write_payload(self, writer):
# """
# Generate the fulfillment payload.

# This writes the fulfillment payload to a Writer.

# Args:
# writer (Writer): Subject for writing the fulfillment payload.
# """
# if not isinstance(writer, (Writer, Predictor)):
# raise TypeError('writer must be a Writer instance')
# if self.preimage is None:
# raise ValueError('Preimage must be specified')

# writer.write(self.preimage)
# return writer

def to_dict(self):
"""
Expand All @@ -110,7 +54,6 @@ def to_dict(self):
return {
'type': 'fulfillment',
'type_id': self.TYPE_ID,
'bitmask': self.bitmask,
'preimage': self.preimage.decode()
}

Expand All @@ -124,8 +67,8 @@ def to_asn1_dict(self):
@property
def fingerprint_contents(self):
if self.preimage is None:
# TODO MissingDataError('Could not calculate hash, no preimage provided')
raise Exception('Could not calculate hash, no preimage provided')
raise MissingDataError(
'Could not calculate hash, no preimage provided')
return self.preimage

def parse_json(self, data):
Expand Down

0 comments on commit 45a15ad

Please sign in to comment.