Skip to content

Commit

Permalink
Merge branch '2.0' into account-anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Oct 18, 2023
2 parents 9a7af78 + 2b83eb9 commit 693e763
Show file tree
Hide file tree
Showing 228 changed files with 3,419 additions and 1,794 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/bindings-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ jobs:
working-directory: bindings/python
run: tox -e lint-examples

# TODO temporarily disabled https://github.com/iotaledger/iota-sdk/issues/647
# - name: Run tests
# working-directory: bindings/python
# run: tox
- name: Run tests
working-directory: bindings/python
run: tox
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings/core/src/method_handler/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{method::AccountMethod, Response, Result};
pub(crate) async fn call_account_method_internal(account: &Account, method: AccountMethod) -> Result<Response> {
let response = match method {
AccountMethod::Addresses => {
let addresses = account.addresses().await?;
let addresses = account.addresses().await;
Response::Addresses(addresses)
}
AccountMethod::AddressesWithUnspentOutputs => {
Expand Down
7 changes: 4 additions & 3 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[cfg(feature = "mqtt")]
use iota_sdk::client::mqtt::{MqttPayload, Topic};
use iota_sdk::{
client::{request_funds_from_faucet, Client},
client::{request_funds_from_faucet, secret::SecretManager, Client},
types::{
api::core::response::OutputWithMetadataResponse,
block::{
Expand Down Expand Up @@ -169,15 +169,16 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetProtocolParameters => Response::ProtocolParameters(client.get_protocol_parameters().await?),
ClientMethod::PostBlockPayload { payload } => {
let block = client
.finish_basic_block_builder(
.build_basic_block::<SecretManager>(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
Some(Payload::try_from_dto_with_params(
payload,
&client.get_protocol_parameters().await?,
)?),
todo!("secret manager"),
todo!("chain"),
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
UtilsMethod::HexPublicKeyToBech32Address { hex, bech32_hrp } => {
Response::Bech32Address(hex_public_key_to_bech32_address(&hex, bech32_hrp)?)
}
UtilsMethod::ParseBech32Address { address } => Response::ParsedBech32Address(Address::from(address.inner())),
UtilsMethod::ParseBech32Address { address } => Response::ParsedBech32Address(address.into_inner()),
UtilsMethod::IsAddressValid { address } => Response::Bool(Address::is_valid_bech32(&address)),
UtilsMethod::GenerateMnemonic => Response::GeneratedMnemonic(Client::generate_mnemonic()?.to_string()),
UtilsMethod::MnemonicToHexSeed { mnemonic } => {
Expand Down
4 changes: 3 additions & 1 deletion bindings/core/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ async fn utils() -> Result<()> {

let bech32_address =
Bech32Address::try_from_str("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy")?;
let method = UtilsMethod::Bech32ToHex { bech32: bech32_address };
let method = UtilsMethod::Bech32ToHex {
bech32: bech32_address.clone(),
};

let response = call_utils_method(method);
match response {
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/11-build-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async function run() {
addressUnlockCondition,
new ExpirationUnlockCondition(
new Ed25519Address(hexAddress),
BigInt(1),
1,
),
],
});
Expand All @@ -91,7 +91,7 @@ async function run() {
amount: BigInt(1000000),
unlockConditions: [
addressUnlockCondition,
new TimelockUnlockCondition(BigInt(1)),
new TimelockUnlockCondition(1),
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function run() {

// Create an output with amount 1_000_000 and a timelock of 1 hour
// TODO Make the slot index properly 1h ahead
const slotIndex = BigInt(1000);
const slotIndex = 1000;
const basicOutput = await client.buildBasicOutput({
unlockConditions: [
new AddressUnlockCondition(
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/how_tos/outputs/unlock-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function run() {
const basicOutputWithTimelock = await client.buildBasicOutput({
unlockConditions: [
addressUnlockCondition,
new TimelockUnlockCondition(BigInt(1)),
new TimelockUnlockCondition(1),
],
});

Expand All @@ -74,7 +74,7 @@ async function run() {
addressUnlockCondition,
new ExpirationUnlockCondition(
new Ed25519Address(hexAddress),
BigInt(1),
1,
),
],
});
Expand Down
9 changes: 5 additions & 4 deletions bindings/nodejs/lib/types/block/output/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
BlockIssuerKeyDiscriminator,
} from './block-issuer-key';
import { u64 } from '../../utils/type-aliases';
import { EpochIndex } from '../../block/slot';

/**
* All of the feature block types.
Expand Down Expand Up @@ -144,17 +145,17 @@ class StakingFeature extends Feature {
/**
* The epoch index in which the staking started.
*/
readonly startEpoch: u64;
readonly startEpoch: EpochIndex;
/**
* The epoch index in which the staking ends.
*/
readonly endEpoch: u64;
readonly endEpoch: EpochIndex;

constructor(
stakedAmount: u64,
fixedCost: u64,
startEpoch: u64,
endEpoch: u64,
startEpoch: EpochIndex,
endEpoch: EpochIndex,
) {
super(FeatureType.Staking);
this.stakedAmount = stakedAmount;
Expand Down
9 changes: 5 additions & 4 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { HexEncodedString, hexToBigInt, u64 } from '../../utils';
import { TokenScheme, TokenSchemeDiscriminator } from './token-scheme';
import { INativeToken } from '../../models';
import { AccountId, DelegationId } from '../id';
import { EpochIndex } from '../../block/slot';

export type OutputId = string;

Expand Down Expand Up @@ -300,11 +301,11 @@ class DelegationOutput extends Output {
/**
* The index of the first epoch for which this output delegates.
*/
readonly startEpoch: u64;
readonly startEpoch: EpochIndex;
/**
* The index of the last epoch for which this output delegates.
*/
readonly endEpoch: u64;
readonly endEpoch: EpochIndex;
/**
* The unlock conditions for the output.
*/
Expand All @@ -327,8 +328,8 @@ class DelegationOutput extends Output {
delegatedAmount: u64,
delegationId: DelegationId,
validatorId: AccountId,
startEpoch: u64,
endEpoch: u64,
startEpoch: EpochIndex,
endEpoch: EpochIndex,
unlockConditions: UnlockCondition[],
) {
super(OutputType.Delegation, amount);
Expand Down
7 changes: 3 additions & 4 deletions bindings/nodejs/lib/types/block/output/unlock-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class TimelockUnlockCondition extends UnlockCondition {
}

/**
* Defines an expiration slot index. Before the slot index is reached, only the Address defined in the Address
* Unlock Condition is allowed to unlock the output. Afterward, only the Return Address can unlock it.
* Defines a slot index until which only the Address defined in the Address Unlock Condition is allowed to unlock the output.
* After the slot index is reached/passed, only the Return Address can unlock it.
*/
class ExpirationUnlockCondition extends UnlockCondition {
/**
Expand All @@ -168,8 +168,7 @@ class ExpirationUnlockCondition extends UnlockCondition {
})
readonly returnAddress: Address;
/**
* Before this slot index, the condition is allowed to unlock the output,
* after that only the address defined in return address.
* Before this slot index, the Address Unlock Condition is allowed to unlock the output, after that only the address defined in Return Address can.
*/
readonly slotIndex: SlotIndex;

Expand Down
12 changes: 10 additions & 2 deletions bindings/nodejs/lib/types/block/slot/commitment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import { u64 } from '../..';
* To calculate the slot index of a timestamp, `genesisTimestamp` and the duration of a slot are needed.
* The slot index of timestamp `ts` is `(ts - genesisTimestamp)/duration + 1`.
*/
type SlotIndex = u64;
type SlotIndex = number;

/**
* The tangle timeline is divided into epochs, and each epoch has a corresponding epoch index.
* Epochs are further subdivided into slots, each with a `SlotIndex.
* To calculate the epoch index of a timestamp, `slotsPerEpochExponent` and `slotDurationInSeconds` are needed.
* An epoch consists of `2^slotsPerEpochExponent` slots.
*/
type EpochIndex = number;

/**
* Identifier of a slot commitment
Expand Down Expand Up @@ -59,4 +67,4 @@ class SlotCommitment {
}
}

export { SlotCommitment, SlotIndex, SlotCommitmentId, RootsId };
export { SlotCommitment, SlotIndex, EpochIndex, SlotCommitmentId, RootsId };
59 changes: 48 additions & 11 deletions bindings/nodejs/lib/types/models/info/node-info-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { u64 } from '../../utils';
import type { RentStructure } from '../rent-structure';
import { EpochIndex } from '../../block/slot';

/**
* The Protocol Info.
Expand All @@ -11,7 +12,7 @@ export interface ProtocolInfo {
/**
* The start epoch of the set of protocol parameters.
*/
startEpoch: string;
startEpoch: EpochIndex;
/**
* The protocol parameters.
*/
Expand Down Expand Up @@ -69,31 +70,31 @@ export interface ProtocolParameters {
/**
* The unbonding period in epochs before an account can stop staking.
*/
stakingUnbondingPeriod: u64;
stakingUnbondingPeriod: number;
/**
* The number of validation blocks that each validator should issue each slot.
*/
validationBlocksPerSlot: number;
/**
* The number of epochs worth of Mana that a node is punished with for each additional validation block it issues.
*/
punishmentEpochs: u64;
punishmentEpochs: number;
/**
* Determine if a block is eligible by evaluating issuingTime and commitments in its pastcone to ATT and lastCommittedSlot respectively.
*/
livenessThreshold: u64;
livenessThreshold: number;
/**
* MinCommittableAge is the minimum age relative to the accepted tangle time slot index that a slot can be committed.
*/
minCommittableAge: u64;
minCommittableAge: number;
/**
* MaxCommittableAge is the maximum age for a slot commitment to be included in a block relative to the slot index of the block issuing time.
*/
maxCommittableAge: u64;
maxCommittableAge: number;
/**
* Determine the slot that should trigger a new committee selection for the next and upcoming epoch.
*/
epochNearingThreshold: u64;
epochNearingThreshold: number;
/**
* Congestion Control Parameters defines the parameters used to calculate the Reference Mana Cost (RMC).
*/
Expand All @@ -102,6 +103,46 @@ export interface ProtocolParameters {
* The parameters used by signaling protocol parameters upgrade.
*/
versionSignaling: VersionSignalingParameters;
/**
* Rewards Parameters defines the parameters that are used to calculate Mana rewards.
*/
rewardsParameters: RewardsParameters;
}

/**
* Rewards Parameters defines the parameters that are used to calculate Mana rewards.
*/
export interface RewardsParameters {
/**
* The number of validation blocks that should be issued by a selected validator
* per slot during its epoch duties.
*/
validationBlocksPerSlot: number;
/**
* Profit Margin Exponent is used for shift operation for calculation of profit margin.
*/
profitMarginExponent: number;
/**
* The length in epochs of the bootstrapping phase.
*/
bootstrappingDuration: number;
/**
* Mana Share Coefficient is the coefficient used for calculation of initial rewards.
*/
manaShareCoefficient: u64;
/**
* Decay Balancing Constant Exponent is the exponent used for calculation of the initial reward.
*/
decayBalancingConstantExponent: number;
/**
* Decay Balancing Constant is an integer approximation calculated based on chosen Decay Balancing Constant Exponent.
*/
decayBalancingConstant: u64;
/**
* Pool Coefficient Exponent is the exponent used for shifting operation
* in the pool rewards calculations.
*/
poolCoefficientExponent: number;
}

/**
Expand Down Expand Up @@ -220,10 +261,6 @@ export interface CongestionControlParameters {
* The rate at which the scheduler runs in workscore units per second.
*/
schedulerRate: number;
/**
* The minimum amount of Mana that an account must have to have a block scheduled.
*/
minMana: u64;
/**
* The maximum size of the buffer.
*/
Expand Down
10 changes: 6 additions & 4 deletions bindings/nodejs/lib/types/models/info/node-info-status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { SlotIndex, EpochIndex } from '../../block/slot';

/**
* Response from the /info endpoint.
*/
Expand Down Expand Up @@ -32,17 +34,17 @@ export interface INodeInfoStatus {
/**
* The index of latest finalized slot.
*/
latestFinalizedSlot: string;
latestFinalizedSlot: SlotIndex;
/**
* The slot index of the latest accepted block.
*/
latestAcceptedBlockSlot?: string;
latestAcceptedBlockSlot?: SlotIndex;
/**
* The slot index of the latest confirmed block.
*/
latestConfirmedBlockSlot?: string;
latestConfirmedBlockSlot?: SlotIndex;
/**
* The index of the epoch before which the tangle history is pruned.
*/
pruningEpoch: string;
pruningEpoch: EpochIndex;
}
2 changes: 1 addition & 1 deletion bindings/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 693e763

Please sign in to comment.