Skip to content

Commit

Permalink
Merge branch '2.0' into some-docs-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Sep 15, 2023
2 parents 7c5471d + 37d92b9 commit 1f44204
Show file tree
Hide file tree
Showing 82 changed files with 1,976 additions and 2,132 deletions.
6 changes: 3 additions & 3 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iota_sdk::{
NativeToken, NftId, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, transaction::TransactionId},
BlockDto, BlockId,
BlockId, BlockWrapperDto,
},
utils::serde::{option_string, string},
};
Expand Down Expand Up @@ -151,7 +151,7 @@ pub enum ClientMethod {
/// Post block (JSON)
PostBlock {
/// Block
block: BlockDto,
block: BlockWrapperDto,
},
/// Post block (raw)
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -327,6 +327,6 @@ pub enum ClientMethod {
/// Returns a block ID from a block
BlockId {
/// Block
block: BlockDto,
block: BlockWrapperDto,
},
}
4 changes: 2 additions & 2 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iota_sdk::types::block::{
protocol::ProtocolParameters,
signature::Ed25519Signature,
slot::SlotCommitment,
BlockDto,
BlockWrapperDto,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -83,7 +83,7 @@ pub enum UtilsMethod {
#[serde(rename_all = "camelCase")]
BlockId {
/// Block
block: BlockDto,
block: BlockWrapperDto,
/// Network Protocol Parameters
protocol_parameters: ProtocolParameters,
},
Expand Down
25 changes: 15 additions & 10 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iota_sdk::{
dto::OutputDto, AccountOutput, BasicOutput, FoundryOutput, NftOutput, Output, OutputBuilderAmount, Rent,
},
payload::Payload,
Block, BlockDto,
BlockWrapper, BlockWrapperDto,
},
TryFromDto,
},
Expand Down Expand Up @@ -187,7 +187,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM

let block_id = block.id();

Response::BlockIdWithBlock(block_id, BlockDto::from(&block))
Response::BlockIdWithBlock(block_id, BlockWrapperDto::from(&block))
}
#[cfg(not(target_family = "wasm"))]
ClientMethod::UnhealthyNodes => Response::UnhealthyNodes(client.unhealthy_nodes().await.into_iter().collect()),
Expand All @@ -198,18 +198,23 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetIssuance => Response::Issuance(client.get_issuance().await?),
ClientMethod::PostBlockRaw { block_bytes } => Response::BlockId(
client
.post_block_raw(&Block::unpack_strict(
.post_block_raw(&BlockWrapper::unpack_strict(
&block_bytes[..],
&client.get_protocol_parameters().await?,
)?)
.await?,
),
ClientMethod::PostBlock { block } => Response::BlockId(
client
.post_block(&Block::try_from_dto(block, client.get_protocol_parameters().await?)?)
.post_block(&BlockWrapper::try_from_dto(
block,
client.get_protocol_parameters().await?,
)?)
.await?,
),
ClientMethod::GetBlock { block_id } => Response::Block(BlockDto::from(&client.get_block(&block_id).await?)),
ClientMethod::GetBlock { block_id } => {
Response::Block(BlockWrapperDto::from(&client.get_block(&block_id).await?))
}
ClientMethod::GetBlockMetadata { block_id } => {
Response::BlockMetadata(client.get_block_metadata(&block_id).await?)
}
Expand All @@ -223,9 +228,9 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetOutputMetadata { output_id } => {
Response::OutputMetadata(client.get_output_metadata(&output_id).await?)
}
ClientMethod::GetIncludedBlock { transaction_id } => {
Response::Block(BlockDto::from(&client.get_included_block(&transaction_id).await?))
}
ClientMethod::GetIncludedBlock { transaction_id } => Response::Block(BlockWrapperDto::from(
&client.get_included_block(&transaction_id).await?,
)),
ClientMethod::GetIncludedBlockMetadata { transaction_id } => {
Response::BlockMetadata(client.get_included_block_metadata(&transaction_id).await?)
}
Expand Down Expand Up @@ -267,7 +272,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.find_blocks(&block_ids)
.await?
.iter()
.map(BlockDto::from)
.map(BlockWrapperDto::from)
.collect(),
),
ClientMethod::FindInputs { addresses, amount } => {
Expand Down Expand Up @@ -309,7 +314,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
Response::CustomJson(data)
}
ClientMethod::BlockId { block } => {
Response::BlockId(Block::try_from_dto(block, client.get_protocol_parameters().await?)?.id())
Response::BlockId(BlockWrapper::try_from_dto(block, client.get_protocol_parameters().await?)?.id())
}
};
Ok(response)
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use iota_sdk::{
input::UtxoInput,
output::{AccountId, FoundryId, InputsCommitment, NftId, Output, OutputId, Rent, TokenId},
payload::{transaction::TransactionEssence, TransactionPayload},
Block,
BlockWrapper,
},
TryFromDto,
},
Expand Down Expand Up @@ -41,7 +41,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
block,
protocol_parameters,
} => {
let block = Block::try_from_dto(block, protocol_parameters)?;
let block = BlockWrapper::try_from_dto(block, protocol_parameters)?;
Response::BlockId(block.id())
}
UtilsMethod::TransactionId { payload } => {
Expand Down
8 changes: 4 additions & 4 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use iota_sdk::{
signature::Ed25519Signature,
slot::SlotCommitmentId,
unlock::Unlock,
BlockDto, BlockId,
BlockId, BlockWrapperDto,
},
},
wallet::account::{
Expand Down Expand Up @@ -107,10 +107,10 @@ pub enum Response {
/// Response for:
/// - [`GetBlock`](crate::method::ClientMethod::GetBlock)
/// - [`GetIncludedBlock`](crate::method::ClientMethod::GetIncludedBlock)
Block(BlockDto),
Block(BlockWrapperDto),
/// Response for:
/// - [`PostBlockPayload`](crate::method::ClientMethod::PostBlockPayload)
BlockIdWithBlock(BlockId, BlockDto),
BlockIdWithBlock(BlockId, BlockWrapperDto),
/// Response for:
/// - [`GetBlockMetadata`](crate::method::ClientMethod::GetBlockMetadata)
BlockMetadata(BlockMetadataResponse),
Expand Down Expand Up @@ -140,7 +140,7 @@ pub enum Response {
OutputIdsResponse(OutputIdsResponse),
/// Response for:
/// - [`FindBlocks`](crate::method::ClientMethod::FindBlocks)
Blocks(Vec<BlockDto>),
Blocks(Vec<BlockWrapperDto>),
/// Response for:
/// - [`FindInputs`](crate::method::ClientMethod::FindInputs)
Inputs(Vec<UtxoInput>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function run() {

// New minted NFT id is empty in the output
if (
nftOutput.getNftId() ===
nftOutput.nftId ===
'0x0000000000000000000000000000000000000000000000000000000000000000'
) {
const outputId = Utils.computeOutputId(
Expand Down
7 changes: 4 additions & 3 deletions bindings/nodejs/examples/wallet/17-check-unlock-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ async function run() {
const basicOutput = output as BasicOutput;
let controlledByAccount = false;
if (
basicOutput.getUnlockConditions().length === 1 &&
basicOutput.getUnlockConditions()[0] instanceof
basicOutput.unlockConditions.length === 1 &&
basicOutput.unlockConditions[0] instanceof
AddressUnlockCondition &&
hexEncodedAccountAddresses.includes(
(
basicOutput.getUnlockConditions()[0] as AddressUnlockCondition
basicOutput
.unlockConditions[0] as AddressUnlockCondition
).address.toString(),
)
) {
Expand Down
6 changes: 2 additions & 4 deletions bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
Response,
OutputId,
ProtocolParameters,
u64,
} from '../types';
import { OutputResponse, IOutputsResponse } from '../types/models/api';

Expand Down Expand Up @@ -203,10 +204,7 @@ export class Client {
* @param amount The amount to find inputs for.
* @returns An array of UTXO inputs.
*/
async findInputs(
addresses: string[],
amount: bigint,
): Promise<UTXOInput[]> {
async findInputs(addresses: string[], amount: u64): Promise<UTXOInput[]> {
const response = await this.methodHandler.callMethod({
name: 'findInputs',
data: {
Expand Down
42 changes: 15 additions & 27 deletions bindings/nodejs/lib/types/block/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ enum AddressType {
* The base class for addresses.
*/
abstract class Address {
/**
* The type of address.
*/
readonly type: AddressType;

/**
Expand All @@ -29,12 +32,6 @@ abstract class Address {
constructor(type: AddressType) {
this.type = type;
}
/**
* Get the type of address.
*/
getType(): AddressType {
return this.type;
}

abstract toString(): string;

Expand Down Expand Up @@ -62,6 +59,9 @@ abstract class Address {
* An Ed25519 Address.
*/
class Ed25519Address extends Address {
/**
* The public key hash.
*/
readonly pubKeyHash: HexEncodedString;

/**
Expand All @@ -71,22 +71,19 @@ class Ed25519Address extends Address {
super(AddressType.Ed25519);
this.pubKeyHash = address;
}
/**
* Get the public key hash.
*/
getPubKeyHash(): HexEncodedString {
return this.pubKeyHash;
}

toString(): string {
return this.getPubKeyHash();
return this.pubKeyHash;
}
}

/**
* An Account address.
*/
class AccountAddress extends Address {
/**
* The account ID.
*/
readonly accountId: AccountId;
/**
* @param address An account address as account ID.
Expand All @@ -95,21 +92,18 @@ class AccountAddress extends Address {
super(AddressType.Account);
this.accountId = address;
}
/**
* Get the account ID.
*/
getAccountId(): AccountId {
return this.accountId;
}

toString(): string {
return this.getAccountId();
return this.accountId;
}
}
/**
* An NFT address.
*/
class NftAddress extends Address {
/**
* The NFT ID.
*/
readonly nftId: NftId;
/**
* @param address An NFT address as NFT ID.
Expand All @@ -118,15 +112,9 @@ class NftAddress extends Address {
super(AddressType.Nft);
this.nftId = address;
}
/**
* Get the NFT ID.
*/
getNftId(): NftId {
return this.nftId;
}

toString(): string {
return this.getNftId();
return this.nftId;
}
}

Expand Down
8 changes: 4 additions & 4 deletions bindings/nodejs/lib/types/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ export class Block {
/**
* The protocol version under which this block operates.
*/
protocolVersion!: number;
readonly protocolVersion!: number;
/**
* The parent block ids.
*/
parents!: HexEncodedString[];
readonly parents!: HexEncodedString[];
/**
* The payload contents.
*/
@Type(() => Payload, {
discriminator: PayloadDiscriminator,
})
payload?: Payload;
readonly payload?: Payload;
/**
* The amount of mana the Account identified by IssuerID is at most
* willing to burn for this block.
*/
burnedMana!: string;
readonly burnedMana!: string;
}
11 changes: 2 additions & 9 deletions bindings/nodejs/lib/types/block/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ abstract class Input {
constructor(type: InputType) {
this.type = type;
}

/**
* Get the type of input.
*/
getType(): InputType {
return this.type;
}
}

/**
Expand All @@ -40,11 +33,11 @@ class UTXOInput extends Input {
/**
* The transaction ID.
*/
transactionId: HexEncodedString;
readonly transactionId: HexEncodedString;
/**
* The output index.
*/
transactionOutputIndex: number;
readonly transactionOutputIndex: number;

/**
* @param transactionId The ID of the transaction it is an input of.
Expand Down
Loading

0 comments on commit 1f44204

Please sign in to comment.