@mainsail/crypto-block 0.0.1-evm.43 → 0.0.1-evm.44
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/distribution/block.d.ts +23 -2
- package/distribution/block.d.ts.map +1 -1
- package/distribution/block.js +65 -12
- package/distribution/block.js.map +1 -1
- package/distribution/deserializer.d.ts +0 -2
- package/distribution/deserializer.d.ts.map +1 -1
- package/distribution/deserializer.js +14 -52
- package/distribution/deserializer.js.map +1 -1
- package/distribution/factory.d.ts +3 -2
- package/distribution/factory.d.ts.map +1 -1
- package/distribution/factory.js +57 -71
- package/distribution/factory.js.map +1 -1
- package/distribution/hash.factory.d.ts.map +1 -1
- package/distribution/hash.factory.js +1 -2
- package/distribution/hash.factory.js.map +1 -1
- package/distribution/schemas.d.ts +1 -1
- package/distribution/schemas.d.ts.map +1 -1
- package/distribution/schemas.js +43 -17
- package/distribution/schemas.js.map +1 -1
- package/distribution/serializer-schemas.d.ts +2 -2
- package/distribution/serializer-schemas.d.ts.map +1 -1
- package/distribution/serializer-schemas.js +3 -3
- package/distribution/serializer-schemas.js.map +1 -1
- package/distribution/serializer.d.ts +2 -2
- package/distribution/serializer.d.ts.map +1 -1
- package/distribution/serializer.js +3 -3
- package/distribution/serializer.js.map +1 -1
- package/package.json +22 -19
package/distribution/block.d.ts
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import type { Contracts } from "@mainsail/contracts";
|
|
2
|
+
import type { BigNumber } from "@mainsail/utils";
|
|
2
3
|
interface BlockArguments {
|
|
3
|
-
data: Contracts.Crypto.
|
|
4
|
+
data: Contracts.Crypto.BlockHeader;
|
|
4
5
|
serialized: string;
|
|
5
6
|
transactions: Contracts.Crypto.Transaction[];
|
|
6
7
|
}
|
|
7
|
-
export declare
|
|
8
|
+
export declare class Block implements Contracts.Crypto.Block {
|
|
9
|
+
readonly timestamp: number;
|
|
10
|
+
readonly version: number;
|
|
11
|
+
readonly number: number;
|
|
12
|
+
readonly round: number;
|
|
13
|
+
readonly parentHash: string;
|
|
14
|
+
readonly stateRoot: string;
|
|
15
|
+
readonly logsBloom: string;
|
|
16
|
+
readonly transactionsCount: number;
|
|
17
|
+
readonly gasUsed: number;
|
|
18
|
+
readonly fee: BigNumber;
|
|
19
|
+
readonly reward: BigNumber;
|
|
20
|
+
readonly payloadSize: number;
|
|
21
|
+
readonly transactionsRoot: string;
|
|
22
|
+
readonly proposer: string;
|
|
23
|
+
readonly hash: string;
|
|
24
|
+
readonly serialized: string;
|
|
25
|
+
readonly transactions: Contracts.Crypto.BlockTransaction[];
|
|
26
|
+
constructor({ data, serialized, transactions }: BlockArguments);
|
|
27
|
+
toData(): Contracts.Crypto.BlockData;
|
|
28
|
+
}
|
|
8
29
|
export {};
|
|
9
30
|
//# sourceMappingURL=block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,UAAU,cAAc;IACvB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,UAAU,cAAc;IACvB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;CAC7C;AAED,qBAAa,KAAM,YAAW,SAAS,CAAC,MAAM,CAAC,KAAK;IACnD,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,iBAAiB,EAAE,MAAM,CAAC;IAC1C,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,GAAG,EAAE,SAAS,CAAC;IAC/B,SAAgB,MAAM,EAAE,SAAS,CAAC;IAClC,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,SAAgB,gBAAgB,EAAE,MAAM,CAAC;IACzC,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;gBAE/C,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,cAAc;IA6BrE,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,SAAS;CAsBpC"}
|
package/distribution/block.js
CHANGED
|
@@ -1,13 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { BlockTransaction } from "@mainsail/crypto-transaction";
|
|
2
|
+
export class Block {
|
|
3
|
+
timestamp;
|
|
4
|
+
version;
|
|
5
|
+
number;
|
|
6
|
+
round;
|
|
7
|
+
parentHash;
|
|
8
|
+
stateRoot;
|
|
9
|
+
logsBloom;
|
|
10
|
+
transactionsCount;
|
|
11
|
+
gasUsed;
|
|
12
|
+
fee;
|
|
13
|
+
reward;
|
|
14
|
+
payloadSize;
|
|
15
|
+
transactionsRoot;
|
|
16
|
+
proposer;
|
|
17
|
+
hash;
|
|
18
|
+
serialized;
|
|
19
|
+
transactions;
|
|
20
|
+
constructor({ data, serialized, transactions }) {
|
|
21
|
+
this.timestamp = data.timestamp;
|
|
22
|
+
this.version = data.version;
|
|
23
|
+
this.number = data.number;
|
|
24
|
+
this.round = data.round;
|
|
25
|
+
this.parentHash = data.parentHash;
|
|
26
|
+
this.stateRoot = data.stateRoot;
|
|
27
|
+
this.logsBloom = data.logsBloom;
|
|
28
|
+
this.transactionsCount = data.transactionsCount;
|
|
29
|
+
this.gasUsed = data.gasUsed;
|
|
30
|
+
this.fee = data.fee;
|
|
31
|
+
this.reward = data.reward;
|
|
32
|
+
this.payloadSize = data.payloadSize;
|
|
33
|
+
this.transactionsRoot = data.transactionsRoot;
|
|
34
|
+
this.proposer = data.proposer;
|
|
35
|
+
this.hash = data.hash;
|
|
36
|
+
this.serialized = serialized;
|
|
37
|
+
this.transactions = transactions.map((transaction, index) => new BlockTransaction(transaction, transaction.serialized, {
|
|
38
|
+
blockHash: this.hash,
|
|
39
|
+
blockNumber: this.number,
|
|
40
|
+
transactionIndex: index,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
toData() {
|
|
44
|
+
return {
|
|
45
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
46
|
+
timestamp: this.timestamp,
|
|
47
|
+
version: this.version,
|
|
48
|
+
number: this.number,
|
|
49
|
+
round: this.round,
|
|
50
|
+
parentHash: this.parentHash,
|
|
51
|
+
stateRoot: this.stateRoot,
|
|
52
|
+
logsBloom: this.logsBloom,
|
|
53
|
+
transactionsCount: this.transactionsCount,
|
|
54
|
+
gasUsed: this.gasUsed,
|
|
55
|
+
fee: this.fee,
|
|
56
|
+
reward: this.reward,
|
|
57
|
+
payloadSize: this.payloadSize,
|
|
58
|
+
transactionsRoot: this.transactionsRoot,
|
|
59
|
+
proposer: this.proposer,
|
|
60
|
+
hash: this.hash,
|
|
61
|
+
transactions: this.transactions.map((transaction) => transaction.toData()),
|
|
62
|
+
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
13
66
|
//# sourceMappingURL=block.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAShE,MAAM,OAAO,KAAK;IACD,SAAS,CAAS;IAClB,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,KAAK,CAAS;IACd,UAAU,CAAS;IACnB,SAAS,CAAS;IAClB,SAAS,CAAS;IAClB,iBAAiB,CAAS;IAC1B,OAAO,CAAS;IAChB,GAAG,CAAY;IACf,MAAM,CAAY;IAClB,WAAW,CAAS;IACpB,gBAAgB,CAAS;IACzB,QAAQ,CAAS;IACjB,IAAI,CAAS;IACb,UAAU,CAAS;IACnB,YAAY,CAAsC;IAElE,YAAmB,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAkB;QACpE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;QAChD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CA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,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YAC1E,+CAA+C;SAC/C,CAAC;IACH,CAAC;CACD"}
|
|
@@ -3,10 +3,8 @@ export declare class Deserializer implements Contracts.Crypto.BlockDeserializer
|
|
|
3
3
|
#private;
|
|
4
4
|
private readonly hashFactory;
|
|
5
5
|
private readonly transactionFactory;
|
|
6
|
-
private readonly transactionDeserializer;
|
|
7
6
|
private readonly serializer;
|
|
8
7
|
private readonly headerSize;
|
|
9
|
-
private readonly workerPool;
|
|
10
8
|
deserializeHeader(serialized: Buffer): Promise<Contracts.Crypto.BlockHeader>;
|
|
11
9
|
deserializeWithTransactions(serialized: Buffer): Promise<Contracts.Crypto.BlockWithTransactions>;
|
|
12
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAOrD,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,iBAAiB;;IAEtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAG1E,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAOrD,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,iBAAiB;;IAEtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAG1E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE9B,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;IAW5E,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC;CA8D7G"}
|
|
@@ -8,18 +8,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Identifiers } from "@mainsail/constants";
|
|
11
|
-
import { inject, injectable
|
|
12
|
-
import {
|
|
13
|
-
import { ByteBuffer
|
|
11
|
+
import { inject, injectable } from "@mainsail/container";
|
|
12
|
+
import { InvalidBlockBytesError } from "@mainsail/exceptions";
|
|
13
|
+
import { ByteBuffer } from "@mainsail/utils";
|
|
14
14
|
import { HashFactory } from "./hash.factory.js";
|
|
15
|
-
import {
|
|
15
|
+
import { blockHeaderSchema, transactionsSchema } from "./serializer-schemas.js";
|
|
16
16
|
let Deserializer = class Deserializer {
|
|
17
17
|
hashFactory;
|
|
18
18
|
transactionFactory;
|
|
19
|
-
transactionDeserializer;
|
|
20
19
|
serializer;
|
|
21
20
|
headerSize;
|
|
22
|
-
workerPool;
|
|
23
21
|
async deserializeHeader(serialized) {
|
|
24
22
|
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
25
23
|
const header = await this.#deserializeBufferHeader(buffer);
|
|
@@ -35,60 +33,33 @@ let Deserializer = class Deserializer {
|
|
|
35
33
|
if (buffer.getRemainderLength() > 0) {
|
|
36
34
|
transactions = await this.#deserializeTransactions(header, buffer);
|
|
37
35
|
}
|
|
36
|
+
if (buffer.getRemainderLength() !== 0) {
|
|
37
|
+
throw new InvalidBlockBytesError(`Found trailing bytes of length ${buffer.getRemainderLength()}`);
|
|
38
|
+
}
|
|
38
39
|
return {
|
|
39
40
|
data: {
|
|
40
41
|
...header,
|
|
41
42
|
hash: await this.hashFactory.make(header),
|
|
42
|
-
transactions: transactions.map((tx) => tx.data),
|
|
43
43
|
},
|
|
44
44
|
transactions,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
async #deserializeBufferHeader(buffer) {
|
|
48
|
-
|
|
48
|
+
const header = await this.serializer.deserialize(buffer, {}, {
|
|
49
49
|
length: this.headerSize(),
|
|
50
|
-
schema,
|
|
50
|
+
schema: blockHeaderSchema,
|
|
51
51
|
});
|
|
52
|
+
if (buffer.getRemainderLength() !== header.payloadSize) {
|
|
53
|
+
throw new InvalidBlockBytesError(`Payload size ${header.payloadSize} does not match actual payload size ${buffer.getRemainderLength()}`);
|
|
54
|
+
}
|
|
55
|
+
return header;
|
|
52
56
|
}
|
|
53
57
|
async #deserializeTransactions(header, buf) {
|
|
54
58
|
const block = await this.serializer.deserialize(buf, { ...header }, {
|
|
55
59
|
length: header.payloadSize,
|
|
56
60
|
schema: transactionsSchema,
|
|
57
61
|
});
|
|
58
|
-
|
|
59
|
-
* After unpacking we need to turn the transactions into DTOs!
|
|
60
|
-
*
|
|
61
|
-
* We keep this behavior out of the (de)serializer because it
|
|
62
|
-
* is very specific to this bit of code in this specific class.
|
|
63
|
-
*/
|
|
64
|
-
const transactions = Array.from({ length: block.transactionsCount });
|
|
65
|
-
await Promise.all(block.transactions.map(async (serialized, index) => {
|
|
66
|
-
const transaction = await this.transactionDeserializer.deserialize(serialized);
|
|
67
|
-
if (index % 20 === 0) {
|
|
68
|
-
await sleep(0);
|
|
69
|
-
}
|
|
70
|
-
const computed = await this.#computeCryptoData(transaction.data);
|
|
71
|
-
if (computed.schemaError) {
|
|
72
|
-
throw new TransactionSchemaError(computed.schemaError);
|
|
73
|
-
}
|
|
74
|
-
transaction.data.data = transaction.data.data.startsWith("0x")
|
|
75
|
-
? transaction.data.data.slice(2)
|
|
76
|
-
: transaction.data.data;
|
|
77
|
-
transaction.data.hash = computed.hash;
|
|
78
|
-
transaction.data.from = computed.address;
|
|
79
|
-
transaction.data.senderPublicKey = computed.publicKey;
|
|
80
|
-
transaction.data.senderLegacyAddress = computed.legacyAddress;
|
|
81
|
-
transactions[index] = transaction;
|
|
82
|
-
block.transactions[index] = transaction.data;
|
|
83
|
-
}));
|
|
84
|
-
return transactions;
|
|
85
|
-
}
|
|
86
|
-
async #computeCryptoData(transaction) {
|
|
87
|
-
if (this.workerPool) {
|
|
88
|
-
const worker = await this.workerPool.getWorker();
|
|
89
|
-
return worker.transactionFactory("computeCryptoData", transaction);
|
|
90
|
-
}
|
|
91
|
-
return this.transactionFactory.computeCryptoData(transaction);
|
|
62
|
+
return Promise.all(block.transactions.map(async (serialized) => this.transactionFactory.fromBytes(serialized)));
|
|
92
63
|
}
|
|
93
64
|
};
|
|
94
65
|
__decorate([
|
|
@@ -99,10 +70,6 @@ __decorate([
|
|
|
99
70
|
inject(Identifiers.Cryptography.Transaction.Factory),
|
|
100
71
|
__metadata("design:type", Object)
|
|
101
72
|
], Deserializer.prototype, "transactionFactory", void 0);
|
|
102
|
-
__decorate([
|
|
103
|
-
inject(Identifiers.Cryptography.Transaction.Deserializer),
|
|
104
|
-
__metadata("design:type", Object)
|
|
105
|
-
], Deserializer.prototype, "transactionDeserializer", void 0);
|
|
106
73
|
__decorate([
|
|
107
74
|
inject(Identifiers.Cryptography.Serializer),
|
|
108
75
|
__metadata("design:type", Object)
|
|
@@ -111,11 +78,6 @@ __decorate([
|
|
|
111
78
|
inject(Identifiers.Cryptography.Block.HeaderSize),
|
|
112
79
|
__metadata("design:type", Function)
|
|
113
80
|
], Deserializer.prototype, "headerSize", void 0);
|
|
114
|
-
__decorate([
|
|
115
|
-
inject(Identifiers.CryptoWorker.WorkerPool),
|
|
116
|
-
optional(),
|
|
117
|
-
__metadata("design:type", Object)
|
|
118
|
-
], Deserializer.prototype, "workerPool", void 0);
|
|
119
81
|
Deserializer = __decorate([
|
|
120
82
|
injectable()
|
|
121
83
|
], Deserializer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGzE,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEP,WAAW,CAAe;IAG1B,kBAAkB,CAAuC;IAGzD,UAAU,CAAmC;IAG7C,UAAU,CAAgB;IAEpC,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QAChD,MAAM,MAAM,GAAe,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAE7D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAE3D,OAAO;YACN,GAAG,MAAM;YACT,IAAI,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;SACzC,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,2BAA2B,CAAC,UAAkB;QAC1D,MAAM,MAAM,GAAe,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAE7D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAA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,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAC3C,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,UAA+B,CAAC,CAClE,CACD,CAAC;IACH,CAAC;CACD,CAAA;AApFiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC;8BACpB,WAAW;iDAAC;AAG1B;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC;;wDACqB;AAGzD;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;gDACkB;AAG7C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;gDACP;AAX/B,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAsFxB"}
|
|
@@ -6,11 +6,12 @@ export declare class BlockFactory implements Contracts.Crypto.BlockFactory {
|
|
|
6
6
|
private readonly hashFactory;
|
|
7
7
|
private readonly transactionFactory;
|
|
8
8
|
private readonly validator;
|
|
9
|
-
make(data: Contracts.Crypto.
|
|
9
|
+
make(data: Contracts.Crypto.BlockHeaderRaw, transactions: Contracts.Crypto.Transaction[]): Promise<Contracts.Crypto.Block>;
|
|
10
10
|
fromHex(hex: string): Promise<Contracts.Crypto.Block>;
|
|
11
11
|
fromBytes(buff: Buffer): Promise<Contracts.Crypto.Block>;
|
|
12
|
+
fromStorage(header: Contracts.Evm.BlockHeaderStorageData, transactions: Contracts.Evm.TransactionStorageData[]): Promise<Contracts.Crypto.Block>;
|
|
13
|
+
headerFromStorage(header: Contracts.Evm.BlockHeaderStorageData): Promise<Contracts.Crypto.BlockHeader>;
|
|
12
14
|
fromJson(json: Contracts.Crypto.BlockJson): Promise<Contracts.Crypto.Block>;
|
|
13
15
|
fromData(data: Contracts.Crypto.BlockData): Promise<Contracts.Crypto.Block>;
|
|
14
|
-
fromStorage(header: Contracts.Evm.BlockHeaderStorageData, transactions: Contracts.Evm.TransactionStorageData[]): Promise<Contracts.Crypto.Block>;
|
|
15
16
|
}
|
|
16
17
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAOrD,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,YAAY;;IAEjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAG/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IAGnE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAG1E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAE3C,IAAI,CAChB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,cAAc,EACrC,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,GAC1C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAcrB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAIrD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAIxD,WAAW,CACvB,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,sBAAsB,EAC5C,YAAY,EAAE,SAAS,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAClD,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAkBrB,iBAAiB,CAC7B,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,sBAAsB,GAC1C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;IAoB3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAe3E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;CAmCxF"}
|
package/distribution/factory.js
CHANGED
|
@@ -11,7 +11,7 @@ import { Identifiers } from "@mainsail/constants";
|
|
|
11
11
|
import { inject, injectable } from "@mainsail/container";
|
|
12
12
|
import { BlockSchemaError } from "@mainsail/exceptions";
|
|
13
13
|
import { BigNumber } from "@mainsail/utils";
|
|
14
|
-
import {
|
|
14
|
+
import { Block } from "./block.js";
|
|
15
15
|
import { HashFactory } from "./hash.factory.js";
|
|
16
16
|
let BlockFactory = class BlockFactory {
|
|
17
17
|
serializer;
|
|
@@ -21,8 +21,9 @@ let BlockFactory = class BlockFactory {
|
|
|
21
21
|
validator;
|
|
22
22
|
async make(data, transactions) {
|
|
23
23
|
const block = { ...data, hash: await this.hashFactory.make(data) };
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
await this.#verify({ ...block, transactions });
|
|
25
|
+
const serialized = await this.serializer.serializeWithTransactions({ ...data, transactions });
|
|
26
|
+
return new Block({
|
|
26
27
|
data: block,
|
|
27
28
|
serialized: serialized.toString("hex"),
|
|
28
29
|
transactions,
|
|
@@ -34,89 +35,74 @@ let BlockFactory = class BlockFactory {
|
|
|
34
35
|
async fromBytes(buff) {
|
|
35
36
|
return this.#fromSerialized(buff);
|
|
36
37
|
}
|
|
38
|
+
async fromStorage(header, transactions) {
|
|
39
|
+
const parsedTransactions = await Promise.all(transactions.map((tx) => this.transactionFactory.fromStorage({ ...tx, blockHash: header.hash })));
|
|
40
|
+
const data = await this.headerFromStorage(header);
|
|
41
|
+
const serialized = await this.serializer.serializeWithTransactions({
|
|
42
|
+
...data,
|
|
43
|
+
transactions: parsedTransactions,
|
|
44
|
+
});
|
|
45
|
+
return new Block({
|
|
46
|
+
data,
|
|
47
|
+
serialized: serialized.toString("hex"),
|
|
48
|
+
transactions: parsedTransactions,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async headerFromStorage(header) {
|
|
52
|
+
return {
|
|
53
|
+
fee: BigNumber.make(header.fee),
|
|
54
|
+
gasUsed: header.gasUsed,
|
|
55
|
+
hash: header.hash,
|
|
56
|
+
logsBloom: header.logsBloom,
|
|
57
|
+
number: header.number,
|
|
58
|
+
parentHash: header.parentHash,
|
|
59
|
+
payloadSize: header.payloadSize,
|
|
60
|
+
proposer: header.proposer,
|
|
61
|
+
reward: BigNumber.make(header.reward),
|
|
62
|
+
round: header.round,
|
|
63
|
+
stateRoot: header.stateRoot,
|
|
64
|
+
timestamp: Number(header.timestamp),
|
|
65
|
+
transactionsCount: header.transactionsCount,
|
|
66
|
+
transactionsRoot: header.transactionsRoot,
|
|
67
|
+
version: header.version,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
37
70
|
async fromJson(json) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
71
|
+
const data = {
|
|
72
|
+
...json,
|
|
73
|
+
fee: BigNumber.make(json.fee),
|
|
74
|
+
reward: BigNumber.make(json.reward),
|
|
75
|
+
transactions: json.transactions.map((tx) => ({
|
|
76
|
+
...tx,
|
|
77
|
+
nonce: BigNumber.make(tx.nonce),
|
|
78
|
+
value: BigNumber.make(tx.value),
|
|
79
|
+
})),
|
|
80
|
+
};
|
|
48
81
|
return this.fromData(data);
|
|
49
82
|
}
|
|
50
83
|
async fromData(data) {
|
|
51
|
-
await this.#
|
|
52
|
-
const
|
|
53
|
-
|
|
84
|
+
await this.#verify(data);
|
|
85
|
+
const transactions = await Promise.all(data.transactions.map((tx) => this.transactionFactory.fromData(tx, false)));
|
|
86
|
+
const serialized = await this.serializer.serializeWithTransactions({ ...data, transactions });
|
|
87
|
+
return new Block({
|
|
54
88
|
...(await this.deserializer.deserializeWithTransactions(serialized)),
|
|
55
89
|
serialized: serialized.toString("hex"),
|
|
56
90
|
});
|
|
57
91
|
}
|
|
58
|
-
async fromStorage(header, transactions) {
|
|
59
|
-
const parsedTransactions = await Promise.all(transactions.map((tx) => this.transactionFactory.fromStorage(tx)));
|
|
60
|
-
return sealBlock({
|
|
61
|
-
data: {
|
|
62
|
-
fee: BigNumber.make(header.fee),
|
|
63
|
-
gasUsed: header.gasUsed,
|
|
64
|
-
hash: header.hash,
|
|
65
|
-
logsBloom: header.logsBloom,
|
|
66
|
-
number: header.number,
|
|
67
|
-
parentHash: header.parentHash,
|
|
68
|
-
payloadSize: header.payloadSize,
|
|
69
|
-
proposer: header.proposer,
|
|
70
|
-
reward: BigNumber.make(header.reward),
|
|
71
|
-
round: header.round,
|
|
72
|
-
stateRoot: header.stateRoot,
|
|
73
|
-
timestamp: Number(header.timestamp),
|
|
74
|
-
transactions: parsedTransactions.map((tx) => tx.data),
|
|
75
|
-
transactionsCount: header.transactionsCount,
|
|
76
|
-
transactionsRoot: header.transactionsRoot,
|
|
77
|
-
version: header.version,
|
|
78
|
-
},
|
|
79
|
-
serialized: "",
|
|
80
|
-
transactions: parsedTransactions,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
92
|
async #fromSerialized(serialized) {
|
|
84
93
|
const deserialized = await this.deserializer.deserializeWithTransactions(serialized);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
deserialized.data = validated;
|
|
88
|
-
}
|
|
89
|
-
return sealBlock({
|
|
94
|
+
await this.#verify({ ...deserialized.data, transactions: deserialized.transactions });
|
|
95
|
+
return new Block({
|
|
90
96
|
...deserialized,
|
|
91
97
|
serialized: serialized.toString("hex"),
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
|
-
async #
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
for (const error of result.errors ?? []) {
|
|
100
|
-
let fatal = false;
|
|
101
|
-
const match = error.instancePath.match(/\.transactions\[(\d+)]/);
|
|
102
|
-
if (match === null) {
|
|
103
|
-
fatal = true;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
if (data.transactions) {
|
|
107
|
-
const txIndex = Number(match[1]);
|
|
108
|
-
const tx = data.transactions[txIndex];
|
|
109
|
-
if (tx.hash === undefined) {
|
|
110
|
-
fatal = true;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (fatal) {
|
|
115
|
-
throw new BlockSchemaError(data.number, `Invalid data${error.instancePath ? " at " + error.instancePath : ""}: ` +
|
|
116
|
-
`${error.message}: ${JSON.stringify(error.data)}`);
|
|
117
|
-
}
|
|
100
|
+
async #verify(data) {
|
|
101
|
+
const { error } = this.validator.validate("block", data);
|
|
102
|
+
if (!error) {
|
|
103
|
+
return;
|
|
118
104
|
}
|
|
119
|
-
|
|
105
|
+
throw new BlockSchemaError(data.number, error);
|
|
120
106
|
}
|
|
121
107
|
};
|
|
122
108
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO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"version":3,"file":"hash.factory.d.ts","sourceRoot":"","sources":["../source/hash.factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBACa,WAAW;IAEvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAG5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAElD,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"hash.factory.d.ts","sourceRoot":"","sources":["../source/hash.factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBACa,WAAW;IAEvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAG5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAElD,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;CAGzE"}
|
|
@@ -13,8 +13,7 @@ let HashFactory = class HashFactory {
|
|
|
13
13
|
hashFactory;
|
|
14
14
|
serializer;
|
|
15
15
|
async make(data) {
|
|
16
|
-
|
|
17
|
-
return buffer.toString("hex");
|
|
16
|
+
return this.hashFactory.sha256(await this.serializer.serializeHeader(data)).toString("hex");
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
19
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.factory.js","sourceRoot":"","sources":["../source/hash.factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAIlD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEN,WAAW,CAAgC;IAG3C,UAAU,CAAoC;IAExD,KAAK,CAAC,IAAI,CAAC,IAAqC;QACtD,
|
|
1
|
+
{"version":3,"file":"hash.factory.js","sourceRoot":"","sources":["../source/hash.factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAIlD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEN,WAAW,CAAgC;IAG3C,UAAU,CAAoC;IAExD,KAAK,CAAC,IAAI,CAAC,IAAqC;QACtD,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7F,CAAC;CACD,CAAA;AARiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;;gDACc;AAG3C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;+CACa;AALnD,WAAW;IADvB,UAAU,EAAE;GACA,WAAW,CAUvB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AnySchemaObject } from "ajv";
|
|
2
|
-
export declare const schemas: Record<"block" | "blockHash" | "prefixedBlockHash" | "blockHeader" | "logsBloom", AnySchemaObject>;
|
|
2
|
+
export declare const schemas: Record<"block" | "blockHash" | "prefixedBlockHash" | "blockHeader" | "logsBloom" | "stateRoot" | "transactionsRoot", AnySchemaObject>;
|
|
3
3
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAE3C,eAAO,MAAM,OAAO,EAAE,MAAM,CAC3B,OAAO,GAAG,WAAW,GAAG,mBAAmB,GAAG,aAAa,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAE3C,eAAO,MAAM,OAAO,EAAE,MAAM,CAC3B,OAAO,GAAG,WAAW,GAAG,mBAAmB,GAAG,aAAa,GAAG,WAAW,GAAG,WAAW,GAAG,kBAAkB,EAC5G,eAAe,CA8Gf,CAAC"}
|
package/distribution/schemas.js
CHANGED
|
@@ -26,36 +26,40 @@ export const schemas = {
|
|
|
26
26
|
blockHeader: {
|
|
27
27
|
$id: "blockHeader",
|
|
28
28
|
properties: {
|
|
29
|
-
|
|
30
|
-
gasUsed: { minimum: 0, type: "integer" },
|
|
29
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
31
30
|
hash: { $ref: "blockHash" },
|
|
32
|
-
|
|
31
|
+
version: { enum: [1] },
|
|
32
|
+
timestamp: { maximum: 2 ** 48 - 1, minimum: 0, type: "integer" },
|
|
33
33
|
number: { minimum: 0, type: "integer" },
|
|
34
|
+
round: { minimum: 0, type: "integer" },
|
|
34
35
|
parentHash: { $ref: "blockHash" },
|
|
36
|
+
stateRoot: { $ref: "stateRoot" },
|
|
37
|
+
logsBloom: { $ref: "logsBloom" },
|
|
38
|
+
transactionsCount: { minimum: 0, type: "integer" },
|
|
39
|
+
gasUsed: { minimum: 0, type: "integer" },
|
|
40
|
+
fee: { bignumber: { minimum: 0 } },
|
|
41
|
+
reward: { bignumber: { minimum: 0 } },
|
|
35
42
|
payloadSize: { minimum: 0, type: "integer" },
|
|
43
|
+
transactionsRoot: { $ref: "transactionsRoot" },
|
|
36
44
|
proposer: { $ref: "address" },
|
|
37
|
-
|
|
38
|
-
stateRoot: { $ref: "hex" },
|
|
39
|
-
timestamp: { maximum: 2 ** 48 - 1, minimum: 0, type: "integer" },
|
|
40
|
-
transactionsCount: { minimum: 0, type: "integer" },
|
|
41
|
-
transactionsRoot: { $ref: "hex" },
|
|
42
|
-
version: { enum: [1] },
|
|
45
|
+
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
43
46
|
},
|
|
44
47
|
required: [
|
|
45
|
-
"fee",
|
|
46
|
-
"gasUsed",
|
|
47
48
|
"hash",
|
|
48
|
-
"
|
|
49
|
+
"version",
|
|
50
|
+
"timestamp",
|
|
49
51
|
"number",
|
|
52
|
+
"round",
|
|
50
53
|
"parentHash",
|
|
51
|
-
"payloadSize",
|
|
52
|
-
"proposer",
|
|
53
|
-
"reward",
|
|
54
54
|
"stateRoot",
|
|
55
|
-
"
|
|
55
|
+
"logsBloom",
|
|
56
56
|
"transactionsCount",
|
|
57
|
+
"gasUsed",
|
|
58
|
+
"fee",
|
|
59
|
+
"reward",
|
|
60
|
+
"payloadSize",
|
|
57
61
|
"transactionsRoot",
|
|
58
|
-
"
|
|
62
|
+
"proposer",
|
|
59
63
|
],
|
|
60
64
|
type: "object",
|
|
61
65
|
},
|
|
@@ -81,5 +85,27 @@ export const schemas = {
|
|
|
81
85
|
],
|
|
82
86
|
type: "string",
|
|
83
87
|
},
|
|
88
|
+
stateRoot: {
|
|
89
|
+
$id: "stateRoot",
|
|
90
|
+
allOf: [
|
|
91
|
+
{
|
|
92
|
+
$ref: "hex",
|
|
93
|
+
maxLength: 64,
|
|
94
|
+
minLength: 64,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
type: "string",
|
|
98
|
+
},
|
|
99
|
+
transactionsRoot: {
|
|
100
|
+
$id: "transactionsRoot",
|
|
101
|
+
allOf: [
|
|
102
|
+
{
|
|
103
|
+
$ref: "hex",
|
|
104
|
+
maxLength: 64,
|
|
105
|
+
minLength: 64,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
type: "string",
|
|
109
|
+
},
|
|
84
110
|
};
|
|
85
111
|
//# sourceMappingURL=schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAGhB;IACH,KAAK,EAAE;QACN,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE;YACX,YAAY,EAAE;gBACb,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE;gBAC1C,QAAQ,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE;gBAC1C,IAAI,EAAE,OAAO;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,SAAS,EAAE;QACV,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,WAAW,EAAE;QACZ,GAAG,EAAE,aAAa;QAClB,UAAU,EAAE;YACX,
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAGhB;IACH,KAAK,EAAE;QACN,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE;YACX,YAAY,EAAE;gBACb,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE;gBAC1C,QAAQ,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE;gBAC1C,IAAI,EAAE,OAAO;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,SAAS,EAAE;QACV,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,WAAW,EAAE;QACZ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kBAAkB;YAClB,UAAU;SACV;QACD,IAAI,EAAE,QAAQ;KACd;IACD,SAAS,EAAE;QACV,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,GAAG;gBACd,SAAS,EAAE,GAAG;aACd;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,iBAAiB,EAAE;QAClB,GAAG,EAAE,mBAAmB;QACxB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,qBAAqB;gBAC3B,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,SAAS,EAAE;QACV,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,gBAAgB,EAAE;QACjB,GAAG,EAAE,kBAAkB;QACvB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;CACD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Contracts } from "@mainsail/contracts";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const blockHeaderSchema: Record<string, Contracts.Serializer.DeserializationSchema>;
|
|
3
3
|
export declare const transactionsSchema: Record<string, Contracts.Serializer.SerializationSchema>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const blockSchema: Record<string, Contracts.Serializer.SerializationSchema>;
|
|
5
5
|
//# sourceMappingURL=serializer-schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer-schemas.d.ts","sourceRoot":"","sources":["../source/serializer-schemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"serializer-schemas.d.ts","sourceRoot":"","sources":["../source/serializer-schemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,qBAAqB,CA4CxF,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAIvF,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAKhF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const blockHeaderSchema = {
|
|
2
2
|
version: {
|
|
3
3
|
type: "uint8",
|
|
4
4
|
},
|
|
@@ -48,8 +48,8 @@ export const transactionsSchema = {
|
|
|
48
48
|
type: "transactions",
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
|
-
export const
|
|
52
|
-
...
|
|
51
|
+
export const blockSchema = {
|
|
52
|
+
...blockHeaderSchema,
|
|
53
53
|
transactions: {
|
|
54
54
|
type: "transactions",
|
|
55
55
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer-schemas.js","sourceRoot":"","sources":["../source/serializer-schemas.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"serializer-schemas.js","sourceRoot":"","sources":["../source/serializer-schemas.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,iBAAiB,GAA+D;IAC5F,OAAO,EAAE;QACR,IAAI,EAAE,OAAO;KACb;IACD,SAAS,EAAE;QACV,IAAI,EAAE,QAAQ;KACd;IACD,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ;KACd;IACD,KAAK,EAAE;QACN,IAAI,EAAE,QAAQ;KACd;IACD,UAAU,EAAE;QACX,IAAI,EAAE,MAAM;KACZ;IACD,SAAS,EAAE;QACV,IAAI,EAAE,MAAM;KACZ;IACD,SAAS,EAAE;QACV,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,GAAG;KACT;IACD,iBAAiB,EAAE;QAClB,IAAI,EAAE,QAAQ;KACd;IACD,OAAO,EAAE;QACR,IAAI,EAAE,QAAQ;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,SAAS;KACf;IACD,MAAM,EAAE;QACP,IAAI,EAAE,SAAS;KACf;IACD,WAAW,EAAE;QACZ,IAAI,EAAE,QAAQ;KACd;IACD,gBAAgB,EAAE;QACjB,IAAI,EAAE,MAAM;KACZ;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,SAAS;KACf;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAA6D;IAC3F,YAAY,EAAE;QACb,IAAI,EAAE,cAAc;KACpB;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAA6D;IACpF,GAAG,iBAAiB;IACpB,YAAY,EAAE;QACb,IAAI,EAAE,cAAc;KACpB;CACD,CAAC"}
|
|
@@ -2,8 +2,8 @@ import type { Contracts } from "@mainsail/contracts";
|
|
|
2
2
|
export declare class Serializer implements Contracts.Crypto.BlockSerializer {
|
|
3
3
|
private readonly serializer;
|
|
4
4
|
private readonly headerSize;
|
|
5
|
-
totalSize(block: Contracts.Crypto.
|
|
5
|
+
totalSize(block: Contracts.Crypto.BlockHeaderRaw): number;
|
|
6
6
|
serializeHeader(header: Contracts.Crypto.BlockHeaderRaw): Promise<Buffer>;
|
|
7
|
-
serializeWithTransactions(block: Contracts.Crypto.
|
|
7
|
+
serializeWithTransactions(block: Contracts.Crypto.BlockSerializable): Promise<Buffer>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD,qBACa,UAAW,YAAW,SAAS,CAAC,MAAM,CAAC,eAAe;IAElE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAEpC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD,qBACa,UAAW,YAAW,SAAS,CAAC,MAAM,CAAC,eAAe;IAElE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAEpC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM;IAInD,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzE,yBAAyB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;CAOlG"}
|
|
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Identifiers } from "@mainsail/constants";
|
|
11
11
|
import { inject, injectable } from "@mainsail/container";
|
|
12
|
-
import {
|
|
12
|
+
import { blockHeaderSchema, blockSchema } from "./serializer-schemas.js";
|
|
13
13
|
let Serializer = class Serializer {
|
|
14
14
|
serializer;
|
|
15
15
|
headerSize;
|
|
@@ -19,14 +19,14 @@ let Serializer = class Serializer {
|
|
|
19
19
|
async serializeHeader(header) {
|
|
20
20
|
return this.serializer.serialize(header, {
|
|
21
21
|
length: this.headerSize(),
|
|
22
|
-
schema,
|
|
22
|
+
schema: blockHeaderSchema,
|
|
23
23
|
skip: 0,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
async serializeWithTransactions(block) {
|
|
27
27
|
return this.serializer.serialize(block, {
|
|
28
28
|
length: this.totalSize(block),
|
|
29
|
-
schema:
|
|
29
|
+
schema: blockSchema,
|
|
30
30
|
skip: 0,
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGlE,IAAM,UAAU,GAAhB,MAAM,UAAU;IAEL,UAAU,CAAmC;IAG7C,UAAU,CAAgB;IAEpC,SAAS,CAAC,KAAsC;QACtD,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAuC;QACnE,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE;YACxC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE;YACzB,MAAM,EAAE,iBAAiB;YACzB,IAAI,EAAE,CAAC;SACP,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,yBAAyB,CAAC,KAAyC;QAC/E,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE;YACvC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC7B,MAAM,EAAE,WAAW;YACnB,IAAI,EAAE,CAAC;SACP,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAxBiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;8CACkB;AAG7C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;8CACP;AAL/B,UAAU;IADtB,UAAU,EAAE;GACA,UAAU,CA0BtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainsail/crypto-block",
|
|
3
|
-
"version": "0.0.1-evm.
|
|
3
|
+
"version": "0.0.1-evm.44",
|
|
4
4
|
"description": "Block utilities for the Mainsail blockchain",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"contributors": [],
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"ajv": "8.17.1",
|
|
15
|
-
"@mainsail/constants": "0.0.1-evm.
|
|
16
|
-
"@mainsail/
|
|
17
|
-
"@mainsail/
|
|
18
|
-
"@mainsail/
|
|
19
|
-
"@mainsail/kernel": "0.0.1-evm.
|
|
15
|
+
"@mainsail/constants": "0.0.1-evm.44",
|
|
16
|
+
"@mainsail/crypto-transaction": "0.0.1-evm.44",
|
|
17
|
+
"@mainsail/container": "0.0.1-evm.44",
|
|
18
|
+
"@mainsail/exceptions": "0.0.1-evm.44",
|
|
19
|
+
"@mainsail/kernel": "0.0.1-evm.44",
|
|
20
|
+
"@mainsail/utils": "0.0.1-evm.44"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/lodash.clone": "4.5.9",
|
|
@@ -24,19 +25,20 @@
|
|
|
24
25
|
"lodash.clone": "4.5.0",
|
|
25
26
|
"lodash.clonedeep": "4.5.0",
|
|
26
27
|
"uvu": "0.5.6",
|
|
27
|
-
"@mainsail/
|
|
28
|
-
"@mainsail/crypto-address-
|
|
29
|
-
"@mainsail/crypto-
|
|
30
|
-
"@mainsail/crypto-
|
|
31
|
-
"@mainsail/crypto-
|
|
32
|
-
"@mainsail/crypto-
|
|
33
|
-
"@mainsail/crypto-
|
|
34
|
-
"@mainsail/crypto-
|
|
35
|
-
"@mainsail/
|
|
36
|
-
"@mainsail/crypto-
|
|
37
|
-
"@mainsail/crypto-validation": "0.0.1-evm.
|
|
38
|
-
"@mainsail/
|
|
39
|
-
"@mainsail/validation": "0.0.1-evm.
|
|
28
|
+
"@mainsail/crypto-address-base58": "0.0.1-evm.44",
|
|
29
|
+
"@mainsail/crypto-address-keccak256": "0.0.1-evm.44",
|
|
30
|
+
"@mainsail/crypto-config": "0.0.1-evm.44",
|
|
31
|
+
"@mainsail/crypto-hash-bcrypto": "0.0.1-evm.44",
|
|
32
|
+
"@mainsail/crypto-key-pair-ecdsa": "0.0.1-evm.44",
|
|
33
|
+
"@mainsail/crypto-key-pair-bls12-381": "0.0.1-evm.44",
|
|
34
|
+
"@mainsail/crypto-signature-bls12-381": "0.0.1-evm.44",
|
|
35
|
+
"@mainsail/crypto-wif": "0.0.1-evm.44",
|
|
36
|
+
"@mainsail/contracts": "0.0.1-evm.44",
|
|
37
|
+
"@mainsail/crypto-signature-ecdsa": "0.0.1-evm.44",
|
|
38
|
+
"@mainsail/crypto-validation": "0.0.1-evm.44",
|
|
39
|
+
"@mainsail/test-runner": "0.0.1-evm.44",
|
|
40
|
+
"@mainsail/validation": "0.0.1-evm.44",
|
|
41
|
+
"@mainsail/serializer": "0.0.1-evm.44"
|
|
40
42
|
},
|
|
41
43
|
"engines": {
|
|
42
44
|
"node": ">=20.x"
|
|
@@ -47,6 +49,7 @@
|
|
|
47
49
|
"release": "pnpm publish --access public",
|
|
48
50
|
"test": "pnpm run uvu source .test.ts",
|
|
49
51
|
"test:coverage": "c8 -r=text -r=lcov --all pnpm run test",
|
|
52
|
+
"test:coverage:file": "c8 -r=text -r=lcov --all pnpm run test:file",
|
|
50
53
|
"test:coverage:html": "c8 -r html --all pnpm run test",
|
|
51
54
|
"test:file": "pnpm run uvu source",
|
|
52
55
|
"uvu": "tsx --tsconfig ../../tsconfig.test.json ./node_modules/uvu/bin.js"
|