@leofcoin/messages 1.4.13 → 1.4.15
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 +2 -13
- package/exports/protos/block.proto.d.ts +1 -1
- package/package.json +1 -1
package/exports/block.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BigNumber } from '@leofcoin/utils';
|
|
2
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface';
|
|
3
|
-
import TransactionMessage from './transaction.js';
|
|
4
3
|
import ValidatorMessage from './validator.js';
|
|
5
4
|
import smartConcat from '@vandeurenglenn/typed-array-smart-concat';
|
|
6
5
|
import smartDeconcat from '@vandeurenglenn/typed-array-smart-deconcat';
|
|
@@ -11,7 +10,7 @@ var proto = {
|
|
|
11
10
|
timestamp: Number(),
|
|
12
11
|
reward: BigNumber.from(0),
|
|
13
12
|
fees: BigNumber.from(0),
|
|
14
|
-
transactions:
|
|
13
|
+
transactions: Array(),
|
|
15
14
|
validators: new Uint8Array()
|
|
16
15
|
};
|
|
17
16
|
|
|
@@ -28,31 +27,21 @@ class BlockMessage extends FormatInterface {
|
|
|
28
27
|
encode(decoded) {
|
|
29
28
|
decoded = decoded || this.decoded;
|
|
30
29
|
const validators = [];
|
|
31
|
-
const transactions = [];
|
|
32
30
|
for (const validator of decoded.validators) {
|
|
33
31
|
if (validator instanceof ValidatorMessage)
|
|
34
32
|
validators.push(validator.encode());
|
|
35
33
|
else
|
|
36
34
|
validators.push(new ValidatorMessage(validator).encode());
|
|
37
35
|
}
|
|
38
|
-
for (const transaction of decoded.transactions) {
|
|
39
|
-
if (transaction instanceof TransactionMessage)
|
|
40
|
-
transactions.push(transaction.encode());
|
|
41
|
-
else
|
|
42
|
-
transactions.push(new TransactionMessage(transaction).encode());
|
|
43
|
-
}
|
|
44
36
|
return super.encode({
|
|
45
37
|
...decoded,
|
|
46
|
-
validators: smartConcat(validators)
|
|
47
|
-
transactions: smartConcat(transactions)
|
|
38
|
+
validators: smartConcat(validators)
|
|
48
39
|
});
|
|
49
40
|
}
|
|
50
41
|
decode(encoded) {
|
|
51
42
|
encoded = encoded || this.encoded;
|
|
52
43
|
super.decode(encoded);
|
|
53
44
|
// @ts-ignore
|
|
54
|
-
this.decoded.transactions = smartDeconcat(this.decoded.transactions).map((transaction) => new TransactionMessage(transaction).decoded);
|
|
55
|
-
// @ts-ignore
|
|
56
45
|
this.decoded.validators = smartDeconcat(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
|
|
57
46
|
return this.decoded;
|
|
58
47
|
}
|