Skip to content

Commit

Permalink
Remove metadata from output endpoint (#673)
Browse files Browse the repository at this point in the history
* Remove metadata from output endpoint

* Fix compilation

* Remove wallet nodejs workflow

* Use get_output_raw

* Move get_output_with_metadata
  • Loading branch information
thibault-martinez authored and Alex Coats committed Jul 24, 2023
1 parent 227f887 commit 62c5920
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 159 deletions.
106 changes: 0 additions & 106 deletions .github/workflows/bindings-wallet-nodejs.yml

This file was deleted.

6 changes: 3 additions & 3 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetBlockRaw { block_id } => Response::Raw(client.get_block_raw(&block_id).await?),
ClientMethod::GetOutput { output_id } => Response::OutputWithMetadataResponse(
client
.get_output(&output_id)
.get_output_with_metadata(&output_id)
.await
.map(OutputWithMetadataResponse::from)?,
),
Expand Down Expand Up @@ -313,7 +313,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::FoundryOutputId { foundry_id } => Response::OutputId(client.foundry_output_id(foundry_id).await?),
ClientMethod::GetOutputs { output_ids } => {
let outputs_response = client
.get_outputs(&output_ids)
.get_outputs_with_metadata(&output_ids)
.await?
.iter()
.map(OutputWithMetadataResponse::from)
Expand All @@ -322,7 +322,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
}
ClientMethod::GetOutputsIgnoreErrors { output_ids } => {
let outputs_response = client
.get_outputs_ignore_errors(&output_ids)
.get_outputs_with_metadata_ignore_errors(&output_ids)
.await?
.iter()
.map(OutputWithMetadataResponse::from)
Expand Down
3 changes: 1 addition & 2 deletions sdk/examples/client/02_address_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ async fn main() -> Result<()> {
// Calculate the total amount and native tokens
let mut total_amount = 0;
let mut total_native_tokens = NativeTokensBuilder::new();
for output_response in outputs_responses {
let output = output_response.output();
for output in outputs_responses {
if let Some(native_tokens) = output.native_tokens() {
total_native_tokens.add_native_tokens(native_tokens.clone())?;
}
Expand Down
14 changes: 6 additions & 8 deletions sdk/examples/client/output/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,16 @@ async fn main() -> Result<()> {
let output_ids_response = client
.basic_output_ids([QueryParameter::Address(bech32_nft_address)])
.await?;
let output_with_meta = client.get_output(&output_ids_response.items[0]).await?;
let output = client.get_output(&output_ids_response.items[0]).await?;

let block = client
.build_block()
.with_secret_manager(&secret_manager)
.with_input(nft_output_id.into())?
.with_input(output_ids_response.items[0].into())?
.with_outputs([
NftOutputBuilder::new_with_amount(1_000_000 + output_with_meta.output().amount(), nft_id)
.add_unlock_condition(AddressUnlockCondition::new(bech32_nft_address))
.finish_output(token_supply)?,
])?
.with_outputs([NftOutputBuilder::new_with_amount(1_000_000 + output.amount(), nft_id)
.add_unlock_condition(AddressUnlockCondition::new(bech32_nft_address))
.finish_output(token_supply)?])?
.finish()
.await?;

Expand All @@ -122,8 +120,8 @@ async fn main() -> Result<()> {
//////////////////////////////////

let nft_output_id = get_nft_output_id(block.payload().unwrap())?;
let output_with_meta = client.get_output(&nft_output_id).await?;
let outputs = [BasicOutputBuilder::new_with_amount(output_with_meta.output().amount())
let output = client.get_output(&nft_output_id).await?;
let outputs = [BasicOutputBuilder::new_with_amount(output.amount())
.add_unlock_condition(AddressUnlockCondition::new(bech32_nft_address))
.finish_output(token_supply)?];

Expand Down
4 changes: 1 addition & 3 deletions sdk/examples/client/send_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ async fn main() -> Result<()> {
let mut total_amount = 0;
let mut total_native_tokens = NativeTokensBuilder::new();

for output_response in outputs_responses {
let output = output_response.output();

for output in outputs_responses {
if let Some(native_tokens) = output.native_tokens() {
total_native_tokens.add_native_tokens(native_tokens.clone())?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> ClientBlockBuilder<'a> {
.items,
);

self.client.get_outputs(&output_ids).await
self.client.get_outputs_with_metadata(&output_ids).await
}

/// Searches inputs for provided outputs, by requesting the outputs from the account addresses or for
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/api/block_builder/input_selection/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> ClientBlockBuilder<'a> {

if let Some(inputs) = &self.inputs {
for input in inputs {
let output_with_meta = self.client.get_output(input.output_id()).await?;
let output_with_meta = self.client.get_output_with_metadata(input.output_id()).await?;

if !output_with_meta.metadata().is_spent() {
let alias_transition = is_alias_transition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> ClientBlockBuilder<'a> {
}
}) {
let output_id = self.client.alias_output_id(*alias_id).await?;
let output_with_meta = self.client.get_output(&output_id).await?;
let output_with_meta = self.client.get_output_with_metadata(&output_id).await?;
if let Output::Alias(alias_output) = output_with_meta.output() {
// State transition if we add them to inputs
let unlock_address = alias_output.state_controller_address();
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'a> ClientBlockBuilder<'a> {
}
}) {
let output_id = self.client.nft_output_id(*nft_id).await?;
let output_with_meta = self.client.get_output(&output_id).await?;
let output_with_meta = self.client.get_output_with_metadata(&output_id).await?;
if let Output::Nft(nft_output) = output_with_meta.output() {
let unlock_address = nft_output
.unlock_conditions()
Expand Down
10 changes: 5 additions & 5 deletions sdk/src/client/api/block_builder/input_selection/utxo_chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) async fn get_alias_and_nft_outputs_recursively(
match unlock_address {
Address::Alias(address) => {
let input_id = client.alias_output_id(*address.alias_id()).await?;
let input = client.get_output(&input_id).await?;
let input = client.get_output_with_metadata(&input_id).await?;
if let Output::Alias(alias_input) = input.output() {
// State transition if we add them to inputs
let alias_unlock_address = alias_input.state_controller_address();
Expand All @@ -71,7 +71,7 @@ pub(crate) async fn get_alias_and_nft_outputs_recursively(
}
Address::Nft(address) => {
let input_id = client.nft_output_id(*address.nft_id()).await?;
let input = client.get_output(&input_id).await?;
let input = client.get_output_with_metadata(&input_id).await?;
if let Output::Nft(nft_input) = input.output() {
let unlock_address = nft_input
.unlock_conditions()
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a> ClientBlockBuilder<'a> {
// Check if the transaction is a governance_transition, by checking if the new index is the same
// as the previous index
let output_id = client.alias_output_id(*alias_output.alias_id()).await?;
let input = client.get_output(&output_id).await?;
let input = client.get_output_with_metadata(&output_id).await?;
if let Output::Alias(alias_input) = input.output() {
// A governance transition is identified by an unchanged State Index in next
// state.
Expand All @@ -135,7 +135,7 @@ impl<'a> ClientBlockBuilder<'a> {
// If the id is null then this output creates it and we can't have a previous output
if !nft_output.nft_id().is_null() {
let output_id = client.nft_output_id(*nft_output.nft_id()).await?;
let input = client.get_output(&output_id).await?;
let input = client.get_output_with_metadata(&output_id).await?;
if let Output::Nft(nft_input) = input.output() {
let unlock_address = nft_input
.unlock_conditions()
Expand All @@ -148,7 +148,7 @@ impl<'a> ClientBlockBuilder<'a> {
Output::Foundry(foundry_output) => {
// if it's the first foundry output, then we can't have it as input
if let Ok(output_id) = client.foundry_output_id(foundry_output.id()).await {
let input = client.get_output(&output_id).await?;
let input = client.get_output_with_metadata(&output_id).await?;
if let Output::Foundry(foundry_input_output) = input.output() {
utxo_chains.push((Address::Alias(*foundry_input_output.alias_address()), input));
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/api/consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Client {
])
.await?;

let basic_outputs_responses = self.get_outputs(&output_ids_response.items).await?;
let basic_outputs_responses = self.get_outputs_with_metadata(&output_ids_response.items).await?;

if !basic_outputs_responses.is_empty() {
// If we reach the same index again
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/client/api/high_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Client {
})
.collect::<Vec<_>>();

self.get_outputs(&input_ids).await
self.get_outputs_with_metadata(&input_ids).await
}

/// Get a builder that can be used to construct a block in parts.
Expand Down Expand Up @@ -179,7 +179,7 @@ impl Client {
})
.and_then(|res| async {
let items = res.items;
self.get_outputs(&items).await
self.get_outputs_with_metadata(&items).await
})
.try_collect::<Vec<_>>()
.await?;
Expand Down
Loading

0 comments on commit 62c5920

Please sign in to comment.