Skip to content

Commit

Permalink
refactor!: remove --no-waitMined option
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Commands don't accept `--no-waitMined` anymore
In the most cases transactions gets mined immediately. In case of NameClaim, tx needs to be
submitted in the next keyblock after preclaim. In that case it would be mined also immediately,
with no early name revealing.
If still needed, use `aecli chain broadcast tx_... --no-waitMined` instead.
  • Loading branch information
davidyuk committed Apr 15, 2024
1 parent 91978c5 commit 5fe7dc4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 113 deletions.
80 changes: 22 additions & 58 deletions src/actions/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { isAddressValid, getDefaultPointerKey } from '@aeternity/aepp-sdk';
import { initSdkByWalletFile } from '../utils/cli.js';
import { print, printTransaction } from '../utils/print.js';
import { printTransaction } from '../utils/print.js';
import { getNameEntry, validateName } from '../utils/helpers.js';
import CliError from '../utils/CliError.js';

Expand All @@ -18,7 +18,7 @@ async function ensureNameStatus(name, sdk, status, operation) {
// ## Claim `name` function
export async function preClaim(walletPath, name, options) {
const {
ttl, fee, nonce, waitMined, json,
ttl, fee, nonce, json,
} = options;

// Validate `name`(check if `name` end on `.chain`)
Expand All @@ -29,20 +29,14 @@ export async function preClaim(walletPath, name, options) {
// Check if that `name' available
await ensureNameStatus(name, sdk, 'AVAILABLE', 'preclaimed');
// Create `pre-claim` transaction
const preClaimTx = await sdk.aensPreclaim(name, {
ttl, fee, nonce, waitMined,
});
if (waitMined) {
await printTransaction(preClaimTx, json, sdk);
} else {
print(`Transaction send to the chain. Tx hash: ${preClaimTx.hash}`);
}
const preClaimTx = await sdk.aensPreclaim(name, { ttl, fee, nonce });
await printTransaction(preClaimTx, json, sdk);
}

// ## Claim `name` function
export async function claim(walletPath, name, salt, options) {
const {
ttl, fee, nonce, waitMined, json, nameFee,
ttl, fee, nonce, json, nameFee,
} = options;
// Validate `name`
// validateName(name)
Expand All @@ -54,19 +48,15 @@ export async function claim(walletPath, name, salt, options) {

// Wait for next block and create `claimName` transaction
const claimTx = await sdk.aensClaim(name, salt, {
nonce, ttl, fee, waitMined, nameFee,
nonce, ttl, fee, nameFee,
});
if (waitMined) {
await printTransaction(claimTx, json, sdk);
} else {
print(`Transaction send to the chain. Tx hash: ${claimTx.hash}`);
}
await printTransaction(claimTx, json, sdk);
}

// ##Update `name` function
export async function updateName(walletPath, name, addresses, options) {
const {
ttl, fee, nonce, waitMined, json, nameTtl, clientTtl, extendPointers = false,
ttl, fee, nonce, json, nameTtl, clientTtl, extendPointers = false,
} = options;

// Validate `address`
Expand All @@ -84,20 +74,16 @@ export async function updateName(walletPath, name, addresses, options) {
name,
Object.fromEntries(addresses.map((address) => [getDefaultPointerKey(address), address])),
{
ttl, fee, nonce, waitMined, nameTtl, clientTtl, extendPointers,
ttl, fee, nonce, nameTtl, clientTtl, extendPointers,
},
);
if (waitMined) {
await printTransaction(updateTx, json, sdk);
} else {
print(`Transaction send to the chain. Tx hash: ${updateTx.hash}`);
}
await printTransaction(updateTx, json, sdk);
}

// ##Extend `name` ttl function
export async function extendName(walletPath, name, nameTtl, options) {
const {
ttl, fee, nonce, waitMined, json,
ttl, fee, nonce, json,
} = options;

// Validate `name`
Expand All @@ -109,19 +95,15 @@ export async function extendName(walletPath, name, nameTtl, options) {

// Create `updateName` transaction
const updateTx = await sdk.aensUpdate(name, {}, {
ttl, fee, nonce, waitMined, nameTtl, extendPointers: true,
ttl, fee, nonce, nameTtl, extendPointers: true,
});
if (waitMined) {
await printTransaction(updateTx, json, sdk);
} else {
print(`Transaction send to the chain. Tx hash: ${updateTx.hash}`);
}
await printTransaction(updateTx, json, sdk);
}

// ##Transfer `name` function
export async function transferName(walletPath, name, address, options) {
const {
ttl, fee, nonce, waitMined, json,
ttl, fee, nonce, json,
} = options;

// Validate `address`
Expand All @@ -134,20 +116,14 @@ export async function transferName(walletPath, name, address, options) {
await ensureNameStatus(name, sdk, 'CLAIMED', 'transferred');

// Create `transferName` transaction
const transferTX = await sdk.aensTransfer(name, address, {
ttl, fee, nonce, waitMined,
});
if (waitMined) {
await printTransaction(transferTX, json, sdk);
} else {
print(`Transaction send to the chain. Tx hash: ${transferTX.hash}`);
}
const transferTX = await sdk.aensTransfer(name, address, { ttl, fee, nonce });
await printTransaction(transferTX, json, sdk);
}

// ## Revoke `name` function
export async function revokeName(walletPath, name, options) {
const {
ttl, fee, nonce, waitMined, json,
ttl, fee, nonce, json,
} = options;

// Validate `name`
Expand All @@ -158,19 +134,13 @@ export async function revokeName(walletPath, name, options) {
await ensureNameStatus(name, sdk, 'CLAIMED', 'revoked');

// Create `revokeName` transaction
const revokeTx = await sdk.aensRevoke(name, {
ttl, fee, nonce, waitMined,
});
if (waitMined) {
await printTransaction(revokeTx, json, sdk);
} else {
print(`Transaction send to the chain. Tx hash: ${revokeTx.hash}`);
}
const revokeTx = await sdk.aensRevoke(name, { ttl, fee, nonce });
await printTransaction(revokeTx, json, sdk);
}

export async function nameBid(walletPath, name, nameFee, options) {
const {
ttl, fee, nonce, waitMined, json,
ttl, fee, nonce, json,
} = options;
// Validate `name`
validateName(name);
Expand All @@ -181,14 +151,8 @@ export async function nameBid(walletPath, name, nameFee, options) {
await ensureNameStatus(name, sdk, 'AUCTION', 'bidded');

// Wait for next block and create `claimName` transaction
const nameBidTx = await sdk.aensBid(name, nameFee, {
nonce, ttl, fee, waitMined,
});
if (waitMined) {
await printTransaction(nameBidTx, json, sdk);
} else {
print(`Transaction send to the chain. Tx hash: ${nameBidTx.hash}`);
}
const nameBidTx = await sdk.aensBid(name, nameFee, { nonce, ttl, fee });
await printTransaction(nameBidTx, json, sdk);
}

export async function fullClaim(walletPath, name, options) {
Expand Down
36 changes: 8 additions & 28 deletions src/actions/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ function ensureTtlANumber(ttl, name) {
// ## Create Oracle
export async function createOracle(walletPath, queryFormat, responseFormat, options) {
const {
ttl, fee, nonce, waitMined, json, oracleTtl, queryFee,
ttl, fee, nonce, json, oracleTtl, queryFee,
} = options;

ensureTtlANumber(oracleTtl, 'Oracle');
const sdk = await initSdkByWalletFile(walletPath, options);
// Register Oracle
const oracle = await sdk.registerOracle(queryFormat, responseFormat, {
ttl,
waitMined,
nonce,
fee,
...oracleTtl && {
Expand All @@ -34,17 +33,13 @@ export async function createOracle(walletPath, queryFormat, responseFormat, opti
},
queryFee,
});
if (waitMined) {
await printTransaction(oracle, json, sdk);
} else {
print('Transaction send to the chain. Tx hash: ', oracle);
}
await printTransaction(oracle, json, sdk);
}

// ## Extend Oracle
export async function extendOracle(walletPath, oracleId, oracleTtl, options) {
const {
ttl, fee, nonce, waitMined, json,
ttl, fee, nonce, json,
} = options;

ensureTtlANumber(oracleTtl, 'Oracle');
Expand All @@ -53,25 +48,20 @@ export async function extendOracle(walletPath, oracleId, oracleTtl, options) {
const oracle = await sdk.getOracleObject(oracleId);
const extended = await oracle.extendOracle({
ttl,
waitMined,
nonce,
fee,
...oracleTtl && {
oracleTtlType: ORACLE_TTL_TYPES.delta,
oracleTtlValue: oracleTtl,
},
});
if (waitMined) {
await printTransaction(extended, json, sdk);
} else {
print('Transaction send to the chain. Tx hash: ', extended);
}
await printTransaction(extended, json, sdk);
}

// ## Create Oracle Query
export async function createOracleQuery(walletPath, oracleId, query, options) {
const {
ttl, fee, nonce, waitMined, json, queryTtl, queryFee, responseTtl,
ttl, fee, nonce, json, queryTtl, queryFee, responseTtl,
} = options;

decode(oracleId, 'ok');
Expand All @@ -82,7 +72,6 @@ export async function createOracleQuery(walletPath, oracleId, query, options) {
const oracle = await sdk.getOracleObject(oracleId);
const oracleQuery = await oracle.postQuery(query, {
ttl,
waitMined,
nonce,
fee,
...queryTtl && {
Expand All @@ -95,11 +84,7 @@ export async function createOracleQuery(walletPath, oracleId, query, options) {
},
queryFee,
});
if (waitMined) {
await printTransaction(oracleQuery, json, sdk);
} else {
print('Transaction send to the chain. Tx hash: ', oracleQuery);
}
await printTransaction(oracleQuery, json, sdk);
}

// ## Respond to Oracle Query
Expand All @@ -111,7 +96,7 @@ export async function respondToQuery(
options,
) {
const {
ttl, fee, nonce, waitMined, json, responseTtl,
ttl, fee, nonce, json, responseTtl,
} = options;

decode(oracleId, 'ok');
Expand All @@ -122,19 +107,14 @@ export async function respondToQuery(
const oracle = await sdk.getOracleObject(oracleId);
const queryResponse = await oracle.respondToQuery(queryId, response, {
ttl,
waitMined,
nonce,
fee,
...responseTtl && {
responseTtlType: ORACLE_TTL_TYPES.delta,
responseTtlValue: responseTtl,
},
});
if (waitMined) {
await printTransaction(queryResponse, json, sdk);
} else {
print('Transaction send to the chain. Tx hash: ', queryResponse);
}
await printTransaction(queryResponse, json, sdk);
}

// ## Get oracle
Expand Down
4 changes: 2 additions & 2 deletions src/commands/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ addCommonOptions(program
// Example: `aecli tx spend ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi ak_AgV756Vfo99juwzNVgnjP1gXX1op1QN3NXTxvkPnHJPUDE8NT 100`
addCommonOptions(program
.command('broadcast <tx>')
.option('-W, --no-waitMined', 'Force waiting until transaction will be mined')
.option('--verify', 'Verify Transaction before broadcast.')
.option('-W, --no-waitMined', 'Don\'t wait until transaction gets mined')
.option('--verify', 'Verify Transaction before broadcasting.')
.description('Send transaction to the chain')
.action(Chain.broadcast));

Expand Down
2 changes: 0 additions & 2 deletions src/commands/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ addCommonOptions(program
.option('--contractAddress [contractAddress]', 'Contract address to call')
.addOption(contractSourceFilenameOption)
.addOption(contractAciFilenameOption)
.option('-W, --no-waitMined', 'Force waiting until transaction will be mined')
.addOption(passwordOption)
.addOption(gasOption)
.option('-s, --callStatic', 'Call static')
Expand Down Expand Up @@ -133,7 +132,6 @@ addCommonOptions(program
.addOption(contractSourceFilenameOption)
.option('--contractBytecode [contractBytecode]', 'Contract bytecode file name')
.addOption(contractAciFilenameOption)
.option('-W, --no-waitMined', 'Force waiting until transaction will be mined')
.addOption(passwordOption)
.addOption(gasOption)
.addOption(gasPriceOption(true))
Expand Down
9 changes: 0 additions & 9 deletions src/commands/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const addCommonOptions = (p) => p
// You can use `--nameTtl` and `--ttl` to pre-set transaction and name `time to leave`
addCommonOptions(program
.command('full-claim <wallet_path> <name>')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.option('--nameFee [nameFee]', 'Amount of coins to pay for name')
.option('--nameTtl [nameTtl]', 'Validity of name.', NAME_TTL)
.option('--clientTtl [clientTtl]', 'Client ttl.', CLIENT_TTL)
Expand All @@ -48,12 +47,10 @@ addCommonOptions(program
// Example: `aecli name pre-claim ./myWalletKeyFile --password testpass testname.chain`
//
// This command build and send `pre-claim` transaction.
// And wait until it will be mined. You can force waiting by using `--waitMined false` option. Default: true
//
// You can use `--ttl` to pre-set transaction `time to leave`
addCommonOptions(program
.command('pre-claim <wallet_path> <name>')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.description('Pre-Claim an AENS name')
.action(AENS.preClaim));

Expand All @@ -68,7 +65,6 @@ addCommonOptions(program
// You can use `--nameTtl` and `--ttl` to pre-set transaction and name `time to leave`
addCommonOptions(program
.command('claim <wallet_path> <name> <salt>')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.option('--nameFee [nameFee]', 'Amount of coins to pay for name')
.description('Claim an AENS name')
.action(AENS.claim));
Expand All @@ -84,7 +80,6 @@ addCommonOptions(program
// You can use `--nameTtl` and `--ttl` to pre-set transaction and name `time to leave`
addCommonOptions(program
.command('bid <wallet_path> <name> <nameFee>')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.description('Bid on name')
.action(AENS.nameBid));

Expand All @@ -95,7 +90,6 @@ addCommonOptions(program
// Example: `aecli name update ./myWalletKeyFile --password testpass testname.chain ak_qwe23dffasfgdesag323`
addCommonOptions(program
.command('update <wallet_path> <name> [addresses...]')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.option('--extendPointers', 'Extend pointers', false)
.option('--nameTtl [nameTtl]', 'A number of blocks until name expires', NAME_TTL)
.option('--clientTtl [clientTtl]', 'Client TTL', CLIENT_TTL)
Expand All @@ -110,7 +104,6 @@ addCommonOptions(program
addCommonOptions(program
.command('extend <wallet_path> <name>')
.argument('[nameTtl]', 'A number of blocks until name expires', NAME_TTL)
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.option('--clientTtl [clientTtl]', 'Client TTL', CLIENT_TTL)
.description('Extend name ttl')
.action(AENS.extendName));
Expand All @@ -122,7 +115,6 @@ addCommonOptions(program
// Example: `aecli name revoke ./myWalletKeyFile --password testpass testname.chain`
addCommonOptions(program
.command('revoke <wallet_path> <name>')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.description('Revoke an AENS name')
.action(AENS.revokeName));

Expand All @@ -133,7 +125,6 @@ addCommonOptions(program
// Example: `aecli name transfer ./myWalletKeyFile --password testpass testname.chain ak_qqwemjgflewgkj349gjdslksd`
addCommonOptions(program
.command('transfer <wallet_path> <name> <address>')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.description('Transfer a name to another account')
.action(AENS.transferName));

Expand Down

0 comments on commit 5fe7dc4

Please sign in to comment.