Example #1
0
    def _binary(self, encoder):
        result = bytearray()
        result.extend(self._type)
        # 106 size of the atomicswap condition in binary form
        result.extend(encoder.encode(106))
        result.extend(encoder.encode(UnlockHash.from_string(self._sender)))
        result.extend(encoder.encode(UnlockHash.from_string(self._reciever)))
        result.extend(encoder.encode(self._hashed_secret, type_='hex'))
        result.extend(encoder.encode(self._locktime))

        return result
Example #2
0
 def create_singlesig_condition(self, address, locktime=None):
     """
     Create a new single signature condition
     """
     unlockhash = UnlockHash.from_string(address)
     condition = UnlockHashCondition(unlockhash=unlockhash)
     if locktime is not None:
         condition = LockTimeCondition(condition=condition, locktime=locktime)
     return condition
Example #3
0
 def data(self):
     """
     Retruns the binary format of the data on the condition
     """
     result = bytearray()
     result.extend(binary.encode(self._min_nr_sig))
     result.extend(binary.encode(len(self._unlockhashes)))
     for unlockhash in self._unlockhashes:
         result.extend(binary.encode(UnlockHash.from_string(unlockhash)))
     return result
Example #4
0
 def _binary(self, encoder):
     result = bytearray()
     result.extend(self._type)
     condition_binary = bytearray()
     condition_binary.extend(encoder.encode(self._min_nr_sig))
     condition_binary.extend(encoder.encode(len(self._unlockhashes)))
     for unlockhash in self._unlockhashes:
         condition_binary.extend(
             encoder.encode(UnlockHash.from_string(unlockhash)))
     result.extend(binary.encode(condition_binary, type_='slice'))
     return result
Example #5
0
 def from_dict(condition_dict):
     """
     Creates an unlock condition object from a dictionary
     """
     if 'data' in condition_dict:
         if 'type' in condition_dict:
             if condition_dict['type'] == 1:
                 return UnlockHashCondition(
                     unlockhash=UnlockHash.from_string(
                         condition_dict['data']['unlockhash']))
             elif condition_dict['type'] == 2:
                 return AtomicSwapCondition.from_dict(
                     condition_dict['data'])
             elif condition_dict['type'] == 3:
                 return LockTimeCondition.from_dict(condition_dict['data'])
             elif condition_dict['type'] == 4:
                 return MultiSignatureCondition.from_dict(
                     condition_dict['data'])
Example #6
0
def ulh():
    """
    Generates a test unlockhash of with unlock type publickey
    """
    hash = utils.hash(b'hello')
    return UnlockHash(unlock_type=UNLOCK_TYPE_PUBKEY, hash=hash)
Example #7
0
def recipient():
    """
    Generates a recipient address
    """
    hash = utils.hash(b'hello recipient')
    return str(UnlockHash(unlock_type=UNLOCK_TYPE_PUBKEY, hash=hash))
Example #8
0
def test_unlockhash_from_string():
    """
    Tests loading an unlockhash from a string
    """
    input = '01324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf57a828ea336a'
    assert str(UnlockHash.from_string(input)) == input, "Failed to load unlockhash from string"
 def unlock_hash(self):
     encoded_pub_key = self.binary
     hash = utils.hash(encoded_pub_key, encoding_type='slice')
     return UnlockHash(unlock_type=UNLOCK_TYPE_PUBKEY, hash=hash)