From e74d19a7d608a4783a8614561522704f69875bb3 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Tue, 27 Feb 2024 10:13:03 +0100 Subject: [PATCH] Flatten and fix ClientOptions in bindings (#2042) * Flatten ClientOptions in bindings * Fix types in ProtocolParameters * Remove tangle_time from bindings, update copyright date * Remove tangleTime from JS Binding * Remove comment * Unflatten mqtt broker options * Update event API link * Undo changes --------- Co-authored-by: Thibault Martinez --- bindings/nodejs/examples/client/10-mqtt.ts | 2 +- .../nodejs/lib/types/client/client-options.ts | 11 ++++++---- .../types/models/info/node-info-protocol.ts | 20 +++++++++++-------- .../nodejs/lib/types/models/storage-score.ts | 12 +++++------ .../nodejs/tests/client/infoMethods.spec.ts | 14 +++++++++++++ bindings/python/examples/client/mqtt.py | 2 +- bindings/python/iota_sdk/client/client.py | 6 ++++++ .../python/iota_sdk/types/client_options.py | 2 +- sdk/src/client/builder.rs | 2 +- 9 files changed, 49 insertions(+), 22 deletions(-) diff --git a/bindings/nodejs/examples/client/10-mqtt.ts b/bindings/nodejs/examples/client/10-mqtt.ts index 79b4133e3a..3d77ac5c57 100644 --- a/bindings/nodejs/examples/client/10-mqtt.ts +++ b/bindings/nodejs/examples/client/10-mqtt.ts @@ -24,7 +24,7 @@ async function run() { }); // Array of topics to subscribe to - // Topics can be found here https://studio.asyncapi.com/?url=https://raw.githubusercontent.com/iotaledger/tips/main/tips/TIP-0028/event-api.yml + // Topics can be found here https://studio.asyncapi.com/?url=https://raw.githubusercontent.com/iotaledger/tips/tip48/tips/TIP-0048/asyncapi3.yaml const topics = ['blocks']; const callback = function (error: Error, data: string) { diff --git a/bindings/nodejs/lib/types/client/client-options.ts b/bindings/nodejs/lib/types/client/client-options.ts index 5fe0ba5b07..864f2b5f67 100644 --- a/bindings/nodejs/lib/types/client/client-options.ts +++ b/bindings/nodejs/lib/types/client/client-options.ts @@ -1,6 +1,7 @@ -// Copyright 2021-2023 IOTA Stiftung +// Copyright 2021-2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { ProtocolParameters } from '../models'; + +import { ProtocolParameters } from '../models/info/node-info-protocol'; import type { IMqttBrokerOptions, INode } from './network'; /** Options for the client builder */ @@ -21,10 +22,12 @@ export interface IClientOptions { minQuorumSize?: number; /** % of nodes that have to return the same response so it gets accepted */ quorumThreshold?: number; - /** Data related to the used network */ - protocolParameters?: ProtocolParameters; + /** The User-Agent header for requests */ + userAgent?: string; /** Options for the MQTT broker */ brokerOptions?: IMqttBrokerOptions; + /** Protocol parameters */ + protocolParameters?: ProtocolParameters; /** Timeout for API requests */ apiTimeout?: IDuration; /** The maximum parallel API requests. */ diff --git a/bindings/nodejs/lib/types/models/info/node-info-protocol.ts b/bindings/nodejs/lib/types/models/info/node-info-protocol.ts index 584a661cc8..d17b8d3cbe 100644 --- a/bindings/nodejs/lib/types/models/info/node-info-protocol.ts +++ b/bindings/nodejs/lib/types/models/info/node-info-protocol.ts @@ -3,7 +3,7 @@ import type { StorageScoreParameters } from '../storage-score'; import { EpochIndex } from '../../block/slot'; -import { u64 } from '../../utils/type-aliases'; +import { NumericString } from '../../utils'; /** * The Protocol Info. @@ -54,7 +54,7 @@ interface ProtocolParameters { /** * Current supply of base token. */ - tokenSupply: u64; + tokenSupply: NumericString; /** * Genesis Slot defines the slot of the genesis. */ @@ -62,7 +62,7 @@ interface ProtocolParameters { /** * The genesis timestamp at which the slots start to count. */ - genesisUnixTimestamp: u64; + genesisUnixTimestamp: NumericString; /** * The duration of a slot, in seconds. */ @@ -145,11 +145,11 @@ interface RewardsParameters { /** * Decay Balancing Constant Exponent is the exponent used for calculation of the initial reward. */ - initialTargetRewardsRate: u64; + initialTargetRewardsRate: NumericString; /** * The rate of Mana rewards after the bootstrapping phase. */ - finalTargetRewardsRate: u64; + finalTargetRewardsRate: NumericString; /** * Pool Coefficient Exponent is the exponent used for shifting operation * in the pool rewards calculations. @@ -239,6 +239,10 @@ interface ManaParameters { * The scaling of ManaDecayFactorEpochsSum expressed as an exponent of 2. */ decayFactorEpochsSumExponent: number; + /** + * Decay factor for 1 year. + */ + annualDecayFactorPercentage: number; } /** @@ -248,15 +252,15 @@ interface CongestionControlParameters { /** * The minimum value of the reference Mana cost. */ - minReferenceManaCost: u64; + minReferenceManaCost: NumericString; /** * The increase step size of the reference Mana cost. */ - increase: u64; + increase: NumericString; /** * The decrease step size of the reference Mana cost. */ - decrease: u64; + decrease: NumericString; /** * The threshold for increasing the reference Mana cost. */ diff --git a/bindings/nodejs/lib/types/models/storage-score.ts b/bindings/nodejs/lib/types/models/storage-score.ts index aa9b975136..89952f69b9 100644 --- a/bindings/nodejs/lib/types/models/storage-score.ts +++ b/bindings/nodejs/lib/types/models/storage-score.ts @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { u64 } from '../utils/type-aliases'; +import { NumericString } from '../utils'; /** * Defines the parameters of storage score calculations on objects which take node resources. @@ -10,7 +10,7 @@ export interface StorageScoreParameters { /** * Defines the number of IOTA tokens required per unit of storage score. */ - storageCost: u64; + storageCost: NumericString; /** * Defines the factor to be used for data only fields. */ @@ -18,17 +18,17 @@ export interface StorageScoreParameters { /** * Defines the offset to be applied to all outputs for the overhead of handling them in storage. */ - offsetOutputOverhead: u64; + offsetOutputOverhead: NumericString; /** * Defines the offset to be used for block issuer feature public keys. */ - offsetEd25519BlockIssuerKey: u64; + offsetEd25519BlockIssuerKey: NumericString; /** * Defines the offset to be used for staking feature. */ - offsetStakingFeature: u64; + offsetStakingFeature: NumericString; /** * Defines the offset to be used for delegation output. */ - offsetDelegation: u64; + offsetDelegation: NumericString; } diff --git a/bindings/nodejs/tests/client/infoMethods.spec.ts b/bindings/nodejs/tests/client/infoMethods.spec.ts index 5ec63bba74..e106076481 100644 --- a/bindings/nodejs/tests/client/infoMethods.spec.ts +++ b/bindings/nodejs/tests/client/infoMethods.spec.ts @@ -7,6 +7,7 @@ import 'dotenv/config'; import { Client } from '../../lib/client'; import '../customMatchers'; +import protocolParametersFixture from '../../../../sdk/tests/types/fixtures/protocol_parameters.json'; async function makeClient(): Promise { return await Client.create({ @@ -80,3 +81,16 @@ describe.skip('Client info methods', () => { expect(bech32Hrp).toBeDefined(); }); }); + +// TODO: enable after ProtocolParameters fixture is updated https://github.com/iotaledger/iota-sdk/issues/2040 +// describe('Offline client info methods', () => { + // it('provided protocol parameters', async () => { + // const protocolParameters = protocolParametersFixture.params; + // const client = await Client.create({ + // protocolParameters + // }); + // const networkInfo = await client.getNetworkInfo(); + + // expect(networkInfo.protocolParameters).toStrictEqual(protocolParameters); + // }); +// }) diff --git a/bindings/python/examples/client/mqtt.py b/bindings/python/examples/client/mqtt.py index c948af27cd..78aeebc724 100644 --- a/bindings/python/examples/client/mqtt.py +++ b/bindings/python/examples/client/mqtt.py @@ -35,7 +35,7 @@ def callback(event): # Topics can be found here -# https://studio.asyncapi.com/?url=https://raw.githubusercontent.com/iotaledger/tips/main/tips/TIP-0028/event-api.yml +# https://studio.asyncapi.com/?url=https://raw.githubusercontent.com/iotaledger/tips/tip48/tips/TIP-0048/asyncapi3.yaml client.listen_mqtt(["blocks"], callback) # Exit after 10 received events diff --git a/bindings/python/iota_sdk/client/client.py b/bindings/python/iota_sdk/client/client.py index 8835d371ff..646c8c9f27 100644 --- a/bindings/python/iota_sdk/client/client.py +++ b/bindings/python/iota_sdk/client/client.py @@ -13,6 +13,7 @@ from iota_sdk.client._utils import ClientUtils from iota_sdk.client.common import _call_client_method_routine from iota_sdk.types.block.block import UnsignedBlock +from iota_sdk.types.client_options import MqttBrokerOptions from iota_sdk.types.common import HexStr, Node from iota_sdk.types.feature import Feature from iota_sdk.types.network_info import NetworkInfo @@ -45,6 +46,7 @@ def __init__( min_quorum_size: Optional[int] = None, quorum_threshold: Optional[int] = None, user_agent: Optional[str] = None, + broker_options: Optional[MqttBrokerOptions] = None, max_parallel_api_requests: Optional[int] = None, client_handle=None ): @@ -69,6 +71,8 @@ def __init__( % of nodes that have to return the same response so it gets accepted. user_agent : The User-Agent header for requests. + broker_options (MqttBrokerOptions): + Options for the MQTT broker. max_parallel_api_requests : Set maximum parallel API requests. client_handle : @@ -83,6 +87,8 @@ def __init__( client_config['primary_nodes'] = convert_nodes(primary_nodes) client_config['nodes'] = convert_nodes(nodes) + if broker_options is not None: + client_config['broker_options'] = broker_options.to_dict() if protocol_parameters is not None: client_config['protocol_parameters'] = protocol_parameters.to_dict() diff --git a/bindings/python/iota_sdk/types/client_options.py b/bindings/python/iota_sdk/types/client_options.py index 34a1c6521a..42124b4f90 100644 --- a/bindings/python/iota_sdk/types/client_options.py +++ b/bindings/python/iota_sdk/types/client_options.py @@ -1,4 +1,4 @@ -# Copyright 2023 IOTA Stiftung +# Copyright 2024 IOTA Stiftung # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations diff --git a/sdk/src/client/builder.rs b/sdk/src/client/builder.rs index 01a70d101c..1e6a018c27 100644 --- a/sdk/src/client/builder.rs +++ b/sdk/src/client/builder.rs @@ -33,7 +33,7 @@ pub struct ClientBuilder { /// Options for the MQTT broker #[cfg(feature = "mqtt")] #[cfg_attr(docsrs, doc(cfg(feature = "mqtt")))] - #[serde(flatten)] + #[serde(default)] pub broker_options: BrokerOptions, /// Protocol parameters #[serde(default, skip_serializing_if = "Option::is_none")]