Skip to content

Commit

Permalink
Merge branch '2.0' into address-converters-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M authored Mar 6, 2024
2 parents 14a280a + 4aac837 commit 4013788
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 133 deletions.
29 changes: 1 addition & 28 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ pub enum WalletMethod {
/// Expected response: [`OutputIds`](crate::Response::OutputIds)
#[serde(rename_all = "camelCase")]
ClaimableOutputs { outputs_to_claim: OutputsToClaim },
/// Claim outputs.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
#[serde(rename_all = "camelCase")]
ClaimOutputs { output_ids_to_claim: Vec<OutputId> },
// /// Removes a previously registered participation event from local storage.
// /// Expected response: [`Ok`](crate::Response::Ok)
// #[cfg(feature = "participation")]
Expand Down Expand Up @@ -308,7 +304,7 @@ pub enum WalletMethod {
#[serde(default)]
transaction_options: Option<TransactionOptions>,
},
/// Prepare to send base coins.
/// Prepare to send base coins to multiple addresses, or with additional parameters.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareSend {
params: Vec<SendParams>,
Expand Down Expand Up @@ -421,29 +417,6 @@ pub enum WalletMethod {
/// Maximum attempts
max_attempts: Option<u64>,
},
/// Send base coins.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
Send {
#[serde(with = "string")]
amount: u64,
address: Bech32Address,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Send base coins to multiple addresses, or with additional parameters.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
SendWithParams {
params: Vec<SendParams>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Send outputs in a transaction.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
SendOutputs {
outputs: Vec<Output>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Set the alias of the wallet.
/// Expected response: [`Ok`](crate::Response::Ok)
SetAlias { alias: String },
Expand Down
20 changes: 0 additions & 20 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ pub(crate) async fn call_wallet_method_internal(
let output_ids = wallet.claimable_outputs(outputs_to_claim).await?;
Response::OutputIds(output_ids)
}
WalletMethod::ClaimOutputs { output_ids_to_claim } => {
let transaction = wallet.claim_outputs(output_ids_to_claim.to_vec()).await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
// #[cfg(feature = "participation")]
// WalletMethod::DeregisterParticipationEvent { event_id } => {
// wallet.deregister_participation_event(&event_id).await?;
Expand Down Expand Up @@ -390,22 +386,6 @@ pub(crate) async fn call_wallet_method_internal(
.await?;
Response::Ok
}
WalletMethod::Send {
amount,
address,
options,
} => {
let transaction = wallet.send(amount, address, options).await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
WalletMethod::SendWithParams { params, options } => {
let transaction = wallet.send_with_params(params, options).await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
WalletMethod::SendOutputs { outputs, options } => {
let transaction = wallet.send_outputs(outputs, options).await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
WalletMethod::SetAlias { alias } => {
wallet.set_alias(&alias).await?;
Response::Ok
Expand Down
9 changes: 3 additions & 6 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ pub enum Response {
/// - [`VerifySecp256k1EcdsaSignature`](crate::method::UtilsMethod::VerifySecp256k1EcdsaSignature)
Bool(bool),
/// Response for:
/// - [`Backup`](crate::method::WalletMethod::Backup),
/// - [`BackupToStrongholdSnapshot`](crate::method::WalletMethod::BackupToStrongholdSnapshot),
/// - [`ClearListeners`](crate::method::WalletMethod::ClearListeners)
/// - [`ClearStrongholdPassword`](crate::method::WalletMethod::ClearStrongholdPassword),
/// - [`DeregisterParticipationEvent`](crate::method::WalletMethod::DeregisterParticipationEvent),
/// - [`EmitTestEvent`](crate::method::WalletMethod::EmitTestEvent),
/// - [`RestoreBackup`](crate::method::WalletMethod::RestoreBackup),
/// - [`RestoreFromStrongholdSnapshot`](crate::method::WalletMethod::RestoreFromStrongholdSnapshot),
/// - [`SetAlias`](crate::method::WalletMethod::SetAlias),
/// - [`SetClientOptions`](crate::method::WalletMethod::SetClientOptions),
/// - [`SetDefaultSyncOptions`](crate::method::WalletMethod::SetDefaultSyncOptions),
Expand Down Expand Up @@ -314,10 +314,10 @@ pub enum Response {
/// - [`PrepareMeltNativeToken`](crate::method::WalletMethod::PrepareMeltNativeToken)
/// - [`PrepareMintNativeToken`](crate::method::WalletMethod::PrepareMintNativeToken),
/// - [`PrepareMintNfts`](crate::method::WalletMethod::PrepareMintNfts),
/// - [`PrepareSend`](crate::method::WalletMethod::PrepareSend),
/// - [`PrepareSendMana`](crate::method::WalletMethod::PrepareSendMana),
/// - [`PrepareSendNativeTokens`](crate::method::WalletMethod::PrepareSendNativeTokens),
/// - [`PrepareSendNft`](crate::method::WalletMethod::PrepareSendNft),
/// - [`PrepareSend`](crate::method::WalletMethod::PrepareSend),
/// - [`PrepareStopParticipating`](crate::method::WalletMethod::PrepareStopParticipating)
/// - [`PrepareSendOutputs`](crate::method::WalletMethod::PrepareSendOutputs)
/// - [`PrepareVote`](crate::method::WalletMethod::PrepareVote)
Expand Down Expand Up @@ -346,9 +346,6 @@ pub enum Response {
/// - [`Sync`](crate::method::WalletMethod::Sync)
Balance(Balance),
/// Response for:
/// - [`ClaimOutputs`](crate::method::WalletMethod::ClaimOutputs)
/// - [`Send`](crate::method::WalletMethod::Send)
/// - [`SendOutputs`](crate::method::WalletMethod::SendOutputs)
/// - [`SignAndSubmitTransaction`](crate::method::WalletMethod::SignAndSubmitTransaction)
/// - [`SubmitAndStoreTransaction`](crate::method::WalletMethod::SubmitAndStoreTransaction)
SentTransaction(TransactionWithMetadataDto),
Expand Down
8 changes: 2 additions & 6 deletions bindings/nodejs/lib/types/wallet/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import type {
__PrepareMintNativeTokenMethod__,
__PrepareMintNftsMethod__,
__PrepareOutputMethod__,
__PrepareSendMethod__,
__PrepareSendManaMethod__,
__PrepareSendMethod__,
__PrepareCreateDelegationMethod__,
__PrepareDelayDelegationClaimingMethod__,
__PrepareBeginStakingMethod__,
Expand All @@ -34,8 +34,6 @@ import type {
__PrepareSendOutputsMethod__,
__RegisterParticipationEventsMethod__,
__WaitForTransactionAcceptanceMethod__,
__SendMethod__,
__SendWithParamsMethod__,
__PrepareSendNativeTokensMethod__,
__PrepareSendNftMethod__,
__SendOutputsMethod__,
Expand Down Expand Up @@ -105,8 +103,8 @@ export type __WalletMethod__ =
| __PrepareMintNativeTokenMethod__
| __PrepareMintNftsMethod__
| __PrepareOutputMethod__
| __PrepareSendMethod__
| __PrepareSendManaMethod__
| __PrepareSendMethod__
| __PrepareCreateDelegationMethod__
| __PrepareDelayDelegationClaimingMethod__
| __PrepareBeginStakingMethod__
Expand All @@ -115,8 +113,6 @@ export type __WalletMethod__ =
| __PrepareSendOutputsMethod__
| __RegisterParticipationEventsMethod__
| __WaitForTransactionAcceptanceMethod__
| __SendMethod__
| __SendWithParamsMethod__
| __PrepareSendNativeTokensMethod__
| __PrepareSendNftMethod__
| __SendOutputsMethod__
Expand Down
21 changes: 2 additions & 19 deletions bindings/nodejs/lib/types/wallet/bridge/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,6 @@ export type __PrepareOutputMethod__ = {
};
};

export type __PrepareSendMethod__ = {
name: 'prepareSend';
data: {
params: SendParams[];
options?: TransactionOptions;
};
};

export type __PrepareSendOutputsMethod__ = {
name: 'prepareSendOutputs';
data: {
Expand All @@ -375,17 +367,8 @@ export type __WaitForTransactionAcceptanceMethod__ = {
};
};

export type __SendMethod__ = {
name: 'send';
data: {
amount: NumericString;
address: string;
options?: TransactionOptions;
};
};

export type __SendWithParamsMethod__ = {
name: 'sendWithParams';
export type __PrepareSendMethod__ = {
name: 'prepareSend';
data: {
params: SendParams[];
options?: TransactionOptions;
Expand Down
40 changes: 8 additions & 32 deletions bindings/nodejs/lib/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,11 +1463,11 @@ export class Wallet {
}

/**
* Send outputs.
* Send outputs in a transaction.
*
* @param outputs Outputs to use in the transaction.
* @param options Additional transaction options.
* @returns The transaction data.
* @param outputs The outputs to send.
* @param transactionOptions Additional transaction options.
* @returns The sent transaction.
*/
async sendOutputs(
outputs: Output[],
Expand Down Expand Up @@ -1555,18 +1555,9 @@ export class Wallet {
if (typeof amount === 'bigint') {
amount = amount.toString(10);
}
const response = await this.methodHandler.callMethod({
name: 'send',
data: {
amount,
address,
options: transactionOptions,
},
});
const parsed = JSON.parse(
response,
) as Response<TransactionWithMetadata>;
return plainToInstance(TransactionWithMetadata, parsed.payload);
return (
await this.prepareSend([{ address, amount }], transactionOptions)
).send();
}

/**
Expand All @@ -1580,22 +1571,7 @@ export class Wallet {
params: SendParams[],
transactionOptions?: TransactionOptions,
): Promise<TransactionWithMetadata> {
for (let i = 0; i < params.length; i++) {
if (typeof params[i].amount === 'bigint') {
params[i].amount = params[i].amount.toString(10);
}
}
const response = await this.methodHandler.callMethod({
name: 'sendWithParams',
data: {
params,
options: transactionOptions,
},
});
const parsed = JSON.parse(
response,
) as Response<TransactionWithMetadata>;
return plainToInstance(TransactionWithMetadata, parsed.payload);
return (await this.prepareSend(params, transactionOptions)).send();
}

/**
Expand Down
33 changes: 11 additions & 22 deletions bindings/python/iota_sdk/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,6 @@ def prepare_output(self, params: OutputParams,
})
)

def prepare_send(self, params: List[SendParams],
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Prepare to send base coins.
"""
prepared = PreparedTransactionData.from_dict(self._call_method(
'prepareSend', {
'params': params,
'options': options
}
))
return PreparedTransaction(self, prepared)

def create_delegation(self, params: CreateDelegationParams,
options: Optional[TransactionOptions] = None) -> CreateDelegationTransaction:
"""Create a delegation.
Expand Down Expand Up @@ -735,24 +723,25 @@ def send(self, amount: int, address: str,
options: Optional[TransactionOptions] = None) -> TransactionWithMetadata:
"""Send base coins.
"""
return TransactionWithMetadata.from_dict(self._call_method(
'send', {
'amount': str(amount),
'address': address,
'options': options
}
))
return self.prepare_send([SendParams(address, amount)], options).send()

def send_with_params(
self, params: List[SendParams], options: Optional[TransactionOptions] = None) -> TransactionWithMetadata:
"""Send base coins to multiple addresses or with additional parameters.
"""
return TransactionWithMetadata.from_dict(self._call_method(
'sendWithParams', {
'params': [param.to_dict() for param in params],
return self.prepare_send(params, options).send()

def prepare_send(self, params: List[SendParams],
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Prepare to send with params.
"""
prepared = PreparedTransactionData.from_dict(self._call_method(
'prepareSend', {
'params': params,
'options': options
}
))
return PreparedTransaction(self, prepared)

def send_native_tokens(
self, params: List[SendNativeTokenParams], options: Optional[TransactionOptions] = None) -> TransactionWithMetadata:
Expand Down

0 comments on commit 4013788

Please sign in to comment.