@leofcoin/messages 1.3.17 → 1.4.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.
package/exports/block.js CHANGED
@@ -20,24 +20,26 @@ class BlockMessage extends FormatInterface {
20
20
  return 'BlockMessage';
21
21
  }
22
22
  constructor(buffer) {
23
+ if (buffer instanceof BlockMessage)
24
+ return buffer;
23
25
  const name = 'block-message';
24
26
  super(buffer, proto, { name });
25
27
  }
26
- encode() {
27
- const decoded = this.decoded;
28
+ encode(decoded) {
29
+ decoded = decoded || this.decoded;
28
30
  const validators = [];
29
31
  const transactions = [];
30
32
  for (const validator of decoded.validators) {
31
33
  if (validator instanceof ValidatorMessage)
32
- validators.push(validator.encoded);
34
+ validators.push(validator.encode());
33
35
  else
34
- validators.push(new ValidatorMessage(validator).encoded);
36
+ validators.push(new ValidatorMessage(validator).encode());
35
37
  }
36
38
  for (const transaction of decoded.transactions) {
37
39
  if (transaction instanceof TransactionMessage)
38
- transactions.push(transaction.encoded);
40
+ transactions.push(transaction.encode());
39
41
  else
40
- transactions.push(new TransactionMessage(transaction).encoded);
42
+ transactions.push(new TransactionMessage(transaction).encode());
41
43
  }
42
44
  return super.encode({
43
45
  ...decoded,
@@ -45,12 +47,13 @@ class BlockMessage extends FormatInterface {
45
47
  transactions: smartConcat(transactions)
46
48
  });
47
49
  }
48
- decode() {
49
- super.decode();
50
+ decode(encoded) {
51
+ encoded = encoded || this.encoded;
52
+ super.decode(encoded);
50
53
  // @ts-ignore
51
- this.decoded.transactions = smartDeconcat(this.decoded.transactions).map(transaction => new TransactionMessage(transaction).decoded);
54
+ this.decoded.transactions = smartDeconcat(this.decoded.transactions).map((transaction) => new TransactionMessage(transaction).decoded);
52
55
  // @ts-ignore
53
- this.decoded.validators = smartDeconcat(this.decoded.validators).map(validator => new ValidatorMessage(validator).decoded);
56
+ this.decoded.validators = smartDeconcat(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
54
57
  return this.decoded;
55
58
  }
56
59
  }
@@ -7,6 +7,8 @@ class BWRequestMessage extends FormatInterface {
7
7
  return 'BWRequestMessage';
8
8
  }
9
9
  constructor(buffer) {
10
+ if (buffer instanceof BWRequestMessage)
11
+ return buffer;
10
12
  const name = 'bw-request-message';
11
13
  super(buffer, proto, { name });
12
14
  }
package/exports/bw.js CHANGED
@@ -10,6 +10,8 @@ class BWMessage extends FormatInterface {
10
10
  return 'BWMessage';
11
11
  }
12
12
  constructor(buffer) {
13
+ if (buffer instanceof BWMessage)
14
+ return buffer;
13
15
  const name = 'bw-message';
14
16
  super(buffer, proto, { name });
15
17
  }
@@ -11,6 +11,8 @@ class ContractMessage extends FormatInterface {
11
11
  return 'ContractMessage';
12
12
  }
13
13
  constructor(buffer) {
14
+ if (buffer instanceof ContractMessage)
15
+ return buffer;
14
16
  super(buffer, proto, { name: 'contract-message' });
15
17
  }
16
18
  }
package/exports/index.js CHANGED
@@ -15,9 +15,9 @@ var proto = {
15
15
  timestamp: Number(),
16
16
  from: String(),
17
17
  to: String(),
18
- nonce: Number(),
19
18
  method: String(),
20
- params: Array()
19
+ params: Array(),
20
+ 'nonce?': Number()
21
21
  };
22
22
 
23
23
  class RawTransactionMessage extends FormatInterface {
@@ -25,6 +25,8 @@ class RawTransactionMessage extends FormatInterface {
25
25
  return 'RawTransactionMessage';
26
26
  }
27
27
  constructor(buffer) {
28
+ if (buffer instanceof RawTransactionMessage)
29
+ return buffer;
28
30
  const name = 'raw-transaction-message';
29
31
  super(buffer, proto, { name });
30
32
  }
@@ -7,6 +7,8 @@ class LastBlockRequestMessage extends FormatInterface {
7
7
  return 'LastBlockRequestMessage';
8
8
  }
9
9
  constructor(buffer) {
10
+ if (buffer instanceof LastBlockRequestMessage)
11
+ return buffer;
10
12
  const name = 'last-block-request-message';
11
13
  super(buffer, proto, { name });
12
14
  }
@@ -10,6 +10,8 @@ class LastBlockMessage extends FormatInterface {
10
10
  return 'LastBlockMessage';
11
11
  }
12
12
  constructor(buffer) {
13
+ if (buffer instanceof LastBlockMessage)
14
+ return buffer;
13
15
  const name = 'last-block-message';
14
16
  super(buffer, proto, { name });
15
17
  }
@@ -15,8 +15,8 @@ export default class BlockMessage extends FormatInterface {
15
15
  };
16
16
  get messageName(): string;
17
17
  constructor(buffer: messageInput);
18
- encode(): Uint8Array;
19
- decode(): {
18
+ encode(decoded?: any): Uint8Array;
19
+ decode(encoded?: any): {
20
20
  index: Number;
21
21
  previousHash: String;
22
22
  timestamp: String;
@@ -1,7 +1,7 @@
1
1
  import proto from '../protos/publish.proto.js';
2
2
  import { FormatInterface } from '@leofcoin/codec-format-interface';
3
3
  import type { messageInput } from '../types.js';
4
- export default class BWRequestMessage extends FormatInterface {
4
+ export default class publishMessage extends FormatInterface {
5
5
  decoded: typeof proto;
6
6
  get messageName(): string;
7
7
  constructor(buffer: messageInput);
@@ -1,4 +1,4 @@
1
- import { BigNumber } from "@leofcoin/utils";
1
+ import { BigNumber } from '@leofcoin/utils';
2
2
  declare const _default: {
3
3
  index: number;
4
4
  previousHash: string;
@@ -1,4 +1,4 @@
1
- import { BigNumber } from "@leofcoin/utils";
1
+ import { BigNumber } from '@leofcoin/utils';
2
2
  declare const _default: {
3
3
  address: string;
4
4
  reward: BigNumber;
@@ -4,10 +4,12 @@ var proto = {
4
4
  timestamp: Number(),
5
5
  from: String(),
6
6
  to: String(),
7
- nonce: Number(),
8
7
  method: String(),
9
8
  params: Array(),
10
- signature: String()
9
+ signature: String(),
10
+ 'nonce?': Number(),
11
+ 'dependsOn?': Array(),
12
+ 'priority?': Boolean()
11
13
  };
12
14
 
13
15
  class TransactionMessage extends FormatInterface {
@@ -15,6 +17,8 @@ class TransactionMessage extends FormatInterface {
15
17
  return 'TransactionMessage';
16
18
  }
17
19
  constructor(buffer) {
20
+ if (buffer instanceof TransactionMessage)
21
+ return buffer;
18
22
  const name = 'transaction-message';
19
23
  super(buffer, proto, { name });
20
24
  }
@@ -11,6 +11,8 @@ class ValidatorMessage extends FormatInterface {
11
11
  return 'ValidatorMessage';
12
12
  }
13
13
  constructor(buffer) {
14
+ if (buffer instanceof ValidatorMessage)
15
+ return buffer;
14
16
  const name = 'validator-message';
15
17
  super(buffer, proto, { name });
16
18
  }
package/package.json CHANGED
@@ -1,61 +1,62 @@
1
- {
2
- "name": "@leofcoin/messages",
3
- "version": "1.3.17",
4
- "description": "",
5
- "exports": {
6
- ".": {
7
- "import": "./exports/index.js",
8
- "types": "./exports/index.d.ts"
9
- },
10
- "./block": {
11
- "import": "./exports/block.js",
12
- "types": "./exports/block.d.ts"
13
- },
14
- "./bw-request": {
15
- "import": "./exports/bw-request.js",
16
- "types": "./exports/bw-request.d.ts"
17
- },
18
- "./bw": {
19
- "import": "./exports/bw.js",
20
- "types": "./exports/bw.d.ts"
21
- },
22
- "./contract": {
23
- "import": "./exports/contract.js",
24
- "types": "./exports/contract.d.ts"
25
- },
26
- "./last-block-request": {
27
- "import": "./exports/last-block-request.js",
28
- "types": "./exports/last-block-request.d.ts"
29
- },
30
- "./last-block": {
31
- "import": "./exports/last-block.js",
32
- "types": "./exports/last-block.d.ts"
33
- },
34
- "./transaction": {
35
- "import": "./exports/transaction.js",
36
- "types": "./exports/transaction.d.ts"
37
- }
38
- },
39
- "files": [
40
- "exports"
41
- ],
42
- "type": "module",
43
- "scripts": {
44
- "test": "echo \"Error: no test specified\" && exit 1",
45
- "build": "rollup -c"
46
- },
47
- "keywords": [],
48
- "author": "",
49
- "license": "MIT",
50
- "devDependencies": {
51
- "@rollup/plugin-typescript": "^11.0.0",
52
- "rollup": "^3.10.0",
53
- "tslib": "^2.4.1",
54
- "typescript": "^5.2.2"
55
- },
56
- "dependencies": {
57
- "@leofcoin/codec-format-interface": "^1.6.18",
58
- "@leofcoin/utils": "^1.1.5",
59
- "@vandeurenglenn/easy-worker": "^1.0.2"
60
- }
61
- }
1
+ {
2
+ "name": "@leofcoin/messages",
3
+ "version": "1.4.1",
4
+ "description": "",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./exports/index.js",
8
+ "types": "./exports/index.d.ts"
9
+ },
10
+ "./block": {
11
+ "import": "./exports/block.js",
12
+ "types": "./exports/block.d.ts"
13
+ },
14
+ "./bw-request": {
15
+ "import": "./exports/bw-request.js",
16
+ "types": "./exports/bw-request.d.ts"
17
+ },
18
+ "./bw": {
19
+ "import": "./exports/bw.js",
20
+ "types": "./exports/bw.d.ts"
21
+ },
22
+ "./contract": {
23
+ "import": "./exports/contract.js",
24
+ "types": "./exports/contract.d.ts"
25
+ },
26
+ "./last-block-request": {
27
+ "import": "./exports/last-block-request.js",
28
+ "types": "./exports/last-block-request.d.ts"
29
+ },
30
+ "./last-block": {
31
+ "import": "./exports/last-block.js",
32
+ "types": "./exports/last-block.d.ts"
33
+ },
34
+ "./transaction": {
35
+ "import": "./exports/transaction.js",
36
+ "types": "./exports/transaction.d.ts"
37
+ }
38
+ },
39
+ "files": [
40
+ "exports"
41
+ ],
42
+ "type": "module",
43
+ "scripts": {
44
+ "prettier": "prettier src --config ./../../.prettierrc --write",
45
+ "test": "node test",
46
+ "build": "rollup -c"
47
+ },
48
+ "keywords": [],
49
+ "author": "",
50
+ "license": "MIT",
51
+ "devDependencies": {
52
+ "@rollup/plugin-typescript": "^11.0.0",
53
+ "rollup": "^3.10.0",
54
+ "tslib": "^2.4.1",
55
+ "typescript": "^5.2.2"
56
+ },
57
+ "dependencies": {
58
+ "@leofcoin/codec-format-interface": "^1.6.18",
59
+ "@leofcoin/utils": "^1.1.5",
60
+ "@vandeurenglenn/easy-worker": "^1.0.2"
61
+ }
62
+ }