def test_random():
    assert (Currency.random(Currency(5),
                            Currency(5)).nanocodas() == 5 * precision)
    for _ in range(25):
        rand = Currency.random(Currency(3, format=CurrencyFormat.NANO),
                               Currency(5, format=CurrencyFormat.NANO))
        assert (3 <= rand.nanocodas() and rand.nanocodas() <= 5)
Exemple #2
0
    def send_transaction(self):
        print("---Sending Transaction---")
        try: 
            to_account = self.get_to_account()
            print("Trying to unlock Wallet!")
            self.unlock_wallet()
        except ConnectionError:
            print("Transaction Failed due to connection error... is the Daemon running?")
            TRANSACTION_ERRORS.inc()
            return None
        except Exception as e: 
            print("Error unlocking wallet...")
            print(e)
            return None

        tx_amount = Currency.random(self.min_tx_amount, self.max_tx_amount)
        fee_amount = Currency.random(self.min_fee_amount, self.max_fee_amount)
        try: 
            response = self.coda.send_payment(to_account, self.public_key, tx_amount, fee_amount, memo="BeepBoop")
        except Exception as e: 
            print("Error sending transaction...", e)
            TRANSACTION_ERRORS.inc()
            return None
        if not response.get("errors", None):
            print("Sent a Transaction {}".format(response))
            TRANSACTIONS_SENT.inc()
        else: 
            print("Error sending transaction: Request: {} Response: {}".format(self.public_key, response))
            TRANSACTION_ERRORS.inc()
        return response
Exemple #3
0
def getenv_currency(env_var: str, lower_bound: Currency, upper_bound: Currency) -> Currency:
    return getenv_default_map(env_var, Currency, Currency.random(lower_bound, upper_bound))
from CodaClient import Client, Currency, CurrencyFormat
import os
import schedule
import time
import urllib3
import random
from requests.exceptions import ConnectionError
from prometheus_client import Counter, start_http_server

CODA_PUBLIC_KEY = os.getenv(
    "CODA_PUBLIC_KEY",
    "4vsRCVyVkSRs89neWnKPrnz4FRPmXXrWtbsAQ31hUTSi41EkbptYaLkzmxezQEGCgZnjqY2pQ6mdeCytu7LrYMGx9NiUNNJh8XfJYbzprhhJmm1ZjVbW9ZLRvhWBXRqes6znuF7fWbECrCpQ"
).strip()
CODA_PRIVKEY_PASS = os.getenv("CODA_PRIVKEY_PASS", "naughty blue worm")
AGENT_MIN_FEE = os.getenv("AGENT_MIN_FEE") or Currency.random(
    Currency("0.06"), Currency("0.1"))
AGENT_MAX_FEE = os.getenv("AGENT_MAX_FEE") or Currency.random(
    AGENT_MIN_FEE, AGENT_MIN_FEE + Currency("0.2"))
AGENT_MIN_TX = os.getenv("AGENT_MIN_TX") or Currency.random(
    Currency("0.0015"), Currency("0.005"))
AGENT_MAX_TX = os.getenv("AGENT_MAX_TX") or Currency.random(
    AGENT_MIN_TX, AGENT_MIN_TX + Currency("0.01"))
AGENT_SEND_EVERY_MINS = os.getenv("AGENT_SEND_EVERY_MINS",
                                  random.randint(1, 5))
AGENT_METRICS_PORT = os.getenv("AGENT_METRICS_PORT", 8000)

CODA_CLIENT_ARGS = {
    "graphql_host": os.getenv("CODA_HOST", "localhost"),
    "graphql_port": os.getenv("CODA_PORT", "3085")
}