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

fix(wallet): ensure assoc. resource address included for detect_inputs #1245

Merged
merged 1 commit into from
Jan 16, 2025
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
6 changes: 3 additions & 3 deletions applications/tari_dan_wallet_daemon/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ pub async fn handle_reveal_funds(
let account_substate = sdk.substate_api().get_substate(&account.address)?;
// Add all versioned account child addresses as inputs
let child_addresses = sdk.substate_api().load_dependent_substates(&[&account.address])?;
let mut inputs = vec![account_substate.address];
let mut inputs = vec![account_substate.substate_id];
inputs.extend(child_addresses);

let inputs = inputs
Expand Down Expand Up @@ -817,7 +817,7 @@ fn get_or_create_account<T: WalletStore>(
.key_manager_api()
.derive_key(key_manager::TRANSACTION_BRANCH, key_index)?;
let account_substate = sdk.substate_api().get_substate(&account.address)?;
inputs.push(account_substate.address.into());
inputs.push(account_substate.substate_id.into());

(account.address, account_secret_key, None)
},
Expand Down Expand Up @@ -863,7 +863,7 @@ pub async fn handle_transfer(
.accounts_api()
.get_vault_by_resource(&account.address, &req.resource_address)?;
let src_vault_substate = sdk.substate_api().get_substate(&src_vault.address)?;
inputs.push(src_vault_substate.address);
inputs.push(src_vault_substate.substate_id);

// add the input for the resource address to be transfered
let resource_substate = sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub async fn handle_create_transfer_proof(
.substate_api()
.scan_for_substate(
&req.resource_address.into(),
known_resource_substate_address.map(|s| s.address.version),
known_resource_substate_address.map(|s| s.substate_id.version),
)
.await?;
let resource_view_key = resource
Expand Down
6 changes: 3 additions & 3 deletions applications/tari_dan_wallet_daemon/src/handlers/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

use std::fmt::Display;

use tari_dan_common_types::optional::Optional;
use tari_dan_common_types::{optional::Optional, VersionedSubstateId};
use tari_dan_wallet_sdk::{
apis::accounts::{AccountsApi, AccountsApiError},
models::{Account, VersionedSubstateId},
models::Account,
DanWalletSdk,
};
use tari_dan_wallet_storage_sqlite::SqliteWalletStore;
Expand Down Expand Up @@ -95,7 +95,7 @@ pub fn get_account_with_inputs(

// add the input for the source account component substate
let account_substate = sdk.substate_api().get_substate(&account.address)?;
inputs.push(account_substate.address);
inputs.push(account_substate.substate_id);

// Add all versioned account child addresses as inputs
let child_addresses = sdk.substate_api().load_dependent_substates(&[&account.address])?;
Expand Down
6 changes: 3 additions & 3 deletions applications/tari_dan_wallet_daemon/src/handlers/substates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ pub async fn handle_get(

let substate = sdk
.get_network_interface()
.query_substate(&record.address.substate_id, Some(record.address.version), false)
.query_substate(&record.substate_id.substate_id, Some(record.substate_id.version), false)
.await?;

Ok(SubstatesGetResponse {
record: WalletSubstateRecord {
substate_id: record.address.substate_id,
substate_id: record.substate_id.substate_id,
parent_id: record.parent_address,
module_name: record.module_name,
version: record.address.version,
version: record.substate_id.version,
template_address: record.template_address,
},
value: substate.substate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ where
created_by_tx,
} = substate_api
.scan_for_substate(
&account_substate.address.substate_id,
Some(account_substate.address.version),
&account_substate.substate_id.substate_id,
Some(account_substate.substate_id.version),
)
.await?;

substate_api.save_root(created_by_tx, versioned_account_address.clone())?;

let vaults_value = IndexedWellKnownTypes::from_value(account_value.component().unwrap().state())?;
let known_child_vaults = substate_api
.load_dependent_substates(&[&account_substate.address.substate_id])?
.load_dependent_substates(&[&account_substate.substate_id.substate_id])?
.into_iter()
.filter(|s| s.substate_id.is_vault())
.map(|s| (s.substate_id, s.version))
Expand Down Expand Up @@ -330,6 +330,7 @@ where

let non_fungible = NonFungibleToken {
is_burned: maybe_nft_contents.is_none(),
resource_address: *vault.resource_address(),
vault_id,
nft_id: id.clone(),
data: maybe_nft_contents
Expand Down Expand Up @@ -480,7 +481,7 @@ where
let version = substate_api
.get_substate(&resx_addr)
.optional()?
.map(|s| s.address.version)
.map(|s| s.substate_id.version)
.unwrap_or(0);
let ValidatorScanResult { substate: resource, .. } =
substate_api.scan_for_substate(&resx_addr, Some(version)).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,22 @@ import CodeBlockExpand from "../../Components/CodeBlock";
import { useTheme } from "@mui/material/styles";
import type { Substate, SubstateId, TransactionResult } from "@tari-project/typescript-bindings";

function RowData({ info, state }: { info: [SubstateId, Substate | number]; state: string }, index: number) {
function SubstateRowData(
{
id,
substate,
state,
}: {
id: SubstateId;
substate?: Substate | number;
state: string;
},
index: number,
) {
const [open, setOpen] = useState(false);
const theme = useTheme();
const itemKey = Object.keys(info[0])[0];
const itemValue = Object.values(info[0])[0];
const itemKey = Object.keys(id)[0];
const itemValue = Object.values(id)[0];
return (
<>
<TableRow key={`${index}-1`}>
Expand Down Expand Up @@ -64,7 +75,13 @@ function RowData({ info, state }: { info: [SubstateId, Substate | number]; state
) : (
<IoArrowDownCircle style={{ width: 22, height: 22, color: "#ECA86A" }} />
)}
{state}({typeof info[1] === "number" ? info?.[1] : info[1].version})
{state}(
{substate !== null && substate !== undefined
? typeof substate === "number"
? substate
: substate.version
: ""}
)
</div>
</DataTableCell>
<DataTableCell>{itemKey}</DataTableCell>
Expand All @@ -82,7 +99,7 @@ function RowData({ info, state }: { info: [SubstateId, Substate | number]; state
colSpan={4}
>
<Collapse in={open} timeout="auto" unmountOnExit>
<CodeBlockExpand title="Substate" content={info} />
<CodeBlockExpand title="Substate" content={{ substate, id }} />
</Collapse>
</DataTableCell>
</TableRow>
Expand All @@ -107,11 +124,11 @@ export default function Substates({ data }: { data: TransactionResult }) {
<TableContainer>
<Table>
<TableBody>
{up.map((item: [SubstateId, Substate], index: number) => {
return <RowData info={item} state="Up" key={index} />;
{up.map(([id, substate]: [SubstateId, Substate | number], index: number) => {
return <SubstateRowData id={id} substate={substate} state="Up" key={index} />;
})}
{down.map((item: [SubstateId, number], index: number) => {
return <RowData info={item} state="Down" key={index} />;
{down.map(([id, substate]: [SubstateId, Substate | number], index: number) => {
return <SubstateRowData id={id} substate={substate} state="Down" key={index} />;
})}
</TableBody>
</Table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
import Loading from "../../Components/Loading";
import Error from "../../Components/Error";
import type { FinalizeResult, TransactionResult, TransactionSignature } from "@tari-project/typescript-bindings";
import {
FinalizeResult,
Substate,
SubstateId,
substateIdToString,
SubstateRequirement,
TransactionResult,
TransactionSignature,
} from "@tari-project/typescript-bindings";
import { getRejectReasonFromTransactionResult, rejectReasonToString } from "@tari-project/typescript-bindings";

export default function TransactionDetails() {
Expand All @@ -58,7 +66,7 @@ export default function TransactionDetails() {
};

const expandAll = () => {
setExpandedPanels(["panel1", "panel2", "panel3", "panel4", "panel5", "panel6"]);
setExpandedPanels(["panel1", "panel2", "panel3", "panel4", "panel5", "panel6", "panel7"]);
};

const collapseAll = () => {
Expand Down Expand Up @@ -308,7 +316,31 @@ export default function TransactionDetails() {
</Accordion>
)}
<Accordion expanded={expandedPanels.includes("panel6")} onChange={handleChange("panel6")}>
<AccordionSummary aria-controls="panel6bh-content" id="panel6bh-header">
<AccordionSummary aria-controls="panel1bh-content" id="panel1bh-header">
<Typography>Inputs</Typography>
</AccordionSummary>
<AccordionDetails>
{transaction?.inputs?.length ? (
<TableContainer>
<Table>
<TableBody>
{transaction.inputs.map((item: SubstateRequirement, index: number) => {
return (
<div key={index}>
{substateIdToString(item.substate_id)}:{item.version || "x"}
</div>
);
})}
</TableBody>
</Table>
</TableContainer>
) : (
<span>Empty</span>
)}
</AccordionDetails>
</Accordion>
<Accordion expanded={expandedPanels.includes("panel7")} onChange={handleChange("panel7")}>
<AccordionSummary aria-controls="panel7bh-content" id="panel7bh-header">
<Typography>Signers</Typography>
</AccordionSummary>
<AccordionDetails>
Expand Down
5 changes: 1 addition & 4 deletions dan_layer/template_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ tari_template_macros = { workspace = true, optional = true }
tari_bor = { workspace = true, default-features = false }

newtype-ops = { workspace = true }
serde = { workspace = true, default-features = false, features = [
"derive",
"alloc",
] }
serde = { workspace = true, default-features = false, features = ["derive", "alloc"] }
serde_with = { workspace = true }
ts-rs = { workspace = true, optional = true }
borsh = { workspace = true, optional = true }
Expand Down
23 changes: 10 additions & 13 deletions dan_layer/wallet/sdk/src/apis/confidential_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use log::*;
use tari_bor::{Deserialize, Serialize};
use tari_common_types::types::{PrivateKey, PublicKey};
use tari_crypto::keys::PublicKey as _;
use tari_dan_common_types::optional::{IsNotFoundError, Optional};
use tari_dan_common_types::{
optional::{IsNotFoundError, Optional},
VersionedSubstateId,
};
use tari_dan_wallet_crypto::{ConfidentialOutputMaskAndValue, ConfidentialProofStatement};
use tari_engine_types::{component::new_component_address_from_public_key, substate::SubstateId};
use tari_template_builtin::ACCOUNT_TEMPLATE_ADDRESS;
Expand All @@ -28,7 +31,7 @@ use crate::{
key_manager::{KeyManagerApi, KeyManagerApiError},
substate::{SubstateApiError, SubstatesApi, ValidatorScanResult},
},
models::{ConfidentialOutputModel, ConfidentialProofId, OutputStatus, VersionedSubstateId},
models::{ConfidentialOutputModel, ConfidentialProofId, OutputStatus},
network::WalletNetworkInterface,
storage::{WalletStorageError, WalletStore},
};
Expand Down Expand Up @@ -217,13 +220,7 @@ where
.optional()?
{
Some(ValidatorScanResult { address, .. }) => Ok((address, true)),
None => Ok((
VersionedSubstateId {
substate_id: account_component.into(),
version: 0,
},
false,
)),
None => Ok((VersionedSubstateId::new(account_component, 0), false)),
}
}

Expand All @@ -243,7 +240,7 @@ where

let account = self.accounts_api.get_account_by_address(&params.from_account.into())?;
let account_substate = self.substate_api.get_substate(&params.from_account.into())?;
inputs.push(account_substate.address);
inputs.push(account_substate.substate_id);

// Add all versioned account child addresses as inputs
let child_addresses = self.substate_api.load_dependent_substates(&[&account.address])?;
Expand All @@ -253,7 +250,7 @@ where
.accounts_api
.get_vault_by_resource(&account.address, &params.resource_address)?;
let src_vault_substate = self.substate_api.get_substate(&src_vault.address)?;
inputs.push(src_vault_substate.address);
inputs.push(src_vault_substate.substate_id);

// add the input for the resource address to be transferred
let maybe_known_resource = self
Expand All @@ -264,7 +261,7 @@ where
.substate_api
.scan_for_substate(
&SubstateId::Resource(params.resource_address),
maybe_known_resource.map(|r| r.address.version),
maybe_known_resource.map(|r| r.substate_id.version),
)
.await?;
inputs.push(resource_substate.address.clone());
Expand All @@ -275,7 +272,7 @@ where
.substate_api
.scan_for_substate(
&SubstateId::Resource(*resource_address),
maybe_known_resource.map(|r| r.address.version),
maybe_known_resource.map(|r| r.substate_id.version),
)
.await?;
inputs.push(resource_substate.address.clone());
Expand Down
Loading
Loading