Skip to content

Commit cb66661

Browse files
authored
Bumped dependencies (#11)
1 parent b64bd41 commit cb66661

10 files changed

Lines changed: 113 additions & 48 deletions

File tree

.github/workflows/publish.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish snapshot package
2+
on:
3+
push:
4+
branches: [ 'master' ]
5+
release:
6+
types: [ published ]
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
jobs:
12+
publish-snapshots:
13+
environment:
14+
name: NPMJS
15+
url: ${{ steps.publish.outputs.url }}
16+
name: Publish snapshot packages
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
21+
with:
22+
registry-url: 'https://registry.npmjs.org'
23+
node-version: '>=24.7.0' # Trusted publishing requires npm CLI version 11.5.1 or later.
24+
- run: npm i
25+
- if: ${{ github.event_name == 'push' }}
26+
run: |
27+
PACKAGE_NAME=$(jq --raw-output .name package.json)
28+
npm version prerelease --preid=snapshot --no-git-tag-version
29+
PREFIX=$(jq --raw-output .version package.json | sed 's/\.[0-9]\+$//')
30+
NEXT=$(npm view $PACKAGE_NAME versions --json \
31+
| jq --raw-output --arg prefix $PREFIX '[.[] | select(startswith($prefix))|capture("snapshot\\.(?<n>[0-9]+)").n|tonumber]|max + 1 // 0')
32+
npm version $PREFIX.$NEXT --no-git-tag-version
33+
echo "TAG=snapshot" >> $GITHUB_ENV
34+
- if: ${{ github.event_name == 'release' }}
35+
run: |
36+
npm version $(echo ${{ github.release.tag_name }} | sed 's/^v//') --no-git-tag-version
37+
echo "TAG=latest" >> $GITHUB_ENV
38+
- id: publish
39+
run: |
40+
npm run build
41+
npm publish --provenance --access public --tag $TAG
42+
echo "url=https://www.npmjs.com/package/@waves/ts-lib-crypto/v/$(jq --raw-output .version package.json)" >> "$GITHUB_OUTPUT"

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
{
22
"name": "@waves/node-state",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "",
55
"main": "dist/index.js",
66
"bin": {
77
"node-state": "dist/cli.js"
88
},
99
"scripts": {
10-
"prepare": "tsc",
11-
"postversion": "npm publish"
10+
"prepare": "npx tsc",
11+
"build": "npm run prepare"
1212
},
1313
"author": {
1414
"email": "tsddaniil@gmail.com",
1515
"name": "Tsigel"
1616
},
1717
"repository": {
18-
"url": "https://github.com/wavesplatform/node-state",
18+
"url": "https://github.com/wavesplatform/node-state.git",
1919
"type": "git"
2020
},
2121
"license": "ISC",
2222
"devDependencies": {
23-
"typescript": "^3.9.4"
23+
"typescript": "^5.9.2"
2424
},
2525
"files": [
2626
"dist",
2727
"env",
2828
"config.json"
2929
],
3030
"dependencies": {
31-
"@types/cli-color": "^0.3.29",
31+
"@types/cli-color": "^2.0.6",
3232
"@types/dotenv": "^8.2.0",
33-
"@types/fs-extra": "^8.0.1",
34-
"@types/yargs": "^16.0.3",
35-
"@waves/ts-types": "1.0.2",
36-
"@waves/waves-transactions": "^4.1.8",
37-
"cli-color": "^2.0.0",
33+
"@types/fs-extra": "^11.0.4",
34+
"@types/yargs": "^17.0.35",
35+
"@waves/node-api-js": "1.3.11-beta.1",
36+
"@waves/ts-types": "1.3.1-snapshot.1",
37+
"@waves/waves-transactions": "4.3.11",
38+
"cli-color": "^2.0.4",
3839
"dotenv": "^8.2.0",
39-
"fs-extra": "^8.1.0",
40-
"yargs": "^17.0.1"
40+
"fs-extra": "^11.0.4",
41+
"yargs": "^17.0.35"
4142
}
4243
}

src/args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const data = options({
3737
verbose: {
3838
type: 'boolean'
3939
}
40-
}).argv;
40+
}).parseSync();
4141

4242
export const out = data.out;
4343
export const config = data.config;

src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { outputFile, readFile } from 'fs-extra';
2-
import { alias, broadcast, libs } from '@waves/waves-transactions';
1+
import { outputFile, readJson } from 'fs-extra';
2+
import { alias, libs } from '@waves/waves-transactions';
3+
import { broadcast } from '@waves/node-api-js/cjs/api-node/transactions';
34
import { ACCOUNT_SCRIPT, CHAIN_ID, DAP_SCRIPT, MASTER_ACCOUNT_SEED, NODE_URL, SMART_ASSET_SCRIPT } from './constants';
45
import createAssets from './state/createAssets';
56
import createAccounts from './state/createAccounts';
@@ -9,13 +10,13 @@ import setBalances from './state/setBalances';
910

1011

1112
export async function write(options: IOptions) {
12-
broadcast(alias({
13+
broadcast(NODE_URL, alias({
1314
alias: 'master',
1415
chainId: CHAIN_ID
15-
}, MASTER_ACCOUNT_SEED), NODE_URL)
16+
}, MASTER_ACCOUNT_SEED))
1617
.catch(() => null);
1718

18-
const state = JSON.parse(await readFile(options.config, 'utf8'));
19+
const state = await readJson(options.config);
1920
const ACCOUNTS = await createAccounts(state.ACCOUNTS || {});
2021
const ASSETS = await createAssets(state.ASSETS || {}, ACCOUNTS);
2122
await setBalances(state.ACCOUNTS || {}, ASSETS, ACCOUNTS);

src/middlewares/apply.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,25 @@ export default async (ctx: any, next: any) => {
1414

1515
if (!runTests) {
1616
return next();
17-
} else {
18-
// TODO add check test command
19-
const child = runCommand('npm', ['run', 'testCommand'], {
20-
log: console.warn,
21-
});
17+
}
18+
19+
const npmExecPath = process.env.npm_execpath;
20+
const command = npmExecPath ? process.execPath : process.platform === 'win32' ? 'npm.cmd' : 'npm';
21+
const args = npmExecPath ? [npmExecPath, 'run', 'testCommand'] : ['run', 'testCommand'];
22+
23+
// TODO add check test command
24+
const child = runCommand(command, args, {
25+
log: console.warn,
26+
});
2227

23-
child.on('exit', code => {
24-
process.exit(code || 0);
25-
});
28+
const exitCode = await new Promise<number>((resolve, reject) => {
29+
child.on('exit', code => resolve(code || 0));
30+
child.on('error', reject);
31+
});
2632

27-
next();
33+
if (exitCode !== 0) {
34+
process.exitCode = exitCode;
2835
}
36+
37+
return next();
2938
};

src/middlewares/checkDockerNetwork.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const checkDockerNetworkCommand = [
99
].join(' ');
1010

1111
export default async (ctx: any, next: any) => {
12-
await new Promise(resolve => {
12+
await new Promise<void>(resolve => {
1313
exec(checkDockerNetworkCommand, () => {
1414
console.log('Docker network created (or reused): ', DOCKER_NETWORK);
1515
resolve();
1616
});
1717
});
1818

19-
next();
19+
await next();
2020
};

src/middlewares/node.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ export default async (ctx: any, next: any) => {
2424
NODE_IMAGE
2525
);
2626

27-
await new Promise(resolve => {
28-
node.stdout.on('data', chunk => {
29-
const message = String(chunk);
30-
if (message.includes('REST API was bound')) {
31-
console.info('REST API was bound');
32-
resolve();
33-
}
27+
try {
28+
await new Promise<void>(resolve => {
29+
node.stdout.on('data', chunk => {
30+
const message = String(chunk);
31+
if (message.includes('REST API was bound')) {
32+
console.info('REST API was bound');
33+
resolve();
34+
}
35+
});
3436
});
35-
});
3637

37-
next();
38+
await next();
39+
} finally {
40+
await stop(NODE_IMAGE);
41+
await remove(NODE_IMAGE);
42+
}
3843

3944
};

src/state/createAccounts.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import {IAccount, IAsset, TAccountsResponse, TAssetsResponse, TLong} from '../interface';
2-
import { alias, data, lease, libs, nodeInteraction, setScript, transfer } from '@waves/waves-transactions';
1+
import {IAccount, IAsset, TAccountsResponse, TLong} from '../interface';
2+
import { alias, data, lease, libs, setScript, transfer } from '@waves/waves-transactions';
3+
import { fetchBalanceDetails } from '@waves/node-api-js/cjs/api-node/addresses';
34
import { ACCOUNT_SCRIPT, CHAIN_ID, DAP_SCRIPT, MASTER_ACCOUNT_SEED, NODE_URL } from '../constants';
45
import { broadcastAndWait } from '../utils';
56
import console from '../utils/console';
@@ -51,7 +52,7 @@ export default function <ASSETS extends Record<string, IAsset>, ACCOUNTS extends
5152
await setLeasing(randomAddress, amount);
5253
}
5354

54-
const { available } = await nodeInteraction.balanceDetails(address, NODE_URL);
55+
const { available } = await fetchBalanceDetails(NODE_URL, address);
5556
const toSend = 100 * Math.pow(10, 8) - (+available);
5657

5758
await setBalance(address, toSend);

src/state/setBalances.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { alias, data, libs, nodeInteraction, setScript, transfer } from '@waves/waves-transactions';
1+
import { transfer } from '@waves/waves-transactions';
22
import { MASTER_ACCOUNT_SEED } from '../constants';
33
import { broadcastAndWait } from '../utils';
44
import { IAccount, IAsset, TAccountsResponse, TAssetsResponse } from '../interface';

src/utils.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import { broadcast, waitForTx } from '@waves/waves-transactions';
1+
22
import { NODE_URL } from './constants';
33
import { ChildProcessWithoutNullStreams, spawn, SpawnOptionsWithoutStdio } from 'child_process';
4+
import { broadcast } from '@waves/node-api-js/cjs/api-node/transactions';
5+
import waitTx from '@waves/node-api-js/cjs/tools/transactions/wait';
46
import console from './utils/console';
5-
import * as os from "os";
67

78

89
export async function broadcastAndWait(tx: any): Promise<any> {
910
try {
10-
await broadcast(tx, NODE_URL);
11-
await waitForTx(tx.id, { apiBase: NODE_URL });
11+
const broadcastedTx = await broadcast(NODE_URL, tx);
12+
await waitTx(NODE_URL, broadcastedTx);
1213
} catch (e) {
13-
console.error(`Can't send transaction! ${JSON.stringify(tx, null, 4)}` + '\n' + `Error: ${e.message}`);
14+
const message = e instanceof Error ? e.message : String(e);
15+
console.error(`Can't send transaction! ${JSON.stringify(tx, null, 4)}` + '\n' + `Error: ${message}`);
1416
}
1517
}
1618

@@ -30,6 +32,10 @@ export const run = (command: string, args: Array<string>, options?: { log?: TFun
3032
error(data);
3133
});
3234

35+
process.on('error', err => {
36+
error(err);
37+
});
38+
3339
process.on('close', (code) => {
3440
console.info(`Child process "${command} ${args.join(' ')}" exited with code ${code}`);
3541
});

0 commit comments

Comments
 (0)