Skip to content

Commit

Permalink
Add DelegationOutput (#719)
Browse files Browse the repository at this point in the history
* Add DelegationOutput

* Nit

* Fix a match

* Add delegation to chain ID

* Fix compilation

* Clippy

* Docs

* Update sdk/src/types/block/output/delegation.rs

Co-authored-by: /alex/ <[email protected]>

* Update sdk/src/types/block/output/delegation.rs

Co-authored-by: /alex/ <[email protected]>

* Remove doc

* Nits

* Fmt and audit

---------

Co-authored-by: /alex/ <[email protected]>
  • Loading branch information
thibault-martinez and Alex6323 committed Jul 17, 2023
1 parent e0e68e4 commit 187caed
Show file tree
Hide file tree
Showing 9 changed files with 746 additions and 61 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/bindings-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
sudo apt-get update
sudo apt-get install libudev-dev libusb-1.0-0-dev
- name: Run Tox
working-directory: bindings/python
run: tox
# TODO temporarily disabled https://github.com/iotaledger/iota-sdk/issues/647
# - name: Run Tox
# working-directory: bindings/python
# run: tox
4 changes: 2 additions & 2 deletions sdk/examples/client/02_address_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ async fn main() -> Result<()> {
.await?;

// Get the outputs by their id
let outputs_responses = client.get_outputs(&output_ids_response.items).await?;
let outputs = client.get_outputs(&output_ids_response.items).await?;

// Calculate the total amount and native tokens
let mut total_amount = 0;
let mut total_native_tokens = NativeTokensBuilder::new();
for output in outputs_responses {
for output in outputs {
if let Some(native_tokens) = output.native_tokens() {
total_native_tokens.add_native_tokens(native_tokens.clone())?;
}
Expand Down
12 changes: 11 additions & 1 deletion sdk/examples/client/block/04_block_tagged_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ async fn main() -> Result<()> {
.finish_block_builder(
None,
Some(Payload::TaggedData(Box::new(
TaggedDataPayload::new(b"Hello".to_vec(), b"Tangle".to_vec()).unwrap(),
TaggedDataPayload::new(
std::env::args()
.nth(1)
.unwrap_or_else(|| "Hello".to_string())
.as_bytes(),
std::env::args()
.nth(2)
.unwrap_or_else(|| "Tangle".to_string())
.as_bytes(),
)
.unwrap(),
))),
)
.await?;
Expand Down
8 changes: 7 additions & 1 deletion sdk/src/types/block/output/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use derive_more::From;

use crate::types::block::output::{AccountId, FoundryId, NftId, OutputId};
use crate::types::block::output::{AccountId, DelegationId, FoundryId, NftId, OutputId};

///
#[derive(Clone, Copy, Eq, Hash, PartialEq, Ord, PartialOrd, From)]
Expand All @@ -15,6 +15,8 @@ pub enum ChainId {
Foundry(FoundryId),
///
Nft(NftId),
///
Delegation(DelegationId),
}

impl core::fmt::Debug for ChainId {
Expand All @@ -24,6 +26,7 @@ impl core::fmt::Debug for ChainId {
Self::Account(id) => formatter.field(id),
Self::Foundry(id) => formatter.field(id),
Self::Nft(id) => formatter.field(id),
Self::Delegation(id) => formatter.field(id),
};
formatter.finish()
}
Expand All @@ -36,6 +39,7 @@ impl ChainId {
Self::Account(id) => id.is_null(),
Self::Foundry(id) => id.is_null(),
Self::Nft(id) => id.is_null(),
Self::Delegation(id) => id.is_null(),
}
}

Expand All @@ -49,6 +53,7 @@ impl ChainId {
Self::Account(_) => Self::Account(AccountId::from(output_id)),
Self::Foundry(_) => self,
Self::Nft(_) => Self::Nft(NftId::from(output_id)),
Self::Delegation(_) => Self::Delegation(DelegationId::from(output_id)),
}
}
}
Expand All @@ -59,6 +64,7 @@ impl core::fmt::Display for ChainId {
Self::Account(id) => write!(f, "{id}"),
Self::Foundry(id) => write!(f, "{id}"),
Self::Nft(id) => write!(f, "{id}"),
Self::Delegation(id) => write!(f, "{id}"),
}
}
}
Loading

0 comments on commit 187caed

Please sign in to comment.