Skip to content

Commit a70ebef

Browse files
committed
refactor: rename sdk to aeSdk in consistency with sdk tests
1 parent 34a00d8 commit a70ebef

18 files changed

+257
-255
lines changed

src/actions/account.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export async function verifyMessage(address, hexSignature, dataArray = [], optio
4242
}
4343

4444
export async function sign(walletPath, tx, { networkId: networkIdOpt, json, ...options }) {
45-
const sdk = await initSdkByWalletFile(walletPath, options);
46-
const networkId = networkIdOpt ?? await sdk.api.getNetworkId();
47-
const signedTx = await sdk.signTransaction(tx, { networkId });
48-
const { address } = sdk;
45+
const aeSdk = await initSdkByWalletFile(walletPath, options);
46+
const networkId = networkIdOpt ?? await aeSdk.api.getNetworkId();
47+
const signedTx = await aeSdk.signTransaction(tx, { networkId });
48+
const { address } = aeSdk;
4949
if (json) {
5050
print({ signedTx, address, networkId });
5151
} else {

src/actions/aens.js

+35-35
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { printTransaction } from '../utils/print.js';
44
import { getNameEntry, validateName } from '../utils/helpers.js';
55
import CliError from '../utils/CliError.js';
66

7-
async function ensureNameStatus(name, sdk, status, operation) {
8-
const nameEntry = await getNameEntry(name, sdk);
7+
async function ensureNameStatus(name, aeSdk, status, operation) {
8+
const nameEntry = await getNameEntry(name, aeSdk);
99
if (nameEntry.status !== status) {
1010
throw new CliError(`AENS name is ${nameEntry.status} and cannot be ${operation}`);
1111
}
@@ -16,23 +16,23 @@ export async function preClaim(walletPath, name, options) {
1616
ttl, fee, nonce, json,
1717
} = options;
1818
validateName(name);
19-
const sdk = await initSdkByWalletFile(walletPath, options);
20-
await ensureNameStatus(name, sdk, 'AVAILABLE', 'preclaimed');
21-
const preClaimTx = await sdk.aensPreclaim(name, { ttl, fee, nonce });
22-
await printTransaction(preClaimTx, json, sdk);
19+
const aeSdk = await initSdkByWalletFile(walletPath, options);
20+
await ensureNameStatus(name, aeSdk, 'AVAILABLE', 'preclaimed');
21+
const preClaimTx = await aeSdk.aensPreclaim(name, { ttl, fee, nonce });
22+
await printTransaction(preClaimTx, json, aeSdk);
2323
}
2424

2525
export async function claim(walletPath, name, salt, options) {
2626
const {
2727
ttl, fee, nonce, json, nameFee,
2828
} = options;
2929
validateName(name);
30-
const sdk = await initSdkByWalletFile(walletPath, options);
31-
await ensureNameStatus(name, sdk, 'AVAILABLE', 'claimed');
32-
const claimTx = await sdk.aensClaim(name, salt, {
30+
const aeSdk = await initSdkByWalletFile(walletPath, options);
31+
await ensureNameStatus(name, aeSdk, 'AVAILABLE', 'claimed');
32+
const claimTx = await aeSdk.aensClaim(name, salt, {
3333
nonce, ttl, fee, nameFee,
3434
});
35-
await printTransaction(claimTx, json, sdk);
35+
await printTransaction(claimTx, json, aeSdk);
3636
}
3737

3838
export async function updateName(walletPath, name, addresses, options) {
@@ -42,29 +42,29 @@ export async function updateName(walletPath, name, addresses, options) {
4242
const invalidAddresses = addresses.filter((address) => !isAddressValid(address));
4343
if (invalidAddresses.length) throw new CliError(`Addresses "[${invalidAddresses}]" is not valid`);
4444
validateName(name);
45-
const sdk = await initSdkByWalletFile(walletPath, options);
46-
await ensureNameStatus(name, sdk, 'CLAIMED', 'updated');
47-
const updateTx = await sdk.aensUpdate(
45+
const aeSdk = await initSdkByWalletFile(walletPath, options);
46+
await ensureNameStatus(name, aeSdk, 'CLAIMED', 'updated');
47+
const updateTx = await aeSdk.aensUpdate(
4848
name,
4949
Object.fromEntries(addresses.map((address) => [getDefaultPointerKey(address), address])),
5050
{
5151
ttl, fee, nonce, nameTtl, clientTtl, extendPointers,
5252
},
5353
);
54-
await printTransaction(updateTx, json, sdk);
54+
await printTransaction(updateTx, json, aeSdk);
5555
}
5656

5757
export async function extendName(walletPath, name, nameTtl, options) {
5858
const {
5959
ttl, fee, nonce, json,
6060
} = options;
6161
validateName(name);
62-
const sdk = await initSdkByWalletFile(walletPath, options);
63-
await ensureNameStatus(name, sdk, 'CLAIMED', 'extended');
64-
const updateTx = await sdk.aensUpdate(name, {}, {
62+
const aeSdk = await initSdkByWalletFile(walletPath, options);
63+
await ensureNameStatus(name, aeSdk, 'CLAIMED', 'extended');
64+
const updateTx = await aeSdk.aensUpdate(name, {}, {
6565
ttl, fee, nonce, nameTtl, extendPointers: true,
6666
});
67-
await printTransaction(updateTx, json, sdk);
67+
await printTransaction(updateTx, json, aeSdk);
6868
}
6969

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

8282
export async function revokeName(walletPath, name, options) {
8383
const {
8484
ttl, fee, nonce, json,
8585
} = options;
8686
validateName(name);
87-
const sdk = await initSdkByWalletFile(walletPath, options);
88-
await ensureNameStatus(name, sdk, 'CLAIMED', 'revoked');
89-
const revokeTx = await sdk.aensRevoke(name, { ttl, fee, nonce });
90-
await printTransaction(revokeTx, json, sdk);
87+
const aeSdk = await initSdkByWalletFile(walletPath, options);
88+
await ensureNameStatus(name, aeSdk, 'CLAIMED', 'revoked');
89+
const revokeTx = await aeSdk.aensRevoke(name, { ttl, fee, nonce });
90+
await printTransaction(revokeTx, json, aeSdk);
9191
}
9292

9393
export async function nameBid(walletPath, name, nameFee, options) {
9494
const {
9595
ttl, fee, nonce, json,
9696
} = options;
9797
validateName(name);
98-
const sdk = await initSdkByWalletFile(walletPath, options);
99-
await ensureNameStatus(name, sdk, 'AUCTION', 'bidded');
100-
const nameBidTx = await sdk.aensBid(name, nameFee, { nonce, ttl, fee });
101-
await printTransaction(nameBidTx, json, sdk);
98+
const aeSdk = await initSdkByWalletFile(walletPath, options);
99+
await ensureNameStatus(name, aeSdk, 'AUCTION', 'bidded');
100+
const nameBidTx = await aeSdk.aensBid(name, nameFee, { nonce, ttl, fee });
101+
await printTransaction(nameBidTx, json, aeSdk);
102102
}
103103

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

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

120120
nonce = nonce && nonce + 1;
121121
const updateTx = await nameInstance.update(
122-
{ account_pubkey: sdk.address },
122+
{ account_pubkey: aeSdk.address },
123123
{
124124
nonce, ttl, fee, nameTtl, clientTtl,
125125
},
126126
);
127-
await printTransaction(updateTx, json, sdk);
127+
await printTransaction(updateTx, json, aeSdk);
128128
}

src/actions/chain.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { getBlock } from '../utils/helpers.js';
77

88
export async function status(options) {
99
const { json } = options;
10-
const sdk = initSdk(options);
11-
const st = await sdk.api.getStatus();
12-
const { consensusProtocolVersion } = await sdk.getNodeInfo();
10+
const aeSdk = initSdk(options);
11+
const st = await aeSdk.api.getStatus();
12+
const { consensusProtocolVersion } = await aeSdk.getNodeInfo();
1313
if (json) {
1414
print(st);
1515
return;
@@ -28,8 +28,8 @@ export async function status(options) {
2828
}
2929

3030
export async function ttl(_absoluteTtl, { json, ...options }) {
31-
const sdk = initSdk(options);
32-
const height = await sdk.getHeight();
31+
const aeSdk = initSdk(options);
32+
const height = await aeSdk.getHeight();
3333
const absoluteTtl = +_absoluteTtl;
3434
const relativeTtl = absoluteTtl - height;
3535
if (json) {
@@ -41,38 +41,38 @@ export async function ttl(_absoluteTtl, { json, ...options }) {
4141
}
4242

4343
export async function top({ json, ...options }) {
44-
const sdk = initSdk(options);
45-
printBlock(await sdk.api.getTopHeader(), json, true);
44+
const aeSdk = initSdk(options);
45+
printBlock(await aeSdk.api.getTopHeader(), json, true);
4646
}
4747

4848
export async function play(options) {
4949
let { height, limit, json } = options;
5050
limit = +limit;
5151
height = +height;
52-
const sdk = initSdk(options);
53-
let block = await sdk.api.getTopHeader();
52+
const aeSdk = initSdk(options);
53+
let block = await aeSdk.api.getTopHeader();
5454
while (height ? block.height >= height : limit) {
5555
if (!height) limit -= 1;
5656
printBlock(block, json);
57-
block = await getBlock(block.prevHash, sdk); // eslint-disable-line no-await-in-loop
57+
block = await getBlock(block.prevHash, aeSdk); // eslint-disable-line no-await-in-loop
5858
}
5959
}
6060

6161
export async function broadcast(signedTx, options) {
6262
const { json, waitMined, verify } = options;
63-
const sdk = initSdk(options);
63+
const aeSdk = initSdk(options);
6464

6565
if (verify) {
66-
const validation = await verifyTransaction(signedTx, sdk.api);
66+
const validation = await verifyTransaction(signedTx, aeSdk.api);
6767
if (validation.length) {
6868
printValidation({ validation, transaction: signedTx });
6969
return;
7070
}
7171
}
7272

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

76-
await printTransaction(tx, json, sdk);
76+
await printTransaction(tx, json, aeSdk);
7777
if (!waitMined && !json) print('Transaction send to the chain.');
7878
}

src/actions/contract.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ async function getContractParams({
3232
}
3333

3434
export async function compile(contractSource, options) {
35-
const sdk = initSdk(options);
36-
const contract = await sdk.initializeContract({ sourceCodePath: contractSource });
35+
const aeSdk = initSdk(options);
36+
const contract = await aeSdk.initializeContract({ sourceCodePath: contractSource });
3737
const bytecode = await contract.$compile();
3838
if (options.json) print({ bytecode });
3939
else print(`Contract bytecode: ${bytecode}`);
4040
}
4141

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

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

6565
export async function deploy(walletPath, args, options) {
66-
const sdk = await initSdkByWalletFile(walletPath, options);
67-
const contract = await sdk.initializeContract(await getContractParams(options, { descrMayNotExist: true }));
66+
const aeSdk = await initSdkByWalletFile(walletPath, options);
67+
const contract = await aeSdk.initializeContract(await getContractParams(options, { descrMayNotExist: true }));
6868
const result = await contract.$deploy(args, options);
6969
const filename = options.contractSource ?? options.contractBytecode;
7070
options.descrPath ??= getFullPath(`${filename}.deploy.${result.address.slice(3)}.json`);
@@ -92,8 +92,8 @@ export async function call(fn, args, walletPath, options) {
9292
if (callStatic !== true && walletPath == null) {
9393
throw new CliError('wallet_path is required for on-chain calls');
9494
}
95-
const sdk = await initSdkByWalletFile(walletPath, options);
96-
const contract = await sdk.initializeContract(await getContractParams(options));
95+
const aeSdk = await initSdkByWalletFile(walletPath, options);
96+
const contract = await aeSdk.initializeContract(await getContractParams(options));
9797
const callResult = await contract.$call(fn, args, {
9898
ttl: ttl && +ttl,
9999
gas,
@@ -105,7 +105,7 @@ export async function call(fn, args, walletPath, options) {
105105
});
106106
if (json) print(callResult);
107107
else {
108-
await printTransaction(callResult.txData, json, sdk);
108+
await printTransaction(callResult.txData, json, aeSdk);
109109
print('----------------------Call info-----------------------');
110110
const gasCoins = BigInt(callResult.result.gasUsed) * callResult.txData.tx.gasPrice;
111111
printUnderscored('Gas used', `${callResult.result.gasUsed} (${formatCoins(gasCoins)})`);

src/actions/inspect.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ function printEntries(object) {
1818

1919
async function getBlockByHash(hash, { json, ...options }) {
2020
checkPref(hash, [Encoding.KeyBlockHash, Encoding.MicroBlockHash]);
21-
const sdk = initSdk(options);
22-
printBlock(await getBlock(hash, sdk), json, true);
21+
const aeSdk = initSdk(options);
22+
printBlock(await getBlock(hash, aeSdk), json, true);
2323
}
2424

2525
async function getTransactionByHash(hash, { json, ...options }) {
2626
checkPref(hash, Encoding.TxHash);
27-
const sdk = initSdk(options);
28-
await printTransaction(await sdk.api.getTransactionByHash(hash), json, sdk);
27+
const aeSdk = initSdk(options);
28+
await printTransaction(await aeSdk.api.getTransactionByHash(hash), json, aeSdk);
2929
}
3030

3131
async function unpackTx(encodedTx, { json }) {
@@ -38,10 +38,10 @@ async function unpackTx(encodedTx, { json }) {
3838

3939
async function getAccountByHash(hash, { json, ...options }) {
4040
checkPref(hash, Encoding.AccountAddress);
41-
const sdk = initSdk(options);
42-
const { nonce } = await sdk.api.getAccountByPubkey(hash);
43-
const balance = await sdk.getBalance(hash);
44-
const { transactions } = await sdk.api.getPendingAccountTransactionsByPubkey(hash);
41+
const aeSdk = initSdk(options);
42+
const { nonce } = await aeSdk.api.getAccountByPubkey(hash);
43+
const balance = await aeSdk.getBalance(hash);
44+
const { transactions } = await aeSdk.api.getPendingAccountTransactionsByPubkey(hash);
4545
if (json) {
4646
print({
4747
hash,
@@ -59,21 +59,21 @@ async function getAccountByHash(hash, { json, ...options }) {
5959
}
6060

6161
async function getBlockByHeight(height, { json, ...options }) {
62-
const sdk = initSdk(options);
63-
printBlock(await sdk.api.getKeyBlockByHeight(+height), json);
62+
const aeSdk = initSdk(options);
63+
printBlock(await aeSdk.api.getKeyBlockByHeight(+height), json);
6464
}
6565

6666
async function getName(name, { json, ...options }) {
6767
validateName(name);
68-
const sdk = initSdk(options);
69-
const nameEntry = await getNameEntry(name, sdk);
68+
const aeSdk = initSdk(options);
69+
const nameEntry = await getNameEntry(name, aeSdk);
7070

7171
if (json) {
7272
print(nameEntry);
7373
return;
7474
}
7575

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

100100
async function getContract(contractId, { json, ...options }) {
101-
const sdk = initSdk(options);
102-
const contract = await sdk.api.getContract(contractId);
101+
const aeSdk = initSdk(options);
102+
const contract = await aeSdk.api.getContract(contractId);
103103
if (json) print(contract);
104104
else printEntries(contract);
105105
}
106106

107107
async function getOracle(oracleId, { json, ...options }) {
108-
const sdk = initSdk(options);
109-
const oracle = await sdk.api.getOracleByPubkey(oracleId);
110-
oracle.queries = (await sdk.api.getOracleQueriesByPubkey(oracleId)).oracleQueries;
108+
const aeSdk = initSdk(options);
109+
const oracle = await aeSdk.api.getOracleByPubkey(oracleId);
110+
oracle.queries = (await aeSdk.api.getOracleQueriesByPubkey(oracleId)).oracleQueries;
111111
if (json) {
112112
print(oracle);
113113
return;

0 commit comments

Comments
 (0)