def do(self): ''' update delegate statistics and save in DB ''' try: api.use('ark') ark_node.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) ark_node.set_delegate( address=config.DELEGATE['ADDRESS'], pubkey=config.DELEGATE['PUBKEY'], ) all_delegates = utils.api_call( api.Delegate.getDelegates)['delegates'] for delegate in all_delegates: delegate_obj = ark_delegate_manager.models.ArkDelegates.objects.get_or_create( pubkey=delegate['publicKey'])[0] delegate_obj.username = delegate['username'] delegate_obj.address = delegate['address'] delegate_obj.ark_votes = delegate['vote'] delegate_obj.producedblocks = delegate['producedblocks'] delegate_obj.missedblocks = delegate['missedblocks'] delegate_obj.productivity = delegate['productivity'] delegate_obj.rank = delegate['rate'] delegate_obj.voters = len( ark_node.Delegate.voters(delegate['address'])) + 1 delegate_obj.save() except Exception: logger.exception('Error during UpdateDelegates')
def networkUse(network): hidePanels() api.use(network) wdg.AddressPanel.candidates = api.Delegate.getCandidates() if cfg.__NET__ not in Glob.history: Glob.history[cfg.__NET__] = {} Glob.addresspanel.wallet.set("") Glob.addresspanel.combo["values"] = tuple( getHistoryList("addresspanel.wallet"))
def do(self): ''' update the currenct blockchain height and save it in DB ''' try: ark_node.set_connection(host=config.CONNECTION['HOST'], database=config.CONNECTION['DATABASE'], user=config.CONNECTION['USER'], password=config.CONNECTION['PASSWORD']) api.use('ark') blockchain_height = ark_node.Blockchain.height() node = Node.objects.get_or_create(id='main')[0] node.blockchain_height = blockchain_height node.save() except Exception: logger.exception('failed to update blockchain height')
def send_delegate_share(amount): api.use(network='ark') tx = core.Transaction( amount=amount, recipientId=config.DELEGATE['REWARDWALLET']) if config.DELEGATE['SECOND_SECRET']: tx.sign(secret=config.DELEGATE['SECRET'], secondSecret=config.DELEGATE['SECOND_SECRET']) else: tx.sign(secret=config.DELEGATE['SECRET']) tx.serialize() res = api.sendTx( tx=tx, url_base=config.IP, secret=config.DELEGATE['SECRET'], secondSecret=config.DELEGATE['SECOND_SECRET']) return res
def transmit_payments(payouts): api.use(network='ark') for ark_address in payouts: tx = core.Transaction( amount=payouts[ark_address], recipientId=ark_address, vendorField=config.SENDER_SETTINGS['PERSONAL_MESSAGE']) if config.DELEGATE['SECOND_SECRET']: tx.sign(secret=config.DELEGATE['SECRET'], secondSecret=config.DELEGATE['SECOND_SECRET']) else: tx.sign(secret=config.DELEGATE['SECRET']) tx.serialize() res = api.sendTx(tx=tx, url_base=config.IP, secret=config.DELEGATE['SECRET'], secondSecret=config.DELEGATE['SECOND_SECRET']) if not res['success']: logger.warning('{}'.format(res))
# -*- encoding -*- from arky import api, wallet, __PY3__ import os, json, datetime api.use("ark") # screen command line from optparse import OptionParser parser = OptionParser() parser.set_usage("usage: %prog [JSON] [options]") parser.add_option("-s", "--secret", dest="secret", help="wallet secret you want to use") parser.add_option("-w", "--wallet", dest="wallet", help="wallet file you want to use") (options, args) = parser.parse_args() if len(args) == 1 and os.path.exists(args[0]): in_ = open(args[0]) content = in_.read() in_.close() conf = json.loads( content.decode() if isinstance(content, bytes) else content) wlt = wallet.Wallet(conf["forging"]["secret"][0]) elif options.secret: wlt = wallet.Wallet(options.secret) elif options.wallet: wlt = wallet.open(options.wallet) else:
from arky import api, core import arkdbtools.config as constants from requests.exceptions import ReadTimeout from urllib3.exceptions import ReadTimeoutError secret = '' def send_tx(address, amount, vendor_field=''): try: tx = core.Transaction(amount=amount, recipientId=address, vendorField=vendor_field) tx.sign(secret) tx.serialize() result = api.sendTx(tx=tx, url_base='http://146.185.144.47:4001') except ReadTimeoutError: # we'll make a single retry in case of a ReadTimeOutError. We are sending the exact same TX hash to make # sure no double payouts occur result = api.sendTx(tx=tx, url_base='http://146.185.144.47:4001') if result['success']: return True return False api.use('ark') send_tx(address='AJ8nGFj9CVq3i4hb2CnxBoy41bUDhShJwr', amount=constants.ARK)
from arky import api from arky import core import json api.use("rchain") def num_threads(): return api.get("/api/transactions").count def all_threads(): """ Returns every thread in the ledger. """ roots = [] seen = {} trans = api.get("/api/transactions") if not trans.success: print(trans) return None for post_transaction in reversed(trans.transactions): if 'vendorField' not in post_transaction: continue post = json.loads(post_transaction['vendorField']) post['kids'] = [] post['voters'] = dict() if len(seen) == 0: roots.append(post) seen[post['id']] = post elif post['id'] in seen: if post_transaction['senderId'] not in seen[post['id']]['voters'] or\ post['votes'] != seen[post['id']]['voters'][post_transaction['senderId']]: