Ejemplo n.º 1
0
class System:
    def __init__(self, *kwargs):
        self.aqua = AquaTool(ipcpath='/home/user/.aquachain/aquachain.ipc')
        #self.aqua = AquaTool(ipcpath='/home/user/.aquachain/testnet/aquachain.ipc')
        # self.aqua = AquaTool(rpchost='https://c.onical.org')

    def run(self):
        txpool = self.aqua.w3.txpool
        print('pending', from_hex(txpool.status.pending))
        print('queued', from_hex(txpool.status.queued))
        new_block_filter = self.aqua.w3.eth.filter('latest')
        new_transaction_filter = self.aqua.w3.eth.filter('pending')
        while True:
            txs = new_transaction_filter.get_new_entries()
            if len(txs) > 0:
                print('\n')
                for tx in txs:
                    tx_hash = tx.hex()
                    t = self.aqua.gettransaction(f'{tx_hash}')
                    print("\nnew tx:", tx_hash, '\n\n', t, '\n')

            newblock = new_block_filter.get_new_entries()
            if len(newblock) > 0:
                print('\n')
                print('\n\nnewblock', newblock)
                for i in range(len(newblock)):
                    block = self.aqua.getblockbyhash(newblock[i].hex())
                    print(from_hex(block['number']), block)
                    print('\n\n')
            time.sleep(WAIT_SECONDS)
            print('.', end='', flush=True)
Ejemplo n.º 2
0
    def __init__(self):
        Tk.__init__(self)

        # self.wm_geometry(newGeometry='800x400-100+100')
        self.version = 'Aquachain TK v0.0.3'
        self.configure(background='black')
        self.logo = PhotoImage(file=LogoPath)
        self.head_difficulty = IntVar()
        self.head_number = IntVar()
        self.head_timing = IntVar()
        self.head_timestamp = IntVar()
        self.total_supply = IntVar()

        self.head_difficulty.set(0)
        self.head_number.set(0)
        self.head_timing.set(0)
        self.head_timestamp.set(0)
        self.total_supply.set(0)

        # connect to aquachain node
        self.aqua = None
        self.aqua = AquaTool(rpchost='https://c.onical.org')

        # get latest block from aquachain node
        self.head = self.aqua.gethead()

        # keys
        self.keystore = Keystore()
        self.hdkeys = []
        self.addresses = []

        # TK
        self._mainframe = Frame(self, background='green')
        self._mainframe.pack(side='top', anchor='n', expand=True, fill='both')
        self._framename = ''


        self.buttons = btns = {
            'Quit': NoButton(text='Quit',
                command=self.quit, width=13),
            'Lock': NoButton(text='Lock',
                command=self.lock, width=13),
            'PageWallets': NoButton(text='Wallets',
                command=self.switch_frame, arg=PageWallets, width=13),
            'PageAbout': NoButton(text='About',
                command=self.switch_frame, arg=PageAbout, width=13),
            'PageAbout': NoButton(text='Recv',
                command=self.switch_frame, arg=PageReceive, width=13),
        }
        self._toolbar = Toolbar(self._mainframe, app=self, logo=self.logo)
        self._toolbar.addbtns(btns)
        self._toolbar.grid(sticky='nw', columnspan=1, column=0, row=0)

        # take it away
        # self._leftcol = Frame(self, background='blue')
        self._frame = ThemedFrame(self._mainframe, app=self, background='teal', height='100')

        self.homepage()
Ejemplo n.º 3
0
 def __init__(self, *kwargs):
     self.aqua = AquaTool(ipcpath='/home/user/.aquachain/aquachain.ipc')
     #self.aqua = AquaTool(rpchost='https://c.onical.org')
     self.block = self.aqua.gethead()
     self.headnumber = int(self.block['number'], 16)
     self.motd_contract = self.aqua.w3.eth.contract(
         address=MOTD_ADDRESS,
         abi=MOTD_ABI,
         ContractFactoryClass=ConciseContract)
     self.latest = self.motd_contract.get()
     self.count = self.motd_contract.changedCount()
     print('got: ', self.motd_contract.get())
Ejemplo n.º 4
0
class System:
    def __init__(self, *kwargs):
        self.aqua = AquaTool(ipcpath='/home/user/.aquachain/aquachain.ipc')
        #self.aqua = AquaTool(rpchost='https://c.onical.org')
        self.block = self.aqua.gethead()
        self.headnumber = int(self.block['number'], 16)
        self.motd_contract = self.aqua.w3.eth.contract(
            address=MOTD_ADDRESS,
            abi=MOTD_ABI,
            ContractFactoryClass=ConciseContract)
        self.latest = self.motd_contract.get()
        self.count = self.motd_contract.changedCount()
        print('got: ', self.motd_contract.get())

    def run(self):
        log.info('main thread started')
        while True:
            log.info('all systems go, latest: (%d) %s [%d]', self.headnumber,
                     self.latest, self.count)
            time.sleep(WAIT_SECONDS)

    def handle_event(self, event):
        log.info('%s: new event: %x', datetime.datetime.utcnow(), event)
        self.count = self.motd_contract.changedCount()
        self.block = self.aqua.gethead()
        self.latest = self.motd_contract.get()
        self.headnumber = int(self.block['number'], 16)

    def log_loop(self, event_filter, poll_interval):
        log.info('filter log thread started')
        while True:
            # for event in block_filter.get_new_entries():
            #     self.handle_event(event)
            for tx in event_filter.get_new_entries():
                print('\n', len(tx))
                tx_hash = tx.hex()
                t = self.aqua.gettransaction(f'{tx_hash}')
                if t == None:
                    t = self.aqua.getblockbyhash(tx_hash)
                print("\nnew event:", tx_hash, '\n\n', t, '\n')
            time.sleep(poll_interval)
Ejemplo n.º 5
0
#!/usr/bin/env python3.6
from aquachain.aquatool import AquaTool
from datetime import datetime

aqua = AquaTool(ipcpath='~/.aquachain/aquachain.ipc')

head = aqua.gethead_header()

parent = head
#d = 0
while head[
        'parentHash'] != "0x0000000000000000000000000000000000000000000000000000000000000000":
    #	d = d + 1
    #	if d % 1000 == 0:
    #		print("\nchecking", int(head['number'], 16))
    #		print("")
    #		d = 0

    for tx in head['transactions']:
        receipt = aqua.gettransactionreceipt(tx)
        if receipt['contractAddress'] != None:
            print("\nblock number", int(head['number'], 16))
            print("tx time",
                  datetime.utcfromtimestamp(int(head['timestamp'], 16)))
            print("tx hash", tx)
            #print("tx receipt", receipt)
            print("gas used", int(receipt['gasUsed'], 16))
            print("contract address", receipt['contractAddress'])
            print("creator", receipt['from'])
    head = aqua.getheaderbyhash(head['parentHash'])
Ejemplo n.º 6
0
from aquachain.aquatool import AquaTool
import sys
aqua = AquaTool(ipcpath='/home/user/.aquachain/aquachain.ipc')

block = aqua.gethead()

total_tx = 0

acct_tx_incoming = []
acct_tx_outgoing = []

ACCOUNT = '0x0000001bb3ee5e82f08c884428797c65c102683e'

if len(sys.argv) == 2:
    ACCOUNT = sys.argv[1]
    print(f'scanning blockchain for transactions related to account: {ACCOUNT}')

try:
    nonce = aqua.getnonce(ACCOUNT)
    balance = aqua.getbalance(ACCOUNT)
    if nonce == 0 and balance == 0:
        print('this account is not active')
        quit()
    print('Account:', ACCOUNT)
    print('Current Balance:', balance)
    print('Current Nonce:', nonce)
except TypeError:
    print('this account is invalid')
    quit()
limit = int(block['number'], 16)
print(f"Scanning {limit} blocks for transactions.", end='', flush=True)
Ejemplo n.º 7
0
# hello world
testcase1 = 'sea oval armed kid foil tuition journey initial salad' + \
            ' convince fortune filter pulse drastic evidence argue piano' + \
            ' skirt wealth dragon call blast wide hard'

testcase2b = '0x5a6772e31ea5AE3D41D21dAc90968e910523853C'
testcase2 = 'wisdom write work exercise critic ' + \
            'chair legal call truck final ' + \
            'umbrella cat foil neither tomorrow ' + \
            'human worry blossom north snack ' + \
            'infant swear reunion student'

dummykey = b'\xc1\xf3\xb4/=%\xa7\xd4^\x1b\x9f\xbeE\xf1n+:\xd8\x84\x93' + \
           b'p\\\xa4\x19W\xe0\xa1\x02\x06.\xfe\xab'

aqua = AquaTool(rpchost='https://c.onical.org')


class Test_Account(unittest.TestCase):
    # def test_fileloader(self):
    #     log.info("fileloader")
    #     private_key = aqua.file_to_private(my_key, '')
    #     self.assertNotEqual('', private_key)
    #     acct = aqua.private_to_account(private_key)
    #     self.assertNotEqual('', acct.address)
    #     log.info("got real account: %s", acct.address)
    #     signed = aqua.sign(private_key, 'hello world')
    #     log.info("Signed Helloworld: %s",
    #              signed)

    def test_nonce(self):
Ejemplo n.º 8
0
# python3.6
from aquachain.aquatool import AquaTool

aqua = AquaTool(ipcpath='~/.aquachain/aquachain.ipc')
head = aqua.gethead_header()
headnumber = int(head['number'], 16)


def fmtrange(x, y):
    s = str(x)
    if x == y + 1 or x == y - 1:
        return f'{x}, {y}'
    for i in range(x + 1, y):
        s += ',' + str(i)
    return s


blocks_mined = []
msg = ""
prev_num = 0
prev_miner = ''
for i in range(headnumber):
    block = aqua.getblock(headnumber - i)
    if block['miner'] == prev_miner:
        cur = int(block['number'], 16)
        blocks_mined.append(cur)
        msg = f"Block {blocks_mined} mined by {block['miner']}"
    elif msg != '':
        if len(blocks_mined) > 10:
            msg = 'super effective! ' + msg
        if len(blocks_mined) > 3:
Ejemplo n.º 9
0
class TestApplication(Tk):
    def __init__(self):
        Tk.__init__(self)

        # self.wm_geometry(newGeometry='800x400-100+100')
        self.version = 'Aquachain TK v0.0.3'
        self.configure(background='black')
        self.logo = PhotoImage(file=LogoPath)
        self.head_difficulty = IntVar()
        self.head_number = IntVar()
        self.head_timing = IntVar()
        self.head_timestamp = IntVar()
        self.total_supply = IntVar()

        self.head_difficulty.set(0)
        self.head_number.set(0)
        self.head_timing.set(0)
        self.head_timestamp.set(0)
        self.total_supply.set(0)

        # connect to aquachain node
        self.aqua = None
        self.aqua = AquaTool(rpchost='https://c.onical.org')

        # get latest block from aquachain node
        self.head = self.aqua.gethead()

        # keys
        self.keystore = Keystore()
        self.hdkeys = []
        self.addresses = []

        # TK
        self._mainframe = Frame(self, background='green')
        self._mainframe.pack(side='top', anchor='n', expand=True, fill='both')
        self._framename = ''


        self.buttons = btns = {
            'Quit': NoButton(text='Quit',
                command=self.quit, width=13),
            'Lock': NoButton(text='Lock',
                command=self.lock, width=13),
            'PageWallets': NoButton(text='Wallets',
                command=self.switch_frame, arg=PageWallets, width=13),
            'PageAbout': NoButton(text='About',
                command=self.switch_frame, arg=PageAbout, width=13),
            'PageAbout': NoButton(text='Recv',
                command=self.switch_frame, arg=PageReceive, width=13),
        }
        self._toolbar = Toolbar(self._mainframe, app=self, logo=self.logo)
        self._toolbar.addbtns(btns)
        self._toolbar.grid(sticky='nw', columnspan=1, column=0, row=0)

        # take it away
        # self._leftcol = Frame(self, background='blue')
        self._frame = ThemedFrame(self._mainframe, app=self, background='teal', height='100')

        self.homepage()
    def quit(self):
        quit()
    def lock(self):
        quit()
    def homepage(self):
        # self.switch_frame(/StartPage)
        self.switch_frame(StartPage)
    def switch_frame(self, frame_class):
        """Destroys current frame and replaces it with a new one."""
        self._framename = frame_class.__name__
        new_frame = frame_class(parent=self._mainframe,app=self)
        if self._frame is not None:
            print('deleting:',self._frame)
            self._frame.destroy()
        self._frame = new_frame
        self._frame.grid(sticky='ne',ipadx=100, column=1, row=0)
        print('switchin to framename:', self._framename)
Ejemplo n.º 10
0
from aquachain.aquatool import AquaTool
from aquachain.aquakeys import Keystore
passphrase = ''
vanity = '0xaa'

keystore = Keystore(directory='myaquakeys')
aqua = AquaTool(ipcpath="~/.aquachain/aquachain.ipc")

print("Looking for", vanity, "saving to", keystore.directory)

#keys = keystore.listphrases()
#for keyphrase in keys:
#    key = aqua.key_from_mnemonic(keyphrase, passphrase)
#    address = key._key.public_key.address()
#    print(address, keyphrase)
count = 0
while True:
    if count % 1000 == 0:
        print('.')
        count = 0
    count = count + 1
    phrase = aqua.generate_phrase()
    key = aqua.key_from_mnemonic(phrase, passphrase)
    address = key._key.public_key.address()
    if vanity in address:
        print(key._key.public_key.address(), phrase)
        keystore.save_phrase(phrase)
        break
Ejemplo n.º 11
0
 def __init__(self, *kwargs):
     self.aqua = AquaTool(ipcpath='/home/user/.aquachain/aquachain.ipc')
Ejemplo n.º 12
0
from aquachain.aquatool import AquaTool

aqua = AquaTool(ipcpath='/home/user/.aquachain/aquachain.ipc')

block = aqua.gethead()

total_uncles = 0
uncle_blocks = []
for i in range(1000000):
    #if i % 1000 == 0:
    #    print('scanning', int(block['number'], 16))
    l = len(block['uncles'])
    if l > 0:
        total_uncles += l
        num = int(block['number'], 16)
        print('uncles in', num, l)
        uncle_blocks.append(num)
    if block[
            'parentHash'] == '0x0000000000000000000000000000000000000000000000000000000000000000':
        break
    block = aqua.getblockbyhash(block['parentHash'])

print(f'found total of {total_uncles} uncles')
print(f'located in blocks: {uncle_blocks}')
Ejemplo n.º 13
0
from aquachain.aquatool import AquaTool
from aquachain.aquakeys import Keystore
from web3.contract import ConciseContract
from aquamotd import MOTD_ABI, MOTD_ADDRESS
import os, time, random, datetime
import logging
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
log = logging.getLogger(__name__)


def userenv(foo):
    os.os.path.expanduser(foo)


aqua = AquaTool(ipcpath=os.path.expanduser('~/.aquachain/aquachain.ipc'))
keystore = Keystore(directory=os.path.expanduser('~/.aquachain/aquakeys'))

args = []


def _handle_args():
    import sys
    return sys.argv


args = _handle_args()


def from_hex(i=0):
    return int(i, 16)