def test_decode_int():
    """
    Test decode integers from binary
    """
    value = bytearray([1])
    output = binary.decode(value, type_=int)
    assert output == 1, "Failed to decode integer value from binary"
Esempio n. 2
0
 def json(self):
     """
     Returns a json encoded version of the UnlockHashCondition
     """
     return {
         'type': binary.decode(self._type, type_=int),
         'data': {
             'unlockhash': str(self._unlockhash)
         }
     }
Esempio n. 3
0
 def json(self):
     """
     Returns a json encoded versoin of the Fulfillment
     """
     return {
         'type': binary.decode(self._type, type_=int),
         'data': {
             'publickey': self._pub_key.json,
             'signature': self._signature.hex() if self._signature else ''
         }
     }
Esempio n. 4
0
 def json(self):
     """
     Returns a json encoded version of the MultiSignatureCondition
     """
     return {
         'type': binary.decode(self._type, type_=int),
         'data': {
             'unlockhashes': self._unlockhashes,
             'minimumsignaturecount': self._min_nr_sig
         }
     }
Esempio n. 5
0
 def json(self):
     """
     Returns a json encoded version of the AtomicSwapCondition
     """
     return {
         'type': binary.decode(self._type, type_=int),
         'data': {
             'timelock': self._locktime,
             'sender': self._sender,
             'receiver': self._reciever,
             'hashedsecret': self._hashed_secret
         }
     }
Esempio n. 6
0
 def json(self):
     """
     Returns a json encoded versoin of the MultiSignatureFulfillment
     """
     return {
         'type': binary.decode(self._type, type_=int),
         'data': {
             "pairs": [{
                 'publickey': pair['publickey'].json,
                 'signature': pair['signature'].hex()
             } for pair in self._pairs]
         }
     }
Esempio n. 7
0
 def json(self):
     """
     Returns a json encoded version of the LockTimeCondition
     """
     result = {
         'type': binary.decode(self._type, type_=int),
         'data': {
             'locktime': self._locktime,
             'condition': {},
         }
     }
     if self._condition:
         result['data']['condition'] = self._condition.json
     return result
Esempio n. 8
0
 def _validate(self,
               transaction_id,
               amount=None,
               hashed_secret=None,
               receiver_address=None,
               time_left=None):
     """
     An internal function that does all the validation the public validate method does, but return more info
     """
     output_id, output_result = self._get_output_info_from_id(
         transaction_id=transaction_id)
     if output_result:
         if amount and int(
                 output_result['value']) != amount * HASTINGS_TFT_VALUE:
             raise InvalidAtomicswapContract(
                 "Contract amount does not match the provided amount value")
         if output_result['condition']['type'] != binary.decode(
                 ATOMICSWAP_CONDITION_TYPE, type_=int):
             raise InvalidAtomicswapContract(
                 "Condition type is not correct")
         if receiver_address and output_result['condition']['data'][
                 'receiver'] != receiver_address:
             raise InvalidAtomicswapContract(
                 "Receiver address does not match the provided address")
         if hashed_secret and output_result['condition']['data'][
                 'hashedsecret'] != hashed_secret:
             raise InvalidAtomicswapContract(
                 "Hashed secret does not match the provided hashed secret")
         if time_left and abs(output_result['condition']['data']['timelock']
                              - time.time()) < time_left:
             raise InvalidAtomicswapContract(
                 "Contract will expired in less than the minimum time specified"
             )
     else:
         raise InvalidAtomicswapContract(
             "Could not validate atomicswap contract for transaction {}".
             format(transaction_id))
     return True, output_result, output_id