Skip to content

Commit

Permalink
refactor: Query/handle new registry types
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Feb 20, 2024
1 parent 7e56f93 commit 5d04394
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/Editor/EditorButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const EditorButtons = ({
<InputGroup.Text> Contract Filter</InputGroup.Text>
<Form.Control
disabled={!isCreateNewIndexer}
value={indexerDetails.config.filter}
value={indexerDetails.rule.affected_account_id}
type="text"
placeholder="social.near"
required={true}
Expand Down
24 changes: 18 additions & 6 deletions frontend/src/components/Form/IndexerConfigOptionsInputGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,32 @@ const IndexerConfigOptions = ({ updateConfig }) => {
const [blockHeightError, setBlockHeightError] = useState(null)

useEffect(() => {
if (indexerDetails.config?.startBlockHeight) {
if (indexerDetails.rule?.affected_account_id) {
setContractFilter(indexerDetails.rule.affected_account_id)
}

if (indexerDetails.startBlock?.HEIGHT) {
setStartBlock(START_BLOCK.HEIGHT)
setBlockHeight(indexerDetails.config.startBlockHeight)
setBlockHeight(indexerDetails.startBlock.HEIGHT)
return;
}
if (indexerDetails.config?.filter) {
setContractFilter(indexerDetails.config.filter)

if (indexerDetails.startBlock == "LATEST") {
setStartBlock(START_BLOCK.LATEST)
return;
}

if (indexerDetails.startBlock == "CONTINUE") {
setStartBlock(START_BLOCK.CONTINUE)
return;
}
}, [indexerDetails])

const onChangeStartBlock = (e) => {
setStartBlock(e.target.value)

if (e.target.value === START_BLOCK.CONTINUE) {
handleSetContractFilter(indexerDetails.config.filter)
handleSetContractFilter(indexerDetails.rule.affected_account_id)
}
}

Expand Down Expand Up @@ -110,7 +122,7 @@ const IndexerConfigOptions = ({ updateConfig }) => {
<InputGroup size="sm" hasValidation={true} className="pt-3">
<InputGroup.Text>Contract Filter</InputGroup.Text>
<Form.Control
value={startBlock === START_BLOCK.CONTINUE ? indexerDetails.config.filter : contractFilter}
value={startBlock === START_BLOCK.CONTINUE ? indexerDetails.rule.affected_account_id : contractFilter}
onChange={(e) => handleSetContractFilter(e.target.value)}
isValid={isContractFilterValid}
type="text"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Logs/LogButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const LogButtons = ({
<InputGroup size="sm" style={{ width: "fit-content" }}>
<InputGroup.Text> Contract Filter</InputGroup.Text>
<Form.Control
value={indexerDetails.config.filter}
value={indexerDetails.rule.affected_account_id}
disabled={true}
type="text"
placeholder="social.near"
Expand Down
12 changes: 5 additions & 7 deletions frontend/src/contexts/IndexerDetailsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getLatestBlockHeight } from "../utils/getLatestBlockHeight";
// }

export const IndexerDetailsContext = React.createContext({
indexerDetails: { code: undefined, schema: undefined, config: { filter: "social.near", startBlockHeight: null }, accountId: "", indexerName: "" },
indexerDetails: { code: undefined, schema: undefined, rule: { affected_account_id: "social.near" }, startBlock: "LATEST", accountId: "", indexerName: "" },
showResetCodeModel: false,
setShowResetCodeModel: () => { },
showPublishModal: false,
Expand Down Expand Up @@ -65,16 +65,13 @@ export const IndexerDetailsProvider = ({ children }) => {
const requestIndexerDetails = async () => {
const data = await queryIndexerFunctionDetails(accountId, indexerName);
if (data) {
const indexerConfig = {
startBlockHeight: data.start_block_height,
filter: data.filter.matching_rule.affected_account_id,
}
const details = {
accountId: accountId,
indexerName: indexerName,
code: wrapCode(data.code),
schema: data.schema,
config: indexerConfig
startBlock: data.start_block,
rule: data.rule
}
return details
}
Expand Down Expand Up @@ -102,7 +99,8 @@ export const IndexerDetailsProvider = ({ children }) => {
indexerName: indexer.indexerName,
code: indexer.code,
schema: indexer.schema,
config: indexer.config
startBlock: indexer.startBlock,
rule: indexer.rule
}
setIndexerDetails(details);
})();
Expand Down
18 changes: 12 additions & 6 deletions frontend/src/utils/queryIndexerFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ const provider = new providers.JsonRpcProvider(
);

export const queryIndexerFunctionDetails = async (accountId, functionName) => {
let args = { account_id: accountId, function_name: functionName };
let args = { account_id: accountId };

try {
const result = await provider.query({
request_type: "call_function",
account_id: REGISTRY_CONTRACT,
method_name: "read_indexer_function",
// TODO Create method to query single indexer
method_name: "list_by_account",
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
finality: "optimistic",
});
return (
result.result &&

const indexers = result.result &&
result.result.length > 0 &&
JSON.parse(Buffer.from(result.result).toString())
);
JSON.parse(Buffer.from(result.result).toString());

if (!indexers) {
return null;
}

return indexers[functionName];
} catch (error) {
console.log(`Could not query indexer function details from registry ${REGISTRY_CONTRACT}, for ${accountId}/${functionName}`)
console.log(error, "error");
Expand Down

0 comments on commit 5d04394

Please sign in to comment.