Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace reissue_transaction_until_included() with wait_for_transaction_acceptance() #1979

Merged

Conversation

Thoralf-M
Copy link
Member

@Thoralf-M Thoralf-M commented Feb 9, 2024

Description of change

Replace reissue_transaction_until_included() with wait_for_transaction_acceptance() because we can't simply reissue blocks anymore, since they cost Mana. So now it only issues the block once when there was no block issued yet (should happen only very rarely because of some node/network issue) and then just checks the transaction acceptance.
Also changed the interval to milliseconds and set the default to 500, so it can return faster.

Links to any relevant issues

Closes #1930

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How the change has been tested

Running this example

use iota_sdk::{
    types::block::output::{
        unlock_condition::{AddressUnlockCondition, ExpirationUnlockCondition},
        NftOutputBuilder, UnlockCondition,
    },
    wallet::Result,
    Wallet,
};

#[tokio::main]
async fn main() -> Result<()> {
    let logger_output_config = fern_logger::LoggerOutputConfigBuilder::new()
        .name("wallet.log")
        .target_exclusions(&["h2", "hyper", "rustls"])
        .level_filter(log::LevelFilter::Debug);

    let config = fern_logger::LoggerConfig::build()
        .with_output(logger_output_config)
        .finish();

    fern_logger::logger_init(config).unwrap();
    // This example uses secrets in environment variables for simplicity which should not be done in production.
    dotenvy::dotenv().ok();

    let wallet = Wallet::builder()
        .with_storage_path(&"./cli/stardust-cli-wallet-db")
        .finish()
        .await?;

    // May want to ensure the wallet is synced before sending a transaction.
    let balance = wallet.sync(None).await?;

    // Get the first nft
    if let Some(nft_id) = balance.nfts().first() {
        // Set the stronghold password
        wallet.set_stronghold_password("test".to_string()).await?;

        let nft = NftOutputBuilder::new_with_amount(1_000_000, *nft_id)
            .with_unlock_conditions([
                UnlockCondition::Address(AddressUnlockCondition::new(wallet.address().await)),
                UnlockCondition::Expiration(ExpirationUnlockCondition::new(
                    wallet.address().await,
                    wallet.client().get_slot_index().await? + 5000,
                )?),
            ])
            .finish_output()?;

        let transaction = wallet.send_outputs(vec![nft], None).await?;
        println!("Transaction sent: {}", transaction.transaction_id);

        println!("Tx: {:?}", transaction);

        let block_id = wallet
            .wait_for_transaction_acceptance(&transaction.transaction_id, Some(1), None)
            .await?;

        println!("Block included: /block/{}", block_id);
    } else {
        println!("No available NFTs");
    }

    Ok(())
}

@DaughterOfMars
Copy link

I don't really like BlockOnTransactionAcceptance, what about WaitForTransactionAcceptance?

@thibault-martinez
Copy link
Member

I don't really like BlockOnTransactionAcceptance, what about WaitForTransactionAcceptance?

@DaughterOfMars it has been discussed here #1979 (comment) if you want to comment

@Thoralf-M Thoralf-M changed the title Replace reissue_transaction_until_included() with await_transaction_acceptance() Replace reissue_transaction_until_included() with wait_for_transaction_acceptance() Feb 12, 2024
DaughterOfMars
DaughterOfMars previously approved these changes Feb 12, 2024
DaughterOfMars
DaughterOfMars previously approved these changes Feb 12, 2024
@thibault-martinez thibault-martinez merged commit 8a3933f into iotaledger:2.0 Feb 12, 2024
37 checks passed
@Thoralf-M Thoralf-M deleted the await_transaction_acceptance branch February 12, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change reissue_transaction_until_included() to await_block_inclusion()?
4 participants