@dashevo/dapi-client 4.0.0-rc.2 → 4.1.0-beta.1

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.
@@ -64,7 +64,16 @@ function getDataContractHistoryFactory(grpcTransport) {
64
64
  options,
65
65
  );
66
66
 
67
- return GetDataContractHistoryResponse.createFromProto(getDataContractHistoryResponse);
67
+ const parsedResponse = GetDataContractHistoryResponse.createFromProto(
68
+ getDataContractHistoryResponse,
69
+ );
70
+ if (options.prove && (!parsedResponse.getProof() || !parsedResponse.getMetadata())) {
71
+ throw new InvalidResponseError(
72
+ 'Proved data contract history response is missing proof or metadata',
73
+ );
74
+ }
75
+
76
+ return parsedResponse;
68
77
  } catch (e) {
69
78
  if (e instanceof InvalidResponseError) {
70
79
  lastError = e;
@@ -52,9 +52,17 @@ function waitForStateTransitionResultFactory(grpcTransport) {
52
52
  options,
53
53
  );
54
54
 
55
- return WaitForStateTransitionResultResponse.createFromProto(
55
+ const parsedResponse = WaitForStateTransitionResultResponse.createFromProto(
56
56
  waitForStateTransitionResultResponse,
57
57
  );
58
+ if (options.prove && !parsedResponse.getError()
59
+ && (!parsedResponse.getProof() || !parsedResponse.getMetadata())) {
60
+ throw new InvalidResponseError(
61
+ 'Proved state transition confirmation is missing proof or metadata',
62
+ );
63
+ }
64
+
65
+ return parsedResponse;
58
66
  } catch (e) {
59
67
  if (e instanceof InvalidResponseError) {
60
68
  lastError = e;
@@ -18,10 +18,11 @@ const getRoot = (network) => {
18
18
  };
19
19
 
20
20
  const BLOCK_TIME = 2.5 * 60;
21
+ const MIN_DIFFICULTY_BLOCK_TIME = (2 * 60 * 60) + 1;
21
22
 
22
23
  let x11;
23
24
 
24
- const mockHeadersChain = async (network, length, root) => {
25
+ const mockHeadersChain = async (network, length, root, options = {}) => {
25
26
  if (!x11) {
26
27
  x11 = await X11();
27
28
  // Configure Dashcore lib to operate with wasm x11
@@ -36,14 +37,22 @@ const mockHeadersChain = async (network, length, root) => {
36
37
 
37
38
  let prevHeader = rootHeader;
38
39
  for (let i = 0; i < length - 1; i += 1) {
39
- const header = new BlockHeader({
40
- version: prevHeader.version,
41
- prevHash: Buffer.from(prevHeader.hash, 'hex').reverse(),
42
- merkleRoot: Buffer.alloc(32),
43
- time: prevHeader.time + BLOCK_TIME,
44
- bits: prevHeader.bits,
45
- nonce: 3861367235,
46
- });
40
+ let nonce = options.mine ? 0 : 3861367235;
41
+ let header;
42
+ do {
43
+ header = new BlockHeader({
44
+ version: prevHeader.version,
45
+ prevHash: Buffer.from(prevHeader.hash, 'hex').reverse(),
46
+ merkleRoot: Buffer.alloc(32),
47
+ // Regtest headers spaced by more than two hours use the canonical
48
+ // minimum-difficulty target, keeping long mined fixtures cheap while
49
+ // still exercising the full consensus validator.
50
+ time: prevHeader.time + (options.mine ? MIN_DIFFICULTY_BLOCK_TIME : BLOCK_TIME),
51
+ bits: prevHeader.bits,
52
+ nonce,
53
+ });
54
+ nonce += 1;
55
+ } while (options.mine && !header.validProofOfWork());
47
56
 
48
57
  chain.push(header);
49
58
  prevHeader = header;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "4.0.0-rc.2",
3
+ "version": "4.1.0-beta.1",
4
4
  "description": "Client library used to access Dash DAPI endpoints",
5
5
  "main": "lib/index.js",
6
6
  "contributors": [
@@ -26,11 +26,11 @@
26
26
  }
27
27
  ],
28
28
  "dependencies": {
29
- "@dashevo/dapi-grpc": "4.0.0-rc.2",
30
- "@dashevo/dash-spv": "5.0.0-rc.2",
29
+ "@dashevo/dapi-grpc": "4.1.0-beta.1",
30
+ "@dashevo/dash-spv": "5.1.0-beta.1",
31
31
  "@dashevo/dashcore-lib": "~0.22.0",
32
- "@dashevo/grpc-common": "4.0.0-rc.2",
33
- "@dashevo/wasm-dpp": "4.0.0-rc.2",
32
+ "@dashevo/grpc-common": "4.1.0-beta.1",
33
+ "@dashevo/wasm-dpp": "4.1.0-beta.1",
34
34
  "cbor": "^8.0.0",
35
35
  "google-protobuf": "^3.12.2",
36
36
  "undici": "^6.0.0",