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 19, 2024
2 parents 10366c0 + 257bcff commit 0f95ec1
Show file tree
Hide file tree
Showing 125 changed files with 3,703 additions and 2,458 deletions.
3 changes: 1 addition & 2 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
&wallet.client().get_protocol_parameters().await?,
)?,
None,
None,
)
.await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
Expand All @@ -438,7 +437,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
&wallet.client().get_protocol_parameters().await?,
)?;
let transaction = wallet
.submit_and_store_transaction(signed_transaction_data, None, None)
.submit_and_store_transaction(signed_transaction_data, None)
.await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
Expand Down
6 changes: 2 additions & 4 deletions bindings/nodejs/examples/client/04-get-output.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Client, initLogger, OutputId } from '@iota/sdk';
import { Client, initLogger } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// Run with command:
Expand All @@ -22,9 +22,7 @@ async function run() {
});
try {
const output = await client.getOutput(
new OutputId(
'0x022aefa73dff09b35b21ab5493412b0d354ad07a970a12b71e8087c6f3a7b866000000000000',
),
'0x022aefa73dff09b35b21ab5493412b0d354ad07a970a12b71e8087c6f3a7b866000000000000',
);
console.log('Output: ', output);
} catch (error) {
Expand Down
12 changes: 2 additions & 10 deletions bindings/nodejs/examples/client/05-get-address-balance.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// Copyright 2021-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import {
Client,
CommonOutput,
SecretManager,
initLogger,
OutputId,
} from '@iota/sdk';
import { Client, CommonOutput, SecretManager, initLogger } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// Run with command:
Expand Down Expand Up @@ -51,9 +45,7 @@ async function run() {
});

// Get outputs by their IDs
const addressOutputs = await client.getOutputs(
outputIdsResponse.items.map((id) => new OutputId(id)),
);
const addressOutputs = await client.getOutputs(outputIdsResponse.items);

// Calculate the total amount and native tokens
let totalAmount = BigInt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function run() {
},
];
const options = {
mandatoryInputs: [input],
requiredInputs: [input],
allowMicroAmount: false,
};
const transaction = await wallet.sendWithParams(params, options);
Expand Down
6 changes: 2 additions & 4 deletions bindings/nodejs/examples/how_tos/client/get-outputs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Client, initLogger, OutputId } from '@iota/sdk';
import { Client, initLogger } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// Run with command:
Expand Down Expand Up @@ -33,9 +33,7 @@ async function run() {
console.log('First output of query:');
console.log('ID: ', outputIdsResponse.items[0]);

const outputs = await client.getOutputs(
outputIdsResponse.items.map((id) => new OutputId(id)),
);
const outputs = await client.getOutputs(outputIdsResponse.items);
console.log(outputs[0]);
} catch (error) {
console.error('Error: ', error);
Expand Down
26 changes: 2 additions & 24 deletions bindings/nodejs/lib/types/block/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import { HexEncodedString } from '../utils';
import { SlotIndex } from './slot';

/**
* Base class for IDs with a hex encoded slot index at the end.
*/
export class IdWithSlotIndex extends String {
slotIndex(): SlotIndex {
const numberString = super.slice(-8);
const chunks = [];
for (
let i = 0, charsLength = numberString.length;
i < charsLength;
i += 2
) {
chunks.push(numberString.substring(i, i + 2));
}
const separated = chunks.map((n) => parseInt(n, 16));
const buf = Uint8Array.from(separated).buffer;
const view = new DataView(buf);
return view.getUint32(0, true);
}
}

/**
* An Account ID represented as hex-encoded string.
Expand All @@ -43,7 +21,7 @@ export type NftId = HexEncodedString;
/**
* A Block ID represented as hex-encoded string.
*/
export class BlockId extends IdWithSlotIndex {}
export type BlockId = HexEncodedString;

/**
* A Token ID represented as hex-encoded string.
Expand All @@ -53,7 +31,7 @@ export type TokenId = HexEncodedString;
/**
* A Transaction ID represented as hex-encoded string.
*/
export class TransactionId extends IdWithSlotIndex {}
export type TransactionId = HexEncodedString;

/**
* A Foundry ID represented as hex-encoded string.
Expand Down
3 changes: 0 additions & 3 deletions bindings/nodejs/lib/types/block/input/input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Transform, Type } from 'class-transformer';
import { TransactionId } from '../id';
import { OutputId } from '../output';

Expand Down Expand Up @@ -34,8 +33,6 @@ class UTXOInput extends Input {
/**
* The transaction ID.
*/
@Type(() => TransactionId)
@Transform(({ value }) => new TransactionId(value), { toClassOnly: true })
readonly transactionId: TransactionId;
/**
* The output index.
Expand Down
25 changes: 3 additions & 22 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,13 @@ import { Feature, FeatureDiscriminator, NativeTokenFeature } from './feature';

// Temp solution for not double parsing JSON
import { plainToInstance, Type } from 'class-transformer';
import { NumericString, u64 } from '../../utils';
import { HexEncodedString, NumericString, u64 } from '../../utils';
import { TokenScheme, TokenSchemeDiscriminator } from './token-scheme';
import { AccountId, NftId, AnchorId, DelegationId, TransactionId } from '../id';
import { AccountId, NftId, AnchorId, DelegationId } from '../id';
import { EpochIndex } from '../../block/slot';
import { NativeToken } from '../../models/native-token';

export class OutputId extends String {
transactionId(): TransactionId {
return new TransactionId(this.slice(74));
}
outputIndex(): number {
const numberString = this.slice(-4);
const chunks = [];
for (
let i = 0, charsLength = numberString.length;
i < charsLength;
i += 2
) {
chunks.push(numberString.substring(i, i + 2));
}
const separated = chunks.map((n) => parseInt(n, 16));
const buf = Uint8Array.from(separated).buffer;
const view = new DataView(buf);
return view.getUint16(0, true);
}
}
export type OutputId = HexEncodedString;

/**
* All of the output types.
Expand Down
5 changes: 2 additions & 3 deletions bindings/nodejs/lib/types/block/slot/commitment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { u64 } from '../..';
import { IdWithSlotIndex } from '../id';
import { HexEncodedString, u64 } from '../..';

/**
* Timeline is divided into slots, and each slot has a corresponding slot index.
Expand All @@ -22,7 +21,7 @@ type EpochIndex = number;
/**
* Identifier of a slot commitment
*/
class SlotCommitmentId extends IdWithSlotIndex {}
type SlotCommitmentId = HexEncodedString;

/**
* A BLAKE2b-256 hash of concatenating multiple sparse merkle tree roots of a slot.
Expand Down
6 changes: 2 additions & 4 deletions bindings/nodejs/lib/types/client/client-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import type { IMqttBrokerOptions, INetworkInfo, INode } from './network';

/** Options for the client builder */
export interface IClientOptions {
/** Node which will be tried first for all requests */
primaryNode?: string | INode;
/** Nodes which will be tried first for all requests */
primaryNodes?: Array<string | INode>;
/** A list of nodes. */
nodes?: Array<string | INode>;
/** A list of permanodes. */
permanodes?: Array<string | INode>;
/** If the node health status should be ignored */
ignoreNodeHealth?: boolean;
/** Interval in which nodes will be checked for their sync status and the NetworkInfo gets updated */
Expand Down
2 changes: 2 additions & 0 deletions bindings/nodejs/lib/types/client/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface INode {
auth?: IAuth;
/** Whether the node is disabled or not. */
disabled?: boolean;
/** Whether the node is a permanode or not. */
permanode?: boolean;
}

/**
Expand Down
29 changes: 12 additions & 17 deletions bindings/nodejs/lib/types/models/block-failure-reason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ export enum BlockFailureReason {
ParentTooOld = 2,
/** One of the block's parents does not exist. */
ParentDoesNotExist = 3,
/** One of the block's parents is invalid. */
ParentInvalid = 4,
/** The block's issuer account could not be found. */
IssuerAccountNotFound = 5,
/** The block's protocol version is invalid. */
VersionInvalid = 6,
IssuerAccountNotFound = 4,
/** The mana cost could not be calculated. */
ManaCostCalculationFailed = 7,
ManaCostCalculationFailed = 5,
/** The block's issuer account burned insufficient Mana for a block. */
BurnedInsufficientMana = 8,
/** The account is invalid. */
AccountInvalid = 9,
BurnedInsufficientMana = 6,
/** The account is locked. */
AccountLocked = 7,
/** The account is expired. */
AccountExpired = 8,
/** The block's signature is invalid. */
SignatureInvalid = 10,
SignatureInvalid = 9,
/** The block is dropped due to congestion. */
DroppedDueToCongestion = 11,
DroppedDueToCongestion = 10,
/** The block payload is invalid. */
PayloadInvalid = 12,
PayloadInvalid = 11,
/** The block is invalid. */
Invalid = 255,
}
Expand All @@ -43,17 +41,14 @@ export const BLOCK_FAILURE_REASON_STRINGS: {
[BlockFailureReason.ParentTooOld]: "One of the block's parents is too old.",
[BlockFailureReason.ParentDoesNotExist]:
"One of the block's parents does not exist.",
[BlockFailureReason.ParentInvalid]:
"One of the block's parents is invalid.",
[BlockFailureReason.IssuerAccountNotFound]:
"The block's issuer account could not be found.",
[BlockFailureReason.VersionInvalid]:
"The block's protocol version is invalid.",
[BlockFailureReason.ManaCostCalculationFailed]:
'The mana cost could not be calculated.',
[BlockFailureReason.BurnedInsufficientMana]:
"The block's issuer account burned insufficient Mana for a block.",
[BlockFailureReason.AccountInvalid]: 'The account is invalid.',
[BlockFailureReason.AccountLocked]: 'The account is locked.',
[BlockFailureReason.AccountExpired]: 'The account is expired.',
[BlockFailureReason.SignatureInvalid]: "The block's signature is invalid.",
[BlockFailureReason.DroppedDueToCongestion]:
'The block is dropped due to congestion.',
Expand Down
10 changes: 5 additions & 5 deletions bindings/nodejs/lib/types/models/info/node-info-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ interface RewardsParameters {
*/
bootstrappingDuration: number;
/**
* Mana Share Coefficient is the coefficient used for calculation of initial rewards.
* The rate of Mana rewards at the start of the bootstrapping phase.
*/
manaShareCoefficient: u64;
rewardToGenerationRatio: number;
/**
* Decay Balancing Constant Exponent is the exponent used for calculation of the initial reward.
*/
decayBalancingConstantExponent: number;
initialTargetRewardsRate: u64;
/**
* Decay Balancing Constant is an integer approximation calculated based on chosen Decay Balancing Constant Exponent.
* The rate of Mana rewards after the bootstrapping phase.
*/
decayBalancingConstant: u64;
finalTargetRewardsRate: u64;
/**
* Pool Coefficient Exponent is the exponent used for shifting operation
* in the pool rewards calculations.
Expand Down
Loading

0 comments on commit 0f95ec1

Please sign in to comment.