Skip to content

Commit

Permalink
muck up Simulate_with_request in ATC, need to change SimulateATCResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Apr 25, 2023
1 parent 7f792ef commit 93bb4c3
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions algosdk/atomic_transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from algosdk.transaction import GenericSignedTransaction
from algosdk.abi.address_type import AddressType
from algosdk.v2client import algod
from algosdk.v2client.models import models

# The first four bytes of an ABI method call return must have this hash
ABI_RETURN_HASH = b"\x15\x1f\x7c\x75"
Expand Down Expand Up @@ -716,6 +717,9 @@ def simulate(
simulation_result = cast(
Dict[str, Any], client.simulate_raw_transactions(self.signed_txns)
)
return self.__report_simulation_response(simulation_result)

def __report_simulation_response(self, simulation_result: Dict[str, Any]):
# Only take the first group in the simulate response
txn_group: Dict[str, Any] = simulation_result["txn-groups"][0]

Expand Down Expand Up @@ -768,6 +772,41 @@ def simulate(
results=sim_results,
)

def simulate_with_request(
self,
client: algod.AlgodClient,
request: models.SimulateRequest = models.SimulateRequest(),
):
current_simulation_request = request

if (
self.status < AtomicTransactionComposerStatus.BUILT
or self.status > AtomicTransactionComposerStatus.SUBMITTED
):
raise error.AtomicTransactionComposerError(
"AtomicTransactionComposerStatus must be in range [BUILT, SUBMITTED] "
"to simulate a group"
)
elif self.status == AtomicTransactionComposerStatus.BUILT:
unsigned_txn: List[transaction.GenericSignedTransaction] = [
transaction.SignedTransaction(txn_with_signer.txn, "")
for txn_with_signer in self.txn_list
]
current_simulation_request.txn_groups = [
models.SimulateRequestTransactionGroup(txns=unsigned_txn)
]
pass
else:
current_simulation_request.txn_groups = [
models.SimulateRequestTransactionGroup(txns=self.signed_txns)
]

simulation_result = cast(
Dict[str, Any],
client.simulate_transactions(current_simulation_request),
)
return self.__report_simulation_response(simulation_result)

def execute(
self, client: algod.AlgodClient, wait_rounds: int
) -> AtomicTransactionResponse:
Expand Down

0 comments on commit 93bb4c3

Please sign in to comment.