예제 #1
0
    def _handle_api_error(self, payload: dict):
        if payload.get("result", None) is True:
            return
        if "Error" in payload:
            # class java.lang.NullPointerException : null
            raise ApiError(payload["Error"])
        if "code" in payload:
            try:
                msg = bytes.fromhex(payload["message"]).decode()
            except Exception:
                msg = payload.get("message", str(payload))

            if payload["code"] == "SIGERROR":
                raise BadSignature(msg)
            elif payload["code"] == "TAPOS_ERROR":
                raise TaposError(msg)
            elif payload["code"] in [
                    "TRANSACTION_EXPIRATION_ERROR", "TOO_BIG_TRANSACTION_ERROR"
            ]:
                raise TransactionError(msg)
            elif payload["code"] == "CONTRACT_VALIDATE_ERROR":
                raise ValidationError(msg)
            raise UnknownError(msg, payload["code"])
        if "result" in payload and isinstance(payload["result"], (dict, )):
            return self._handle_api_error(payload["result"])
예제 #2
0
 async def check_sign_weight(self):
     sign_weight = await self._client.get_sign_weight(self)
     if "transaction" not in sign_weight:
         self._client._handle_api_error(sign_weight)
         raise TransactionError('transaction not in sign_weight')
     self.txid = sign_weight["transaction"]["transaction"]["txID"]
     # when account not exist on-chain
     self._permission = sign_weight.get("permission", None)
예제 #3
0
파일: tron.py 프로젝트: 77ph/tronpy
 def trigger_const_smart_contract_function(
     self, owner_address: TAddress, contract_address: TAddress, function_selector: str, parameter: str,
 ) -> str:
     ret = self.provider.make_request(
         "wallet/triggerconstantcontract",
         {
             "owner_address": keys.to_base58check_address(owner_address),
             "contract_address": keys.to_base58check_address(contract_address),
             "function_selector": function_selector,
             "parameter": parameter,
             "visible": True,
         },
     )
     self._handle_api_error(ret)
     if 'message' in ret['result']:
         raise TransactionError(ret['result']['message'])
     return ret["constant_result"][0]