From 7e7dbef3957cbf57786ac1fcbc1a41015f9a75d7 Mon Sep 17 00:00:00 2001 From: Stan Bondi Date: Wed, 14 Feb 2024 10:59:55 +0400 Subject: [PATCH] feat(walletd): add substates and templates calls to JSON-RPC (#936) Description --- feat(walletd): adds substates.get and substates.list calls feat(walletd): adds template.get call feat(indexer): adds template.get call feat(walletd/js/client): add JWT auth calls feat(walletd/js/client): add substate and template calls chore: update typescript bindings Motivation and Context --- These JSON-RPC calls allow clients to retrieve details about substates managed by the wallet as well as retrieve the template definition for arbitrary templates. How Has This Been Tested? --- Mnaually using [tari-template-web](https://github.com/tari-project/tari-template-web) What process can a PR reviewer use to test or verify this change? --- Run [tari-template-web](https://github.com/tari-project/tari-template-web) Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify --- Cargo.lock | 4 + .../tari_dan_wallet_daemon/Cargo.toml | 1 + .../src/handlers/mod.rs | 2 + .../src/handlers/substates.rs | 67 +++ .../src/handlers/templates.rs | 23 + .../src/indexer_jrpc_impl.rs | 13 + .../tari_dan_wallet_daemon/src/jrpc_server.rs | 8 +- .../tari_indexer/src/json_rpc/handlers.rs | 41 +- .../tari_indexer/src/json_rpc/server.rs | 1 + applications/tari_indexer/src/lib.rs | 1 + .../tari_indexer_web_ui/package-lock.json | 2 +- .../src/json_rpc/handlers.rs | 2 +- bindings/build.sh | 2 + bindings/index.ts | 431 +++++++++--------- bindings/src/types/Account.ts | 5 - bindings/src/types/BaseLayerValidatorNode.ts | 7 + bindings/src/types/Claims.ts | 5 - bindings/src/types/CommitteeShardInfo.ts | 4 +- bindings/src/types/GetAllVnsResponse.ts | 4 +- .../src/types/GetNetworkCommitteeResponse.ts | 4 +- .../src/types/GetTemplateDefinitionRequest.ts | 5 + .../types/GetTemplateDefinitionResponse.ts | 7 + bindings/src/types/Instruction.ts | 2 +- bindings/src/types/JrpcPermission.ts | 7 +- bindings/src/types/JrpcPermissions.ts | 5 - bindings/src/types/SubstateType.ts | 10 + bindings/src/types/SubstatesGetRequest.ts | 6 + bindings/src/types/SubstatesGetResponse.ts | 8 + bindings/src/types/SubstatesListRequest.ts | 7 + bindings/src/types/SubstatesListResponse.ts | 6 + bindings/src/types/TemplateDef.ts | 4 + bindings/src/types/TemplateDefV1.ts | 8 + bindings/src/types/TemplatesGetRequest.ts | 5 + bindings/src/types/TemplatesGetResponse.ts | 6 + bindings/src/types/TransactionStatus.ts | 5 - bindings/src/types/ValidatorNode.ts | 2 +- bindings/src/types/WalletSubstateRecord.ts | 10 + clients/base_node_client/src/grpc.rs | 6 +- clients/base_node_client/src/traits.rs | 4 +- clients/base_node_client/src/types.rs | 2 +- .../wallet_daemon_client/package.json | 2 +- .../wallet_daemon_client/src/index.ts | 94 +++- clients/tari_indexer_client/Cargo.toml | 1 + .../src/json_rpc_client.rs | 9 + clients/tari_indexer_client/src/types.rs | 19 +- clients/validator_node_client/src/types.rs | 40 +- clients/wallet_daemon_client/Cargo.toml | 1 + clients/wallet_daemon_client/src/types.rs | 60 ++- dan_layer/engine_types/src/instruction.rs | 2 + .../engine_types/src/serde_with/string.rs | 29 ++ .../src/global/models/validator_node.rs | 7 - dan_layer/template_abi/src/types.rs | 4 + dan_layer/wallet/sdk/Cargo.toml | 1 + dan_layer/wallet/sdk/src/apis/jwt.rs | 6 + dan_layer/wallet/sdk/src/apis/substate.rs | 15 +- dan_layer/wallet/sdk/src/models/substate.rs | 30 ++ dan_layer/wallet/sdk/src/network.rs | 4 + dan_layer/wallet/sdk/src/storage.rs | 8 + .../sdk/tests/confidential_output_api.rs | 7 +- dan_layer/wallet/storage_sqlite/src/reader.rs | 36 +- 60 files changed, 834 insertions(+), 283 deletions(-) create mode 100644 applications/tari_dan_wallet_daemon/src/handlers/substates.rs create mode 100644 applications/tari_dan_wallet_daemon/src/handlers/templates.rs mode change 100644 => 100755 bindings/build.sh create mode 100644 bindings/src/types/BaseLayerValidatorNode.ts create mode 100644 bindings/src/types/GetTemplateDefinitionRequest.ts create mode 100644 bindings/src/types/GetTemplateDefinitionResponse.ts create mode 100644 bindings/src/types/SubstateType.ts create mode 100644 bindings/src/types/SubstatesGetRequest.ts create mode 100644 bindings/src/types/SubstatesGetResponse.ts create mode 100644 bindings/src/types/SubstatesListRequest.ts create mode 100644 bindings/src/types/SubstatesListResponse.ts create mode 100644 bindings/src/types/TemplateDef.ts create mode 100644 bindings/src/types/TemplateDefV1.ts create mode 100644 bindings/src/types/TemplatesGetRequest.ts create mode 100644 bindings/src/types/TemplatesGetResponse.ts create mode 100644 bindings/src/types/WalletSubstateRecord.ts diff --git a/Cargo.lock b/Cargo.lock index b6602f406..ac24c6aaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9277,6 +9277,7 @@ dependencies = [ "tari_indexer_client", "tari_key_manager", "tari_shutdown", + "tari_template_abi", "tari_template_builtin", "tari_template_lib", "tari_transaction", @@ -9313,6 +9314,7 @@ dependencies = [ "tari_engine_types", "tari_hash_domains", "tari_key_manager", + "tari_template_abi", "tari_template_lib", "tari_transaction", "tari_utilities", @@ -9466,6 +9468,7 @@ dependencies = [ "tari_dan_common_types", "tari_dan_storage", "tari_engine_types", + "tari_template_abi", "tari_transaction", "thiserror", "ts-rs", @@ -10081,6 +10084,7 @@ dependencies = [ "tari_dan_common_types", "tari_dan_wallet_sdk", "tari_engine_types", + "tari_template_abi", "tari_template_lib", "tari_transaction", "thiserror", diff --git a/applications/tari_dan_wallet_daemon/Cargo.toml b/applications/tari_dan_wallet_daemon/Cargo.toml index c7747408c..d62a798f2 100644 --- a/applications/tari_dan_wallet_daemon/Cargo.toml +++ b/applications/tari_dan_wallet_daemon/Cargo.toml @@ -23,6 +23,7 @@ tari_wallet_daemon_client = { workspace = true } tari_template_builtin = { workspace = true } # TODO: Ideally we should not have to include the WASM template lib, we should perhaps extract the address types into a separate crate (e.g. template_types) tari_template_lib = { workspace = true } +tari_template_abi = { workspace = true } tari_indexer_client = { workspace = true } tari_key_manager = { workspace = true } diff --git a/applications/tari_dan_wallet_daemon/src/handlers/mod.rs b/applications/tari_dan_wallet_daemon/src/handlers/mod.rs index 69e7f7b0d..6d4236c01 100644 --- a/applications/tari_dan_wallet_daemon/src/handlers/mod.rs +++ b/applications/tari_dan_wallet_daemon/src/handlers/mod.rs @@ -10,6 +10,8 @@ pub mod keys; pub mod nfts; pub mod rpc; pub mod settings; +pub mod substates; +pub mod templates; pub mod transaction; pub mod validator; pub mod webrtc; diff --git a/applications/tari_dan_wallet_daemon/src/handlers/substates.rs b/applications/tari_dan_wallet_daemon/src/handlers/substates.rs new file mode 100644 index 000000000..640b426a2 --- /dev/null +++ b/applications/tari_dan_wallet_daemon/src/handlers/substates.rs @@ -0,0 +1,67 @@ +// Copyright 2023 The Tari Project +// SPDX-License-Identifier: BSD-3-Clause + +use tari_dan_wallet_sdk::{apis::jwt::JrpcPermission, network::WalletNetworkInterface}; +use tari_wallet_daemon_client::types::{ + SubstatesGetRequest, + SubstatesGetResponse, + SubstatesListRequest, + SubstatesListResponse, + WalletSubstateRecord, +}; + +use crate::handlers::HandlerContext; + +pub async fn handle_get( + context: &HandlerContext, + token: Option, + req: SubstatesGetRequest, +) -> Result { + let sdk = context.wallet_sdk().clone(); + sdk.jwt_api().check_auth(token, &[JrpcPermission::SubstatesRead])?; + + let record = sdk.substate_api().get_substate(&req.substate_id)?; + + let substate = sdk + .get_network_interface() + .query_substate(&record.address.substate_id, Some(record.address.version), false) + .await?; + + Ok(SubstatesGetResponse { + record: WalletSubstateRecord { + substate_id: record.address.substate_id, + parent_id: record.parent_address, + module_name: record.module_name, + version: record.address.version, + template_address: record.template_address, + }, + value: substate.substate, + }) +} + +pub async fn handle_list( + context: &HandlerContext, + token: Option, + req: SubstatesListRequest, +) -> Result { + let sdk = context.wallet_sdk().clone(); + sdk.jwt_api().check_auth(token, &[JrpcPermission::SubstatesRead])?; + + // TODO: pagination + let substates = + sdk.substate_api() + .list_substates(req.filter_by_type, req.filter_by_template.as_ref(), None, None)?; + + let substates = substates + .into_iter() + .map(|substate| WalletSubstateRecord { + substate_id: substate.address.substate_id, + parent_id: substate.parent_address, + version: substate.address.version, + template_address: substate.template_address, + module_name: substate.module_name, + }) + .collect(); + + Ok(SubstatesListResponse { substates }) +} diff --git a/applications/tari_dan_wallet_daemon/src/handlers/templates.rs b/applications/tari_dan_wallet_daemon/src/handlers/templates.rs new file mode 100644 index 000000000..82da022c0 --- /dev/null +++ b/applications/tari_dan_wallet_daemon/src/handlers/templates.rs @@ -0,0 +1,23 @@ +// Copyright 2023 The Tari Project +// SPDX-License-Identifier: BSD-3-Clause + +use tari_dan_wallet_sdk::{apis::jwt::JrpcPermission, network::WalletNetworkInterface}; +use tari_wallet_daemon_client::types::{TemplatesGetRequest, TemplatesGetResponse}; + +use crate::handlers::HandlerContext; + +pub async fn handle_get( + context: &HandlerContext, + token: Option, + req: TemplatesGetRequest, +) -> Result { + let sdk = context.wallet_sdk().clone(); + sdk.jwt_api().check_auth(token, &[JrpcPermission::TemplatesRead])?; + + let template_definition = sdk + .get_network_interface() + .fetch_template_definition(req.template_address) + .await?; + + Ok(TemplatesGetResponse { template_definition }) +} diff --git a/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs b/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs index 8bc26228c..7474aa6c9 100644 --- a/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs +++ b/applications/tari_dan_wallet_daemon/src/indexer_jrpc_impl.rs @@ -23,6 +23,7 @@ use tari_indexer_client::{ SubmitTransactionRequest, }, }; +use tari_template_lib::models::TemplateAddress; use tari_transaction::{SubstateRequirement, Transaction, TransactionId}; use url::ParseError; @@ -133,6 +134,18 @@ impl WalletNetworkInterface for IndexerJsonRpcNetworkInterface { result: convert_indexer_result_to_wallet_result(resp.result), }) } + + async fn fetch_template_definition( + &self, + template_address: TemplateAddress, + ) -> Result { + let mut client = self.get_client()?; + let resp = client + .get_template_definition(tari_indexer_client::types::GetTemplateDefinitionRequest { template_address }) + .await?; + + Ok(resp.definition) + } } #[derive(Debug, thiserror::Error)] diff --git a/applications/tari_dan_wallet_daemon/src/jrpc_server.rs b/applications/tari_dan_wallet_daemon/src/jrpc_server.rs index ba9f4168d..1cf99053a 100644 --- a/applications/tari_dan_wallet_daemon/src/jrpc_server.rs +++ b/applications/tari_dan_wallet_daemon/src/jrpc_server.rs @@ -25,7 +25,7 @@ use tari_dan_wallet_sdk::apis::jwt::JwtApiError; use tari_shutdown::ShutdownSignal; use tower_http::{cors::CorsLayer, trace::TraceLayer}; -use super::handlers::HandlerContext; +use super::handlers::{substates, templates, HandlerContext}; use crate::handlers::{ accounts, confidential, @@ -154,6 +154,12 @@ async fn handler( }, _ => Ok(value.method_not_found(&value.method)), }, + Some(("substates", method)) => match method { + "get" => call_handler(context, value, token, substates::handle_get).await, + "list" => call_handler(context, value, token, substates::handle_list).await, + _ => Ok(value.method_not_found(&value.method)), + }, + Some(("templates", "get")) => call_handler(context, value, token, templates::handle_get).await, Some(("nfts", method)) => match method { "mint_account_nft" => call_handler(context, value, token, nfts::handle_mint_account_nft).await, "get" => call_handler(context, value, token, nfts::handle_get_nft).await, diff --git a/applications/tari_indexer/src/json_rpc/handlers.rs b/applications/tari_indexer/src/json_rpc/handlers.rs index 25d4c0cab..1148c9544 100644 --- a/applications/tari_indexer/src/json_rpc/handlers.rs +++ b/applications/tari_indexer/src/json_rpc/handlers.rs @@ -32,8 +32,13 @@ use libp2p::swarm::dial_opts::{DialOpts, PeerCondition}; use log::{error, warn}; use serde_json::{self as json, json, Value}; use tari_base_node_client::{grpc::GrpcBaseNodeClient, types::BaseLayerConsensusConstants, BaseNodeClient}; -use tari_dan_app_utilities::{keypair::RistrettoKeypair, substate_file_cache::SubstateFileCache}; +use tari_dan_app_utilities::{ + keypair::RistrettoKeypair, + substate_file_cache::SubstateFileCache, + template_manager::{implementation::TemplateManager, interface::TemplateExecutable}, +}; use tari_dan_common_types::{optional::Optional, public_key_to_peer_id, PeerAddress}; +use tari_dan_engine::{template::TemplateModuleLoader, wasm::WasmModule}; use tari_dan_p2p::TariMessagingSpec; use tari_dan_storage::consensus_models::Decision; use tari_epoch_manager::{base_layer::EpochManagerHandle, EpochManagerReader}; @@ -62,6 +67,8 @@ use tari_indexer_client::{ GetRelatedTransactionsResponse, GetSubstateRequest, GetSubstateResponse, + GetTemplateDefinitionRequest, + GetTemplateDefinitionResponse, GetTransactionResultRequest, GetTransactionResultResponse, IndexerTransactionFinalizedResult, @@ -99,6 +106,7 @@ pub struct JsonRpcHandlers { epoch_manager: EpochManagerHandle, transaction_manager: TransactionManager, TariValidatorNodeRpcClientFactory, SubstateFileCache>, + template_manager: TemplateManager, dry_run_transaction_processor: DryRunTransactionProcessor, } @@ -113,6 +121,7 @@ impl JsonRpcHandlers { TariValidatorNodeRpcClientFactory, SubstateFileCache, >, + template_manager: TemplateManager, dry_run_transaction_processor: DryRunTransactionProcessor, ) -> Self { Self { @@ -123,6 +132,7 @@ impl JsonRpcHandlers { substate_manager, epoch_manager: services.epoch_manager.clone(), transaction_manager, + template_manager, dry_run_transaction_processor, } } @@ -587,6 +597,35 @@ impl JsonRpcHandlers { Ok(JsonRpcResponse::success(answer_id, response)) } + pub async fn get_template_definition(&self, value: JsonRpcExtractor) -> JrpcResult { + let answer_id = value.get_answer_id(); + let request: GetTemplateDefinitionRequest = value.parse_params()?; + let template = self + .template_manager + .fetch_template(&request.template_address) + .map_err(|e| Self::internal_error(answer_id, e))?; + let template = match template.executable { + TemplateExecutable::CompiledWasm(code) => WasmModule::from_code(code) + .load_template() + .map_err(|e| Self::internal_error(answer_id, format!("Error loading template: {}", e)))?, + TemplateExecutable::Manifest(_) | TemplateExecutable::Flow(_) => { + return Err(JsonRpcResponse::error( + answer_id, + JsonRpcError::new( + JsonRpcErrorReason::InvalidRequest, + "Template is not a wasm module".to_string(), + json::Value::Null, + ), + )); + }, + }; + + Ok(JsonRpcResponse::success(answer_id, GetTemplateDefinitionResponse { + definition: template.template_def().clone(), + name: template.template_name().to_string(), + })) + } + pub async fn get_transaction_result(&self, value: JsonRpcExtractor) -> JrpcResult { let answer_id = value.get_answer_id(); let request: GetTransactionResultRequest = value.parse_params()?; diff --git a/applications/tari_indexer/src/json_rpc/server.rs b/applications/tari_indexer/src/json_rpc/server.rs index da6d2ad82..d8d97106d 100644 --- a/applications/tari_indexer/src/json_rpc/server.rs +++ b/applications/tari_indexer/src/json_rpc/server.rs @@ -76,6 +76,7 @@ async fn handler(Extension(handlers): Extension>, value: Js "get_transaction_result" => handlers.get_transaction_result(value).await, "get_substate_transactions" => handlers.get_substate_transactions(value).await, "get_epoch_manager_stats" => handlers.get_epoch_manager_stats(value).await, + "get_template_definition" => handlers.get_template_definition(value).await, method => Ok(value.method_not_found(method)), } } diff --git a/applications/tari_indexer/src/lib.rs b/applications/tari_indexer/src/lib.rs index 6ee720283..190b1845d 100644 --- a/applications/tari_indexer/src/lib.rs +++ b/applications/tari_indexer/src/lib.rs @@ -144,6 +144,7 @@ pub async fn run_indexer(config: ApplicationConfig, mut shutdown_signal: Shutdow base_node_client, substate_manager.clone(), transaction_manager, + services.template_manager.clone(), dry_run_transaction_processor, ); task::spawn(run_json_rpc(jrpc_address, handlers)); diff --git a/applications/tari_indexer_web_ui/package-lock.json b/applications/tari_indexer_web_ui/package-lock.json index 0bc995a9c..31d03912f 100644 --- a/applications/tari_indexer_web_ui/package-lock.json +++ b/applications/tari_indexer_web_ui/package-lock.json @@ -37,7 +37,7 @@ } }, "../../bindings": { - "name": "tari-bindings", + "name": "@tarilabs/typescript-bindings", "version": "1.0.0", "license": "ISC", "devDependencies": { diff --git a/applications/tari_validator_node/src/json_rpc/handlers.rs b/applications/tari_validator_node/src/json_rpc/handlers.rs index edaaba24f..5b2beaf6a 100644 --- a/applications/tari_validator_node/src/json_rpc/handlers.rs +++ b/applications/tari_validator_node/src/json_rpc/handlers.rs @@ -762,7 +762,7 @@ impl JsonRpcHandlers { .map(|(bucket, validators)| CommitteeShardInfo { shard: bucket, substate_address_range: bucket.to_substate_address_range(num_committees), - validators, + validators: validators.into_iter().map(Into::into).collect(), }) .collect(); diff --git a/bindings/build.sh b/bindings/build.sh old mode 100644 new mode 100755 index 8cc53e775..89b6d3aa5 --- a/bindings/build.sh +++ b/bindings/build.sh @@ -1,6 +1,8 @@ # Copyright 2023 The Tari Project # SPDX-License-Identifier: BSD-3-Clause +set -e + cargo test --workspace --exclude integration_tests export_bindings --features ts npx shx mv ../dan_layer/bindings/src/types/* ./src/types/ npx shx rm -rf ../dan_layer/bindings/ diff --git a/bindings/index.ts b/bindings/index.ts index 2f94621af..05565735b 100644 --- a/bindings/index.ts +++ b/bindings/index.ts @@ -1,236 +1,249 @@ // Copyright 2023 The Tari Project // SPDX-License-Identifier: BSD-3-Clause -export * from "./src/types/AccessRule"; -export * from "./src/types/Account"; -export * from "./src/types/AccountGetDefaultRequest"; -export * from "./src/types/AccountGetRequest"; -export * from "./src/types/AccountGetResponse"; -export * from "./src/types/AccountInfo"; -export * from "./src/types/AccountNftInfo"; -export * from "./src/types/AccountsCreateFreeTestCoinsRequest"; -export * from "./src/types/AccountsCreateFreeTestCoinsResponse"; -export * from "./src/types/AccountsCreateRequest"; -export * from "./src/types/AccountsCreateResponse"; -export * from "./src/types/AccountSetDefaultRequest"; -export * from "./src/types/AccountSetDefaultResponse"; -export * from "./src/types/AccountsGetBalancesRequest"; -export * from "./src/types/AccountsGetBalancesResponse"; -export * from "./src/types/AccountsInvokeRequest"; -export * from "./src/types/AccountsInvokeResponse"; +export * from "./src/types/Metadata"; +export * from "./src/types/GetTransactionResultRequest"; +export * from "./src/types/BucketId"; +export * from "./src/types/Substate"; +export * from "./src/types/WalletSubstateRecord"; +export * from "./src/types/GetSubstateRequest"; +export * from "./src/types/ProofsFinalizeResponse"; +export * from "./src/types/CallInstructionRequest"; +export * from "./src/types/AuthLoginAcceptResponse"; export * from "./src/types/AccountsListRequest"; -export * from "./src/types/AccountsListResponse"; -export * from "./src/types/AddAddressRequest"; -export * from "./src/types/AddAddressResponse"; -export * from "./src/types/AddPeerRequest"; -export * from "./src/types/AddPeerResponse"; -export * from "./src/types/Amount"; -export * from "./src/types/Arg"; -export * from "./src/types/ArgDef"; -export * from "./src/types/AuthGetAllJwtRequest"; +export * from "./src/types/Evidence"; export * from "./src/types/AuthGetAllJwtResponse"; -export * from "./src/types/AuthLoginAcceptRequest"; -export * from "./src/types/AuthLoginAcceptResponse"; -export * from "./src/types/AuthLoginDenyRequest"; -export * from "./src/types/AuthLoginDenyResponse"; -export * from "./src/types/AuthLoginRequest"; +export * from "./src/types/GetTemplateDefinitionRequest"; export * from "./src/types/AuthLoginResponse"; -export * from "./src/types/AuthRevokeTokenRequest"; -export * from "./src/types/AuthRevokeTokenResponse"; -export * from "./src/types/BalanceEntry"; -export * from "./src/types/Block"; -export * from "./src/types/BucketId"; -export * from "./src/types/CallInstructionRequest"; -export * from "./src/types/ClaimBurnRequest"; -export * from "./src/types/ClaimBurnResponse"; -export * from "./src/types/Claims"; -export * from "./src/types/ClaimValidatorFeesRequest"; -export * from "./src/types/ClaimValidatorFeesResponse"; -export * from "./src/types/ClearAddressesResponse"; -export * from "./src/types/Command"; -export * from "./src/types/CommitteeShard"; -export * from "./src/types/CommitteeShardInfo"; -export * from "./src/types/ComponentAccessRules"; -export * from "./src/types/ComponentAddress"; -export * from "./src/types/ComponentAddressOrName"; -export * from "./src/types/ComponentBody"; -export * from "./src/types/ComponentHeader"; -export * from "./src/types/ConfidentialClaim"; -export * from "./src/types/ConfidentialCreateOutputProofRequest"; -export * from "./src/types/ConfidentialCreateOutputProofResponse"; -export * from "./src/types/ConfidentialOutput"; -export * from "./src/types/ConfidentialOutputProof"; +export * from "./src/types/TemplateMetadata"; +export * from "./src/types/SubstateRecord"; +export * from "./src/types/GetValidatorFeesRequest"; +export * from "./src/types/AddPeerResponse"; +export * from "./src/types/AccountGetDefaultRequest"; +export * from "./src/types/AuthGetAllJwtRequest"; +export * from "./src/types/ArgDef"; +export * from "./src/types/Vault"; +export * from "./src/types/AccountGetResponse"; +export * from "./src/types/FeeReceipt"; +export * from "./src/types/SettingsSetRequest"; export * from "./src/types/ConfidentialStatement"; -export * from "./src/types/ConfidentialTransferRequest"; -export * from "./src/types/ConfidentialTransferResponse"; -export * from "./src/types/ConfidentialWithdrawProof"; -export * from "./src/types/Connection"; -export * from "./src/types/ConnectionDirection"; -export * from "./src/types/Decision"; -export * from "./src/types/DeleteAddressRequest"; -export * from "./src/types/DeleteAddressResponse"; -export * from "./src/types/DryRunTransactionFinalizeResult"; -export * from "./src/types/Epoch"; -export * from "./src/types/Event"; -export * from "./src/types/Evidence"; -export * from "./src/types/ExecutedTransaction"; -export * from "./src/types/ExecuteResult"; -export * from "./src/types/FeeBreakdown"; +export * from "./src/types/AddPeerRequest"; +export * from "./src/types/GetCommsStatsResponse"; +export * from "./src/types/GetValidatorFeesResponse"; +export * from "./src/types/GetIdentityResponse"; +export * from "./src/types/TransactionGetAllRequest"; +export * from "./src/types/QuorumCertificate"; export * from "./src/types/FeeClaim"; -export * from "./src/types/FeeClaimAddress"; -export * from "./src/types/FeeCostBreakdown"; -export * from "./src/types/FeeReceipt"; -export * from "./src/types/FeeSource"; -export * from "./src/types/FinalizeResult"; -export * from "./src/types/ForeignProposal"; -export * from "./src/types/ForeignProposalState"; +export * from "./src/types/RevealFundsRequest"; +export * from "./src/types/AuthLoginDenyResponse"; +export * from "./src/types/GetTemplateResponse"; +export * from "./src/types/InspectSubstateRequest"; export * from "./src/types/FunctionDef"; -export * from "./src/types/GetAccountNftRequest"; -export * from "./src/types/GetAddressesResponse"; -export * from "./src/types/GetAllVnsRequest"; -export * from "./src/types/GetAllVnsResponse"; -export * from "./src/types/GetBlockRequest"; -export * from "./src/types/GetBlockResponse"; +export * from "./src/types/AuthLoginDenyRequest"; +export * from "./src/types/FeeBreakdown"; +export * from "./src/types/TransactionSubmitResponse"; export * from "./src/types/GetBlocksCountResponse"; -export * from "./src/types/GetBlocksRequest"; -export * from "./src/types/GetBlocksResponse"; -export * from "./src/types/GetCommitteeRequest"; -export * from "./src/types/GetCommsStatsResponse"; -export * from "./src/types/GetConnectionsResponse"; -export * from "./src/types/GetEpochManagerStatsResponse"; -export * from "./src/types/GetIdentityResponse"; -export * from "./src/types/GetNetworkCommitteeResponse"; -export * from "./src/types/GetNonFungibleCollectionsResponse"; -export * from "./src/types/GetNonFungibleCountRequest"; -export * from "./src/types/GetNonFungibleCountResponse"; -export * from "./src/types/GetNonFungiblesRequest"; -export * from "./src/types/GetNonFungiblesResponse"; -export * from "./src/types/GetRecentTransactionsRequest"; -export * from "./src/types/GetRecentTransactionsResponse"; -export * from "./src/types/GetRelatedTransactionsRequest"; -export * from "./src/types/GetRelatedTransactionsResponse"; -export * from "./src/types/GetShardKey"; -export * from "./src/types/GetStateRequest"; -export * from "./src/types/GetStateResponse"; -export * from "./src/types/GetSubstateRequest"; -export * from "./src/types/GetSubstateResponse"; -export * from "./src/types/GetSubstatesByTransactionRequest"; +export * from "./src/types/ProofsGenerateResponse"; +export * from "./src/types/SubstateDestroyed"; export * from "./src/types/GetSubstatesByTransactionResponse"; -export * from "./src/types/GetTemplateRequest"; -export * from "./src/types/GetTemplateResponse"; -export * from "./src/types/GetTemplatesRequest"; -export * from "./src/types/GetTemplatesResponse"; -export * from "./src/types/GetTransactionRequest"; -export * from "./src/types/GetTransactionResponse"; -export * from "./src/types/GetTransactionResultRequest"; -export * from "./src/types/GetTransactionResultResponse"; -export * from "./src/types/GetValidatorFeesRequest"; -export * from "./src/types/GetValidatorFeesResponse"; +export * from "./src/types/SubstateRequirement"; export * from "./src/types/IndexedValue"; -export * from "./src/types/IndexedWellKnownTypes"; +export * from "./src/types/ComponentHeader"; +export * from "./src/types/ClaimValidatorFeesRequest"; +export * from "./src/types/GetRelatedTransactionsResponse"; +export * from "./src/types/NonFungibleAddress"; +export * from "./src/types/FeeSource"; +export * from "./src/types/TransactionAtom"; +export * from "./src/types/AuthLoginRequest"; +export * from "./src/types/Event"; +export * from "./src/types/GetTransactionResultResponse"; export * from "./src/types/IndexerTransactionFinalizedResult"; -export * from "./src/types/InspectSubstateRequest"; -export * from "./src/types/InspectSubstateResponse"; -export * from "./src/types/Instruction"; -export * from "./src/types/InstructionResult"; -export * from "./src/types/JrpcPermission"; -export * from "./src/types/JrpcPermissions"; -export * from "./src/types/KeysCreateRequest"; -export * from "./src/types/KeysCreateResponse"; -export * from "./src/types/KeysListRequest"; -export * from "./src/types/KeysListResponse"; -export * from "./src/types/KeysSetActiveRequest"; -export * from "./src/types/KeysSetActiveResponse"; export * from "./src/types/ListAccountNftRequest"; -export * from "./src/types/ListAccountNftResponse"; -export * from "./src/types/ListBlocksRequest"; -export * from "./src/types/ListBlocksResponse"; -export * from "./src/types/LockFlag"; -export * from "./src/types/LogEntry"; -export * from "./src/types/LogLevel"; -export * from "./src/types/Metadata"; -export * from "./src/types/MintAccountNftRequest"; -export * from "./src/types/MintAccountNftResponse"; -export * from "./src/types/NodeHeight"; -export * from "./src/types/NonFungible"; -export * from "./src/types/NonFungibleAddress"; -export * from "./src/types/NonFungibleAddressContents"; -export * from "./src/types/NonFungibleContainer"; +export * from "./src/types/TransactionGetRequest"; +export * from "./src/types/GetTemplatesResponse"; export * from "./src/types/NonFungibleId"; -export * from "./src/types/NonFungibleIndex"; -export * from "./src/types/NonFungibleIndexAddress"; -export * from "./src/types/NonFungibleSubstate"; -export * from "./src/types/Ordering"; -export * from "./src/types/OwnerRule"; -export * from "./src/types/ProofId"; -export * from "./src/types/ProofsCancelRequest"; -export * from "./src/types/ProofsCancelResponse"; +export * from "./src/types/AuthRevokeTokenResponse"; export * from "./src/types/ProofsFinalizeRequest"; -export * from "./src/types/ProofsFinalizeResponse"; -export * from "./src/types/ProofsGenerateRequest"; -export * from "./src/types/ProofsGenerateResponse"; -export * from "./src/types/QuorumCertificate"; -export * from "./src/types/QuorumDecision"; -export * from "./src/types/RegisterValidatorNodeRequest"; -export * from "./src/types/RegisterValidatorNodeResponse"; -export * from "./src/types/RejectReason"; -export * from "./src/types/RequireRule"; export * from "./src/types/Resource"; -export * from "./src/types/ResourceAccessRules"; -export * from "./src/types/ResourceAddress"; -export * from "./src/types/ResourceContainer"; -export * from "./src/types/ResourceType"; export * from "./src/types/RestrictedAccessRule"; -export * from "./src/types/RevealFundsRequest"; -export * from "./src/types/RevealFundsResponse"; -export * from "./src/types/RuleRequirement"; -export * from "./src/types/SettingsGetResponse"; -export * from "./src/types/SettingsSetRequest"; +export * from "./src/types/GetTransactionRequest"; +export * from "./src/types/TransactionReceipt"; +export * from "./src/types/TransferResponse"; +export * from "./src/types/FinalizeResult"; +export * from "./src/types/NodeHeight"; +export * from "./src/types/TransactionStatus"; +export * from "./src/types/GetStateRequest"; +export * from "./src/types/RejectReason"; +export * from "./src/types/ConfidentialOutput"; +export * from "./src/types/NonFungibleContainer"; export * from "./src/types/SettingsSetResponse"; -export * from "./src/types/ShardEvidence"; -export * from "./src/types/SubmitTransactionRequest"; -export * from "./src/types/SubmitTransactionResponse"; -export * from "./src/types/Substate"; -export * from "./src/types/SubstateAddress"; -export * from "./src/types/SubstateDestroyed"; -export * from "./src/types/SubstateDiff"; -export * from "./src/types/SubstateId"; -export * from "./src/types/SubstateRecord"; -export * from "./src/types/SubstateRequirement"; -export * from "./src/types/SubstateStatus"; -export * from "./src/types/SubstateValue"; -export * from "./src/types/TemplateAbi"; -export * from "./src/types/TemplateMetadata"; -export * from "./src/types/TemplateRegistrationRequest"; -export * from "./src/types/TemplateRegistrationResponse"; -export * from "./src/types/Transaction"; -export * from "./src/types/TransactionAtom"; -export * from "./src/types/TransactionClaimBurnResponse"; -export * from "./src/types/TransactionGetAllRequest"; -export * from "./src/types/TransactionGetAllResponse"; -export * from "./src/types/TransactionGetRequest"; -export * from "./src/types/TransactionGetResponse"; -export * from "./src/types/TransactionGetResultRequest"; +export * from "./src/types/GetConnectionsResponse"; +export * from "./src/types/TransferRequest"; +export * from "./src/types/RegisterValidatorNodeResponse"; +export * from "./src/types/KeysListRequest"; export * from "./src/types/TransactionGetResultResponse"; -export * from "./src/types/TransactionReceipt"; -export * from "./src/types/TransactionReceiptAddress"; -export * from "./src/types/TransactionResult"; +export * from "./src/types/VaultId"; +export * from "./src/types/ClaimBurnRequest"; +export * from "./src/types/LockFlag"; +export * from "./src/types/GetNonFungiblesRequest"; +export * from "./src/types/GetAddressesResponse"; +export * from "./src/types/KeysListResponse"; +export * from "./src/types/SubstatesGetRequest"; export * from "./src/types/TransactionSignature"; -export * from "./src/types/TransactionStatus"; export * from "./src/types/TransactionSubmitRequest"; -export * from "./src/types/TransactionSubmitResponse"; +export * from "./src/types/ResourceType"; +export * from "./src/types/AccountsGetBalancesResponse"; +export * from "./src/types/TransactionGetAllResponse"; +export * from "./src/types/AccountsCreateFreeTestCoinsResponse"; +export * from "./src/types/GetBlocksRequest"; +export * from "./src/types/FeeClaimAddress"; +export * from "./src/types/ExecutedTransaction"; +export * from "./src/types/Epoch"; +export * from "./src/types/QuorumDecision"; +export * from "./src/types/Amount"; +export * from "./src/types/ResourceAccessRules"; +export * from "./src/types/ConfidentialTransferResponse"; +export * from "./src/types/NonFungible"; +export * from "./src/types/ClearAddressesResponse"; +export * from "./src/types/Connection"; +export * from "./src/types/GetTemplateRequest"; +export * from "./src/types/TransactionGetResponse"; +export * from "./src/types/AddAddressRequest"; +export * from "./src/types/SubstateId"; +export * from "./src/types/SubstatesGetResponse"; +export * from "./src/types/BaseLayerValidatorNode"; +export * from "./src/types/TransactionReceiptAddress"; +export * from "./src/types/ComponentAddress"; +export * from "./src/types/SubstateType"; +export * from "./src/types/GetAccountNftRequest"; +export * from "./src/types/AuthRevokeTokenRequest"; +export * from "./src/types/InstructionResult"; +export * from "./src/types/ProofsGenerateRequest"; +export * from "./src/types/GetSubstatesByTransactionRequest"; +export * from "./src/types/ValidatorSignature"; +export * from "./src/types/RevealFundsResponse"; +export * from "./src/types/JrpcPermissions"; +export * from "./src/types/Transaction"; +export * from "./src/types/GetTransactionResponse"; +export * from "./src/types/Ordering"; +export * from "./src/types/ShardEvidence"; +export * from "./src/types/ConfidentialOutputProof"; +export * from "./src/types/GetShardKey"; +export * from "./src/types/Claims"; +export * from "./src/types/ConfidentialClaim"; +export * from "./src/types/AccountsInvokeResponse"; +export * from "./src/types/ResourceContainer"; +export * from "./src/types/AccountsListResponse"; +export * from "./src/types/CommitteeShardInfo"; +export * from "./src/types/WebRtcStartResponse"; +export * from "./src/types/ConfidentialWithdrawProof"; +export * from "./src/types/TransactionGetResultRequest"; +export * from "./src/types/CommitteeShard"; +export * from "./src/types/GetRelatedTransactionsRequest"; +export * from "./src/types/ProofsCancelResponse"; +export * from "./src/types/AccountsCreateRequest"; +export * from "./src/types/MintAccountNftRequest"; +export * from "./src/types/TransactionClaimBurnResponse"; export * from "./src/types/TransactionWaitResultRequest"; -export * from "./src/types/TransactionWaitResultResponse"; -export * from "./src/types/TransferRequest"; -export * from "./src/types/TransferResponse"; +export * from "./src/types/ResourceAddress"; +export * from "./src/types/ClaimValidatorFeesResponse"; +export * from "./src/types/ConfidentialCreateOutputProofRequest"; +export * from "./src/types/KeysCreateRequest"; +export * from "./src/types/GetCommitteeRequest"; +export * from "./src/types/NonFungibleAddressContents"; +export * from "./src/types/IndexedWellKnownTypes"; +export * from "./src/types/RuleRequirement"; +export * from "./src/types/Arg"; +export * from "./src/types/TemplateRegistrationRequest"; +export * from "./src/types/RequireRule"; +export * from "./src/types/SettingsGetResponse"; +export * from "./src/types/LogEntry"; +export * from "./src/types/Command"; +export * from "./src/types/Instruction"; +export * from "./src/types/ClaimBurnResponse"; +export * from "./src/types/GetNonFungiblesResponse"; +export * from "./src/types/GetTemplateDefinitionResponse"; +export * from "./src/types/GetSubstateResponse"; +export * from "./src/types/WebRtcStartRequest"; +export * from "./src/types/TemplateDef"; +export * from "./src/types/DryRunTransactionFinalizeResult"; +export * from "./src/types/SubstateValue"; +export * from "./src/types/WebRtcStart"; +export * from "./src/types/TemplateRegistrationResponse"; +export * from "./src/types/GetStateResponse"; +export * from "./src/types/AccountSetDefaultRequest"; export * from "./src/types/Type"; -export * from "./src/types/UnclaimedConfidentialOutput"; +export * from "./src/types/ProofId"; +export * from "./src/types/Block"; +export * from "./src/types/TemplateDefV1"; +export * from "./src/types/ConfidentialCreateOutputProofResponse"; +export * from "./src/types/SubstateStatus"; +export * from "./src/types/ComponentAccessRules"; +export * from "./src/types/GetAllVnsRequest"; +export * from "./src/types/TemplatesGetResponse"; +export * from "./src/types/ListAccountNftResponse"; +export * from "./src/types/AccountsGetBalancesRequest"; +export * from "./src/types/MintAccountNftResponse"; +export * from "./src/types/DeleteAddressRequest"; +export * from "./src/types/InspectSubstateResponse"; +export * from "./src/types/SubstateDiff"; +export * from "./src/types/AccountsCreateFreeTestCoinsRequest"; +export * from "./src/types/GetNonFungibleCollectionsResponse"; +export * from "./src/types/AccessRule"; +export * from "./src/types/GetBlocksResponse"; +export * from "./src/types/ListBlocksResponse"; +export * from "./src/types/KeysCreateResponse"; +export * from "./src/types/GetBlockRequest"; +export * from "./src/types/AccountInfo"; +export * from "./src/types/GetRecentTransactionsRequest"; +export * from "./src/types/SubstatesListRequest"; export * from "./src/types/ValidatorFee"; +export * from "./src/types/BalanceEntry"; +export * from "./src/types/AddAddressResponse"; +export * from "./src/types/TemplatesGetRequest"; +export * from "./src/types/ExecuteResult"; +export * from "./src/types/RegisterValidatorNodeRequest"; +export * from "./src/types/OwnerRule"; +export * from "./src/types/NonFungibleSubstate"; +export * from "./src/types/GetRecentTransactionsResponse"; +export * from "./src/types/GetNonFungibleCountResponse"; +export * from "./src/types/AccountsInvokeRequest"; +export * from "./src/types/NonFungibleIndexAddress"; +export * from "./src/types/SubstateAddress"; +export * from "./src/types/ProofsCancelRequest"; +export * from "./src/types/JrpcPermission"; +export * from "./src/types/UnclaimedConfidentialOutput"; +export * from "./src/types/AccountSetDefaultResponse"; export * from "./src/types/ValidatorNode"; -export * from "./src/types/ValidatorSignature"; -export * from "./src/types/Vault"; -export * from "./src/types/VaultId"; -export * from "./src/types/WebRtcStart"; -export * from "./src/types/WebRtcStartRequest"; -export * from "./src/types/WebRtcStartResponse"; +export * from "./src/types/ForeignProposalState"; +export * from "./src/types/SubmitTransactionRequest"; +export * from "./src/types/SubstatesListResponse"; +export * from "./src/types/Decision"; +export * from "./src/types/NonFungibleIndex"; +export * from "./src/types/ListBlocksRequest"; +export * from "./src/types/GetNetworkCommitteeResponse"; +export * from "./src/types/KeysSetActiveResponse"; +export * from "./src/types/TemplateAbi"; +export * from "./src/types/ComponentAddressOrName"; +export * from "./src/types/GetTemplatesRequest"; +export * from "./src/types/AuthLoginAcceptRequest"; +export * from "./src/types/KeysSetActiveRequest"; +export * from "./src/types/ConnectionDirection"; +export * from "./src/types/ComponentBody"; +export * from "./src/types/GetEpochManagerStatsResponse"; +export * from "./src/types/GetBlockResponse"; +export * from "./src/types/DeleteAddressResponse"; +export * from "./src/types/ForeignProposal"; +export * from "./src/types/FeeCostBreakdown"; +export * from "./src/types/TransactionResult"; +export * from "./src/types/LogLevel"; +export * from "./src/types/SubmitTransactionResponse"; +export * from "./src/types/GetNonFungibleCountRequest"; +export * from "./src/types/AccountNftInfo"; +export * from "./src/types/ConfidentialTransferRequest"; +export * from "./src/types/Account"; +export * from "./src/types/GetAllVnsResponse"; +export * from "./src/types/AccountsCreateResponse"; +export * from "./src/types/TransactionWaitResultResponse"; +export * from "./src/types/AccountGetRequest"; export * from "./src/helpers/helpers"; diff --git a/bindings/src/types/Account.ts b/bindings/src/types/Account.ts index 4895dbf4a..ab5adb79b 100644 --- a/bindings/src/types/Account.ts +++ b/bindings/src/types/Account.ts @@ -1,8 +1,3 @@ -/* - * // Copyright 2024 The Tari Project - * // SPDX-License-Identifier: BSD-3-Clause - */ - // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { SubstateId } from "./SubstateId"; diff --git a/bindings/src/types/BaseLayerValidatorNode.ts b/bindings/src/types/BaseLayerValidatorNode.ts new file mode 100644 index 000000000..f026fff0a --- /dev/null +++ b/bindings/src/types/BaseLayerValidatorNode.ts @@ -0,0 +1,7 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { SubstateAddress } from "./SubstateAddress"; + +export interface BaseLayerValidatorNode { + public_key: string; + shard_key: SubstateAddress; +} diff --git a/bindings/src/types/Claims.ts b/bindings/src/types/Claims.ts index 59f53a7c4..03c6b98d7 100644 --- a/bindings/src/types/Claims.ts +++ b/bindings/src/types/Claims.ts @@ -1,8 +1,3 @@ -/* - * // Copyright 2024 The Tari Project - * // SPDX-License-Identifier: BSD-3-Clause - */ - // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { JrpcPermissions } from "./JrpcPermissions"; diff --git a/bindings/src/types/CommitteeShardInfo.ts b/bindings/src/types/CommitteeShardInfo.ts index 248d1219b..4b1378953 100644 --- a/bindings/src/types/CommitteeShardInfo.ts +++ b/bindings/src/types/CommitteeShardInfo.ts @@ -2,8 +2,8 @@ import type { SubstateAddress } from "./SubstateAddress"; import type { ValidatorNode } from "./ValidatorNode"; -export interface CommitteeShardInfo { +export interface CommitteeShardInfo { shard: number; substate_address_range: { start: SubstateAddress; end: SubstateAddress }; - validators: Array>; + validators: Array; } diff --git a/bindings/src/types/GetAllVnsResponse.ts b/bindings/src/types/GetAllVnsResponse.ts index 6452f04d0..7b38c748d 100644 --- a/bindings/src/types/GetAllVnsResponse.ts +++ b/bindings/src/types/GetAllVnsResponse.ts @@ -1,6 +1,6 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { ValidatorNode } from "./ValidatorNode"; +import type { BaseLayerValidatorNode } from "./BaseLayerValidatorNode"; export interface GetAllVnsResponse { - vns: Array; + vns: Array; } diff --git a/bindings/src/types/GetNetworkCommitteeResponse.ts b/bindings/src/types/GetNetworkCommitteeResponse.ts index e746758b8..d40bfb402 100644 --- a/bindings/src/types/GetNetworkCommitteeResponse.ts +++ b/bindings/src/types/GetNetworkCommitteeResponse.ts @@ -2,7 +2,7 @@ import type { CommitteeShardInfo } from "./CommitteeShardInfo"; import type { Epoch } from "./Epoch"; -export interface GetNetworkCommitteeResponse { +export interface GetNetworkCommitteeResponse { current_epoch: Epoch; - committees: Array>; + committees: Array; } diff --git a/bindings/src/types/GetTemplateDefinitionRequest.ts b/bindings/src/types/GetTemplateDefinitionRequest.ts new file mode 100644 index 000000000..10a8b6ccd --- /dev/null +++ b/bindings/src/types/GetTemplateDefinitionRequest.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface GetTemplateDefinitionRequest { + template_address: string; +} diff --git a/bindings/src/types/GetTemplateDefinitionResponse.ts b/bindings/src/types/GetTemplateDefinitionResponse.ts new file mode 100644 index 000000000..ebacd3bc1 --- /dev/null +++ b/bindings/src/types/GetTemplateDefinitionResponse.ts @@ -0,0 +1,7 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { TemplateDef } from "./TemplateDef"; + +export interface GetTemplateDefinitionResponse { + name: string; + definition: TemplateDef; +} diff --git a/bindings/src/types/Instruction.ts b/bindings/src/types/Instruction.ts index 630248902..76802f18c 100644 --- a/bindings/src/types/Instruction.ts +++ b/bindings/src/types/Instruction.ts @@ -8,7 +8,7 @@ import type { LogLevel } from "./LogLevel"; export type Instruction = | { CallFunction: { template_address: string; function: string; args: Array } } - | { CallMethod: { component_address: ComponentAddress; method: string; args: Array } } + | { CallMethod: { component_address: ComponentAddress; method: string; args: Array } } | { PutLastInstructionOutputOnWorkspace: { key: Array } } | { EmitLog: { level: LogLevel; message: string } } | { ClaimBurn: { claim: ConfidentialClaim } } diff --git a/bindings/src/types/JrpcPermission.ts b/bindings/src/types/JrpcPermission.ts index 735a39e0b..a31939c7d 100644 --- a/bindings/src/types/JrpcPermission.ts +++ b/bindings/src/types/JrpcPermission.ts @@ -1,8 +1,3 @@ -/* - * // Copyright 2024 The Tari Project - * // SPDX-License-Identifier: BSD-3-Clause - */ - // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { ComponentAddress } from "./ComponentAddress"; import type { ResourceAddress } from "./ResourceAddress"; @@ -13,6 +8,8 @@ export type JrpcPermission = | { NftGetOwnershipProof: ResourceAddress | null } | { AccountBalance: SubstateId } | { AccountList: ComponentAddress | null } + | "SubstatesRead" + | "TemplatesRead" | "KeyList" | "TransactionGet" | { TransactionSend: SubstateId | null } diff --git a/bindings/src/types/JrpcPermissions.ts b/bindings/src/types/JrpcPermissions.ts index 90158ef86..9c212ab4e 100644 --- a/bindings/src/types/JrpcPermissions.ts +++ b/bindings/src/types/JrpcPermissions.ts @@ -1,8 +1,3 @@ -/* - * // Copyright 2024 The Tari Project - * // SPDX-License-Identifier: BSD-3-Clause - */ - // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { JrpcPermission } from "./JrpcPermission"; diff --git a/bindings/src/types/SubstateType.ts b/bindings/src/types/SubstateType.ts new file mode 100644 index 000000000..72e7c5a85 --- /dev/null +++ b/bindings/src/types/SubstateType.ts @@ -0,0 +1,10 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type SubstateType = + | "Component" + | "Resource" + | "Vault" + | "UnclaimedConfidentialOutput" + | "NonFungible" + | "TransactionReceipt" + | "FeeClaim"; diff --git a/bindings/src/types/SubstatesGetRequest.ts b/bindings/src/types/SubstatesGetRequest.ts new file mode 100644 index 000000000..d2f36c712 --- /dev/null +++ b/bindings/src/types/SubstatesGetRequest.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { SubstateId } from "./SubstateId"; + +export interface SubstatesGetRequest { + substate_id: SubstateId; +} diff --git a/bindings/src/types/SubstatesGetResponse.ts b/bindings/src/types/SubstatesGetResponse.ts new file mode 100644 index 000000000..fc42ab866 --- /dev/null +++ b/bindings/src/types/SubstatesGetResponse.ts @@ -0,0 +1,8 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Substate } from "./Substate"; +import type { WalletSubstateRecord } from "./WalletSubstateRecord"; + +export interface SubstatesGetResponse { + record: WalletSubstateRecord; + value: Substate; +} diff --git a/bindings/src/types/SubstatesListRequest.ts b/bindings/src/types/SubstatesListRequest.ts new file mode 100644 index 000000000..938b4a09f --- /dev/null +++ b/bindings/src/types/SubstatesListRequest.ts @@ -0,0 +1,7 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { SubstateType } from "./SubstateType"; + +export interface SubstatesListRequest { + filter_by_template: string | null; + filter_by_type: SubstateType | null; +} diff --git a/bindings/src/types/SubstatesListResponse.ts b/bindings/src/types/SubstatesListResponse.ts new file mode 100644 index 000000000..6907c84b0 --- /dev/null +++ b/bindings/src/types/SubstatesListResponse.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { WalletSubstateRecord } from "./WalletSubstateRecord"; + +export interface SubstatesListResponse { + substates: Array; +} diff --git a/bindings/src/types/TemplateDef.ts b/bindings/src/types/TemplateDef.ts new file mode 100644 index 000000000..9fbbfaa7e --- /dev/null +++ b/bindings/src/types/TemplateDef.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { TemplateDefV1 } from "./TemplateDefV1"; + +export type TemplateDef = { V1: TemplateDefV1 }; diff --git a/bindings/src/types/TemplateDefV1.ts b/bindings/src/types/TemplateDefV1.ts new file mode 100644 index 000000000..03427e25a --- /dev/null +++ b/bindings/src/types/TemplateDefV1.ts @@ -0,0 +1,8 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { FunctionDef } from "./FunctionDef"; + +export interface TemplateDefV1 { + template_name: string; + tari_version: string; + functions: Array; +} diff --git a/bindings/src/types/TemplatesGetRequest.ts b/bindings/src/types/TemplatesGetRequest.ts new file mode 100644 index 000000000..828f2dd7b --- /dev/null +++ b/bindings/src/types/TemplatesGetRequest.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface TemplatesGetRequest { + template_address: string; +} diff --git a/bindings/src/types/TemplatesGetResponse.ts b/bindings/src/types/TemplatesGetResponse.ts new file mode 100644 index 000000000..e125232f8 --- /dev/null +++ b/bindings/src/types/TemplatesGetResponse.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { TemplateDef } from "./TemplateDef"; + +export interface TemplatesGetResponse { + template_definition: TemplateDef; +} diff --git a/bindings/src/types/TransactionStatus.ts b/bindings/src/types/TransactionStatus.ts index cb3b43f71..ab9356ff7 100644 --- a/bindings/src/types/TransactionStatus.ts +++ b/bindings/src/types/TransactionStatus.ts @@ -1,8 +1,3 @@ -/* - * // Copyright 2024 The Tari Project - * // SPDX-License-Identifier: BSD-3-Clause - */ - // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. export type TransactionStatus = diff --git a/bindings/src/types/ValidatorNode.ts b/bindings/src/types/ValidatorNode.ts index f7476bc51..4f3ac8eb9 100644 --- a/bindings/src/types/ValidatorNode.ts +++ b/bindings/src/types/ValidatorNode.ts @@ -2,7 +2,7 @@ import type { Epoch } from "./Epoch"; import type { SubstateAddress } from "./SubstateAddress"; -export interface ValidatorNode { +export interface ValidatorNode { address: string; public_key: string; shard_key: SubstateAddress; diff --git a/bindings/src/types/WalletSubstateRecord.ts b/bindings/src/types/WalletSubstateRecord.ts new file mode 100644 index 000000000..a6e102937 --- /dev/null +++ b/bindings/src/types/WalletSubstateRecord.ts @@ -0,0 +1,10 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { SubstateId } from "./SubstateId"; + +export interface WalletSubstateRecord { + substate_id: SubstateId; + parent_id: SubstateId | null; + module_name: string | null; + version: number; + template_address: string | null; +} diff --git a/clients/base_node_client/src/grpc.rs b/clients/base_node_client/src/grpc.rs index d6300c672..b56595138 100644 --- a/clients/base_node_client/src/grpc.rs +++ b/clients/base_node_client/src/grpc.rs @@ -34,7 +34,7 @@ use tari_dan_common_types::SubstateAddress; use tari_utilities::ByteArray; use crate::{ - types::{BaseLayerConsensusConstants, BaseLayerMetadata, BlockInfo, SideChainUtxos, ValidatorNode}, + types::{BaseLayerConsensusConstants, BaseLayerMetadata, BaseLayerValidatorNode, BlockInfo, SideChainUtxos}, BaseNodeClient, BaseNodeClientError, }; @@ -114,7 +114,7 @@ impl BaseNodeClient for GrpcBaseNodeClient { }) } - async fn get_validator_nodes(&mut self, height: u64) -> Result, BaseNodeClientError> { + async fn get_validator_nodes(&mut self, height: u64) -> Result, BaseNodeClientError> { let inner = self.connection().await?; let request = grpc::GetActiveValidatorNodesRequest { height }; @@ -124,7 +124,7 @@ impl BaseNodeClient for GrpcBaseNodeClient { loop { match stream.message().await { Ok(Some(val)) => { - vns.push(ValidatorNode { + vns.push(BaseLayerValidatorNode { public_key: PublicKey::from_canonical_bytes(&val.public_key).map_err(|_| { BaseNodeClientError::InvalidPeerMessage("public_key was not a valid public key".to_string()) })?, diff --git a/clients/base_node_client/src/traits.rs b/clients/base_node_client/src/traits.rs index b5a91287b..ffbb51c09 100644 --- a/clients/base_node_client/src/traits.rs +++ b/clients/base_node_client/src/traits.rs @@ -8,14 +8,14 @@ use tari_dan_common_types::SubstateAddress; use crate::{ error::BaseNodeClientError, - types::{BaseLayerConsensusConstants, BaseLayerMetadata, SideChainUtxos, ValidatorNode}, + types::{BaseLayerConsensusConstants, BaseLayerMetadata, BaseLayerValidatorNode, SideChainUtxos}, }; #[async_trait] pub trait BaseNodeClient: Send + Sync + Clone { async fn test_connection(&mut self) -> Result<(), BaseNodeClientError>; async fn get_tip_info(&mut self) -> Result; - async fn get_validator_nodes(&mut self, height: u64) -> Result, BaseNodeClientError>; + async fn get_validator_nodes(&mut self, height: u64) -> Result, BaseNodeClientError>; async fn get_shard_key( &mut self, height: u64, diff --git a/clients/base_node_client/src/types.rs b/clients/base_node_client/src/types.rs index 064e2816c..0206dd3dd 100644 --- a/clients/base_node_client/src/types.rs +++ b/clients/base_node_client/src/types.rs @@ -29,7 +29,7 @@ pub struct BlockInfo { #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] -pub struct ValidatorNode { +pub struct BaseLayerValidatorNode { #[cfg_attr(feature = "ts", ts(type = "string"))] pub public_key: PublicKey, pub shard_key: SubstateAddress, diff --git a/clients/javascript/wallet_daemon_client/package.json b/clients/javascript/wallet_daemon_client/package.json index f87081514..b376d230a 100644 --- a/clients/javascript/wallet_daemon_client/package.json +++ b/clients/javascript/wallet_daemon_client/package.json @@ -1,5 +1,5 @@ { - "name": "@tari/wallet_jrpc_client", + "name": "@tarilabs/wallet_jrpc_client", "version": "1.0.0", "description": "Tari wallet JSON-RPC client library", "scripts": { diff --git a/clients/javascript/wallet_daemon_client/src/index.ts b/clients/javascript/wallet_daemon_client/src/index.ts index d5012e617..eb4bee884 100644 --- a/clients/javascript/wallet_daemon_client/src/index.ts +++ b/clients/javascript/wallet_daemon_client/src/index.ts @@ -4,29 +4,84 @@ */ import { + AccountGetDefaultRequest, + AccountGetRequest, + AccountGetResponse, AccountsGetBalancesRequest, AccountsGetBalancesResponse, + Arg, + FinalizeResult, + TemplateDef, + FunctionDef, + Type, + ArgDef, + Instruction, SubstatesGetRequest, SubstatesGetResponse, SubstatesListRequest, SubstatesListResponse, + SubstateType, TransactionSubmitRequest, TransactionSubmitResponse, - AccountGetRequest, - AccountGetResponse, AccountGetDefaultRequest + SubstateId, + TransactionWaitResultRequest, + TransactionWaitResultResponse, TemplatesGetRequest, TemplatesGetResponse, } from 'bindings/index'; -export type { AccountsGetBalancesRequest, AccountsGetBalancesResponse, TransactionSubmitRequest, TransactionSubmitResponse, AccountGetRequest, AccountGetResponse, AccountGetDefaultRequest }; +export type { + AccountGetDefaultRequest, + AccountGetRequest, + AccountGetResponse, + AccountsGetBalancesRequest, + AccountsGetBalancesResponse, + TemplateDef, + FunctionDef, + Type, + ArgDef, + TemplatesGetResponse, + TemplatesGetRequest, + SubstatesGetResponse, + SubstatesGetRequest, + SubstateId, + FinalizeResult, + Arg, + SubstateType, + Instruction, + SubstatesListRequest, + SubstatesListResponse, + TransactionSubmitRequest, + TransactionSubmitResponse, + TransactionWaitResultRequest, + TransactionWaitResultResponse +}; export function createClient(url: string): WalletDaemonClient { return new WalletDaemonClient(url); } export class WalletDaemonClient { + private token: string | null; private url: string; private id: number; constructor(url: string) { + this.token = null; this.url = url; this.id = 0; } + setToken(token: string) { + this.token = token; + } + + async authRequest(permissions: string[]): Promise { + // TODO: Exchange some secret credentials for a JWT + let resp = await this.__invokeRpc("auth.request", {permissions}); + return resp.auth_token; + } + + async authAccept(adminToken: string, name: string): Promise { + let resp = await this.__invokeRpc("auth.accept", {auth_token: adminToken, name}); + this.token = resp.permissions_token; + return this.token; + } + accountsGetBalances(params: AccountsGetBalancesRequest): Promise { return this.__invokeRpc("accounts.get_balances", params); } @@ -42,10 +97,31 @@ export class WalletDaemonClient { submitTransaction(params: TransactionSubmitRequest): Promise { return this.__invokeRpc("transactions.submit", params); } + substatesGet(params: SubstatesGetRequest): Promise { + return this.__invokeRpc("substates.get", params); + } + + substatesList(params: SubstatesListRequest): Promise { + return this.__invokeRpc("substates.list", params); + } - async __invokeRpc(method: string, params: Object = null) { - let id = this.id++; - let response = await fetch(this.url, { + waitForTransactionResult(params: TransactionWaitResultRequest): Promise { + return this.__invokeRpc("transactions.wait_result", params); + } + + templatesGet(params: TemplatesGetRequest): Promise { + return this.__invokeRpc("templates.get", params); + } + + async __invokeRpc(method: string, params: object = null) { + const id = this.id++; + const headers = { + "Content-Type": "application/json", + }; + if (this.token) { + headers["Authorization"] = `Bearer ${this.token}`; + } + const response = await fetch(this.url, { method: "POST", body: JSON.stringify({ method: method, @@ -53,11 +129,9 @@ export class WalletDaemonClient { id: id, params: params || {}, }), - headers: { - "Content-Type": "application/json", - }, + headers, }); - let json = await response.json(); + const json = await response.json(); if (json.error) { throw new Error(`${json.error.code}: ${json.error.message}`); } diff --git a/clients/tari_indexer_client/Cargo.toml b/clients/tari_indexer_client/Cargo.toml index 7d79dc1d2..034381993 100644 --- a/clients/tari_indexer_client/Cargo.toml +++ b/clients/tari_indexer_client/Cargo.toml @@ -13,6 +13,7 @@ tari_dan_common_types = { workspace = true } tari_engine_types = { workspace = true } tari_transaction = { workspace = true } tari_dan_storage = { workspace = true } +tari_template_abi = { workspace = true } anyhow = { workspace = true } reqwest = { workspace = true, features = ["json"] } diff --git a/clients/tari_indexer_client/src/json_rpc_client.rs b/clients/tari_indexer_client/src/json_rpc_client.rs index 643e46a5d..ed066d60a 100644 --- a/clients/tari_indexer_client/src/json_rpc_client.rs +++ b/clients/tari_indexer_client/src/json_rpc_client.rs @@ -38,6 +38,8 @@ use crate::{ GetNonFungiblesResponse, GetSubstateRequest, GetSubstateResponse, + GetTemplateDefinitionRequest, + GetTemplateDefinitionResponse, GetTransactionResultRequest, GetTransactionResultResponse, SubmitTransactionRequest, @@ -100,6 +102,13 @@ impl IndexerJsonRpcClient { self.send_request("get_transaction_result", req).await } + pub async fn get_template_definition( + &mut self, + req: GetTemplateDefinitionRequest, + ) -> Result { + self.send_request("get_template_definition", req).await + } + pub async fn delete_address(&mut self, req: DeleteAddressRequest) -> Result<(), IndexerClientError> { self.send_request("delete_address", req).await } diff --git a/clients/tari_indexer_client/src/types.rs b/clients/tari_indexer_client/src/types.rs index 29ade752d..a10c207bb 100644 --- a/clients/tari_indexer_client/src/types.rs +++ b/clients/tari_indexer_client/src/types.rs @@ -7,7 +7,7 @@ use multiaddr::Multiaddr; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; use serde_with::{serde_as, DisplayFromStr}; -use tari_base_node_client::types::ValidatorNode; +use tari_base_node_client::types::BaseLayerValidatorNode; use tari_common_types::types::PublicKey; use tari_dan_common_types::Epoch; use tari_dan_storage::consensus_models::Decision; @@ -15,6 +15,7 @@ use tari_engine_types::{ commit_result::ExecuteResult, serde_with as serde_tools, substate::{Substate, SubstateId}, + TemplateAddress, }; use tari_transaction::{SubstateRequirement, Transaction, TransactionId}; #[cfg(feature = "ts")] @@ -135,7 +136,7 @@ pub struct GetAllVnsRequest { #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct GetAllVnsResponse { - pub vns: Vec, + pub vns: Vec, } #[serde_as] @@ -286,3 +287,17 @@ pub enum ConnectionDirection { pub struct GetConnectionsResponse { pub connections: Vec, } + +#[derive(Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct GetTemplateDefinitionRequest { + #[cfg_attr(feature = "ts", ts(type = "string"))] + pub template_address: TemplateAddress, +} + +#[derive(Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct GetTemplateDefinitionResponse { + pub name: String, + pub definition: tari_template_abi::TemplateDef, +} diff --git a/clients/validator_node_client/src/types.rs b/clients/validator_node_client/src/types.rs index 365482996..2375b706b 100644 --- a/clients/validator_node_client/src/types.rs +++ b/clients/validator_node_client/src/types.rs @@ -25,10 +25,10 @@ use std::{ops::RangeInclusive, time::Duration}; use multiaddr::Multiaddr; use serde::{Deserialize, Serialize}; use tari_common_types::{transaction::TxId, types::PublicKey}; -use tari_dan_common_types::{committee::CommitteeShard, shard::Shard, Epoch, SubstateAddress}; +use tari_dan_common_types::{committee::CommitteeShard, shard::Shard, Epoch, PeerAddress, SubstateAddress}; use tari_dan_storage::{ consensus_models::{Block, BlockId, Decision, ExecutedTransaction, QuorumDecision, SubstateRecord}, - global::models::ValidatorNode, + global::models, Ordering, }; use tari_engine_types::{ @@ -282,18 +282,46 @@ pub struct GetCommitteeRequest { } #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] -pub struct GetNetworkCommitteeResponse { +pub struct GetNetworkCommitteeResponse { pub current_epoch: Epoch, - pub committees: Vec>, + pub committees: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] -pub struct CommitteeShardInfo { +pub struct CommitteeShardInfo { #[cfg_attr(feature = "ts", ts(type = "number"))] pub shard: Shard, pub substate_address_range: RangeInclusive, - pub validators: Vec>, + pub validators: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct ValidatorNode { + #[cfg_attr(feature = "ts", ts(type = "string"))] + pub address: PeerAddress, + #[cfg_attr(feature = "ts", ts(type = "string"))] + pub public_key: PublicKey, + pub shard_key: SubstateAddress, + pub epoch: Epoch, + #[cfg_attr(feature = "ts", ts(type = "number | null"))] + pub committee_shard: Option, + #[cfg_attr(feature = "ts", ts(type = "string"))] + pub fee_claim_public_key: PublicKey, +} + +impl From> for ValidatorNode { + fn from(value: models::ValidatorNode) -> Self { + Self { + address: value.address, + public_key: value.public_key, + shard_key: value.shard_key, + epoch: value.epoch, + committee_shard: value.committee_shard, + fee_claim_public_key: value.fee_claim_public_key, + } + } } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/clients/wallet_daemon_client/Cargo.toml b/clients/wallet_daemon_client/Cargo.toml index 5bc230717..b2265f936 100644 --- a/clients/wallet_daemon_client/Cargo.toml +++ b/clients/wallet_daemon_client/Cargo.toml @@ -15,6 +15,7 @@ tari_transaction = { workspace = true } tari_dan_wallet_sdk = { workspace = true } # TODO: Ideally we should not have to include the WASM template lib, we should perhaps extract the address types into a separate crate (e.g. template_types) tari_template_lib = { workspace = true } +tari_template_abi = { workspace = true } chrono = { workspace = true } reqwest = { workspace = true, features = ["json"] } diff --git a/clients/wallet_daemon_client/src/types.rs b/clients/wallet_daemon_client/src/types.rs index 6ed33ac49..c75f8d173 100644 --- a/clients/wallet_daemon_client/src/types.rs +++ b/clients/wallet_daemon_client/src/types.rs @@ -29,15 +29,17 @@ use tari_common_types::types::PublicKey; use tari_dan_common_types::{Epoch, SubstateAddress}; use tari_dan_wallet_sdk::{ apis::jwt::Claims, - models::{Account, ConfidentialProofId, TransactionStatus}, + models::{Account, ConfidentialProofId, SubstateType, TransactionStatus}, }; use tari_engine_types::{ commit_result::{ExecuteResult, FinalizeResult}, instruction::Instruction, instruction_result::InstructionResult, serde_with, - substate::SubstateId, + substate::{Substate, SubstateId}, + TemplateAddress, }; +use tari_template_abi::TemplateDef; use tari_template_lib::{ args::Arg, auth::ComponentAccessRules, @@ -717,3 +719,57 @@ pub struct SettingsSetResponse {} pub struct SettingsGetResponse { pub indexer_url: String, } + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct SubstatesListRequest { + #[serde(default, deserialize_with = "serde_with::string::option::deserialize")] + #[cfg_attr(feature = "ts", ts(type = "string | null"))] + pub filter_by_template: Option, + pub filter_by_type: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct SubstatesListResponse { + pub substates: Vec, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct SubstatesGetRequest { + pub substate_id: SubstateId, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct SubstatesGetResponse { + pub record: WalletSubstateRecord, + pub value: Substate, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct WalletSubstateRecord { + pub substate_id: SubstateId, + pub parent_id: Option, + pub module_name: Option, + pub version: u32, + #[serde(default, with = "serde_with::string::option")] + #[cfg_attr(feature = "ts", ts(type = "string | null"))] + pub template_address: Option, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct TemplatesGetRequest { + #[cfg_attr(feature = "ts", ts(type = "string"))] + #[serde(with = "serde_with::string")] + pub template_address: TemplateAddress, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] +pub struct TemplatesGetResponse { + pub template_definition: TemplateDef, +} diff --git a/dan_layer/engine_types/src/instruction.rs b/dan_layer/engine_types/src/instruction.rs index df4d33c33..19a4a848d 100644 --- a/dan_layer/engine_types/src/instruction.rs +++ b/dan_layer/engine_types/src/instruction.rs @@ -34,6 +34,8 @@ pub enum Instruction { component_address: ComponentAddress, method: String, #[serde(deserialize_with = "crate::argument_parser::json_deserialize")] + // Argument parser takes an array of strings as input + #[cfg_attr(feature = "ts", ts(type = "Array"))] args: Vec, }, PutLastInstructionOutputOnWorkspace { diff --git a/dan_layer/engine_types/src/serde_with/string.rs b/dan_layer/engine_types/src/serde_with/string.rs index e37f63659..c6c623ce2 100644 --- a/dan_layer/engine_types/src/serde_with/string.rs +++ b/dan_layer/engine_types/src/serde_with/string.rs @@ -26,3 +26,32 @@ where T::deserialize(d) } } + +pub mod option { + use super::*; + + pub fn serialize(v: &Option, s: S) -> Result { + if s.is_human_readable() { + match v { + Some(v) => s.serialize_some(&v.to_string()), + None => s.serialize_none(), + } + } else { + v.serialize(s) + } + } + + pub fn deserialize<'de, D, T>(d: D) -> Result, D::Error> + where + D: Deserializer<'de>, + T: FromStr + DeserializeOwned, + T::Err: std::fmt::Display, + { + if d.is_human_readable() { + let s = as Deserialize>::deserialize(d)?; + s.map(|s| s.parse()).transpose().map_err(serde::de::Error::custom) + } else { + Option::::deserialize(d) + } + } +} diff --git a/dan_layer/storage/src/global/models/validator_node.rs b/dan_layer/storage/src/global/models/validator_node.rs index 3b622c0c9..5e79d8969 100644 --- a/dan_layer/storage/src/global/models/validator_node.rs +++ b/dan_layer/storage/src/global/models/validator_node.rs @@ -5,21 +5,14 @@ use serde::{Deserialize, Serialize}; use tari_common::configuration::Network; use tari_common_types::types::{FixedHash, PublicKey}; use tari_dan_common_types::{shard::Shard, vn_node_hash, Epoch, NodeAddressable, SubstateAddress}; -#[cfg(feature = "ts")] -use ts_rs::TS; #[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct ValidatorNode { - #[cfg_attr(feature = "ts", ts(type = "string"))] pub address: TAddr, - #[cfg_attr(feature = "ts", ts(type = "string"))] pub public_key: PublicKey, pub shard_key: SubstateAddress, pub epoch: Epoch, - #[cfg_attr(feature = "ts", ts(type = "number | null"))] pub committee_shard: Option, - #[cfg_attr(feature = "ts", ts(type = "string"))] pub fee_claim_public_key: PublicKey, } diff --git a/dan_layer/template_abi/src/types.rs b/dan_layer/template_abi/src/types.rs index d71f47712..7c1a4d93a 100644 --- a/dan_layer/template_abi/src/types.rs +++ b/dan_layer/template_abi/src/types.rs @@ -27,6 +27,7 @@ use ts_rs::TS; use crate::rust::{boxed::Box, string::String, vec::Vec}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub enum TemplateDef { V1(TemplateDefV1), } @@ -58,6 +59,7 @@ impl TemplateDef { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct TemplateDefV1 { pub template_name: String, pub tari_version: String, @@ -71,6 +73,7 @@ impl TemplateDefV1 { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct FunctionDef { pub name: String, pub arguments: Vec, @@ -79,6 +82,7 @@ pub struct FunctionDef { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "ts", derive(TS), ts(export, export_to = "../../bindings/src/types/"))] pub struct ArgDef { pub name: String, pub arg_type: Type, diff --git a/dan_layer/wallet/sdk/Cargo.toml b/dan_layer/wallet/sdk/Cargo.toml index 39933558b..4759a5537 100644 --- a/dan_layer/wallet/sdk/Cargo.toml +++ b/dan_layer/wallet/sdk/Cargo.toml @@ -18,6 +18,7 @@ tari_hash_domains = { workspace = true } tari_key_manager = { workspace = true } tari_transaction = { workspace = true } tari_template_lib = { workspace = true } +tari_template_abi = { workspace = true } tari_utilities = { workspace = true } anyhow = { workspace = true } diff --git a/dan_layer/wallet/sdk/src/apis/jwt.rs b/dan_layer/wallet/sdk/src/apis/jwt.rs index 75bf8aed7..c8c6d6290 100644 --- a/dan_layer/wallet/sdk/src/apis/jwt.rs +++ b/dan_layer/wallet/sdk/src/apis/jwt.rs @@ -30,6 +30,8 @@ pub enum JrpcPermission { NftGetOwnershipProof(Option), AccountBalance(SubstateId), AccountList(Option), + SubstatesRead, + TemplatesRead, KeyList, TransactionGet, TransactionSend(Option), @@ -67,6 +69,8 @@ impl FromStr for JrpcPermission { "AccountInfo" => Ok(JrpcPermission::AccountInfo), "NftGetOwnershipProof" => Ok(JrpcPermission::NftGetOwnershipProof(None)), "AccountList" => Ok(JrpcPermission::AccountList(None)), + "SubstatesRead" => Ok(JrpcPermission::SubstatesRead), + "TemplatesRead" => Ok(JrpcPermission::TemplatesRead), "KeyList" => Ok(JrpcPermission::KeyList), "GetNft" => Ok(JrpcPermission::GetNft(None, None)), "TransactionGet" => Ok(JrpcPermission::TransactionGet), @@ -95,6 +99,8 @@ impl Display for JrpcPermission { JrpcPermission::GetNft(_, _) => f.write_str("GetNft"), JrpcPermission::StartWebrtc => f.write_str("StartWebrtc"), JrpcPermission::Admin => f.write_str("Admin"), + JrpcPermission::SubstatesRead => f.write_str("SubstatesRead"), + JrpcPermission::TemplatesRead => f.write_str("TemplatesRead"), } } } diff --git a/dan_layer/wallet/sdk/src/apis/substate.rs b/dan_layer/wallet/sdk/src/apis/substate.rs index c40e80d06..5857b1a78 100644 --- a/dan_layer/wallet/sdk/src/apis/substate.rs +++ b/dan_layer/wallet/sdk/src/apis/substate.rs @@ -9,11 +9,12 @@ use tari_engine_types::{ indexed_value::{IndexedValueError, IndexedWellKnownTypes}, substate::{SubstateId, SubstateValue}, transaction_receipt::TransactionReceiptAddress, + TemplateAddress, }; use tari_transaction::TransactionId; use crate::{ - models::{SubstateModel, VersionedSubstateId}, + models::{SubstateModel, SubstateType, VersionedSubstateId}, network::WalletNetworkInterface, storage::{WalletStorageError, WalletStore, WalletStoreReader, WalletStoreWriter}, }; @@ -44,6 +45,18 @@ where Ok(substate) } + pub fn list_substates( + &self, + filter_by_type: Option, + filter_by_template: Option<&TemplateAddress>, + limit: Option, + offset: Option, + ) -> Result, SubstateApiError> { + let mut tx = self.store.create_read_tx()?; + let substates = tx.substates_get_all(filter_by_type, filter_by_template, limit, offset)?; + Ok(substates) + } + pub fn load_dependent_substates( &self, parents: &[&SubstateId], diff --git a/dan_layer/wallet/sdk/src/models/substate.rs b/dan_layer/wallet/sdk/src/models/substate.rs index b9fa54a91..b6c1259b7 100644 --- a/dan_layer/wallet/sdk/src/models/substate.rs +++ b/dan_layer/wallet/sdk/src/models/substate.rs @@ -17,6 +17,36 @@ pub struct SubstateModel { pub template_address: Option, } +#[derive(Debug, Clone, Copy, Deserialize, Serialize)] +#[cfg_attr( + feature = "ts", + derive(ts_rs::TS), + ts(export, export_to = "../../bindings/src/types/") +)] +pub enum SubstateType { + Component, + Resource, + Vault, + UnclaimedConfidentialOutput, + NonFungible, + TransactionReceipt, + FeeClaim, +} + +impl SubstateType { + pub fn as_prefix_str(&self) -> &str { + match self { + SubstateType::Component => "component", + SubstateType::Resource => "resource", + SubstateType::Vault => "vault", + SubstateType::UnclaimedConfidentialOutput => "commitment", + SubstateType::NonFungible => "nft", + SubstateType::TransactionReceipt => "txreceipt", + SubstateType::FeeClaim => "feeclaim", + } + } +} + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct VersionedSubstateId { #[serde(with = "serde_with::string")] diff --git a/dan_layer/wallet/sdk/src/network.rs b/dan_layer/wallet/sdk/src/network.rs index 736ab6416..8e1db401c 100644 --- a/dan_layer/wallet/sdk/src/network.rs +++ b/dan_layer/wallet/sdk/src/network.rs @@ -11,6 +11,8 @@ use tari_engine_types::{ commit_result::ExecuteResult, substate::{Substate, SubstateId}, }; +use tari_template_abi::TemplateDef; +use tari_template_lib::prelude::TemplateAddress; use tari_transaction::{SubstateRequirement, Transaction, TransactionId}; #[async_trait] @@ -40,6 +42,8 @@ pub trait WalletNetworkInterface { &self, transaction_id: TransactionId, ) -> Result; + + async fn fetch_template_definition(&self, template_address: TemplateAddress) -> Result; } #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/dan_layer/wallet/sdk/src/storage.rs b/dan_layer/wallet/sdk/src/storage.rs index f7011d8a2..c77bd9945 100644 --- a/dan_layer/wallet/sdk/src/storage.rs +++ b/dan_layer/wallet/sdk/src/storage.rs @@ -24,6 +24,7 @@ use crate::models::{ NonFungibleToken, OutputStatus, SubstateModel, + SubstateType, TransactionStatus, VaultModel, VersionedSubstateId, @@ -125,6 +126,13 @@ pub trait WalletStoreReader { ) -> Result, WalletStorageError>; // Substates fn substates_get(&mut self, address: &SubstateId) -> Result; + fn substates_get_all( + &mut self, + by_type: Option, + by_template_address: Option<&TemplateAddress>, + limit: Option, + offset: Option, + ) -> Result, WalletStorageError>; fn substates_get_children(&mut self, parent: &SubstateId) -> Result, WalletStorageError>; // Accounts fn accounts_get(&mut self, address: &SubstateId) -> Result; diff --git a/dan_layer/wallet/sdk/tests/confidential_output_api.rs b/dan_layer/wallet/sdk/tests/confidential_output_api.rs index e4fac33a0..4611afb73 100644 --- a/dan_layer/wallet/sdk/tests/confidential_output_api.rs +++ b/dan_layer/wallet/sdk/tests/confidential_output_api.rs @@ -17,9 +17,10 @@ use tari_dan_wallet_sdk::{ }; use tari_dan_wallet_storage_sqlite::SqliteWalletStore; use tari_engine_types::substate::SubstateId; +use tari_template_abi::TemplateDef; use tari_template_lib::{ constants::CONFIDENTIAL_TARI_RESOURCE_ADDRESS, - models::{Amount, EncryptedData}, + models::{Amount, EncryptedData, TemplateAddress}, resource::ResourceType, }; use tari_transaction::{SubstateRequirement, Transaction, TransactionId}; @@ -265,4 +266,8 @@ impl WalletNetworkInterface for PanicIndexer { ) -> Result { panic!("PanicIndexer called") } + + async fn fetch_template_definition(&self, _template_address: TemplateAddress) -> Result { + panic!("PanicIndexer called") + } } diff --git a/dan_layer/wallet/storage_sqlite/src/reader.rs b/dan_layer/wallet/storage_sqlite/src/reader.rs index cb0dfe110..22a3e4f9b 100644 --- a/dan_layer/wallet/storage_sqlite/src/reader.rs +++ b/dan_layer/wallet/storage_sqlite/src/reader.rs @@ -26,13 +26,17 @@ use tari_dan_wallet_sdk::{ NonFungibleToken, OutputStatus, SubstateModel, + SubstateType, TransactionStatus, VaultModel, WalletTransaction, }, storage::{WalletStorageError, WalletStoreReader}, }; -use tari_engine_types::substate::{InvalidSubstateIdFormat, SubstateId}; +use tari_engine_types::{ + substate::{InvalidSubstateIdFormat, SubstateId}, + TemplateAddress, +}; use tari_template_lib::{ models::{ResourceAddress, VaultId}, prelude::{ComponentAddress, NonFungibleId}, @@ -239,6 +243,36 @@ impl WalletStoreReader for ReadTransaction<'_> { Ok(rec) } + fn substates_get_all( + &mut self, + by_type: Option, + by_template_address: Option<&TemplateAddress>, + limit: Option, + offset: Option, + ) -> Result, WalletStorageError> { + use crate::schema::substates; + + let mut query = substates::table.into_boxed(); + if let Some(template_address) = by_template_address { + query = query.filter(substates::template_address.eq(template_address.to_string())); + } + if let Some(substate_type) = by_type { + query = query.filter(substates::address.like(format!("{}_%", substate_type.as_prefix_str()))); + } + if let Some(limit) = limit { + query = query.limit(limit as i64); + } + if let Some(offset) = offset { + query = query.offset(offset as i64); + } + + let rows = query + .get_results::(self.connection()) + .map_err(|e| WalletStorageError::general("substates_get_all", e))?; + + rows.into_iter().map(|rec| rec.try_to_record()).collect() + } + fn substates_get_children(&mut self, parent: &SubstateId) -> Result, WalletStorageError> { use crate::schema::substates;