Skip to content

Commit

Permalink
feat!: narrow first column and remove _ in tables
Browse files Browse the repository at this point in the history
BREAKING CHANGE: tables aligned without `_` char, first column narrowed
  • Loading branch information
davidyuk committed Jan 25, 2025
1 parent 16f2f76 commit 0bd2b62
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 379 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ The next step is to create a wallet to use in other commands:

```
$ aecli account create ./wallet.json
Address _________________________________ ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Path ____________________________________ /path/to/wallet.json
Address ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Path /path/to/wallet.json
```

<!-- WALLET-CREATE-END -->
Expand All @@ -67,9 +67,9 @@ Run `$ aecli inspect <wallet address>` to ensure that it got coins.

```
$ aecli inspect ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Account ID ______________________________ ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Account balance _________________________ 10000ae
Account nonce ___________________________ 0
Account ID ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Account balance 10000ae
Account nonce 0
No pending transactions
```

Expand All @@ -82,18 +82,18 @@ At the last step, we will send our coins to another account:
```
$ aecli spend ./wallet.json ak_AgV756Vfo99juwzNVgnjP1gXX1op1QN3NXTxvkPnHJPUDE8NT 42ae
Transaction mined
Transaction hash ________________________ th_2muLsbZeFaVJ3tePTnLqobPhxBzwFsm1zUv8sjgMX4LKuevX2T
Block hash ______________________________ mh_dnoULQWpiRtcrntd5yJPUxcu7YrTu18xZ1e9EC2b8prKdShME
Block height ____________________________ 2 (about now)
Signatures ______________________________ ["sg_SG5uW5KEGiy5iG1cCkKq4VEdpyvewcW4NjVf4vj2ZoCiap5iB7UQoknWpyWsD4FkziBuGPE88zwXemq3ZvPrdzNtXtKuD"]
Transaction type ________________________ SpendTx (ver. 1)
Sender address __________________________ ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Recipient address _______________________ ak_AgV756Vfo99juwzNVgnjP1gXX1op1QN3NXTxvkPnHJPUDE8NT
Amount __________________________________ 42ae
Payload _________________________________ ba_Xfbg4g==
Fee _____________________________________ 0.00001684ae
Nonce ___________________________________ 1
TTL _____________________________________ 4 (about now)
Transaction hash th_2muLsbZeFaVJ3tePTnLqobPhxBzwFsm1zUv8sjgMX4LKuevX2T
Block hash mh_dnoULQWpiRtcrntd5yJPUxcu7YrTu18xZ1e9EC2b8prKdShME
Block height 2 (about now)
Signatures ["sg_SG5uW5KEGiy5iG1cCkKq4VEdpyvewcW4NjVf4vj2ZoCiap5iB7UQoknWpyWsD4FkziBuGPE88zwXemq3ZvPrdzNtXtKuD"]
Transaction type SpendTx (ver. 1)
Sender address ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E
Recipient address ak_AgV756Vfo99juwzNVgnjP1gXX1op1QN3NXTxvkPnHJPUDE8NT
Amount 42ae
Payload ba_Xfbg4g==
Fee 0.00001684ae
Nonce 1
TTL 4 (about now)
```

<!-- SPEND-END -->
Expand Down
4 changes: 4 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export default [
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
files: ['test/*.js'],
rules: { 'no-regex-spaces': 'off' },
},
];
14 changes: 7 additions & 7 deletions src/actions/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ function buildAndPrintTx(params, json, extraKeys = {}) {
print({ tx, txObject, ...extraKeys });
return;
}
printTable([['Transaction type', Tag[params.tag]]]);
print('Summary');
// TODO: print the same way as transactions from node
printTable(
Object.entries({ ...txObject, ...extraKeys }).map(([key, value]) => [
printTable([
['Transaction type', Tag[params.tag]],
['Summary', ''],
...Object.entries({ ...txObject, ...extraKeys }).map(([key, value]) => [
` ${key.toUpperCase()}`,
value,
]),
);
print('Output');
printTable([[' Encoded', tx]]);
['Output', ''],
[' Encoded', tx],
]);
print(
'This is an unsigned transaction. Use `account sign` and `tx broadcast` to submit the transaction to the network, or verify that it will be accepted with `tx verify`.',
);
Expand Down
20 changes: 6 additions & 14 deletions src/utils/print.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Encoding, unpackTx, AbiVersion, VmVersion } from '@aeternity/aepp-sdk';
import { decode, formatCoins, formatTtl as formatTtlUnbound, formatSeconds } from './helpers.js';

const ROW_WIDTH = 40;

const JsonStringifyEs = (object, spaced) =>
JSON.stringify(
object,
Expand All @@ -27,19 +25,13 @@ export function print(msg, obj) {
}
}

function printUnderscored(key, val) {
print(
[
key,
'_'.repeat(ROW_WIDTH - key.length),
typeof val !== 'object' ? val : JsonStringifyEs(val),
].join(' '),
);
}

export function printTable(data) {
for (const row of data) {
printUnderscored(...row);
const firstColumnWidth = Math.max(...data.map(([key]) => key.length));
for (const [key, val] of data) {
console.log(
key.padEnd(firstColumnWidth + 1),
typeof val !== 'object' ? val : JsonStringifyEs(val),
);
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ describe('Account Module', () => {
const resJson = await executeAccount('address', walletName, '--json');
expect(resJson.publicKey).to.be.a('string');
expectToMatchLines(createRes, [
`Address _________________________________ ${resJson.publicKey}`,
`Path ____________________________________ ${resolve(walletName)}`,
`Address ${resJson.publicKey}`,
`Path ${resolve(walletName)}`,
]);
const res = await executeAccount('address', walletName);
expectToMatchLines(res, [`Address _________________________________ ${resJson.publicKey}`]);
expectToMatchLines(res, [`Address ${resJson.publicKey}`]);
});

it('Create Wallet From Private Key', async () => {
Expand Down Expand Up @@ -116,8 +116,8 @@ describe('Account Module', () => {
'--forcePrompt',
);
expectToMatchLines(res, [
`Address _________________________________ ${keypair.publicKey}`,
`Secret Key ______________________________ ${keypair.secretKey}`,
`Address ${keypair.publicKey}`,
`Secret Key ${keypair.secretKey}`,
]);
});

Expand Down
49 changes: 23 additions & 26 deletions test/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ describe('Chain Module', () => {
const res = await executeChain('top');
expectToMatchLines(res, [
`<<--------------- ${resJson.hash.startsWith('mh_') ? 'MicroBlock' : 'KeyBlock'} --------------->>`,
`Block hash ______________________________ ${resJson.hash}`,
`Block height ____________________________ ${resJson.height}`,
`State hash ______________________________ ${resJson.stateHash}`,
`Nonce ___________________________________ ${resJson.nonce ?? 'N/A'}`,
`Miner ___________________________________ ${resJson.miner ?? 'N/A'}`,
`Time ____________________________________ ${new Date(resJson.time).toString()}`,
`Previous block hash _____________________ ${resJson.prevHash}`,
`Previous key block hash _________________ ${resJson.prevKeyHash}`,
`Version _________________________________ 6`,
`Target __________________________________ ${resJson.target ?? 'N/A'}`,
`Transactions ____________________________ 0`,
`Block hash ${resJson.hash}`,
`Block height ${resJson.height}`,
`State hash ${resJson.stateHash}`,
`Nonce ${resJson.nonce ?? 'N/A'}`,
`Miner ${resJson.miner ?? 'N/A'}`,
`Time ${new Date(resJson.time).toString()}`,
`Previous block hash ${resJson.prevHash}`,
`Previous key block hash ${resJson.prevKeyHash}`,
`Version 6`,
`Target ${resJson.target ?? 'N/A'}`,
`Transactions 0`,
]);
});

Expand Down Expand Up @@ -65,17 +65,17 @@ describe('Chain Module', () => {

const res = await executeChain('status');
expectToMatchLines(res, [
`Difficulty ______________________________ ${resJson.difficulty}`,
`Node version ____________________________ 7.3.0-rc3`,
`Consensus protocol version ______________ 6 (Ceres)`,
`Node revision ___________________________ 57bc00b760dbb3ccd10be51f447e33cb3a2f56e3`,
`Genesis hash ____________________________ ${resJson.genesisKeyBlockHash}`,
`Network ID ______________________________ ae_dev`,
`Listening _______________________________ true`,
`Peer count ______________________________ 0`,
`Pending transactions count ______________ 0`,
`Solutions _______________________________ 0`,
`Syncing _________________________________ false`,
`Difficulty ${resJson.difficulty}`,
`Node version 7.3.0-rc3`,
`Consensus protocol version 6 (Ceres)`,
`Node revision 57bc00b760dbb3ccd10be51f447e33cb3a2f56e3`,
`Genesis hash ${resJson.genesisKeyBlockHash}`,
`Network ID ae_dev`,
`Listening true`,
`Peer count 0`,
`Pending transactions count 0`,
`Solutions 0`,
`Syncing false`,
]);
});

Expand Down Expand Up @@ -103,9 +103,6 @@ describe('Chain Module', () => {
});

const res = await executeChain('ttl', 10);
expectToMatchLines(res, [
`Absolute TTL ____________________________ 10`,
`Relative TTL ____________________________ ${resJson.relativeTtl}`,
]);
expectToMatchLines(res, [`Absolute TTL 10`, `Relative TTL ${resJson.relativeTtl}`]);
});
});
Loading

0 comments on commit 0bd2b62

Please sign in to comment.