예제 #1
0
    def post(self):
        # 获取指定时间区间内的无效区块集
        if not check_request(request, "beginTime"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param beginTime not exist")
        if not check_request(request, "endTime"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param endTime not exist")

        startTime = request.json.get("beginTime")
        endTime = request.json.get("endTime")
        pool = current_app.config['bigchain_pool']
        with pool() as b:
            try:
                invalidBlockIdList = b.get_invalidBlockIdList(
                    startTime=startTime, endTime=endTime)
            except:
                return make_response(constant.RESPONSE_STATUS_SERVER_ERROR,
                                     constant.RESPONSE_CODE_SERVER_ERROR,
                                     "None")
        return make_response(constant.RESPONSE_STATUS_SUCCESS,
                             constant.RESPONSE_CODE_SUCCESS, "query success",
                             list(invalidBlockIdList))
예제 #2
0
    def post(self):
        print("txCreateAvgTime")
        if not check_request(request, "beginTime"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param beginTime not exist")
        if not check_request(request, "endTime"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param endTime not exist")
        begintime = request.json.get("beginTime")
        endtime = request.json.get("endTime")

        pool = current_app.config['bigchain_pool']
        with pool() as unichain:
            avgtime, status = unichain.get_txCreateAvgTimeByRange(
                begintime, endtime)
        if not status:
            return make_response(constant.RESPONSE_STATUS_SERVER_ERROR,
                                 constant.RESPONSE_CODE_SERVER_ERROR,
                                 "response is none")
        avgtime_dict = {'avgTime': avgtime}
        return make_response(constant.RESPONSE_STATUS_SUCCESS,
                             constant.RESPONSE_CODE_SUCCESS, "query success",
                             avgtime_dict)
예제 #3
0
 def post(self):
     print("ApiGetTxByConHashId")
     contract_hash_id = request.get_json()["contract_hash_id"]
     if not check_request(request, "contract_hash_id"):
         return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                              constant.RESPONSE_CODE_PARAM_ERROE,
                              "param contract_hash_id not exist")
     pool = current_app.config['bigchain_pool']
     with pool() as bigchain:
         try:
             result = bigchain.get_tx_by_contract_hash_id(contract_hash_id)
             # print(result)
         except(Exception):
             return make_response(constant.RESPONSE_STATUS_SERVER_ERROE,
                                  constant.RESPONSE_CODE_SERVER_ERROR,
                                  "get output failed.")
         if not result:
             result = {}
             return make_response(constant.RESPONSE_STATUS_SUCCESS_NODATA,
                                  constant.RESPONSE_CODE_SUCCESS_NODATA,
                                  "no asset exist!",
                                  result)
         else:
             return make_response(constant.RESPONSE_STATUS_SUCCESS,
                                  constant.RESPONSE_CODE_SUCCESS,
                                  "query success",
                                  list(result))
예제 #4
0
    def post(self):
        # 根据交易ID获取交易
        # @common_api.route('/getTxById/', methods=['POST'])
        # def getTxById():
        type = request.get_json()["type"]

        if not check_request(request, "type"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param type not exist.")
        tx_id = request.get_json()["tx_id"]
        if not check_request(request, "tx_id"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param tx_id not exist")

        pool = current_app.config['bigchain_pool']
        with pool() as b:
            if type == '0':
                # get single tx by txid without vaildate
                tx = list(b.get_transaction_no_valid(tx_id))
            if type == '1':
                # get all block which contains the tx without validate.
                tx = list(b.get_tx_by_id(tx_id))
            elif type == '2':
                # get block status which contains the tx
                tx = b.get_blocks_status_containing_tx(tx_id)
            elif type == '3':
                # get signle validate tx in validate block
                tx = b.get_transaction(tx_id)
                tx = tx.to_dict()

        if not tx:
            tx = {}
            return make_response(constant.RESPONSE_STATUS_SUCCESS_NODATA,
                                 constant.RESPONSE_CODE_SUCCESS_NODATA,
                                 "tx not exist!", tx)
        else:
            # tx_result = tx.to_dict()
            return make_response(constant.RESPONSE_STATUS_SUCCESS,
                                 constant.RESPONSE_CODE_SUCCESS,
                                 "query success", tx)
예제 #5
0
    def post(self):
        # 根据指定时间区间获取交易集
        # @common_api.route('/getTxsByTime/', methods=['POST'])
        # def getTxsByTime():
        startTime = request.get_json()['beginTime']
        if not check_request(request, "beginTime"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param beginTime not exist")

        endTime = request.get_json()['endTime']
        if not check_request(request, "endTime"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param endTime not exist")

        pool = current_app.config['bigchain_pool']
        with pool() as b:
            txIdList = b.get_TxIdByTime(startTime, endTime)

        return make_response(constant.RESPONSE_STATUS_SUCCESS,
                             constant.RESPONSE_CODE_SUCCESS, "query success",
                             txIdList)
예제 #6
0
    def post(self):
        if not check_request(request, "block_id"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param block id not exist")
        block_id = request.json.get("block_id")

        pool = current_app.config['bigchain_pool']
        with pool() as unichain:
            avgtime, status = unichain.get_voteTimeByBlockID(block_id)
        if not status:
            return make_response(constant.RESPONSE_STATUS_SUCCESS_NODATA,
                                 constant.RESPONSE_CODE_SUCCESS_NODATA,
                                 "response is none")
        avgtime_dict = {'avgTime': avgtime}
        return make_response(constant.RESPONSE_STATUS_SUCCESS,
                             constant.RESPONSE_CODE_SUCCESS, "query success",
                             avgtime_dict)
예제 #7
0
 def post(self):
     # 根据区块ID获取区块中的交易条数
     if not check_request(request, "block_id"):
         return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                              constant.RESPONSE_CODE_PARAM_ERROE,
                              "param block id not exist")
     block_id = request.get_json()["block_id"]
     pool = current_app.config['bigchain_pool']
     with pool() as b:
         try:
             number = b.get_txNumber(block_id)
         except:
             return make_response(constant.RESPONSE_STATUS_SERVER_ERROR,
                                  constant.RESPONSE_CODE_SERVER_ERROR,
                                  "None")
     return make_response(constant.RESPONSE_STATUS_SUCCESS,
                          constant.RESPONSE_CODE_SUCCESS, "query success",
                          number)
예제 #8
0
 def post(self):
     # 根据区块ID获取区块中的交易
     if not check_request(request, "block_id"):
         return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                              constant.RESPONSE_CODE_PARAM_ERROE,
                              "param block id not exist")
     block_id = request.get_json()["block_id"]
     pool = current_app.config['bigchain_pool']
     with pool() as b:
         try:
             block = b.get_block(block_id)
         except:
             return make_response(constant.RESPONSE_STATUS_SERVER_ERROR,
                                  constant.RESPONSE_CODE_SERVER_ERROR,
                                  "None")
     print(block)
     txList = block["block"]['transactions']
     return make_response(constant.RESPONSE_STATUS_SUCCESS,
                          constant.RESPONSE_CODE_SUCCESS, "query success",
                          txList)
예제 #9
0
    def post(self):
        print("getContractTx")

        tx_id = request.get_json()["tx_id"]
        if not check_request(request, "tx_id"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                                 constant.RESPONSE_CODE_PARAM_ERROE,
                                 "param tx_id not exist")
        pool = current_app.config['bigchain_pool']
        with pool() as bigchain:
            txs = bigchain.get_contract_txs_by_tx_id(tx_id)

        if not txs:
            txs = {}
            return make_response(constant.RESPONSE_STATUS_SUCCESS_NODATA,
                                 constant.RESPONSE_CODE_SUCCESS_NODATA,
                                 "contract or tx not exist!",
                                 list(txs))
        else:
            return make_response(constant.RESPONSE_STATUS_SUCCESS,
                                 constant.RESPONSE_CODE_SUCCESS,
                                 "query success",
                                 list(txs))
예제 #10
0
    def post(self):
        print("getContract")

        contract_id = request.get_json()["contract_id"]
        if not check_request(request, "contract_id"):
            return make_response(constant.RESPONSE_STATUS_PARAM_ERROE,
                             constant.RESPONSE_CODE_PARAM_ERROE,
                             "param contract_id not exist")
        pool = current_app.config['bigchain_pool']
        with pool() as bigchain:
            contract = bigchain.get_contract_by_id(contract_id)
        if not contract:
            contract = {}
            return make_response(constant.RESPONSE_STATUS_SUCCESS_NODATA,
                                 constant.RESPONSE_CODE_SUCCESS_NODATA,
                                 "contract not exist!",
                                 list(contract))
        else:
            res = list(contract)
            # print("getContract return", res)
            return make_response(constant.RESPONSE_STATUS_SUCCESS,
                                 constant.RESPONSE_CODE_SUCCESS,
                                 "query success",
                                 res)