diff --git a/bindings/nodejs/examples/client/05-get-address-balance.ts b/bindings/nodejs/examples/client/05-get-address-balance.ts index 9f8491b8cb..1c9b3f6b2d 100644 --- a/bindings/nodejs/examples/client/05-get-address-balance.ts +++ b/bindings/nodejs/examples/client/05-get-address-balance.ts @@ -38,12 +38,12 @@ async function run() { }); // Get output ids of basic outputs that can be controlled by this address without further unlock constraints - const outputIdsResponse = await client.basicOutputIds([ - { address: addresses[0] }, - { hasExpiration: false }, - { hasTimelock: false }, - { hasStorageDepositReturn: false }, - ]); + const outputIdsResponse = await client.basicOutputIds({ + address: addresses[0], + hasExpiration: false, + hasTimelock: false, + hasStorageDepositReturn: false, + }); // Get outputs by their IDs const addressOutputs = await client.getOutputs(outputIdsResponse.items); diff --git a/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts b/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts index 3d5b375a90..aa7176e992 100644 --- a/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts +++ b/bindings/nodejs/examples/how_tos/account_wallet/transaction.ts @@ -54,11 +54,9 @@ async function run() { ); // Find first output unlockable by the account address - const queryParameters = [ - { - address: accountAddress, - }, - ]; + const queryParameters = { + address: accountAddress, + }; const input = ( await (await wallet.getClient()).basicOutputIds(queryParameters) ).items[0]; diff --git a/bindings/nodejs/examples/how_tos/client/get-outputs.ts b/bindings/nodejs/examples/how_tos/client/get-outputs.ts index ebbef29b82..0f58a6b84d 100644 --- a/bindings/nodejs/examples/how_tos/client/get-outputs.ts +++ b/bindings/nodejs/examples/how_tos/client/get-outputs.ts @@ -21,15 +21,13 @@ async function run() { try { // Get output ids of basic outputs that can be controlled by this address without further unlock constraints - const outputIdsResponse = await client.basicOutputIds([ - { - address: - 'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy', - }, - { hasExpiration: false }, - { hasTimelock: false }, - { hasStorageDepositReturn: false }, - ]); + const outputIdsResponse = await client.basicOutputIds({ + address: + 'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy', + hasExpiration: false, + hasTimelock: false, + hasStorageDepositReturn: false, + }); console.log('First output of query:'); console.log('ID: ', outputIdsResponse.items[0]); diff --git a/bindings/nodejs/lib/client/client.ts b/bindings/nodejs/lib/client/client.ts index c74553c68c..26e4eb1213 100644 --- a/bindings/nodejs/lib/client/client.ts +++ b/bindings/nodejs/lib/client/client.ts @@ -4,21 +4,21 @@ import { ClientMethodHandler } from './client-method-handler'; import { IClientOptions, - QueryParameter, PreparedTransactionData, INetworkInfo, INode, IAuth, - BasicOutputBuilderParams, AccountOutputBuilderParams, + BasicOutputBuilderParams, FoundryOutputBuilderParams, NftOutputBuilderParams, - FoundryQueryParameter, - NftQueryParameter, - AccountQueryParameter, - AnchorQueryParameter, - GenericQueryParameter, - DelegationQueryParameter, + AccountOutputQueryParameters, + AnchorOutputQueryParameters, + BasicOutputQueryParameters, + DelegationOutputQueryParameters, + FoundryOutputQueryParameters, + NftOutputQueryParameters, + OutputQueryParameters, } from '../types/client'; import type { INodeInfoWrapper } from '../types/client/nodeInfo'; import { @@ -100,38 +100,6 @@ export class Client { return JSON.parse(response).payload; } - /** - * Fetch alias/basic/NFT/foundry output IDs based on the given query parameters. - */ - async outputIds( - queryParameters: GenericQueryParameter[], - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'outputIds', - data: { - queryParameters, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Fetch basic output IDs based on the given query parameters. - */ - async basicOutputIds( - queryParameters: QueryParameter[], - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'basicOutputIds', - data: { - queryParameters, - }, - }); - - return JSON.parse(response).payload; - } - /** * Get output from a given output ID. */ @@ -571,186 +539,6 @@ export class Client { return JSON.parse(response).payload; } - /** - * Get the corresponding output IDs given a list of account query parameters. - * - * @param queryParameters An array of `AccountQueryParameter`s. - * @returns A paginated query response of corresponding output IDs. - */ - async accountOutputIds( - queryParameters: AccountQueryParameter[], - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'accountOutputIds', - data: { - queryParameters, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output ID from an account ID. - * - * @param accountId An account ID. - * @returns The corresponding output ID. - */ - async accountOutputId(accountId: AccountId): Promise { - const response = await this.methodHandler.callMethod({ - name: 'accountOutputId', - data: { - accountId, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output IDs given a list of anchor query parameters. - * - * @param queryParameters An array of `AnchorQueryParameter`s. - * @returns A paginated query response of corresponding output IDs. - */ - async anchorOutputIds( - queryParameters: AnchorQueryParameter[], - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'anchorOutputIds', - data: { - queryParameters, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output ID from an anchor ID. - * - * @param anchorId An anchor ID. - * @returns The corresponding output ID. - */ - async anchorOutputId(anchorId: AnchorId): Promise { - const response = await this.methodHandler.callMethod({ - name: 'anchorOutputId', - data: { - anchorId, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output IDs given a list of delegation query parameters. - * - * @param queryParameters An array of `DelegationQueryParameter`s. - * @returns A paginated query response of corresponding output IDs. - */ - async delegationOutputIds( - queryParameters: DelegationQueryParameter[], - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'delegationOutputIds', - data: { - queryParameters, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output ID from an delegation ID. - * - * @param delegationId A delegation ID. - * @returns The corresponding output ID. - */ - async delegationOutputId(delegationId: DelegationId): Promise { - const response = await this.methodHandler.callMethod({ - name: 'delegationOutputId', - data: { - delegationId, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output IDs given a list of Foundry query parameters. - * - * @param queryParameters An array of `FoundryQueryParameter`s. - * @returns A paginated query response of corresponding output IDs. - */ - async foundryOutputIds( - queryParameters: FoundryQueryParameter[], - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'foundryOutputIds', - data: { - queryParameters, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output ID from a Foundry ID. - * - * @param foundryId A Foundry ID. - * @returns The corresponding output ID. - */ - async foundryOutputId(foundryId: FoundryId): Promise { - const response = await this.methodHandler.callMethod({ - name: 'foundryOutputId', - data: { - foundryId, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output IDs given a list of NFT query parameters. - * - * @param queryParameters An array of `NftQueryParameter`s. - * @returns A paginated query response of corresponding output IDs. - */ - async nftOutputIds( - queryParameters: NftQueryParameter[], - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'nftOutputIds', - data: { - queryParameters, - }, - }); - - return JSON.parse(response).payload; - } - - /** - * Get the corresponding output ID from an NFT ID. - * - * @param nftId An NFT ID. - * @returns The corresponding output ID. - */ - async nftOutputId(nftId: NftId): Promise { - const response = await this.methodHandler.callMethod({ - name: 'nftOutputId', - data: { - nftId, - }, - }); - - return JSON.parse(response).payload; - } - /** * Get outputs from provided output IDs (requests are sent * in parallel and errors are ignored, can be useful for spent outputs) @@ -970,4 +758,218 @@ export class Client { return JSON.parse(response).payload; } + + // inx-indexer routes + + /** + * Fetch account/anchor/basic/delegation/NFT/foundry output IDs based on the given query parameters. + */ + async outputIds( + queryParameters: OutputQueryParameters, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'outputIds', + data: { + queryParameters, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Fetch basic output IDs based on the given query parameters. + */ + async basicOutputIds( + queryParameters: BasicOutputQueryParameters, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'basicOutputIds', + data: { + queryParameters, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output IDs given a list of account query parameters. + * + * @param outputQueryParameters `AccountOutputQueryParameters`. + * @returns A paginated query response of corresponding output IDs. + */ + async accountOutputIds( + queryParameters: AccountOutputQueryParameters, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'accountOutputIds', + data: { + queryParameters, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output ID from an account ID. + * + * @param accountId An account ID. + * @returns The corresponding output ID. + */ + async accountOutputId(accountId: AccountId): Promise { + const response = await this.methodHandler.callMethod({ + name: 'accountOutputId', + data: { + accountId, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output IDs given a list of anchor query parameters. + * + * @param outputQueryParameters `AnchorOutputQueryParameters`. + * @returns A paginated query response of corresponding output IDs. + */ + async anchorOutputIds( + queryParameters: AnchorOutputQueryParameters, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'anchorOutputIds', + data: { + queryParameters, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output ID from an anchor ID. + * + * @param anchorId An anchor ID. + * @returns The corresponding output ID. + */ + async anchorOutputId(anchorId: AnchorId): Promise { + const response = await this.methodHandler.callMethod({ + name: 'anchorOutputId', + data: { + anchorId, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output IDs given a list of delegation query parameters. + * + * @param outputQueryParameters `DelegationOutputQueryParameters`. + * @returns A paginated query response of corresponding output IDs. + */ + async delegationOutputIds( + queryParameters: DelegationOutputQueryParameters, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'delegationOutputIds', + data: { + queryParameters, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output ID from an delegation ID. + * + * @param delegationId A delegation ID. + * @returns The corresponding output ID. + */ + async delegationOutputId(delegationId: DelegationId): Promise { + const response = await this.methodHandler.callMethod({ + name: 'delegationOutputId', + data: { + delegationId, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output IDs given a list of Foundry query parameters. + * + * @param outputQueryParameters `FoundryOutputQueryParameters`. + * @returns A paginated query response of corresponding output IDs. + */ + async foundryOutputIds( + queryParameters: FoundryOutputQueryParameters, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'foundryOutputIds', + data: { + queryParameters, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output ID from a Foundry ID. + * + * @param foundryId A Foundry ID. + * @returns The corresponding output ID. + */ + async foundryOutputId(foundryId: FoundryId): Promise { + const response = await this.methodHandler.callMethod({ + name: 'foundryOutputId', + data: { + foundryId, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output IDs given a list of NFT query parameters. + * + * @param outputQueryParameters `NftOutputQueryParameters`. + * @returns A paginated query response of corresponding output IDs. + */ + async nftOutputIds( + queryParameters: NftOutputQueryParameters, + ): Promise { + const response = await this.methodHandler.callMethod({ + name: 'nftOutputIds', + data: { + queryParameters, + }, + }); + + return JSON.parse(response).payload; + } + + /** + * Get the corresponding output ID from an NFT ID. + * + * @param nftId An NFT ID. + * @returns The corresponding output ID. + */ + async nftOutputId(nftId: NftId): Promise { + const response = await this.methodHandler.callMethod({ + name: 'nftOutputId', + data: { + nftId, + }, + }); + + return JSON.parse(response).payload; + } } diff --git a/bindings/nodejs/lib/types/block/address.ts b/bindings/nodejs/lib/types/block/address.ts index 14e1308a86..748fa3a6b5 100644 --- a/bindings/nodejs/lib/types/block/address.ts +++ b/bindings/nodejs/lib/types/block/address.ts @@ -20,12 +20,12 @@ enum AddressType { Account = 8, /** An NFT address. */ Nft = 16, - /** An implicit account creation address. */ - ImplicitAccountCreation = 24, /** An Anchor address. */ - Anchor = 28, + Anchor = 24, + /** An implicit account creation address. */ + ImplicitAccountCreation = 32, /** An address with restricted capabilities. */ - Restricted = 40, + Restricted = 48, } /** @@ -62,13 +62,13 @@ abstract class Address { ) as any as AccountAddress; } else if (data.type == AddressType.Nft) { return plainToInstance(NftAddress, data) as any as NftAddress; + } else if (data.type == AddressType.Anchor) { + return plainToInstance(AnchorAddress, data) as any as AnchorAddress; } else if (data.type == AddressType.ImplicitAccountCreation) { return plainToInstance( ImplicitAccountCreationAddress, data, ) as any as ImplicitAccountCreationAddress; - } else if (data.type == AddressType.Anchor) { - return plainToInstance(AnchorAddress, data) as any as AnchorAddress; } else if (data.type == AddressType.Restricted) { return plainToInstance( RestrictedAddress, @@ -142,6 +142,27 @@ class NftAddress extends Address { } } +/** + * An Anchor address. + */ +class AnchorAddress extends Address { + /** + * The anchor ID. + */ + readonly anchorId: AnchorId; + /** + * @param address An anchor address as anchor ID. + */ + constructor(address: AnchorId) { + super(AddressType.Anchor); + this.anchorId = address; + } + + toString(): string { + return this.anchorId; + } +} + /** * An implicit account creation address that can be used to convert a Basic Output to an Account Output. */ @@ -164,27 +185,6 @@ class ImplicitAccountCreationAddress extends Address { } } -/** - * An Anchor address. - */ -class AnchorAddress extends Address { - /** - * The anchor ID. - */ - readonly anchorId: AnchorId; - /** - * @param address An anchor address as anchor ID. - */ - constructor(address: AnchorId) { - super(AddressType.Anchor); - this.anchorId = address; - } - - toString(): string { - return this.anchorId; - } -} - const RestrictedAddressDiscriminator = { property: 'type', subTypes: [ @@ -255,11 +255,11 @@ const AddressDiscriminator = { { value: Ed25519Address, name: AddressType.Ed25519 as any }, { value: AccountAddress, name: AddressType.Account as any }, { value: NftAddress, name: AddressType.Nft as any }, + { value: AnchorAddress, name: AddressType.Anchor as any }, { value: ImplicitAccountCreationAddress, name: AddressType.ImplicitAccountCreation as any, }, - { value: AnchorAddress, name: AddressType.Anchor as any }, { value: RestrictedAddress, name: AddressType.Restricted as any }, ], }; @@ -273,4 +273,6 @@ export { AccountAddress, NftAddress, AnchorAddress, + ImplicitAccountCreationAddress, + RestrictedAddress, }; diff --git a/bindings/nodejs/lib/types/block/output/output.ts b/bindings/nodejs/lib/types/block/output/output.ts index 95bfdd45af..fb2fe10cb1 100644 --- a/bindings/nodejs/lib/types/block/output/output.ts +++ b/bindings/nodejs/lib/types/block/output/output.ts @@ -25,14 +25,14 @@ enum OutputType { Basic = 0, /** An Account output. */ Account = 1, + /** An Anchor output. */ + Anchor = 2, /** A Foundry output. */ - Foundry = 2, + Foundry = 3, /** An NFT output. */ - Nft = 3, + Nft = 4, /** A Delegation output. */ - Delegation = 4, - /** An Anchor output. */ - Anchor = 5, + Delegation = 5, } /** @@ -74,6 +74,8 @@ abstract class Output { return plainToInstance(BasicOutput, data) as any as BasicOutput; } else if (data.type == OutputType.Account) { return plainToInstance(AccountOutput, data) as any as AccountOutput; + } else if (data.type == OutputType.Anchor) { + return plainToInstance(AnchorOutput, data) as any as AnchorOutput; } else if (data.type == OutputType.Foundry) { return plainToInstance(FoundryOutput, data) as any as FoundryOutput; } else if (data.type == OutputType.Nft) { @@ -83,8 +85,6 @@ abstract class Output { DelegationOutput, data, ) as any as DelegationOutput; - } else if (data.type == OutputType.Anchor) { - return plainToInstance(AnchorOutput, data) as any as AnchorOutput; } throw new Error('Invalid JSON'); } @@ -144,6 +144,7 @@ abstract class CommonOutput extends Output { return this.nativeTokens; } } + /** * A Basic output. */ @@ -272,71 +273,73 @@ class AnchorOutput extends ImmutableFeaturesOutput { } /** - * An NFT output. + * A Foundry output. */ -class NftOutput extends ImmutableFeaturesOutput { +class FoundryOutput extends ImmutableFeaturesOutput { /** - * Unique identifier of the NFT, which is the BLAKE2b-256 hash of the Output ID that created it. - * Unless its newly minted, then the id is zeroed. + * The serial number of the Foundry with respect to the controlling alias. */ - readonly nftId: NftId; + readonly serialNumber: number; /** - * The amount of (stored) Mana held by the output. + * The token scheme for the Foundry. */ - readonly mana: u64; + @Type(() => TokenScheme, { + discriminator: TokenSchemeDiscriminator, + }) + readonly tokenScheme: TokenScheme; /** * @param amount The amount of the output. - * @param mana The amount of stored mana. - * @param nftId The NFT ID as hex-encoded string. + * @param serialNumber The serial number of the Foundry with respect to the controlling alias. * @param unlockConditions The unlock conditions of the output. + * @param tokenScheme The token scheme for the Foundry. */ constructor( amount: u64, - mana: u64, - nftId: NftId, + serialNumber: number, unlockConditions: UnlockCondition[], + tokenScheme: TokenScheme, ) { - super(OutputType.Nft, amount, unlockConditions); - this.nftId = nftId; - this.mana = mana; + super(OutputType.Foundry, amount, unlockConditions); + this.serialNumber = serialNumber; + this.tokenScheme = tokenScheme; } } + /** - * A Foundry output. + * An NFT output. */ -class FoundryOutput extends ImmutableFeaturesOutput { +class NftOutput extends ImmutableFeaturesOutput { /** - * The serial number of the Foundry with respect to the controlling alias. + * Unique identifier of the NFT, which is the BLAKE2b-256 hash of the Output ID that created it. + * Unless its newly minted, then the id is zeroed. */ - readonly serialNumber: number; + readonly nftId: NftId; /** - * The token scheme for the Foundry. + * The amount of (stored) Mana held by the output. */ - @Type(() => TokenScheme, { - discriminator: TokenSchemeDiscriminator, - }) - readonly tokenScheme: TokenScheme; + readonly mana: u64; /** * @param amount The amount of the output. - * @param serialNumber The serial number of the Foundry with respect to the controlling alias. + * @param mana The amount of stored mana. + * @param nftId The NFT ID as hex-encoded string. * @param unlockConditions The unlock conditions of the output. - * @param tokenScheme The token scheme for the Foundry. */ constructor( amount: u64, - serialNumber: number, + mana: u64, + nftId: NftId, unlockConditions: UnlockCondition[], - tokenScheme: TokenScheme, ) { - super(OutputType.Foundry, amount, unlockConditions); - this.serialNumber = serialNumber; - this.tokenScheme = tokenScheme; + super(OutputType.Nft, amount, unlockConditions); + this.nftId = nftId; + this.mana = mana; } } + /** * A Delegation output. */ @@ -402,8 +405,9 @@ const OutputDiscriminator = { subTypes: [ { value: BasicOutput, name: OutputType.Basic as any }, { value: AccountOutput, name: OutputType.Account as any }, - { value: NftOutput, name: OutputType.Nft as any }, + { value: AnchorOutput, name: OutputType.Anchor as any }, { value: FoundryOutput, name: OutputType.Foundry as any }, + { value: NftOutput, name: OutputType.Nft as any }, { value: DelegationOutput, name: OutputType.Delegation as any }, ], }; @@ -416,7 +420,7 @@ export { BasicOutput, AccountOutput, AnchorOutput, - NftOutput, FoundryOutput, + NftOutput, DelegationOutput, }; diff --git a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts index 0df204647d..de2107e7d2 100644 --- a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts +++ b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts @@ -21,13 +21,13 @@ enum UnlockType { */ Account = 2, /** - * An NFT unlock. + * An Anchor unlock. */ - Nft = 3, + Anchor = 3, /** - * An Anchor unlock. + * An NFT unlock. */ - Anchor = 4, + Nft = 4, } /** @@ -104,9 +104,9 @@ class AccountUnlock extends Unlock { } /** - * An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to. + * An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to. */ -class NftUnlock extends Unlock { +class AnchorUnlock extends Unlock { /** * The reference. */ @@ -116,15 +116,15 @@ class NftUnlock extends Unlock { * @param reference An index referencing a previous unlock. */ constructor(reference: number) { - super(UnlockType.Nft); + super(UnlockType.Anchor); this.reference = reference; } } /** - * An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to. + * An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to. */ -class AnchorUnlock extends Unlock { +class NftUnlock extends Unlock { /** * The reference. */ @@ -134,7 +134,7 @@ class AnchorUnlock extends Unlock { * @param reference An index referencing a previous unlock. */ constructor(reference: number) { - super(UnlockType.Anchor); + super(UnlockType.Nft); this.reference = reference; } } @@ -154,14 +154,14 @@ const UnlockDiscriminator = { value: AccountUnlock, name: UnlockType.Account as any, }, - { - value: NftUnlock, - name: UnlockType.Nft as any, - }, { value: AnchorUnlock, name: UnlockType.Anchor as any, }, + { + value: NftUnlock, + name: UnlockType.Nft as any, + }, ], }; @@ -171,7 +171,7 @@ export { SignatureUnlock, ReferenceUnlock, AccountUnlock, - NftUnlock, AnchorUnlock, + NftUnlock, UnlockDiscriminator, }; diff --git a/bindings/nodejs/lib/types/client/bridge/client.ts b/bindings/nodejs/lib/types/client/bridge/client.ts index 0837c9f808..913a5500f9 100644 --- a/bindings/nodejs/lib/types/client/bridge/client.ts +++ b/bindings/nodejs/lib/types/client/bridge/client.ts @@ -20,13 +20,13 @@ import type { } from '../../block'; import type { PreparedTransactionData } from '../prepared-transaction-data'; import type { - AccountQueryParameter, - AnchorQueryParameter, - FoundryQueryParameter, - GenericQueryParameter, - NftQueryParameter, - QueryParameter, - DelegationQueryParameter, + AccountOutputQueryParameters, + AnchorOutputQueryParameters, + BasicOutputQueryParameters, + DelegationOutputQueryParameters, + FoundryOutputQueryParameters, + NftOutputQueryParameters, + OutputQueryParameters, } from '../query-parameters'; import type { IAuth } from '../network'; import type { BasicOutputBuilderParams } from '../output_builder_params/basic-output-params'; @@ -47,20 +47,6 @@ export interface __GetOutputMethod__ { }; } -export interface __GetOutputIdsMethod__ { - name: 'outputIds'; - data: { - queryParameters: GenericQueryParameter[]; - }; -} - -export interface __GetBasicOutputIdsMethod__ { - name: 'basicOutputIds'; - data: { - queryParameters: QueryParameter[]; - }; -} - export interface __GetOutputsMethod__ { name: 'getOutputs'; data: { @@ -225,76 +211,6 @@ export interface __HexPublicKeyToBech32AddressMethod__ { }; } -export interface __AccountOutputIdsMethod__ { - name: 'accountOutputIds'; - data: { - queryParameters: AccountQueryParameter[]; - }; -} - -export interface __AccountOutputIdMethod__ { - name: 'accountOutputId'; - data: { - accountId: AccountId; - }; -} - -export interface __AnchorOutputIdsMethod__ { - name: 'anchorOutputIds'; - data: { - queryParameters: AnchorQueryParameter[]; - }; -} - -export interface __AnchorOutputIdMethod__ { - name: 'anchorOutputId'; - data: { - anchorId: AnchorId; - }; -} - -export interface __DelegationOutputIdsMethod__ { - name: 'delegationOutputIds'; - data: { - queryParameters: DelegationQueryParameter[]; - }; -} - -export interface __DelegationOutputIdMethod__ { - name: 'delegationOutputId'; - data: { - delegationId: DelegationId; - }; -} - -export interface __FoundryOutputIdsMethod__ { - name: 'foundryOutputIds'; - data: { - queryParameters: FoundryQueryParameter[]; - }; -} - -export interface __FoundryOutputIdMethod__ { - name: 'foundryOutputId'; - data: { - foundryId: FoundryId; - }; -} - -export interface __NftOutputIdsMethod__ { - name: 'nftOutputIds'; - data: { - queryParameters: NftQueryParameter[]; - }; -} - -export interface __NftOutputIdMethod__ { - name: 'nftOutputId'; - data: { - nftId: NftId; - }; -} - export interface __GetOutputsIgnoreErrorsMethod__ { name: 'getOutputsIgnoreErrors'; data: { @@ -365,3 +281,89 @@ export type __CallPluginRouteMethod__ = { request?: string; }; }; + +// inx-indexer methods + +export interface __GetOutputIdsMethod__ { + name: 'outputIds'; + data: { + queryParameters: OutputQueryParameters; + }; +} + +export interface __GetBasicOutputIdsMethod__ { + name: 'basicOutputIds'; + data: { + queryParameters: BasicOutputQueryParameters; + }; +} + +export interface __AccountOutputIdsMethod__ { + name: 'accountOutputIds'; + data: { + queryParameters: AccountOutputQueryParameters; + }; +} + +export interface __AccountOutputIdMethod__ { + name: 'accountOutputId'; + data: { + accountId: AccountId; + }; +} + +export interface __AnchorOutputIdsMethod__ { + name: 'anchorOutputIds'; + data: { + queryParameters: AnchorOutputQueryParameters; + }; +} + +export interface __AnchorOutputIdMethod__ { + name: 'anchorOutputId'; + data: { + anchorId: AnchorId; + }; +} + +export interface __DelegationOutputIdsMethod__ { + name: 'delegationOutputIds'; + data: { + queryParameters: DelegationOutputQueryParameters; + }; +} + +export interface __DelegationOutputIdMethod__ { + name: 'delegationOutputId'; + data: { + delegationId: DelegationId; + }; +} + +export interface __FoundryOutputIdsMethod__ { + name: 'foundryOutputIds'; + data: { + queryParameters: FoundryOutputQueryParameters; + }; +} + +export interface __FoundryOutputIdMethod__ { + name: 'foundryOutputId'; + data: { + foundryId: FoundryId; + }; +} + +export interface __NftOutputIdsMethod__ { + name: 'nftOutputIds'; + data: { + queryParameters: NftOutputQueryParameters; + }; +} + +export interface __NftOutputIdMethod__ { + name: 'nftOutputId'; + data: { + nftId: NftId; + }; +} diff --git a/bindings/nodejs/lib/types/client/query-parameters.ts b/bindings/nodejs/lib/types/client/query-parameters.ts index 7dcf40375e..29c9cab157 100644 --- a/bindings/nodejs/lib/types/client/query-parameters.ts +++ b/bindings/nodejs/lib/types/client/query-parameters.ts @@ -2,187 +2,162 @@ // SPDX-License-Identifier: Apache-2.0 import { SlotIndex } from '../block/slot'; -import { Bech32Address } from '../block'; +import { Bech32Address, TokenId } from '../block'; +import { HexEncodedString } from '../utils/hex-encoding'; /** - * Query parameter for filtering output requests + * Common query parameters for output requests. */ -export type QueryParameter = - | Address - | AccountAddress - | HasStorageDepositReturn - | StorageDepositReturnAddress - | HasTimelock - | TimelockedBefore - | TimelockedAfter - | HasExpiration - | ExpiresBefore - | ExpiresAfter - | ExpirationReturnAddress - | Sender - | Tag - | Issuer - | StateController - | Governor - | UnlockableByAddress - | CommonQueryParameters; - -/** Query parameters for filtering Account Outputs */ -export type AccountQueryParameter = - | Address - | Issuer - | Sender - | UnlockableByAddress - | CommonQueryParameters; - -/** Query parameters for filtering Anchor Outputs */ -// TODO https://github.com/iotaledger/iota-sdk/issues/1503 -export type AnchorQueryParameter = any; - -/** Query parameters for filtering Delegation Outputs */ -// TODO https://github.com/iotaledger/iota-sdk/issues/1503 -export type DelegationQueryParameter = any; - -/** Query parameters for filtering Foundry Outputs */ -export type FoundryQueryParameter = AccountAddress | CommonQueryParameters; - -/** Query parameters for filtering Nft Outputs */ -export type NftQueryParameter = - | Address - | HasStorageDepositReturn - | StorageDepositReturnAddress - | HasTimelock - | TimelockedBefore - | TimelockedAfter - | HasExpiration - | ExpiresBefore - | ExpiresAfter - | ExpirationReturnAddress - | Issuer - | Sender - | Tag - | UnlockableByAddress - | CommonQueryParameters; - -/** Shared query parameters*/ -type CommonQueryParameters = - | HasNativeTokens - | MinNativeTokenCount - | MaxNativeTokenCount - | CreatedAfter - | CreatedBefore - | PageSize - | Cursor; - -/** Query parameters for filtering alias/basic/NFT/foundry Outputs*/ -export type GenericQueryParameter = - | UnlockableByAddress - | HasNativeTokens - | MinNativeTokenCount - | MaxNativeTokenCount - | CreatedAfter - | CreatedBefore - | PageSize - | Cursor; - -/** Bech32-encoded address that should be searched for. */ -interface Address { - address: Bech32Address; -} -/** Filter foundry outputs based on bech32-encoded address of the controlling account. */ -interface AccountAddress { - accountAddress: Bech32Address; +export interface CommonOutputQueryParameters { + /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is + /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. + pageSize?: number; + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty string is provided, only + /// the first page is returned. + cursor?: string; + /// Returns outputs that were created before a certain slot index. + createdBefore?: SlotIndex; + /// Returns outputs that were created after a certain slot index. + createdAfter?: SlotIndex; } -/** Filters outputs based on the presence of storage deposit return unlock condition. */ -interface HasStorageDepositReturn { - hasStorageDepositReturn: boolean; -} -/** Filter outputs based on the presence of a specific Bech32-encoded return address - * in the storage deposit return unlock condition. + +/** + * Query parameters for output requests. */ -interface StorageDepositReturnAddress { - storageDepositReturnAddress: Bech32Address; -} -/** Filters outputs based on the presence of timelock unlock condition. */ -interface HasTimelock { - hasTimelock: boolean; -} -/** Return outputs that are timelocked before a certain slot index. */ -interface TimelockedBefore { - timelockedBefore: SlotIndex; -} -/** Return outputs that are timelocked after a certain slot index. */ -interface TimelockedAfter { - timelockedAfter: SlotIndex; +export interface OutputQueryParameters extends CommonOutputQueryParameters { + /// Filters outputs based on the presence of a native token. + hasNativeToken?: boolean; + /// Filters outputs based on the presence of a specific native token. + nativeToken?: TokenId; + /// Returns outputs that are unlockable by the bech32 address. + unlockableByAddress?: Bech32Address; } -/** Filters outputs based on the presence of expiration unlock condition. */ -interface HasExpiration { - hasExpiration: boolean; -} -/** Filters outputs based on the presence of native tokens. */ -interface HasNativeTokens { - hasNativeTokens: boolean; -} -/** Filters outputs that have at most a certain number of distinct native tokens. */ -interface MaxNativeTokenCount { - maxNativeTokenCount: number; -} -/** Filters outputs that have at least a certain number of distinct native tokens. */ -interface MinNativeTokenCount { - minNativeTokenCount: number; -} -/** Return outputs that expire before a certain slot index. */ -interface ExpiresBefore { - expiresBefore: SlotIndex; -} -/** Return outputs that expire after a certain slot index. */ -interface ExpiresAfter { - expiresAfter: SlotIndex; -} -/** Filter outputs based on the presence of a specific Bech32-encoded return - * address in the expiration unlock condition. - * */ -interface ExpirationReturnAddress { - expirationReturnAddress: Bech32Address; -} -/** Filter for a certain sender */ -interface Sender { - sender: string; -} -/** Filter for a certain tag */ -interface Tag { - tag: string; -} -/** Return outputs that were created before a certain slot index. */ -interface CreatedBefore { - createdBefore: SlotIndex; -} -/** Return outputs that were created after a certain slot index. */ -interface CreatedAfter { - createdAfter: SlotIndex; -} -/** Pass the cursor(confirmationMS+outputId.pageSize) to start the results from */ -interface Cursor { - cursor: string; +/** + * Query parameters for basic output requests. + */ +export interface BasicOutputQueryParameters + extends CommonOutputQueryParameters { + /// Filters outputs based on the presence of a native token. + hasNativeToken?: boolean; + /// Filters outputs based on the presence of a specific native token. + nativeToken?: TokenId; + /// Returns outputs that are unlockable by the bech32 address. + unlockableByAddress?: Bech32Address; + /// Bech32-encoded address that should be searched for. + address?: Bech32Address; + /// Filters outputs based on the presence of storage deposit return unlock condition. + hasStorageDepositReturn?: boolean; + /// Filters outputs based on the presence of a specific return address in the storage deposit return unlock + /// condition. + storageDepositReturnAddress?: Bech32Address; + /// Filters outputs based on the presence of expiration unlock condition. + hasExpiration?: boolean; + /// Filters outputs based on the presence of a specific Bech32-encoded return address in the expiration unlock + /// condition. + expirationReturnAddress?: Bech32Address; + /// Returns outputs that expire before a certain slot index. + expiresBefore?: SlotIndex; + /// Returns outputs that expire after a certain slot index. + expiresAfter?: SlotIndex; + /// Filters outputs based on the presence of timelock unlock condition. + hasTimelock?: boolean; + /// Returns outputs that are timelocked before a certain slot index. + timelockedBefore?: SlotIndex; + /// Returns outputs that are timelocked after a certain slot index. + timelockedAfter?: SlotIndex; + /// Filters outputs based on the presence of validated Sender (bech32 encoded). + sender?: Bech32Address; + /// Filters outputs based on matching Tag Block. + tag?: HexEncodedString; } -/** Filter for a certain issuer */ -interface Issuer { - issuer: string; + +/** + * Query parameters for account output requests. + */ +export interface AccountOutputQueryParameters + extends CommonOutputQueryParameters { + /// Bech32-encoded address that should be searched for. + address?: Bech32Address; + /// Filters outputs based on bech32-encoded issuer address. + issuer?: Bech32Address; + /// Filters outputs based on the presence of validated Sender (bech32 encoded). + sender?: Bech32Address; } -/** Filter outputs based on bech32-encoded state controller address. */ -interface StateController { - stateController: Bech32Address; + +/** + * Query parameters for anchor output requests. + */ +export interface AnchorOutputQueryParameters + extends CommonOutputQueryParameters { + /// Returns outputs that are unlockable by the bech32 address. + unlockableByAddress?: Bech32Address; + /// Filters outputs based on bech32-encoded state controller address. + stateController?: Bech32Address; + /// Filters outputs based on bech32-encoded governor (governance controller) address. + governor?: Bech32Address; + /// Filters outputs based on bech32-encoded issuer address. + issuer?: Bech32Address; + /// Filters outputs based on the presence of validated Sender (bech32 encoded). + sender?: Bech32Address; } -/** Filter outputs based on bech32-encoded governor (governance controller) address. */ -interface Governor { - governor: Bech32Address; + +/** + * Query parameters for delegation output requests. + */ +export interface DelegationOutputQueryParameters + extends CommonOutputQueryParameters { + /// Bech32-encoded address that should be searched for. + address?: Bech32Address; + /// Filter foundry outputs based on bech32-encoded address of the validator. + validator?: Bech32Address; } -/** Define the page size for the results. */ -interface PageSize { - pageSize: number; + +/** + * Query parameters for foundry output requests. + */ +export interface FoundryOutputQueryParameters + extends CommonOutputQueryParameters { + /// Filters outputs based on the presence of a native token. + hasNativeToken?: boolean; + /// Filters outputs based on the presence of a specific native token. + nativeToken?: TokenId; + /// Filter foundry outputs based on bech32-encoded address of the controlling account. + account?: Bech32Address; } -/** Returns outputs that are unlockable by the bech32 address. */ -interface UnlockableByAddress { - unlockableByAddress: Bech32Address; + +/** + * Query parameters for NFT output requests. + */ +export interface NftOutputQueryParameters extends CommonOutputQueryParameters { + /// Returns outputs that are unlockable by the bech32 address. + unlockableByAddress?: Bech32Address; + /// Bech32-encoded address that should be searched for. + address?: Bech32Address; + /// Filters outputs based on the presence of storage deposit return unlock condition. + hasStorageDepositReturn?: boolean; + /// Filters outputs based on the presence of a specific return address in the storage deposit return unlock + /// condition. + storageDepositReturnAddress?: Bech32Address; + /// Filters outputs based on the presence of expiration unlock condition. + hasExpiration?: boolean; + /// Filters outputs based on the presence of a specific Bech32-encoded return address in the expiration unlock + /// condition. + expirationReturnAddress?: Bech32Address; + /// Returns outputs that expire before a certain slot index. + expiresBefore?: SlotIndex; + /// Returns outputs that expire after a certain slot index. + expiresAfter?: SlotIndex; + /// Filters outputs based on the presence of timelock unlock condition. + hasTimelock?: boolean; + /// Returns outputs that are timelocked before a certain slot index. + timelockedBefore?: SlotIndex; + /// Returns outputs that are timelocked after a certain slot index. + timelockedAfter?: SlotIndex; + /// Filters outputs based on bech32-encoded issuer address. + issuer?: Bech32Address; + /// Filters outputs based on the presence of validated Sender (bech32 encoded). + sender?: Bech32Address; + /// Filters outputs based on matching Tag Block. + tag?: HexEncodedString; } diff --git a/bindings/python/iota_sdk/types/address.py b/bindings/python/iota_sdk/types/address.py index f59818d7a7..4a12c3d75e 100644 --- a/bindings/python/iota_sdk/types/address.py +++ b/bindings/python/iota_sdk/types/address.py @@ -14,16 +14,17 @@ class AddressType(IntEnum): ED25519 (0): Ed25519 address. ACCOUNT (8): Account address. NFT (16): Nft address. - IMPLICIT_ACCOUNT_CREATION (24): Implicit Account Creation address. - RESTRICTED (40): Address with restricted capabilities. - ANCHOR (48): Anchor address. + ANCHOR (24): Anchor address. + IMPLICIT_ACCOUNT_CREATION (32): Implicit Account Creation address. + RESTRICTED (48): Address with restricted capabilities. + """ ED25519 = 0 ACCOUNT = 8 NFT = 16 - IMPLICIT_ACCOUNT_CREATION = 24 - RESTRICTED = 40 - ANCHOR = 48 + ANCHOR = 24 + IMPLICIT_ACCOUNT_CREATION = 32 + RESTRICTED = 48 @json @@ -65,6 +66,20 @@ class NFTAddress: type: int = field(default_factory=lambda: int(AddressType.NFT), init=False) +@json +@dataclass +class AnchorAddress: + """Represents an Anchor address. + Attributes: + anchor_id: The hex encoded anchor id. + """ + anchor_id: HexStr + type: int = field( + default_factory=lambda: int( + AddressType.ANCHOR), + init=False) + + @json @dataclass class ImplicitAccountCreationAddress: @@ -115,20 +130,6 @@ def with_allowed_capabilities(self, capabilities: bytes): self.allowed_capabilities = '0x' + capabilities.hex() -@json -@dataclass -class AnchorAddress: - """Represents an Anchor address. - Attributes: - anchor_id: The hex encoded anchor id. - """ - anchor_id: HexStr - type: int = field( - default_factory=lambda: int( - AddressType.ANCHOR), - init=False) - - @json @dataclass class AddressWithUnspentOutputs(): @@ -140,8 +141,12 @@ class AddressWithUnspentOutputs(): output_ids: bool -Address: TypeAlias = Union[Ed25519Address, AccountAddress, - NFTAddress, ImplicitAccountCreationAddress, RestrictedAddress, AnchorAddress] +Address: TypeAlias = Union[Ed25519Address, + AccountAddress, + NFTAddress, + AnchorAddress, + ImplicitAccountCreationAddress, + RestrictedAddress] def deserialize_address(d: Dict[str, Any]) -> Address: @@ -158,12 +163,12 @@ def deserialize_address(d: Dict[str, Any]) -> Address: return AccountAddress.from_dict(d) if address_type == AddressType.NFT: return NFTAddress.from_dict(d) + if address_type == AddressType.ANCHOR: + return AnchorAddress.from_dict(d) if address_type == AddressType.IMPLICIT_ACCOUNT_CREATION: return ImplicitAccountCreationAddress.from_dict(d) if address_type == AddressType.RESTRICTED: return RestrictedAddress.from_dict(d) - if address_type == AddressType.ANCHOR: - return AnchorAddress.from_dict(d) raise Exception(f'invalid address type: {address_type}') diff --git a/bindings/python/iota_sdk/types/output.py b/bindings/python/iota_sdk/types/output.py index 1208b47534..92769c780a 100644 --- a/bindings/python/iota_sdk/types/output.py +++ b/bindings/python/iota_sdk/types/output.py @@ -19,17 +19,18 @@ class OutputType(IntEnum): Attributes: Basic (0): A basic output. Account (1): An account output. - Foundry (2): A foundry output. - Nft (3): An NFT output. - Delegation (4): A delegation output. - Anchor (5): An anchor output. + Anchor (2): An anchor output. + Foundry (3): A foundry output. + Nft (4): An NFT output. + Delegation (5): A delegation output. + """ Basic = 0 Account = 1 - Foundry = 2 - Nft = 3 - Delegation = 4 - Anchor = 5 + Anchor = 2 + Foundry = 3 + Nft = 4 + Delegation = 5 @json @@ -304,8 +305,12 @@ class DelegationOutput: OutputType.Delegation), init=False) -Output: TypeAlias = Union[BasicOutput, AccountOutput, - FoundryOutput, NftOutput, DelegationOutput, AnchorOutput] +Output: TypeAlias = Union[BasicOutput, + AccountOutput, + AnchorOutput, + FoundryOutput, + NftOutput, + DelegationOutput] def deserialize_output(d: Dict[str, Any]) -> Output: @@ -320,14 +325,14 @@ def deserialize_output(d: Dict[str, Any]) -> Output: return BasicOutput.from_dict(d) if output_type == OutputType.Account: return AccountOutput.from_dict(d) + if output_type == OutputType.Anchor: + return AnchorOutput.from_dict(d) if output_type == OutputType.Foundry: return FoundryOutput.from_dict(d) if output_type == OutputType.Nft: return NftOutput.from_dict(d) if output_type == OutputType.Delegation: return DelegationOutput.from_dict(d) - if output_type == OutputType.Anchor: - return AnchorOutput.from_dict(d) raise Exception(f'invalid output type: {output_type}') diff --git a/bindings/python/iota_sdk/types/unlock.py b/bindings/python/iota_sdk/types/unlock.py index 3e71581e2c..4118ec5466 100644 --- a/bindings/python/iota_sdk/types/unlock.py +++ b/bindings/python/iota_sdk/types/unlock.py @@ -16,14 +16,15 @@ class UnlockType(IntEnum): Signature (0): An unlock holding a signature unlocking one or more inputs. Reference (1): An unlock which must reference a previous unlock which unlocks also the input at the same index as this Reference Unlock. Account (2): An unlock which must reference a previous unlock which unlocks the account that the input is locked to. - Nft (3): An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to. - Anchor (4): An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to. + Anchor (3): An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to. + Nft (4): An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to. + """ Signature = 0 Reference = 1 Account = 2 - Nft = 3 - Anchor = 4 + Anchor = 3 + Nft = 4 @json @@ -70,15 +71,6 @@ class AccountUnlock: init=False) -@json -@dataclass -class NftUnlock: - """An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to. - """ - reference: int - type: int = field(default_factory=lambda: int(UnlockType.Nft), init=False) - - @json @dataclass class AnchorUnlock: @@ -91,8 +83,20 @@ class AnchorUnlock: init=False) +@json +@dataclass +class NftUnlock: + """An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to. + """ + reference: int + type: int = field(default_factory=lambda: int(UnlockType.Nft), init=False) + + Unlock: TypeAlias = Union[SignatureUnlock, - ReferenceUnlock, AccountUnlock, NftUnlock, AnchorUnlock] + ReferenceUnlock, + AccountUnlock, + AnchorUnlock, + NftUnlock] def deserialize_unlock(d: Dict[str, Any]) -> Unlock: @@ -109,10 +113,10 @@ def deserialize_unlock(d: Dict[str, Any]) -> Unlock: return ReferenceUnlock.from_dict(d) if unlock_type == UnlockType.Account: return AccountUnlock.from_dict(d) - if unlock_type == UnlockType.Nft: - return NftUnlock.from_dict(d) if unlock_type == UnlockType.Anchor: return AnchorUnlock.from_dict(d) + if unlock_type == UnlockType.Nft: + return NftUnlock.from_dict(d) raise Exception(f'invalid unlock type: {unlock_type}') diff --git a/bindings/python/tests/test_output.py b/bindings/python/tests/test_output.py index 9964d70b68..dabdffb0c9 100644 --- a/bindings/python/tests/test_output.py +++ b/bindings/python/tests/test_output.py @@ -169,7 +169,7 @@ def test_output(): assert account_output.to_dict() == account_output_dict foundry_output_dict = { - "type": 2, + "type": 3, "amount": "54700", "serialNumber": 1, "tokenScheme": { @@ -198,7 +198,7 @@ def test_output(): assert foundry_output.to_dict() == foundry_output_dict nft_output_dict = { - "type": 3, + "type": 4, "mana": "47800", "amount": "47800", "nftId": "0x90e84936bd0cffd1595d2a58f63b1a8d0d3e333ed893950a5f3f0043c6e59ec1", diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs b/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs index 65daa9618a..c3a4d097a9 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs +++ b/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs @@ -250,10 +250,10 @@ impl InputSelection { Output::Account(output) => AccountOutputBuilder::from(&*output) .with_amount(new_amount) .finish_output(self.protocol_parameters.token_supply())?, - Output::Nft(output) => NftOutputBuilder::from(&*output) + Output::Foundry(output) => FoundryOutputBuilder::from(&*output) .with_amount(new_amount) .finish_output(self.protocol_parameters.token_supply())?, - Output::Foundry(output) => FoundryOutputBuilder::from(&*output) + Output::Nft(output) => NftOutputBuilder::from(&*output) .with_amount(new_amount) .finish_output(self.protocol_parameters.token_supply())?, _ => panic!("only account, nft and foundry can be automatically created"), diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/mod.rs b/sdk/src/client/api/block_builder/input_selection/requirement/mod.rs index 599e713b22..9da2517062 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/mod.rs +++ b/sdk/src/client/api/block_builder/input_selection/requirement/mod.rs @@ -78,18 +78,6 @@ impl InputSelection { is_created } - // Add an nft requirement if the nft output is transitioning and then required in the inputs. - Output::Nft(nft_output) => { - let is_created = nft_output.nft_id().is_null(); - - if !is_created { - let requirement = Requirement::Nft(*nft_output.nft_id()); - log::debug!("Adding {requirement:?} from output"); - self.requirements.push(requirement); - } - - is_created - } // Add a foundry requirement if the foundry output is transitioning and then required in the inputs. // Also add an account requirement since the associated account output needs to be transitioned. Output::Foundry(foundry_output) => { @@ -114,6 +102,18 @@ impl InputSelection { is_created } + // Add an nft requirement if the nft output is transitioning and then required in the inputs. + Output::Nft(nft_output) => { + let is_created = nft_output.nft_id().is_null(); + + if !is_created { + let requirement = Requirement::Nft(*nft_output.nft_id()); + log::debug!("Adding {requirement:?} from output"); + self.requirements.push(requirement); + } + + is_created + } _ => false, }; diff --git a/sdk/src/client/api/block_builder/input_selection/transition.rs b/sdk/src/client/api/block_builder/input_selection/transition.rs index 84213bb246..44141ff90c 100644 --- a/sdk/src/client/api/block_builder/input_selection/transition.rs +++ b/sdk/src/client/api/block_builder/input_selection/transition.rs @@ -152,8 +152,8 @@ impl InputSelection { pub(crate) fn transition_input(&mut self, input: &InputSigningData) -> Result, Error> { match &input.output { Output::Account(account_input) => self.transition_account_input(account_input, input.output_id()), - Output::Nft(nft_input) => self.transition_nft_input(nft_input, input.output_id()), Output::Foundry(foundry_input) => self.transition_foundry_input(foundry_input, input.output_id()), + Output::Nft(nft_input) => self.transition_nft_input(nft_input, input.output_id()), _ => Ok(None), } } diff --git a/sdk/src/client/node_api/indexer/query_parameters.rs b/sdk/src/client/node_api/indexer/query_parameters.rs index 5f63a6cacd..8027cea872 100644 --- a/sdk/src/client/node_api/indexer/query_parameters.rs +++ b/sdk/src/client/node_api/indexer/query_parameters.rs @@ -71,7 +71,8 @@ pub struct OutputQueryParameters { /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. page_size: Option, - /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty String is provided, only + /// the first page is returned. cursor: Option, /// Returns outputs that were created before a certain slot index. created_before: Option, @@ -121,7 +122,8 @@ pub struct BasicOutputQueryParameters { /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. page_size: Option, - /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty String is provided, only + /// the first page is returned. cursor: Option, /// Returns outputs that were created before a certain slot index. created_before: Option, @@ -157,7 +159,8 @@ pub struct AccountOutputQueryParameters { /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. page_size: Option, - /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty String is provided, only + /// the first page is returned. cursor: Option, /// Returns outputs that were created before a certain slot index. created_before: Option, @@ -185,7 +188,8 @@ pub struct AnchorOutputQueryParameters { /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. page_size: Option, - /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty String is provided, only + /// the first page is returned. cursor: Option, /// Returns outputs that were created before a certain slot index. created_before: Option, @@ -207,7 +211,8 @@ pub struct DelegationOutputQueryParameters { /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. page_size: Option, - /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty String is provided, only + /// the first page is returned. cursor: Option, /// Returns outputs that were created before a certain slot index. created_before: Option, @@ -231,7 +236,8 @@ pub struct FoundryOutputQueryParameters { /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. page_size: Option, - /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty String is provided, only + /// the first page is returned. cursor: Option, /// Returns outputs that were created before a certain slot index. created_before: Option, @@ -279,7 +285,8 @@ pub struct NftOutputQueryParameters { /// The maximum amount of items returned in one call. If there are more items, a cursor to the next page is /// returned too. The parameter is ignored when pageSize is defined via the cursor parameter. page_size: Option, - /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). + /// Starts the search from the cursor (createdSlotIndex+outputId.pageSize). If an empty String is provided, only + /// the first page is returned. cursor: Option, /// Returns outputs that were created before a certain slot index. created_before: Option, diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index 21f363386f..c54fd11901 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -379,8 +379,7 @@ pub struct AnchorOutput { impl AnchorOutput { /// The [`Output`](crate::types::block::output::Output) kind of an [`AnchorOutput`]. - /// TODO - pub const KIND: u8 = 255; + pub const KIND: u8 = 2; /// Maximum possible length in bytes of the state metadata. pub const STATE_METADATA_LENGTH_MAX: u16 = 8192; /// The set of allowed [`UnlockCondition`]s for an [`AnchorOutput`]. diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index 0e40245870..8a90cff520 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -262,7 +262,7 @@ pub struct DelegationOutput { impl DelegationOutput { /// The [`Output`](crate::types::block::output::Output) kind of a [`DelegationOutput`]. - pub const KIND: u8 = 4; + pub const KIND: u8 = 5; /// The set of allowed [`UnlockCondition`]s for a [`DelegationOutput`]. pub const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::ADDRESS; diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index 56c2782e14..e39f8053f9 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -351,7 +351,7 @@ pub struct FoundryOutput { impl FoundryOutput { /// The [`Output`](crate::types::block::output::Output) kind of a [`FoundryOutput`]. - pub const KIND: u8 = 2; + pub const KIND: u8 = 3; /// The set of allowed [`UnlockCondition`]s for a [`FoundryOutput`]. pub const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::IMMUTABLE_ACCOUNT_ADDRESS; /// The set of allowed [`Feature`]s for a [`FoundryOutput`]. diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 840819c7a2..38cb152b7c 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -132,10 +132,10 @@ impl core::fmt::Debug for Output { match self { Self::Basic(output) => output.fmt(f), Self::Account(output) => output.fmt(f), + Self::Anchor(output) => output.fmt(f), Self::Foundry(output) => output.fmt(f), Self::Nft(output) => output.fmt(f), Self::Delegation(output) => output.fmt(f), - Self::Anchor(output) => output.fmt(f), } } } @@ -149,10 +149,10 @@ impl Output { match self { Self::Basic(_) => BasicOutput::KIND, Self::Account(_) => AccountOutput::KIND, + Self::Anchor(_) => AnchorOutput::KIND, Self::Foundry(_) => FoundryOutput::KIND, Self::Nft(_) => NftOutput::KIND, Self::Delegation(_) => DelegationOutput::KIND, - Self::Anchor(_) => AnchorOutput::KIND, } } @@ -161,10 +161,10 @@ impl Output { match self { Self::Basic(_) => "Basic", Self::Account(_) => "Account", + Self::Anchor(_) => "Anchor", Self::Foundry(_) => "Foundry", Self::Nft(_) => "Nft", Self::Delegation(_) => "Delegation", - Self::Anchor(_) => "Anchor", } } @@ -173,10 +173,10 @@ impl Output { match self { Self::Basic(output) => output.amount(), Self::Account(output) => output.amount(), + Self::Anchor(output) => output.amount(), Self::Foundry(output) => output.amount(), Self::Nft(output) => output.amount(), Self::Delegation(output) => output.amount(), - Self::Anchor(output) => output.amount(), } } @@ -185,10 +185,10 @@ impl Output { match self { Self::Basic(output) => output.mana(), Self::Account(output) => output.mana(), + Self::Anchor(output) => output.mana(), Self::Foundry(_) => 0, Self::Nft(output) => output.mana(), Self::Delegation(_) => 0, - Self::Anchor(output) => output.mana(), } } @@ -197,10 +197,10 @@ impl Output { match self { Self::Basic(output) => Some(output.native_tokens()), Self::Account(output) => Some(output.native_tokens()), + Self::Anchor(output) => Some(output.native_tokens()), Self::Foundry(output) => Some(output.native_tokens()), Self::Nft(output) => Some(output.native_tokens()), Self::Delegation(_) => None, - Self::Anchor(output) => Some(output.native_tokens()), } } @@ -209,10 +209,10 @@ impl Output { match self { Self::Basic(output) => Some(output.unlock_conditions()), Self::Account(output) => Some(output.unlock_conditions()), + Self::Anchor(output) => Some(output.unlock_conditions()), Self::Foundry(output) => Some(output.unlock_conditions()), Self::Nft(output) => Some(output.unlock_conditions()), Self::Delegation(output) => Some(output.unlock_conditions()), - Self::Anchor(output) => Some(output.unlock_conditions()), } } @@ -221,10 +221,10 @@ impl Output { match self { Self::Basic(output) => Some(output.features()), Self::Account(output) => Some(output.features()), + Self::Anchor(output) => Some(output.features()), Self::Foundry(output) => Some(output.features()), Self::Nft(output) => Some(output.features()), Self::Delegation(_) => None, - Self::Anchor(output) => Some(output.features()), } } @@ -233,10 +233,10 @@ impl Output { match self { Self::Basic(_) => None, Self::Account(output) => Some(output.immutable_features()), + Self::Anchor(output) => Some(output.immutable_features()), Self::Foundry(output) => Some(output.immutable_features()), Self::Nft(output) => Some(output.immutable_features()), Self::Delegation(_) => None, - Self::Anchor(output) => Some(output.immutable_features()), } } @@ -245,10 +245,10 @@ impl Output { match self { Self::Basic(_) => None, Self::Account(output) => Some(output.chain_id()), + Self::Anchor(output) => Some(output.chain_id()), Self::Foundry(output) => Some(output.chain_id()), Self::Nft(output) => Some(output.chain_id()), Self::Delegation(_) => None, - Self::Anchor(output) => Some(output.chain_id()), } } @@ -277,6 +277,7 @@ impl Output { .clone(), Some(Address::Account(output.account_address(output_id))), )), + Self::Anchor(_) => Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)), Self::Foundry(output) => Ok((Address::Account(*output.account_address()), None)), Self::Nft(output) => Ok(( output @@ -292,7 +293,6 @@ impl Output { .clone(), None, )), - Self::Anchor(_) => Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)), } } @@ -391,6 +391,10 @@ impl Packable for Output { AccountOutput::KIND.pack(packer)?; output.pack(packer) } + Self::Anchor(output) => { + AnchorOutput::KIND.pack(packer)?; + output.pack(packer) + } Self::Foundry(output) => { FoundryOutput::KIND.pack(packer)?; output.pack(packer) @@ -403,10 +407,6 @@ impl Packable for Output { DelegationOutput::KIND.pack(packer)?; output.pack(packer) } - Self::Anchor(output) => { - AnchorOutput::KIND.pack(packer)?; - output.pack(packer) - } }?; Ok(()) @@ -419,10 +419,10 @@ impl Packable for Output { Ok(match u8::unpack::<_, VERIFY>(unpacker, &()).coerce()? { BasicOutput::KIND => Self::from(BasicOutput::unpack::<_, VERIFY>(unpacker, visitor).coerce()?), AccountOutput::KIND => Self::from(AccountOutput::unpack::<_, VERIFY>(unpacker, visitor).coerce()?), + AnchorOutput::KIND => Self::from(AnchorOutput::unpack::<_, VERIFY>(unpacker, visitor).coerce()?), FoundryOutput::KIND => Self::from(FoundryOutput::unpack::<_, VERIFY>(unpacker, visitor).coerce()?), NftOutput::KIND => Self::from(NftOutput::unpack::<_, VERIFY>(unpacker, visitor).coerce()?), DelegationOutput::KIND => Self::from(DelegationOutput::unpack::<_, VERIFY>(unpacker, visitor).coerce()?), - AnchorOutput::KIND => Self::from(AnchorOutput::unpack::<_, VERIFY>(unpacker, visitor).coerce()?), k => return Err(UnpackError::Packable(Error::InvalidOutputKind(k))), }) } @@ -496,10 +496,10 @@ pub mod dto { pub enum OutputDto { Basic(BasicOutputDto), Account(AccountOutputDto), + Anchor(AnchorOutputDto), Foundry(FoundryOutputDto), Nft(NftOutputDto), Delegation(DelegationOutputDto), - Anchor(AnchorOutputDto), } impl From<&Output> for OutputDto { @@ -507,10 +507,10 @@ pub mod dto { match value { Output::Basic(o) => Self::Basic(o.into()), Output::Account(o) => Self::Account(o.into()), + Output::Anchor(o) => Self::Anchor(o.into()), Output::Foundry(o) => Self::Foundry(o.into()), Output::Nft(o) => Self::Nft(o.into()), Output::Delegation(o) => Self::Delegation(o.into()), - Output::Anchor(o) => Self::Anchor(o.into()), } } } @@ -523,12 +523,12 @@ pub mod dto { Ok(match dto { OutputDto::Basic(o) => Self::Basic(BasicOutput::try_from_dto_with_params_inner(o, params)?), OutputDto::Account(o) => Self::Account(AccountOutput::try_from_dto_with_params_inner(o, params)?), + OutputDto::Anchor(o) => Self::Anchor(AnchorOutput::try_from_dto_with_params_inner(o, params)?), OutputDto::Foundry(o) => Self::Foundry(FoundryOutput::try_from_dto_with_params_inner(o, params)?), OutputDto::Nft(o) => Self::Nft(NftOutput::try_from_dto_with_params_inner(o, params)?), OutputDto::Delegation(o) => { Self::Delegation(DelegationOutput::try_from_dto_with_params_inner(o, params)?) } - OutputDto::Anchor(o) => Self::Anchor(AnchorOutput::try_from_dto_with_params_inner(o, params)?), }) } } @@ -550,6 +550,10 @@ pub mod dto { AccountOutputDto::deserialize(value) .map_err(|e| serde::de::Error::custom(format!("cannot deserialize account output: {e}")))?, ), + AnchorOutput::KIND => Self::Anchor( + AnchorOutputDto::deserialize(value) + .map_err(|e| serde::de::Error::custom(format!("cannot deserialize anchor output: {e}")))?, + ), FoundryOutput::KIND => Self::Foundry( FoundryOutputDto::deserialize(value) .map_err(|e| serde::de::Error::custom(format!("cannot deserialize foundry output: {e}")))?, @@ -563,10 +567,6 @@ pub mod dto { serde::de::Error::custom(format!("cannot deserialize delegation output: {e}")) })?) } - AnchorOutput::KIND => Self::Anchor( - AnchorOutputDto::deserialize(value) - .map_err(|e| serde::de::Error::custom(format!("cannot deserialize anchor output: {e}")))?, - ), _ => return Err(serde::de::Error::custom("invalid output type")), }, ) @@ -583,10 +583,10 @@ pub mod dto { enum OutputDto_<'a> { T0(&'a BasicOutputDto), T1(&'a AccountOutputDto), - T2(&'a FoundryOutputDto), - T3(&'a NftOutputDto), - T4(&'a DelegationOutputDto), - T5(&'a AnchorOutputDto), + T2(&'a AnchorOutputDto), + T3(&'a FoundryOutputDto), + T4(&'a NftOutputDto), + T5(&'a DelegationOutputDto), } #[derive(Serialize)] struct TypedOutput<'a> { @@ -600,16 +600,16 @@ pub mod dto { Self::Account(o) => TypedOutput { output: OutputDto_::T1(o), }, - Self::Foundry(o) => TypedOutput { + Self::Anchor(o) => TypedOutput { output: OutputDto_::T2(o), }, - Self::Nft(o) => TypedOutput { + Self::Foundry(o) => TypedOutput { output: OutputDto_::T3(o), }, - Self::Delegation(o) => TypedOutput { + Self::Nft(o) => TypedOutput { output: OutputDto_::T4(o), }, - Self::Anchor(o) => TypedOutput { + Self::Delegation(o) => TypedOutput { output: OutputDto_::T5(o), }, }; diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 3b8b397888..3f5224a52f 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -309,7 +309,7 @@ pub struct NftOutput { impl NftOutput { /// The [`Output`](crate::types::block::output::Output) kind of an [`NftOutput`]. - pub const KIND: u8 = 3; + pub const KIND: u8 = 4; /// The set of allowed [`UnlockCondition`]s for an [`NftOutput`]. pub const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::ADDRESS .union(UnlockConditionFlags::STORAGE_DEPOSIT_RETURN) diff --git a/sdk/src/types/block/payload/mod.rs b/sdk/src/types/block/payload/mod.rs index 639f0c4a83..8a86eb63e4 100644 --- a/sdk/src/types/block/payload/mod.rs +++ b/sdk/src/types/block/payload/mod.rs @@ -31,10 +31,10 @@ use crate::types::block::{protocol::ProtocolParameters, Error}; /// A generic payload that can represent different types defining block payloads. #[derive(Clone, Eq, PartialEq, From)] pub enum Payload { - /// A signed transaction payload. - SignedTransaction(Box), /// A tagged data payload. TaggedData(Box), + /// A signed transaction payload. + SignedTransaction(Box), /// A candidacy announcement payload. CandidacyAnnouncement(CandidacyAnnouncementPayload), } @@ -42,31 +42,31 @@ pub enum Payload { impl core::fmt::Debug for Payload { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - Self::SignedTransaction(payload) => payload.fmt(f), Self::TaggedData(payload) => payload.fmt(f), + Self::SignedTransaction(payload) => payload.fmt(f), Self::CandidacyAnnouncement(payload) => payload.fmt(f), } } } -impl From for Payload { - fn from(payload: SignedTransactionPayload) -> Self { - Self::SignedTransaction(Box::new(payload)) - } -} - impl From for Payload { fn from(payload: TaggedDataPayload) -> Self { Self::TaggedData(Box::new(payload)) } } +impl From for Payload { + fn from(payload: SignedTransactionPayload) -> Self { + Self::SignedTransaction(Box::new(payload)) + } +} + impl Payload { /// Returns the payload kind of a `Payload`. pub fn kind(&self) -> u8 { match self { - Self::SignedTransaction(_) => SignedTransactionPayload::KIND, Self::TaggedData(_) => TaggedDataPayload::KIND, + Self::SignedTransaction(_) => SignedTransactionPayload::KIND, Self::CandidacyAnnouncement(_) => CandidacyAnnouncementPayload::KIND, } } @@ -80,14 +80,14 @@ impl Packable for Payload { fn pack(&self, packer: &mut P) -> Result<(), P::Error> { match self { - Self::SignedTransaction(transaction) => { - SignedTransactionPayload::KIND.pack(packer)?; - transaction.pack(packer) - } Self::TaggedData(tagged_data) => { TaggedDataPayload::KIND.pack(packer)?; tagged_data.pack(packer) } + Self::SignedTransaction(transaction) => { + SignedTransactionPayload::KIND.pack(packer)?; + transaction.pack(packer) + } Self::CandidacyAnnouncement(_) => CandidacyAnnouncementPayload::KIND.pack(packer), }?; @@ -99,10 +99,10 @@ impl Packable for Payload { visitor: &Self::UnpackVisitor, ) -> Result> { Ok(match u8::unpack::<_, VERIFY>(unpacker, &()).coerce()? { + TaggedDataPayload::KIND => Self::from(TaggedDataPayload::unpack::<_, VERIFY>(unpacker, &()).coerce()?), SignedTransactionPayload::KIND => { Self::from(SignedTransactionPayload::unpack::<_, VERIFY>(unpacker, visitor).coerce()?) } - TaggedDataPayload::KIND => Self::from(TaggedDataPayload::unpack::<_, VERIFY>(unpacker, &()).coerce()?), CandidacyAnnouncementPayload::KIND => Self::from(CandidacyAnnouncementPayload), k => return Err(UnpackError::Packable(Error::InvalidPayloadKind(k))), }) @@ -197,30 +197,30 @@ pub mod dto { #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum PayloadDto { - SignedTransaction(Box), TaggedData(Box), + SignedTransaction(Box), CandidacyAnnouncement, } - impl From for PayloadDto { - fn from(payload: SignedTransactionPayloadDto) -> Self { - Self::SignedTransaction(Box::new(payload)) - } - } - impl From for PayloadDto { fn from(payload: TaggedDataPayload) -> Self { Self::TaggedData(Box::new(payload)) } } + impl From for PayloadDto { + fn from(payload: SignedTransactionPayloadDto) -> Self { + Self::SignedTransaction(Box::new(payload)) + } + } + impl From<&Payload> for PayloadDto { fn from(value: &Payload) -> Self { match value { + Payload::TaggedData(p) => Self::TaggedData(p.clone()), Payload::SignedTransaction(p) => { Self::SignedTransaction(Box::new(SignedTransactionPayloadDto::from(p.as_ref()))) } - Payload::TaggedData(p) => Self::TaggedData(p.clone()), Payload::CandidacyAnnouncement(_) => Self::CandidacyAnnouncement, } } @@ -232,10 +232,10 @@ pub mod dto { fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { Ok(match dto { + PayloadDto::TaggedData(p) => Self::from(*p), PayloadDto::SignedTransaction(p) => { Self::from(SignedTransactionPayload::try_from_dto_with_params_inner(*p, params)?) } - PayloadDto::TaggedData(p) => Self::from(*p), PayloadDto::CandidacyAnnouncement => Self::from(CandidacyAnnouncementPayload), }) } diff --git a/sdk/src/types/block/payload/signed_transaction/transaction.rs b/sdk/src/types/block/payload/signed_transaction/transaction.rs index a02b2e3629..ea8ced1379 100644 --- a/sdk/src/types/block/payload/signed_transaction/transaction.rs +++ b/sdk/src/types/block/payload/signed_transaction/transaction.rs @@ -432,10 +432,10 @@ fn verify_outputs(outputs: &[Output], visitor: &ProtocolPara let (amount, native_tokens, chain_id) = match output { Output::Basic(output) => (output.amount(), Some(output.native_tokens()), None), Output::Account(output) => (output.amount(), Some(output.native_tokens()), Some(output.chain_id())), + Output::Anchor(output) => (output.amount(), None, Some(output.chain_id())), Output::Foundry(output) => (output.amount(), Some(output.native_tokens()), Some(output.chain_id())), Output::Nft(output) => (output.amount(), Some(output.native_tokens()), Some(output.chain_id())), Output::Delegation(output) => (output.amount(), None, Some(output.chain_id())), - Output::Anchor(output) => (output.amount(), None, Some(output.chain_id())), }; amount_sum = amount_sum diff --git a/sdk/src/types/block/semantic.rs b/sdk/src/types/block/semantic.rs index 8edeacaebb..6359cee8e7 100644 --- a/sdk/src/types/block/semantic.rs +++ b/sdk/src/types/block/semantic.rs @@ -273,6 +273,7 @@ impl<'a> SemanticValidationContext<'a> { Some(output.native_tokens()), output.unlock_conditions(), ), + Output::Anchor(_) => return Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)), Output::Foundry(output) => ( output.unlock(output_id, unlock, &mut self), output.amount(), @@ -294,7 +295,6 @@ impl<'a> SemanticValidationContext<'a> { None, output.unlock_conditions(), ), - Output::Anchor(_) => return Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)), }; if let Err(conflict) = conflict { @@ -361,6 +361,7 @@ impl<'a> SemanticValidationContext<'a> { Some(output.native_tokens()), Some(output.features()), ), + Output::Anchor(_) => return Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)), Output::Foundry(output) => ( output.amount(), 0, @@ -374,7 +375,6 @@ impl<'a> SemanticValidationContext<'a> { Some(output.features()), ), Output::Delegation(output) => (output.amount(), 0, None, None), - Output::Anchor(_) => return Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)), }; if let Some(unlock_conditions) = created_output.unlock_conditions() { @@ -425,9 +425,9 @@ impl<'a> SemanticValidationContext<'a> { if match &created_output { Output::Account(_) => !address.has_capability(AddressCapabilityFlag::AccountOutputs), + Output::Anchor(_) => !address.has_capability(AddressCapabilityFlag::AnchorOutputs), Output::Nft(_) => !address.has_capability(AddressCapabilityFlag::NftOutputs), Output::Delegation(_) => !address.has_capability(AddressCapabilityFlag::DelegationOutputs), - Output::Anchor(_) => !address.has_capability(AddressCapabilityFlag::AnchorOutputs), _ => false, } { // TODO: add a variant https://github.com/iotaledger/iota-sdk/issues/1430 diff --git a/sdk/src/types/block/unlock/anchor.rs b/sdk/src/types/block/unlock/anchor.rs index 21073c48d4..cc9f6d9e64 100644 --- a/sdk/src/types/block/unlock/anchor.rs +++ b/sdk/src/types/block/unlock/anchor.rs @@ -21,7 +21,7 @@ impl TryFrom for AnchorUnlock { impl AnchorUnlock { /// The [`Unlock`](crate::types::block::unlock::Unlock) kind of an [`AnchorUnlock`]. - pub const KIND: u8 = 4; + pub const KIND: u8 = 3; /// Creates a new [`AnchorUnlock`]. #[inline(always)] diff --git a/sdk/src/types/block/unlock/mod.rs b/sdk/src/types/block/unlock/mod.rs index 559c60a341..07e8c36273 100644 --- a/sdk/src/types/block/unlock/mod.rs +++ b/sdk/src/types/block/unlock/mod.rs @@ -50,12 +50,12 @@ pub enum Unlock { /// An account unlock. #[packable(tag = AccountUnlock::KIND)] Account(AccountUnlock), - /// An NFT unlock. - #[packable(tag = NftUnlock::KIND)] - Nft(NftUnlock), /// An Anchor unlock. #[packable(tag = AnchorUnlock::KIND)] Anchor(AnchorUnlock), + /// An NFT unlock. + #[packable(tag = NftUnlock::KIND)] + Nft(NftUnlock), } impl From for Unlock { @@ -70,8 +70,8 @@ impl core::fmt::Debug for Unlock { Self::Signature(unlock) => unlock.fmt(f), Self::Reference(unlock) => unlock.fmt(f), Self::Account(unlock) => unlock.fmt(f), - Self::Nft(unlock) => unlock.fmt(f), Self::Anchor(unlock) => unlock.fmt(f), + Self::Nft(unlock) => unlock.fmt(f), } } } @@ -83,8 +83,8 @@ impl Unlock { Self::Signature(_) => SignatureUnlock::KIND, Self::Reference(_) => ReferenceUnlock::KIND, Self::Account(_) => AccountUnlock::KIND, - Self::Nft(_) => NftUnlock::KIND, Self::Anchor(_) => AnchorUnlock::KIND, + Self::Nft(_) => NftUnlock::KIND, } } @@ -144,16 +144,16 @@ fn verify_unlocks(unlocks: &[Unlock], _: &()) -> Result<(), return Err(Error::InvalidUnlockAccount(index)); } } - Unlock::Nft(nft) => { - if index == 0 || nft.index() >= index { - return Err(Error::InvalidUnlockNft(index)); - } - } Unlock::Anchor(anchor) => { if index == 0 || anchor.index() >= index { return Err(Error::InvalidUnlockAnchor(index)); } } + Unlock::Nft(nft) => { + if index == 0 || nft.index() >= index { + return Err(Error::InvalidUnlockNft(index)); + } + } } } } diff --git a/sdk/src/types/block/unlock/nft.rs b/sdk/src/types/block/unlock/nft.rs index 85323bdc99..930b647824 100644 --- a/sdk/src/types/block/unlock/nft.rs +++ b/sdk/src/types/block/unlock/nft.rs @@ -21,7 +21,7 @@ impl TryFrom for NftUnlock { impl NftUnlock { /// The [`Unlock`](crate::types::block::unlock::Unlock) kind of a [`NftUnlock`]. - pub const KIND: u8 = 3; + pub const KIND: u8 = 4; /// Creates a new [`NftUnlock`]. #[inline(always)] diff --git a/sdk/tests/types/unlock/mod.rs b/sdk/tests/types/unlock/mod.rs index 8917cb07f3..dc352f534b 100644 --- a/sdk/tests/types/unlock/mod.rs +++ b/sdk/tests/types/unlock/mod.rs @@ -8,7 +8,7 @@ mod signature; use iota_sdk::types::block::{ rand::signature::rand_signature, - unlock::{AccountUnlock, NftUnlock, ReferenceUnlock, SignatureUnlock, Unlock, Unlocks}, + unlock::{AccountUnlock, AnchorUnlock, NftUnlock, ReferenceUnlock, SignatureUnlock, Unlock, Unlocks}, Error, }; use packable::bounded::TryIntoBoundedU16Error; @@ -19,7 +19,8 @@ fn kind() { assert_eq!(Unlock::from(SignatureUnlock::from(rand_signature())).kind(), 0); assert_eq!(Unlock::from(ReferenceUnlock::new(0).unwrap()).kind(), 1); assert_eq!(Unlock::from(AccountUnlock::new(0).unwrap()).kind(), 2); - assert_eq!(Unlock::from(NftUnlock::new(0).unwrap()).kind(), 3); + assert_eq!(Unlock::from(AnchorUnlock::new(0).unwrap()).kind(), 3); + assert_eq!(Unlock::from(NftUnlock::new(0).unwrap()).kind(), 4); } #[test] diff --git a/sdk/tests/types/unlock/nft.rs b/sdk/tests/types/unlock/nft.rs index 356c0d9c71..70204ae4ca 100644 --- a/sdk/tests/types/unlock/nft.rs +++ b/sdk/tests/types/unlock/nft.rs @@ -7,7 +7,7 @@ use pretty_assertions::assert_eq; #[test] fn kind() { - assert_eq!(NftUnlock::KIND, 3); + assert_eq!(NftUnlock::KIND, 4); } #[test]