Пример #1
0
    def validate_inputs(self):
        """
        This method makes sure inputs are valid.

        Action icon on each QLineEdit is changed accordingly and Ok button is enabled accordingly.
        """
        states = {
            "name": self.lineEdit_Name.text() != "",
            "address": is_valid_address(self.lineEdit_Address.text())
        }

        self.lineEditAction_name.setIcon(
            self.icon_valid if states["name"] else self.icon_not_valid)

        self.lineEditAction_address.setIcon(
            self.icon_valid if states["address"] else self.icon_not_valid)

        self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(
            all(states))
Пример #2
0
def fund_transaction(address, role):
    """ Fund account with Monopoly Money """
    amount = 0
    message_text = ''
    error_text = ''
    if encoding.is_valid_address(address):
        if check_optin(address):
            if role == 'player':
                amount = 1500
                message_text = 'Your account has been funded with 1,500 Monopoly Money'

            elif role == 'banker':
                amount = 20000
                message_text = 'Your account has been funded with 20,000 Monopoly Money'

            asset_transfer(SENDER_ADDRESS, SENDER_PRIVATE_KEY, address, amount, ASSET_ID)
        else:
            error_text = "Your account not opt-in to Monopoly Money asset"
    else:
        error_text = "Enter correct Algorand address"
    return message_text, error_text
from algosdk import account, encoding

# generate an account
private_key, address = account.generate_account()
# print("Private key:", private_key)
# print("Address:", address)
address = "36DTG5ITNWLAVZBSZ6BXPWP7UTSPEOL3K4HWIEUYML7RKUCBZQP5XBR7XY"
# check if the address is valid
if encoding.is_valid_address(address):
    print("The address is valid!")
else:
    print("The address is invalid.")
Пример #4
0
    def test_transaction(self):
        # get the default wallet
        wallets = self.kcl.list_wallets()
        wallet_id = None
        for w in wallets:
            if w["name"] == wallet_name:
                wallet_id = w["id"]

        # get a new handle for the wallet
        handle = self.kcl.init_wallet_handle(wallet_id, wallet_pswd)

        # generate account and check if it's valid
        private_key_1, account_1 = account.generate_account()
        self.assertTrue(encoding.is_valid_address(account_1))

        # import generated account
        import_key = self.kcl.import_key(handle, private_key_1)
        self.assertEqual(import_key, account_1)

        # generate account with kmd
        account_2 = self.kcl.generate_key(handle, False)

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

        # create transaction
        txn = transaction.PaymentTxn(self.account_0,
                                     fee,
                                     last_round,
                                     last_round + 100,
                                     gh,
                                     account_1,
                                     100000,
                                     gen=gen)

        # sign transaction with kmd
        signed_kmd = self.kcl.sign_transaction(handle, wallet_pswd, txn)

        # get self.account_0 private key
        private_key_0 = self.kcl.export_key(handle, wallet_pswd,
                                            self.account_0)
        # sign transaction with account
        signed_account = txn.sign(private_key_0)
        txid = txn.get_txid()

        # check that signing both ways results in the same thing
        self.assertEqual(encoding.msgpack_encode(signed_account),
                         encoding.msgpack_encode(signed_kmd))

        # send the transaction
        send = self.acl.send_transaction(signed_account)
        self.assertEqual(send, txid)

        # get transaction info in pending transactions
        self.assertEqual(self.acl.pending_transaction_info(txid)["tx"], txid)

        # wait for transaction to send
        self.acl.status_after_block(last_round + 2)

        # get transaction info three different ways
        info_1 = self.acl.transactions_by_address(self.account_0, last_round)
        info_2 = self.acl.transaction_info(self.account_0, txid)
        self.assertIn("transactions", info_1)
        self.assertIn("type", info_2)

        # delete accounts
        del_1 = self.kcl.delete_key(handle, wallet_pswd, account_1)
        del_2 = self.kcl.delete_key(handle, wallet_pswd, account_2)
        self.assertTrue(del_1)
        self.assertTrue(del_2)
Пример #5
0
 def test_is_valid(self):
     valid = "MO2H6ZU47Q36GJ6GVHUKGEBEQINN7ZWVACMWZQGIYUOE3RBSRVYHV4ACJI"
     self.assertTrue(encoding.is_valid_address(valid))
     invalid = "MO2H6ZU47Q36GJ6GVHUKGEBEQINN7ZWVACMWZQGIYUOE3RBSRVYHV4ACJG"
     self.assertFalse(encoding.is_valid_address(invalid))
Пример #6
0
import params
from algosdk import account, encoding, mnemonic, algod, transaction

# create an algod client
acl = algod.AlgodClient(params.algod_token, params.algod_address)

# generate an sender account
sender_private_key, sender = account.generate_account()
# extract the mnemonic phrase from the private key
sender_mn = mnemonic.from_private_key(sender_private_key)
print("Sender Private key:", sender_private_key)
print("Sender Mnemonic:", sender_mn)
print("Sender Address:", sender)
# check if the address is valid
if encoding.is_valid_address(sender):
    print("The address is valid!" + '\n')
else:
    print("The address is invalid." + '\n')

input("Please go to: https://bank.testnet.algorand.network/ to fund your sender address." + '\n' + "Press Enter to continue..." + '\n')

# generate an receiver account
receiver_private_key, receiver = account.generate_account()
# extract the mnemonic phrase from the private key
receiver_mn = mnemonic.from_private_key(receiver_private_key)
print("Receiver Private key:", receiver_private_key)
print("Receiver Mnemonic:", receiver_mn)
print("Receiver Address:", receiver)

# check if the address is valid
if encoding.is_valid_address(receiver):
Пример #7
0
    def validate_inputs(self):
        # TODO Right now when a single widget changes all widgets get checked. Would be better to only update the state
        #  of the changed widget. We would still need to check all states to decide OK button and "suggested fee" button
        #  but at least we wouldn't have to calculate them.
        """
        This method ensures OK button and "suggested fee" button are enabled under the right conditions.

        This method checked the right subset of user inputs based on what type of transaction is taking place.
        """
        states = {
            "sender":
            self.comboBox_Sender.currentText() != ""
            and self.comboBox_Sender.currentIndex() != 0,
            "receiver":
            False,
            "close_to":
            False,
            "asset_id":
            self.lineEdit_AssetId.text() != "",
            "amount":
            self.lineEdit_Amount.text() != "",
            "fee":
            self.lineEdit_Fee.text() != ""
        }

        # This means: If the selected item is not the first AND (the item is either a valid algorand address OR
        #   is the same as the pre-compiled item)
        receiver_text = self.comboBox_Receiver.currentText()
        if (self.comboBox_Receiver.currentIndex() != 0 and
            (is_valid_address(receiver_text)
             or self.comboBox_Receiver.itemText(
                 self.comboBox_Receiver.currentIndex()) == receiver_text)):
            states["receiver"] = True

        close_to_text = self.comboBox_CloseTo.currentText()
        if (self.comboBox_CloseTo.currentIndex() != 0 and
            (is_valid_address(close_to_text) or self.comboBox_CloseTo.itemText(
                self.comboBox_CloseTo.currentIndex()) == close_to_text)):
            states["close_to"] = True

        # Here we save only the states that are compulsory for the OK button.
        if not self.checkBox_CloseTo.isChecked():
            del states["close_to"]

        if self.comboBox_Type.currentIndex() == 0:
            # Algos transaction
            del states["asset_id"]
        else:
            # Asset transaction
            if self.comboBox_AssetMode.currentIndex() == 0:
                # Transfer
                pass
            elif self.comboBox_AssetMode.currentIndex() == 1:
                # Opt-in
                del states["receiver"]
                del states["amount"]
            elif self.comboBox_AssetMode.currentIndex() == 2:
                # Close
                pass
            else:
                raise Exception(
                    f"self.comboBox_type.currentIndex() has unexpected value - {self.comboBox_Type.currentIndex()}"
                )

        ok_button_enabled = all(states.values())
        del states["fee"]
        suggested_fee_button_enabled = all(states.values())

        self.buttonBox.button(
            QtWidgets.QDialogButtonBox.Ok).setEnabled(ok_button_enabled)
        self.pushButton_SuggestedFee.setEnabled(suggested_fee_button_enabled)