Skip to content

Commit

Permalink
Merge branch '2.0' of https://github.com/iotaledger/iota-sdk into 500…
Browse files Browse the repository at this point in the history
…-error-patch
  • Loading branch information
marc2332 committed Feb 27, 2024
2 parents 4570579 + 137f651 commit fdd19a1
Show file tree
Hide file tree
Showing 38 changed files with 233 additions and 194 deletions.
5 changes: 4 additions & 1 deletion bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use iota_sdk::{
node_manager::node::NodeAuth,
},
types::block::{
address::{Bech32Address, Hrp},
address::{Address, Bech32Address, Hrp},
output::{
feature::Feature, unlock_condition::UnlockCondition, AccountId, AnchorId, DelegationId, FoundryId, NftId,
Output, OutputId, TokenScheme,
Expand Down Expand Up @@ -417,6 +417,9 @@ pub enum ClientMethod {
/// Human readable part
bech32_hrp: Option<Hrp>,
},
/// Converts an address to its bech32 representation
#[serde(rename_all = "camelCase")]
AddressToBech32 { address: Address, bech32_hrp: Option<Hrp> },
/// Transforms an account id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
AccountIdToBech32 {
Expand Down
8 changes: 7 additions & 1 deletion bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use derivative::Derivative;
use iota_sdk::{
client::secret::types::InputSigningData,
types::block::{
address::{Bech32Address, Hrp},
address::{Address, Bech32Address, Hrp},
output::{AccountId, AnchorId, NftId, Output, OutputId, StorageScoreParameters},
payload::signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
Expand Down Expand Up @@ -41,6 +41,12 @@ pub enum UtilsMethod {
hex: String,
bech32_hrp: Hrp,
},
/// Converts an address to its bech32 representation
#[serde(rename_all = "camelCase")]
AddressToBech32 {
address: Address,
bech32_hrp: Hrp,
},
/// Transforms an account id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
AccountIdToBech32 {
Expand Down
3 changes: 3 additions & 0 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::HexToBech32 { hex, bech32_hrp } => {
Response::Bech32Address(client.hex_to_bech32(&hex, bech32_hrp).await?)
}
ClientMethod::AddressToBech32 { address, bech32_hrp } => {
Response::Bech32Address(client.address_to_bech32(address, bech32_hrp).await?)
}
ClientMethod::AccountIdToBech32 { account_id, bech32_hrp } => {
Response::Bech32Address(client.account_id_to_bech32(account_id, bech32_hrp).await?)
}
Expand Down
1 change: 1 addition & 0 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
let response = match method {
UtilsMethod::Bech32ToHex { bech32 } => Response::Bech32ToHex(Client::bech32_to_hex(bech32)?),
UtilsMethod::HexToBech32 { hex, bech32_hrp } => Response::Bech32Address(hex_to_bech32(&hex, bech32_hrp)?),
UtilsMethod::AddressToBech32 { address, bech32_hrp } => Response::Bech32Address(address.to_bech32(bech32_hrp)),
UtilsMethod::AccountIdToBech32 { account_id, bech32_hrp } => {
Response::Bech32Address(account_id.to_bech32(bech32_hrp))
}
Expand Down
2 changes: 2 additions & 0 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ pub enum Response {
/// - [`PrepareOutput`](crate::method::WalletMethod::PrepareOutput)
Output(Output),
/// Response for:
/// - [`AddressToBech32`](crate::method::ClientMethod::AddressToBech32)
/// - [`AddressToBech32`](crate::method::UtilsMethod::AddressToBech32)
/// - [`AccountIdToBech32`](crate::method::ClientMethod::AccountIdToBech32)
/// - [`AccountIdToBech32`](crate::method::UtilsMethod::AccountIdToBech32)
/// - [`AnchorIdToBech32`](crate::method::ClientMethod::AnchorIdToBech32)
Expand Down
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
23 changes: 23 additions & 0 deletions bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
SlotIndex,
SlotCommitmentId,
SlotCommitment,
Address,
} from '../types/block';
import { HexEncodedString } from '../utils';
import {
Expand Down Expand Up @@ -690,6 +691,28 @@ export class Client {
return JSON.parse(response).payload;
}

/**
* Converts an address to its bech32 representation
*
* @param address An address.
* @param bech32Hrp The Bech32 HRP (human readable part) to be used.
* @returns The corresponding Bech32 address.
*/
async addressToBech32(
address: Address,
bech32Hrp?: string,
): Promise<Bech32Address> {
const response = await this.methodHandler.callMethod({
name: 'addressToBech32',
data: {
address,
bech32Hrp,
},
});

return JSON.parse(response).payload;
}

/**
* Transforms an account id to a bech32 encoded address.
*
Expand Down
9 changes: 9 additions & 0 deletions bindings/nodejs/lib/types/client/bridge/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
Payload,
SlotIndex,
SlotCommitmentId,
Address,
} from '../../block';
import type { PreparedTransactionData } from '../prepared-transaction-data';
import type {
Expand Down Expand Up @@ -271,6 +272,14 @@ export interface __HexToBech32Method__ {
};
}

export interface __AddressToBech32Method__ {
name: 'addressToBech32';
data: {
address: Address;
bech32Hrp?: string;
};
}

export interface __AccountIdToBech32Method__ {
name: 'accountIdToBech32';
data: {
Expand Down
2 changes: 2 additions & 0 deletions bindings/nodejs/lib/types/client/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
__GetUtxoChangesByIndexMethod__,
__GetUtxoChangesFullByIndexMethod__,
__HexToBech32Method__,
__AddressToBech32Method__,
__AccountIdToBech32Method__,
__AnchorIdToBech32Method__,
__NftIdToBech32Method__,
Expand Down Expand Up @@ -105,6 +106,7 @@ export type __ClientMethods__ =
| __GetUtxoChangesByIndexMethod__
| __GetUtxoChangesFullByIndexMethod__
| __HexToBech32Method__
| __AddressToBech32Method__
| __AccountIdToBech32Method__
| __AnchorIdToBech32Method__
| __NftIdToBech32Method__
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;
}
2 changes: 2 additions & 0 deletions bindings/nodejs/lib/types/utils/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
__TransactionIdMethod__,
__Bech32ToHexMethod__,
__HexToBech32Method__,
__AddressToBech32Method__,
__AccountIdToBech32Method__,
__AnchorIdToBech32Method__,
__NftIdToBech32Method__,
Expand Down Expand Up @@ -50,6 +51,7 @@ export type __UtilsMethods__ =
| __TransactionIdMethod__
| __Bech32ToHexMethod__
| __HexToBech32Method__
| __AddressToBech32Method__
| __AccountIdToBech32Method__
| __AnchorIdToBech32Method__
| __NftIdToBech32Method__
Expand Down
17 changes: 13 additions & 4 deletions bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
NftId,
Bech32Address,
Unlock,
Address,
} from '../../';
import { AccountId, AnchorId } from '../../block/id';
import { SlotCommitment } from '../../block/slot';
Expand Down Expand Up @@ -111,15 +112,23 @@ export interface __HexToBech32Method__ {
name: 'hexToBech32';
data: {
hex: HexEncodedString;
bech32Hrp?: string;
bech32Hrp: string;
};
}

export interface __AddressToBech32Method__ {
name: 'addressToBech32';
data: {
address: Address;
bech32Hrp: string;
};
}

export interface __AccountIdToBech32Method__ {
name: 'accountIdToBech32';
data: {
accountId: AccountId;
bech32Hrp?: string;
bech32Hrp: string;
};
}

Expand All @@ -135,15 +144,15 @@ export interface __NftIdToBech32Method__ {
name: 'nftIdToBech32';
data: {
nftId: NftId;
bech32Hrp?: string;
bech32Hrp: string;
};
}

export interface __HexPublicKeyToBech32AddressMethod__ {
name: 'hexPublicKeyToBech32Address';
data: {
hex: HexEncodedString;
bech32Hrp?: string;
bech32Hrp: string;
};
}

Expand Down
10 changes: 0 additions & 10 deletions bindings/nodejs/lib/types/wallet/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ import { SlotIndex } from '../block/slot';
import { Bech32Address, NftId, TokenId } from '../block';
import { NumericString, u256, u64 } from '../utils';

/** A Bip44 address */
export interface Bip44Address {
/** The Bech32 address. */
address: Bech32Address;
/** The address key index. */
keyIndex: number;
/** Whether the address is a public or an internal (change) address. */
internal: boolean;
}

/** Address with a base token amount */
export interface SendParams {
/** The Bech32 address to send the amount to. */
Expand Down
17 changes: 17 additions & 0 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ export class Utils {
});
}

/**
* Converts an address to its bech32 representation.
*
* @param address An address.
* @param bech32Hrp The Bech32 HRP (human readable part) to use.
* @returns The Bech32-encoded address string.
*/
static addressToBech32(address: Address, bech32Hrp: string): Bech32Address {
return callUtilsMethod({
name: 'addressToBech32',
data: {
address,
bech32Hrp,
},
});
}

/**
* Transforms an account id to a bech32 encoded address.
*
Expand Down
Loading

0 comments on commit fdd19a1

Please sign in to comment.