diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1b3f265d238f02ff8523cdd94ac9b6f9399936d0..5eff77bdccf7f81745e7674234c138e7efa80784 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,6 +39,8 @@ docker-build: echo -e "\e[0Ksection_start:$(date +%s):build[collapsed=true]\r\e[0KBaking image "$CI_REGISTRY_IMAGE:$TAG"..." scripts/build_instance.sh --progress=plain "$CI_PROJECT_DIR" echo "IMAGE_NAME=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" > docker-build.env + echo "Unique image tag:" + cat docker-build.env echo -e "\e[0Ksection_end:$(date +%s):build\r\e[0K" artifacts: reports: @@ -96,6 +98,7 @@ lint: scripts/run_instance.sh \ --image="$IMAGE_NAME" \ --api-endpoint="$API_ENDPOINT" \ + --hive-blog-api-endpoint="$HIVE_BLOG_API_ENDPOINT" \ --port=$PORT \ --name=$CONTAINER_NAME \ --detach @@ -111,6 +114,7 @@ staging:deploy: variables: PORT: 5000 API_ENDPOINT: http://192.168.4.250:3000 + HIVE_BLOG_API_ENDPOINT: https://api.hive.blog CONTAINER_NAME: block-explorer-ui environment: name: staging @@ -122,6 +126,7 @@ test:deploy: variables: PORT: 5001 API_ENDPOINT: http://192.168.6.7:3000 + HIVE_BLOG_API_ENDPOINT: https://api.hive.blog CONTAINER_NAME: block-explorer-ui-2 environment: name: test diff --git a/Config.ts b/Config.ts index 77d209aa101342a9d0a7e2e68e2a22687adf5e8f..a19fb77b1867fa40dcfcd0bdc51fb86ceac5e0f2 100644 --- a/Config.ts +++ b/Config.ts @@ -1,9 +1,8 @@ import env from "@beam-australia/react-env" export const config = { - hiveBlogAdress: "https://api.hive.blog", - // apiAdress: process.env.NEXT_PUBLIC_API_ADDRESS ? process.env.NEXT_PUBLIC_API_ADDRESS : "http://192.168.4.250:3000", - apiAdress: `${env('API_ADDRESS') ? env('API_ADDRESS') : 'http://192.168.4.250:3000'}`, + hiveBlogAddress: `${env('HIVE_BLOG_API_ADDRESS') ? env('HIVE_BLOG_API_ADDRESS') : 'https://api.hive.blog'}`, + apiAddress: `${env('API_ADDRESS') ? env('API_ADDRESS') : 'http://192.168.4.250:3000'}`, baseMomentTimeFormat: "YYYY/MM/DD hh:mm:ss", gitHash: process.env.NEXT_PUBLIC_COMMIT_HASH, opsBodyLimit: 100000, diff --git a/docker/.env b/docker/.env index ad2498bb17f59952a21841fed3db82fe29dfd75a..16cc684d1eec83f03f2f3e22a19f474cbcb31690 100644 --- a/docker/.env +++ b/docker/.env @@ -1,2 +1,3 @@ PORT=5000 -REACT_APP_API_ADDRESS=http://192.168.4.250:3000 \ No newline at end of file +REACT_APP_API_ADDRESS=http://192.168.4.250:3000 +REACT_APP_HIVE_BLOG_API_ADDRESS=https://api.deathwing.me \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index b26a45fd0b025281e66dd5a77358252ed3b70b49..1857ebcab690dc98c982709b850b92b1aa6e9d65 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -5,5 +5,6 @@ services: environment: PORT: REACT_APP_API_ADDRESS: + REACT_APP_HIVE_BLOG_API_ADDRESS: ports: - "${PORT}:${PORT}" \ No newline at end of file diff --git a/scripts/run_instance.sh b/scripts/run_instance.sh index fb98f1437b9bcd7ac2c908ce64de763d3c12aee2..5c35835ec087384291a1f49d9c8423264717819c 100755 --- a/scripts/run_instance.sh +++ b/scripts/run_instance.sh @@ -8,18 +8,20 @@ Usage: $0 [OPTION[=VALUE]]... Run a Block Explorer UI Docker instance OPTIONS: - --image=IMAGE Docker image to run (default: 'registry.gitlab.syncad.com/hive/block_explorer_ui:latest') - --api-endpoint=URL API endpoint to be used by the new instance (default: 'http://192.168.4.250:3000') - --port=PORT Port to be exposed (default: 5000) - --name=NAME Container name to be used (default: block_explorer_ui) - --detach Run in detached mode - --help|-h|-? Display this help screen and exit + --image=IMAGE Docker image to run (default: 'registry.gitlab.syncad.com/hive/block_explorer_ui:latest') + --api-endpoint=URL API endpoint to be used by the new instance (default: 'http://192.168.4.250:3000') + --hive-blog-api-endpoint=URL Hive Blog API endpoint to be used by the new instance (default: 'https://api.hive.blog') + --port=PORT Port to be exposed (default: 5000) + --name=NAME Container name to be used (default: block_explorer_ui) + --detach Run in detached mode + --help|-h|-? Display this help screen and exit EOF } IMAGE=${IMAGE:-"registry.gitlab.syncad.com/hive/block_explorer_ui:latest"} PORT=${PORT:-"5000"} API_ENDPOINT=${API_ENDPOINT:-"http://192.168.4.250:3000"} +HIVE_BLOG_API_ENDPOINT=${HIVE_BLOG_API_ENDPOINT:-"https://api.hive.blog"} CONTAINER_NAME=${CONTAINER_NAME:-"block_explorer_ui"} DETACH=${DETACH:-false} @@ -33,6 +35,10 @@ while [ $# -gt 0 ]; do arg="${1#*=}" API_ENDPOINT="$arg" ;; + --hive-blog-api-endpoint=*) + arg="${1#*=}" + HIVE_BLOG_API_ENDPOINT="$arg" + ;; --port=*) arg="${1#*=}" PORT="$arg" @@ -65,6 +71,7 @@ RUN_OPTIONS=( "--publish" "$PORT:$PORT" "--env" "PORT=$PORT" "--env" "REACT_APP_API_ADDRESS=$API_ENDPOINT" + "--env" "REACT_APP_HIVE_BLOG_API_ADDRESS=$HIVE_BLOG_API_ENDPOINT" "--name" "$CONTAINER_NAME" ) diff --git a/services/FetchingService.ts b/services/FetchingService.ts index 6a444f5ba8720f8e8cc2d47c25b700c3fd0c18d2..ffa0ee595ca1cf5070d70ac44f02eb434a6368dc 100644 --- a/services/FetchingService.ts +++ b/services/FetchingService.ts @@ -18,31 +18,31 @@ class FetchingService { } async getHeadBlockNum(): Promise<number> { - const url = `${config.apiAdress}/rpc/get_head_block_num`; + const url = `${config.apiAddress}/rpc/get_head_block_num`; return await this.makePostRequest(url, {}); } async getBlock(blockNumber: number): Promise<Hive.BlockDetails> { const requestBody: Hive.GetBlockProps = { _block_num: blockNumber }; - const url = `${config.apiAdress}/rpc/get_block`; + const url = `${config.apiAddress}/rpc/get_block`; return await this.makePostRequest(url, requestBody); } async getLastBlocks(limit: number): Promise<Hive.LastBlocksTypeResponse[]> { const requestBody: Hive.GetLatestBlocksProps = { _limit: limit }; - const url = `${config.apiAdress}/rpc/get_latest_blocks `; + const url = `${config.apiAddress}/rpc/get_latest_blocks `; return await this.makePostRequest(url, requestBody); } async getInputType(input: string): Promise<Hive.InputTypeResponse> { const requestBody: Hive.GetInputTypeProps = { _input: input }; - const url = `${config.apiAdress}/rpc/get_input_type`; + const url = `${config.apiAddress}/rpc/get_input_type`; return await this.makePostRequest(url, requestBody); } async getBlockOpTypes(blockNumber: number): Promise<Hive.OperationTypes[]> { const requestBody: Hive.GetBlockOpTypesProps = { _block_num: blockNumber }; - const url = `${config.apiAdress}/rpc/get_block_op_types`; + const url = `${config.apiAddress}/rpc/get_block_op_types`; return await this.makePostRequest(url, requestBody); } @@ -55,7 +55,7 @@ class FetchingService { _filter: filter, _body_limit: config.opsBodyLimit }; - const url = `${config.apiAdress}/rpc/get_ops_by_block`; + const url = `${config.apiAddress}/rpc/get_ops_by_block`; return await this.makePostRequest(url, requestBody); } async getTransaction( @@ -64,7 +64,7 @@ class FetchingService { const requestBody: Hive.GetTransactionProps = { _trx_hash: transactionHash, }; - const url = `${config.apiAdress}/rpc/get_transaction`; + const url = `${config.apiAddress}/rpc/get_transaction`; return await this.makePostRequest(url, requestBody); } @@ -74,7 +74,7 @@ class FetchingService { method: "database_api.get_reward_funds", id: 1, }; - const url = `${config.hiveBlogAdress}`; + const url = `${config.hiveBlogAddress}`; return await this.makePostRequest(url, requestBody); } @@ -84,7 +84,7 @@ class FetchingService { method: "database_api.get_dynamic_global_properties", id: 1, }; - const url = `${config.hiveBlogAdress}`; + const url = `${config.hiveBlogAddress}`; return await this.makePostRequest(url, requestBody); } @@ -94,13 +94,13 @@ class FetchingService { method: "database_api.get_current_price_feed", id: 1, }; - const url = `${config.hiveBlogAdress}`; + const url = `${config.hiveBlogAddress}`; return await this.makePostRequest(url, requestBody); } async getAccOpTypes(account: string): Promise<unknown> { const requestBody: Hive.GetAccOpTypesProps = { _account: account }; - const url = `${config.apiAdress}/rpc/get_acc_op_types`; + const url = `${config.apiAddress}/rpc/get_acc_op_types`; return await this.makePostRequest(url, requestBody); } @@ -118,7 +118,7 @@ class FetchingService { _date_end: accountOperationsProps.endDate, _body_limit: config.opsBodyLimit }; - const url = `${config.apiAdress}/rpc/get_ops_by_account`; + const url = `${config.apiAddress}/rpc/get_ops_by_account`; return await this.makePostRequest(url, requestBody); } @@ -130,13 +130,13 @@ class FetchingService { _account: account, _operations: operations, }; - const url = `${config.apiAdress}/rpc/get_account_operations_count`; + const url = `${config.apiAddress}/rpc/get_account_operations_count`; return await this.makePostRequest(url, requestBody); } async getAccount(account: string): Promise<unknown> { const requestBody: Hive.GetAccountProps = { _account: account }; - const url = `${config.apiAdress}/rpc/get_account`; + const url = `${config.apiAddress}/rpc/get_account`; return await this.makePostRequest(url, requestBody); } @@ -144,7 +144,7 @@ class FetchingService { const requestBody: Hive.GetAccountResourceCreditsProps = { _account: account, }; - const url = `${config.apiAdress}/rpc/get_account_resource_credits`; + const url = `${config.apiAddress}/rpc/get_account_resource_credits`; return await this.makePostRequest(url, requestBody); } @@ -152,7 +152,7 @@ class FetchingService { const requestBody: Hive.GetBtrackerAccountBalanceProps = { _account: account, }; - const url = `${config.apiAdress}/rpc/get_btracker_account_balance`; + const url = `${config.apiAddress}/rpc/get_btracker_account_balance`; return await this.makePostRequest(url, requestBody); } @@ -168,13 +168,13 @@ class FetchingService { _order_by: orderBy, _order_is: orderIs, }; - const url = `${config.apiAdress}/rpc/get_witnesses`; + const url = `${config.apiAddress}/rpc/get_witnesses`; return await this.makePostRequest(url, requestBody); } async getWitnessesVotersNum(witness: string): Promise<unknown> { const requestBody: Hive.GetWitnessVotersNumProps = { _witness: witness }; - const url = `${config.apiAdress}/rpc/get_witness_voters_num`; + const url = `${config.apiAddress}/rpc/get_witness_voters_num`; return await this.makePostRequest(url, requestBody); } @@ -190,7 +190,7 @@ class FetchingService { _order_is: orderIs, }; if (limit) requestBody._limit = limit; - const url = `${config.apiAdress}/rpc/get_witness_voters`; + const url = `${config.apiAddress}/rpc/get_witness_voters`; return await this.makePostRequest(url, requestBody); } @@ -200,7 +200,7 @@ class FetchingService { const requestBody: Hive.GetOperationTypesProps = { _operation_type_pattern: operation_type_pattern, }; - const url = `${config.apiAdress}/rpc/get_matching_operation_types`; + const url = `${config.apiAddress}/rpc/get_matching_operation_types`; return await this.makePostRequest(url, requestBody); } @@ -208,7 +208,7 @@ class FetchingService { const requestBody: Hive.GetWitnessProps = { _account: witnessName, }; - const url = `${config.apiAdress}/rpc/get_witness`; + const url = `${config.apiAddress}/rpc/get_witness`; return await this.makePostRequest(url, requestBody); } @@ -216,7 +216,7 @@ class FetchingService { const requestBody: Hive.GetBlockByTimeProps = { _timestamp: date, }; - const url = `${config.apiAdress}/rpc/get_block_by_time`; + const url = `${config.apiAddress}/rpc/get_block_by_time`; return await this.makePostRequest(url, requestBody); } @@ -224,7 +224,7 @@ class FetchingService { const requestBody: Hive.GetOperationKeysProps = { _op_type_id: operationTypeId, } - const url = `${config.apiAdress}/rpc/get_operation_keys `; + const url = `${config.apiAddress}/rpc/get_operation_keys `; return await this.makePostRequest(url, requestBody); } @@ -243,7 +243,7 @@ class FetchingService { _key_content: blockSearchProps.deepProps.content ? [blockSearchProps.deepProps.content] : undefined, _setof_keys: blockSearchProps.deepProps.keys ? [blockSearchProps.deepProps.keys] : undefined }; - const url = `${config.apiAdress}/rpc/get_block_by_op `; + const url = `${config.apiAddress}/rpc/get_block_by_op `; return await this.makePostRequest(url, requestBody); } @@ -263,7 +263,7 @@ class FetchingService { _from_time: fromTime, _to_time: toTime, }; - const url = `${config.apiAdress}/rpc/get_witness_votes_history `; + const url = `${config.apiAddress}/rpc/get_witness_votes_history `; return await this.makePostRequest(url, requestBody); } @@ -273,7 +273,7 @@ class FetchingService { const requestBody: Hive.GetOperationProps = { _operation_id: operationId }; - const url = `${config.apiAdress}/rpc/get_operation` + const url = `${config.apiAddress}/rpc/get_operation` return await this.makePostRequest(url, requestBody); } @@ -292,13 +292,13 @@ class FetchingService { _body_limit: config.opsBodyLimit, _page_size: config.standardPaginationSize }; - const url = `${config.apiAdress}/rpc/get_comment_operations` + const url = `${config.apiAddress}/rpc/get_comment_operations` return await this.makePostRequest(url, requestBody); } async getHafbeVersion(): Promise<string> { const requestBody = {}; - const url = `${config.apiAdress}/rpc/get_hafbe_version`; + const url = `${config.apiAddress}/rpc/get_hafbe_version`; return await this.makePostRequest(url, requestBody); }