Skip to content

Commit

Permalink
Add AnchorOutput and AnchorAddress (#1379)
Browse files Browse the repository at this point in the history
* Add AnchorOutput and AnchorAddress

* Start removing account transitions

* More changes

* Remove state_metadata

* More changes

* It compiles!!!

* Some more examples fixes

* More test fixes

* Warnings

* Fix some tests

* Some bindings changes

* More changes :sadcat:

* Set AnchorAddress type

* Add AnchorOutputs address capability

* Add AnchorUnlock

* Fix ANCHOR_OUTPUTS capability

* Fix test compilation

* Add DESTROY_ANCHOR_OUTPUTS tx capability

* Add Anchor address cap semantic validation

* Fix compilation

* Temporarily disable test until TIP is updated

* Fix some tests

* Last failing tests

* Some nits

* Fix test

* Some Python fixes

* Nits

* Remove TODO

* Doc nit

* Add Anchor to def_is_as_opt

* Display delegations/anchors in CLI addresses cmd

* Update sdk/src/client/api/block_builder/input_selection/mod.rs

Co-authored-by: Thoralf-M <[email protected]>

* Fix warning

* Cleanup account transition validation

* Reviews

* Nit

* Add ISA UnsupportedAddressType error

* impl From<&OutputId> for AnchorAddress

* Update addresses order and types

* Update restricted address tests

* Address semantic TODOs

* required_and_unlocked_address TODO

* Address unlock TODO

* Secret TODO

* Ledger nano TODO

* Reenable test

* Typo

* Warning

* Address Display

* ISA nits

* Move anchor tx cap

* Update rand address modulo

* then_some(index)

* Fix nodejs example

* Fix python

* wtf

---------

Co-authored-by: Thoralf-M <[email protected]>
  • Loading branch information
thibault-martinez and Thoralf-M authored Oct 28, 2023
1 parent 143cdef commit 46d979b
Show file tree
Hide file tree
Showing 93 changed files with 3,164 additions and 4,164 deletions.
2 changes: 0 additions & 2 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ pub enum ClientMethod {
mana: u64,
native_tokens: Option<Vec<NativeToken>>,
account_id: AccountId,
state_index: Option<u32>,
state_metadata: Option<String>,
foundry_counter: Option<u32>,
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
Expand Down
4 changes: 0 additions & 4 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
mana,
native_tokens,
account_id,
state_index,
state_metadata,
foundry_counter,
unlock_conditions,
features,
Expand All @@ -76,8 +74,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
mana,
native_tokens,
&account_id,
state_index,
state_metadata.map(prefix_hex::decode).transpose()?,
foundry_counter,
unlock_conditions,
features,
Expand Down
11 changes: 2 additions & 9 deletions bindings/nodejs/examples/client/13-build-account-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
Client,
initLogger,
Utils,
StateControllerAddressUnlockCondition,
MetadataFeature,
SenderFeature,
Ed25519Address,
IssuerFeature,
GovernorAddressUnlockCondition,
AddressUnlockCondition,
utf8ToHex,
} from '@iota/sdk';
require('dotenv').config({ path: '.env' });
Expand Down Expand Up @@ -38,14 +37,8 @@ async function run() {
const accountOutput = await client.buildAccountOutput({
accountId:
'0x0000000000000000000000000000000000000000000000000000000000000000',
stateMetadata: utf8ToHex('hello'),
unlockConditions: [
new StateControllerAddressUnlockCondition(
new Ed25519Address(hexAddress),
),
new GovernorAddressUnlockCondition(
new Ed25519Address(hexAddress),
),
new AddressUnlockCondition(new Ed25519Address(hexAddress)),
],
features: [
new SenderFeature(new Ed25519Address(hexAddress)),
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion bindings/nodejs/examples/how_tos/outputs/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require('dotenv').config({ path: '.env' });
// Run with command:
// yarn run-example ./how_tos/outputs/features.ts

// Build ouputs with all features
// Build outputs with all features
async function run() {
initLogger();

Expand Down
19 changes: 1 addition & 18 deletions bindings/nodejs/examples/how_tos/outputs/unlock-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
ExpirationUnlockCondition,
TimelockUnlockCondition,
SimpleTokenScheme,
StateControllerAddressUnlockCondition,
GovernorAddressUnlockCondition,
ImmutableAccountAddressUnlockCondition,
AccountAddress,
} from '@iota/sdk';
Expand All @@ -22,7 +20,7 @@ require('dotenv').config({ path: '.env' });
// Run with command:
// yarn run-example ./how_tos/outputs/unlock-conditions.ts

// Build ouputs with all unlock conditions
// Build outputs with all unlock conditions
async function run() {
initLogger();

Expand Down Expand Up @@ -81,20 +79,6 @@ async function run() {
],
});

// Output with governor and state controller unlock condition
const accountOutput = await client.buildAccountOutput({
accountId:
'0x0000000000000000000000000000000000000000000000000000000000000000',
unlockConditions: [
new GovernorAddressUnlockCondition(
new Ed25519Address(hexAddress),
),
new StateControllerAddressUnlockCondition(
new Ed25519Address(hexAddress),
),
],
});

// Output with immutable account unlock condition
const foundryOutput = await client.buildFoundryOutput({
serialNumber: 1,
Expand All @@ -113,7 +97,6 @@ async function run() {
basicOutputWithStorageReturn,
basicOutputWithTimelock,
basicOutputWithExpiration,
accountOutput,
foundryOutput,
],
null,
Expand Down
29 changes: 1 addition & 28 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,39 +177,15 @@ abstract class ImmutableFeaturesOutput extends CommonOutput {
}
}

/**
* Base class for state metadata outputs.
*/
abstract class StateMetadataOutput extends ImmutableFeaturesOutput {
readonly stateMetadata?: HexEncodedString;

/**
* @param type The type of output.
* @param amount The amount of the output.
* @param unlockConditions The unlock conditions for the output.
*/
constructor(
type: OutputType,
amount: u64,
unlockConditions: UnlockCondition[],
) {
super(type, amount, unlockConditions);
}
}

/**
* An Account output.
*/
class AccountOutput extends StateMetadataOutput {
class AccountOutput extends ImmutableFeaturesOutput {
/**
* Unique identifier of the account, which is the BLAKE2b-256 hash of the Output ID that created it.
* Unless its a newly created account, then the id is zeroed.
*/
readonly accountId: HexEncodedString;
/**
* A counter that must increase by 1 every time the account output is state transitioned.
*/
readonly stateIndex: number;
/**
* A counter that denotes the number of foundries created by this account output.
*/
Expand All @@ -223,21 +199,18 @@ class AccountOutput extends StateMetadataOutput {
* @param amount The amount of the output.
* @param mana The amount of stored mana.
* @param accountId The account ID as hex-encoded string.
* @param stateIndex A counter that must increase by 1 every time the account output is state transitioned.
* @param foundryCounter A counter that denotes the number of foundries created by this account output.
* @param unlockConditions The unlock conditions of the output.
*/
constructor(
amount: u64,
mana: u64,
accountId: HexEncodedString,
stateIndex: number,
foundryCounter: number,
unlockConditions: UnlockCondition[],
) {
super(OutputType.Account, amount, unlockConditions);
this.accountId = accountId;
this.stateIndex = stateIndex;
this.foundryCounter = foundryCounter;
this.mana = mana;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { AccountId, Feature, HexEncodedString } from '../..';
import { AccountId, Feature } from '../..';
import type { BasicOutputBuilderParams } from './basic-output-params';

/**
Expand All @@ -12,14 +12,6 @@ export interface AccountOutputBuilderParams extends BasicOutputBuilderParams {
* Unique identifier of an account, which is the BLAKE2b-256 hash of the Output ID that created it.
*/
accountId: AccountId;
/**
* A counter that must increase by 1 every time the account output is state transitioned.
*/
stateIndex?: number;
/**
* Metadata that can only be changed by the state controller.
*/
stateMetadata?: HexEncodedString;
/**
* A counter that denotes the number of foundries created by this account output.
*/
Expand Down
Loading

0 comments on commit 46d979b

Please sign in to comment.