コード例 #1
0
class FlaskWorker():
    def __init__(self, privateKey):
        self.app = Flask(__name__)
        self.cryptor = NooCrypto()
        self.cryptor.setPrivateKey(privateKey)
        self.dataFieldsMas = <%FIELDS%>
        self.stemIP = "<%STEMIP%>"
        self.stemPK = "<%STEMPK%>"
        self.redis_host = os.getenv("REDIS_PORT_6379_TCP_ADDR") or 'localhost'
        self.redis_port = os.getenv("REDIS_PORT_6379_TCP_PORT") or '6379'
        self.redis = redis.StrictRedis(self.redis_host, self.redis_port, db=2)

        @self.app.route('/shard/getStatData', methods=['GET','POST'])
        def saveMapElement():
            if not request:
                abort(400)

            jsond = {}
            for field in self.dataFieldsMas:
                if self.redis.get(field) is not None:
                    jsond.update({field: self.redis.get(field)})

            jsonstr = json.dumps(jsond)
            sign = self.cryptor.signMessage(jsonstr)

            return json.dumps({"DATA": jsond,"SIGNATURE": sign}, separators=(',', ':'))

    def run(self):
        self.app.run(host='0.0.0.0', port=5005)
コード例 #2
0
    def createPrecommitBlock(cryptor:NooCrypto, ver:str, transactions:set, bheight):
        jtransactions = []
        for tran in transactions:
            jtransactions.append(json.loads(tran))

        block = json.dumps({'TT': 'BL', 'SENDER': cryptor.getPublicKey(), 'VERSION': ver, 'TCOUNT': len(jtransactions), "BHEIGHT": bheight, 'TRANSACTIONS':jtransactions}, separators=(',', ':'))
        sign = cryptor.signMessage(block)
        jblock = json.loads(block)
        jblock.update({'SIGNATURE':sign})

        return json.dumps(jblock, separators=(',', ':'))
コード例 #3
0
 def createPurifierBlock(cryptor:NooCrypto, addressList:list, keyList:list, bheight:int):
     temp = json.dumps({'TT': 'PURIFIER', 'SENDER': cryptor.getPublicKey(), 'CLEAN_LIST': addressList, 'CLEAN_KEY_LIST': keyList, "BHEIGHT": bheight}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #4
0
 def giveAllSizeBlock(cryptor:NooCrypto, NBH:int):
     temp = json.dumps({'TT': 'ASB', 'SENDER': cryptor.getPublicKey(), "NBH": NBH}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #5
0
 def chooserTransaction(cryptor:NooCrypto, blockchain_height): # Транзакция выбора ноды для работы
     temp = json.dumps({'TT': 'CT', 'SENDER': cryptor.getPublicKey(), "NBH": blockchain_height, "TST": str(int(time.time()))}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #6
0
 def createSignaturePrecommitedBlock(cryptor:NooCrypto, pblock:str, hash:str):
     temp = json.dumps({'TT': 'SG', 'SENDER': cryptor.getPublicKey(), 'HASH': hash,'SIGNPB': cryptor.signMessage(pblock)}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #7
0
 def createCommitBlockForResendHash(cryptor:NooCrypto, block:str, bheight:int):
     block = json.dumps({'TT': 'CBRH', 'SENDER': cryptor.getPublicKey(), "HASH":NooTree.hash(block), "STEM_SIGNATURE": cryptor.signMessage(block), "BHEIGHT": bheight}, separators=(',', ':'))
     sign = cryptor.signMessage(block)
     jblock = json.loads(block)
     jblock.update({'SIGNATURE':sign})
     return json.dumps(jblock, separators=(',', ':'))
コード例 #8
0
 def createCommitBlockForResend(cryptor:NooCrypto, block:str):
     block = json.dumps({'TT': 'CBR', 'SENDER': cryptor.getPublicKey(), "BLOCK" :json.loads(block)}, separators=(',', ':'))
     sign = cryptor.signMessage(block)
     jblock = json.loads(block)
     jblock.update({'SIGNATURE':sign})
     return json.dumps(jblock, separators=(',', ':'))
コード例 #9
0
 def createCommitBlock(cryptor:NooCrypto, preCommitedBlock:str, signs:list):
     block = json.dumps({'TT': 'CB', 'SENDER': cryptor.getPublicKey(), "BLOCK" :json.loads(preCommitedBlock), "SIGNATURES":signs}, separators=(',', ':'))
     sign = cryptor.signMessage(block)
     jblock = json.loads(block)
     jblock.update({'SIGNATURE':sign})
     return json.dumps(jblock, separators=(',', ':'))
コード例 #10
0
 def standartTransacton(cryptor:NooCrypto, reciever:str, token_count:int, token_type:str): # Стандартная транзакция перевода средств
     temp = json.dumps({'TT': 'ST', 'SENDER': cryptor.getPublicKey(), 'RECEIVER': reciever, 'TTOKEN':token_type, 'CTOKEN': str(token_count), "TST": str(int(time.time()))}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #11
0
 def applicantTransacton(cryptor:NooCrypto, ip:str): # Транзакция заявка на участие в следующем туре валидации
     temp = json.dumps({'TT': 'AT', 'SENDER': cryptor.getPublicKey(), 'IPADR': ip, "TST": str(int(time.time()))}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #12
0
 def universalPacket(cryptor:NooCrypto, type:str, value):
     temp = json.dumps({'TT': type, 'DATA': value, 'SENDER': cryptor.getPublicKey()}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #13
0
 def badAnswer(cryptor:NooCrypto):
     temp = json.dumps({'TT': 'BAN', 'SENDER': cryptor.getPublicKey()}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #14
0
 def myBenchmarkResult(cryptor:NooCrypto, result:str, start:str):
     temp = json.dumps({'TT': 'MBR', 'SENDER': cryptor.getPublicKey(), 'RESULT': result, 'START': start}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #15
0
 def benchmarkTesting(cryptor:NooCrypto, uuid:str):
     temp = json.dumps({'TT': 'BT', 'SENDER': cryptor.getPublicKey(), 'START': uuid}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))
コード例 #16
0
 def createСomplaint(cryptor:NooCrypto, evidence_block:str, evidence_transaction:str):
     temp = json.dumps({'TT': 'COMPLAINT', 'SENDER': cryptor.getPublicKey(), 'EVIDENCE_BLOCK': evidence_block, 'EVIDENCE_TRANSACTION': evidence_transaction}, separators=(',', ':'))
     sign = cryptor.signMessage(temp)
     jtemp = json.loads(temp)
     jtemp.update({'SIGNATURE':sign})
     return json.dumps(jtemp, separators=(',', ':'))