Skip to content

Commit

Permalink
Rename Alias to Account (#1077)
Browse files Browse the repository at this point in the history
* Rename Alias to Account

* More rename

* Rename files

* Last renames

* Format

* Nits

* Disambiguate AccountAddress

* AccountIdentifier

* Fix wasm test
  • Loading branch information
thibault-martinez committed Aug 30, 2023
1 parent 766f040 commit fdd31ca
Show file tree
Hide file tree
Showing 44 changed files with 1,187 additions and 1,181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
require('dotenv').config({ path: '.env' });

// Run with command:
// yarn run-example ./client/13-build-alias-output.ts
// yarn run-example ./client/13-build-account-output.ts

// In this example we will build an alias output.
// In this example we will build an account output.
async function run() {
initLogger();
if (!process.env.NODE_URL) {
Expand All @@ -35,8 +35,8 @@ async function run() {
'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy',
);

const aliasOutput = await client.buildAliasOutput({
aliasId:
const accountOutput = await client.buildAccountOutput({
accountId:
'0x0000000000000000000000000000000000000000000000000000000000000000',
stateMetadata: utf8ToHex('hello'),
unlockConditions: [
Expand All @@ -57,7 +57,7 @@ async function run() {
],
});

console.log(JSON.stringify(aliasOutput, null, 2));
console.log(JSON.stringify(accountOutput, null, 2));
process.exit();
} catch (error) {
console.error('Error: ', error);
Expand Down
10 changes: 5 additions & 5 deletions bindings/nodejs/examples/client/14-build-foundry-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import {
Client,
initLogger,
ImmutableAliasAddressUnlockCondition,
AliasAddress,
ImmutableAccountAddressUnlockCondition,
AccountAddress,
SimpleTokenScheme,
} from '@iota/sdk';
require('dotenv').config({ path: '.env' });
Expand All @@ -30,7 +30,7 @@ async function run() {
throw new Error('.env MNEMONIC is undefined, see .env.example');
}

const aliasId =
const accountId =
'0xff311f59790ccb85343a36fbac2f06d233734794404142b308c13f2c616935b5';

const foundryOutput = await client.buildFoundryOutput({
Expand All @@ -42,8 +42,8 @@ async function run() {
),
amount: BigInt(1000000),
unlockConditions: [
new ImmutableAliasAddressUnlockCondition(
new AliasAddress(aliasId),
new ImmutableAccountAddressUnlockCondition(
new AccountAddress(accountId),
),
],
});
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/1-create-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function run() {
});

// Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked,
// have a storage deposit return, expiration or are nft/alias/foundry outputs.
// have a storage deposit return, expiration or are nft/account/foundry outputs.
account.setDefaultSyncOptions({ syncOnlyMostBasicOutputs: true });

console.log(account);
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/3-check-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function run() {
console.log('Addresses:', addresses);

// Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked,
// have a storage deposit return, expiration or are nft/alias/foundry outputs.
// have a storage deposit return, expiration or are nft/account/foundry outputs.
const balance = await account.sync({ syncOnlyMostBasicOutputs: true });

console.log('Balance', balance);
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/4-listen-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function run() {

// Sync to detect new outputs
// Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked,
// have a storage deposit return, expiration or are nft/alias/foundry outputs.
// have a storage deposit return, expiration or are nft/account/foundry outputs.
await account.sync({ syncOnlyMostBasicOutputs: true });
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/5-send-amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function run() {
console.log('Account:', account);

// Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked,
// have a storage deposit return, expiration or are nft/alias/foundry outputs.
// have a storage deposit return, expiration or are nft/account/foundry outputs.
await account.sync({ syncOnlyMostBasicOutputs: true });

const response = await account.send(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { Wallet, initLogger } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// Run with command:
// yarn run-example ./how_tos/alias/create.ts
// yarn run-example ./how_tos/account_output/create.ts

// In this example we create alias.
// In this example we create an account output.
async function run() {
initLogger();
if (!process.env.FAUCET_URL) {
Expand All @@ -40,18 +40,18 @@ async function run() {
let balance = await account.sync();

console.log(
`Aliases BEFORE (${balance.aliases.length}):\n`,
balance.aliases,
`Accounts BEFORE (${balance.accounts.length}):\n`,
balance.accounts,
);

// To sign a transaction we need to unlock stronghold.
await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD);

console.log('Sending the create-alias transaction...');
console.log('Sending the create-account transaction...');

// Create an alias
// Create an account output
const transaction = await account
.prepareCreateAliasOutput()
.prepareCreateAccountOutput()
.then((prepared) => prepared.send());

console.log(`Transaction sent: ${transaction.transactionId}`);
Expand All @@ -66,8 +66,8 @@ async function run() {

balance = await account.sync();
console.log(
`Aliases AFTER (${balance.aliases.length}):\n`,
balance.aliases,
`Accounts AFTER (${balance.accounts.length}):\n`,
balance.accounts,
);
} catch (error) {
console.log('Error: ', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { Wallet, initLogger } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// Run with command:
// yarn run-example ./how_tos/alias/destroy.ts
// yarn run-example ./how_tos/account_output/destroy.ts

// In this example we destroy alias.
// In this example we destroy an account output.
async function run() {
initLogger();
if (!process.env.FAUCET_URL) {
Expand All @@ -35,26 +35,26 @@ async function run() {
// May want to ensure the account is synced before sending a transaction.
let balance = await account.sync();

if (balance.aliases.length == 0) {
throw new Error(`No Alias available in account 'Alice'`);
if (balance.accounts.length == 0) {
throw new Error(`No Account output available in account 'Alice'`);
}

// We try to destroy the first alias in the account
const aliasId = balance.aliases[0];
// We try to destroy the first account output in the account
const accountId = balance.accounts[0];

console.log(
`Aliases BEFORE destroying (${balance.aliases.length}):\n`,
balance.aliases,
`Accounts BEFORE destroying (${balance.accounts.length}):\n`,
balance.accounts,
);

// To sign a transaction we need to unlock stronghold.
await wallet.setStrongholdPassword(process.env.STRONGHOLD_PASSWORD);

console.log('Sending the destroy-alias transaction...');
console.log('Sending the destroy-account transaction...');

// Destroy an alias
// Destroy an account output
const transaction = await account
.prepareDestroyAlias(aliasId)
.prepareDestroyAccount(accountId)
.then((prepared) => prepared.send());

console.log(`Transaction sent: ${transaction.transactionId}`);
Expand All @@ -66,12 +66,12 @@ async function run() {
console.log(
`Block included: ${process.env.EXPLORER_URL}/block/${blockId}`,
);
console.log(`Destroyed alias ${aliasId}`);
console.log(`Destroyed account output ${accountId}`);

balance = await account.sync();
console.log(
`Aliases AFTER destroying (${balance.aliases.length}):\n`,
balance.aliases,
`Accounts AFTER destroying (${balance.accounts.length}):\n`,
balance.accounts,
);
} catch (error) {
console.log('Error: ', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { Utils, Wallet, initLogger } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// Run with command:
// yarn run-example ./how_tos/alias-wallet/request-funds.ts
// yarn run-example ./how_tos/account_wallet/request-funds.ts

// In this example we request funds to an alias wallet.
// In this example we request funds to an account wallet.
async function run() {
initLogger();
if (!process.env.FAUCET_URL) {
Expand All @@ -34,33 +34,33 @@ async function run() {

const totalBaseTokenBalance = balance.baseCoin.total;
console.log(
`Balance before requesting funds on alias address: ${totalBaseTokenBalance}`,
`Balance before requesting funds on account address: ${totalBaseTokenBalance}`,
);

const aliasId = balance.aliases[0];
console.log(`Alias Id: ${aliasId}`);
const accountId = balance.accounts[0];
console.log(`Account Id: ${accountId}`);

// Get Alias address
const aliasAddress = Utils.aliasIdToBech32(
aliasId,
// Get Account address
const accountAddress = Utils.accountIdToBech32(
accountId,
await (await wallet.getClient()).getBech32Hrp(),
);
const faucetResponse = await (
await wallet.getClient()
).requestFundsFromFaucet(faucetUrl, aliasAddress);
).requestFundsFromFaucet(faucetUrl, accountAddress);
console.log(faucetResponse);

await new Promise((resolve) => setTimeout(resolve, 10000));

const syncOptions = {
alias: {
account: {
basicOutputs: true,
},
};
const totalBaseTokenBalanceAfter = (await account.sync(syncOptions))
.baseCoin.total;
console.log(
`Balance after requesting funds on alias address: ${totalBaseTokenBalanceAfter}`,
`Balance after requesting funds on account address: ${totalBaseTokenBalanceAfter}`,
);
} catch (error) {
console.error('Error: ', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { Wallet, initLogger, Utils } from '@iota/sdk';
require('dotenv').config({ path: '.env' });

// Run with command:
// yarn run-example ./how_tos/alias_wallet/transaction.ts
// yarn run-example ./how_tos/account_wallet/transaction.ts

// In this example we send funds from an alias wallet.
// In this example we send funds from an account wallet.
async function run() {
initLogger();
try {
Expand All @@ -24,7 +24,7 @@ async function run() {
}

const syncOptions = {
alias: {
account: {
basicOutputs: true,
},
};
Expand All @@ -41,22 +41,22 @@ async function run() {

const totalBaseTokenBalance = balance.baseCoin.total;
console.log(
`Balance before sending funds from alias: ${totalBaseTokenBalance}`,
`Balance before sending funds from account: ${totalBaseTokenBalance}`,
);

const aliasId = balance.aliases[0];
console.log(`Alias Id: ${aliasId}`);
const accountId = balance.accounts[0];
console.log(`Account Id: ${accountId}`);

// Get Alias address
const aliasAddress = Utils.aliasIdToBech32(
aliasId,
// Get Account address
const accountAddress = Utils.accountIdToBech32(
accountId,
await (await wallet.getClient()).getBech32Hrp(),
);

// Find first output unlockable by the alias address
// Find first output unlockable by the account address
const queryParameters = [
{
address: aliasAddress,
address: accountAddress,
},
];
const input = (
Expand Down Expand Up @@ -85,7 +85,7 @@ async function run() {
const totalBaseTokenBalanceAfter = (await account.sync(syncOptions))
.baseCoin.total;
console.log(
`Balance after sending funds from alias: ${totalBaseTokenBalanceAfter}`,
`Balance after sending funds from account: ${totalBaseTokenBalanceAfter}`,
);
} catch (error) {
console.error('Error: ', error);
Expand Down
8 changes: 4 additions & 4 deletions bindings/nodejs/examples/how_tos/native_tokens/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ async function run() {

const balance = await account.sync();

// We can first check if we already have an alias in our account, because an alias can have
// We can first check if we already have an account output in our account, because an account output can have
// many foundry outputs and therefore we can reuse an existing one
if (balance.aliases.length == 0) {
// If we don't have an alias, we need to create one
if (balance.accounts.length == 0) {
// If we don't have an account output, we need to create one
const transaction = await account
.prepareCreateAliasOutput()
.prepareCreateAccountOutput()
.then((prepared) => prepared.send());
console.log(`Transaction sent: ${transaction.transactionId}`);

Expand Down
18 changes: 9 additions & 9 deletions bindings/nodejs/examples/how_tos/outputs/unlock-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
SimpleTokenScheme,
StateControllerAddressUnlockCondition,
GovernorAddressUnlockCondition,
ImmutableAliasAddressUnlockCondition,
AliasAddress,
ImmutableAccountAddressUnlockCondition,
AccountAddress,
} from '@iota/sdk';
require('dotenv').config({ path: '.env' });

Expand All @@ -33,7 +33,7 @@ async function run() {
'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy',
);

const aliasHexAddress = Utils.bech32ToHex(
const accountHexAddress = Utils.bech32ToHex(
'rms1pr59qm43mjtvhcajfmupqf23x29llam88yecn6pyul80rx099krmv2fnnux',
);

Expand Down Expand Up @@ -82,8 +82,8 @@ async function run() {
});

// Output with governor and state controller unlock condition
const aliasOutput = await client.buildAliasOutput({
aliasId:
const accountOutput = await client.buildAccountOutput({
accountId:
'0x0000000000000000000000000000000000000000000000000000000000000000',
unlockConditions: [
new GovernorAddressUnlockCondition(
Expand All @@ -95,13 +95,13 @@ async function run() {
],
});

// Output with immutable alias unlock condition
// Output with immutable account unlock condition
const foundryOutput = await client.buildFoundryOutput({
serialNumber: 1,
tokenScheme: tokenSchema,
unlockConditions: [
new ImmutableAliasAddressUnlockCondition(
new AliasAddress(aliasHexAddress),
new ImmutableAccountAddressUnlockCondition(
new AccountAddress(accountHexAddress),
),
],
});
Expand All @@ -113,7 +113,7 @@ async function run() {
basicOutputWithStorageReturn,
basicOutputWithTimelock,
basicOutputWithExpiration,
aliasOutput,
accountOutput,
foundryOutput,
],
null,
Expand Down
Loading

0 comments on commit fdd31ca

Please sign in to comment.