Skip to content

Commit

Permalink
Merge branch '2.0' into feat/mana-semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jan 10, 2024
2 parents d1f8f35 + a54b4f8 commit 93ff09b
Show file tree
Hide file tree
Showing 55 changed files with 1,084 additions and 1,000 deletions.
17 changes: 10 additions & 7 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ pub enum ClientMethod {
/// The Account ID of the account.
account_id: AccountId,
},
/// Returns the totally available Mana rewards of an account or delegation output decayed up to endEpoch index
/// provided in the response.
/// Returns all the available Mana rewards of an account or delegation output in the returned range of epochs.
#[serde(rename_all = "camelCase")]
GetRewards {
/// Output ID of an account or delegation output.
output_id: OutputId,
/// A client can specify a slot index explicitly, which should be equal to the slot it uses as the commitment
/// input for the claiming transaction. This parameter is only recommended to be provided when requesting
/// rewards for a Delegation Output in delegating state (i.e. when Delegation ID is zeroed).
/// input for the claiming transaction to ensure the node calculates the rewards identically as during
/// transaction execution. Rewards are decayed up to the epoch corresponding to the given slotIndex +
/// MinCommittableAge. For a Delegation Output in delegating state (i.e. when Delegation ID is zeroed), that
/// epoch - 1 is also used as the last epoch for which rewards are fetched. Callers that do not build
/// transactions with the returned values may omit this value in which case it defaults to the latest committed
/// slot, which is good enough to, e.g. display estimated rewards to users.
slot_index: Option<SlotIndex>,
},
/// Returns information of all registered validators and if they are active, ordered by their holding stake.
Expand Down Expand Up @@ -282,17 +285,17 @@ pub enum ClientMethod {
/// Look up a commitment by a given commitment index.
GetCommitmentByIndex {
/// Index of the commitment to look up.
index: SlotIndex,
slot: SlotIndex,
},
/// Get all UTXO changes of a given slot by commitment index.
GetUtxoChangesByIndex {
/// Index of the commitment to look up.
index: SlotIndex,
slot: SlotIndex,
},
/// Get all full UTXO changes of a given slot by commitment index.
GetUtxoChangesFullByIndex {
/// Index of the commitment to look up.
index: SlotIndex,
slot: SlotIndex,
},

//////////////////////////////////////////////////////////////////////
Expand Down
126 changes: 68 additions & 58 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iota_sdk::{
api::core::OutputWithMetadataResponse,
block::{
output::{
AccountOutput, BasicOutput, FoundryOutput, MinimumOutputAmount, NftOutput, Output, OutputBuilderAmount,
AccountOutputBuilder, BasicOutputBuilder, FoundryOutputBuilder, MinimumOutputAmount, NftOutputBuilder,
},
payload::Payload,
Block, BlockDto, UnsignedBlockDto,
Expand Down Expand Up @@ -64,40 +64,43 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
immutable_features,
} => {
let output = Output::from(AccountOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
&account_id,
foundry_counter,
unlock_conditions,
features,
immutable_features,
)?);
let mut output_builder = if let Some(amount) = amount {
AccountOutputBuilder::new_with_amount(amount, account_id)
} else {
AccountOutputBuilder::new_with_minimum_amount(client.get_storage_score_parameters().await?, account_id)
}
.with_mana(mana)
.with_foundry_counter(foundry_counter)
.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
output_builder = output_builder.with_features(features);
}
if let Some(immutable_features) = immutable_features {
output_builder = output_builder.with_immutable_features(immutable_features)
}

Response::Output(output)
Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildBasicOutput {
amount,
mana,
unlock_conditions,
features,
} => {
let output = Output::from(BasicOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
unlock_conditions,
features,
)?);
let mut output_builder = if let Some(amount) = amount {
BasicOutputBuilder::new_with_amount(amount)
} else {
BasicOutputBuilder::new_with_minimum_amount(client.get_storage_score_parameters().await?)
}
.with_mana(mana)
.with_unlock_conditions(unlock_conditions);

Response::Output(output)
if let Some(features) = features {
output_builder = output_builder.with_features(features);
}

Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildFoundryOutput {
amount,
Expand All @@ -107,20 +110,25 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
immutable_features,
} => {
let output = Output::from(FoundryOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
serial_number,
token_scheme,
unlock_conditions,
features,
immutable_features,
)?);
let mut output_builder = if let Some(amount) = amount {
FoundryOutputBuilder::new_with_amount(amount, serial_number, token_scheme)
} else {
FoundryOutputBuilder::new_with_minimum_amount(
client.get_storage_score_parameters().await?,
serial_number,
token_scheme,
)
}
.with_unlock_conditions(unlock_conditions);

Response::Output(output)
if let Some(features) = features {
output_builder = output_builder.with_features(features);
}
if let Some(immutable_features) = immutable_features {
output_builder = output_builder.with_immutable_features(immutable_features)
}

Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildNftOutput {
amount,
Expand All @@ -130,20 +138,22 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
immutable_features,
} => {
let output = Output::from(NftOutput::try_from_dtos(
if let Some(amount) = amount {
OutputBuilderAmount::Amount(amount)
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
&nft_id,
unlock_conditions,
features,
immutable_features,
)?);
let mut output_builder = if let Some(amount) = amount {
NftOutputBuilder::new_with_amount(amount, nft_id)
} else {
NftOutputBuilder::new_with_minimum_amount(client.get_storage_score_parameters().await?, nft_id)
}
.with_mana(mana)
.with_unlock_conditions(unlock_conditions);

if let Some(features) = features {
output_builder = output_builder.with_features(features);
}
if let Some(immutable_features) = immutable_features {
output_builder = output_builder.with_immutable_features(immutable_features)
}

Response::Output(output)
Response::Output(output_builder.finish_output()?)
}
ClientMethod::BuildBasicBlock { issuer_id, payload } => {
let payload = if let Some(payload) = payload {
Expand Down Expand Up @@ -241,14 +251,14 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.get_utxo_changes_full_by_slot_commitment_id(&commitment_id)
.await?,
),
ClientMethod::GetCommitmentByIndex { index } => {
Response::SlotCommitment(client.get_slot_commitment_by_slot(index).await?)
ClientMethod::GetCommitmentByIndex { slot } => {
Response::SlotCommitment(client.get_slot_commitment_by_slot(slot).await?)
}
ClientMethod::GetUtxoChangesByIndex { index } => {
Response::UtxoChanges(client.get_utxo_changes_by_slot(index).await?)
ClientMethod::GetUtxoChangesByIndex { slot } => {
Response::UtxoChanges(client.get_utxo_changes_by_slot(slot).await?)
}
ClientMethod::GetUtxoChangesFullByIndex { index } => {
Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(index).await?)
ClientMethod::GetUtxoChangesFullByIndex { slot } => {
Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(slot).await?)
}
ClientMethod::OutputIds { query_parameters } => {
Response::OutputIdsResponse(client.output_ids(query_parameters).await?)
Expand Down
11 changes: 5 additions & 6 deletions bindings/nodejs/examples/exchange/4-listen-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// Run with command:
// yarn run-example ./exchange/4-listen-events.ts

import { Wallet, Event, WalletEventType } from '@iota/sdk';
import { Wallet, WalletEvent, WalletEventType } from '@iota/sdk';

// This example uses secrets in environment variables for simplicity which should not be done in production.
require('dotenv').config({ path: '.env' });

async function run() {
try {
for (const envVar of ['WALLET_DB_PATH']) {
for (const envVar of ['WALLET_DB_PATH', 'FAUCET_URL']) {
if (!(envVar in process.env)) {
throw new Error(
`.env ${envVar} is undefined, see .env.example`,
Expand All @@ -24,9 +24,8 @@ async function run() {
storagePath: process.env.WALLET_DB_PATH,
});

const callback = function (err: any, event: Event) {
console.log('AccountIndex:', event.accountIndex);
console.log('Event:', event.event);
const callback = function (err: any, event: WalletEvent) {
console.log('Event:', event);

// Exit after receiving an event.
process.exit(0);
Expand All @@ -37,7 +36,7 @@ async function run() {

// Use the faucet to send testnet tokens to your address.
console.log(
'Fill your address with the faucet: https://faucet.testnet.shimmer.network/',
`Fill your address with the faucet: ${process.env.FAUCET_URL}`,
);

const address = await wallet.address();
Expand Down
6 changes: 2 additions & 4 deletions bindings/nodejs/examples/wallet/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import {
Event,
ConsolidationRequiredWalletEvent,
WalletEvent,
TransactionProgressWalletEvent,
SelectingInputsProgress,
} from '@iota/sdk';
Expand All @@ -24,13 +23,12 @@ async function run() {
// Create the wallet
const wallet = await getUnlockedWallet();

const callback = function (err: any, event: Event) {
const callback = function (err: any, event: WalletEvent) {
console.log('Event:', event);
};

await wallet.listen([], callback);

await wallet.emitTestEvent(new ConsolidationRequiredWalletEvent());
await wallet.emitTestEvent(
new TransactionProgressWalletEvent(new SelectingInputsProgress()),
);
Expand Down
Loading

0 comments on commit 93ff09b

Please sign in to comment.