コード例 #1
0
ファイル: api_keys.py プロジェクト: michaelberge8/dragonchain
def delete_api_key_v1(key_id: str,
                      **kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not key_id:
        raise exceptions.ValidationException("Invalid parameter: key_id")

    api_keys.delete_api_key_v1(key_id=key_id)
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #2
0
def public_blockchain_transaction_v1() -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    data = flask.request.json

    if not data.get("network"):
        raise exceptions.ValidationException("Invalid parameter: network")
    try:
        if data["network"] in ["BTC_MAINNET", "BTC_TESTNET3"]:
            _validate_bitcoin_transaction_v1(data.get("transaction"))
        elif data["network"] in [
                "ETH_MAINNET", "ETH_ROPSTEN", "ETC_MAINNET", "ETC_MORDEN"
        ]:
            _validate_ethereum_transaction_v1(data.get("transaction"))
        else:
            raise exceptions.ValidationException(
                "User input did not match JSON schema")
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException(
            "User input did not match JSON schema")

    return helpers.flask_http_response(
        200,
        interchain.legacy_sign_blockchain_transaction_v1(
            data["network"], data["transaction"]))
コード例 #3
0
def get_transaction_v1(transaction_id: str) -> Tuple[str, int, Dict[str, str]]:
    if not transaction_id:
        raise exceptions.BadRequest("Paramterer 'transaction_id' is required'")

    should_parse = flask.request.headers.get("Parse-Payload") != "false"
    return helpers.flask_http_response(
        200, transactions.get_transaction_v1(transaction_id, should_parse))
コード例 #4
0
def get_transaction_type_v1(txn_type: str,
                            **kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not txn_type:
        raise exceptions.ValidationException("Invalid parameter: txn_type")

    return helpers.flask_http_response(
        200, transaction_types.get_transaction_type_v1(txn_type))
コード例 #5
0
def delete_transaction_type_v1(txn_type: str,
                               **kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not txn_type:
        raise exceptions.ValidationException("Invalid parameter: txn_type")

    transaction_types.delete_transaction_type_v1(txn_type)
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #6
0
def query_transaction_v1() -> Tuple[str, int, Dict[str, str]]:
    params = helpers.parse_query_parameters(flask.request.args.to_dict())
    if params.get("transaction_type"):
        should_parse = flask.request.headers.get("Parse-Payload") != "false"
        return helpers.flask_http_response(
            200, transactions.query_transactions_v1(params, should_parse))
    raise exceptions.ValidationException(
        "User input must specify transaction type to query")
コード例 #7
0
ファイル: transactions.py プロジェクト: uningan/dragonchain
def post_transaction_bulk_v1(**kwargs) -> Tuple[str, int, Dict[str, str]]:
    """
    Enqueue bulk transactions to be processed
    """
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    content = flask.request.json

    try:
        _validate_bulk_txn_create_v1(content)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    response = transactions.submit_bulk_transaction_v1(content, api_key=kwargs["used_auth_key"])
    if not response["201"]:
        return helpers.flask_http_response(400, response)
    return helpers.flask_http_response(207, response)
コード例 #8
0
def post_transaction_bulk_v1() -> Tuple[str, int, Dict[str, str]]:
    """
    Enqueue bulk transactions to be processed
    """
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    content = flask.request.json

    try:
        _validate_bulk_txn_create_v1(content)
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException(
            "User input did not match JSON schema")

    response = transactions.submit_bulk_transaction_v1(content)
    if not response["201"]:
        return helpers.flask_http_response(400, response)
    return helpers.flask_http_response(207, response)
コード例 #9
0
def get_smart_contract_logs_v1(
        contract_id: str) -> Tuple[str, int, Dict[str, str]]:
    since = flask.request.args.get("since")
    tail = cast(Any, flask.request.args.get("tail"))
    try:
        tail = int(tail)
    except Exception:
        raise exceptions.BadRequest("Invalid parameter for tail")

    return helpers.flask_http_response(
        200, smart_contracts.get_logs_v1(contract_id, since, tail))
コード例 #10
0
ファイル: interchain.py プロジェクト: uningan/dragonchain
def create_binance_interchain_v1(**kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")
    data = flask.request.json
    try:
        _validate_binance_network_create_v1(data)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    return helpers.flask_http_response(
        201, interchain.create_binance_interchain_v1(data))
コード例 #11
0
ファイル: dragonnet.py プロジェクト: hewei-github/dragonchain
def receipt_v1() -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    content = flask.request.json

    try:
        dragonnet.process_receipt_v1(content)
    except NotImplementedError as e:
        raise exceptions.BadRequest(str(e))
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #12
0
def update_bitcoin_interchain_v1(name: str) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")
    data = flask.request.json
    try:
        _validate_bitcoin_network_update_v1(data)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    return helpers.flask_http_response(
        200, interchain.update_bitcoin_interchain_v1(name, data))
コード例 #13
0
ファイル: api_keys.py プロジェクト: hewei-github/dragonchain
def create_api_key_v1() -> Tuple[str, int, Dict[str, str]]:
    nickname = ""
    if flask.request.is_json:
        body = flask.request.json
        try:
            _validate_api_key_creation_v1(body)
        except fastjsonschema.JsonSchemaException as e:
            raise exceptions.ValidationException(str(e))
        nickname = body.get("nickname") or ""

    return helpers.flask_http_response(201,
                                       api_keys.create_api_key_v1(nickname))
コード例 #14
0
def create_ethereum_interchain_v1() -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")
    data = flask.request.json
    try:
        _validate_ethereum_network_create_v1(data)
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException(
            "User input did not match JSON schema")

    return helpers.flask_http_response(
        201, interchain.create_ethereum_interchain_v1(data))
コード例 #15
0
ファイル: interchain.py プロジェクト: uningan/dragonchain
def set_default_network_v1(**kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")
    data = flask.request.json
    try:
        _validate_set_default_interchain_v1(data)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    return helpers.flask_http_response(
        200,
        interchain.set_default_interchain_v1(data["blockchain"], data["name"]))
コード例 #16
0
def update_contract_v1(contract_id: str) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    update = flask.request.json

    try:
        _validate_sc_update_v1(update)
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException("User input did not match JSON schema")

    return helpers.flask_http_response(202, smart_contracts.update_contract_v1(contract_id, update))
コード例 #17
0
ファイル: interchain.py プロジェクト: uningan/dragonchain
def create_binance_transaction_v1(name: str,
                                  **kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")
    data = flask.request.json
    try:
        _validate_binance_transaction_v1(data)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    return helpers.flask_http_response(
        200, interchain.sign_interchain_transaction_v1("binance", name, data))
コード例 #18
0
def register_transaction_type_v1() -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    content = flask.request.json

    try:
        _validate_create_txn_type_v1(content)
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException("User input did not match JSON schema")

    transaction_types.register_transaction_type_v1(content)
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #19
0
def create_bitcoin_transaction_v1(
        name: str) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")
    data = flask.request.json
    try:
        _validate_bitcoin_transaction_v1(data)
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException(
            "User input did not match JSON schema")

    return helpers.flask_http_response(
        200, interchain.sign_interchain_transaction_v1("bitcoin", name, data))
コード例 #20
0
ファイル: transactions.py プロジェクト: uningan/dragonchain
def post_transaction_v1(**kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    txn = flask.request.json

    try:
        _validate_txn_create_v1(txn)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    return helpers.flask_http_response(
        201, transactions.submit_transaction_v1(txn, flask.request.headers.get("X-Callback-URL"), api_key=kwargs["used_auth_key"])
    )
コード例 #21
0
def post_contract_v1() -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    contract = flask.request.json

    try:
        _validate_sc_create_v1(contract)
        if contract.get("custom_indexes"):
            helpers.verify_custom_indexes_options(contract.get("custom_indexes"))
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException("User input did not match JSON schema")

    return helpers.flask_http_response(202, smart_contracts.create_contract_v1(contract))
コード例 #22
0
ファイル: dragonnet.py プロジェクト: hewei-github/dragonchain
def enqueue_v1() -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    content = flask.request.json
    deadline = int(cast(str, flask.request.headers.get(
        "deadline"))) if flask.request.headers.get("deadline") else 30

    try:
        _validate_broadcast_schema_v1(content)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    dragonnet.enqueue_item_for_verification_v1(content, deadline)
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #23
0
def register_transaction_type_v1(**kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    content = flask.request.json

    try:
        _validate_create_txn_type_v1(content)
        if content.get("custom_indexes"):
            helpers.verify_custom_indexes_options(content["custom_indexes"])
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    transaction_types.register_transaction_type_v1(content)
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #24
0
ファイル: api_keys.py プロジェクト: hewei-github/dragonchain
def update_api_key_v1(key_id: str) -> Tuple[str, int, Dict[str, str]]:
    if not key_id:
        raise exceptions.ValidationException("Invalid parameter: key_id")

    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    body = flask.request.json

    try:
        _validate_api_key_update_v1(body)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    api_keys.update_api_key_v1(key_id, body["nickname"])
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #25
0
ファイル: dragonnet.py プロジェクト: hewei-github/dragonchain
def dragonnet_auth_v1() -> Tuple[str, int, Dict[str, str]]:
    """
    Create a new DragonNet interchain communication key pair with the requester (unauthenticated by design)
    """
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    body = flask.request.json

    try:
        _validate_interchain_auth_v1(body)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    dragonnet.register_interchain_auth_v1(body)
    return helpers.flask_http_response(201, helpers.format_success(True))
コード例 #26
0
def update_transaction_type_v1(txn_type: str) -> Tuple[str, int, Dict[str, str]]:
    if not txn_type:
        raise exceptions.ValidationException("Invalid parameter: txn_type")

    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    content = flask.request.json

    try:
        _validate_update_txn_type_v1(content)
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException("User input did not match JSON schema")

    transaction_types.update_transaction_type_v1(txn_type, content["custom_indexes"])
    return helpers.flask_http_response(200, helpers.format_success(True))
コード例 #27
0
def post_transaction_v1() -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    txn = flask.request.json

    try:
        _validate_txn_create_v1(txn)
    except fastjsonschema.JsonSchemaException:
        raise exceptions.ValidationException(
            "User input did not match JSON schema")

    return helpers.flask_http_response(
        201,
        transactions.submit_transaction_v1(
            txn, flask.request.headers.get("X-Callback-URL")))
コード例 #28
0
ファイル: api_keys.py プロジェクト: michaelberge8/dragonchain
def update_api_key_v1(key_id: str,
                      **kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not key_id:
        raise exceptions.ValidationException("Invalid parameter: key_id")

    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")

    body = flask.request.json

    try:
        _validate_api_key_update_v1(body)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    return helpers.flask_http_response(
        200,
        api_keys.update_api_key_v1(key_id, body.get("nickname"),
                                   body.get("permissions_document")))
コード例 #29
0
def list_sc_heap_v1(prefix_key: str) -> Tuple[str, int, Dict[str, str]]:
    """
    /v1/list/<prefix_key>
    method = GET
    path = '/' seperate string where the left side is the contract_id
            and the right side is an optional object key in the heap

            i.e. /v1/list/currency_contract/folder_in_heap (to search the folder_in_heap for a the currency_contract SC)
            i.e. /v1/list/a_contract/ (to list at the root of the heap for the a_contract SC)
    Get an array of keys from the smart contract heap in storage
    List storage keys under a prefix
    """
    initial_index = prefix_key.find("/")
    if initial_index == -1:
        raise exceptions.BadRequest(
            "Path must look like /v1/list/<contract_id>/<object_folder> or /v1/list/<contract_id>/ to search the root of the heap"
        )
    contract_id = prefix_key[:initial_index]
    path = prefix_key[initial_index:]
    return helpers.flask_http_response(200, smart_contracts.heap_list_v1(contract_id, path))
コード例 #30
0
ファイル: dragonnet.py プロジェクト: hewei-github/dragonchain
def get_claim_v1(block_id: str) -> Tuple[str, int, Dict[str, str]]:
    if not block_id:
        raise exceptions.BadRequest("block_id is required")

    return helpers.flask_http_response(200,
                                       dragonnet.get_local_claim_v1(block_id))