@leofcoin/messages 1.3.4 → 1.3.6
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/messages/block.js +3 -2
- package/exports/messages/validator.js +1 -1
- package/exports/typings/protos/block.proto.d.ts +2 -2
- package/exports/typings/protos/validator.proto.d.ts +1 -1
- package/package.json +2 -1
- package/src/messages/block.ts +4 -3
- package/src/protos/block.proto.js +4 -2
- package/src/protos/validator.proto.js +1 -1
- package/test.js +10 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import '@leofcoin/utils';
|
|
1
2
|
import { FormatInterface } from '@leofcoin/codec-format-interface';
|
|
2
3
|
import TransactionMessage from './transaction.js';
|
|
3
4
|
import ValidatorMessage from './validator.js';
|
|
@@ -8,8 +9,8 @@ var proto = {
|
|
|
8
9
|
index: Number(),
|
|
9
10
|
previousHash: String(),
|
|
10
11
|
timestamp: Number(),
|
|
11
|
-
reward:
|
|
12
|
-
fees:
|
|
12
|
+
reward: String(),
|
|
13
|
+
fees: String(),
|
|
13
14
|
transactions: new Uint8Array(),
|
|
14
15
|
validators: new Uint8Array()
|
|
15
16
|
};
|
|
@@ -2,8 +2,8 @@ declare namespace _default {
|
|
|
2
2
|
const index: number;
|
|
3
3
|
const previousHash: string;
|
|
4
4
|
const timestamp: number;
|
|
5
|
-
const reward:
|
|
6
|
-
const fees:
|
|
5
|
+
const reward: string;
|
|
6
|
+
const fees: string;
|
|
7
7
|
const transactions: Uint8Array;
|
|
8
8
|
const validators: Uint8Array;
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/messages",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./exports/index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@leofcoin/codec-format-interface": "^1.6.5",
|
|
31
|
+
"@leofcoin/utils": "^1.1.5",
|
|
31
32
|
"@vandeurenglenn/easy-worker": "^1.0.2"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/src/messages/block.ts
CHANGED
|
@@ -4,14 +4,15 @@ import TransactionMessage from './transaction.js'
|
|
|
4
4
|
import ValidatorMessage from './validator.js'
|
|
5
5
|
import smartConcat from '@vandeurenglenn/typed-array-smart-concat'
|
|
6
6
|
import smartDeconcat from '@vandeurenglenn/typed-array-smart-deconcat'
|
|
7
|
+
import { BigNumber } from '@leofcoin/utils'
|
|
7
8
|
|
|
8
9
|
export default class BlockMessage extends FormatInterface {
|
|
9
10
|
declare decoded: {
|
|
10
11
|
index: Number,
|
|
11
12
|
previousHash: String,
|
|
12
|
-
timestamp: String,
|
|
13
|
-
reward:
|
|
14
|
-
fees:
|
|
13
|
+
timestamp: String,
|
|
14
|
+
reward: BigNumber,
|
|
15
|
+
fees: BigNumber,
|
|
15
16
|
transactions: Uint8Array[] | Object[] | Uint8Array,
|
|
16
17
|
validators: Uint8Array[] | Object[] | Uint8Array
|
|
17
18
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { BigNumber } from "@leofcoin/utils"
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
index: Number(),
|
|
3
5
|
previousHash: String(),
|
|
4
6
|
timestamp: Number(),
|
|
5
|
-
reward:
|
|
6
|
-
fees:
|
|
7
|
+
reward: String(),
|
|
8
|
+
fees: String(),
|
|
7
9
|
transactions: new Uint8Array(),
|
|
8
10
|
validators: new Uint8Array()
|
|
9
11
|
}
|
package/test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BlockMessage from "./exports/messages/block.js";
|
|
2
2
|
import BWRequestMessage from "./exports/messages/bw-request.js";
|
|
3
3
|
import { ContractMessage } from "./exports/index.js";
|
|
4
|
+
import { BigNumber } from "@leofcoin/utils";
|
|
4
5
|
|
|
5
6
|
console.log(globalThis.peernet);
|
|
6
7
|
// globalThis.peernet.codecs
|
|
@@ -28,13 +29,13 @@ const block = {
|
|
|
28
29
|
index: 0,
|
|
29
30
|
previousHash: 'hash',
|
|
30
31
|
timestamp: new Date().getTime(),
|
|
31
|
-
reward: 0,
|
|
32
|
-
fees: 0,
|
|
32
|
+
reward: new BigNumber.from('0'),
|
|
33
|
+
fees: new BigNumber.from('0'),
|
|
33
34
|
transactions,
|
|
34
35
|
validators
|
|
35
36
|
}
|
|
36
37
|
const contractMessage = new ContractMessage({
|
|
37
|
-
creator: '',
|
|
38
|
+
creator: 'aaa',
|
|
38
39
|
contract: new Uint8Array(),
|
|
39
40
|
constructorParameters: []
|
|
40
41
|
})
|
|
@@ -42,8 +43,13 @@ console.log({contractMessage});
|
|
|
42
43
|
const bw = new BWRequestMessage()
|
|
43
44
|
|
|
44
45
|
const message = new BlockMessage(block)
|
|
46
|
+
console.log({reward: message.decoded.reward});
|
|
45
47
|
console.time('message encoded')
|
|
48
|
+
console.log(await message.hash());
|
|
46
49
|
await message.encode()
|
|
50
|
+
console.log(await message.hash());
|
|
51
|
+
console.log({reward: new BlockMessage(message.encoded).decoded.reward});
|
|
52
|
+
console.log(await new BlockMessage(message.encoded).hash());
|
|
47
53
|
console.timeEnd('message encoded')
|
|
48
54
|
console.time('normal encoded')
|
|
49
55
|
const normalEncoded = new TextEncoder().encode(JSON.stringify(block))
|
|
@@ -53,5 +59,5 @@ console.log('# is smaller then normal encoded');
|
|
|
53
59
|
console.info(`normal: ${normalEncoded.length}\nmessage: ${message.encoded.length}`);
|
|
54
60
|
console.log(normalEncoded.length > message.encoded.length);
|
|
55
61
|
|
|
56
|
-
const contract = new ContractMessage(
|
|
62
|
+
const contract = new ContractMessage(contractMessage.encoded)
|
|
57
63
|
console.log(contract);
|