Example #1
0
def getAllBlocks():
    startblock = config['firstBlock']
    steps = 100
    blocks = []

    #determine endBlock
    if config['endBlock'] == 0:
        endBlock = requests.get(config['node'] +
                                '/blocks/height').json()['height'] - 1
    else:
        endBlock = config['endBlock']

    #try to load previous processed blocks
    try:
        with open(config['blockStorage'], 'r') as f:
            blocks = hyperjson.load(f)

        startblock = blocks[len(blocks) - 1]['height'] + 1
        print('retrieved blocks from ' + str(blocks[0]['height']) + ' to ' +
              str(startblock - 1))
    except Exception as e:
        print('no previous blocks file found')

    #retrieve blocks
    while (startblock < endBlock):
        if (startblock + (steps - 1) < endBlock):
            print('getting blocks from ' + str(startblock) + ' to ' +
                  str(startblock + (steps - 1)))
            blocksJSON = requests.get(config['node'] + '/blocks/seq/' +
                                      str(startblock) + '/' +
                                      str(startblock + (steps - 1))).json()
        else:
            print('getting blocks from ' + str(startblock) + ' to ' +
                  str(endBlock))
            blocksJSON = requests.get(config['node'] + '/blocks/seq/' +
                                      str(startblock) + '/' +
                                      str(endBlock)).json()

        #clear payed tx
        if (startblock + (steps - 1)) < config['startBlock']:
            for block in blocksJSON:
                txs = []

                if block['height'] < config['startBlock']:
                    for tx in block['transactions']:
                        if tx['type'] == 8 or tx['type'] == 9:
                            txs.append(tx)
                else:
                    txs = block['transactions']

                block['transactions'] = txs

        blocks += cleanBlocks(blocksJSON)

        if (startblock + steps < endBlock):
            startblock += steps
        else:
            startblock = endBlock

    return blocks
Example #2
0
    def test_loadFileLikeObject(self):
        class filelike:
            def read(self):
                try:
                    self.end
                except AttributeError:
                    self.end = True
                    return "[1,2,3,4]"

        f = filelike()
        self.assertEqual([1, 2, 3, 4], hyperjson.load(f))
Example #3
0
def getAllBlocks():
    startblock = 1
    steps = 100
    blocks = []

    #determine endBlock
    if config['endBlock'] == 0:
        endBlock = requests.get(config['node'] +
                                '/blocks/height').json()['height'] - 1
    else:
        endBlock = config['endBlock']

    #try to load previous processed blocks
    try:
        with open(config['blockStorage'], 'r') as f:
            #blocks = json.load(f)
            blocks = hyperjson.load(f)

        startblock = blocks[len(blocks) - 1]['height'] + 1
        print('retrieved blocks from ' + str(blocks[0]['height']) + ' to ' +
              str(startblock - 1))
    except Exception as e:
        print('no previous blocks file found')

    #retrieve blocks
    while (startblock < endBlock):
        if (startblock + (steps - 1) < endBlock):
            print('getting blocks from ' + str(startblock) + ' to ' +
                  str(startblock + (steps - 1)))
            blocksJSON = requests.get(config['node'] + '/blocks/seq/' +
                                      str(startblock) + '/' +
                                      str(startblock + (steps - 1))).json()
        else:
            print('getting blocks from ' + str(startblock) + ' to ' +
                  str(endBlock))
            blocksJSON = requests.get(config['node'] + '/blocks/seq/' +
                                      str(startblock) + '/' +
                                      str(endBlock)).json()

        blocks += blocksJSON

        if (startblock + steps < endBlock):
            startblock += steps
        else:
            startblock = endBlock

    return blocks
Example #4
0
def test_object_pairs_hook(self):
    s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
    p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
         ("qrt", 5), ("pad", 6), ("hoy", 7)]
    assert hyperjson.loads(s) == eval(s)
    assert hyperjson.loads(s, object_pairs_hook=lambda x: x) == p
    assert hyperjson.load(StringIO(s), object_pairs_hook=lambda x: x) == p
    od = hyperjson.loads(s, object_pairs_hook=OrderedDict)
    assert od == OrderedDict(p)
    assert type(od) == OrderedDict
    # the object_pairs_hook takes priority over the object_hook
    assert hyperjson.loads(s, object_pairs_hook=OrderedDict,
                           object_hook=lambda x: None) == OrderedDict(p)
    # check that empty object literals work (see #17368)
    assert hyperjson.loads(
        '{}', object_pairs_hook=OrderedDict) == OrderedDict()
    assert hyperjson.loads('{"empty": {}}', object_pairs_hook=OrderedDict) == OrderedDict(
        [('empty', OrderedDict())])
def test_load():
    obj = io.StringIO(u'["streaming API"]')
    assert json.load(obj) == hyperjson.load(obj)
def test_load_invalid_reader():
    with pytest.raises(TypeError):
        hyperjson.load("{}", '')
Example #7
0
import requests
import hyperjson
import os

myLeases = {}
myCanceledLeases = {}
myForgedBlocks = []
payments = {}
totalfee = 0

with open('config_run.json') as json_file:
    config = hyperjson.load(json_file)


def cleanBlocks(blocksJSON):
    for block in blocksJSON:

        if 'totalFee' in block:
            block['fee'] = block['totalFee']

        block.pop('nxt-consensus', None)
        block.pop('version', None)
        block.pop('features', None)
        block.pop('blocksize', None)
        block.pop('signature', None)
        block.pop('reference', None)
        block.pop('transactionCount', None)
        block.pop('generatorPublicKey', None)
        block.pop('desiredReward', None)
        block.pop('timestamp', None)
Example #8
0
 def test_loadFile(self):
     f = six.StringIO("[1,2,3,4]")
     self.assertEqual([1, 2, 3, 4], hyperjson.load(f))
Example #9
0
def load_json(inp_path):
    with open(inp_path, 'r') as ifile:
        loadedj = json.load(ifile)
    return loadedj