Skip to content

Commit

Permalink
Merge pull request #258 from aeternity/rename-aesdk
Browse files Browse the repository at this point in the history
refactor: rename `sdk` to `aeSdk` in consistency with sdk tests
  • Loading branch information
davidyuk authored May 22, 2024
2 parents 34a00d8 + a70ebef commit 4e04021
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 255 deletions.
8 changes: 4 additions & 4 deletions src/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export async function verifyMessage(address, hexSignature, dataArray = [], optio
}

export async function sign(walletPath, tx, { networkId: networkIdOpt, json, ...options }) {
const sdk = await initSdkByWalletFile(walletPath, options);
const networkId = networkIdOpt ?? await sdk.api.getNetworkId();
const signedTx = await sdk.signTransaction(tx, { networkId });
const { address } = sdk;
const aeSdk = await initSdkByWalletFile(walletPath, options);
const networkId = networkIdOpt ?? await aeSdk.api.getNetworkId();
const signedTx = await aeSdk.signTransaction(tx, { networkId });
const { address } = aeSdk;
if (json) {
print({ signedTx, address, networkId });
} else {
Expand Down
70 changes: 35 additions & 35 deletions src/actions/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { printTransaction } from '../utils/print.js';
import { getNameEntry, validateName } from '../utils/helpers.js';
import CliError from '../utils/CliError.js';

async function ensureNameStatus(name, sdk, status, operation) {
const nameEntry = await getNameEntry(name, sdk);
async function ensureNameStatus(name, aeSdk, status, operation) {
const nameEntry = await getNameEntry(name, aeSdk);
if (nameEntry.status !== status) {
throw new CliError(`AENS name is ${nameEntry.status} and cannot be ${operation}`);
}
Expand All @@ -16,23 +16,23 @@ export async function preClaim(walletPath, name, options) {
ttl, fee, nonce, json,
} = options;
validateName(name);
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'AVAILABLE', 'preclaimed');
const preClaimTx = await sdk.aensPreclaim(name, { ttl, fee, nonce });
await printTransaction(preClaimTx, json, sdk);
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'AVAILABLE', 'preclaimed');
const preClaimTx = await aeSdk.aensPreclaim(name, { ttl, fee, nonce });
await printTransaction(preClaimTx, json, aeSdk);
}

export async function claim(walletPath, name, salt, options) {
const {
ttl, fee, nonce, json, nameFee,
} = options;
validateName(name);
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'AVAILABLE', 'claimed');
const claimTx = await sdk.aensClaim(name, salt, {
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'AVAILABLE', 'claimed');
const claimTx = await aeSdk.aensClaim(name, salt, {
nonce, ttl, fee, nameFee,
});
await printTransaction(claimTx, json, sdk);
await printTransaction(claimTx, json, aeSdk);
}

export async function updateName(walletPath, name, addresses, options) {
Expand All @@ -42,29 +42,29 @@ export async function updateName(walletPath, name, addresses, options) {
const invalidAddresses = addresses.filter((address) => !isAddressValid(address));
if (invalidAddresses.length) throw new CliError(`Addresses "[${invalidAddresses}]" is not valid`);
validateName(name);
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'CLAIMED', 'updated');
const updateTx = await sdk.aensUpdate(
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'CLAIMED', 'updated');
const updateTx = await aeSdk.aensUpdate(
name,
Object.fromEntries(addresses.map((address) => [getDefaultPointerKey(address), address])),
{
ttl, fee, nonce, nameTtl, clientTtl, extendPointers,
},
);
await printTransaction(updateTx, json, sdk);
await printTransaction(updateTx, json, aeSdk);
}

export async function extendName(walletPath, name, nameTtl, options) {
const {
ttl, fee, nonce, json,
} = options;
validateName(name);
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'CLAIMED', 'extended');
const updateTx = await sdk.aensUpdate(name, {}, {
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'CLAIMED', 'extended');
const updateTx = await aeSdk.aensUpdate(name, {}, {
ttl, fee, nonce, nameTtl, extendPointers: true,
});
await printTransaction(updateTx, json, sdk);
await printTransaction(updateTx, json, aeSdk);
}

export async function transferName(walletPath, name, address, options) {
Expand All @@ -73,32 +73,32 @@ export async function transferName(walletPath, name, address, options) {
} = options;
if (!isAddressValid(address)) throw new CliError(`Address "${address}" is not valid`);
validateName(name);
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'CLAIMED', 'transferred');
const transferTX = await sdk.aensTransfer(name, address, { ttl, fee, nonce });
await printTransaction(transferTX, json, sdk);
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'CLAIMED', 'transferred');
const transferTX = await aeSdk.aensTransfer(name, address, { ttl, fee, nonce });
await printTransaction(transferTX, json, aeSdk);
}

export async function revokeName(walletPath, name, options) {
const {
ttl, fee, nonce, json,
} = options;
validateName(name);
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'CLAIMED', 'revoked');
const revokeTx = await sdk.aensRevoke(name, { ttl, fee, nonce });
await printTransaction(revokeTx, json, sdk);
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'CLAIMED', 'revoked');
const revokeTx = await aeSdk.aensRevoke(name, { ttl, fee, nonce });
await printTransaction(revokeTx, json, aeSdk);
}

export async function nameBid(walletPath, name, nameFee, options) {
const {
ttl, fee, nonce, json,
} = options;
validateName(name);
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'AUCTION', 'bidded');
const nameBidTx = await sdk.aensBid(name, nameFee, { nonce, ttl, fee });
await printTransaction(nameBidTx, json, sdk);
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'AUCTION', 'bidded');
const nameBidTx = await aeSdk.aensBid(name, nameFee, { nonce, ttl, fee });
await printTransaction(nameBidTx, json, aeSdk);
}

export async function fullClaim(walletPath, name, options) {
Expand All @@ -107,10 +107,10 @@ export async function fullClaim(walletPath, name, options) {
} = options;
validateName(name);
if (name.split('.')[0] < 13) throw new CliError('Full name claiming works only with name longer then 12 symbol (not trigger auction)');
const sdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, sdk, 'AVAILABLE', 'claimed');
const aeSdk = await initSdkByWalletFile(walletPath, options);
await ensureNameStatus(name, aeSdk, 'AVAILABLE', 'claimed');
nonce = nonce && +nonce;
const preclaim = await sdk.aensPreclaim(name, { nonce, ttl, fee });
const preclaim = await aeSdk.aensPreclaim(name, { nonce, ttl, fee });

nonce = nonce && nonce + 1;
const nameInstance = await preclaim.claim({
Expand All @@ -119,10 +119,10 @@ export async function fullClaim(walletPath, name, options) {

nonce = nonce && nonce + 1;
const updateTx = await nameInstance.update(
{ account_pubkey: sdk.address },
{ account_pubkey: aeSdk.address },
{
nonce, ttl, fee, nameTtl, clientTtl,
},
);
await printTransaction(updateTx, json, sdk);
await printTransaction(updateTx, json, aeSdk);
}
30 changes: 15 additions & 15 deletions src/actions/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { getBlock } from '../utils/helpers.js';

export async function status(options) {
const { json } = options;
const sdk = initSdk(options);
const st = await sdk.api.getStatus();
const { consensusProtocolVersion } = await sdk.getNodeInfo();
const aeSdk = initSdk(options);
const st = await aeSdk.api.getStatus();
const { consensusProtocolVersion } = await aeSdk.getNodeInfo();
if (json) {
print(st);
return;
Expand All @@ -28,8 +28,8 @@ export async function status(options) {
}

export async function ttl(_absoluteTtl, { json, ...options }) {
const sdk = initSdk(options);
const height = await sdk.getHeight();
const aeSdk = initSdk(options);
const height = await aeSdk.getHeight();
const absoluteTtl = +_absoluteTtl;
const relativeTtl = absoluteTtl - height;
if (json) {
Expand All @@ -41,38 +41,38 @@ export async function ttl(_absoluteTtl, { json, ...options }) {
}

export async function top({ json, ...options }) {
const sdk = initSdk(options);
printBlock(await sdk.api.getTopHeader(), json, true);
const aeSdk = initSdk(options);
printBlock(await aeSdk.api.getTopHeader(), json, true);
}

export async function play(options) {
let { height, limit, json } = options;
limit = +limit;
height = +height;
const sdk = initSdk(options);
let block = await sdk.api.getTopHeader();
const aeSdk = initSdk(options);
let block = await aeSdk.api.getTopHeader();
while (height ? block.height >= height : limit) {
if (!height) limit -= 1;
printBlock(block, json);
block = await getBlock(block.prevHash, sdk); // eslint-disable-line no-await-in-loop
block = await getBlock(block.prevHash, aeSdk); // eslint-disable-line no-await-in-loop
}
}

export async function broadcast(signedTx, options) {
const { json, waitMined, verify } = options;
const sdk = initSdk(options);
const aeSdk = initSdk(options);

if (verify) {
const validation = await verifyTransaction(signedTx, sdk.api);
const validation = await verifyTransaction(signedTx, aeSdk.api);
if (validation.length) {
printValidation({ validation, transaction: signedTx });
return;
}
}

const { txHash } = await sdk.api.postTransaction({ tx: signedTx });
const tx = await (waitMined ? sdk.poll(txHash) : sdk.api.getTransactionByHash(txHash));
const { txHash } = await aeSdk.api.postTransaction({ tx: signedTx });
const tx = await (waitMined ? aeSdk.poll(txHash) : aeSdk.api.getTransactionByHash(txHash));

await printTransaction(tx, json, sdk);
await printTransaction(tx, json, aeSdk);
if (!waitMined && !json) print('Transaction send to the chain.');
}
22 changes: 11 additions & 11 deletions src/actions/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ async function getContractParams({
}

export async function compile(contractSource, options) {
const sdk = initSdk(options);
const contract = await sdk.initializeContract({ sourceCodePath: contractSource });
const aeSdk = initSdk(options);
const contract = await aeSdk.initializeContract({ sourceCodePath: contractSource });
const bytecode = await contract.$compile();
if (options.json) print({ bytecode });
else print(`Contract bytecode: ${bytecode}`);
}

export async function encodeCalldata(fn, args, options) {
const sdk = initSdk(options);
const aeSdk = initSdk(options);
const contractParams = await getContractParams(options, { dummyBytecode: true });
delete contractParams.address; // TODO: remove after dropping Iris support
const contract = await sdk.initializeContract(contractParams);
const contract = await aeSdk.initializeContract(contractParams);
// eslint-disable-next-line no-underscore-dangle
const calldata = contract._calldata.encode(contract._name, fn, args);
if (options.json) print({ calldata });
else print(`Contract encoded calldata: ${calldata}`);
}

export async function decodeCallResult(fn, calldata, options) {
const sdk = initSdk(options);
const contract = await sdk.initializeContract(await getContractParams(options, { dummyBytecode: true }));
const aeSdk = initSdk(options);
const contract = await aeSdk.initializeContract(await getContractParams(options, { dummyBytecode: true }));
// eslint-disable-next-line no-underscore-dangle
const decoded = contract._calldata.decode(contract._name, fn, calldata);
if (options.json) print({ decoded });
Expand All @@ -63,8 +63,8 @@ export async function decodeCallResult(fn, calldata, options) {
}

export async function deploy(walletPath, args, options) {
const sdk = await initSdkByWalletFile(walletPath, options);
const contract = await sdk.initializeContract(await getContractParams(options, { descrMayNotExist: true }));
const aeSdk = await initSdkByWalletFile(walletPath, options);
const contract = await aeSdk.initializeContract(await getContractParams(options, { descrMayNotExist: true }));
const result = await contract.$deploy(args, options);
const filename = options.contractSource ?? options.contractBytecode;
options.descrPath ??= getFullPath(`${filename}.deploy.${result.address.slice(3)}.json`);
Expand Down Expand Up @@ -92,8 +92,8 @@ export async function call(fn, args, walletPath, options) {
if (callStatic !== true && walletPath == null) {
throw new CliError('wallet_path is required for on-chain calls');
}
const sdk = await initSdkByWalletFile(walletPath, options);
const contract = await sdk.initializeContract(await getContractParams(options));
const aeSdk = await initSdkByWalletFile(walletPath, options);
const contract = await aeSdk.initializeContract(await getContractParams(options));
const callResult = await contract.$call(fn, args, {
ttl: ttl && +ttl,
gas,
Expand All @@ -105,7 +105,7 @@ export async function call(fn, args, walletPath, options) {
});
if (json) print(callResult);
else {
await printTransaction(callResult.txData, json, sdk);
await printTransaction(callResult.txData, json, aeSdk);
print('----------------------Call info-----------------------');
const gasCoins = BigInt(callResult.result.gasUsed) * callResult.txData.tx.gasPrice;
printUnderscored('Gas used', `${callResult.result.gasUsed} (${formatCoins(gasCoins)})`);
Expand Down
36 changes: 18 additions & 18 deletions src/actions/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ function printEntries(object) {

async function getBlockByHash(hash, { json, ...options }) {
checkPref(hash, [Encoding.KeyBlockHash, Encoding.MicroBlockHash]);
const sdk = initSdk(options);
printBlock(await getBlock(hash, sdk), json, true);
const aeSdk = initSdk(options);
printBlock(await getBlock(hash, aeSdk), json, true);
}

async function getTransactionByHash(hash, { json, ...options }) {
checkPref(hash, Encoding.TxHash);
const sdk = initSdk(options);
await printTransaction(await sdk.api.getTransactionByHash(hash), json, sdk);
const aeSdk = initSdk(options);
await printTransaction(await aeSdk.api.getTransactionByHash(hash), json, aeSdk);
}

async function unpackTx(encodedTx, { json }) {
Expand All @@ -38,10 +38,10 @@ async function unpackTx(encodedTx, { json }) {

async function getAccountByHash(hash, { json, ...options }) {
checkPref(hash, Encoding.AccountAddress);
const sdk = initSdk(options);
const { nonce } = await sdk.api.getAccountByPubkey(hash);
const balance = await sdk.getBalance(hash);
const { transactions } = await sdk.api.getPendingAccountTransactionsByPubkey(hash);
const aeSdk = initSdk(options);
const { nonce } = await aeSdk.api.getAccountByPubkey(hash);
const balance = await aeSdk.getBalance(hash);
const { transactions } = await aeSdk.api.getPendingAccountTransactionsByPubkey(hash);
if (json) {
print({
hash,
Expand All @@ -59,21 +59,21 @@ async function getAccountByHash(hash, { json, ...options }) {
}

async function getBlockByHeight(height, { json, ...options }) {
const sdk = initSdk(options);
printBlock(await sdk.api.getKeyBlockByHeight(+height), json);
const aeSdk = initSdk(options);
printBlock(await aeSdk.api.getKeyBlockByHeight(+height), json);
}

async function getName(name, { json, ...options }) {
validateName(name);
const sdk = initSdk(options);
const nameEntry = await getNameEntry(name, sdk);
const aeSdk = initSdk(options);
const nameEntry = await getNameEntry(name, aeSdk);

if (json) {
print(nameEntry);
return;
}

const height = await sdk.getHeight({ cached: true });
const height = await aeSdk.getHeight({ cached: true });
printUnderscored('Status', nameEntry.status);
printUnderscored('Name hash', nameEntry.id);
switch (nameEntry.status) {
Expand All @@ -98,16 +98,16 @@ async function getName(name, { json, ...options }) {
}

async function getContract(contractId, { json, ...options }) {
const sdk = initSdk(options);
const contract = await sdk.api.getContract(contractId);
const aeSdk = initSdk(options);
const contract = await aeSdk.api.getContract(contractId);
if (json) print(contract);
else printEntries(contract);
}

async function getOracle(oracleId, { json, ...options }) {
const sdk = initSdk(options);
const oracle = await sdk.api.getOracleByPubkey(oracleId);
oracle.queries = (await sdk.api.getOracleQueriesByPubkey(oracleId)).oracleQueries;
const aeSdk = initSdk(options);
const oracle = await aeSdk.api.getOracleByPubkey(oracleId);
oracle.queries = (await aeSdk.api.getOracleQueriesByPubkey(oracleId)).oracleQueries;
if (json) {
print(oracle);
return;
Expand Down
Loading

0 comments on commit 4e04021

Please sign in to comment.