Skip to content

Commit

Permalink
Replace reissue_transaction_until_included() with wait_for_transactio…
Browse files Browse the repository at this point in the history
…n_acceptance() (iotaledger#1979)

* reissue_transaction_until_included -> await_transaction_acceptance

* Update log

* Change interval to ms, update error

* Fix wasm

* Apply suggestions from code review

Co-authored-by: DaughterOfMars <[email protected]>

* Casing

* Review suggestions

* Don't build block, rename file, move failed code into TransactionState::Failed branch

* Rename to wait_for

* Apply suggestions from code review

Co-authored-by: DaughterOfMars <[email protected]>

* fmt

* Adapt to rename

* Rename part 2

* Duration const, use block id from node response, move timeouts after first request

* Rename const

---------

Co-authored-by: DaughterOfMars <[email protected]>
  • Loading branch information
Thoralf-M and DaughterOfMars authored Feb 12, 2024
1 parent 75cfa6f commit 8a3933f
Show file tree
Hide file tree
Showing 83 changed files with 382 additions and 407 deletions.
6 changes: 3 additions & 3 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ pub enum WalletMethod {
// RegisterParticipationEvents {
// options: ParticipationEventRegistrationOptions,
// },
/// Reissues a transaction sent from the wallet for a provided transaction id until it's
/// included (referenced by a milestone). Returns the included block id.
/// Checks the transaction state for a provided transaction id until it's accepted. Interval in milliseconds.
/// Returns the block id that contains this transaction.
/// Expected response: [`BlockId`](crate::Response::BlockId)
#[serde(rename_all = "camelCase")]
ReissueTransactionUntilIncluded {
WaitForTransactionAcceptance {
/// Transaction id
transaction_id: TransactionId,
/// Interval
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
// let events = wallet.register_participation_events(&options).await?;
// Response::ParticipationEvents(events)
// }
WalletMethod::ReissueTransactionUntilIncluded {
WalletMethod::WaitForTransactionAcceptance {
transaction_id,
interval,
max_attempts,
} => {
let block_id = wallet
.reissue_transaction_until_included(&transaction_id, interval, max_attempts)
.wait_for_transaction_acceptance(&transaction_id, interval, max_attempts)
.await?;
Response::BlockId(block_id)
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub enum Response {
/// - [`BlockId`](crate::method::UtilsMethod::BlockId)
/// - [`PostBlock`](crate::method::ClientMethod::PostBlock)
/// - [`PostBlockRaw`](crate::method::ClientMethod::PostBlockRaw)
/// - [`ReissueTransactionUntilIncluded`](crate::method::WalletMethod::ReissueTransactionUntilIncluded)
/// - [`WaitForTransactionAcceptance`](crate::method::WalletMethod::WaitForTransactionAcceptance)
BlockId(BlockId),
/// Response for:
/// - [`GetHealth`](crate::method::ClientMethod::GetHealth)
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/account_output/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

balance = await wallet.sync();
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/account_output/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
console.log(`Destroyed account output ${accountId}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function run() {
allowMicroAmount: false,
};
const transaction = await wallet.sendWithParams(params, options);
await wallet.reissueTransactionUntilIncluded(transaction.transactionId);
await wallet.waitForTransactionAcceptance(transaction.transactionId);
console.log(
`Transaction with custom input: https://explorer.iota.org/testnet/transaction/${transaction.transactionId}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ async function run() {
const transaction = await wallet.sendOutputs([basicOutput]);
console.log(`Transaction sent: ${transaction.transactionId}`);

console.log('Waiting until included in block...');
const blockId = await wallet.reissueTransactionUntilIncluded(
console.log('Waiting until transaction is accepted...');
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(`Block sent: ${process.env.EXPLORER_URL}/block/${blockId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function run() {
const transaction = await wallet.claimOutputs(output_ids);
console.log(`Transaction sent: ${transaction.transactionId}`);

const blockId = await wallet.reissueTransactionUntilIncluded(
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(`Block sent: ${process.env.EXPLORER_URL}/block/${blockId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

const blockId = await wallet.reissueTransactionUntilIncluded(
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/native_tokens/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

balance = await wallet.sync();
Expand Down
12 changes: 6 additions & 6 deletions bindings/nodejs/examples/how_tos/native_tokens/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ async function run() {
.then((prepared) => prepared.send());
console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

await wallet.sync();
Expand All @@ -71,13 +71,13 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

console.log(`Created token: ${prepared.tokenId()}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

balance = await wallet.sync();
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/native_tokens/melt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

balance = await wallet.sync();
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/native_tokens/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

balance = await wallet.sync();
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/native_tokens/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

balance = await wallet.sync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ async function run() {
};
const transaction = await wallet.mintNfts([params]);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

transaction.payload.transaction.outputs.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ async function run() {
);
const transaction = await wallet.mintNfts(chunk);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

// Sync so the new outputs are available again for new transactions
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/nfts/burn_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);
console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
console.log(`Burned NFT ${nftId}`);

Expand Down
12 changes: 6 additions & 6 deletions bindings/nodejs/examples/how_tos/nfts/mint_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ async function run() {
let transaction = await wallet.mintNfts([params]);
console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
let blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
let blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
console.log('Minted NFT 1');

Expand All @@ -104,13 +104,13 @@ async function run() {
transaction = await wallet.sendOutputs([output]);
console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

console.log('Minted NFT 2');
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/how_tos/nfts/send_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ async function run() {

console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);

// To send an NFT with expiration unlock condition prepareOutput() can be used like this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ async function run() {
});
console.log('Transaction sent: %s', transaction.transactionId);

// Wait for the consolidation transaction to get confirmed
const blockId = wallet.reissueTransactionUntilIncluded(
// Wait for the consolidation transaction to get accepted
const blockId = wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
'Transaction included: %s/block/$s',
'Transaction accepted: %s/block/$s',
process.env.EXPLORER_URL,
blockId,
);
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/wallet/06-send-micro-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ async function run() {
});
console.log(`Transaction sent: ${transaction.transactionId}`);

// Wait for transaction to get included
const blockId = await wallet.reissueTransactionUntilIncluded(
// Wait for transaction to get accepted
const blockId = await wallet.waitForTransactionAcceptance(
transaction.transactionId,
);

console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
`Tx accepted in block: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
} catch (error) {
console.log('Error: ', error);
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type ClientErrorName =
| 'secretManagerMismatch'
| 'healthyNodePoolEmpty'
| 'taggedData'
| 'tangleInclusion'
| 'transactionAcceptance'
| 'taskJoin'
| 'timeNotSynced'
| 'transactionSemantic'
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/wallet/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type {
__PrepareEndStakingMethod__,
__PrepareTransactionMethod__,
__RegisterParticipationEventsMethod__,
__ReissueTransactionUntilIncludedMethod__,
__WaitForTransactionAcceptanceMethod__,
__SendMethod__,
__SendWithParamsMethod__,
__PrepareSendNativeTokensMethod__,
Expand Down Expand Up @@ -114,7 +114,7 @@ export type __WalletMethod__ =
| __PrepareEndStakingMethod__
| __PrepareTransactionMethod__
| __RegisterParticipationEventsMethod__
| __ReissueTransactionUntilIncludedMethod__
| __WaitForTransactionAcceptanceMethod__
| __SendMethod__
| __SendWithParamsMethod__
| __PrepareSendNativeTokensMethod__
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/wallet/bridge/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ export type __RegisterParticipationEventsMethod__ = {
};
};

export type __ReissueTransactionUntilIncludedMethod__ = {
name: 'reissueTransactionUntilIncluded';
export type __WaitForTransactionAcceptanceMethod__ = {
name: 'waitForTransactionAcceptance';
data: {
transactionId: TransactionId;
interval?: number;
Expand Down
Loading

0 comments on commit 8a3933f

Please sign in to comment.