@leofcoin/messages 1.3.3 → 1.3.4
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 +44 -44
- package/exports/messages/bw-request.js +9 -9
- package/exports/messages/bw.js +11 -11
- package/exports/messages/contract.js +11 -11
- package/exports/messages/last-block-request.js +9 -9
- package/exports/messages/last-block.js +11 -11
- package/exports/messages/transaction.js +16 -16
- package/exports/messages/validator.js +11 -11
- package/exports/typings/index.d.ts +8 -8
- package/exports/typings/messages/block.d.ts +24 -24
- package/exports/typings/messages/bw-request.d.ts +5 -5
- package/exports/typings/messages/bw.d.ts +5 -5
- package/exports/typings/messages/contract.d.ts +5 -5
- package/exports/typings/messages/last-block-request.d.ts +5 -5
- package/exports/typings/messages/last-block.d.ts +5 -5
- package/exports/typings/messages/publish.d.ts +5 -5
- package/exports/typings/messages/transaction.d.ts +5 -5
- package/exports/typings/messages/validator.d.ts +5 -5
- package/exports/typings/protos/block.proto.d.ts +10 -10
- package/exports/typings/protos/bw-request.proto.d.ts +2 -2
- package/exports/typings/protos/bw.proto.d.ts +5 -5
- package/exports/typings/protos/contract.proto.d.ts +6 -6
- package/exports/typings/protos/last-block-request.proto.d.ts +2 -2
- package/exports/typings/protos/last-block.proto.d.ts +5 -5
- package/exports/typings/protos/publish.proto.d.ts +8 -8
- package/exports/typings/protos/transaction.proto.d.ts +10 -10
- package/exports/typings/protos/validator.proto.d.ts +5 -5
- package/exports/typings/workers/transaction-worker.d.ts +1 -1
- package/exports/workers/transaction-worker.js +12 -12
- package/package.json +33 -33
- package/rollup.config.js +55 -55
- package/src/index.ts +9 -9
- package/src/messages/block.ts +56 -56
- package/src/messages/bw-request.ts +13 -13
- package/src/messages/bw.ts +13 -13
- package/src/messages/contract.ts +12 -12
- package/src/messages/last-block-request.ts +13 -13
- package/src/messages/last-block.ts +13 -13
- package/src/messages/publish.ts +13 -13
- package/src/messages/transaction.ts +13 -13
- package/src/messages/validator.ts +13 -13
- package/src/protos/block.proto.js +9 -9
- package/src/protos/bw-request.proto.js +2 -2
- package/src/protos/bw.proto.js +4 -4
- package/src/protos/contract.proto.js +5 -5
- package/src/protos/last-block-request.proto.js +2 -2
- package/src/protos/last-block.proto.js +4 -4
- package/src/protos/publish.proto.js +7 -7
- package/src/protos/transaction.proto.js +9 -9
- package/src/protos/validator.proto.js +4 -4
- package/test.js +56 -56
- package/tsconfig.json +15 -15
package/test.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import BlockMessage from "./exports/messages/block.js";
|
|
2
|
-
import BWRequestMessage from "./exports/messages/bw-request.js";
|
|
3
|
-
import { ContractMessage } from "./exports/index.js";
|
|
4
|
-
|
|
5
|
-
console.log(globalThis.peernet);
|
|
6
|
-
// globalThis.peernet.codecs
|
|
7
|
-
const validators = [{
|
|
8
|
-
address: 'address',
|
|
9
|
-
reward: 0
|
|
10
|
-
}]
|
|
11
|
-
|
|
12
|
-
const transactions = []
|
|
13
|
-
for (let i = 0; i <= 1_235; i++) {
|
|
14
|
-
transactions.push(
|
|
15
|
-
{
|
|
16
|
-
timestamp: new Date().getTime(),
|
|
17
|
-
from: 'fromAddress',
|
|
18
|
-
to: 'toAddress',
|
|
19
|
-
nonce: 0,
|
|
20
|
-
method: 'getAddress',
|
|
21
|
-
params: [],
|
|
22
|
-
signature: new Uint8Array(32)
|
|
23
|
-
}
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const block = {
|
|
28
|
-
index: 0,
|
|
29
|
-
previousHash: 'hash',
|
|
30
|
-
timestamp: new Date().getTime(),
|
|
31
|
-
reward: 0,
|
|
32
|
-
fees: 0,
|
|
33
|
-
transactions,
|
|
34
|
-
validators
|
|
35
|
-
}
|
|
36
|
-
const contractMessage = new ContractMessage({
|
|
37
|
-
creator: '',
|
|
38
|
-
contract: new Uint8Array(),
|
|
39
|
-
constructorParameters: []
|
|
40
|
-
})
|
|
41
|
-
console.log({contractMessage});
|
|
42
|
-
const bw = new BWRequestMessage()
|
|
43
|
-
|
|
44
|
-
const message = new BlockMessage(block)
|
|
45
|
-
console.time('message encoded')
|
|
46
|
-
await message.encode()
|
|
47
|
-
console.timeEnd('message encoded')
|
|
48
|
-
console.time('normal encoded')
|
|
49
|
-
const normalEncoded = new TextEncoder().encode(JSON.stringify(block))
|
|
50
|
-
console.timeEnd('normal encoded')
|
|
51
|
-
|
|
52
|
-
console.log('# is smaller then normal encoded');
|
|
53
|
-
console.info(`normal: ${normalEncoded.length}\nmessage: ${message.encoded.length}`);
|
|
54
|
-
console.log(normalEncoded.length > message.encoded.length);
|
|
55
|
-
|
|
56
|
-
const contract = new ContractMessage('237,198,141,3,53,89,84,113,120,75,115,104,87,72,52,81,111,55,75,112,114,71,89,120,81,86,67,78,89,117,116,101,100,97,69,54,89,71,111,85,100,85,80,110,85,100,70,85,86,66,80,114,84,122,103,115,114,80,238,4,99,108,97,115,115,32,70,97,99,116,111,114,121,123,35,110,97,109,101,61,34,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,34,59,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,48,59,35,99,111,110,116,114,97,99,116,115,61,91,93,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,116,97,116,101,38,38,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,99,111,110,116,114,97,99,116,115,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,116,111,116,97,108,67,111,110,116,114,97,99,116,115,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,116,111,116,97,108,67,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,44,99,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,125,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,91,46,46,46,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,93,125,103,101,116,32,116,111,116,97,108,67,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,125,97,115,121,110,99,32,114,101,103,105,115,116,101,114,67,111,110,116,114,97,99,116,40,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,97,100,100,114,101,115,115,44,34,104,97,115,82,111,108,101,34,44,91,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,93,41,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,125,114,101,116,117,114,110,32,70,97,99,116,111,114,121,59,2,91,93')
|
|
1
|
+
import BlockMessage from "./exports/messages/block.js";
|
|
2
|
+
import BWRequestMessage from "./exports/messages/bw-request.js";
|
|
3
|
+
import { ContractMessage } from "./exports/index.js";
|
|
4
|
+
|
|
5
|
+
console.log(globalThis.peernet);
|
|
6
|
+
// globalThis.peernet.codecs
|
|
7
|
+
const validators = [{
|
|
8
|
+
address: 'address',
|
|
9
|
+
reward: 0
|
|
10
|
+
}]
|
|
11
|
+
|
|
12
|
+
const transactions = []
|
|
13
|
+
for (let i = 0; i <= 1_235; i++) {
|
|
14
|
+
transactions.push(
|
|
15
|
+
{
|
|
16
|
+
timestamp: new Date().getTime(),
|
|
17
|
+
from: 'fromAddress',
|
|
18
|
+
to: 'toAddress',
|
|
19
|
+
nonce: 0,
|
|
20
|
+
method: 'getAddress',
|
|
21
|
+
params: [],
|
|
22
|
+
signature: new Uint8Array(32)
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const block = {
|
|
28
|
+
index: 0,
|
|
29
|
+
previousHash: 'hash',
|
|
30
|
+
timestamp: new Date().getTime(),
|
|
31
|
+
reward: 0,
|
|
32
|
+
fees: 0,
|
|
33
|
+
transactions,
|
|
34
|
+
validators
|
|
35
|
+
}
|
|
36
|
+
const contractMessage = new ContractMessage({
|
|
37
|
+
creator: '',
|
|
38
|
+
contract: new Uint8Array(),
|
|
39
|
+
constructorParameters: []
|
|
40
|
+
})
|
|
41
|
+
console.log({contractMessage});
|
|
42
|
+
const bw = new BWRequestMessage()
|
|
43
|
+
|
|
44
|
+
const message = new BlockMessage(block)
|
|
45
|
+
console.time('message encoded')
|
|
46
|
+
await message.encode()
|
|
47
|
+
console.timeEnd('message encoded')
|
|
48
|
+
console.time('normal encoded')
|
|
49
|
+
const normalEncoded = new TextEncoder().encode(JSON.stringify(block))
|
|
50
|
+
console.timeEnd('normal encoded')
|
|
51
|
+
|
|
52
|
+
console.log('# is smaller then normal encoded');
|
|
53
|
+
console.info(`normal: ${normalEncoded.length}\nmessage: ${message.encoded.length}`);
|
|
54
|
+
console.log(normalEncoded.length > message.encoded.length);
|
|
55
|
+
|
|
56
|
+
const contract = new ContractMessage('237,198,141,3,53,89,84,113,120,75,115,104,87,72,52,81,111,55,75,112,114,71,89,120,81,86,67,78,89,117,116,101,100,97,69,54,89,71,111,85,100,85,80,110,85,100,70,85,86,66,80,114,84,122,103,115,114,80,238,4,99,108,97,115,115,32,70,97,99,116,111,114,121,123,35,110,97,109,101,61,34,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,34,59,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,48,59,35,99,111,110,116,114,97,99,116,115,61,91,93,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,116,97,116,101,38,38,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,99,111,110,116,114,97,99,116,115,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,116,111,116,97,108,67,111,110,116,114,97,99,116,115,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,116,111,116,97,108,67,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,44,99,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,125,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,91,46,46,46,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,93,125,103,101,116,32,116,111,116,97,108,67,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,125,97,115,121,110,99,32,114,101,103,105,115,116,101,114,67,111,110,116,114,97,99,116,40,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,115,116,97,116,105,99,67,97,108,108,40,97,100,100,114,101,115,115,44,34,104,97,115,82,111,108,101,34,44,91,109,115,103,46,115,101,110,100,101,114,44,34,79,87,78,69,82,34,93,41,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,105,110,99,108,117,100,101,115,40,97,100,100,114,101,115,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,34,97,108,114,101,97,100,121,32,114,101,103,105,115,116,101,114,101,100,34,41,59,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,125,114,101,116,117,114,110,32,70,97,99,116,111,114,121,59,2,91,93')
|
|
57
57
|
console.log(contract);
|
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "ES2022",
|
|
4
|
-
"target": "es2022",
|
|
5
|
-
"outDir": "./exports",
|
|
6
|
-
"moduleResolution":"NodeNext",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationDir": "./exports/typings",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"allowSyntheticDefaultImports": true
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"./src/**/*"
|
|
14
|
-
],
|
|
15
|
-
"exclude": ["./node_modules"]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ES2022",
|
|
4
|
+
"target": "es2022",
|
|
5
|
+
"outDir": "./exports",
|
|
6
|
+
"moduleResolution":"NodeNext",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationDir": "./exports/typings",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"./src/**/*"
|
|
14
|
+
],
|
|
15
|
+
"exclude": ["./node_modules"]
|
|
16
16
|
}
|