Skip to content

Instantly share code, notes, and snippets.

@littlekfc
Created June 27, 2018 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save littlekfc/425ba75d83a73682f2f5ac0e5ecdadcb to your computer and use it in GitHub Desktop.
Save littlekfc/425ba75d83a73682f2f5ac0e5ecdadcb to your computer and use it in GitHub Desktop.
sell ram
!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import fire
import json
import time
from datetime import datetime
#base_dir = '/Users/jr/code/exp/bitstar/ak/key/eos_key'
base_dir = './eos_key'
key_files = []
for root, dirs, files in os.walk(base_dir):
key_files = ['%s/%s' % (root, f) for f in files if f.startswith('addr')]
key_files = key_files[::-1]
#cleos = 'cleos --wallet-url http://127.0.0.1:8900 -u https://node1.eosphere.io/'
cleos = 'cleos --wallet-url http://127.0.0.1:8900 -u http://47.91.247.187:8098/'
class Tools(object):
def account(self, key):
accounts = json.loads(open('accounts.json' , 'r').read())
for p_k, account_names in accounts.items():
if p_k == key:
for name in account_names:
print name
def import_keys(self):
for key in key_files:
p_k = open(key, 'r').read().split('\n')[0]
cmd = '%s wallet import %s' % (cleos, p_k)
res = os.popen(cmd).read()
print res
def register(self):
accounts = json.loads(open('accounts.json' , 'r').read())
for p_k, account_names in accounts.items():
name = account_names[0]
print '%s %s' % (p_k, name)
cmd = '%s system regproducer %s %s "" 0' % (cleos, name, p_k)
res = os.popen(cmd).read()
print res
def undelegatebw(self):
accounts = json.loads(open('accounts.json' , 'r').read())
for p_k, account_names in accounts.items():
for name in account_names:
cmd = '%s system undelegatebw %s %s "%s EOS" "%s EOS"' % (cleos, name, name, 8, 9.9)
res = os.popen(cmd).read()
print res
def claim(self):
accounts = json.loads(open('accounts.json' , 'r').read())
for p_k, account_names in accounts.items():
name = account_names[0]
print '%s %s' % (p_k, name)
cmd = '%s system claimrewards %s' % (cleos, name)
print cmd
res = os.popen(cmd).read()
print res
def vote_to_all(self, account, l=0, h=30):
accounts = json.loads(open('accounts.json' , 'r').read())
names = []
for p_k, account_names in accounts.items():
name = account_names[0]
names.append(name)
names = names[l:h]
cmd = '%s system voteproducer prods %s %s -p %s' % (cleos, account, ' '.join(names), account)
print cmd
res = os.popen(cmd).read()
print res
def vote(self, producer):
accounts = json.loads(open('accounts.json' , 'r').read())
for p_k, account_names in accounts.items():
for name in account_names:
cmd = '%s system voteproducer prods %s %s -p %s' % (cleos, name, producer, name)
res = os.popen(cmd).read()
print res
#system voteproducer prods giydmnbxg4ge eoscanadacom eoscannonchn -p giydmnbxg4ge
def gather(self, account):
accounts = json.loads(open('accounts.json' , 'r').read())
for p_k, account_names in accounts.items():
print p_k
for name in account_names:
cmd = '%s get currency balance eosio.token %s' % (cleos, name)
res = os.popen(cmd).read()
print '%s %s' % (name, res)
cnt = 0
try:
cnt = float(res.split(' ')[0])
except Exception as e:
pass
if cnt > 0:
if name != account:
cmd = '%s transfer %s %s "%s EOS" ""' % (cleos, name, account, cnt)
res = os.popen(cmd).read()
print res
def balances(self):
accounts = json.loads(open('accounts.json' , 'r').read())
total = 0
for p_k, account_names in accounts.items():
print p_k
for name in account_names:
cmd = '%s get currency balance eosio.token %s' % (cleos, name)
res = os.popen(cmd).read()
print '%s %s' % (name, res)
try:
total = total + float(res.split(' ')[0])
except Exception as e:
pass
print '%s EOS' % total
def accounts(self, refresh=False):
accounts = {}
if not refresh and os.path.isfile('accounts.json'):
accounts = json.loads(open('accounts.json' , 'r').read())
for p_k, account_names in accounts.items():
for account in account_names:
print account
else:
cnt = 0
for key in key_files:
p_k = open(key, 'r').read().split('\n')[1]
print p_k
print cnt
cnt += 1
account_names = json.loads(os.popen('%s get accounts %s' % (cleos, p_k)).read())['account_names']
accounts[p_k] = account_names
for account in account_names:
print account
f = open('accounts.json', 'w')
f.write(json.dumps(accounts))
f.close()
def bid(self, account, name, bid_price):
cmd = "%s system bidname %s %s '%s EOS' -p %s" % (cleos, account, name, bid_price, account)
print cmd
print os.popen(cmd).read()
def register_account(self, account, name, key):
cmd = '%s system newaccount %s %s %s -p %s --stake-net "0.001 EOS" --stake-cpu "0.001 EOS" --buy-ram "0.06 EOS"' % (cleos, account, name, key, account)
print cmd
print os.popen(cmd).read()
def newaccount(self, account, key):
words = open('word.txt', 'r').read().split('\n')[::-1]
prefix = 'eos'
for w in words:
if len(w) == 12:
name = w.lower()
cmd = '%s system newaccount %s %s %s -p %s --stake-net "0.001 EOS" --stake-cpu "0.001 EOS" --buy-ram "0.06 EOS"' % (cleos, account, name, key, account)
print cmd
print os.popen(cmd).read()
def getaccount(self, p_k):
cmd = '%s get accounts %s' % (cleos, p_k)
print cmd
res = json.loads( os.popen(cmd).read() )
for name in res['account_names']:
cmd = '%s get account %s' % (cleos, name)
print os.popen(cmd).read()
def getalltx(self):
cmd = '%s get info' % cleos
res = json.loads( os.popen(cmd).read() )
last_irreversible_block_num = res['last_irreversible_block_num']
cur_id = last_irreversible_block_num
while cur_id > 0:
cmd = '%s get block %s' % (cleos, cur_id)
print cmd
res = json.loads( os.popen(cmd).read() )
transactions = res['transactions']
for tx in transactions:
actions = ['trx']['transaction']['actions']
for action in actions:
if action['name'] == 'updateauth':
if action['data']['permission'] == 'owner':
print action['data']['account']
cur_id -= 1
def sellram(self, account, threshold, sell=1):
cmd = '%s get table eosio eosio rammarket' % cleos
account_cmd = '%s get account %s -j' % (cleos, account)
sell_cmd = '%s system sellram %s 2048' % (cleos, account)
pre_total_ram_remain = 0
while True:
total_ram_remain = int(json.loads( os.popen(cmd).read() )['rows'][0]['base']['balance'].split(' ')[0])
my_ram_remain = int(json.loads( os.popen(account_cmd).read() )['ram_quota'])
if pre_total_ram_remain != total_ram_remain:
print total_ram_remain, total_ram_remain/68719476736.0, my_ram_remain
pre_total_ram_remain = total_ram_remain
if sell == 1:
if my_ram_remain > 19644750:
if total_ram_remain < int(threshold):
res = os.popen(sell_cmd).read()
print res
time.sleep(1)
def bidnames(self, sortby='bid', myself=False, refresh=1, length=10000):
"""
{
"rows": [{
"newname": "",
"high_bidder": "gu2dqmrxhage",
"high_bid": 1000,
"last_bid_time": "1528713386000000"
}
],
"more": true
}
"""
c = '%s get table eosio eosio namebids' % cleos
rows = []
if refresh == 0:
rows = json.loads(open('bidnames.json', 'r').read())
else:
cmd = c + ' -L %s -l %s' % (len(rows), length)
print cmd
res = json.loads(os.popen(cmd).read())
rows.extend(res['rows'])
open('bidnames.json', 'w').write(json.dumps(rows))
print 'total %s' % len(rows)
f = json.loads(open('accounts.json' , 'r').read())
accounts = []
for p_k, account_names in f.items():
for a in account_names:
accounts.append(a)
if sortby == 'name':
rows = sorted(rows, lambda a, b: len(a['newname']) - len(b['newname']))
elif sortby == 'bid':
rows = sorted(rows, lambda a, b: b['high_bid'] - a['high_bid'])
try:
for row in rows:
if row['high_bidder'] in accounts:
print '%s %s %s %s 1' % (row['newname'], row['high_bidder'], row['high_bid'], datetime.fromtimestamp(float(row['last_bid_time'])/1000000).strftime('%Y-%m-%d %H:%M:%S'))
elif not myself:
print '%s %s %s %s 0' % (row['newname'], row['high_bidder'], row['high_bid'], datetime.fromtimestamp(float(row['last_bid_time'])/1000000).strftime('%Y-%m-%d %H:%M:%S'))
except Exception as e:
pass
if __name__ == '__main__':
fire.Fire(Tools)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment