Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPLT-1027 Prod Release #97

Merged
merged 12 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ name: Rust
on:
push:
branches: [ main ]
paths:
- "indexer/**"
pull_request:
branches: [ main, staging, production ]
branches: [ main, stable ]
paths:
- "indexer/**"

env:
CARGO_TERM_COLOR: always
Expand All @@ -17,6 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Run check
working-directory: ./indexer
run: cargo check

rustfmt:
Expand All @@ -33,7 +38,7 @@ jobs:
profile: minimal
components: rustfmt
- name: Check formatting
- working-directory: ./indexer
working-directory: ./indexer
run: |
cargo fmt -- --check

Expand All @@ -51,6 +56,6 @@ jobs:
profile: minimal
components: clippy
- name: Clippy check
- working-directory: ./indexer
working-directory: ./indexer
run: |
cargo clippy
4 changes: 2 additions & 2 deletions .github/workflows/deploy-dev-widgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ on:
push:
branches: [main]
paths:
- "frontend/widgets/src/**"
- "frontend/widgets/**"
jobs:
deploy-mainnet:
uses: ./.github/workflows/deploy-widgets.yml
with:
directory-path: frontend/widgets/
directory-paths: ${{vars.WIDGETS_DIRECTORY_PATHS}}
deploy-account-address: ${{ vars.DEV_SIGNER_ACCOUNT_ID }}
signer-public-key: ${{ vars.DEV_SIGNER_PUBLIC_KEY }}
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-prod-widgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
deploy-mainnet:
uses: ./.github/workflows/deploy-widgets.yml
with:
directory-path: frontend/widgets/
directory-paths: ${{vars.WIDGETS_DIRECTORY_PATHS}}
deploy-account-address: ${{ vars.PROD_SIGNER_ACCOUNT_ID }}
signer-public-key: ${{ vars.PROD_SIGNER_PUBLIC_KEY }}
secrets:
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/deploy-widgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ on:
required: true
description: "Public key for signing transactions in the format: `ed25519:<public_key>`"
type: string
directory-path:
directory-paths:
required: true
description: "Path to the directory that contains the code to be deployed"
description: "Comma-separated paths to the directories that contain the code to be deployed"
type: string
secrets:
SIGNER_PRIVATE_KEY:
Expand All @@ -31,7 +31,7 @@ jobs:
BOS_DEPLOY_ACCOUNT_ID: ${{ inputs.deploy-account-address }}
BOS_SIGNER_PUBLIC_KEY: ${{ inputs.signer-public-key }}
BOS_SIGNER_PRIVATE_KEY: ${{ secrets.SIGNER_PRIVATE_KEY }}
DIRECTORY_PATH: ${{ inputs.directory-path }}
DIRECTORY_PATHS: ${{ inputs.directory-paths }}

steps:
- name: Checkout repository
Expand All @@ -43,5 +43,9 @@ jobs:

- name: Deploy widgets
run: |
cd $DIRECTORY_PATH
bos components deploy "$BOS_DEPLOY_ACCOUNT_ID" sign-as "$BOS_DEPLOY_ACCOUNT_ID" network-config mainnet sign-with-plaintext-private-key --signer-public-key "$BOS_SIGNER_PUBLIC_KEY" --signer-private-key "$BOS_SIGNER_PRIVATE_KEY" send
for DIR in $(echo $DIRECTORY_PATHS | tr "," "\n")
do
cd "$DIR"
bos components deploy "$BOS_DEPLOY_ACCOUNT_ID" sign-as "$BOS_DEPLOY_ACCOUNT_ID" network-config mainnet sign-with-plaintext-private-key --signer-public-key "$BOS_SIGNER_PUBLIC_KEY" --signer-private-key "$BOS_SIGNER_PRIVATE_KEY" send
cd -
done
79 changes: 65 additions & 14 deletions frontend/src/components/Editor/BlockPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import {
Badge,
InputGroup,
FormControl,
Dropdown,
ButtonGroup,
} from "react-bootstrap";

import { Play, Plus } from "react-bootstrap-icons";
import { Play, Plus, Stop } from "react-bootstrap-icons";

export const BlockPicker = ({
heights = [],
setHeights,
executeIndexerFunction,
latestHeight,
isExecuting,
stopExecution,
}) => {
const [inputValue, setInputValue] = useState(String(latestHeight));

Expand All @@ -37,24 +41,71 @@ export const BlockPicker = ({
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
<Button variant="outline-secondary" onClick={addHeight}>
<Plus size={24} style={{ cursor: "pointer" }} />
</Button>
<OverlayTrigger
{isExecuting === true &&
<OverlayTrigger
placement="bottom"
overlay={<Tooltip>Stop Indexer Execution</Tooltip>}
>
<Button variant="outline-secondary" onClick={() => stopExecution()}>
<Stop size={24} style={{ cursor: "pointer" }} />
</Button>
</OverlayTrigger>
}
{!isExecuting && (<> <OverlayTrigger
placement="bottom"
overlay={<Tooltip>Test Indexer Function In Browser</Tooltip>}
overlay={<Tooltip>Add Block To Debug List</Tooltip>}
>
<Button
className="mx-2"
size="sm"
variant="primary"
onClick={() => executeIndexerFunction()}
>
<Play size={24} />
<Button variant="outline-secondary" onClick={addHeight}>
<Plus size={24} style={{ cursor: "pointer" }} />
</Button>
</OverlayTrigger>
<Dropdown as={ButtonGroup}>
<OverlayTrigger
placement="bottom"
overlay={<Tooltip>
{
(() => {
if (heights.length > 0) {
return "Test Indexer Function With Debug List"
} else if (inputValue) {
return "Test Indexer Function With Specific Block"
} else {
return "Follow the Tip of the Network"
}
})()
}
</Tooltip>}
>

<Button
size="sm"
variant="primary"
onClick={() => {
if (heights.length > 0) {
executeIndexerFunction("debugList")
} else if (inputValue) {
executeIndexerFunction("specific", inputValue)
} else {
executeIndexerFunction("latest")
}
}
}
>
<Play size={24} />
</Button>
</OverlayTrigger>
<Dropdown.Toggle split variant="primary" id="dropdown-split-basic" />
<Dropdown.Menu>
<Dropdown.Item onClick={() => executeIndexerFunction("latest")}>Follow The Network</Dropdown.Item>
<Dropdown.Item disabled={heights.length === 0} onClick={() => executeIndexerFunction("debugList")}>Execute From Debug List</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</>)
}


</InputGroup>
</div>
</div>
</div >
);
};
59 changes: 43 additions & 16 deletions frontend/src/components/Editor/Editor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useCallback } from "react";
import React, { useEffect, useState, useCallback, useMemo } from "react";
import {
formatSQL,
formatIndexingCode,
Expand All @@ -16,11 +16,10 @@ import { ResetChangesModal } from "../Modals/resetChanges";
import { FileSwitcher } from "./FileSwitcher";
import EditorButtons from "./EditorButtons";
import { PublishModal } from "../Modals/PublishModal";
import {getLatestBlockHeight} from "../../utils/getLatestBlockHeight";
const BLOCKHEIGHT_LIMIT = 3600;
import { validateContractId } from "../../utils/validators"

const contractRegex = RegExp(
"^(([a-zd]+[-_])*[a-zd]+.)*([a-zd]+[-_])*[a-zd]+$"
);

const Editor = ({
options,
Expand All @@ -29,14 +28,15 @@ const Editor = ({
onLoadErrorText,
actionButtonText,
}) => {
const DEBUG_LIST_STORAGE_KEY = `QueryAPI:debugList:${accountId}#${indexerName}`
const [error, setError] = useState(undefined);
const [blockHeightError, setBlockHeightError] = useState(undefined);
const [showResetCodeModel, setShowResetCodeModel] = useState(false);
const [fileName, setFileName] = useState("indexingLogic.js");
const [originalSQLCode, setOriginalSQLCode] = useState(defaultSchema);
const [originalIndexingCode, setOriginalIndexingCode] = useState(defaultCode);
const [debugMode, setDebugMode] = useState(false);
const [heights, setHeights] = useState([]);
const [heights, setHeights] = useState(localStorage.getItem(DEBUG_LIST_STORAGE_KEY) || []);
const [showPublishModal, setShowPublishModal] = useState(false);
const [debugModeInfoDisabled, setDebugModeInfoDisabled] = useState(false);
const handleLog = (blockHeight, log, callback) => {
Expand All @@ -46,7 +46,7 @@ const Editor = ({
}
};

const indexerRunner = new IndexerRunner(handleLog);
const indexerRunner = useMemo(() => new IndexerRunner(handleLog), []);

const [indexingCode, setIndexingCode] = useState(defaultCode);
const [schema, setSchema] = useState(defaultSchema);
Expand All @@ -59,6 +59,12 @@ const Editor = ({
const [isContractFilterValid, setIsContractFilterValid] = useState(true);
const [contractFilter, setContractFilter] = useState("social.near");
const { height, selectedTab, currentUserAccountId } = useInitialPayload();
const [isExecutingIndexerFunction, setIsExecutingIndexerFunction] = useState(false)

const requestLatestBlockHeight = async () => {
const blockHeight = getLatestBlockHeight()
return blockHeight
}

const handleOptionChange = (event) => {
setSelectedOption(event.target.value);
Expand All @@ -71,6 +77,10 @@ const Editor = ({
}
}, [selectedTab]);

useEffect(() => {
localStorage.setItem(DEBUG_LIST_STORAGE_KEY, heights);
}, [heights]);

useEffect(() => {
if (selectedOption == "latestBlockHeight") {
setBlockHeightError(null);
Expand Down Expand Up @@ -287,22 +297,37 @@ const Editor = ({
}

function handleSetContractFilter(e) {
// check if contract filter is greater than 2 and less than or equal to 64 chars
const contractFilter = e.target.value;
setContractFilter(contractFilter);
if (
contractFilter.length > 64 ||
contractFilter.length < 2 ||
!contractRegex.test(contractFilter)
) {
setIsContractFilterValid(false);
} else {
const isValid = validateContractId(contractFilter);

if (isValid) {
setIsContractFilterValid(true);
} else {
setIsContractFilterValid(false);
}
}

async function executeIndexerFunction() {
await indexerRunner.executeIndexerFunction(heights,indexingCode)
async function executeIndexerFunction(option = "latest", startingBlockHeight = null) {
setIsExecutingIndexerFunction(() => true)

switch (option) {
case "debugList":
await indexerRunner.executeIndexerFunctionOnHeights(heights, indexingCode, option)
break
case "specific":
if (startingBlockHeight === null && Number(startingBlockHeight) === 0) {
console.log("Invalid Starting Block Height: starting block height is null or 0")
break
}

await indexerRunner.start(startingBlockHeight, indexingCode, option)
break
case "latest":
const latestHeight = await requestLatestBlockHeight()
if (latestHeight) await indexerRunner.start(latestHeight - 10, indexingCode, option)
}
setIsExecutingIndexerFunction(() => false)
}

return (
Expand Down Expand Up @@ -331,6 +356,8 @@ const Editor = ({
debugMode={debugMode}
heights={heights}
setHeights={setHeights}
isExecuting={isExecutingIndexerFunction}
stopExecution={() => indexerRunner.stop()}
contractFilter={contractFilter}
handleSetContractFilter={handleSetContractFilter}
isContractFilterValid={isContractFilterValid}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/Editor/EditorButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const EditorButtons = ({
getActionButtonText,
submit,
debugMode,
isExecuting,
stopExecution,
heights,
setHeights,
setShowPublishModal,
Expand Down Expand Up @@ -104,6 +106,8 @@ const EditorButtons = ({
setHeights={setHeights}
executeIndexerFunction={executeIndexerFunction}
latestHeight={latestHeight}
isExecuting={isExecuting}
stopExecution={stopExecution}
/>
)}
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const BlockHeightOptions = ({
<Form.Control
value={contractFilter}
onChange={handleSetContractFilter}
isValid={isContractFilterValid}
type="text"
placeholder="social.near"
required={true}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ overrideLocalStorage();

export default function App({ Component, pageProps }: AppProps) {
return (
<NearSocialBridgeProvider fallback={<Spinner />}>
<NearSocialBridgeProvider waitForStorage fallback={<Spinner />}>
<Component {...pageProps} />
</NearSocialBridgeProvider>
);
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/utils/fetchBlock.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const BLOCK_FETCHER_API =
"https://70jshyr5cb.execute-api.eu-central-1.amazonaws.com/block/";

const GENESIS_BLOCK_HEIGHT = 52945886;
export async function fetchBlockDetails(blockHeight) {
try {
const response = await fetch(
`${BLOCK_FETCHER_API}${String(blockHeight)}`
);
const block_details = await response.json();
return block_details;
} catch {
console.log(`Error Fetching Block Height details at ${blockHeight}`);
}
if (blockHeight <= GENESIS_BLOCK_HEIGHT) {
throw new Error(`Block Height must be greater than genesis block height #${GENESIS_BLOCK_HEIGHT}`);
}
try {
const response = await fetch(
`${BLOCK_FETCHER_API}${String(blockHeight)}`
);
const block_details = await response.json();
return block_details;
} catch {
// console.log(`Error Fetching Block Height details at ${blockHeight}`);
throw new Error(`Error Fetching Block Height details at BlockHeight #${blockHeight}`);
}
}
Loading