@leofcoin/messages 1.3.10 → 1.3.12
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/transaction.js +1 -1
- package/exports/typings/messages/block.d.ts +5 -4
- package/exports/typings/protos/block.proto.d.ts +7 -7
- package/exports/typings/protos/bw.proto.d.ts +2 -2
- package/exports/typings/protos/contract.proto.d.ts +3 -3
- package/exports/typings/protos/last-block.proto.d.ts +2 -2
- package/exports/typings/protos/publish.proto.d.ts +5 -5
- package/exports/typings/protos/raw-transaction.proto.d.ts +6 -6
- package/exports/typings/protos/transaction.proto.d.ts +7 -7
- package/exports/typings/protos/validator.proto.d.ts +2 -2
- package/package.json +11 -3
- package/rollup.config.js +0 -56
- package/src/index.ts +0 -11
- package/src/messages/block.ts +0 -57
- package/src/messages/bw-request.ts +0 -13
- package/src/messages/bw.ts +0 -13
- package/src/messages/contract.ts +0 -12
- package/src/messages/last-block-request.ts +0 -13
- package/src/messages/last-block.ts +0 -13
- package/src/messages/publish.ts +0 -13
- package/src/messages/raw-transaction.ts +0 -13
- package/src/messages/transaction.ts +0 -13
- package/src/messages/validator.ts +0 -13
- package/src/protos/block.proto.js +0 -11
- package/src/protos/bw-request.proto.js +0 -2
- package/src/protos/bw.proto.js +0 -4
- package/src/protos/contract.proto.js +0 -5
- package/src/protos/last-block-request.proto.js +0 -2
- package/src/protos/last-block.proto.js +0 -4
- package/src/protos/publish.proto.js +0 -7
- package/src/protos/raw-transaction.proto.js +0 -8
- package/src/protos/transaction.proto.js +0 -9
- package/src/protos/validator.proto.js +0 -6
- package/src/types.d.ts +0 -1
- package/test.js +0 -49
- package/tsconfig.json +0 -16
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { FormatInterface } from '@leofcoin/codec-format-interface';
|
|
2
|
+
import { BigNumber } from '@leofcoin/utils';
|
|
2
3
|
export default class BlockMessage extends FormatInterface {
|
|
3
4
|
decoded: {
|
|
4
5
|
index: Number;
|
|
5
6
|
previousHash: String;
|
|
6
7
|
timestamp: String;
|
|
7
|
-
reward:
|
|
8
|
-
fees:
|
|
8
|
+
reward: BigNumber;
|
|
9
|
+
fees: BigNumber;
|
|
9
10
|
transactions: Uint8Array[] | Object[] | Uint8Array;
|
|
10
11
|
validators: Uint8Array[] | Object[] | Uint8Array;
|
|
11
12
|
};
|
|
@@ -16,8 +17,8 @@ export default class BlockMessage extends FormatInterface {
|
|
|
16
17
|
index: Number;
|
|
17
18
|
previousHash: String;
|
|
18
19
|
timestamp: String;
|
|
19
|
-
reward:
|
|
20
|
-
fees:
|
|
20
|
+
reward: BigNumber;
|
|
21
|
+
fees: BigNumber;
|
|
21
22
|
transactions: Uint8Array | Uint8Array[] | Object[];
|
|
22
23
|
validators: Uint8Array | Uint8Array[] | Object[];
|
|
23
24
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
let index: number;
|
|
3
|
+
let previousHash: string;
|
|
4
|
+
let timestamp: number;
|
|
5
|
+
let reward: any;
|
|
6
|
+
let fees: any;
|
|
7
|
+
let transactions: Uint8Array;
|
|
8
|
+
let validators: Uint8Array;
|
|
9
9
|
}
|
|
10
10
|
export default _default;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
let name: string;
|
|
3
|
+
let version: number;
|
|
4
|
+
let publisher: string;
|
|
5
|
+
let entry: string;
|
|
6
|
+
let files: Uint8Array;
|
|
7
7
|
}
|
|
8
8
|
export default _default;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
let timestamp: number;
|
|
3
|
+
let from: string;
|
|
4
|
+
let to: string;
|
|
5
|
+
let nonce: number;
|
|
6
|
+
let method: string;
|
|
7
|
+
let params: any[];
|
|
8
8
|
}
|
|
9
9
|
export default _default;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
let timestamp: number;
|
|
3
|
+
let from: string;
|
|
4
|
+
let to: string;
|
|
5
|
+
let nonce: number;
|
|
6
|
+
let method: string;
|
|
7
|
+
let params: any[];
|
|
8
|
+
let signature: string;
|
|
9
9
|
}
|
|
10
10
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/messages",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./exports/index.js",
|
|
@@ -12,11 +12,19 @@
|
|
|
12
12
|
"./last-block": "./exports/last-block.js",
|
|
13
13
|
"./transaction": "./exports/transaction.js"
|
|
14
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"exports"
|
|
17
|
+
],
|
|
15
18
|
"type": "module",
|
|
16
19
|
"typings": "./exports/typings/index.d.ts",
|
|
17
20
|
"scripts": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "wireit"
|
|
23
|
+
},
|
|
24
|
+
"wireit": {
|
|
25
|
+
"build": {
|
|
26
|
+
"command": "rollup -c --silent error --cache true"
|
|
27
|
+
}
|
|
20
28
|
},
|
|
21
29
|
"keywords": [],
|
|
22
30
|
"author": "",
|
package/rollup.config.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import typescript from "@rollup/plugin-typescript"
|
|
2
|
-
import tsConfig from './tsconfig.json' assert { type: 'json'}
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default [{
|
|
6
|
-
input: ['./src/index.ts'],
|
|
7
|
-
output: {
|
|
8
|
-
format: 'es',
|
|
9
|
-
dir: './exports'
|
|
10
|
-
},
|
|
11
|
-
external: [
|
|
12
|
-
'./messages/block.js',
|
|
13
|
-
'./messages/bw.js',
|
|
14
|
-
'./messages/bw-request.js',
|
|
15
|
-
'./messages/contract.js',
|
|
16
|
-
'./messages/last-block.js',
|
|
17
|
-
'./messages/last-block-request.js',
|
|
18
|
-
'./messages/transaction.js',
|
|
19
|
-
'./messages/validator.js'
|
|
20
|
-
],
|
|
21
|
-
plugins: [
|
|
22
|
-
typescript(tsConfig)
|
|
23
|
-
]
|
|
24
|
-
}, {
|
|
25
|
-
input: [
|
|
26
|
-
'./src/messages/block.ts',
|
|
27
|
-
'./src/messages/bw.ts',
|
|
28
|
-
'./src/messages/bw-request.ts',
|
|
29
|
-
'./src/messages/contract.ts',
|
|
30
|
-
'./src/messages/last-block.ts',
|
|
31
|
-
'./src/messages/last-block-request.ts',
|
|
32
|
-
'./src/messages/transaction.ts',
|
|
33
|
-
'./src/messages/validator.ts'
|
|
34
|
-
],
|
|
35
|
-
output: {
|
|
36
|
-
format: 'es',
|
|
37
|
-
dir: './exports/messages'
|
|
38
|
-
},
|
|
39
|
-
external: [
|
|
40
|
-
'./messages/block.js',
|
|
41
|
-
'./messages/bw.js',
|
|
42
|
-
'./messages/bw-request.js',
|
|
43
|
-
'./messages/contract.js',
|
|
44
|
-
'./messages/last-block.js',
|
|
45
|
-
'./messages/last-block-request.js',
|
|
46
|
-
'./messages/transaction.js',
|
|
47
|
-
'./messages/validator.js'
|
|
48
|
-
],
|
|
49
|
-
plugins: [
|
|
50
|
-
typescript({"module": "ES2022",
|
|
51
|
-
"target": "es2022",
|
|
52
|
-
"moduleResolution":"NodeNext",
|
|
53
|
-
"allowJs": true,
|
|
54
|
-
"allowSyntheticDefaultImports": true, declaration: false, declarationDir: './exports/messages', outDir: './exports/messages'})
|
|
55
|
-
]
|
|
56
|
-
}]
|
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare type messageInput = Uint8Array | String | Object | ArrayBuffer
|
|
2
|
-
|
|
3
|
-
export { default as BlockMessage } from './messages/block.js'
|
|
4
|
-
export { default as BWMessage } from './messages/bw.js'
|
|
5
|
-
export { default as BWRequestMessage } from './messages/bw-request.js'
|
|
6
|
-
export { default as ContractMessage } from './messages/contract.js'
|
|
7
|
-
export { default as LastBlockMessage } from './messages/last-block.js'
|
|
8
|
-
export { default as LastBlockRequestMessage } from './messages/last-block-request.js'
|
|
9
|
-
export { default as TransactionMessage } from './messages/transaction.js'
|
|
10
|
-
export { default as RawTransactionMessage } from './messages/raw-transaction.js'
|
|
11
|
-
export { default as ValidatorMessage } from './messages/validator.js'
|
package/src/messages/block.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/block.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
import TransactionMessage from './transaction.js'
|
|
4
|
-
import ValidatorMessage from './validator.js'
|
|
5
|
-
import smartConcat from '@vandeurenglenn/typed-array-smart-concat'
|
|
6
|
-
import smartDeconcat from '@vandeurenglenn/typed-array-smart-deconcat'
|
|
7
|
-
import { BigNumber } from '@leofcoin/utils'
|
|
8
|
-
|
|
9
|
-
export default class BlockMessage extends FormatInterface {
|
|
10
|
-
declare decoded: {
|
|
11
|
-
index: Number,
|
|
12
|
-
previousHash: String,
|
|
13
|
-
timestamp: String,
|
|
14
|
-
reward: BigNumber,
|
|
15
|
-
fees: BigNumber,
|
|
16
|
-
transactions: Uint8Array[] | Object[] | Uint8Array,
|
|
17
|
-
validators: Uint8Array[] | Object[] | Uint8Array
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get messageName() {
|
|
21
|
-
return 'BlockMessage'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
constructor(buffer: messageInput) {
|
|
25
|
-
const name = 'block-message'
|
|
26
|
-
super(buffer, proto, {name})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
encode(): Uint8Array {
|
|
30
|
-
const decoded = this.decoded
|
|
31
|
-
const validators: Uint8Array[] = []
|
|
32
|
-
const transactions: Uint8Array[] = []
|
|
33
|
-
|
|
34
|
-
for (const validator of decoded.validators) {
|
|
35
|
-
if (validator instanceof ValidatorMessage) validators.push(validator.encoded)
|
|
36
|
-
else validators.push(new ValidatorMessage(validator).encoded)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (const transaction of decoded.transactions) {
|
|
40
|
-
if (transaction instanceof TransactionMessage) transactions.push(transaction.encoded)
|
|
41
|
-
else transactions.push(new TransactionMessage(transaction).encoded)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return super.encode({
|
|
45
|
-
...decoded,
|
|
46
|
-
validators: smartConcat(validators),
|
|
47
|
-
transactions: smartConcat(transactions)
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
decode() {
|
|
52
|
-
super.decode()
|
|
53
|
-
this.decoded.transactions = smartDeconcat(this.decoded.transactions as Uint8Array).map(transaction => new TransactionMessage(transaction).decoded)
|
|
54
|
-
this.decoded.validators = smartDeconcat(this.decoded.validators as Uint8Array).map(validator => new ValidatorMessage(validator).decoded)
|
|
55
|
-
return this.decoded
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/bw-request.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class BWRequestMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'BWRequestMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'bw-request-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/messages/bw.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/bw.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class BWMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'BWMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'bw-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/messages/contract.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/contract.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class ContractMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'ContractMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
super(buffer, proto, {name: 'contract-message'})
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/last-block-request.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class LastBlockRequestMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'LastBlockRequestMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'last-block-request-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/last-block.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class LastBlockMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'LastBlockMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'last-block-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/messages/publish.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/publish.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class BWRequestMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'PublishMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'publish-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/raw-transaction.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class RawTransactionMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'RawTransactionMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'raw-transaction-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/transaction.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class TransactionMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'TransactionMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'transaction-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import proto from '../protos/validator.proto.js'
|
|
2
|
-
import { FormatInterface } from '@leofcoin/codec-format-interface'
|
|
3
|
-
|
|
4
|
-
export default class ValidatorMessage extends FormatInterface {
|
|
5
|
-
get messageName() {
|
|
6
|
-
return 'ValidatorMessage'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
constructor(buffer: messageInput) {
|
|
10
|
-
const name = 'validator-message'
|
|
11
|
-
super(buffer, proto, {name})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "@leofcoin/utils"
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
index: Number(),
|
|
5
|
-
previousHash: String(),
|
|
6
|
-
timestamp: Number(),
|
|
7
|
-
reward: BigNumber.from(0),
|
|
8
|
-
fees: BigNumber.from(0),
|
|
9
|
-
transactions: new Uint8Array(),
|
|
10
|
-
validators: new Uint8Array()
|
|
11
|
-
}
|
package/src/protos/bw.proto.js
DELETED
package/src/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare type messageInput = Uint8Array | String | Object | ArrayBuffer
|
package/test.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
import { BigNumber } from "@leofcoin/utils";
|
|
5
|
-
|
|
6
|
-
console.log(globalThis.peernet);
|
|
7
|
-
// globalThis.peernet.codecs
|
|
8
|
-
const validators = [{
|
|
9
|
-
address: 'address',
|
|
10
|
-
reward: new BigNumber.from(0)
|
|
11
|
-
}]
|
|
12
|
-
|
|
13
|
-
const transactions = []
|
|
14
|
-
for (let i = 0; i <= 1; i++) {
|
|
15
|
-
transactions.push(
|
|
16
|
-
{
|
|
17
|
-
timestamp: new Date().getTime(),
|
|
18
|
-
from: 'fromAddress',
|
|
19
|
-
to: 'toAddress',
|
|
20
|
-
nonce: 0,
|
|
21
|
-
method: 'getAddress',
|
|
22
|
-
params: [],
|
|
23
|
-
signature: new Uint8Array(32)
|
|
24
|
-
}
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const block = {
|
|
29
|
-
index: 0,
|
|
30
|
-
previousHash: 'hash',
|
|
31
|
-
timestamp: new Date().getTime(),
|
|
32
|
-
reward: new BigNumber.from('0'),
|
|
33
|
-
fees: new BigNumber.from('0'),
|
|
34
|
-
transactions,
|
|
35
|
-
validators
|
|
36
|
-
}
|
|
37
|
-
const contractMessage = new ContractMessage({
|
|
38
|
-
creator: 'aaa',
|
|
39
|
-
contract: new Uint8Array(),
|
|
40
|
-
constructorParameters: []
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
const message = new BlockMessage(block)
|
|
44
|
-
console.time('message encoded')
|
|
45
|
-
console.timeEnd('message encoded')
|
|
46
|
-
console.time('normal encoded')
|
|
47
|
-
console.timeEnd('normal encoded')
|
|
48
|
-
|
|
49
|
-
const contract = new ContractMessage(contractMessage.encoded)
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|