def write_dryrun(signed_txn, name, app_id, addrs): path = os.path.dirname(os.path.abspath(__file__)) # Read in approval teal source app_src = open(os.path.join(path, 'approval.teal')).read() # Add source sources = [ DryrunSource(app_index=app_id, field_name="approv", source=app_src), ] # Get account info accounts = [client.account_info(a) for a in addrs] # Get app info app = client.application_info(app_id) # Create request drr = DryrunRequest(txns=signed_txn, sources=sources, apps=[app], accounts=accounts) file_path = os.path.join(path, "{}.msgp".format(name)) data = encoding.msgpack_encode(drr) with open(file_path, "wb") as f: f.write(base64.b64decode(data)) print("Created Dryrun file at {}".format(file_path)) path = os.path.dirname(os.path.abspath(__file__)) # Read in approval teal source app_src = open(os.path.join(path, 'approval.teal')).read() # Add source sources = [ DryrunSource(app_index=app_id, field_name="approv", source=app_src), ] # Get account info accounts = [client.account_info(a) for a in addrs] # Get app info app = client.application_info(app_id) # Create request drr = DryrunRequest(txns=signed_txn, sources=sources, apps=[app], accounts=accounts) file_path = os.path.join(path, "{}.msgp".format(name)) data = encoding.msgpack_encode(drr) with open(file_path, "wb") as f: f.write(base64.b64decode(data)) print("Created Dryrun file at {}".format(file_path))
def dryrun_debug(lstx, mysource): sources = [] if (mysource != None): # source sources = [DryrunSource(field_name="lsig", source=mysource, txn_index=0)] drr = DryrunRequest(txns=[lstx], sources=sources) dryrun_response = algod_client.dryrun(drr) return dryrun_response
def dryrun_request_from_txn(self, txns, app): """ Helper function for creation DryrunRequest and making the REST request Args: txns (list): list of transaction to run as a group app (dict, App): app program additional parameters. Only app.round and app.accounts are used. Returns: dict: dryrun response object Raises: TypeError: program is not bytes or str """ if app is not None: if not isinstance(app, App) and not isinstance(app, dict): raise ValueError("app must be a dict or App") if isinstance(app, dict): app = App(**app) rnd = None accounts = None apps = [] if app is not None: if app.round is not None: rnd = app.round if app.accounts is not None: accounts = app.accounts for acc in accounts: if acc.created_apps: apps.extend(acc.created_apps) drr = DryrunRequest( txns=txns, accounts=accounts, round=rnd, apps=apps, ) return self.algo_client.dryrun(drr)
def build_dryrun_request(cls, program, lsig=None, app=None, sender=ZERO_ADDRESS): """ Helper function for creation DryrunRequest object from a program. By default it uses logic sig mode and if app_idx / on_complete are set then application call is made Args: program (bytes, string): program to use as a source lsig (dict, LSig): logic sig program additional parameters app (dict, App): app program additional parameters Returns: DryrunRequest: dryrun request object Raises: TypeError: program is not bytes or str ValueError: both lsig and app parameters provided or unknown type """ if lsig is not None and app is not None: raise ValueError("both lsig and app not supported") # validate input and determine run mode if app is not None: if not isinstance(app, App) and not isinstance(app, dict): raise ValueError("app must be a dict or App") if isinstance(app, dict): app = App(**app) if app.app_idx is None: app.app_idx = 0 run_mode = "approv" if app.on_complete is None: app.on_complete = transaction.OnComplete.NoOpOC elif app.on_complete == transaction.OnComplete.ClearStateOC: run_mode = "clearp" if app.accounts is not None: accounts = [] for acc in app.accounts: if isinstance(acc, str): accounts.append(Account( address=acc, )) else: accounts.append(acc) app.accounts = accounts txn = cls.sample_txn(sender, appcall_txn) else: if lsig is not None: if not isinstance(lsig, LSig) and not isinstance(lsig, dict): raise ValueError("lsig must be a dict or LSig") if isinstance(lsig, dict): lsig = LSig(**lsig) else: lsig = LSig() run_mode = "lsig" txn = cls.sample_txn(sender, payment_txn) sources = [] apps = [] accounts = [] rnd = None if isinstance(program, bytes): if run_mode != "lsig": txns = [cls._build_appcall_signed_txn(txn, app)] application = cls.sample_app(sender, app, program) apps = [application] accounts = app.accounts rnd = app.round else: txns = [cls._build_logicsig_txn(program, txn, lsig)] elif isinstance(program, str): source = DryrunSource(field_name=run_mode, source=program, txn_index=0) if run_mode != "lsig": txns = [cls._build_appcall_signed_txn(txn, app)] application = cls.sample_app(sender, app) apps = [application] accounts = app.accounts # app idx must match in sources and in apps arrays so dryrun find apps sources source.app_index = application.id rnd = app.round else: txns = [cls._build_logicsig_txn(program, txn, lsig)] sources = [source] else: raise TypeError("program must be bytes or str") return DryrunRequest( txns=txns, sources=sources, apps=apps, accounts=accounts, round=rnd, )