Skip to content

Commit

Permalink
Flatten and fix ClientOptions in bindings (#2042)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Thoralf-M and thibault-martinez authored Feb 27, 2024
1 parent 772a566 commit e74d19a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/client/10-mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions bindings/nodejs/lib/types/client/client-options.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand All @@ -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. */
Expand Down
20 changes: 12 additions & 8 deletions bindings/nodejs/lib/types/models/info/node-info-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -54,15 +54,15 @@ interface ProtocolParameters {
/**
* Current supply of base token.
*/
tokenSupply: u64;
tokenSupply: NumericString;
/**
* Genesis Slot defines the slot of the genesis.
*/
genesisSlot: number;
/**
* The genesis timestamp at which the slots start to count.
*/
genesisUnixTimestamp: u64;
genesisUnixTimestamp: NumericString;
/**
* The duration of a slot, in seconds.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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.
*/
Expand Down
12 changes: 6 additions & 6 deletions bindings/nodejs/lib/types/models/storage-score.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -10,25 +10,25 @@ 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.
*/
factorData: number;
/**
* 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;
}
14 changes: 14 additions & 0 deletions bindings/nodejs/tests/client/infoMethods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Client> {
return await Client.create({
Expand Down Expand Up @@ -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);
// });
// })
2 changes: 1 addition & 1 deletion bindings/python/examples/client/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions bindings/python/iota_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
):
Expand All @@ -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 :
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/client_options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 IOTA Stiftung
# Copyright 2024 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit e74d19a

Please sign in to comment.