@leofcoin/messages 1.3.11 → 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.
Files changed (57) hide show
  1. package/exports/index.js +30 -0
  2. package/exports/messages/block.js +56 -0
  3. package/exports/messages/bw-request.js +16 -0
  4. package/exports/messages/bw.js +18 -0
  5. package/exports/messages/contract.js +18 -0
  6. package/exports/messages/last-block-request.js +16 -0
  7. package/exports/messages/last-block.js +18 -0
  8. package/exports/messages/transaction.js +23 -0
  9. package/exports/messages/validator.js +19 -0
  10. package/{src/index.ts → exports/typings/index.d.ts} +9 -11
  11. package/exports/typings/messages/block.d.ts +25 -0
  12. package/exports/typings/messages/bw-request.d.ts +5 -0
  13. package/exports/typings/messages/bw.d.ts +5 -0
  14. package/exports/typings/messages/contract.d.ts +5 -0
  15. package/exports/typings/messages/last-block-request.d.ts +5 -0
  16. package/exports/typings/messages/last-block.d.ts +5 -0
  17. package/exports/typings/messages/publish.d.ts +5 -0
  18. package/exports/typings/messages/raw-transaction.d.ts +5 -0
  19. package/exports/typings/messages/transaction.d.ts +5 -0
  20. package/exports/typings/messages/validator.d.ts +5 -0
  21. package/exports/typings/protos/block.proto.d.ts +10 -0
  22. package/exports/typings/protos/bw-request.proto.d.ts +2 -0
  23. package/exports/typings/protos/bw.proto.d.ts +5 -0
  24. package/exports/typings/protos/contract.proto.d.ts +6 -0
  25. package/exports/typings/protos/last-block-request.proto.d.ts +2 -0
  26. package/exports/typings/protos/last-block.proto.d.ts +5 -0
  27. package/exports/typings/protos/publish.proto.d.ts +8 -0
  28. package/exports/typings/protos/raw-transaction.proto.d.ts +9 -0
  29. package/exports/typings/protos/transaction.proto.d.ts +10 -0
  30. package/exports/typings/protos/validator.proto.d.ts +5 -0
  31. package/exports/typings/workers/transaction-worker.d.ts +1 -0
  32. package/exports/workers/transaction-worker.js +23 -0
  33. package/package.json +4 -1
  34. package/rollup.config.js +0 -56
  35. package/src/messages/block.ts +0 -57
  36. package/src/messages/bw-request.ts +0 -13
  37. package/src/messages/bw.ts +0 -13
  38. package/src/messages/contract.ts +0 -12
  39. package/src/messages/last-block-request.ts +0 -13
  40. package/src/messages/last-block.ts +0 -13
  41. package/src/messages/publish.ts +0 -13
  42. package/src/messages/raw-transaction.ts +0 -13
  43. package/src/messages/transaction.ts +0 -13
  44. package/src/messages/validator.ts +0 -13
  45. package/src/protos/block.proto.js +0 -11
  46. package/src/protos/bw-request.proto.js +0 -2
  47. package/src/protos/bw.proto.js +0 -4
  48. package/src/protos/contract.proto.js +0 -5
  49. package/src/protos/last-block-request.proto.js +0 -2
  50. package/src/protos/last-block.proto.js +0 -4
  51. package/src/protos/publish.proto.js +0 -7
  52. package/src/protos/raw-transaction.proto.js +0 -8
  53. package/src/protos/transaction.proto.js +0 -9
  54. package/src/protos/validator.proto.js +0 -6
  55. package/src/types.d.ts +0 -1
  56. package/test.js +0 -49
  57. package/tsconfig.json +0 -16
@@ -0,0 +1,30 @@
1
+ export { default as BlockMessage } from './messages/block.js';
2
+ export { default as BWMessage } from './messages/bw.js';
3
+ export { default as BWRequestMessage } from './messages/bw-request.js';
4
+ export { default as ContractMessage } from './messages/contract.js';
5
+ export { default as LastBlockMessage } from './messages/last-block.js';
6
+ export { default as LastBlockRequestMessage } from './messages/last-block-request.js';
7
+ export { default as TransactionMessage } from './messages/transaction.js';
8
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
9
+ export { default as ValidatorMessage } from './messages/validator.js';
10
+
11
+ var proto = {
12
+ timestamp: Number(),
13
+ from: String(),
14
+ to: String(),
15
+ nonce: Number(),
16
+ method: String(),
17
+ params: Array()
18
+ };
19
+
20
+ class RawTransactionMessage extends FormatInterface {
21
+ get messageName() {
22
+ return 'RawTransactionMessage';
23
+ }
24
+ constructor(buffer) {
25
+ const name = 'raw-transaction-message';
26
+ super(buffer, proto, { name });
27
+ }
28
+ }
29
+
30
+ export { RawTransactionMessage };
@@ -0,0 +1,56 @@
1
+ import { BigNumber } from '@leofcoin/utils';
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
+
8
+ var proto = {
9
+ index: Number(),
10
+ previousHash: String(),
11
+ timestamp: Number(),
12
+ reward: BigNumber.from(0),
13
+ fees: BigNumber.from(0),
14
+ transactions: new Uint8Array(),
15
+ validators: new Uint8Array()
16
+ };
17
+
18
+ class BlockMessage extends FormatInterface {
19
+ get messageName() {
20
+ return 'BlockMessage';
21
+ }
22
+ constructor(buffer) {
23
+ const name = 'block-message';
24
+ super(buffer, proto, { name });
25
+ }
26
+ encode() {
27
+ const decoded = this.decoded;
28
+ const validators = [];
29
+ const transactions = [];
30
+ for (const validator of decoded.validators) {
31
+ if (validator instanceof ValidatorMessage)
32
+ validators.push(validator.encoded);
33
+ else
34
+ validators.push(new ValidatorMessage(validator).encoded);
35
+ }
36
+ for (const transaction of decoded.transactions) {
37
+ if (transaction instanceof TransactionMessage)
38
+ transactions.push(transaction.encoded);
39
+ else
40
+ transactions.push(new TransactionMessage(transaction).encoded);
41
+ }
42
+ return super.encode({
43
+ ...decoded,
44
+ validators: smartConcat(validators),
45
+ transactions: smartConcat(transactions)
46
+ });
47
+ }
48
+ decode() {
49
+ super.decode();
50
+ this.decoded.transactions = smartDeconcat(this.decoded.transactions).map(transaction => new TransactionMessage(transaction).decoded);
51
+ this.decoded.validators = smartDeconcat(this.decoded.validators).map(validator => new ValidatorMessage(validator).decoded);
52
+ return this.decoded;
53
+ }
54
+ }
55
+
56
+ export { BlockMessage as default };
@@ -0,0 +1,16 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ };
5
+
6
+ class BWRequestMessage extends FormatInterface {
7
+ get messageName() {
8
+ return 'BWRequestMessage';
9
+ }
10
+ constructor(buffer) {
11
+ const name = 'bw-request-message';
12
+ super(buffer, proto, { name });
13
+ }
14
+ }
15
+
16
+ export { BWRequestMessage as default };
@@ -0,0 +1,18 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ up: Number(),
5
+ down: Number()
6
+ };
7
+
8
+ class BWMessage extends FormatInterface {
9
+ get messageName() {
10
+ return 'BWMessage';
11
+ }
12
+ constructor(buffer) {
13
+ const name = 'bw-message';
14
+ super(buffer, proto, { name });
15
+ }
16
+ }
17
+
18
+ export { BWMessage as default };
@@ -0,0 +1,18 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ creator: String(),
5
+ contract: new Uint8Array(),
6
+ constructorParameters: Array()
7
+ };
8
+
9
+ class ContractMessage extends FormatInterface {
10
+ get messageName() {
11
+ return 'ContractMessage';
12
+ }
13
+ constructor(buffer) {
14
+ super(buffer, proto, { name: 'contract-message' });
15
+ }
16
+ }
17
+
18
+ export { ContractMessage as default };
@@ -0,0 +1,16 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ };
5
+
6
+ class LastBlockRequestMessage extends FormatInterface {
7
+ get messageName() {
8
+ return 'LastBlockRequestMessage';
9
+ }
10
+ constructor(buffer) {
11
+ const name = 'last-block-request-message';
12
+ super(buffer, proto, { name });
13
+ }
14
+ }
15
+
16
+ export { LastBlockRequestMessage as default };
@@ -0,0 +1,18 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ hash: String(),
5
+ index: Number()
6
+ };
7
+
8
+ class LastBlockMessage extends FormatInterface {
9
+ get messageName() {
10
+ return 'LastBlockMessage';
11
+ }
12
+ constructor(buffer) {
13
+ const name = 'last-block-message';
14
+ super(buffer, proto, { name });
15
+ }
16
+ }
17
+
18
+ export { LastBlockMessage as default };
@@ -0,0 +1,23 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ timestamp: Number(),
5
+ from: String(),
6
+ to: String(),
7
+ nonce: Number(),
8
+ method: String(),
9
+ params: Array(),
10
+ signature: String()
11
+ };
12
+
13
+ class TransactionMessage extends FormatInterface {
14
+ get messageName() {
15
+ return 'TransactionMessage';
16
+ }
17
+ constructor(buffer) {
18
+ const name = 'transaction-message';
19
+ super(buffer, proto, { name });
20
+ }
21
+ }
22
+
23
+ export { TransactionMessage as default };
@@ -0,0 +1,19 @@
1
+ import { BigNumber } from '@leofcoin/utils';
2
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
3
+
4
+ var proto = {
5
+ address: String(),
6
+ reward: BigNumber.from(0)
7
+ };
8
+
9
+ class ValidatorMessage extends FormatInterface {
10
+ get messageName() {
11
+ return 'ValidatorMessage';
12
+ }
13
+ constructor(buffer) {
14
+ const name = 'validator-message';
15
+ super(buffer, proto, { name });
16
+ }
17
+ }
18
+
19
+ export { ValidatorMessage as default };
@@ -1,11 +1,9 @@
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'
1
+ export { default as BlockMessage } from './messages/block.js';
2
+ export { default as BWMessage } from './messages/bw.js';
3
+ export { default as BWRequestMessage } from './messages/bw-request.js';
4
+ export { default as ContractMessage } from './messages/contract.js';
5
+ export { default as LastBlockMessage } from './messages/last-block.js';
6
+ export { default as LastBlockRequestMessage } from './messages/last-block-request.js';
7
+ export { default as TransactionMessage } from './messages/transaction.js';
8
+ export { default as RawTransactionMessage } from './messages/raw-transaction.js';
9
+ export { default as ValidatorMessage } from './messages/validator.js';
@@ -0,0 +1,25 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BigNumber } from '@leofcoin/utils';
3
+ export default class BlockMessage extends FormatInterface {
4
+ decoded: {
5
+ index: Number;
6
+ previousHash: String;
7
+ timestamp: String;
8
+ reward: BigNumber;
9
+ fees: BigNumber;
10
+ transactions: Uint8Array[] | Object[] | Uint8Array;
11
+ validators: Uint8Array[] | Object[] | Uint8Array;
12
+ };
13
+ get messageName(): string;
14
+ constructor(buffer: messageInput);
15
+ encode(): Uint8Array;
16
+ decode(): {
17
+ index: Number;
18
+ previousHash: String;
19
+ timestamp: String;
20
+ reward: BigNumber;
21
+ fees: BigNumber;
22
+ transactions: Uint8Array | Uint8Array[] | Object[];
23
+ validators: Uint8Array | Uint8Array[] | Object[];
24
+ };
25
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class BWRequestMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class BWMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class ContractMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class LastBlockRequestMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class LastBlockMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class BWRequestMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class RawTransactionMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class TransactionMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ export default class ValidatorMessage extends FormatInterface {
3
+ get messageName(): string;
4
+ constructor(buffer: messageInput);
5
+ }
@@ -0,0 +1,10 @@
1
+ declare namespace _default {
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
+ }
10
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ declare namespace _default {
2
+ let up: number;
3
+ let down: number;
4
+ }
5
+ export default _default;
@@ -0,0 +1,6 @@
1
+ declare namespace _default {
2
+ let creator: string;
3
+ let contract: Uint8Array;
4
+ let constructorParameters: any[];
5
+ }
6
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ declare namespace _default {
2
+ let hash: string;
3
+ let index: number;
4
+ }
5
+ export default _default;
@@ -0,0 +1,8 @@
1
+ declare namespace _default {
2
+ let name: string;
3
+ let version: number;
4
+ let publisher: string;
5
+ let entry: string;
6
+ let files: Uint8Array;
7
+ }
8
+ export default _default;
@@ -0,0 +1,9 @@
1
+ declare namespace _default {
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
+ }
9
+ export default _default;
@@ -0,0 +1,10 @@
1
+ declare namespace _default {
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
+ }
10
+ export default _default;
@@ -0,0 +1,5 @@
1
+ declare namespace _default {
2
+ let address: string;
3
+ let reward: any;
4
+ }
5
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import '../messages/block.js';
2
+ import '../messages/bw.js';
3
+ import '../messages/bw-request.js';
4
+ import '../messages/contract.js';
5
+ import '../messages/last-block.js';
6
+ import '../messages/last-block-request.js';
7
+ import TransactionMessage from '../messages/transaction.js';
8
+ import '../messages/validator.js';
9
+ import EasyWorker from '@vandeurenglenn/easy-worker';
10
+
11
+ globalThis.peernet = globalThis.peernet || {};
12
+ globalThis.contracts = {};
13
+ const worker = new EasyWorker();
14
+ worker.onmessage(async (transactions) => {
15
+ globalThis.peernet.codecs = {
16
+ 'transaction-message': {
17
+ codec: parseInt('746d', 16),
18
+ hashAlg: 'keccak-256'
19
+ }
20
+ };
21
+ transactions = await Promise.all(transactions.map(async (message) => (message instanceof TransactionMessage ? new Uint8Array(message.encoded) : new TransactionMessage({ ...message, signature: new Uint8Array(message.signature) }).encoded)));
22
+ worker.postMessage(transactions);
23
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/messages",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": "./exports/index.js",
@@ -12,6 +12,9 @@
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": {
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
- }]
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -1,2 +0,0 @@
1
- export default {
2
- }
@@ -1,4 +0,0 @@
1
- export default {
2
- up: Number(),
3
- down: Number()
4
- }
@@ -1,5 +0,0 @@
1
- export default {
2
- creator: String(),
3
- contract: new Uint8Array(),
4
- constructorParameters: Array()
5
- }
@@ -1,2 +0,0 @@
1
- export default {
2
- }
@@ -1,4 +0,0 @@
1
- export default {
2
- hash: String(),
3
- index: Number()
4
- }
@@ -1,7 +0,0 @@
1
- export default {
2
- name: String(),
3
- version: Number(),
4
- publisher: String(),
5
- entry: String(),
6
- files: new Uint8Array()
7
- }
@@ -1,8 +0,0 @@
1
- export default {
2
- timestamp: Number(),
3
- from: String(),
4
- to: String(),
5
- nonce: Number(),
6
- method: String(),
7
- params: Array()
8
- }
@@ -1,9 +0,0 @@
1
- export default {
2
- timestamp: Number(),
3
- from: String(),
4
- to: String(),
5
- nonce: Number(),
6
- method: String(),
7
- params: Array(),
8
- signature: String()
9
- }
@@ -1,6 +0,0 @@
1
- import { BigNumber } from "@leofcoin/utils"
2
-
3
- export default {
4
- address: String(),
5
- reward: BigNumber.from(0)
6
- }
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
- }