def load_blocks(): coda_client = Client() query = ''' { blocks { nodes { creator transactions { userCommands { from to } } protocolState { blockchainState { date } } snarkJobs { prover fee workIds } } } } ''' response = coda_client._send_query(query) return response["data"]["blocks"]["nodes"]
def __init__(self, client_args, public_key, privkey_pass, min_tx_amount=AGENT_MIN_TX, max_tx_amount=AGENT_MAX_TX, min_fee_amount=AGENT_MIN_FEE, max_fee_amount=AGENT_MAX_FEE): self.coda = Client(**client_args) self.public_key = public_key self.privkey_pass = privkey_pass self.min_tx_amount = min_tx_amount self.max_tx_amount = max_tx_amount self.min_fee_amount = min_fee_amount self.max_fee_amount = max_fee_amount self.to_account = None
logger = logging.getLogger(__name__) c = yaml.load(open('config.yml', encoding='utf8'), Loader=yaml.SafeLoader) print("version 1.2.4") WORKER_PUB_KEY = str(c["WORKER_PUB_KEY"]) WORKER_FEE = float(c["WORKER_FEE"]) CHECK_PERIOD_SEC = int(c["CHECK_PERIOD_SEC"]) STOP_WORKER_FOR_MIN = int(c["STOP_WORKER_FOR_MIN"]) STOP_WORKER_BEFORE_MIN = int(c["STOP_WORKER_BEFORE_MIN"]) GRAPHQL_HOST = str(c["GRAPHQL_HOST"]) GRAPHQL_PORT = int(c["GRAPHQL_PORT"]) # MINA --> nanomina WORKER_FEE = int(WORKER_FEE * 1e9) try: coda = Client(graphql_host=GRAPHQL_HOST, graphql_port=GRAPHQL_PORT) WORKER_PUB_KEY = parse_worker_pubkey() except: logger.fatal( f'😿 Can\'t connect to graphql {GRAPHQL_HOST}:{GRAPHQL_PORT}.\n' f'Check troubleshooting manual - https://github.com/c29r3/mina-snark-stopper#troubleshooting' ) exit(1) print(f'Worker public key: {WORKER_PUB_KEY}\n' f'Worker fee: {WORKER_FEE}\n' f'Check period(sec): {CHECK_PERIOD_SEC}\n' f'Stop before(min): {STOP_WORKER_BEFORE_MIN}\n') while True:
def test_send_payment(self, mock_post, snapshot): mock_post.return_value = self._mock_response(json_data={"data": "foo"}) client = Client() client.send_payment("to_pk", "from_pk", "amount", "fee", "memo") snapshot.assert_match(mock_post.call_args_list)
def test_create_wallet_no_args(self, mock_post, snapshot): mock_post.return_value = self._mock_response(json_data={"data": "foo"}) client = Client() client.create_wallet() snapshot.assert_match(mock_post.call_args_list)
def test_set_current_snark_worker(self, mock_post, snapshot): mock_post.return_value = self._mock_response(json_data={"data": "foo"}) client = Client() client.set_current_snark_worker("pk", "fee") snapshot.assert_match(mock_post.call_args_list)
def test_get_sync_status(self, mock_post, snapshot): mock_post.return_value = self._mock_response(json_data={"data": "foo"}) client = Client() client.get_sync_status() snapshot.assert_match(mock_post.call_args_list)
class Agent(object): """Represents a generic agent that operates on the coda blockchain""" def __init__(self, client_args, public_key, privkey_pass, max_tx_amount=AGENT_MAX_TX, max_fee_amount=AGENT_MAX_FEE): self.coda = Client(**client_args) self.public_key = public_key self.privkey_pass = privkey_pass self.max_fee_amount = max_fee_amount self.max_tx_amount = max_tx_amount self.to_account = None def get_to_account(self): if not self.to_account: print("Getting new wallet to send to...") response = self.coda.create_wallet(self.privkey_pass) self.to_account = response["createAccount"]["publicKey"] print("Public Key: {}".format(self.to_account)) return self.to_account def unlock_wallet(self): response = self.coda.unlock_wallet(self.public_key, self.privkey_pass) print("Unlocked Wallet!") return response 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 = random.randint(1, self.max_tx_amount) fee_amount = random.randint(1, 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) 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
# Configure Logging logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='|%(asctime)s| %(message)s') logger = logging.getLogger(__name__) c = yaml.load(open('config.yml', encoding='utf8'), Loader=yaml.SafeLoader) logger.info("version 1.1") WORKER_PUB_KEY = c["WORKER_PUB_KEY"] WORKER_FEE = c["WORKER_FEE"] CHECK_PERIOD_SEC = c["CHECK_PERIOD_SEC"] STOP_WORKER_FOR_MIN = c["STOP_WORKER_FOR_MIN"] STOP_WORKER_BEFORE_MIN = c["STOP_WORKER_BEFORE_MIN"] GRAPHQL_HOST = c["GRAPHQL_HOST"] GRAPHQL_PORT = c["GRAPHQL_PORT"] coda = Client(graphql_host=GRAPHQL_HOST, graphql_port=GRAPHQL_PORT) daemon_status = coda.get_daemon_status() if type(WORKER_PUB_KEY) is not str or len(WORKER_PUB_KEY) != 55: try: WORKER_PUB_KEY = daemon_status["daemonStatus"]["snarkWorker"] BLOCK_PROD_KEY = daemon_status["daemonStatus"]["blockProductionKeys"][ 0] if WORKER_PUB_KEY is None: logger.info( f'Worker public key is None\n' f'Automatically apply Block production key to {WORKER_PUB_KEY}' ) WORKER_PUB_KEY = BLOCK_PROD_KEY