Skip to content

Commit

Permalink
Change sync options (#1737)
Browse files Browse the repository at this point in the history
* Change sync options

* Remove clone
  • Loading branch information
Thoralf-M authored Jan 23, 2023
1 parent b74768e commit e541547
Show file tree
Hide file tree
Showing 31 changed files with 336 additions and 165 deletions.
7 changes: 7 additions & 0 deletions .changes/syncOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"nodejs-binding": patch
---

Renamed AccountSyncOptions to SyncOptions;
Added AccountSyncOptions, AliasSyncOptions and NftSyncOptions;
Replaced SyncOptions::syncAliasesAndNfts with SyncOptions::{account, alias, nft};
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `TransactionOptionsDto`;
- `Transaction::inputs` and `TransactionDto::inputs` fields;
- Derive `Eq, PartialEq` for `Account` and `OutputData`;
- `AccountSyncOptions, AliasSyncOptions, NftSyncOptions`;
- `SyncOptions::{account, alias, nft}` fields;

### Changed

Expand All @@ -41,11 +43,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Account::{get_incoming_transaction_data(), incoming_transactions()}` return now `Transaction` instead of `(TransactionPayload, Vec<OutputWithMetadataResponse>)`;
- `AccountDto::incoming_transactions` from `(TransactionPayloadDto, Vec<OutputWithMetadataResponse>)` to `TransactionDto`;
- `Response::{IncomingTransactionData, IncomingTransactionsData}` contain `TransactionDto` instead of `IncomingTransactionDataDto`;
- Default `SyncOptions` don't sync alias and nft outputs anymore;

### Removed

- `clear_listeners` from the `WalletMessageHandler`;
- `IncomingTransactionDataDto` type;
- `SyncOptions::sync_aliases_and_nfts`;

## 1.0.0-rc.4 - 2022-12-23

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@
- Fixes `setStrongholdPassword` accepting a wrong password after a few tries.
- [991c2e6](https://github.com/iotaledger/wallet.rs/commit/991c2e68c1f88f0c327d1cd37a1275089aaf0ed3) fix(stronghold): mark client as loaded if the snapshot decrypt succeeded ([#357](https://github.com/iotaledger/wallet.rs/pull/357)) on 2021-03-01
- Adds the `options: SyncOptions` parameter on the `AccountManager#syncAccounts` method.
- [9855cfa](https://github.com/iotaledger/wallet.rs/commit/9855cfa4ce7296d04d1c647c7f6ca1722784eb33) refactor(manager): `sync_accounts` gap_limit and address_index options ([#346](https://github.com/iotaledger/wallet.rs/pull/346)) on 2021-02-24
- [9855cfa](https://github.com/iotaledger/wallet.rs/commit/9855cfa4ce7296d04d1c647c7f6ca1722784eb33) refactor(manager): `syncs` gap_limit and address_index options ([#346](https://github.com/iotaledger/wallet.rs/pull/346)) on 2021-02-24
- Move `transfer`, `retry`, `reattach`, `promote` APIs to the account object.
- [8b808c8](https://github.com/iotaledger/wallet.rs/commit/8b808c80bbb7bc1e6b9858551880684a0400ab0c) refactor(sync): automatic sync before transfer/retry/reattach/promote ([#365](https://github.com/iotaledger/wallet.rs/pull/365)) on 2021-03-02
- Added a `TransferProgress` event type, triggered on transfer steps progress.
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { MessageHandler } from './MessageHandler';
import type {
AccountBalance,
AccountMetadata,
AccountSyncOptions,
SyncOptions,
AccountMeta,
Address,
AddressWithAmount,
Expand Down Expand Up @@ -1078,7 +1078,7 @@ export class Account {
* @param options Optional synchronization options.
* @returns The account balance.
*/
async sync(options?: AccountSyncOptions): Promise<AccountBalance> {
async sync(options?: SyncOptions): Promise<AccountBalance> {
const resp = await this.messageHandler.callAccountMethod(
this.meta.index,
{
Expand Down
35 changes: 30 additions & 5 deletions bindings/nodejs/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface NativeTokenBalance {
}

/** Sync options for an account */
export interface AccountSyncOptions {
export interface SyncOptions {
/**
* Specific Bech32 encoded addresses of the account to sync, if addresses are provided,
* then `address_start_index` will be ignored
Expand All @@ -86,15 +86,40 @@ export interface AccountSyncOptions {
syncIncomingTransactions?: boolean;
/** Checks pending transactions and promotes/reattaches them if necessary. Default: true. */
syncPendingTransactions?: boolean;
/** Specifies if only basic outputs should be synced or also alias and nft outputs. Default: true. */
syncAliasesAndNfts?: boolean;
/** Specifies if only basic outputs with an AddressUnlockCondition alone should be synced, will overwrite
* `syncAliasesAndNfts`. Default: false. */
/** Specifies what outputs should be synced for the ed25519 addresses from the account. */
account?: AccountSyncOptions;
/** Specifies what outputs should be synced for the address of an alias output. */
alias?: AliasSyncOptions;
/** Specifies what outputs should be synced for the address of an nft output. */
nft?: NftSyncOptions;
/** Specifies if only basic outputs with an AddressUnlockCondition alone should be synced, will overwrite `account`, `alias` and `nft` options. Default: false. */
syncOnlyMostBasicOutputs?: boolean;
/** Sync native token foundries, so their metadata can be returned in the balance. Default: false. */
syncNativeTokenFoundries?: boolean;
}

/** Specifies what outputs should be synced for the ed25519 addresses from the account. */
export interface AccountSyncOptions {
basicOutputs?: boolean;
aliasOutputs?: boolean;
nftOutputs?: boolean;
}

/** Specifies what outputs should be synced for the address of an alias output. */
export interface AliasSyncOptions {
basicOutputs?: boolean;
aliasOutputs?: boolean;
nftOutputs?: boolean;
foundryOutputs?: boolean;
}

/** Specifies what outputs should be synced for the address of an nft output. */
export interface NftSyncOptions {
basicOutputs?: boolean;
aliasOutputs?: boolean;
nftOutputs?: boolean;
}

/** The account object */
export interface AccountMeta {
index: number;
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/types/bridge/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OutputTypes, HexEncodedAmount } from '@iota/types';
import type { AccountSyncOptions, FilterOptions } from '../account';
import type { SyncOptions, FilterOptions } from '../account';
import type {
AddressWithAmount,
AddressWithMicroAmount,
Expand Down Expand Up @@ -349,7 +349,7 @@ export type __SubmitAndStoreTransactionMethod__ = {
export type __SyncAccountMethod__ = {
name: 'syncAccount';
data: {
options?: AccountSyncOptions;
options?: SyncOptions;
};
};

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/10-claim-outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
wallet.set_stronghold_password("some_hopefully_secure_password")

# Sync account with the node
response = account.sync_account()
response = account.sync()

# Only the unspent outputs in the account
output_ids = account.get_outputs_with_additional_unlock_conditions('All')
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/2-check-balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

# Just calculate the balance with the known state
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/3-send-transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/4-send-micro-transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/5-send-native-tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/6-send-nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/examples/7-mint-native-tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand All @@ -18,7 +18,7 @@
# Wait a few seconds for the transaction to get confirmed
time.sleep(7)

account.sync_account()
account.sync()

native_token_options = {
# 1000 hex encoded
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/8-mint-nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/burn_native_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/burn_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/decrease-native-tokens-supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/destroy_foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/examples/request_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync_account()
response = account.sync()
print(f'Synced: {response}')

# Balance before funding
Expand All @@ -21,7 +21,7 @@
time.sleep(20)

# Sync account with the node
response = account.sync_account()
response = account.sync()

# Balance after funding
balance = account.get_balance()
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/iota_wallet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def retry_transaction_until_included(self, transaction_id, interval=None, max_at
}
)

def sync_account(self, options=None):
def sync(self, options=None):
"""Sync the account by fetching new information from the nodes.
Will also retry pending transactions and consolidate outputs if necessary.
"""
Expand Down
3 changes: 3 additions & 0 deletions documentation/docs/references/nodejs/api_ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
- [BaseCoinBalance](interfaces/BaseCoinBalance.md)
- [RequiredStorageDeposit](interfaces/RequiredStorageDeposit.md)
- [NativeTokenBalance](interfaces/NativeTokenBalance.md)
- [SyncOptions](interfaces/SyncOptions.md)
- [AccountSyncOptions](interfaces/AccountSyncOptions.md)
- [AliasSyncOptions](interfaces/AliasSyncOptions.md)
- [NftSyncOptions](interfaces/NftSyncOptions.md)
- [AccountMeta](interfaces/AccountMeta.md)
- [AccountMetadata](interfaces/AccountMetadata.md)
- [CreateAccountPayload](interfaces/CreateAccountPayload.md)
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/references/nodejs/classes/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ Will also retry pending transactions if necessary.

| Name | Type | Description |
| :------ | :------ | :------ |
| `options?` | [`AccountSyncOptions`](../interfaces/AccountSyncOptions.md) | Optional synchronization options. |
| `options?` | [`SyncOptions`](../interfaces/SyncOptions.md) | Optional synchronization options. |

#### Returns

Expand Down
Original file line number Diff line number Diff line change
@@ -1,86 +1,3 @@
# Interface: AccountSyncOptions

Sync options for an account

## Table of contents

### Properties

- [addresses](AccountSyncOptions.md#addresses)
- [addressStartIndex](AccountSyncOptions.md#addressstartindex)
- [addressStartIndexInternal](AccountSyncOptions.md#addressstartindexinternal)
- [forceSyncing](AccountSyncOptions.md#forcesyncing)
- [syncPendingTransactions](AccountSyncOptions.md#syncpendingtransactions)
- [syncAliasesAndNfts](AccountSyncOptions.md#syncaliasesandnfts)
- [syncOnlyMostBasicOutputs](AccountSyncOptions.md#synconlymostbasicoutputs)
- [syncNativeTokenFoundries](AccountSyncOptions.md#syncnativetokenfoundries)

## Properties

### addresses

`Optional` **addresses**: `string`[]

Specific Bech32 encoded addresses of the account to sync, if addresses are provided,
then `address_start_index` will be ignored

___

### addressStartIndex

`Optional` **addressStartIndex**: `number`

Address index from which to start syncing addresses. 0 by default, using a higher index will be faster because
addresses with a lower index will be skipped, but could result in a wrong balance for that reason

___

### addressStartIndexInternal

`Optional` **addressStartIndexInternal**: `number`

Address index from which to start syncing internal addresses. 0 by default, using a higher index will be faster
because addresses with a lower index will be skipped, but could result in a wrong balance for that reason

___

### forceSyncing

`Optional` **forceSyncing**: `boolean`

Usually syncing is skipped if it's called in between 200ms, because there can only be new changes every
milestone and calling it twice "at the same time" will not return new data
When this to true, we will sync anyways, even if it's called 0ms after the las sync finished. Default: false.

___

### syncPendingTransactions

`Optional` **syncPendingTransactions**: `boolean`

Checks pending transactions and promotes/reattaches them if necessary. Default: true.

___

### syncAliasesAndNfts

`Optional` **syncAliasesAndNfts**: `boolean`

Specifies if only basic outputs should be synced or also alias and nft outputs. Default: true.

___

### syncOnlyMostBasicOutputs

`Optional` **syncOnlyMostBasicOutputs**: `boolean`

Specifies if only basic outputs with an AddressUnlockCondition alone should be synced, will overwrite
`syncAliasesAndNfts`. Default: false.

___

### syncNativeTokenFoundries

`Optional` **syncNativeTokenFoundries**: `boolean`

Sync native token foundries, so their metadata can be returned in the balance. Default: false.
Specifies what outputs should be synced for the ed25519 addresses from the account.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Interface: AliasSyncOptions

Specifies what outputs should be synced for the address of an alias output.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Interface: NftSyncOptions

Specifies what outputs should be synced for the address of an nft output.
Loading

0 comments on commit e541547

Please sign in to comment.