@cardano-sdk/golden-test-generator 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/dist/AddressBalance/applyValue.d.ts +3 -0
- package/dist/AddressBalance/applyValue.d.ts.map +1 -0
- package/dist/AddressBalance/applyValue.js +30 -0
- package/dist/AddressBalance/applyValue.js.map +1 -0
- package/dist/AddressBalance/getOnChainAddressBalances.d.ts +17 -0
- package/dist/AddressBalance/getOnChainAddressBalances.d.ts.map +1 -0
- package/dist/AddressBalance/getOnChainAddressBalances.js +98 -0
- package/dist/AddressBalance/getOnChainAddressBalances.js.map +1 -0
- package/{src/AddressBalance/index.ts → dist/AddressBalance/index.d.ts} +1 -0
- package/dist/AddressBalance/index.d.ts.map +1 -0
- package/dist/AddressBalance/index.js +15 -0
- package/dist/AddressBalance/index.js.map +1 -0
- package/dist/Block/getBlocks.d.ts +14 -0
- package/dist/Block/getBlocks.d.ts.map +1 -0
- package/dist/Block/getBlocks.js +76 -0
- package/dist/Block/getBlocks.js.map +1 -0
- package/dist/Block/index.d.ts +2 -0
- package/dist/Block/index.d.ts.map +1 -0
- package/dist/Block/index.js +14 -0
- package/dist/Block/index.js.map +1 -0
- package/dist/Content.d.ts +23 -0
- package/dist/Content.d.ts.map +1 -0
- package/dist/Content.js +24 -0
- package/dist/Content.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -0
- package/dist/util.d.ts +9 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +14 -0
- package/dist/util.js.map +1 -0
- package/package.json +11 -2
- package/jest.config.js +0 -1
- package/src/.eslintrc.js +0 -7
- package/src/AddressBalance/applyValue.ts +0 -31
- package/src/AddressBalance/getOnChainAddressBalances.ts +0 -137
- package/src/Block/getBlocks.ts +0 -101
- package/src/Block/index.ts +0 -1
- package/src/Content.ts +0 -43
- package/src/index.ts +0 -127
- package/src/tsconfig.json +0 -10
- package/src/util.ts +0 -15
- package/test/.eslintrc.js +0 -7
- package/test/AddressBalance.test.ts +0 -184
- package/test/tsconfig.json +0 -10
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
|
+
const object_hash_1 = __importDefault(require("object-hash"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const cli_progress_1 = require("cli-progress");
|
|
12
|
+
const fs_extra_1 = require("fs-extra");
|
|
13
|
+
const json_bigint_1 = __importDefault(require("json-bigint"));
|
|
14
|
+
const AddressBalance_1 = require("./AddressBalance");
|
|
15
|
+
const Block_1 = require("./Block");
|
|
16
|
+
const Content_1 = require("./Content");
|
|
17
|
+
const clear = require('clear');
|
|
18
|
+
const packageJson = require('../package.json');
|
|
19
|
+
clear();
|
|
20
|
+
console.log(chalk_1.default.blue('Cardano Golden Test Generator'));
|
|
21
|
+
const createProgressBar = (lastblockHeight) => new cli_progress_1.SingleBar({
|
|
22
|
+
barCompleteChar: '\u2588',
|
|
23
|
+
barIncompleteChar: '\u2591',
|
|
24
|
+
format: `Syncing from genesis to block ${lastblockHeight} | ${chalk_1.default.blue('{bar}')} | {percentage}% || {value}/{total} Blocks`,
|
|
25
|
+
hideCursor: true,
|
|
26
|
+
renderThrottle: 300
|
|
27
|
+
});
|
|
28
|
+
const program = new commander_1.Command('cardano-golden-test-generator');
|
|
29
|
+
program
|
|
30
|
+
.option('--ogmios-host [ogmiosHost]', 'Ogmios host. Defaults to localhost')
|
|
31
|
+
.option('--ogmios-port [ogmiosPort]', 'Ogmios TCP port. Defaults to 1337', (port) => Number.parseInt(port))
|
|
32
|
+
.option('--ogmios-tls [ogmiosTls]', 'Is Ogmios being served over a secure connection?. Defaults to false', (port) => Number.parseInt(port));
|
|
33
|
+
program
|
|
34
|
+
.command('address-balance')
|
|
35
|
+
.description('Balance of addresses, determined by syncing the chain from genesis')
|
|
36
|
+
.argument('[addresses]', 'Comma-separated list of addresses', (addresses) => addresses.split(',').filter((a) => a !== ''))
|
|
37
|
+
.requiredOption('--at-blocks [atBlocks]', 'Balance of the addresses at block heights', (heights) => heights
|
|
38
|
+
.split(',')
|
|
39
|
+
.filter((b) => b !== '')
|
|
40
|
+
.map((height) => Number.parseInt(height)))
|
|
41
|
+
.requiredOption('--out-dir [outDir]', 'File path to write results to')
|
|
42
|
+
.action(async (addresses, { atBlocks, outDir }) => {
|
|
43
|
+
try {
|
|
44
|
+
const { ogmiosHost, ogmiosPort, ogmiosTls } = program.opts();
|
|
45
|
+
const atBlockHeights = atBlocks.sort((a, b) => a - b);
|
|
46
|
+
const lastBlockHeight = atBlockHeights[atBlockHeights.length - 1];
|
|
47
|
+
const progress = createProgressBar(lastBlockHeight);
|
|
48
|
+
await fs_extra_1.ensureDir(outDir);
|
|
49
|
+
progress.start(lastBlockHeight, 0);
|
|
50
|
+
const { balances, metadata } = await AddressBalance_1.getOnChainAddressBalances(addresses, atBlockHeights, {
|
|
51
|
+
ogmiosConnectionConfig: { host: ogmiosHost, port: ogmiosPort, tls: ogmiosTls },
|
|
52
|
+
onBlock: (blockHeight) => {
|
|
53
|
+
progress.update(blockHeight);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const content = await Content_1.prepareContent(metadata, balances);
|
|
57
|
+
progress.stop();
|
|
58
|
+
const fileName = node_path_1.default.join(outDir, `address-balances-${object_hash_1.default(content)}.json`);
|
|
59
|
+
console.log(`Writing ${fileName}`);
|
|
60
|
+
await fs_extra_1.writeFile(fileName, json_bigint_1.default.stringify(content, undefined, 2));
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(error);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
program
|
|
69
|
+
.command('get-block')
|
|
70
|
+
.description('Dump the requested blocks in their raw structure')
|
|
71
|
+
.argument('[blockHeights]', 'Comma-separated list of blocks by number', (blockHeights) => blockHeights
|
|
72
|
+
.split(',')
|
|
73
|
+
.filter((b) => b !== '')
|
|
74
|
+
.map((blockHeight) => Number.parseInt(blockHeight)))
|
|
75
|
+
.requiredOption('--out-dir [outDir]', 'File path to write results to')
|
|
76
|
+
.action(async (blockHeights, { outDir }) => {
|
|
77
|
+
try {
|
|
78
|
+
const { ogmiosHost, ogmiosPort, ogmiosTls } = program.opts();
|
|
79
|
+
const sortedblockHeights = blockHeights.sort((a, b) => a - b);
|
|
80
|
+
const lastblockHeight = sortedblockHeights[sortedblockHeights.length - 1];
|
|
81
|
+
const progress = createProgressBar(lastblockHeight);
|
|
82
|
+
await fs_extra_1.ensureDir(outDir);
|
|
83
|
+
progress.start(lastblockHeight, 0);
|
|
84
|
+
const { blocks, metadata } = await Block_1.getBlocks(sortedblockHeights, {
|
|
85
|
+
logger: console,
|
|
86
|
+
ogmiosConnectionConfig: { host: ogmiosHost, port: ogmiosPort, tls: ogmiosTls },
|
|
87
|
+
onBlock: (blockHeight) => {
|
|
88
|
+
progress.update(blockHeight);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
progress.stop();
|
|
92
|
+
const content = await Content_1.prepareContent(metadata, blocks);
|
|
93
|
+
const fileName = node_path_1.default.join(outDir, `blocks-${object_hash_1.default(content)}.json`);
|
|
94
|
+
console.log(`Writing ${fileName}`);
|
|
95
|
+
await fs_extra_1.writeFile(fileName, json_bigint_1.default.stringify(content, undefined, 2));
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error(error);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
program.version(packageJson.version);
|
|
104
|
+
if (process.argv.slice(2).length === 0) {
|
|
105
|
+
program.outputHelp();
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
program.parseAsync(process.argv).catch((error) => {
|
|
110
|
+
console.error(error);
|
|
111
|
+
process.exit(0);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAC1B,yCAAoC;AACpC,8DAA+B;AAC/B,0DAA6B;AAC7B,+CAAkD;AAClD,uCAAgD;AAChD,8DAAkC;AAClC,qDAAsF;AACtF,mCAAuD;AACvD,uCAA2C;AAE3C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE/C,KAAK,EAAE,CAAC;AACR,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC,CAAC;AAEzD,MAAM,iBAAiB,GAAG,CAAC,eAAuB,EAAE,EAAE,CACpD,IAAI,wBAAS,CAAC;IACZ,eAAe,EAAE,QAAQ;IACzB,iBAAiB,EAAE,QAAQ;IAC3B,MAAM,EAAE,iCAAiC,eAAe,MAAM,eAAK,CAAC,IAAI,CACtE,OAAO,CACR,4CAA4C;IAC7C,UAAU,EAAE,IAAI;IAChB,cAAc,EAAE,GAAG;CACT,CAAC,CAAC;AAEhB,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,+BAA+B,CAAC,CAAC;AAE7D,OAAO;KACJ,MAAM,CAAC,4BAA4B,EAAE,oCAAoC,CAAC;KAC1E,M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AC,CAAC;QACpF,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,qBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEnE,OAAO,CAAC,GAAG,CAAC,WAAW,QAAQ,EAAE,CAAC,CAAC;QACnC,MAAM,oBAAS,CAAC,QAAQ,EAAE,qBAAO,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACrC,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;IACtC,OAAO,CAAC,UAAU,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;KAAM;IACL,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QAC/C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schema } from '@cardano-ogmios/client';
|
|
2
|
+
export declare const isByronStandardBlock: (block: Schema.Block) => block is {
|
|
3
|
+
byron: Schema.StandardBlock;
|
|
4
|
+
};
|
|
5
|
+
export declare const isByronEpochBoundaryBlock: (block: Schema.Block) => block is {
|
|
6
|
+
byron: Schema.EpochBoundaryBlock;
|
|
7
|
+
};
|
|
8
|
+
export declare const getLastCommitPromise: () => Promise<import("git-last-commit").Commit>;
|
|
9
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAMhD,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAK;WAAqB,OAAO,aAAa;CACpB,CAAC;AAE9E,eAAO,MAAM,yBAAyB,UAAW,OAAO,KAAK;WAAqB,OAAO,kBAAkB;CAG1G,CAAC;AAEF,eAAO,MAAM,oBAAoB,iDAA2B,CAAC"}
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLastCommitPromise = exports.isByronEpochBoundaryBlock = exports.isByronStandardBlock = void 0;
|
|
4
|
+
const git_last_commit_1 = require("git-last-commit");
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
const isByronStandardBlock = (block) => block.byron?.header.slot !== undefined;
|
|
7
|
+
exports.isByronStandardBlock = isByronStandardBlock;
|
|
8
|
+
const isByronEpochBoundaryBlock = (block) => {
|
|
9
|
+
const castBlock = block;
|
|
10
|
+
return castBlock.byron?.hash !== undefined && castBlock.byron?.header.epoch !== undefined;
|
|
11
|
+
};
|
|
12
|
+
exports.isByronEpochBoundaryBlock = isByronEpochBoundaryBlock;
|
|
13
|
+
exports.getLastCommitPromise = util_1.promisify(git_last_commit_1.getLastCommit);
|
|
14
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AACA,qDAAgD;AAEhD,+BAAiC;AAG1B,MAAM,oBAAoB,GAAG,CAAC,KAAmB,EAA4C,EAAE,CACnG,KAAyC,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC;AADjE,QAAA,oBAAoB,wBAC6C;AAEvE,MAAM,yBAAyB,GAAG,CAAC,KAAmB,EAAiD,EAAE;IAC9G,MAAM,SAAS,GAAG,KAA6C,CAAC;IAChE,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC;AAC5F,CAAC,CAAC;AAHW,QAAA,yBAAyB,6BAGpC;AAEW,QAAA,oBAAoB,GAAG,gBAAS,CAAC,+BAAa,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardano-sdk/golden-test-generator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Generate golden test files for a range of Cardano concepts",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^14"
|
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
"cleanup": "shx rm -rf dist node_modules",
|
|
17
17
|
"dev": "API_PORT=3000 OGMIOS_HOST=localhost OGMIOS_PORT=1337 ts-node-dev ./src/index.ts",
|
|
18
18
|
"lint": "shx echo linting disabled in this package temporarily",
|
|
19
|
+
"lint:fix": "shx echo linting disabled in this package temporarily",
|
|
19
20
|
"prepkg": "yarn build",
|
|
20
21
|
"pkg": "yarn build && pkg -o build/golden-test-generator .",
|
|
21
22
|
"prestart": "yarn build",
|
|
22
23
|
"start": "API_PORT=3000 OGMIOS_HOST=localhost OGMIOS_PORT=1337 ts-node ./src/index.ts",
|
|
24
|
+
"prepack": "yarn build",
|
|
23
25
|
"pretest": "yarn build",
|
|
24
26
|
"test": "jest -c ./jest.config.js",
|
|
27
|
+
"test:e2e": "shx echo 'test:e2e' command not implemented yet",
|
|
25
28
|
"coverage": "shx echo No coverage report for this package"
|
|
26
29
|
},
|
|
27
30
|
"dependencies": {
|
|
@@ -49,5 +52,11 @@
|
|
|
49
52
|
"node14-linux-x64",
|
|
50
53
|
"node14-macos-x64"
|
|
51
54
|
]
|
|
52
|
-
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist/*",
|
|
58
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
59
|
+
"LICENSE",
|
|
60
|
+
"NOTICE"
|
|
61
|
+
]
|
|
53
62
|
}
|
package/jest.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../../test/jest.config');
|
package/src/.eslintrc.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* eslint-disable prettier/prettier */
|
|
2
|
-
import { Schema } from '@cardano-ogmios/client';
|
|
3
|
-
import { BigIntMath } from '@cardano-sdk/core';
|
|
4
|
-
|
|
5
|
-
const throwIfNegative = (value: bigint | number): void => {
|
|
6
|
-
if (value < 0) {
|
|
7
|
-
throw new Error('The value provided cannot be applied as it will result in a negative balance');
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
12
|
-
export const applyValue = (balance: Schema.Value, value: Schema.Value, spending = false): Schema.Value => {
|
|
13
|
-
const coins = balance.coins + (spending ? -Math.abs(value.coins) : value.coins);
|
|
14
|
-
throwIfNegative(coins);
|
|
15
|
-
const balanceToApply: Schema.Value = { coins };
|
|
16
|
-
if (balance.assets !== undefined || value.assets !== undefined) {
|
|
17
|
-
balanceToApply.assets = { ...balance.assets } ?? {};
|
|
18
|
-
}
|
|
19
|
-
const assets = Object.entries(value.assets ?? {});
|
|
20
|
-
if (assets.length > 0) {
|
|
21
|
-
for (const [assetId, qty] of assets) {
|
|
22
|
-
balanceToApply.assets![assetId] =
|
|
23
|
-
balance.assets![assetId] !== undefined
|
|
24
|
-
? balance.assets![assetId] + (spending ? -BigIntMath.abs(qty) : qty)
|
|
25
|
-
: (spending ? -BigIntMath.abs(qty) : qty);
|
|
26
|
-
throwIfNegative(balanceToApply.assets![assetId]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return balanceToApply;
|
|
31
|
-
};
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/* eslint-disable complexity */
|
|
2
|
-
import { dummyLogger, Logger } from 'ts-log';
|
|
3
|
-
import {
|
|
4
|
-
createChainSyncClient,
|
|
5
|
-
StateQuery,
|
|
6
|
-
isAllegraBlock,
|
|
7
|
-
isAlonzoBlock,
|
|
8
|
-
isShelleyBlock,
|
|
9
|
-
isMaryBlock,
|
|
10
|
-
Schema,
|
|
11
|
-
ConnectionConfig,
|
|
12
|
-
createInteractionContext,
|
|
13
|
-
ChainSync
|
|
14
|
-
} from '@cardano-ogmios/client';
|
|
15
|
-
import { GeneratorMetadata } from '../Content';
|
|
16
|
-
import { isByronStandardBlock } from '../util';
|
|
17
|
-
import { applyValue } from './applyValue';
|
|
18
|
-
|
|
19
|
-
export type AddressBalances = {
|
|
20
|
-
[address: string]: Schema.Value;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type AddressBalancesResponse = GeneratorMetadata & {
|
|
24
|
-
balances: { [blockHeight: string]: AddressBalances };
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const getOnChainAddressBalances = (
|
|
28
|
-
addresses: string[],
|
|
29
|
-
atBlocks: number[],
|
|
30
|
-
options: {
|
|
31
|
-
logger?: Logger;
|
|
32
|
-
ogmiosConnectionConfig: ConnectionConfig;
|
|
33
|
-
onBlock?: (slot: number) => void;
|
|
34
|
-
}
|
|
35
|
-
): Promise<AddressBalancesResponse> => {
|
|
36
|
-
const logger = options?.logger ?? dummyLogger;
|
|
37
|
-
const trackedAddressBalances: AddressBalances = Object.fromEntries(
|
|
38
|
-
addresses.map((address) => [address, { coins: 0, assets: {} }])
|
|
39
|
-
);
|
|
40
|
-
const trackedTxs: ({ id: Schema.Hash16 } & Schema.Tx)[] = [];
|
|
41
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
42
|
-
return new Promise(async (resolve, reject) => {
|
|
43
|
-
let currentBlock: number;
|
|
44
|
-
// Required to ensure existing messages in the pipe are not processed after the completion
|
|
45
|
-
// condition is met
|
|
46
|
-
let draining = false;
|
|
47
|
-
const response: AddressBalancesResponse = {
|
|
48
|
-
metadata: {
|
|
49
|
-
cardano: {
|
|
50
|
-
compactGenesis: await StateQuery.genesisConfig(
|
|
51
|
-
await createInteractionContext(reject, logger.info, { connection: options.ogmiosConnectionConfig })
|
|
52
|
-
),
|
|
53
|
-
intersection: undefined as unknown as ChainSync.Intersection
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
balances: {}
|
|
57
|
-
};
|
|
58
|
-
try {
|
|
59
|
-
const syncClient = await createChainSyncClient(
|
|
60
|
-
await createInteractionContext(reject, logger.info, { connection: options.ogmiosConnectionConfig }),
|
|
61
|
-
{
|
|
62
|
-
rollBackward: async (_res, requestNext) => {
|
|
63
|
-
requestNext();
|
|
64
|
-
},
|
|
65
|
-
// eslint-disable-next-line max-statements
|
|
66
|
-
rollForward: async ({ block }, requestNext) => {
|
|
67
|
-
if (draining) return;
|
|
68
|
-
let b:
|
|
69
|
-
| Schema.StandardBlock
|
|
70
|
-
| Schema.BlockShelley
|
|
71
|
-
| Schema.BlockAllegra
|
|
72
|
-
| Schema.BlockMary
|
|
73
|
-
| Schema.BlockAlonzo;
|
|
74
|
-
let blockBody:
|
|
75
|
-
| Schema.StandardBlock['body']['txPayload']
|
|
76
|
-
| Schema.BlockShelley['body']
|
|
77
|
-
| Schema.BlockAllegra['body']
|
|
78
|
-
| Schema.BlockMary['body']
|
|
79
|
-
| Schema.BlockAlonzo['body'];
|
|
80
|
-
if (isByronStandardBlock(block)) {
|
|
81
|
-
b = block.byron as Schema.StandardBlock;
|
|
82
|
-
blockBody = b.body.txPayload;
|
|
83
|
-
} else if (isShelleyBlock(block)) {
|
|
84
|
-
b = block.shelley as Schema.BlockShelley;
|
|
85
|
-
blockBody = b.body;
|
|
86
|
-
} else if (isAllegraBlock(block)) {
|
|
87
|
-
b = block.allegra as Schema.BlockAllegra;
|
|
88
|
-
blockBody = b.body;
|
|
89
|
-
} else if (isMaryBlock(block)) {
|
|
90
|
-
b = block.mary as Schema.BlockMary;
|
|
91
|
-
blockBody = b.body;
|
|
92
|
-
} else if (isAlonzoBlock(block)) {
|
|
93
|
-
b = block.alonzo as Schema.BlockAlonzo;
|
|
94
|
-
} else {
|
|
95
|
-
throw new Error('No support for block');
|
|
96
|
-
}
|
|
97
|
-
if (b !== undefined) {
|
|
98
|
-
currentBlock = b.header!.blockHeight;
|
|
99
|
-
if (options?.onBlock !== undefined) {
|
|
100
|
-
options.onBlock(currentBlock);
|
|
101
|
-
}
|
|
102
|
-
for (const tx of blockBody!) {
|
|
103
|
-
for (const output of tx.body.outputs) {
|
|
104
|
-
if (trackedAddressBalances[output.address] !== undefined) {
|
|
105
|
-
const addressBalance = { ...trackedAddressBalances[output.address] };
|
|
106
|
-
trackedTxs.push({ id: tx.id, inputs: tx.body.inputs, outputs: tx.body.outputs });
|
|
107
|
-
trackedAddressBalances[output.address] = applyValue(addressBalance, output.value);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
for (const input of tx.body.inputs) {
|
|
111
|
-
const trackedInput = trackedTxs.find((t) => t.id === input.txId)?.outputs[input.index];
|
|
112
|
-
if (trackedInput !== undefined && trackedAddressBalances[trackedInput?.address] !== undefined) {
|
|
113
|
-
const addressBalance = { ...trackedAddressBalances[trackedInput.address] };
|
|
114
|
-
trackedAddressBalances[trackedInput.address] = applyValue(addressBalance, trackedInput.value, true);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (atBlocks.includes(currentBlock)) {
|
|
119
|
-
response.balances[currentBlock] = { ...trackedAddressBalances };
|
|
120
|
-
if (atBlocks[atBlocks.length - 1] === currentBlock) {
|
|
121
|
-
draining = true;
|
|
122
|
-
await syncClient.shutdown();
|
|
123
|
-
return resolve(response);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
requestNext();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
response.metadata.cardano.intersection = await syncClient.startSync(['origin']);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
logger.error(error);
|
|
134
|
-
return reject(error);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
};
|
package/src/Block/getBlocks.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/* eslint-disable sonarjs/cognitive-complexity */
|
|
2
|
-
import { Logger, dummyLogger } from 'ts-log';
|
|
3
|
-
import {
|
|
4
|
-
ConnectionConfig,
|
|
5
|
-
createChainSyncClient,
|
|
6
|
-
createInteractionContext,
|
|
7
|
-
StateQuery,
|
|
8
|
-
isAllegraBlock,
|
|
9
|
-
isAlonzoBlock,
|
|
10
|
-
isShelleyBlock,
|
|
11
|
-
isMaryBlock,
|
|
12
|
-
Schema,
|
|
13
|
-
ChainSync
|
|
14
|
-
} from '@cardano-ogmios/client';
|
|
15
|
-
import { GeneratorMetadata } from '../Content';
|
|
16
|
-
|
|
17
|
-
import { isByronStandardBlock } from '../util';
|
|
18
|
-
|
|
19
|
-
export type GetBlocksResponse = GeneratorMetadata & {
|
|
20
|
-
blocks: { [blockHeight: string]: Schema.Block };
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const getBlocks = async (
|
|
24
|
-
blockHeights: number[],
|
|
25
|
-
options: {
|
|
26
|
-
logger?: Logger;
|
|
27
|
-
ogmiosConnectionConfig: ConnectionConfig;
|
|
28
|
-
onBlock?: (slot: number) => void;
|
|
29
|
-
}
|
|
30
|
-
): Promise<GetBlocksResponse> => {
|
|
31
|
-
const logger = options?.logger ?? dummyLogger;
|
|
32
|
-
const requestedBlocks: { [blockHeight: string]: Schema.Block } = {};
|
|
33
|
-
return new Promise(async (resolve, reject) => {
|
|
34
|
-
let currentBlock: number;
|
|
35
|
-
// Required to ensure existing messages in the pipe are not processed after the completion condition is met
|
|
36
|
-
let draining = false;
|
|
37
|
-
const response: GetBlocksResponse = {
|
|
38
|
-
metadata: {
|
|
39
|
-
cardano: {
|
|
40
|
-
compactGenesis: await StateQuery.genesisConfig(
|
|
41
|
-
await createInteractionContext(reject, logger.info, { connection: options.ogmiosConnectionConfig })
|
|
42
|
-
),
|
|
43
|
-
intersection: undefined as unknown as ChainSync.Intersection
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
blocks: {}
|
|
47
|
-
};
|
|
48
|
-
try {
|
|
49
|
-
const syncClient = await createChainSyncClient(
|
|
50
|
-
await createInteractionContext(reject, logger.info, { connection: options.ogmiosConnectionConfig }),
|
|
51
|
-
{
|
|
52
|
-
rollBackward: async (_res, requestNext) => {
|
|
53
|
-
requestNext();
|
|
54
|
-
},
|
|
55
|
-
rollForward: async ({ block }, requestNext) => {
|
|
56
|
-
if (draining) return;
|
|
57
|
-
let b:
|
|
58
|
-
| Schema.StandardBlock
|
|
59
|
-
| Schema.BlockShelley
|
|
60
|
-
| Schema.BlockAllegra
|
|
61
|
-
| Schema.BlockMary
|
|
62
|
-
| Schema.BlockAlonzo;
|
|
63
|
-
if (isByronStandardBlock(block)) {
|
|
64
|
-
b = block.byron as Schema.StandardBlock;
|
|
65
|
-
} else if (isShelleyBlock(block)) {
|
|
66
|
-
b = block.shelley as Schema.BlockShelley;
|
|
67
|
-
} else if (isAllegraBlock(block)) {
|
|
68
|
-
b = block.allegra as Schema.BlockAllegra;
|
|
69
|
-
} else if (isMaryBlock(block)) {
|
|
70
|
-
b = block.mary as Schema.BlockMary;
|
|
71
|
-
} else if (isAlonzoBlock(block)) {
|
|
72
|
-
b = block.alonzo as Schema.BlockAlonzo;
|
|
73
|
-
} else {
|
|
74
|
-
throw new Error('No support for block');
|
|
75
|
-
}
|
|
76
|
-
if (b !== undefined) {
|
|
77
|
-
currentBlock = b.header!.blockHeight;
|
|
78
|
-
if (options?.onBlock !== undefined) {
|
|
79
|
-
options.onBlock(currentBlock);
|
|
80
|
-
}
|
|
81
|
-
if (blockHeights.includes(currentBlock)) {
|
|
82
|
-
requestedBlocks[currentBlock] = block;
|
|
83
|
-
if (blockHeights[blockHeights.length - 1] === currentBlock) {
|
|
84
|
-
draining = true;
|
|
85
|
-
response.blocks = requestedBlocks;
|
|
86
|
-
await syncClient.shutdown();
|
|
87
|
-
return resolve(response);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
requestNext();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
response.metadata.cardano.intersection = await syncClient.startSync(['origin']);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
logger.error(error);
|
|
98
|
-
return reject(error);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
};
|
package/src/Block/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getBlocks';
|
package/src/Content.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { ChainSync, Schema as Cardano } from '@cardano-ogmios/client';
|
|
2
|
-
import { Commit } from 'git-last-commit';
|
|
3
|
-
import { getLastCommitPromise } from './util';
|
|
4
|
-
const packageJson = require('../package.json');
|
|
5
|
-
|
|
6
|
-
export type Metadata = {
|
|
7
|
-
cardano: {
|
|
8
|
-
compactGenesis: Cardano.CompactGenesis;
|
|
9
|
-
intersection: ChainSync.Intersection;
|
|
10
|
-
};
|
|
11
|
-
software: {
|
|
12
|
-
name: string;
|
|
13
|
-
version: string;
|
|
14
|
-
commit: Pick<Commit, 'hash' | 'tags'>;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type GeneratorMetadata = { metadata: { cardano: Metadata['cardano'] } };
|
|
19
|
-
|
|
20
|
-
export const prepareContent = async <Body>(
|
|
21
|
-
metadata: Omit<Metadata, 'software'>,
|
|
22
|
-
body: Body
|
|
23
|
-
): Promise<{
|
|
24
|
-
metadata: Metadata;
|
|
25
|
-
body: Body;
|
|
26
|
-
}> => {
|
|
27
|
-
const lastCommit = await getLastCommitPromise();
|
|
28
|
-
return {
|
|
29
|
-
metadata: {
|
|
30
|
-
...metadata,
|
|
31
|
-
|
|
32
|
-
software: {
|
|
33
|
-
name: packageJson.name,
|
|
34
|
-
version: packageJson.version,
|
|
35
|
-
commit: {
|
|
36
|
-
hash: lastCommit.hash,
|
|
37
|
-
tags: lastCommit.tags
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
body
|
|
42
|
-
};
|
|
43
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { Command } from 'commander';
|
|
5
|
-
import hash from 'object-hash';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import { SingleBar, Options } from 'cli-progress';
|
|
8
|
-
import { ensureDir, writeFile } from 'fs-extra';
|
|
9
|
-
import JSONBig from 'json-bigint';
|
|
10
|
-
import { AddressBalancesResponse, getOnChainAddressBalances } from './AddressBalance';
|
|
11
|
-
import { getBlocks, GetBlocksResponse } from './Block';
|
|
12
|
-
import { prepareContent } from './Content';
|
|
13
|
-
|
|
14
|
-
const clear = require('clear');
|
|
15
|
-
const packageJson = require('../package.json');
|
|
16
|
-
|
|
17
|
-
clear();
|
|
18
|
-
console.log(chalk.blue('Cardano Golden Test Generator'));
|
|
19
|
-
|
|
20
|
-
const createProgressBar = (lastblockHeight: number) =>
|
|
21
|
-
new SingleBar({
|
|
22
|
-
format: `Syncing from genesis to block ${lastblockHeight} | ${chalk.blue(
|
|
23
|
-
'{bar}'
|
|
24
|
-
)} | {percentage}% || {value}/{total} Blocks`,
|
|
25
|
-
barCompleteChar: '\u2588',
|
|
26
|
-
barIncompleteChar: '\u2591',
|
|
27
|
-
hideCursor: true,
|
|
28
|
-
renderThrottle: 300
|
|
29
|
-
} as Options);
|
|
30
|
-
|
|
31
|
-
const program = new Command('cardano-golden-test-generator');
|
|
32
|
-
|
|
33
|
-
program
|
|
34
|
-
.option('--ogmios-host [ogmiosHost]', 'Ogmios host. Defaults to localhost')
|
|
35
|
-
.option('--ogmios-port [ogmiosPort]', 'Ogmios TCP port. Defaults to 1337', (port) => Number.parseInt(port))
|
|
36
|
-
.option('--ogmios-tls [ogmiosTls]', 'Is Ogmios being served over a secure connection?. Defaults to false', (port) =>
|
|
37
|
-
Number.parseInt(port)
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
program
|
|
41
|
-
.command('address-balance')
|
|
42
|
-
.description('Balance of addresses, determined by syncing the chain from genesis')
|
|
43
|
-
.argument('[addresses]', 'Comma-separated list of addresses', (addresses) =>
|
|
44
|
-
addresses.split(',').filter((a) => a !== '')
|
|
45
|
-
)
|
|
46
|
-
.requiredOption('--at-blocks [atBlocks]', 'Balance of the addresses at block heights', (heights) =>
|
|
47
|
-
heights
|
|
48
|
-
.split(',')
|
|
49
|
-
.filter((b) => b !== '')
|
|
50
|
-
.map((height) => Number.parseInt(height))
|
|
51
|
-
)
|
|
52
|
-
.requiredOption('--out-dir [outDir]', 'File path to write results to')
|
|
53
|
-
.action(async (addresses: string[], { atBlocks, outDir }) => {
|
|
54
|
-
try {
|
|
55
|
-
const { ogmiosHost, ogmiosPort, ogmiosTls } = program.opts();
|
|
56
|
-
const atBlockHeights = atBlocks.sort((a: number, b: number) => a - b);
|
|
57
|
-
const lastBlockHeight = atBlockHeights[atBlockHeights.length - 1];
|
|
58
|
-
const progress = createProgressBar(lastBlockHeight);
|
|
59
|
-
await ensureDir(outDir);
|
|
60
|
-
progress.start(lastBlockHeight, 0);
|
|
61
|
-
const { balances, metadata } = await getOnChainAddressBalances(addresses, atBlockHeights, {
|
|
62
|
-
ogmiosConnectionConfig: { host: ogmiosHost, port: ogmiosPort, tls: ogmiosTls },
|
|
63
|
-
onBlock: (blockHeight) => {
|
|
64
|
-
progress.update(blockHeight);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const content = await prepareContent<AddressBalancesResponse['balances']>(metadata, balances);
|
|
68
|
-
progress.stop();
|
|
69
|
-
const fileName = path.join(outDir, `address-balances-${hash(content)}.json`);
|
|
70
|
-
|
|
71
|
-
console.log(`Writing ${fileName}`);
|
|
72
|
-
await writeFile(fileName, JSONBig.stringify(content, undefined, 2));
|
|
73
|
-
process.exit(0);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error(error);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
program
|
|
81
|
-
.command('get-block')
|
|
82
|
-
.description('Dump the requested blocks in their raw structure')
|
|
83
|
-
.argument('[blockHeights]', 'Comma-separated list of blocks by number', (blockHeights) =>
|
|
84
|
-
blockHeights
|
|
85
|
-
.split(',')
|
|
86
|
-
.filter((b) => b !== '')
|
|
87
|
-
.map((blockHeight) => Number.parseInt(blockHeight))
|
|
88
|
-
)
|
|
89
|
-
.requiredOption('--out-dir [outDir]', 'File path to write results to')
|
|
90
|
-
.action(async (blockHeights: number[], { outDir }) => {
|
|
91
|
-
try {
|
|
92
|
-
const { ogmiosHost, ogmiosPort, ogmiosTls } = program.opts();
|
|
93
|
-
const sortedblockHeights = blockHeights.sort((a: number, b: number) => a - b);
|
|
94
|
-
const lastblockHeight = sortedblockHeights[sortedblockHeights.length - 1];
|
|
95
|
-
const progress = createProgressBar(lastblockHeight);
|
|
96
|
-
await ensureDir(outDir);
|
|
97
|
-
progress.start(lastblockHeight, 0);
|
|
98
|
-
const { blocks, metadata } = await getBlocks(sortedblockHeights, {
|
|
99
|
-
logger: console,
|
|
100
|
-
ogmiosConnectionConfig: { host: ogmiosHost, port: ogmiosPort, tls: ogmiosTls },
|
|
101
|
-
onBlock: (blockHeight) => {
|
|
102
|
-
progress.update(blockHeight);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
progress.stop();
|
|
106
|
-
const content = await prepareContent<GetBlocksResponse['blocks']>(metadata, blocks);
|
|
107
|
-
const fileName = path.join(outDir, `blocks-${hash(content)}.json`);
|
|
108
|
-
|
|
109
|
-
console.log(`Writing ${fileName}`);
|
|
110
|
-
await writeFile(fileName, JSONBig.stringify(content, undefined, 2));
|
|
111
|
-
process.exit(0);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error(error);
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
program.version(packageJson.version);
|
|
119
|
-
if (process.argv.slice(2).length === 0) {
|
|
120
|
-
program.outputHelp();
|
|
121
|
-
process.exit(1);
|
|
122
|
-
} else {
|
|
123
|
-
program.parseAsync(process.argv).catch((error) => {
|
|
124
|
-
console.error(error);
|
|
125
|
-
process.exit(0);
|
|
126
|
-
});
|
|
127
|
-
}
|