Exemplo n.º 1
0
    def balance(self) -> float:
        """
        Returns the balance of the wallet

        Returns:
            balance: the balance of the wallet as a float, in Algos
        """
        account_info = algod.account_info(self.public_key)
        balance = float(microalgos_to_algos(account_info["amount"]))
        return balance
Exemplo n.º 2
0
def reset_balances(user1, user2):
    fee = float(microalgos_to_algos(algod.suggested_params().min_fee))

    to_transfer = user2.wallet.balance - 0.1 - fee

    if to_transfer > 0:
        transaction = user2.send(user1, to_transfer, "", None)
        return transaction
    else:
        return None
Exemplo n.º 3
0
    def validate(self) -> bool:
        """
        Check that the transaction is valid, otherwise raise
        a custom error indicating the issue.
        """
        self.params = algod.suggested_params()
        self.fee = float(microalgos_to_algos(self.params.min_fee))

        if self.amount < 1e-6:
            raise ZeroTransactionError

        if (self.amount + self.fee + 0.1) > self.sender.wallet.balance:
            raise InsufficientFundsError(self.amount,
                                         self.sender.wallet.balance)

        if self.receiver.wallet.balance == 0 and self.amount < 0.1:
            raise FirstTransactionError(self.amount)
Exemplo n.º 4
0
    def validate(self) -> bool:
        """
        Chech that the transaction is valid, otherwise raise an error
        that indicates the type of issue
        """
        self.params = algod.suggested_params()
        self.fee = float(microalgos_to_algos(self.params.min_fee))

        self.amount = self.sender.wallet.balance if self.amount == "all" else float(self.amount)
        self.close_account = (self.amount == self.sender.wallet.balance)

        if self.close_account:
            self.amount = self.amount - self.fee

        if self.amount < 1e-6:
            raise ZeroTransactionError

        if (self.amount + self.fee + (int(not self.close_account)*0.1)) > self.sender.wallet.balance:
            raise InsufficientFundsError(self.amount, self.sender.wallet.balance)

        if Wallet("", self.destination).balance == 0 and self.amount < 0.1:
            raise FirstTransactionError(self.amount)
Exemplo n.º 5
0
def convert_algos(context, microalgos):
    context.microalgos = util.algos_to_microalgos(
        util.microalgos_to_algos(int(microalgos)))