Ejemplo n.º 1
0
 def fulfillment(self, value):
     if value == None:
         self._fulfillment = FulfillmentSingleSignature()
         return
     if not isinstance(value, FulfillmentBaseClass):
         raise TypeError(
             "cannot assign value of type {} as a  CoinInput's fulfillment (expected: FulfillmentBaseClass)".format(type(value)))
     self._fulfillment = value
Ejemplo n.º 2
0
 def mint_fulfillment(self):
     """
     Retrieve the current mint fulfillment
     """
     if self._mint_fulfillment is None:
         return FulfillmentSingleSignature()
     return self._mint_fulfillment
Ejemplo n.º 3
0
class CoinInput(BaseDataTypeClass):
    """
    CoinIput class
    """

    def __init__(self, parentid=None, fulfillment=None, parent_output=None):
        self._parent_id = None
        self.parentid = parentid
        self._fulfillment = None
        self.fulfillment = fulfillment
        # property that can be set if known, but which is not part of the actual CoinInput
        self._parent_output = None
        self.parent_output = parent_output

    @classmethod
    def from_json(cls, obj):
        return cls(
            parentid=Hash.from_json(obj['parentid']),
            fulfillment=FulfillmentTypes.from_json(obj['fulfillment']))

    @classmethod
    def from_coin_output(cls, co):
        if not isinstance(co, CoinOutput):
            raise TypeError(
                "invalid co parameter, expected value of type CoinOutput, not {}".format(type(co)))
        ci = cls(
            parentid=co.id,
            fulfillment=FulfillmentTypes.from_condition(co.condition))
        ci.parent_output = co
        return ci

    @property
    def parentid(self):
        return self._parent_id

    @parentid.setter
    def parentid(self, value):
        if isinstance(value, Hash):
            self._parent_id = Hash(value=value.value)
            return
        self._parent_id = Hash(value=value)

    @property
    def fulfillment(self):
        return self._fulfillment

    @fulfillment.setter
    def fulfillment(self, value):
        if value == None:
            self._fulfillment = FulfillmentSingleSignature()
            return
        if not isinstance(value, FulfillmentBaseClass):
            raise TypeError(
                "cannot assign value of type {} as a  CoinInput's fulfillment (expected: FulfillmentBaseClass)".format(type(value)))
        self._fulfillment = value

    @property
    def has_parent_output(self):
        return self._parent_output != None

    @property
    def parent_output(self):
        return self._parent_output or CoinOutput()

    @parent_output.setter
    def parent_output(self, value):
        if value == None:
            self._parent_output = None
            return
        if not isinstance(value, CoinOutput):
            raise TypeError(
                "cannot assign value of type {} as a CoinInput's parent output (expected: CoinOutput)".format(type(value)))
        self._parent_output = value

    def json(self):
        return {
            'parentid': self._parent_id.json(),
            'fulfillment': self._fulfillment.json()
        }

    def sia_binary_encode(self, encoder):
        """
        Encode this CoinInput according to the Sia Binary Encoding format.
        """
        encoder.add_all(self._parent_id, self._fulfillment)

    def rivine_binary_encode(self, encoder):
        """
        Encode this CoinInput according to the Rivine Binary Encoding format.
        """
        encoder.add_all(self._parent_id, self._fulfillment)

    def signature_requests_new(self, input_hash_func):
        """
        Returns all signature requests that can be generated for this Coin Inputs,
        only possible if the parent (coin) output is defined and when there
        are still signatures required.
        """
        if self._parent_output == None:
            # no requestsd get created if the parent output is not set,
            # this allows for partial Tx signings
            return []
        return self._fulfillment.signature_requests_new(
            input_hash_func=input_hash_func,
            parent_condition=self._parent_output.condition,
        )

    def is_fulfilled(self):
        """
        Returns true if this CoinInput is fulfilled.
        """
        if self._parent_output == None:
            return False
        return self._fulfillment.is_fulfilled(self._parent_output.condition)