def transfer_ipi(asset_id, to_account, account, private_key, opt_in=False) : # how do I pass territory string

    # get suggested parameters
    params = acl.suggested_params()
    gen = params["genesisID"]
    gh = params["genesishashb64"]
    last_round = params["lastRound"]
    fee = params["fee"]

    # create transaction2
    # Configure fields for creating the asset.
    # send 10 
    data = {
        "sender": account,
        "fee": fee,
        "first": last_round,
        "last": last_round+100,
        "gh": gh,
        "receiver": to_account,
        "amt": 1 if opt_in==False else 0,
        "index": asset_id,
        "flat_fee": True
    }
    print("Asset Transfer")
    txn = transaction.AssetTransferTxn(**data)
    stxn = txn.sign(private_key)
    txid = acl.send_transaction(stxn, headers={'content-type': 'application/x-binary'})
    print(txid)

    # wait for confirmation
    txinfo = wait_for_confirmation( acl, txid) 
Example #2
0
def unsigned_asset_send(algod_client, sender, receiver, asset_id, asa_amount,
                        validity_range=1000):
    """HELP unsigned_asset_send:
        (AlgodClient, dict, str, int, int, int) - Returns an unsigned
        AssetTransferTxn.
    """
    assert type(asa_amount) == int and validity_range <= 1000
    # Get network suggested params for transactions.
    params = algod_client.suggested_params()
    first_valid = params.first
    last_valid = first_valid + validity_range
    gh = params.gh
    min_fee = params.min_fee
    assert min_fee <= 1000
    data = {
        "sender": sender,
        "fee": min_fee,
        "first": first_valid,
        "last": last_valid,
        "gh": gh,
        "receiver": receiver,
        "amt": asa_amount,
        "index": asset_id,
        "flat_fee": True,
        }
    return transaction.AssetTransferTxn(**data)
Example #3
0
def revoke_txn(context, amount):
    params = context.acl.suggested_params()
    context.txn = transaction.AssetTransferTxn(context.pk,
                                               params,
                                               context.pk,
                                               int(amount),
                                               context.asset_index,
                                               revocation_target=context.rcv)
Example #4
0
def dispense(update, context):
    """
    Transfer a custom asset from default account A to account B (Any)
    :param update: Default telegram argument
    :param context: Same as update
    :return:
    """
    time.sleep(5)
    global dispensed
    global mn
    global test_dispenser

    update.message.reply_text('Sending you some test token....')
    to = context.user_data['address']
    params = client.suggested_params()
    params.flat_fee = True
    note = "Thank you for helping in testing this program".encode('utf-8')
    # optin(update, context)
    time.sleep(4)
    # try:
    trxn = transaction.AssetTransferTxn(test_dispenser,
                                        params.fee,
                                        params.first,
                                        params.last,
                                        params.gh,
                                        to,
                                        amt=200,
                                        index=13251912,
                                        close_assets_to=None,
                                        note=note,
                                        gen=params.gen,
                                        flat_fee=params.flat_fee,
                                        lease=None,
                                        rekey_to=None)

    # Sign the transaction
    k = mnemonic.to_private_key(mn)
    signed_txn = trxn.sign(k)

    # Submit transaction to the network
    tx_id = client.send_transaction(signed_txn)
    wait_for_confirmation(update, context, client, tx_id)
    update.message.reply_text(
        "Yummy! I just sent you 200 DMT2...\nCheck the explorer for txn info.\n"
        ""
        'Hash: '
        f'{tx_id}'
        'Explorer: '
        'https://algoexplorer.io')
    dispensed = dispensed + (to, )
    logging.info(
        "...##Asset Transfer... \nReceiving account: {}.\nOperation: {}.\nTxn Hash: {}"
        .format(to, dispense.__name__, tx_id))

    update.message.reply_text(
        "Successful! \nTransaction hash: {}".format(tx_id))
    context.user_data.clear()
Example #5
0
def group_transactions():

    # recover a account
    passphrase1 = os.getenv("MNEMONIC1")
    pk_account_a = mnemonic.to_private_key(passphrase1)
    account_a = account.address_from_private_key(pk_account_a)

    # recover b account
    account_b = "4O6BRAPVLX5ID23AZWV33TICD35TI6JWOHXVLPGO4VRJATO6MZZQRKC7RI"

    # connect to node
    acl = connect_to_network()

    # get suggested parameters
    params = acl.suggested_params()
    gen = params["genesisID"]
    gh = params["genesishashb64"]
    last_round = params["lastRound"]
    fee = params["fee"]
    asset_index = 14035004

    # create transaction1
    txn1 = transaction.PaymentTxn(account_a, fee, last_round, last_round + 100,
                                  gh, account_b, 42000000)

    # create transaction2
    txn2 = transaction.AssetTransferTxn(account_b, fee, last_round,
                                        last_round + 100, gh, account_a, 1,
                                        asset_index)

    # get group id and assign it to transactions
    gid = transaction.calculate_group_id([txn1, txn2])
    txn1.group = gid
    txn2.group = gid

    # sign transaction1
    stxn1 = txn1.sign(pk_account_a)

    # sign transaction2
    with open("buildweb3/step5.lsig", "rb") as f:
        lsig = encoding.future_msgpack_decode(base64.b64encode(f.read()))
    stxn2 = transaction.LogicSigTransaction(txn2, lsig)

    signedGroup = []
    signedGroup.append(stxn1)
    signedGroup.append(stxn2)

    # send them over network
    sent = acl.send_transactions(signedGroup)
    # print txid
    print(sent)

    # wait for confirmation
    wait_for_confirmation(acl, sent)
Example #6
0
def group_transactions():

    # recover a account
    passphrase1 = os.getenv("MNEMONIC1")
    pk_account_a = mnemonic.to_private_key(passphrase1)
    account_a = account.address_from_private_key(pk_account_a)

    # recover b account
    passphrase2 = os.getenv("MNEMONIC2")
    pk_account_b = mnemonic.to_private_key(passphrase2)
    account_b = account.address_from_private_key(pk_account_b)

    # connect to node
    acl = connect_to_network()

    # get suggested parameters
    params = acl.suggested_params()
    gen = params["genesisID"]
    gh = params["genesishashb64"]
    last_round = params["lastRound"]
    fee = params["fee"]
    asset_index = 14065375

    # create transaction1
    txn1 = transaction.PaymentTxn(account_b, fee, last_round, last_round + 100,
                                  gh, account_a, 12000000)

    # create transaction2
    txn2 = transaction.AssetTransferTxn(account_a, fee, last_round,
                                        last_round + 100, gh, account_b, 1,
                                        asset_index)

    # get group id and assign it to transactions
    gid = transaction.calculate_group_id([txn1, txn2])
    txn1.group = gid
    txn2.group = gid

    # sign transaction1
    stxn1 = txn1.sign(pk_account_b)

    # sign transaction2
    stxn2 = txn2.sign(pk_account_a)

    signedGroup = []
    signedGroup.append(stxn1)
    signedGroup.append(stxn2)

    # send them over network
    sent = acl.send_transactions(signedGroup)
    # print txid
    print(sent)

    # wait for confirmation
    wait_for_confirmation(acl, sent)
Example #7
0
def certifacateDeletionDemo(hash):
    algod_address = "https://testnet-algorand.api.purestake.io/ps1"
    algod_token = ""
    headers = {
        "X-API-Key": "5K5TIs5wJtaqBNHNfOyya2mxDj9mQBEkYAqWgu09",
    }

    algod_client = algod.AlgodClient(algod_token, algod_address, headers)
    status = algod_client.status()
    print(json.dumps(status, indent=4))

    passphrase = "thunder fun scout myself talk repeat hurry miracle puppy run vocal vicious shove fever idea lens above diesel action pulp before cigar horror above mass"

    private_key = mnemonic.to_private_key(passphrase)
    my_address = mnemonic.to_public_key(passphrase)
    print("My address: {}".format(my_address))

    account_info = algod_client.account_info(my_address)
    print("Account balance: {} microAlgos".format(account_info.get('amount')))

    c = Certificate("tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp",
                    "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp")

    params = algod_client.suggested_params()
    first = params.get("lastRound")
    last = first + 1000
    gen = params.get("genesisID")
    gh = params.get("genesishashb64")
    min_fee = params.get("minFee")

    data = {
        "sender": my_address,
        "fee": min_fee,
        "first": first,
        "last": last,
        "gh": gh,
        "total": 1000,
        "decimals": 0,
        "default_frozen": False,
        "unit_name": "aa",
        "asset_name": "bb",
        "metadata_hash": hash,
        "manager": my_address,
        "reserve": my_address,
        "freeze": my_address,
        "clawback": my_address,
        "url": "https://path/to/my/asset/details",
        "flat_fee": True
    }

    txn = transaction.AssetConfigTxn(**data)

    stxn = txn.sign(private_key)

    print("Asset Creation")

    txid = algod_client.send_transaction(
        stxn, headers={'content-type': 'application/x-binary'})

    txinfo = wait_for_confirmation(algod_client, txid)
    print(txinfo.keys())
    print(txinfo)
    asset_id = txinfo["txresults"]["createdasset"]
    account_info = algod_client.account_info(my_address)

    account_info = algod_client.account_info(my_address)
    holding = None
    if 'assets' in account_info:
        holding = account_info['assets'].get(str(asset_id))

    if not holding:
        data = {
            "sender": my_address,
            "fee": min_fee,
            "first": first,
            "last": last,
            "gh": gh,
            "receiver": my_address,
            "amt": 0,
            "index": asset_id,
            "flat_fee": True
        }
        print("Asset Option In")

        txn = transaction.AssetTransferTxn(**data)
        stxn = txn.sign(private_key)
        txid = algod_client.send_transaction(
            stxn, headers={'content-type': 'application/x-binary'})
        print(txid)

        wait_for_confirmation(txid)

        account_info = algod_client.account_info(my_address)
        print(json.dumps(account_info['assets'][str(asset_id)], indent=4))

    data = {
        "sender": my_address,
        "fee": min_fee,
        "first": first,
        "last": last,
        "gh": gh,
        "receiver": my_address,
        "amt": 10,
        "index": asset_id,
        "flat_fee": True
    }
    print("Asset Transfer")
    txn = transaction.AssetTransferTxn(**data)
    stxn = txn.sign(private_key)
    txid = algod_client.send_transaction(
        stxn, headers={'content-type': 'application/x-binary'})
    print(txid)
    wait_for_confirmation(algod_client, txid)
    account_info = algod_client.account_info(my_address)
    print(json.dumps(account_info['assets'][str(asset_id)], indent=4))

    # Revoking an Asset
    data = {
        "sender": my_address,
        "fee": min_fee,
        "first": first,
        "last": last,
        "gh": gh,
        "receiver": my_address,
        "amt": 10,
        "index": asset_id,
        "revocation_target": my_address,
        "flat_fee": True
    }
    print("Asset Revoke")
    txn = transaction.AssetTransferTxn(**data)
    stxn = txn.sign(private_key)
    txid = algod_client.send_transaction(
        stxn, headers={'content-type': 'application/x-binary'})
    print(txid)
    wait_for_confirmation(algod_client, txid)
    account_info = algod_client.account_info(my_address)
    print(json.dumps(account_info['assets'][str(asset_id)], indent=4))
    account_info = algod_client.account_info(my_address)
    print(json.dumps(account_info['assets'][str(asset_id)], indent=4))
Example #8
0
if not holding:
    # Get latest network parameters
    data = {
        "sender": accounts[3]['pk'],
        "fee": min_fee,
        "first": first,
        "last": last,
        "gh": gh,
        "receiver": accounts[3]["pk"],
        "amt": 0,
        "index": asset_id,
        "flat_fee": True
    }

    # Use the AssetTransferTxn class to transfer assets
    txn = transaction.AssetTransferTxn(**data)
    stxn = txn.sign(accounts[3]['sk'])
    txid = algod_client.send_transaction(stxn)
    print(txid)
    # Wait for the transaction to be confirmed
    wait_for_tx_confirmation(txid)
    # Now check the asset holding for that account.
    # This should now show a holding with a balance of 0.
    account_info = algod_client.account_info(accounts[3]['pk'])
    print(json.dumps(account_info['assets'][str(asset_id)], indent=4))

# terminal output should look similar to this...

# 4ZSLST43HZZQNTF7Y2ZM5ENWLHOTS3XCZX574YEPDUI3PFUSODKQ
# {
#     "creator": "THQHGD4HEESOPSJJYYF34MWKOI57HXBX4XR63EPBKCWPOJG5KUPDJ7QJCM",
Example #9
0
    def get_transaction(self, sp: SuggestedParams) -> transaction.Transaction:
        """
        This method returns the transaction the user set up.

        Because this method is used to build a transaction but also to calculate suggested fee we allow an incorrect
        fee parameter in the GUI.
        """
        # TODO we should subclass QComboBox to encapsulate the method that returns the contained algorand address so to
        #  avoid code duplication of the "[-58:]" bit.
        # Here we fill in the fields that are compulsory across the different types of transactions.
        data = {
            "sender":
            self.comboBox_Sender.currentText()[-58:],
            "receiver":
            self.comboBox_Receiver.currentText()[-58:],
            "fee":
            self.get_microalgos_fee()
            if self.lineEdit_Fee.text() != "" else sp.min_fee,
            "flat_fee":
            True,
            "first":
            sp.first,
            "last":
            sp.last,
            "gh":
            sp.gh,
            "note":
            self.textEdit_Note.toPlainText().encode()
        }

        # If the algosdk.transaction raises an error it will be simply propagated and dealt with outside of this
        #  function.
        if self.comboBox_Type.currentIndex() == 0:
            # Algos
            data["amt"] = self.get_microalgos_amount()
            if self.checkBox_CloseTo.isChecked():
                data["close_remainder_to"] = self.comboBox_CloseTo.currentText(
                )[-58:]

            temp_txn = transaction.PaymentTxn(**data)
        elif self.comboBox_Type.currentIndex() == 1:
            # ASA
            if self.checkBox_CloseTo.isChecked():
                data["close_assets_to"] = self.comboBox_CloseTo.currentText(
                )[-58:]
            data["index"] = int(self.lineEdit_AssetId.text())
            if self.comboBox_AssetMode.currentIndex() == 0:
                # Transfer
                data["amt"] = int(self.lineEdit_Amount.text())
            elif self.comboBox_AssetMode.currentIndex() == 1:
                # Opt-in
                data["receiver"] = data["sender"]
                data["amt"] = 0
            elif self.comboBox_AssetMode.currentIndex() == 2:
                # Close
                data["amt"] = int(self.lineEdit_Amount.text())

            temp_txn = transaction.AssetTransferTxn(**data)
        else:
            raise Exception(
                f"self.comboBox_type.currentIndex() has unexpected value: {self.comboBox_Type.currentIndex()}"
            )

        return temp_txn
Example #10
0
def transfer_assets(context, amount):
    params = context.acl.suggested_params()
    context.txn = transaction.AssetTransferTxn(context.rcv, params, context.pk,
                                               int(amount),
                                               context.asset_index)
Example #11
0
def accept_asset_txn(context):
    params = context.acl.suggested_params()
    context.txn = transaction.AssetTransferTxn(context.rcv, params,
                                               context.rcv, 0,
                                               context.asset_index)
Example #12
0
    def createCertificate(self,hash,asset_name, asset_url, amount, receive_address):
        c = Certificate("tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp", "tmp",
                        "tmp", "tmp", "tmp")

        params = self.algod_client.suggested_params()
        # pprint(params.__dict__)
        first = params.first
        last = params.last
        gen = params.gen
        gh = params.gh
        min_fee = params.min_fee

        data = {
            "sender": self.my_address,
            "fee": min_fee,
            "first": first,
            "last": last,
            "gh": gh,
            "total": amount,
            "decimals": 0,
            "default_frozen": False,
            "unit_name": asset_name,
            "asset_name": asset_name,
            "metadata_hash": bytearray(hash.digest()),
            "manager": self.my_address,
            "reserve": self.my_address,
            "freeze": self.my_address,
            "clawback": self.my_address,
            "url": asset_url,
            "flat_fee": True
        }

        txn = transaction.AssetConfigTxn(**data)


        stxn = txn.sign(self.private_key)

        print("Asset Creation")

        txid = self.algod_client.send_transaction(stxn)

        txinfo = Algorand.wait_for_confirmation(self.algod_client, txid)
        #print(txinfo.keys())
        pprint(("txinfo", txinfo))
        # asset_id = txinfo.txn.
        # account_info = self.algod_client.account_info(self.my_address)
        # pprint(account_info)
        print("The hash of certificate is: {}".format(hash.hexdigest()))
        
        print("Certificate recreated")

        # this is not yet working, not being called in the working version
        if receive_address:
            index = txn.index
            params = self.algod_client.suggested_params()
            # pprint(params.__dict__)
            first = params.first
            last = params.last
            gen = params.gen
            gh = params.gh
            min_fee = params.min_fee

            data = {
                "sender": self.my_address,
                "fee": min_fee,
                "first": first,
                "last": last,
                "gh": gh,
                "receiver": receive_address,
                "amt": amount,
                "index": index,
                "flat_fee": True
            }
            ttxn = transaction.AssetTransferTxn(**data)
            sttxn = ttxn.sign(self.private_key)

            print("Asset Transfer")

            ttxid = self.algod_client.send_transaction(sttxn)

            ttxinfo = Algorand.wait_for_confirmation(self.algod_client, ttxid)
            pprint(("ttxinfo", ttxinfo))
        return  txinfo['asset-index']