Skip to content

Commit

Permalink
Merge branch '2.0' into native-token-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Oct 24, 2023
2 parents 1c7e242 + debd49f commit 5411ddd
Show file tree
Hide file tree
Showing 159 changed files with 1,547 additions and 1,679 deletions.
4 changes: 2 additions & 2 deletions bindings/core/src/method/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use iota_sdk::{
types::block::{
address::Bech32Address,
output::{dto::OutputDto, OutputId, TokenId},
payload::transaction::TransactionId,
payload::signed_transaction::TransactionId,
},
wallet::{
account::{
Expand Down Expand Up @@ -306,7 +306,7 @@ pub enum AccountMethod {
/// Sign a prepared transaction.
/// Expected response: [`SignedTransactionData`](crate::Response::SignedTransactionData)
#[serde(rename_all = "camelCase")]
SignTransactionEssence {
SignTransaction {
prepared_transaction_data: PreparedTransactionDataDto,
},
/// Validate the transaction, submit it to a node and store it in the account.
Expand Down
2 changes: 1 addition & 1 deletion bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iota_sdk::{
dto::OutputDto, feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, FoundryId,
NativeToken, NftId, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, transaction::TransactionId},
payload::{dto::PayloadDto, signed_transaction::TransactionId},
BlockId, BlockWrapperDto,
},
utils::serde::{option_string, string},
Expand Down
12 changes: 6 additions & 6 deletions bindings/core/src/method/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ pub enum SecretManagerMethod {
/// Create a single Signature Unlock.
#[serde(rename_all = "camelCase")]
SignatureUnlock {
/// Transaction Essence Hash
transaction_essence_hash: String,
/// Chain to sign the essence hash with
/// Transaction Hash
transaction_hash: String,
/// Chain to sign the hash with
#[serde(with = "Bip44Def")]
chain: Bip44,
},
/// Signs a message with an Ed25519 private key.
SignEd25519 {
/// The message to sign, hex encoded String
message: String,
/// Chain to sign the essence hash with
/// Chain to sign the message with
#[serde(with = "Bip44Def")]
chain: Bip44,
},
Expand Down Expand Up @@ -78,7 +78,7 @@ mod test {
#[test]
fn bip44_deserialization() {
let signature_unlock_method: super::SecretManagerMethod = serde_json::from_str(
r#"{"name": "signatureUnlock", "data": {"transactionEssenceHash": "txhash", "chain": {"addressIndex": 1}}}"#,
r#"{"name": "signatureUnlock", "data": {"transactionHash": "txhash", "chain": {"addressIndex": 1}}}"#,
)
.unwrap();

Expand All @@ -87,7 +87,7 @@ mod test {
serde_json::json!({
"name": "signatureUnlock",
"data": {
"transactionEssenceHash": "txhash",
"transactionHash": "txhash",
"chain": {
"coinType": 4218,
"account": 0,
Expand Down
16 changes: 7 additions & 9 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use derivative::Derivative;
use iota_sdk::types::block::{
address::{Bech32Address, Hrp},
output::{dto::OutputDto, AccountId, NftId, OutputId, RentStructure},
payload::transaction::{
dto::{TransactionEssenceDto, TransactionPayloadDto},
payload::signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
TransactionId,
},
protocol::ProtocolParameters,
Expand Down Expand Up @@ -90,7 +90,7 @@ pub enum UtilsMethod {
/// Returns the transaction ID (Blake2b256 hash of the provided transaction payload)
TransactionId {
/// Transaction Payload
payload: TransactionPayloadDto,
payload: SignedTransactionPayloadDto,
},
/// Computes the account ID
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -123,13 +123,11 @@ pub enum UtilsMethod {
serial_number: u32,
token_scheme_type: u8,
},
/// Computes the hash of a transaction essence.
HashTransactionEssence {
/// The transaction essence
essence: TransactionEssenceDto,
/// Computes the hash of a transaction.
HashTransaction {
/// The transaction.
transaction: TransactionDto,
},
/// Computes the input commitment from the output objects that are used as inputs to fund the transaction.
ComputeInputsCommitment { inputs: Vec<OutputDto> },
/// Computes the required storage deposit of an output.
ComputeStorageDeposit { output: OutputDto, rent: RentStructure },
/// Checks if the given mnemonic is valid.
Expand Down
30 changes: 16 additions & 14 deletions bindings/core/src/method_handler/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use iota_sdk::{
block::output::{dto::OutputDto, Output},
TryFromDto,
},
wallet::account::{types::TransactionDto, Account, OutputDataDto, PreparedCreateNativeTokenTransactionDto},
wallet::account::{
types::TransactionWithMetadataDto, Account, OutputDataDto, PreparedCreateNativeTokenTransactionDto,
},
};

use crate::{method::AccountMethod, Response, Result};
Expand All @@ -30,7 +32,7 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco
}
AccountMethod::ClaimOutputs { output_ids_to_claim } => {
let transaction = account.claim_outputs(output_ids_to_claim.to_vec()).await?;
Response::SentTransaction(TransactionDto::from(&transaction))
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
#[cfg(feature = "participation")]
AccountMethod::DeregisterParticipationEvent { event_id } => {
Expand All @@ -51,7 +53,7 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco

transaction.map_or_else(
|| Response::Transaction(None),
|transaction| Response::Transaction(Some(Box::new(TransactionDto::from(&transaction)))),
|transaction| Response::Transaction(Some(Box::new(TransactionWithMetadataDto::from(&transaction)))),
)
}
AccountMethod::GetOutput { output_id } => {
Expand Down Expand Up @@ -85,7 +87,7 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco
}
AccountMethod::GetTransaction { transaction_id } => {
let transaction = account.get_transaction(&transaction_id).await;
Response::Transaction(transaction.as_ref().map(TransactionDto::from).map(Box::new))
Response::Transaction(transaction.as_ref().map(TransactionWithMetadataDto::from).map(Box::new))
}
#[cfg(feature = "participation")]
AccountMethod::GetVotingPower => {
Expand All @@ -94,15 +96,15 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco
}
AccountMethod::IncomingTransactions => {
let transactions = account.incoming_transactions().await;
Response::Transactions(transactions.iter().map(TransactionDto::from).collect())
Response::Transactions(transactions.iter().map(TransactionWithMetadataDto::from).collect())
}
AccountMethod::Outputs { filter_options } => {
let outputs = account.outputs(filter_options).await?;
Response::OutputsData(outputs.iter().map(OutputDataDto::from).collect())
}
AccountMethod::PendingTransactions => {
let transactions = account.pending_transactions().await;
Response::Transactions(transactions.iter().map(TransactionDto::from).collect())
Response::Transactions(transactions.iter().map(TransactionWithMetadataDto::from).collect())
}
AccountMethod::PrepareBurn { burn, options } => {
let data = account.prepare_burn(burn, options).await?;
Expand Down Expand Up @@ -217,11 +219,11 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco
options,
} => {
let transaction = account.send(amount, address, options).await?;
Response::SentTransaction(TransactionDto::from(&transaction))
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
AccountMethod::SendWithParams { params, options } => {
let transaction = account.send_with_params(params, options).await?;
Response::SentTransaction(TransactionDto::from(&transaction))
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
AccountMethod::SendOutputs { outputs, options } => {
let token_supply = account.client().get_token_supply().await?;
Expand All @@ -234,7 +236,7 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco
options,
)
.await?;
Response::SentTransaction(TransactionDto::from(&transaction))
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
AccountMethod::SetAlias { alias } => {
account.set_alias(&alias).await?;
Expand All @@ -256,13 +258,13 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco
None,
)
.await?;
Response::SentTransaction(TransactionDto::from(&transaction))
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
AccountMethod::SignTransactionEssence {
AccountMethod::SignTransaction {
prepared_transaction_data,
} => {
let signed_transaction_data = account
.sign_transaction_essence(&PreparedTransactionData::try_from_dto(prepared_transaction_data)?)
.sign_transaction(&PreparedTransactionData::try_from_dto(prepared_transaction_data)?)
.await?;
Response::SignedTransactionData(SignedTransactionDataDto::from(&signed_transaction_data))
}
Expand All @@ -276,12 +278,12 @@ pub(crate) async fn call_account_method_internal(account: &Account, method: Acco
let transaction = account
.submit_and_store_transaction(signed_transaction_data, None)
.await?;
Response::SentTransaction(TransactionDto::from(&transaction))
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
AccountMethod::Sync { options } => Response::Balance(account.sync(options).await?),
AccountMethod::Transactions => {
let transactions = account.transactions().await;
Response::Transactions(transactions.iter().map(TransactionDto::from).collect())
Response::Transactions(transactions.iter().map(TransactionWithMetadataDto::from).collect())
}
AccountMethod::UnspentOutputs { filter_options } => {
let outputs = account.unspent_outputs(filter_options).await?;
Expand Down
8 changes: 3 additions & 5 deletions bindings/core/src/method_handler/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ pub(crate) async fn call_secret_manager_method_internal(
Response::SignedTransaction(transaction.into())
}
SecretManagerMethod::SignatureUnlock {
transaction_essence_hash,
transaction_hash,
chain,
} => {
let transaction_essence_hash: [u8; 32] = prefix_hex::decode(transaction_essence_hash)?;
let unlock: Unlock = secret_manager
.signature_unlock(&transaction_essence_hash, chain)
.await?;
let transaction_hash: [u8; 32] = prefix_hex::decode(transaction_hash)?;
let unlock: Unlock = secret_manager.signature_unlock(&transaction_hash, chain).await?;

Response::SignatureUnlock(unlock)
}
Expand Down
17 changes: 5 additions & 12 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use iota_sdk::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
input::UtxoInput,
output::{AccountId, FoundryId, InputsCommitment, NftId, Output, OutputId, Rent, TokenId},
payload::{transaction::TransactionEssence, TransactionPayload},
output::{AccountId, FoundryId, NftId, Output, OutputId, Rent, TokenId},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
BlockWrapper,
},
TryFromDto,
Expand Down Expand Up @@ -46,7 +46,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
Response::BlockId(block.id(&protocol_parameters))
}
UtilsMethod::TransactionId { payload } => {
let payload = TransactionPayload::try_from_dto(payload)?;
let payload = SignedTransactionPayload::try_from_dto(payload)?;
Response::TransactionId(payload.id())
}
UtilsMethod::ComputeAccountId { output_id } => Response::AccountId(AccountId::from(&output_id)),
Expand All @@ -69,15 +69,8 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
let foundry_id = FoundryId::build(&AccountAddress::new(account_id), serial_number, token_scheme_type);
Response::TokenId(TokenId::from(foundry_id))
}
UtilsMethod::HashTransactionEssence { essence } => {
Response::Hash(prefix_hex::encode(TransactionEssence::try_from_dto(essence)?.hash()))
}
UtilsMethod::ComputeInputsCommitment { inputs } => {
let inputs = inputs
.into_iter()
.map(|o| Ok(Output::try_from_dto(o)?))
.collect::<Result<Vec<Output>>>()?;
Response::Hash(InputsCommitment::new(inputs.iter()).to_string())
UtilsMethod::HashTransaction { transaction } => {
Response::Hash(prefix_hex::encode(Transaction::try_from_dto(transaction)?.hash()))
}
UtilsMethod::ComputeStorageDeposit { output, rent } => {
let out = Output::try_from_dto(output)?;
Expand Down
16 changes: 8 additions & 8 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use iota_sdk::{
address::{Address, Bech32Address, Hrp},
input::UtxoInput,
output::{dto::OutputDto, AccountId, FoundryId, NftId, OutputId, OutputMetadata, TokenId},
payload::{dto::TransactionPayloadDto, transaction::TransactionId},
payload::{dto::SignedTransactionPayloadDto, signed_transaction::TransactionId},
protocol::ProtocolParameters,
signature::Ed25519Signature,
slot::SlotCommitmentId,
Expand All @@ -34,7 +34,7 @@ use iota_sdk::{
},
},
wallet::account::{
types::{AddressWithUnspentOutputs, Balance, Bip44Address, OutputDataDto, TransactionDto},
types::{AddressWithUnspentOutputs, Balance, Bip44Address, OutputDataDto, TransactionWithMetadataDto},
AccountDetailsDto, PreparedCreateNativeTokenTransactionDto,
},
};
Expand Down Expand Up @@ -77,7 +77,7 @@ pub enum Response {
ProtocolParameters(ProtocolParameters),
/// Response for:
/// - [`SignTransaction`](crate::method::SecretManagerMethod::SignTransaction)
SignedTransaction(TransactionPayloadDto),
SignedTransaction(SignedTransactionPayloadDto),
/// Response for:
/// - [`SignatureUnlock`](crate::method::SecretManagerMethod::SignatureUnlock)
SignatureUnlock(Unlock),
Expand Down Expand Up @@ -173,7 +173,7 @@ pub enum Response {
/// - [`ComputeFoundryId`](crate::method::UtilsMethod::ComputeFoundryId)
FoundryId(FoundryId),
/// Response for:
/// - [`HashTransactionEssence`](crate::method::UtilsMethod::HashTransactionEssence)
/// - [`HashTransaction`](crate::method::UtilsMethod::HashTransaction)
/// - [`ComputeInputsCommitment`](crate::method::UtilsMethod::ComputeInputsCommitment)
Hash(String),
/// Response for [`GetNodeInfo`](crate::method::ClientMethod::GetNodeInfo)
Expand Down Expand Up @@ -298,14 +298,14 @@ pub enum Response {
/// Response for:
/// - [`GetIncomingTransaction`](crate::method::AccountMethod::GetIncomingTransaction)
/// - [`GetTransaction`](crate::method::AccountMethod::GetTransaction),
Transaction(Option<Box<TransactionDto>>),
Transaction(Option<Box<TransactionWithMetadataDto>>),
/// Response for:
/// - [`IncomingTransactions`](crate::method::AccountMethod::IncomingTransactions)
/// - [`PendingTransactions`](crate::method::AccountMethod::PendingTransactions),
/// - [`Transactions`](crate::method::AccountMethod::Transactions),
Transactions(Vec<TransactionDto>),
Transactions(Vec<TransactionWithMetadataDto>),
/// Response for:
/// - [`SignTransactionEssence`](crate::method::AccountMethod::SignTransactionEssence)
/// - [`SignTransaction`](crate::method::AccountMethod::SignTransaction)
SignedTransactionData(SignedTransactionDataDto),
/// Response for:
/// - [`GenerateEd25519Addresses`](crate::method::AccountMethod::GenerateEd25519Addresses)
Expand All @@ -320,7 +320,7 @@ pub enum Response {
/// - [`SendOutputs`](crate::method::AccountMethod::SendOutputs)
/// - [`SignAndSubmitTransaction`](crate::method::AccountMethod::SignAndSubmitTransaction)
/// - [`SubmitAndStoreTransaction`](crate::method::AccountMethod::SubmitAndStoreTransaction)
SentTransaction(TransactionDto),
SentTransaction(TransactionWithMetadataDto),
/// Response for:
/// - [`GetParticipationEvent`](crate::method::AccountMethod::GetParticipationEvent)
#[cfg(feature = "participation")]
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/how_tos/account_output/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function run() {
console.log('Sending the create-account transaction...');

// Create an account output
const transaction = await account.createAliasOutput();
const transaction = await account.createAccountOutput();

console.log(`Transaction sent: ${transaction.transactionId}`);

Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/block/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class NftAddress extends Address {
}

/**
* An implicit account creation address.
* An implicit account creation address that can be used to convert a Basic Output to an Account Output.
*/
class ImplicitAccountCreationAddress extends Address {
private pubKeyHash: HexEncodedString;
Expand Down
Loading

0 comments on commit 5411ddd

Please sign in to comment.