Skip to content

Commit f992dc9

Browse files
authored
Merge pull request #67 from wavesplatform/challengedblock
Challengedblock
2 parents 3cd059a + 7e9d937 commit f992dc9

8 files changed

Lines changed: 298 additions & 173 deletions

File tree

package-lock.json

Lines changed: 229 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@waves/node-api-js",
3-
"version": "1.2.10",
3+
"version": "1.3.10",
44
"main": "cjs/index.js",
55
"types": "cjs/index.d.ts",
66
"scripts": {
@@ -12,7 +12,7 @@
1212
"dependencies": {
1313
"@types/node-fetch": "^2.5.4",
1414
"@waves/bignumber": "^1.1.1",
15-
"@waves/ts-types": "^1.0.12",
15+
"@waves/ts-types": "1.2.0",
1616
"node-fetch": "^2.6.7",
1717
"typed-ts-events": "^1.1.1"
1818
},
@@ -55,7 +55,7 @@
5555
"devDependencies": {
5656
"@types/jest": "^26.0.23",
5757
"@waves/node-state": "0.1.0",
58-
"@waves/waves-transactions": "^4.2.4",
58+
"@waves/waves-transactions": "4.3.10",
5959
"jest": "^26.6.3",
6060
"ts-jest": "^26.5.6",
6161
"ts-loader": "^7.0.5",

src/api-node/addresses/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export function fetchDataKey(base: string, address: string, key: string, options
1212
});
1313
}
1414

15+
export function fetchScriptInfo(base: string, address: string, options: RequestInit = Object.create(null)): Promise<IScriptInfo<TLong>> {
16+
return request({
17+
base,
18+
url: `/addresses/scriptInfo/${address}`,
19+
options
20+
});
21+
}
22+
1523
export function fetchScriptInfoMeta(base: string, address: string): Promise<IScriptInfoMetaResponse> {
1624
return request({
1725
base,
@@ -35,14 +43,6 @@ export function fetchBalanceConfirmations(base: string, address: string, confirm
3543
});
3644
}
3745

38-
export function fetchScriptInfo(base: string, address: string, options: RequestInit = Object.create(null)): Promise<IScriptInfo<TLong>> {
39-
return request({
40-
base,
41-
url: `/addresses/scriptInfo/${address}`,
42-
options
43-
});
44-
}
45-
4646
export function data(base: string, address: string, params: IDataQueryParams = Object.create(null), options: RequestInit = Object.create(null)): Promise<Array<DataTransactionEntry<TLong>>> {
4747
return request({
4848
base,

src/api-node/blocks/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export interface IBlockHeader {
203203
generatorPublicKey: string;
204204
version: number;
205205
reference: string;
206-
features: Array<string>;
206+
features: Array<number>;
207207
totalFee: TLong;
208208
desiredReward: number;
209209
transactionCount: number;
@@ -213,6 +213,18 @@ export interface IBlockHeader {
213213
'base-target': number;
214214
'generation-signature': string;
215215
}
216+
stateHash?: string;
217+
rewardShares?: {
218+
[key: string]: TLong;
219+
}
220+
challengedHeader?:{
221+
headerSignature: string;
222+
features: Array<number>;
223+
generator: string;
224+
generatorPublicKey: string;
225+
desiredReward: TLong;
226+
stateHash: string;
227+
}
216228
}
217229

218230
export interface IBlock extends IBlockHeader {

src/api-node/consensus/index.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/api-node/debug/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export type TStateChanges = {
6969
args: { type: string, value: string }[],
7070
},
7171
payment: TPayment[],
72-
stateChanges: TStateChanges
72+
stateChanges: TStateChanges,
7373
})[]
7474
error?: {
7575
code: number,
@@ -78,7 +78,7 @@ export type TStateChanges = {
7878
}
7979

8080
export interface IWithStateChanges {
81-
stateChanges: TStateChanges
81+
stateChanges: TStateChanges | null
8282
}
8383

8484
/**

src/create.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as rewardsModule from './api-node/rewards';
77
import * as utilsModule from './api-node/utils';
88
import * as debugModule from './api-node/debug';
99
import * as aliasModule from './api-node/alias';
10-
import * as consensusModule from './api-node/consensus';
1110
import * as activationModule from './api-node/activation';
1211
import * as nodeModule from './api-node/node';
1312
import * as assetsModule from './api-node/assets';
@@ -47,7 +46,6 @@ export function create(base: string) {
4746
const utils: TWrapRecord<typeof utilsModule> = wrapRecord(base, utilsModule);
4847
const debug: TWrapRecord<typeof debugModule> = wrapRecord(base, debugModule);
4948
const alias: TWrapRecord<typeof aliasModule> = wrapRecord(base, aliasModule);
50-
const consensus: TWrapRecord<typeof consensusModule> = wrapRecord(base, consensusModule);
5149
const activation: TWrapRecord<typeof activationModule> = wrapRecord(base, activationModule);
5250
const node: TWrapRecord<typeof nodeModule> = wrapRecord(base, nodeModule);
5351
const assets: TWrapRecord<typeof assetsModule> = wrapRecord(base, assetsModule);
@@ -87,7 +85,6 @@ export function create(base: string) {
8785
utils,
8886
debug,
8987
alias,
90-
consensus,
9188
activation,
9289
node,
9390
assets,

test/api-node/blocks.spec.ts

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {NODE_URL} from '../_state';
1+
//import {NODE_URL} from '../_state';
22
import {create} from '../../src';
33
import {fetchHeadersAt, fetchHeadersLast, IBlockHeader} from '../../src/api-node/blocks';
44

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

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

27+
const checkChallengedBlockHeader = (block: IBlockHeader) => {
28+
expect(typeof block.blocksize).toBe('number');
29+
expect(typeof block.reward).toBe('number');
30+
expect(typeof block.desiredReward).toBe('number');
31+
expect(typeof block.signature).toBe('string');
32+
expect(typeof block.generator).toBe('string');
33+
expect(typeof block.version).toBe('number');
34+
expect(typeof block.reference).toBe('string');
35+
expect(block.features).toBeInstanceOf(Array)
36+
expect(typeof block.totalFee).toBe('number');
37+
expect(typeof block.transactionCount).toBe('number');
38+
expect(typeof block.timestamp).toBe('number');
39+
expect(typeof block.height).toBe('number');
40+
expect(typeof block.VRF).toBe('string');
41+
expect(typeof block.id).toBe('string');
42+
expect(typeof block["nxt-consensus"]["base-target"]).toBe('number')
43+
expect(typeof block["nxt-consensus"]["generation-signature"]).toBe('string')
44+
expect(typeof block.challengedHeader?.headerSignature).toBe('string')
45+
expect(block.challengedHeader?.features).toBeInstanceOf(Array)
46+
expect(typeof block.challengedHeader?.generatorPublicKey).toBe('string')
47+
expect(typeof block.challengedHeader?.desiredReward).toBe('number')
48+
expect(typeof block.challengedHeader?.stateHash).toBe('string')
49+
expect(typeof block.stateHash).toBe('string')
50+
}
51+
52+
it('fetch challenged block', async () => {
53+
checkChallengedBlockHeader(await api.blocks.fetchHeadersAt(34))
54+
})
55+
2756
it('fetchHeadersLast', async () => {
2857
checkBlockHeader(await api.blocks.fetchHeadersLast());
2958
checkBlockHeader(await fetchHeadersLast(NODE_URL));
@@ -76,47 +105,47 @@ it('first block', async () => {
76105
});
77106

78107
it('fetch block delay', async () => {
79-
const { height } = await api.blocks.fetchHeadersLast();
80-
const { id } = await api.blocks.fetchHeadersAt(Math.floor(height / 2));
81-
const { delay } = await api.blocks.fetchDelay(id, height);
108+
const {height} = await api.blocks.fetchHeadersLast();
109+
const {id} = await api.blocks.fetchHeadersAt(Math.floor(height / 2));
110+
const {delay} = await api.blocks.fetchDelay(id, height);
82111
expect(typeof delay).toBe('number');
83112
});
84113

85114
it('block last', async () => {
86-
const block = await api.blocks.fetchLast();
115+
const block = await api.blocks.fetchLast();
87116
checkBlockHeader(block);
88117
expect(block.transactions).toBeInstanceOf(Array);
89118
expect(block.transactionCount).toBe(block.transactions.length);
90119
});
91120

92121
it('block at', async () => {
93-
const { height } = await api.blocks.fetchHeadersLast();
94-
const block = await api.blocks.fetchBlockAt(height - 1);
122+
const {height} = await api.blocks.fetchHeadersLast();
123+
const block = await api.blocks.fetchBlockAt(height - 1);
95124
checkBlockHeader(block);
96125
expect(block.transactions).toBeInstanceOf(Array);
97126
expect(block.transactionCount).toBe(block.transactions.length);
98127
});
99128

100129
it('blocks by address', async () => {
101-
const { generator, height } = await api.blocks.fetchHeadersLast();
130+
const {generator, height} = await api.blocks.fetchHeadersLast();
102131
const minHeight = height - 10 > 1 ? height - 10 : 2;
103-
const blocks = await api.blocks.fetchBlocksByAddress(generator, minHeight, height);
132+
const blocks = await api.blocks.fetchBlocksByAddress(generator, minHeight, height);
104133

105134
blocks.forEach(checkBlockHeader);
106135
});
107136

108137
it('block by id', async () => {
109-
const { id } = await api.blocks.fetchHeadersLast();
110-
const block = await api.blocks.fetchBlockById(id);
138+
const {id} = await api.blocks.fetchHeadersLast();
139+
const block = await api.blocks.fetchBlockById(id);
111140

112141
checkBlockHeader(block);
113142
expect(block.transactions).toBeInstanceOf(Array);
114143
expect(block.transactionCount).toBe(block.transactions.length);
115144
});
116145

117146
it('block headers by id', async () => {
118-
const { id } = await api.blocks.fetchHeadersLast();
119-
const block = await api.blocks.fetchHeadersById(id);
147+
const {id} = await api.blocks.fetchHeadersLast();
148+
const block = await api.blocks.fetchHeadersById(id);
120149

121150
checkBlockHeader(block);
122151
});

0 commit comments

Comments
 (0)