-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
60 changed files
with
834 additions
and
283 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
applications/tari_dan_wallet_daemon/src/handlers/substates.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>, | ||
req: SubstatesGetRequest, | ||
) -> Result<SubstatesGetResponse, anyhow::Error> { | ||
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<String>, | ||
req: SubstatesListRequest, | ||
) -> Result<SubstatesListResponse, anyhow::Error> { | ||
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 }) | ||
} |
23 changes: 23 additions & 0 deletions
23
applications/tari_dan_wallet_daemon/src/handlers/templates.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>, | ||
req: TemplatesGetRequest, | ||
) -> Result<TemplatesGetResponse, anyhow::Error> { | ||
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 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.