Skip to content

Commit

Permalink
Fix SlotCommitment JSON (#1662)
Browse files Browse the repository at this point in the history
* Fix SlotCommitment field names

* Update nodejs

* Fix nodejs

* Remove weirdness

* Remove ComputeInputsCommitment remnants

* Revert
  • Loading branch information
thibault-martinez authored Nov 22, 2023
1 parent 7cc9bc7 commit 3eb4db4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
1 change: 0 additions & 1 deletion bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ pub enum Response {
FoundryId(FoundryId),
/// Response for:
/// - [`TransactionSigningHash`](crate::method::UtilsMethod::TransactionSigningHash)
/// - [`ComputeInputsCommitment`](crate::method::UtilsMethod::ComputeInputsCommitment)
Hash(String),
/// Response for [`GetNodeInfo`](crate::method::ClientMethod::GetNodeInfo)
NodeInfoWrapper(NodeInfoWrapper),
Expand Down
25 changes: 18 additions & 7 deletions bindings/nodejs/lib/types/block/slot/commitment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,48 @@ type RootsId = string;
* It is linked to the commitment of the previous slot, which forms a commitment chain.
*/
class SlotCommitment {
/**
* The version of the protocol running.
*/
readonly protocolVersion: number;
/**
* The slot index of this commitment.
* It is calculated based on genesis timestamp and the duration of a slot.
*/
readonly index: SlotIndex;
readonly slot: SlotIndex;
/**
* The commitment ID of the previous slot.
*/
readonly prevId: SlotCommitmentId;
readonly previousCommitmentId: SlotCommitmentId;
/**
* A BLAKE2b-256 hash of concatenating multiple sparse merkle tree roots of a slot.
*/
readonly rootsId: RootsId;

/**
* The sum of previous slot commitment cumulative weight and weight of issuers of accepted blocks within this
* slot. It is just an indication of "committed into" this slot, and can not strictly be used for evaluating
* the switching of a chain.
*/
readonly cumulativeWeight: u64;
/**
* Reference Mana Cost (RMC) to be used in the slot with index at `index + Max Committable Age`.
*/
readonly referenceManaCost: u64;

constructor(
index: SlotIndex,
previousSlotCommitmentId: SlotCommitmentId,
protocolVersion: number,
slot: SlotIndex,
previousCommitmentId: SlotCommitmentId,
rootsId: RootsId,
cumulativeWeight: u64,
referenceManaCost: u64,
) {
this.index = index;
this.prevId = previousSlotCommitmentId;
this.protocolVersion = protocolVersion;
this.slot = slot;
this.previousCommitmentId = previousCommitmentId;
this.rootsId = rootsId;
this.cumulativeWeight = cumulativeWeight;
this.referenceManaCost = referenceManaCost;
}
}

Expand Down
5 changes: 3 additions & 2 deletions bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ export interface __OutputHexBytes__ {
};
}

// TODO we don't do this anywhere else, but it seems necessary, need to reevaluate later.
// Modified `SlotCommitment` with bigint types converted to strings.
type SlotCommitmentConverted = Omit<
SlotCommitment,
'index' | 'cumulativeWeight'
> & { index: string; cumulativeWeight: string };
'cumulativeWeight' | 'referenceManaCost'
> & { cumulativeWeight: string; referenceManaCost: string };
export interface __ComputeSlotCommitmentId__ {
name: 'computeSlotCommitmentId';
data: {
Expand Down
7 changes: 5 additions & 2 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,14 @@ export class Utils {
name: 'computeSlotCommitmentId',
data: {
slotCommitment: {
index: slotCommitment.index.toString(10),
prevId: slotCommitment.prevId,
protocolVersion: slotCommitment.protocolVersion,
slot: slotCommitment.slot,
previousCommitmentId: slotCommitment.previousCommitmentId,
rootsId: slotCommitment.rootsId,
cumulativeWeight:
slotCommitment.cumulativeWeight.toString(10),
referenceManaCost:
slotCommitment.referenceManaCost.toString(10),
},
},
});
Expand Down
8 changes: 0 additions & 8 deletions bindings/python/iota_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ def compute_foundry_id(account_id: HexStr, serial_number: int,
'tokenSchemeType': token_scheme_type
})

@staticmethod
def compute_inputs_commitment(inputs: List[Output]) -> HexStr:
"""Compute the input commitment from the output objects that are used as inputs to fund the transaction.
"""
return _call_method('computeInputsCommitment', {
'inputs': [i.to_dict() for i in inputs]
})

@staticmethod
def compute_storage_deposit(output, rent) -> HexStr:
"""Compute the required storage deposit of an output.
Expand Down
25 changes: 12 additions & 13 deletions sdk/src/types/block/slot/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ pub struct SlotCommitment {
protocol_version: u8,
/// The slot index of this commitment.
/// It is calculated based on genesis timestamp and the duration of a slot.
index: SlotIndex,
slot: SlotIndex,
/// The commitment ID of the previous slot.
#[cfg_attr(feature = "serde", serde(rename = "previousCommitmentId"))]
previous_slot_commitment_id: SlotCommitmentId,
previous_commitment_id: SlotCommitmentId,
/// The digest of multiple sparse merkle tree roots of this slot.
roots_id: RootsId,
/// The sum of previous slot commitment cumulative weight and weight of issuers of accepted blocks within this
Expand All @@ -43,16 +42,16 @@ impl SlotCommitment {
/// Creates a new [`SlotCommitment`].
pub fn new(
protocol_version: u8,
index: SlotIndex,
previous_slot_commitment_id: SlotCommitmentId,
slot: SlotIndex,
previous_commitment_id: SlotCommitmentId,
roots_id: RootsId,
cumulative_weight: u64,
reference_mana_cost: u64,
) -> Self {
Self {
protocol_version,
index,
previous_slot_commitment_id,
slot,
previous_commitment_id,
roots_id,
cumulative_weight,
reference_mana_cost,
Expand All @@ -64,14 +63,14 @@ impl SlotCommitment {
self.protocol_version
}

/// Returns the index of the [`SlotCommitment`].
pub fn index(&self) -> SlotIndex {
self.index
/// Returns the slot index of the [`SlotCommitment`].
pub fn slot(&self) -> SlotIndex {
self.slot
}

/// Returns the previous slot commitment ID of the [`SlotCommitment`].
pub fn previous_slot_commitment_id(&self) -> &SlotCommitmentId {
&self.previous_slot_commitment_id
pub fn previous_commitment_id(&self) -> &SlotCommitmentId {
&self.previous_commitment_id
}

/// Returns the roots ID of the [`SlotCommitment`].
Expand All @@ -91,6 +90,6 @@ impl SlotCommitment {

/// Computes the [`SlotCommitmentId`] of the [`SlotCommitment`].
pub fn id(&self) -> SlotCommitmentId {
SlotCommitmentHash::new(Blake2b256::digest(self.pack_to_vec()).into()).into_slot_commitment_id(self.index)
SlotCommitmentHash::new(Blake2b256::digest(self.pack_to_vec()).into()).into_slot_commitment_id(self.slot)
}
}

0 comments on commit 3eb4db4

Please sign in to comment.