Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
316 changes: 229 additions & 87 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@waves/node-api-js",
"version": "1.2.10",
"version": "1.3.10",
"main": "cjs/index.js",
"types": "cjs/index.d.ts",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"dependencies": {
"@types/node-fetch": "^2.5.4",
"@waves/bignumber": "^1.1.1",
"@waves/ts-types": "^1.0.12",
"@waves/ts-types": "1.2.0",
"node-fetch": "^2.6.7",
"typed-ts-events": "^1.1.1"
},
Expand Down Expand Up @@ -55,7 +55,7 @@
"devDependencies": {
"@types/jest": "^26.0.23",
"@waves/node-state": "0.1.0",
"@waves/waves-transactions": "^4.2.4",
"@waves/waves-transactions": "4.3.10",
"jest": "^26.6.3",
"ts-jest": "^26.5.6",
"ts-loader": "^7.0.5",
Expand Down
16 changes: 8 additions & 8 deletions src/api-node/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export function fetchDataKey(base: string, address: string, key: string, options
});
}

export function fetchScriptInfo(base: string, address: string, options: RequestInit = Object.create(null)): Promise<IScriptInfo<TLong>> {
return request({
base,
url: `/addresses/scriptInfo/${address}`,
options
});
}

export function fetchScriptInfoMeta(base: string, address: string): Promise<IScriptInfoMetaResponse> {
return request({
base,
Expand All @@ -35,14 +43,6 @@ export function fetchBalanceConfirmations(base: string, address: string, confirm
});
}

export function fetchScriptInfo(base: string, address: string, options: RequestInit = Object.create(null)): Promise<IScriptInfo<TLong>> {
return request({
base,
url: `/addresses/scriptInfo/${address}`,
options
});
}

export function data(base: string, address: string, params: IDataQueryParams = Object.create(null), options: RequestInit = Object.create(null)): Promise<Array<DataTransactionEntry<TLong>>> {
return request({
base,
Expand Down
14 changes: 13 additions & 1 deletion src/api-node/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export interface IBlockHeader {
generatorPublicKey: string;
version: number;
reference: string;
features: Array<string>;
features: Array<number>;
totalFee: TLong;
desiredReward: number;
transactionCount: number;
Expand All @@ -213,6 +213,18 @@ export interface IBlockHeader {
'base-target': number;
'generation-signature': string;
}
stateHash?: string;
rewardShares?: {
[key: string]: TLong;
}
challengedHeader?:{
headerSignature: string;
features: Array<number>;
generator: string;
generatorPublicKey: string;
desiredReward: TLong;
stateHash: string;
}
}

export interface IBlock extends IBlockHeader {
Expand Down
55 changes: 0 additions & 55 deletions src/api-node/consensus/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/api-node/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type TStateChanges = {
args: { type: string, value: string }[],
},
payment: TPayment[],
stateChanges: TStateChanges
stateChanges: TStateChanges,
})[]
error?: {
code: number,
Expand All @@ -78,7 +78,7 @@ export type TStateChanges = {
}

export interface IWithStateChanges {
stateChanges: TStateChanges
stateChanges: TStateChanges | null
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as rewardsModule from './api-node/rewards';
import * as utilsModule from './api-node/utils';
import * as debugModule from './api-node/debug';
import * as aliasModule from './api-node/alias';
import * as consensusModule from './api-node/consensus';
import * as activationModule from './api-node/activation';
import * as nodeModule from './api-node/node';
import * as assetsModule from './api-node/assets';
Expand Down Expand Up @@ -47,7 +46,6 @@ export function create(base: string) {
const utils: TWrapRecord<typeof utilsModule> = wrapRecord(base, utilsModule);
const debug: TWrapRecord<typeof debugModule> = wrapRecord(base, debugModule);
const alias: TWrapRecord<typeof aliasModule> = wrapRecord(base, aliasModule);
const consensus: TWrapRecord<typeof consensusModule> = wrapRecord(base, consensusModule);
const activation: TWrapRecord<typeof activationModule> = wrapRecord(base, activationModule);
const node: TWrapRecord<typeof nodeModule> = wrapRecord(base, nodeModule);
const assets: TWrapRecord<typeof assetsModule> = wrapRecord(base, assetsModule);
Expand Down Expand Up @@ -87,7 +85,6 @@ export function create(base: string) {
utils,
debug,
alias,
consensus,
activation,
node,
assets,
Expand Down
57 changes: 43 additions & 14 deletions test/api-node/blocks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {NODE_URL} from '../_state';
//import {NODE_URL} from '../_state';
import {create} from '../../src';
import {fetchHeadersAt, fetchHeadersLast, IBlockHeader} from '../../src/api-node/blocks';


const NODE_URL = "https://nodes-testnet.wavesnodes.com"
const api = create(NODE_URL);

const checkBlockHeader = (block: IBlockHeader) => {
Expand All @@ -24,6 +24,35 @@ const checkBlockHeader = (block: IBlockHeader) => {
expect(typeof block["nxt-consensus"]["generation-signature"]).toBe('string')
};

const checkChallengedBlockHeader = (block: IBlockHeader) => {
expect(typeof block.blocksize).toBe('number');
expect(typeof block.reward).toBe('number');
expect(typeof block.desiredReward).toBe('number');
expect(typeof block.signature).toBe('string');
expect(typeof block.generator).toBe('string');
expect(typeof block.version).toBe('number');
expect(typeof block.reference).toBe('string');
expect(block.features).toBeInstanceOf(Array)
expect(typeof block.totalFee).toBe('number');
expect(typeof block.transactionCount).toBe('number');
expect(typeof block.timestamp).toBe('number');
expect(typeof block.height).toBe('number');
expect(typeof block.VRF).toBe('string');
expect(typeof block.id).toBe('string');
expect(typeof block["nxt-consensus"]["base-target"]).toBe('number')
expect(typeof block["nxt-consensus"]["generation-signature"]).toBe('string')
expect(typeof block.challengedHeader?.headerSignature).toBe('string')
expect(block.challengedHeader?.features).toBeInstanceOf(Array)
expect(typeof block.challengedHeader?.generatorPublicKey).toBe('string')
expect(typeof block.challengedHeader?.desiredReward).toBe('number')
expect(typeof block.challengedHeader?.stateHash).toBe('string')
expect(typeof block.stateHash).toBe('string')
}

it('fetch challenged block', async () => {
checkChallengedBlockHeader(await api.blocks.fetchHeadersAt(34))
})

it('fetchHeadersLast', async () => {
checkBlockHeader(await api.blocks.fetchHeadersLast());
checkBlockHeader(await fetchHeadersLast(NODE_URL));
Expand Down Expand Up @@ -76,47 +105,47 @@ it('first block', async () => {
});

it('fetch block delay', async () => {
const { height } = await api.blocks.fetchHeadersLast();
const { id } = await api.blocks.fetchHeadersAt(Math.floor(height / 2));
const { delay } = await api.blocks.fetchDelay(id, height);
const {height} = await api.blocks.fetchHeadersLast();
const {id} = await api.blocks.fetchHeadersAt(Math.floor(height / 2));
const {delay} = await api.blocks.fetchDelay(id, height);
expect(typeof delay).toBe('number');
});

it('block last', async () => {
const block = await api.blocks.fetchLast();
const block = await api.blocks.fetchLast();
checkBlockHeader(block);
expect(block.transactions).toBeInstanceOf(Array);
expect(block.transactionCount).toBe(block.transactions.length);
});

it('block at', async () => {
const { height } = await api.blocks.fetchHeadersLast();
const block = await api.blocks.fetchBlockAt(height - 1);
const {height} = await api.blocks.fetchHeadersLast();
const block = await api.blocks.fetchBlockAt(height - 1);
checkBlockHeader(block);
expect(block.transactions).toBeInstanceOf(Array);
expect(block.transactionCount).toBe(block.transactions.length);
});

it('blocks by address', async () => {
const { generator, height } = await api.blocks.fetchHeadersLast();
const {generator, height} = await api.blocks.fetchHeadersLast();
const minHeight = height - 10 > 1 ? height - 10 : 2;
const blocks = await api.blocks.fetchBlocksByAddress(generator, minHeight, height);
const blocks = await api.blocks.fetchBlocksByAddress(generator, minHeight, height);

blocks.forEach(checkBlockHeader);
});

it('block by id', async () => {
const { id } = await api.blocks.fetchHeadersLast();
const block = await api.blocks.fetchBlockById(id);
const {id} = await api.blocks.fetchHeadersLast();
const block = await api.blocks.fetchBlockById(id);

checkBlockHeader(block);
expect(block.transactions).toBeInstanceOf(Array);
expect(block.transactionCount).toBe(block.transactions.length);
});

it('block headers by id', async () => {
const { id } = await api.blocks.fetchHeadersLast();
const block = await api.blocks.fetchHeadersById(id);
const {id} = await api.blocks.fetchHeadersLast();
const block = await api.blocks.fetchHeadersById(id);

checkBlockHeader(block);
});
Expand Down