Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added blockNumber parameter for trigger_constant_contract #138

Open
joseddg92 opened this issue Sep 3, 2024 · 0 comments
Open

Added blockNumber parameter for trigger_constant_contract #138

joseddg92 opened this issue Sep 3, 2024 · 0 comments

Comments

@joseddg92
Copy link

Despite being undocumented, (it does not appear in https://developers.tron.network/reference/triggerconstantcontract) there is a blockNumber paramter that can be used to retrieve the return value of a SmartContract in old blocks.

This could be added to Tron.py trigger_constant_contract like below. If the developer sees it OK, I could event send the pull request. Of course, ContractMethod.call method would also need adaptation so that this can be called from instantiated Contracts easily.

def trigger_constant_contract(
    self,
    owner_address: TAddress,
    contract_address: TAddress,
    function_selector: str,
    parameter: str,
    blockNumber: Union[int, str]
) -> dict:
    body = {
            "owner_address": keys.to_base58check_address(owner_address),
            "contract_address": keys.to_base58check_address(contract_address),
            "function_selector": function_selector,
            "parameter": parameter,
            "visible": True,
        }
    if blockNumber:
            body["blockNumber"] = blockNumber
    ret = self.provider.make_request(
        "wallet/triggerconstantcontract",
        body,
    )
    self._handle_api_error(ret)
    if "message" in ret.get("result", {}):
        msg = ret["result"]["message"]
        result = ret.get("constant_result", [])
        try:
            if result and len(result[0]) > (4 + 32) * 2:
                error_msg = tron_abi.decode_single("string", bytes.fromhex(result[0])[4 + 32 :])
                msg = f"{msg}: {error_msg}"
        except Exception:
            pass
        raise TvmError(msg)
    return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant