iexbase/tron-api-python

Add origin_energy_limit

Closed this issue · 1 comments

This is currently supported using the existing code base due to the way keyword arguments are passed in:

with open("HelloWorldtron.json") as FILE:
    contract = json.load(FILE)

contract = ContractConstructor(
    tron,
    abi=contract['abi'],
    bytecode=to_bytes(text=contract['bytecode'])
)
tx = contract.transact(
    fee_limit=10**9,
    call_value=0,
    origin_energy_limit=9999
)

sign = tron.trx.sign(tx)
result = tron.trx.broadcast(sign)

However, if omitted (which it is in all examples), then the transaction will get rejected by a network running java-tron 3.2 or higher with an ambiguous CONTRACT_VALIDATE_ERROR. Validation should be added as well, such as:

        # Maximum energy consumption limit
        origin_energy_limit = kwargs.setdefault('origin_energy_limit ', 0)

        ...

        if not is_integer(origin_energy_limit) or origin_energy_limit < 0 or origin_energy_limit > 10 ** 9:
            raise ValueError('Invalid energy limit provided')

Issue resolved