Hi all,
When I am trying the make application call contract function returns a value.How do I get that value in a transaction.
This is my code
contract.py
on_result = Seq(
Assert(
And(
Global.latest_timestamp() >= App.globalGet(proposal_start_time),
Global.latest_timestamp() < App.globalGet(proposal_end_time)
)
),
If(App.globalGet(yes_count) == App.globalGet(min_num_approval)).Then (
If(App.globalGet(yes_count) == App.globalGet(total_count)).Then(
Seq(
App.globalPut(vote_result,Int(1)),
)
)
.ElseIf(App.globalGet(min_per_approval) >= Btoi(Txn.application_args[2])).Then(
(App.globalPut(vote_result,Int(0))),
)
),
Return (Btoi(vote_result)),
program = Cond(
[Txn.application_args[0] == Bytes("result"),on_result],
)
)
Operations.py(transaction): Need to “vote_result” returned by the on_result call in contract.
def proposal_result(
client: AlgodClient,
appID: int,
proposal_creator: Account,
proposal_creator_private_key:str,
) -> int:
suggestedParams = client.suggested_params()
appGlobalState = getAppGlobalState(client, appID)
appAddr = get_application_address(appID)
quotient = yes_count/total_count
percentage = quotient * 100
votePercent = int(percentage)
print ("Converted: ", type(votePercent))
txn = transaction.ApplicationCallTxn(
sender=proposal_creator,
index=appID,
on_complete=transaction.OnComplete.NoOpOC,
app_args=[b"result",votePercent],
sp=suggestedParams,
)