Skip to content

Commit

Permalink
fix(bindings): building package (#1113)
Browse files Browse the repository at this point in the history
Description
---
[Tari.js](https://github.com/tari-project/tari.js) is depending on this
package but after inspecting it's dependencies I found issues with
bindings package like incorrect package.json deceleration and project
structure.

Motivation and Context
---
This PR is necessary to also fix Tari.js which throws errors in others
project depending on it with error message that Tari.js is missing types
declarations.

How Has This Been Tested?
---
Locally build bindings and imported it to local Tari.js and after that
imported Tari.js to the
[Tari-Universe](https://github.com/tari-project/tari-universe) and
checked if application was working as expected.

What process can a PR reviewer use to test or verify this change?
---
Build it locally with `npm run build` command and use it as dependency
in other projects.


Breaking Changes
---

- [ ] None
- [ ] Requires data directory to be deleted
- [x] Other - Please specify

Some types have changed their name to distinguish from each other and
everything now it's exported directly from main file `index.ts` so
imports like
```ts
import type { ComponentAddressOrName } from "@tari-project/typescript-bindings/wallet-daemon-client";
```
should be now:
```ts
import type { ComponentAddressOrName } from "@tari-project/typescript-bindings";
```
  • Loading branch information
MCozhusheck authored Aug 9, 2024
1 parent 001f797 commit 3db6653
Show file tree
Hide file tree
Showing 78 changed files with 786 additions and 516 deletions.
2 changes: 1 addition & 1 deletion applications/tari_indexer_web_ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { TextField } from "@mui/material";
import { Form } from "react-router-dom";
import Fade from "@mui/material/Fade";
import CopyToClipboard from "../../../Components/CopyToClipboard";
import type { Connection } from "@tari-project/typescript-bindings/tari-indexer-client";
import type { IndexerConnection } from "@tari-project/typescript-bindings";
import { displayDuration } from "../../../utils/helpers";


Expand All @@ -60,7 +60,7 @@ const useInterval = (fn: () => Promise<unknown>, ms: number) => {
};

function Connections() {
const [connections, setConnections] = useState<Array<Connection>>([]);
const [connections, setConnections] = useState<Array<IndexerConnection>>([]);
const [showPeerDialog, setShowAddPeerDialog] = useState(false);
const [formState, setFormState] = useState({ publicKey: "", address: "" });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableRow from "@mui/material/TableRow";
import { DataTableCell } from "../../../Components/StyledComponents";
import type { GetIdentityResponse } from "@tari-project/typescript-bindings/tari-indexer-client";
import type { IndexerGetIdentityResponse } from "@tari-project/typescript-bindings";

function Info({ identity }: { identity: GetIdentityResponse }) {
function Info({ identity }: { identity: IndexerGetIdentityResponse }) {
return (
<div>
<TableContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useEffect, useState } from "react";
import { getNonFungibles } from "../../../utils/json_rpc";
import { useParams } from "react-router-dom";
import { ImageList, ImageListItem, ImageListItemBar } from "@mui/material";
import type { NonFungibleSubstate } from "@tari-project/typescript-bindings/tari-indexer-client";
import type { NonFungibleSubstate } from "@tari-project/typescript-bindings";

interface IImageData {
img: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import "./ValidatorNode.css";
import { StyledPaper } from "../../Components/StyledComponents";
import Grid from "@mui/material/Grid";
import SecondaryHeading from "../../Components/SecondaryHeading";
import type { GetIdentityResponse } from "@tari-project/typescript-bindings/tari-indexer-client";
import type { IndexerGetIdentityResponse } from "@tari-project/typescript-bindings";

function ValidatorNode() {
const [identity, setIdentity] = useState<GetIdentityResponse>();
const [identity, setIdentity] = useState<IndexerGetIdentityResponse>();
const [error, setError] = useState("");
// Initial fetch
useEffect(() => {
Expand Down
40 changes: 20 additions & 20 deletions applications/tari_indexer_web_ui/src/utils/json_rpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import type {
AddPeerRequest,
AddPeerResponse,
GetAllVnsResponse,
GetCommsStatsResponse,
GetConnectionsResponse,
IndexerAddPeerRequest,
IndexerAddPeerResponse,
IndexerGetAllVnsResponse,
IndexerGetCommsStatsResponse,
IndexerGetConnectionsResponse,
GetEpochManagerStatsResponse,
GetIdentityResponse,
IndexerGetIdentityResponse,
GetNonFungibleCollectionsResponse,
GetNonFungibleCountRequest,
GetNonFungibleCountResponse,
GetNonFungiblesRequest,
GetNonFungiblesResponse,
GetRelatedTransactionsRequest,
GetRelatedTransactionsResponse,
GetSubstateRequest,
GetSubstateResponse,
GetTransactionResultRequest,
GetTransactionResultResponse,
IndexerGetSubstateRequest,
IndexerGetSubstateResponse,
IndexerGetTransactionResultRequest,
IndexerGetTransactionResultResponse,
InspectSubstateRequest,
InspectSubstateResponse,
SubmitTransactionResponse,
} from "@tari-project/typescript-bindings/tari-indexer-client";
IndexerSubmitTransactionResponse,
} from "@tari-project/typescript-bindings";

async function jsonRpc(method: string, params: any = null) {
let id = 0;
Expand Down Expand Up @@ -76,24 +76,24 @@ async function jsonRpc(method: string, params: any = null) {
}

export const getOpenRpcSchema = (): Promise<string> => jsonRpc("rpc.discover");
export const getIdentity = (): Promise<GetIdentityResponse> => jsonRpc("get_identity");
export const getAllVns = (epoch: number): Promise<GetAllVnsResponse> => jsonRpc("get_all_vns", { epoch });
export const addPeer = (request: AddPeerRequest): Promise<AddPeerResponse> => jsonRpc("add_peer", request);
export const getCommsStats = (): Promise<GetCommsStatsResponse> => jsonRpc("get_comms_stats");
export const getSubstate = (request: GetSubstateRequest): Promise<GetSubstateResponse> =>
export const getIdentity = (): Promise<IndexerGetIdentityResponse> => jsonRpc("get_identity");
export const getAllVns = (epoch: number): Promise<IndexerGetAllVnsResponse> => jsonRpc("get_all_vns", { epoch });
export const addPeer = (request: IndexerAddPeerRequest): Promise<IndexerAddPeerResponse> => jsonRpc("add_peer", request);
export const getCommsStats = (): Promise<IndexerGetCommsStatsResponse> => jsonRpc("get_comms_stats");
export const getSubstate = (request: IndexerGetSubstateRequest): Promise<IndexerGetSubstateResponse> =>
jsonRpc("get_substate", request);
export const inspectSubstate = (request: InspectSubstateRequest): Promise<InspectSubstateResponse> =>
jsonRpc("inspect_substate", request);
export const getConnections = (): Promise<GetConnectionsResponse> => jsonRpc("get_connections");
export const getConnections = (): Promise<IndexerGetConnectionsResponse> => jsonRpc("get_connections");
export const getNonFungibleCollections = (): Promise<GetNonFungibleCollectionsResponse> =>
jsonRpc("get_non_fungible_collections");
export const getNonFungibleCount = (request: GetNonFungibleCountRequest): Promise<GetNonFungibleCountResponse> =>
jsonRpc("get_non_fungible_count", request);
export const getNonFungibles = (request: GetNonFungiblesRequest): Promise<GetNonFungiblesResponse> =>
jsonRpc("get_non_fungibles", request);
export const submitTransaction = (request: GetNonFungiblesRequest): Promise<SubmitTransactionResponse> =>
export const submitTransaction = (request: GetNonFungiblesRequest): Promise<IndexerSubmitTransactionResponse> =>
jsonRpc("submit_transaction", request);
export const getTransactionResult = (request: GetTransactionResultRequest): Promise<GetTransactionResultResponse> =>
export const getTransactionResult = (request: IndexerGetTransactionResultRequest): Promise<IndexerGetTransactionResultResponse> =>
jsonRpc("get_transaction_result", request);
export const getSubstateTransactions = (
request: GetRelatedTransactionsRequest,
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_validator_node_web_ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions applications/tari_validator_node_web_ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ import { createContext, useState, useEffect } from "react";
import { getEpochManagerStats, getIdentity, getShardKey } from "./utils/json_rpc";
import TransactionDetails from "./routes/Transactions/TransactionDetails";
import BlockDetails from "./routes/Blocks/BlockDetails";
import type {
GetEpochManagerStatsResponse,
GetIdentityResponse,
} from "@tari-project/typescript-bindings/validator-node-client";
import type { GetEpochManagerStatsResponse, VNGetIdentityResponse } from "@tari-project/typescript-bindings";

interface IContext {
epoch?: GetEpochManagerStatsResponse;
identity?: GetIdentityResponse;
identity?: VNGetIdentityResponse;
shardKey?: string | null;
error?: string;
}
Expand Down Expand Up @@ -126,7 +123,7 @@ export const breadcrumbRoutes = [

export default function App() {
const [epoch, setEpoch] = useState<GetEpochManagerStatsResponse | undefined>(undefined);
const [identity, setIdentity] = useState<GetIdentityResponse | undefined>(undefined);
const [identity, setIdentity] = useState<VNGetIdentityResponse | undefined>(undefined);
const [shardKey, setShardKey] = useState<string | null>(null);
const [error, setError] = useState("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { getBlock, getIdentity } from "../../utils/json_rpc";
import Transactions from "./Transactions";
import { primitiveDateTimeToDate, primitiveDateTimeToSecs } from "../../utils/helpers";
import type { Block, TransactionAtom } from "@tari-project/typescript-bindings";
import type { GetIdentityResponse } from "@tari-project/typescript-bindings/validator-node-client";
import type { VNGetIdentityResponse } from "@tari-project/typescript-bindings";

export default function BlockDetails() {
const { blockId } = useParams();
Expand All @@ -48,7 +48,7 @@ export default function BlockDetails() {
const [localPrepared, setLocalPrepared] = useState<TransactionAtom[]>([]);
const [accept, setAccept] = useState<TransactionAtom[]>([]);
const [epochEvents, setEpochEvents] = useState<string[]>([]);
const [identity, setIdentity] = useState<GetIdentityResponse>();
const [identity, setIdentity] = useState<VNGetIdentityResponse>();
const [blockTime, setBlockTime] = useState<number>(0);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import IconButton from "@mui/material/IconButton";
import Collapse from "@mui/material/Collapse";
import { Typography } from "@mui/material";
import ManageSearchOutlinedIcon from "@mui/icons-material/ManageSearchOutlined";
import type { ValidatorNode } from "@tari-project/typescript-bindings/validator-node-client";
import type { ValidatorNode } from "@tari-project/typescript-bindings";

function Committee({
begin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import TablePagination from "@mui/material/TablePagination";
import { Typography } from "@mui/material";
import CommitteesWaterfall from "./CommitteesWaterfall";
import { emptyRows } from "../../utils/helpers";
import type { CommitteeShardInfo } from "@tari-project/typescript-bindings/validator-node-client";
import type { VNCommitteeShardInfo } from "@tari-project/typescript-bindings";

function Committees({ committees, peerId }: { committees: CommitteeShardInfo[] | null; peerId: string }) {
function Committees({ committees, peerId }: { committees: VNCommitteeShardInfo[] | null; peerId: string }) {
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import CommitteesRadial from "./CommitteesRadial";
import CommitteesPieChart from "./CommitteesPieChart";
import { getNetworkCommittees } from "../../utils/json_rpc";
import type {
CommitteeShardInfo,
VNCommitteeShardInfo,
GetNetworkCommitteeResponse,
} from "@tari-project/typescript-bindings/validator-node-client";
} from "@tari-project/typescript-bindings";

function CommitteesLayout() {
const [committees, setCommittees] = useState<GetNetworkCommitteeResponse | null>(null);
Expand Down Expand Up @@ -63,18 +63,18 @@ function CommitteesLayout() {
Current epoch: {epoch.current_epoch}
<br />
Total number of validators:{" "}
{committees.committees.reduce((acc: number, info: CommitteeShardInfo) => acc + info.validators.length, 0)}
{committees.committees.reduce((acc: number, info: VNCommitteeShardInfo) => acc + info.validators.length, 0)}
<br />
Total buckets: {committees.committees.length}
<br />
Min committee size:{" "}
{committees.committees
.map((vn: CommitteeShardInfo) => vn.validators.length)
.map((vn: VNCommitteeShardInfo) => vn.validators.length)
.reduce((acc, curr) => Math.min(acc, curr), 100000)}
<br />
Max committee size:{" "}
{committees.committees
.map((vn: CommitteeShardInfo) => vn.validators.length)
.map((vn: VNCommitteeShardInfo) => vn.validators.length)
.reduce((acc, curr) => Math.max(acc, curr), 0)}
</StyledPaper>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { useState, useEffect } from "react";
import EChartsReact from "echarts-for-react";
import "../../theme/echarts.css";
import type {
CommitteeShardInfo,
VNCommitteeShardInfo,
GetNetworkCommitteeResponse,
} from "@tari-project/typescript-bindings/validator-node-client";
} from "@tari-project/typescript-bindings";

interface IData {
value: number;
Expand All @@ -41,7 +41,7 @@ const MyChartComponent = ({ chartData }: MyChartComponentProps) => {
const [titles, setTitles] = useState<string[]>([]);

useEffect(() => {
const mappedTitles = chartData.committees.map((shardInfo: CommitteeShardInfo) => {
const mappedTitles = chartData.committees.map((shardInfo: VNCommitteeShardInfo) => {
return `${shardInfo.substate_address_range.start.slice(0, 6)}... - ${shardInfo.substate_address_range.end.slice(
0,
6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import EChartsReact from "echarts-for-react";
import { ICommitteeChart } from "../../utils/interfaces";
import "../../theme/echarts.css";
import type {
CommitteeShardInfo,
VNCommitteeShardInfo,
GetNetworkCommitteeResponse,
ValidatorNode,
} from "@tari-project/typescript-bindings/validator-node-client";
} from "@tari-project/typescript-bindings";

export default function CommitteesRadial({ committees }: { committees: GetNetworkCommitteeResponse }) {
const [chartData, setChartData] = useState<ICommitteeChart>({
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function CommitteesRadial({ committees }: { committees: GetNetwor
activeright: [],
};

dataset.forEach((data: CommitteeShardInfo) => {
dataset.forEach((data: VNCommitteeShardInfo) => {
const start = fromHexString(data.substate_address_range.start)[0];
const end = fromHexString(data.substate_address_range.end)[0];

Expand Down Expand Up @@ -91,7 +91,7 @@ export default function CommitteesRadial({ committees }: { committees: GetNetwor
}
});
setChartData(info);
const newTitles = dataset.map((info: CommitteeShardInfo) => `Committee ${info.shard}`);
const newTitles = dataset.map((info: VNCommitteeShardInfo) => `Committee ${info.shard}`);
setTitles(newTitles);
}, [committees]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import { fromHexString } from "../VN/Components/helpers";
import EChartsReact from "echarts-for-react";
import { ICommitteeChart } from "../../utils/interfaces";
import "../../theme/echarts.css";
import type { CommitteeShardInfo, ValidatorNode } from "@tari-project/typescript-bindings/validator-node-client";
import type { VNCommitteeShardInfo, ValidatorNode } from "@tari-project/typescript-bindings";

export default function CommitteesWaterfall({ committees }: { committees: CommitteeShardInfo[] }) {
export default function CommitteesWaterfall({ committees }: { committees: VNCommitteeShardInfo[] }) {
const [chartData, setChartData] = useState<ICommitteeChart>({
activeleft: [],
inactiveleft: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Typography from "@mui/material/Typography";
import TablePagination from "@mui/material/TablePagination";
import { DataTableCell } from "../../../Components/StyledComponents";
import { emptyRows } from "../../../utils/helpers";
import type { BaseLayerValidatorNode } from "@tari-project/typescript-bindings/base-node-client";
import type { BaseLayerValidatorNode } from "@tari-project/typescript-bindings";

function AllVNs({ epoch }: { epoch: number }) {
const [vns, setVns] = useState<BaseLayerValidatorNode[]>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import Filter from "../../../Components/Filter";
import Fade from "@mui/material/Fade";
import StatusChip from "../../../Components/StatusChip";
import { Ordering, type Block } from "@tari-project/typescript-bindings";
import type { GetIdentityResponse } from "@tari-project/typescript-bindings/validator-node-client";
import type { VNGetIdentityResponse } from "@tari-project/typescript-bindings";

function Blocks() {
const [blocks, setBlocks] = useState<Block[]>([]);
const [blocksCount, setBlocksCount] = useState(0);
const [lastSort, setLastSort] = useState({ column: "height", order: -1 });
const [identity, setIdentity] = useState<GetIdentityResponse>();
const [identity, setIdentity] = useState<VNGetIdentityResponse>();

const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { TextField } from "@mui/material";
import { Form } from "react-router-dom";
import Fade from "@mui/material/Fade";
import CopyToClipboard from "../../../Components/CopyToClipboard";
import type { Connection } from "@tari-project/typescript-bindings/validator-node-client";
import type { VNConnection } from "@tari-project/typescript-bindings";
import { displayDuration } from "../../../utils/helpers";

const useInterval = (fn: () => Promise<unknown>, ms: number) => {
Expand All @@ -59,7 +59,7 @@ const useInterval = (fn: () => Promise<unknown>, ms: number) => {
};

function Connections() {
const [connections, setConnections] = useState<Connection[]>([]);
const [connections, setConnections] = useState<VNConnection[]>([]);
const [showPeerDialog, setShowAddPeerDialog] = useState(false);
const [formState, setFormState] = useState({ publicKey: "", address: "" });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ import { DataTableCell } from "../../../Components/StyledComponents";
import { TextField } from "@mui/material";
import type {
GetEpochManagerStatsResponse,
GetIdentityResponse,
} from "@tari-project/typescript-bindings/validator-node-client";
VNGetIdentityResponse,
} from "@tari-project/typescript-bindings";

function Info({
epoch,
identity,
shardKey,
}: {
epoch: GetEpochManagerStatsResponse;
identity: GetIdentityResponse;
identity: VNGetIdentityResponse;
shardKey: string | null;
}) {
const [registering, setRegistering] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import { DataTableCell, BoxHeading, BoxHeading2 } from "../../../Components/Styl
import PageHeading from "../../../Components/PageHeading";
import Grid from "@mui/material/Grid";
import { StyledPaper } from "../../../Components/StyledComponents";
import { fromHexString } from "./helpers";
import type { ArgDef, GetTemplateResponse } from "@tari-project/typescript-bindings/validator-node-client";
import type { VNArgDef, GetTemplateResponse } from "@tari-project/typescript-bindings";

function TemplateFunctions() {
const { address } = useParams();
Expand Down Expand Up @@ -70,7 +69,7 @@ function TemplateFunctions() {
<DataTableCell style={{ textAlign: "left" }}>{fn.name}</DataTableCell>
<DataTableCell>
{fn.arguments
.map((a: ArgDef) => {
.map((a: VNArgDef) => {
return a.name + ":" + a.arg_type;
})
.join(", ")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Typography from "@mui/material/Typography";
import Fade from "@mui/material/Fade";
import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import { emptyRows } from "../../../utils/helpers";
import type { TemplateMetadata } from "@tari-project/typescript-bindings/validator-node-client";
import type { TemplateMetadata } from "@tari-project/typescript-bindings";

type ColumnKey = keyof TemplateMetadata;

Expand Down
Loading

0 comments on commit 3db6653

Please sign in to comment.