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 automatic mana allotment #1961

Merged
merged 74 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
865cf5a
Add automatic mana allotment
Feb 6, 2024
13a55e1
rework
Feb 6, 2024
e3bfbf7
better loop
Feb 6, 2024
d15d9ef
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 6, 2024
2108a8c
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 6, 2024
38e7734
set mana allotment to 1 not 0
Feb 6, 2024
69b628d
Merge branch 'feat/automatic-mana-allotment' of https://github.com/io…
Feb 6, 2024
5b8988d
better error when there is insufficient mana provided
Feb 6, 2024
b0d6ae6
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 6, 2024
be1a40f
make auto mana allotment optional
Feb 7, 2024
773448b
revert some accidental changes
Feb 7, 2024
f9560a9
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 7, 2024
a5596a6
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 7, 2024
b5173e1
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 8, 2024
5a467c9
missed
Feb 8, 2024
5273d2a
rework transaction options
Feb 8, 2024
0872e4d
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 8, 2024
83fc511
improvements
Feb 8, 2024
5a88376
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 8, 2024
4fb1135
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 9, 2024
0a40797
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 9, 2024
474efa3
sort
Feb 9, 2024
d40b984
privatize
Feb 12, 2024
1f93565
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 12, 2024
a54519f
fix mana addition on newly selected inputs
Feb 12, 2024
f62195d
Merge branch 'feat/automatic-mana-allotment' of https://github.com/io…
Feb 12, 2024
5a4ff71
Allow ISA to add mana to existing outputs
Feb 12, 2024
bd49c60
better calculation
Feb 12, 2024
b8454fa
little cleanup
Feb 12, 2024
98c4308
fix slot usage and detect mana remainder more accurately
Feb 12, 2024
063d88a
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 12, 2024
5f9c4a4
add some debug logging
Feb 12, 2024
56827a8
Merge branch 'feat/automatic-mana-allotment' of https://github.com/io…
Feb 12, 2024
b8abe20
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 13, 2024
5bceb5d
rename to required
Feb 13, 2024
65a42dd
more renames
Feb 13, 2024
6a82da7
make context inputs optional
Feb 13, 2024
f19558c
remove hard coded reward index
Feb 13, 2024
4d786a5
another
Feb 13, 2024
7e8add3
Allow using account mana for allotments, fix semantic validation
Thoralf-M Feb 13, 2024
f91bf99
Add test
Thoralf-M Feb 13, 2024
97684d0
carry over previous required allotment value
Feb 13, 2024
e1d3ea1
add more tests
Feb 13, 2024
dc57b4f
simplify
Feb 13, 2024
568dc59
more simpler
Feb 13, 2024
769c55f
just build the transaction in ISA
Feb 13, 2024
b15d64c
cleanup
Feb 13, 2024
544b534
increase mana bits to fix tests
Feb 13, 2024
589b7a7
review
Feb 14, 2024
544ffb4
Set automatically transitioned account mana to zero and order mana re…
Feb 14, 2024
72dbfc0
fix python
Feb 14, 2024
5ff83da
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 14, 2024
1c84083
unused import
Feb 14, 2024
e01fad2
rename tests
Feb 14, 2024
9fdafd2
don't stack allotments
Feb 14, 2024
8529512
track allotment debt for future selected accounts
Feb 14, 2024
6ac3751
more unused imports
Feb 14, 2024
3825a41
Rework allotment
Feb 14, 2024
42d0933
skip allotment step if there are no inputs selected
Feb 14, 2024
5666e30
Loop over remainder calculations too
Feb 15, 2024
8ea3f42
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 15, 2024
6569ccf
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 15, 2024
7127d81
fix last test
Feb 15, 2024
fe02563
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 15, 2024
9fcecaa
one more creation slot usage
Feb 15, 2024
bc2a7af
only add mana to added outputs with no weird unlock conditions
Feb 15, 2024
d155b8b
merge mana and allotments
Feb 15, 2024
6e20820
include provided
Feb 15, 2024
4ba7497
fix amount sums
Feb 15, 2024
d8c9ac4
remove automatically_transitioned
Feb 15, 2024
e3b9bda
unused import
Feb 15, 2024
c24587a
rework allotment again
Feb 15, 2024
2a0efbf
fix skipping allotment
Feb 15, 2024
f193e12
Merge branch '2.0' into feat/automatic-mana-allotment
Feb 15, 2024
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
3 changes: 1 addition & 2 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
&wallet.client().get_protocol_parameters().await?,
)?,
None,
None,
)
.await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
Expand All @@ -438,7 +437,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
&wallet.client().get_protocol_parameters().await?,
)?;
let transaction = wallet
.submit_and_store_transaction(signed_transaction_data, None, None)
.submit_and_store_transaction(signed_transaction_data, None)
.await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
Expand Down
25 changes: 18 additions & 7 deletions bindings/nodejs/lib/types/wallet/transaction-options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { AccountAddress, AccountId, Bech32Address, OutputId } from '../block';
import {
AccountAddress,
AccountId,
Bech32Address,
ContextInput,
ManaAllotment,
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
OutputId,
} from '../block';
import { TaggedDataPayload } from '../block/payload/tagged';
import { Burn } from '../client';
import { u256, HexEncodedString, NumericString, u64 } from '../utils';
Expand All @@ -13,12 +20,8 @@ export interface TransactionOptions {
remainderValueStrategy?: RemainderValueStrategy;
/** An optional tagged data payload. */
taggedDataPayload?: TaggedDataPayload;
/**
* Custom inputs that should be used for the transaction.
* If custom inputs are provided, only those are used.
* If also other additional inputs should be used, `mandatoryInputs` should be used instead.
*/
customInputs?: OutputId[];
/** Transaction context inputs to include. */
contextInputs?: ContextInput[];
/** Inputs that must be used for the transaction. */
mandatoryInputs?: OutputId[];
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
/** Specifies what needs to be burned during input selection. */
Expand All @@ -27,6 +30,14 @@ export interface TransactionOptions {
note?: string;
/** Whether to allow sending a micro amount. */
allowMicroAmount?: boolean;
/** Whether to allow the selection of additional inputs for this transaction. */
allowAdditionalInputSelection?: boolean;
/** Transaction capabilities. */
capabilities?: HexEncodedString;
/** Mana allotments for the transaction. */
manaAllotments?: ManaAllotment[];
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
/** Optional block issuer to which the transaction will have required mana allotted. */
issuerId?: AccountId;
}

/** The possible remainder value strategies. */
Expand Down
27 changes: 21 additions & 6 deletions bindings/python/iota_sdk/types/transaction_options.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Copyright 2023 IOTA Stiftung
# Copyright 2024 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

from enum import Enum
from typing import Optional, List, Union
from dataclasses import dataclass
from iota_sdk.types.address import AccountAddress
from iota_sdk.types.burn import Burn
from iota_sdk.types.common import json
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.context_input import ContextInput
from iota_sdk.types.mana import ManaAllotment
from iota_sdk.types.output_id import OutputId
from iota_sdk.types.payload import TaggedDataPayload

Expand Down Expand Up @@ -68,26 +71,38 @@ class TransactionOptions:
Attributes:
remainder_value_strategy: The strategy applied for base coin remainders.
tagged_data_payload: An optional tagged data payload.
custom_inputs: If custom inputs are provided only those are used. If also other additional inputs should be used, `mandatory_inputs` should be used instead.
context_inputs: Transaction context inputs to include.
mandatory_inputs: Inputs that must be used for the transaction.
burn: Specifies what needs to be burned during input selection.
note: A string attached to the transaction.
allow_micro_amount: Whether to allow sending a micro amount.
allow_additional_input_selection: Whether to allow the selection of additional inputs for this transaction.
capabilities: Transaction capabilities.
mana_allotments: Mana allotments for the transaction.
issuer_id: Optional block issuer to which the transaction will have required mana allotted.
"""

def __init__(self, remainder_value_strategy: Optional[Union[RemainderValueStrategy, RemainderValueStrategyCustomAddress]] = None,
tagged_data_payload: Optional[TaggedDataPayload] = None,
custom_inputs: Optional[List[OutputId]] = None,
context_inputs: Optional[List[ContextInput]] = None,
mandatory_inputs: Optional[List[OutputId]] = None,
burn: Optional[Burn] = None,
note: Optional[str] = None,
allow_micro_amount: Optional[bool] = None):
allow_micro_amount: Optional[bool] = None,
allow_additional_input_selection: Optional[bool] = None,
capabilities: Optional[HexStr] = None,
mana_allotments: Optional[ManaAllotment] = None,
issuer_id: Optional[AccountAddress] = None):
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
"""Initialize transaction options.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
"""
self.remainder_value_strategy = remainder_value_strategy
self.tagged_data_payload = tagged_data_payload
self.custom_inputs = custom_inputs
self.context_inputs = context_inputs
self.mandatory_inputs = mandatory_inputs
self.burn = burn
self.note = note
self.allow_micro_amount = allow_micro_amount
self.allow_additional_input_selection = allow_additional_input_selection
self.capabilities = capabilities
self.mana_allotments = mana_allotments
self.issuer_id = issuer_id
4 changes: 2 additions & 2 deletions sdk/examples/how_tos/account_output/send_amount.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 IOTA Stiftung
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! In this example we use an account as wallet.
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn main() -> Result<()> {
1_000_000,
"rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
TransactionOptions {
mandatory_inputs: Some(vec![input]),
mandatory_inputs: [input].into(),
..Default::default()
},
)
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/wallet/offline_signing/3_send_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() -> Result<()> {

// Sends offline signed transaction online.
let transaction = wallet
.submit_and_store_transaction(signed_transaction_data, None, None)
.submit_and_store_transaction(signed_transaction_data, None)
.await?;
wait_for_inclusion(&transaction.transaction_id, &wallet).await?;

Expand Down
12 changes: 11 additions & 1 deletion sdk/src/client/api/block_builder/input_selection/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 IOTA Stiftung
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! Error handling for input selection.
Expand All @@ -14,6 +14,8 @@ use crate::types::block::output::{ChainId, OutputId, TokenId};
#[derive(Debug, Eq, PartialEq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("additional inputs required for {0:?}, but additional input selection is disabled")]
AdditionalInputsRequired(Requirement),
/// Block error.
#[error("{0}")]
Block(#[from] crate::types::block::Error),
Expand All @@ -30,6 +32,14 @@ pub enum Error {
/// The required amount.
required: u64,
},
/// Insufficient mana provided.
#[error("insufficient mana: found {found}, required {required}")]
InsufficientMana {
/// The amount found.
found: u64,
/// The required amount.
required: u64,
},
/// Insufficient native token amount provided.
#[error("insufficient native token amount: found {found}, required {required}")]
InsufficientNativeTokenAmount {
Expand Down
Loading
Loading