Beispiel #1
0
    def validate_amount(amount: list):
        if not isinstance(amount, list):
            raise InvalidParam("Invalid amount!")

        for entry in amount:
            if not (isinstance(entry, dict) or isinstance(entry, int)):
                raise InvalidParam("Invalid amount!")
Beispiel #2
0
 def supply(self, supply):
     if not isinstance(supply, int):
         raise InvalidParam("Supply must be type int!")
     if not (supply > 0 or supply == -1):
         raise InvalidParam("Supply must be greater than 0 or equal to -1!")
     self._supply = supply
     return self
Beispiel #3
0
 def symbol(self, symbol: str) -> bool:
     if not isinstance(symbol, str):
         raise InvalidParam("Symbol must be type str!")
     # Regex check for characters A-Z and 1-4 in length.
     if not re.fullmatch(r"[A-Z]{1,4}", symbol.upper()):
         raise InvalidParam("Symbol must be 1-4 characters of the set [A-Z].")
     self._symbol = symbol
     return self
Beispiel #4
0
 def issuer_id(self, issuer_id):
     if not isinstance(issuer_id, str):
         raise InvalidParam("Issuer ID must be a string!")
     # Validate issuer id format
     if not (len(issuer_id) == 64 and issuer_id[0:6] == "888888"):
         raise InvalidParam("Not a valid issuer ID!")
     self._issuer_id = issuer_id
     return self
Beispiel #5
0
    def validate_address(address: Union[FactoidAddress, str]) -> str:
        """
        Validate a Factoid address and convert to a str.

        :param address: a Factoid address as a str or a FactoidAddress object
        """

        if isinstance(address, FactoidAddress):
            address = address.to_string()
        elif isinstance(address, str):
            address = FactoidAddress(address_string=address).to_string()
        else:
            raise InvalidParam("Invalid address!")
        return address
Beispiel #6
0
    def validate_signer(
        self, signer: Union[FactoidPrivateKey, ServerIDPrivateKey, str]
    ) -> Union[FactoidPrivateKey, ServerIDPrivateKey]:
        """
        Validate a privatekey and convert it to a str.

        :param signer: a signing key as a FactoidPrivateKey, ServerIDPrivateKey or a str
        """

        if self.is_mint():
            if isinstance(signer, str):
                signer = ServerIDPrivateKey(signer)
            elif isinstance(signer, ServerIDPrivateKey):
                pass
            else:
                raise InvalidParam("Invalid signer key for transaction type!")
        else:
            if isinstance(signer, str):
                signer = FactoidPrivateKey(signer)
            elif isinstance(signer, FactoidPrivateKey):
                pass
            else:
                raise InvalidParam("Invalid signer key for transaction type!")
        return signer
Beispiel #7
0
    def add_output(self, address: Union[FactoidAddress, str],
                   amount: int) -> None:
        """
        Create an output entry from an address and amount.

        :param address: the factoid output address as a str or FactoidAddress object
        :param amount: the factoid output amount as a n int 
        """

        address = Transaction.validate_address(address)

        if not isinstance(amount, int):
            raise InvalidParam("Incorrect address or amount!")

        self.outputs[address] = amount
        return self
Beispiel #8
0
 def token_id(self, token_id):
     if not isinstance(token_id, str):
         raise InvalidParam("Token ID must be a string!")
     self._token_id = token_id
     return self