Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add issuer_id to Prepared and Signed TransactionData #2219

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bindings-nodejs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
shell: sh
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn publish --access public
run: yarn publish --access public --tag alpha

nodejs-binding-prebuild:
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security -->

## 2.0.0-alpha.5 - 2024-04-15

### Added

- `{PreparedTransactionData, SignedTransactionData}::issuerId`;

### Fixed

- Implicit account transition with existing account;

## 2.0.0-alpha.4 - 2024-04-04

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2021-2023 IOTA Stiftung
// Copyright 2021-2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Type } from 'class-transformer';
import { AccountId } from '../block';
import { Address, AddressDiscriminator } from '../block/address';
import { Output, OutputDiscriminator } from '../block/output/output';
import { Transaction } from '../block/payload/signed_transaction';
Expand Down Expand Up @@ -29,6 +30,10 @@ export class PreparedTransactionData {
* Mana rewards by input.
*/
manaRewards?: { [outputId: HexEncodedString]: NumericString };
/**
* The block issuer id from which the BIC for the block containing this transaction should be burned.
*/
issuerId?: AccountId;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion bindings/nodejs/lib/types/wallet/signed-transaction-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Type } from 'class-transformer';
import { AccountId } from '../block';
import { SignedTransactionPayload } from '../block/payload/signed_transaction';
import { InputSigningData } from '../client';
import { HexEncodedString, NumericString } from '../utils';
Expand All @@ -14,6 +15,8 @@ export class SignedTransactionData {
/** Signed inputs data. */
@Type(() => InputSigningData)
inputsData!: InputSigningData;
/** Mana rewards by input */
/** Mana rewards by input. */
manaRewards?: { [outputId: HexEncodedString]: NumericString };
/** The block issuer id from which the BIC for the block containing this transaction should be burned. */
issuerId?: AccountId;
}
2 changes: 1 addition & 1 deletion bindings/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iota/sdk",
"version": "2.0.0-alpha.4",
"version": "2.0.0-alpha.5",
"description": "Node.js binding to the IOTA SDK library",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion bindings/python/iota_sdk/types/transaction_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from iota_sdk.types.output_metadata import OutputMetadata
from iota_sdk.types.payload import Transaction, SignedTransactionPayload
from iota_sdk.types.signature import Bip44
from iota_sdk.types.common import json
from iota_sdk.types.common import json, HexStr


@json
Expand Down Expand Up @@ -53,11 +53,13 @@ class PreparedTransactionData:
inputs_data: Data about the inputs which is required for signing.
remainders: Data about remainder outputs.
mana_rewards: Mana rewards by input.
issuer_id: The block issuer id from which the BIC for the block containing this transaction should be burned.
"""
transaction: Transaction
inputs_data: List[InputSigningData]
remainders: Optional[List[RemainderData]] = None
mana_rewards: Optional[dict[OutputId, int]] = None
issuer_id: Optional[HexStr] = None


@json
Expand All @@ -69,7 +71,9 @@ class SignedTransactionData:
payload: The transaction payload.
inputs_data: Data about the inputs consumed in the transaction.
mana_rewards: Mana rewards by input.
issuer_id: The block issuer id from which the BIC for the block containing this transaction should be burned.
"""
payload: SignedTransactionPayload
inputs_data: List[InputSigningData]
mana_rewards: Optional[dict[OutputId, int]] = None
issuer_id: Optional[HexStr] = None
1 change: 1 addition & 0 deletions sdk/examples/wallet/offline_signing/2_sign_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
payload: signed_transaction,
inputs_data: prepared_transaction_data.inputs_data,
mana_rewards: prepared_transaction_data.mana_rewards,
issuer_id: prepared_transaction_data.issuer_id,
};

println!("Signed transaction.");
Expand Down
10 changes: 10 additions & 0 deletions sdk/src/client/api/block_builder/transaction_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl Client {
.with_mana_allotments(options.mana_allotments)
.with_remainder_address(remainder_address)
.with_transitions(options.transitions)
.with_issuer_id(options.issuer_id)
.with_burn(options.burn);

if let (Some(account_id), Some(reference_mana_cost)) = (options.issuer_id, reference_mana_cost) {
Expand Down Expand Up @@ -193,6 +194,7 @@ pub struct TransactionBuilder {
latest_slot_commitment_id: SlotCommitmentId,
requirements: Vec<Requirement>,
min_mana_allotment: Option<MinManaAllotment>,
issuer_id: Option<AccountId>,
mana_allotments: BTreeMap<AccountId, u64>,
mana_rewards: HashMap<OutputId, u64>,
payload: Option<TaggedDataPayload>,
Expand Down Expand Up @@ -268,6 +270,7 @@ impl TransactionBuilder {
latest_slot_commitment_id,
requirements: Vec::new(),
min_mana_allotment: None,
issuer_id: None,
mana_allotments: Default::default(),
mana_rewards: Default::default(),
allow_additional_input_selection: true,
Expand Down Expand Up @@ -498,6 +501,7 @@ impl TransactionBuilder {
inputs_data,
remainders: self.remainders.data,
mana_rewards: self.mana_rewards.into_iter().collect(),
issuer_id: self.issuer_id,
};

data.verify_semantic(&self.protocol_parameters)?;
Expand Down Expand Up @@ -607,6 +611,12 @@ impl TransactionBuilder {
self
}

/// Specifies the block issuer id that should be used when sending a block.
pub fn with_issuer_id(mut self, issuer_id: impl Into<Option<AccountId>>) -> Self {
self.issuer_id = issuer_id.into();
self
}

/// Disables selecting additional inputs.
pub fn disable_additional_input_selection(mut self) -> Self {
self.allow_additional_input_selection = false;
Expand Down
14 changes: 13 additions & 1 deletion sdk/src/client/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
types::{
block::{
address::Address,
output::{Output, OutputId},
output::{AccountId, Output, OutputId},
payload::{
signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
Expand All @@ -37,6 +37,8 @@ pub struct PreparedTransactionData {
pub remainders: Vec<RemainderData>,
/// Mana rewards
pub mana_rewards: BTreeMap<OutputId, u64>,
/// The block issuer id from which the BIC for the block containing this transaction should be burned.
pub issuer_id: Option<AccountId>,
}

/// PreparedTransactionData Dto
Expand All @@ -53,6 +55,8 @@ pub struct PreparedTransactionDataDto {
/// Mana rewards
#[serde(default, skip_serializing_if = "BTreeMap::is_empty", with = "mana_rewards")]
pub mana_rewards: BTreeMap<OutputId, u64>,
/// The block issuer id from which the BIC for the block containing this transaction should be burned.
pub issuer_id: Option<AccountId>,
}

impl From<&PreparedTransactionData> for PreparedTransactionDataDto {
Expand All @@ -62,6 +66,7 @@ impl From<&PreparedTransactionData> for PreparedTransactionDataDto {
inputs_data: value.inputs_data.clone(),
remainders: value.remainders.clone(),
mana_rewards: value.mana_rewards.clone(),
issuer_id: value.issuer_id,
}
}
}
Expand All @@ -78,6 +83,7 @@ impl TryFromDto<PreparedTransactionDataDto> for PreparedTransactionData {
inputs_data: dto.inputs_data,
remainders: dto.remainders,
mana_rewards: dto.mana_rewards,
issuer_id: dto.issuer_id,
})
}
}
Expand All @@ -100,6 +106,8 @@ pub struct SignedTransactionData {
pub inputs_data: Vec<InputSigningData>,
/// Mana rewards
pub mana_rewards: BTreeMap<OutputId, u64>,
/// The block issuer id from which the BIC for the block containing this transaction should be burned.
pub issuer_id: Option<AccountId>,
}

/// SignedTransactionData Dto
Expand All @@ -113,6 +121,8 @@ pub struct SignedTransactionDataDto {
/// Mana rewards
#[serde(default, skip_serializing_if = "BTreeMap::is_empty", with = "mana_rewards")]
pub mana_rewards: BTreeMap<OutputId, u64>,
/// The block issuer id from which the BIC for the block containing this transaction should be burned.
pub issuer_id: Option<AccountId>,
}

impl From<&SignedTransactionData> for SignedTransactionDataDto {
Expand All @@ -121,6 +131,7 @@ impl From<&SignedTransactionData> for SignedTransactionDataDto {
payload: SignedTransactionPayloadDto::from(&value.payload),
inputs_data: value.inputs_data.clone(),
mana_rewards: value.mana_rewards.clone(),
issuer_id: value.issuer_id,
}
}
}
Expand All @@ -136,6 +147,7 @@ impl TryFromDto<SignedTransactionDataDto> for SignedTransactionData {
payload: SignedTransactionPayload::try_from_dto_with_params_inner(dto.payload, params)?,
inputs_data: dto.inputs_data,
mana_rewards: dto.mana_rewards,
issuer_id: dto.issuer_id,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/client/secret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ where
transaction,
inputs_data,
mana_rewards,
issuer_id,
..
} = prepared_transaction_data;
let tx_payload = SignedTransactionPayload::new(transaction, unlocks)?;
Expand All @@ -670,6 +671,7 @@ where
payload: tx_payload,
inputs_data,
mana_rewards,
issuer_id,
};

data.verify_semantic(protocol_parameters).inspect_err(|e| {
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/wallet/operations/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ where
let block_id = match self
.submit_basic_block(
Some(Payload::from(signed_transaction_data.payload.clone())),
options.as_ref().and_then(|options| options.issuer_id),
signed_transaction_data
.issuer_id
.or_else(|| options.as_ref().and_then(|options| options.issuer_id)),
true,
)
.await
Expand Down
1 change: 1 addition & 0 deletions sdk/src/wallet/operations/transaction/send_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ where
) -> Result<PreparedTransactionData, WalletError> {
log::debug!("[TRANSACTION] prepare_send_outputs");
let options = options.into().unwrap_or_default();
log::debug!("prepare_send_outputs {options:#?}");
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
let outputs = outputs.into_iter().collect::<Vec<_>>();
let prepare_send_outputs_start_time = Instant::now();
let storage_score_params = self.client().get_storage_score_parameters().await?;
Expand Down
1 change: 1 addition & 0 deletions sdk/src/wallet/operations/transaction/sign_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ where
payload,
inputs_data: prepared_transaction_data.inputs_data.clone(),
mana_rewards: prepared_transaction_data.mana_rewards.clone(),
issuer_id: prepared_transaction_data.issuer_id,
})
}
}
2 changes: 2 additions & 0 deletions sdk/tests/client/signing/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn sign_account_state_transition() -> Result<(), Box<dyn std::error::Error
inputs_data: inputs,
remainders: Vec::new(),
mana_rewards: Default::default(),
issuer_id: None,
};

let unlocks = secret_manager
Expand Down Expand Up @@ -207,6 +208,7 @@ async fn account_reference_unlocks() -> Result<(), Box<dyn std::error::Error>> {
inputs_data: inputs,
remainders: Vec::new(),
mana_rewards: Default::default(),
issuer_id: None,
};

let unlocks = secret_manager
Expand Down
3 changes: 3 additions & 0 deletions sdk/tests/client/signing/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async fn single_ed25519_unlock() -> Result<(), Box<dyn std::error::Error>> {
inputs_data: inputs,
remainders: Vec::new(),
mana_rewards: Default::default(),
issuer_id: None,
};

let unlocks = secret_manager
Expand Down Expand Up @@ -192,6 +193,7 @@ async fn ed25519_reference_unlocks() -> Result<(), Box<dyn std::error::Error>> {
inputs_data: inputs,
remainders: Vec::new(),
mana_rewards: Default::default(),
issuer_id: None,
};

let unlocks = secret_manager
Expand Down Expand Up @@ -306,6 +308,7 @@ async fn two_signature_unlocks() -> Result<(), Box<dyn std::error::Error>> {
inputs_data: inputs,
remainders: Vec::new(),
mana_rewards: Default::default(),
issuer_id: None,
};

let unlocks = secret_manager
Expand Down
Loading
Loading