Skip to content

Commit

Permalink
fix(transactions)!: adds versioned transaction schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Dec 23, 2024
1 parent dadfd5d commit 5ebacb5
Show file tree
Hide file tree
Showing 53 changed files with 803 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct ConcurrentMapSemaphoreGuard<'a, K: Hash + Eq> {
key: K,
}

impl<'a, K: Hash + Eq> ConcurrentMapSemaphoreGuard<'a, K> {
impl<K: Hash + Eq> ConcurrentMapSemaphoreGuard<'_, K> {
pub fn access(&self) -> MutexGuard<'_, ()> {
// Unwrap: only errors if the mutex is poisoned, which is a bug
self.map_mutex.lock().unwrap()
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_dan_wallet_cli/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Table<'t, 's> {
is_row_count_enabled: bool,
}

impl<'t, 's> Table<'t, 's> {
impl<'t> Table<'t, '_> {
pub fn new() -> Self {
Self {
titles: None,
Expand Down Expand Up @@ -141,7 +141,7 @@ impl<'t, 's> Table<'t, 's> {
}
}

impl<'t, 's> Default for Table<'t, 's> {
impl Default for Table<'_, '_> {
fn default() -> Self {
Self::new()
}
Expand Down
22 changes: 15 additions & 7 deletions applications/tari_dan_wallet_daemon/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ fn exit_on_ci() {
}
}

const BUILD: &[(&str, &str)] = &[
("../../bindings", "tsc"),
("../../clients/javascript/wallet_daemon_client", "build"),
("../tari_dan_wallet_web_ui", "build"),
const BUILD: &[(&str, &[&str])] = &[
("../../bindings", &["ci"]),
("../../bindings", &["run", "tsc"]),
("../../clients/javascript/wallet_daemon_client", &["ci"]),
("../../clients/javascript/wallet_daemon_client", &["run", "build"]),
("../tari_dan_wallet_web_ui", &["run", "build"]),
];

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -45,14 +47,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let npm = if cfg!(windows) { "npm.cmd" } else { "npm" };

for (target, build_cmd) in BUILD {
for (target, args) in BUILD {
if let Err(error) = Command::new(npm).arg("ci").current_dir(target).status() {
println!("cargo:warning='npm ci' error : {:?}", error);
exit_on_ci();
break;
}
match Command::new(npm).args(["run", build_cmd]).current_dir(target).output() {
match Command::new(npm).args(*args).current_dir(target).output() {
Ok(output) if !output.status.success() => {
println!("cargo:warning='npm run build' exited with non-zero status code");
println!(
"cargo:warning='npm {}' in {} exited with non-zero status code",
args.iter().map(|s| s.to_string()).collect::<Vec<_>>().join(" "),
target
);
println!("cargo:warning=Status: {}", output.status);
println!("cargo:warning=Output: {}", String::from_utf8_lossy(&output.stdout));
println!("cargo:warning=Error: {}", String::from_utf8_lossy(&output.stderr));
exit_on_ci();
Expand Down
29 changes: 17 additions & 12 deletions applications/tari_dan_wallet_web_ui/package-lock.json

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

6 changes: 3 additions & 3 deletions applications/tari_dan_wallet_web_ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@mui/x-data-grid": "^6.0.2",
"@tanstack/react-query": "^4.33.0",
"@tanstack/react-query-devtools": "^4.33.0",
"@tari-project/typescript-bindings": "^1.0.3",
"@tari-project/wallet_jrpc_client": "^1.0.8",
"@tari-project/typescript-bindings": "file:../../bindings",
"@tari-project/wallet_jrpc_client": "file:../../clients/javascript/wallet_jrpc_client",
"@walletconnect/core": "^2.13.3",
"@walletconnect/web3wallet": "^1.12.3",
"file-saver": "^2.0.5",
Expand All @@ -35,7 +35,7 @@
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react-swc": "^3.0.0",
"prettier": "^3.3.2",
"typescript": "^4.9.3",
"typescript": "^4.9.5",
"vite": "^4.5.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import React from "react";
import FetchStatusCheck from "./FetchStatusCheck";
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from "@mui/material";
import type { ListAccountNftResponse } from "@tari-project/typescript-bindings/wallet-daemon-client";
import type { apiError } from "../api/helpers/types";
import { DataTableCell } from "./StyledComponents";
import { renderJson, toHexString } from "../utils/helpers";
import { toHexString } from "../utils/helpers";
import { IoCheckmarkOutline, IoCloseOutline } from "react-icons/io5";
import type { NonFungibleId, NonFungibleToken } from "@tari-project/typescript-bindings";
import type { NonFungibleId, NonFungibleToken, ListAccountNftResponse } from "@tari-project/typescript-bindings";
import { convertCborValue } from "../utils/cbor";

function NftsList({ nft }: { nft: NonFungibleToken }) {
Expand Down Expand Up @@ -96,7 +95,7 @@ export default function NFTList(props: NftListProps) {
</TableRow>
</TableHead>
<TableBody>
{nftsListData?.nfts.map((nft: NonFungibleToken, index) => <NftsList key={index} nft={nft} />)}
{nftsListData?.nfts.map((nft: NonFungibleToken, index: number) => <NftsList key={index} nft={nft} />)}
</TableBody>
</Table>
</TableContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ import {
} from "../../utils/json_rpc";
import { apiError } from "../helpers/types";
import queryClient from "../queryClient";
import type { ComponentAccessRules, ConfidentialTransferInputSelection } from "@tari-project/typescript-bindings";
import type { ComponentAddressOrName } from "@tari-project/typescript-bindings/wallet-daemon-client";
import type {
ComponentAccessRules,
ConfidentialTransferInputSelection,
ComponentAddressOrName,
} from "@tari-project/typescript-bindings";

// Fees are passed as strings because Amount is tagged
export const useAccountsClaimBurn = (account: string, claimProof: string, fee: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ import TableCell from "@mui/material/TableCell";
import TableBody from "@mui/material/TableBody";
import { useParams } from "react-router-dom";
import { useAccountsGetBalances, useAccountsGet, useAccountNFTsList } from "../../api/hooks/useAccounts";
import { renderJson, shortenString } from "../../utils/helpers";
import { shortenString } from "../../utils/helpers";
import { DataTableCell } from "../../Components/StyledComponents";
import CopyToClipboard from "../../Components/CopyToClipboard";
import FetchStatusCheck from "../../Components/FetchStatusCheck";
import { substateIdToString } from "@tari-project/typescript-bindings";
import type { BalanceEntry } from "@tari-project/typescript-bindings/wallet-daemon-client";
import { IoCheckmarkOutline, IoCloseOutline } from "react-icons/io5";
import { substateIdToString, BalanceEntry } from "@tari-project/typescript-bindings";
import NFTList from "../../Components/NFTList";

function BalanceRow(props: BalanceEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ import { DataTableCell } from "../../../Components/StyledComponents";
import { useAccountNFTsList, useAccountsGetBalances } from "../../../api/hooks/useAccounts";
import useAccountStore from "../../../store/accountStore";
import { shortenString } from "../../../utils/helpers";
import type { BalanceEntry } from "@tari-project/typescript-bindings/wallet-daemon-client";
import NFTList from "../../../Components/NFTList";
import { Button } from "@mui/material";
import { SendMoneyDialog } from "./SendMoney";
import { ResourceAddress, ResourceType, VaultId } from "@tari-project/typescript-bindings";
import { ResourceAddress, ResourceType, VaultId, BalanceEntry } from "@tari-project/typescript-bindings";

interface TabPanelProps {
children?: React.ReactNode;
Expand Down Expand Up @@ -193,7 +192,7 @@ function Assets({ accountName }: { accountName: string }) {
token_symbol,
vault_address,
}: BalanceEntry,
i,
i: number,
) => (
<BalanceRow
key={i}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { useTheme } from "@mui/material/styles";
import { accountsClaimBurn } from "../../../utils/json_rpc";
import useAccountStore from "../../../store/accountStore";
import { useKeysList } from "../../../api/hooks/useKeys";
import type { AccountInfo } from "@tari-project/typescript-bindings/wallet-daemon-client";
import type { AccountInfo } from "@tari-project/typescript-bindings";

export default function ClaimBurn() {
const [open, setOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@
import { useState } from "react";
import { Form } from "react-router-dom";
import Button from "@mui/material/Button";
import CheckBox from "@mui/material/Checkbox";
import TextField from "@mui/material/TextField";
import Dialog from "@mui/material/Dialog";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import FormControlLabel from "@mui/material/FormControlLabel";
import Box from "@mui/material/Box";
import { useAccountsList, useAccountsTransfer } from "../../../api/hooks/useAccounts";
import { useAccountsList } from "../../../api/hooks/useAccounts";
import { useTheme } from "@mui/material/styles";
import useAccountStore from "../../../store/accountStore";
import { FormControl, InputLabel, MenuItem, Select, SelectChangeEvent } from "@mui/material";
import { useKeysList } from "../../../api/hooks/useKeys";
import { validatorsClaimFees } from "../../../utils/json_rpc";
import type { AccountInfo } from "@tari-project/typescript-bindings/wallet-daemon-client";
import type { AccountInfo } from "@tari-project/typescript-bindings";

export default function ClaimFees() {
const [open, setOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Select, { SelectChangeEvent } from "@mui/material/Select";
import Dialog from "./AddAccount";
import useAccountStore from "../../../store/accountStore";
import { useAccountsList } from "../../../api/hooks/useAccounts";
import type { AccountInfo } from "@tari-project/typescript-bindings/wallet-daemon-client";
import type { AccountInfo } from "@tari-project/typescript-bindings";

function SelectAccount() {
const { accountName, setAccountName } = useAccountStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
ResourceType,
ConfidentialTransferInputSelection,
TransactionResult,
BalanceEntry,
} from "@tari-project/typescript-bindings";
import InputLabel from "@mui/material/InputLabel";

Expand Down Expand Up @@ -98,8 +99,8 @@ export function SendMoneyDialog(props: SendMoneyDialogProps) {

const { data } = useAccountsGetBalances(accountName);
const badges = data?.balances
?.filter((b) => b.resource_type === "NonFungible" && b.balance > 0)
.map((b) => b.resource_address) as string[];
?.filter((b: BalanceEntry) => b.resource_type === "NonFungible" && b.balance > 0)
.map((b: BalanceEntry) => b.resource_address) as string[];

// TODO: we should have separate calls for confidential and non-confidential transfers
const { mutateAsync: sendIt } = useAccountsTransfer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Box from "@mui/material/Box";
import { useTheme } from "@mui/material/styles";
import { Divider } from "@mui/material";
import { confidentialViewVaultBalance } from "../../../utils/json_rpc";
import { ConfidentialViewVaultBalanceRequest } from "@tari-project/typescript-bindings/wallet-daemon-client";
import { ConfidentialViewVaultBalanceRequest } from "@tari-project/typescript-bindings";

function ViewVaultBalanceForm() {
const [formState, setFormState] = useState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default function TransactionDetails() {
const handleDownload = () => {
const json = JSON.stringify(data, null, 2);
const blob = new Blob([json], { type: "application/json" });
const filename = `tx-${data?.transaction?.id}.json` || "tx-unknown_id.json";
const filename = `tx-${data?.transaction?.V1?.id}.json` || "tx-unknown_id.json";
saveAs(blob, filename);
};

Expand All @@ -129,6 +129,8 @@ export default function TransactionDetails() {
}
};

const transaction = data.transaction.V1;

if (data.status === "Rejected" || data.status === "InvalidTransaction") {
return (
<>
Expand All @@ -137,7 +139,7 @@ export default function TransactionDetails() {
<TableBody>
<TableRow>
<TableCell>Transaction Hash</TableCell>
<DataTableCell>{data.transaction.id}</DataTableCell>
<DataTableCell>{transaction.id}</DataTableCell>
</TableRow>
<TableRow>
<TableCell>Timestamp</TableCell>
Expand Down Expand Up @@ -177,7 +179,7 @@ export default function TransactionDetails() {
<TableBody>
<TableRow>
<TableCell>Transaction Hash</TableCell>
<DataTableCell>{data.transaction.id}</DataTableCell>
<DataTableCell>{transaction.id}</DataTableCell>
</TableRow>
<TableRow>
<TableCell>Timestamp</TableCell>
Expand Down Expand Up @@ -258,8 +260,8 @@ export default function TransactionDetails() {
<Typography>Fee Instructions</Typography>
</AccordionSummary>
<AccordionDetails>
{data.transaction?.fee_instructions?.length ? (
<FeeInstructions data={data.transaction.fee_instructions} />
{transaction?.fee_instructions?.length ? (
<FeeInstructions data={transaction?.fee_instructions} />
) : (
<span>Empty</span>
)}
Expand All @@ -270,8 +272,8 @@ export default function TransactionDetails() {
<Typography>Instructions</Typography>
</AccordionSummary>
<AccordionDetails>
{data.transaction?.instructions?.length ? (
<Instructions data={data.transaction.instructions} />
{transaction?.instructions?.length ? (
<Instructions data={transaction.instructions} />
) : (
<span>Empty</span>
)}
Expand Down Expand Up @@ -312,11 +314,11 @@ export default function TransactionDetails() {
<Typography>Signers</Typography>
</AccordionSummary>
<AccordionDetails>
{data.transaction?.signatures?.length ? (
{transaction?.signatures?.length ? (
<TableContainer>
<Table>
<TableBody>
{data.transaction.signatures.map((item: TransactionSignature, i: number) => {
{transaction.signatures.map((item: TransactionSignature, i: number) => {
return (
<TableRow key={i}>
<DataTableCell>{item.public_key}</DataTableCell>
Expand Down
Loading

0 comments on commit 5ebacb5

Please sign in to comment.