@xyo-network/xl1-protocol-sdk 1.15.13 → 1.15.15
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/dist/neutral/block/hydrate/hydrateBlock.d.ts +1 -4
- package/dist/neutral/block/hydrate/hydrateBlock.d.ts.map +1 -1
- package/dist/neutral/block/primitives/index.d.ts +0 -1
- package/dist/neutral/block/primitives/index.d.ts.map +1 -1
- package/dist/neutral/block/primitives/model.d.ts +4 -20
- package/dist/neutral/block/primitives/model.d.ts.map +1 -1
- package/dist/neutral/block/primitives/payloads/index.d.ts +0 -3
- package/dist/neutral/block/primitives/payloads/index.d.ts.map +1 -1
- package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts +2 -2
- package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts +1 -1
- package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/eip-712/Payload.d.ts +24 -0
- package/dist/neutral/eip-712/Payload.d.ts.map +1 -0
- package/dist/neutral/eip-712/Types.d.ts +10 -0
- package/dist/neutral/eip-712/Types.d.ts.map +1 -0
- package/dist/neutral/eip-712/index.d.ts +5 -0
- package/dist/neutral/eip-712/index.d.ts.map +1 -0
- package/dist/neutral/eip-712/sign.d.ts +4 -0
- package/dist/neutral/eip-712/sign.d.ts.map +1 -0
- package/dist/neutral/eip-712/spec/fixtures.d.ts +4 -0
- package/dist/neutral/eip-712/spec/fixtures.d.ts.map +1 -0
- package/dist/neutral/eip-712/spec/signAndVerify.spec.d.ts +2 -0
- package/dist/neutral/eip-712/spec/signAndVerify.spec.d.ts.map +1 -0
- package/dist/neutral/eip-712/verify.d.ts +4 -0
- package/dist/neutral/eip-712/verify.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +2 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +421 -380
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/map/MapType.d.ts +3 -1
- package/dist/neutral/map/MapType.d.ts.map +1 -1
- package/dist/neutral/model/index.d.ts +1 -0
- package/dist/neutral/model/index.d.ts.map +1 -1
- package/dist/neutral/model/summary.d.ts +24 -0
- package/dist/neutral/model/summary.d.ts.map +1 -0
- package/dist/neutral/payloads/AddressPairPayload.d.ts.map +1 -0
- package/dist/neutral/{payload → payloads}/index.d.ts +1 -0
- package/dist/neutral/payloads/index.d.ts.map +1 -0
- package/dist/neutral/payloads/netBalancesForPayloads.d.ts.map +1 -0
- package/dist/neutral/payloads/netTransfersForPayloads.d.ts.map +1 -0
- package/dist/neutral/{block/primitives/payloads → payloads/summary}/BalancesStepSummary.d.ts +1 -1
- package/dist/neutral/payloads/summary/BalancesStepSummary.d.ts.map +1 -0
- package/dist/neutral/payloads/summary/StepSummary.d.ts.map +1 -0
- package/dist/neutral/{block/primitives/payloads → payloads/summary}/TransfersSummary.d.ts +1 -1
- package/dist/neutral/payloads/summary/TransfersSummary.d.ts.map +1 -0
- package/dist/neutral/payloads/summary/index.d.ts +4 -0
- package/dist/neutral/payloads/summary/index.d.ts.map +1 -0
- package/dist/neutral/primitives/index.d.ts +2 -0
- package/dist/neutral/primitives/index.d.ts.map +1 -1
- package/dist/neutral/primitives/readPayloadMapFromStore.d.ts +5 -0
- package/dist/neutral/primitives/readPayloadMapFromStore.d.ts.map +1 -0
- package/dist/neutral/{block/primitives → primitives/summary}/balances/balancesStepSummaryFromRange.d.ts +2 -2
- package/dist/neutral/primitives/summary/balances/balancesStepSummaryFromRange.d.ts.map +1 -0
- package/dist/neutral/{block/primitives → primitives/summary}/balances/balancesSummary.d.ts +1 -1
- package/dist/neutral/primitives/summary/balances/balancesSummary.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/balances/index.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/index.d.ts +3 -0
- package/dist/neutral/primitives/summary/index.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/transfers/index.d.ts +3 -0
- package/dist/neutral/primitives/summary/transfers/index.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/transfers/transfersStepSummaryFromRange.d.ts +6 -0
- package/dist/neutral/primitives/summary/transfers/transfersStepSummaryFromRange.d.ts.map +1 -0
- package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts +4 -0
- package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/block/hydrate/hydrateBlock.ts +1 -22
- package/src/block/primitives/index.ts +0 -1
- package/src/block/primitives/model.ts +9 -21
- package/src/block/primitives/payloads/index.ts +0 -3
- package/src/block/primitives/transfers/transfersStepSummaryFromRange.ts +3 -3
- package/src/block/primitives/transfers/transfersSummary.ts +1 -1
- package/src/eip-712/Payload.ts +31 -0
- package/src/eip-712/Types.ts +11 -0
- package/src/eip-712/index.ts +4 -0
- package/src/eip-712/sign.ts +15 -0
- package/src/eip-712/spec/fixtures.ts +27 -0
- package/src/eip-712/spec/signAndVerify.spec.ts +27 -0
- package/src/eip-712/verify.ts +12 -0
- package/src/index.ts +2 -1
- package/src/map/MapType.ts +5 -1
- package/src/model/index.ts +1 -0
- package/src/model/summary.ts +26 -0
- package/src/{payload → payloads}/index.ts +1 -0
- package/src/{block/primitives/payloads → payloads/summary}/BalancesStepSummary.ts +1 -1
- package/src/{block/primitives/payloads → payloads/summary}/TransfersSummary.ts +1 -1
- package/src/payloads/summary/index.ts +3 -0
- package/src/primitives/index.ts +2 -0
- package/src/primitives/readPayloadMapFromStore.ts +24 -0
- package/src/{block/primitives → primitives/summary}/balances/balancesStepSummaryFromRange.ts +7 -6
- package/src/{block/primitives → primitives/summary}/balances/balancesSummary.ts +2 -2
- package/src/primitives/summary/index.ts +2 -0
- package/src/primitives/summary/transfers/index.ts +2 -0
- package/src/primitives/summary/transfers/transfersStepSummaryFromRange.ts +96 -0
- package/src/primitives/summary/transfers/transfersSummary.ts +36 -0
- package/dist/neutral/block/primitives/balances/balancesStepSummaryFromRange.d.ts.map +0 -1
- package/dist/neutral/block/primitives/balances/balancesSummary.d.ts.map +0 -1
- package/dist/neutral/block/primitives/balances/index.d.ts.map +0 -1
- package/dist/neutral/block/primitives/payloads/BalancesStepSummary.d.ts.map +0 -1
- package/dist/neutral/block/primitives/payloads/StepSummary.d.ts.map +0 -1
- package/dist/neutral/block/primitives/payloads/TransfersSummary.d.ts.map +0 -1
- package/dist/neutral/payload/AddressPairPayload.d.ts.map +0 -1
- package/dist/neutral/payload/index.d.ts.map +0 -1
- package/dist/neutral/payload/netBalancesForPayloads.d.ts.map +0 -1
- package/dist/neutral/payload/netTransfersForPayloads.d.ts.map +0 -1
- /package/dist/neutral/{payload → payloads}/AddressPairPayload.d.ts +0 -0
- /package/dist/neutral/{payload → payloads}/netBalancesForPayloads.d.ts +0 -0
- /package/dist/neutral/{payload → payloads}/netTransfersForPayloads.d.ts +0 -0
- /package/dist/neutral/{block/primitives/payloads → payloads/summary}/StepSummary.d.ts +0 -0
- /package/dist/neutral/{block/primitives → primitives/summary}/balances/index.d.ts +0 -0
- /package/src/{payload → payloads}/AddressPairPayload.ts +0 -0
- /package/src/{payload → payloads}/netBalancesForPayloads.ts +0 -0
- /package/src/{payload → payloads}/netTransfersForPayloads.ts +0 -0
- /package/src/{block/primitives/payloads → payloads/summary}/StepSummary.ts +0 -0
- /package/src/{block/primitives → primitives/summary}/balances/index.ts +0 -0
package/dist/neutral/index.mjs
CHANGED
|
@@ -28,110 +28,123 @@ var flattenHydratedBlock = /* @__PURE__ */ __name((hydratedBlock) => {
|
|
|
28
28
|
var flattenHydratedBlocks = /* @__PURE__ */ __name((hydratedBlocks) => hydratedBlocks.flatMap((blk) => flattenHydratedBlock(blk)), "flattenHydratedBlocks");
|
|
29
29
|
|
|
30
30
|
// src/block/hydrate/hydrateBlock.ts
|
|
31
|
-
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
32
|
-
import { isDefined as isDefined3 } from "@xylabs/typeof";
|
|
33
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta2 } from "@xyo-network/xl1-protocol";
|
|
34
|
-
|
|
35
|
-
// src/block/primitives/balances/balancesStepSummaryFromRange.ts
|
|
36
31
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
import { asBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta2 } from "@xyo-network/xl1-protocol";
|
|
33
|
+
var hydrateBlock = /* @__PURE__ */ __name(async ({ chainMap }, hash, maxDepth = 1, minDepth = maxDepth) => {
|
|
34
|
+
assertEx2(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
35
|
+
assertEx2(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
|
|
36
|
+
assertEx2(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
|
|
37
|
+
const bw = assertEx2(asBlockBoundWitnessWithStorageMeta(assertEx2(await chainMap.get(hash), () => `block ${hash} not found`)), () => `hash ${hash} is not a BlockBoundWitness`);
|
|
38
|
+
if (maxDepth === 0) return [
|
|
39
|
+
bw,
|
|
40
|
+
[]
|
|
41
|
+
];
|
|
42
|
+
const blkPayloads = await chainMap.getMany(bw.payload_hashes);
|
|
43
|
+
if (minDepth === 1) assertEx2(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
|
|
44
|
+
if (maxDepth === 1) return [
|
|
45
|
+
bw,
|
|
46
|
+
blkPayloads
|
|
47
|
+
];
|
|
48
|
+
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta2);
|
|
49
|
+
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
50
|
+
const transactionsPayloads = await chainMap.getMany(transactionsPayloadHashes);
|
|
51
|
+
assertEx2(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
52
|
+
const allPayloadsHashes = new Set([
|
|
53
|
+
...blkPayloads,
|
|
54
|
+
...transactionsPayloads
|
|
55
|
+
].flatMap((p) => p._hash));
|
|
56
|
+
const allPayloads = await chainMap.getMany([
|
|
57
|
+
...allPayloadsHashes
|
|
58
|
+
]);
|
|
59
|
+
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
60
|
+
if (maxDepth === 2) assertEx2(allHashesPresent([
|
|
61
|
+
...allPayloadsHashes
|
|
62
|
+
], allPayloadsFiltered), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
63
|
+
return [
|
|
64
|
+
bw,
|
|
65
|
+
allPayloadsFiltered
|
|
66
|
+
];
|
|
67
|
+
}, "hydrateBlock");
|
|
40
68
|
|
|
41
|
-
// src/
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var asOptionalAddressPairPayload = AsObjectFactory.createOptional(isAddressPairPayload);
|
|
69
|
+
// src/block/hydrate/transactionsFromHydratedBlock.ts
|
|
70
|
+
import { filterAs } from "@xylabs/array";
|
|
71
|
+
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
72
|
+
var transactionsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
73
|
+
return filterAs(block[1], asTransactionBoundWitnessWithStorageMeta);
|
|
74
|
+
}, "transactionsFromHydratedBlock");
|
|
48
75
|
|
|
49
|
-
// src/
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
// src/block/hydrate/tryHydrateBlock.ts
|
|
77
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
78
|
+
import { isBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta3 } from "@xyo-network/xl1-protocol";
|
|
79
|
+
var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1) => {
|
|
80
|
+
assertEx3(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
81
|
+
const bw = (await archivist.get([
|
|
82
|
+
hash
|
|
83
|
+
])).find(isBlockBoundWitnessWithStorageMeta);
|
|
84
|
+
if (!bw) return void 0;
|
|
85
|
+
if (maxDepth === 0) return [
|
|
86
|
+
bw,
|
|
87
|
+
[]
|
|
88
|
+
];
|
|
89
|
+
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
90
|
+
if (maxDepth === 1) return [
|
|
91
|
+
bw,
|
|
92
|
+
blkPayloads
|
|
93
|
+
];
|
|
94
|
+
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta3);
|
|
95
|
+
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
96
|
+
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
97
|
+
const allPayloadsHashes = new Set([
|
|
98
|
+
...blkPayloads,
|
|
99
|
+
...transactionsPayloads
|
|
100
|
+
].flatMap((p) => p._hash));
|
|
101
|
+
const allPayloads = await archivist.get([
|
|
102
|
+
...allPayloadsHashes
|
|
103
|
+
]);
|
|
104
|
+
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
105
|
+
return [
|
|
106
|
+
bw,
|
|
107
|
+
allPayloadsFiltered
|
|
108
|
+
];
|
|
109
|
+
}, "tryHydrateBlock");
|
|
68
110
|
|
|
69
|
-
// src/
|
|
70
|
-
import {
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const { from } = payload;
|
|
79
|
-
transfers[from] = transfers[from] ?? {};
|
|
80
|
-
for (let [to, amount] of Object.entries(payload.transfers)) {
|
|
81
|
-
transfers[to] = transfers[to] ?? {};
|
|
82
|
-
transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt2(amount);
|
|
83
|
-
transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt2(amount);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return transfers;
|
|
111
|
+
// src/block/primitives/blockFromBlockNumber.ts
|
|
112
|
+
import { asHash } from "@xylabs/hex";
|
|
113
|
+
import { toSafeJsonString } from "@xylabs/object";
|
|
114
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, StepSizes } from "@xyo-network/xl1-protocol";
|
|
115
|
+
async function blockFromBlockNumber(context, blockNumber) {
|
|
116
|
+
const head = await context.head();
|
|
117
|
+
const result = await context.store.chainMap.get(head);
|
|
118
|
+
let currentBlock = asBlockBoundWitnessWithStorageMeta2(result, () => `Head block not found for hash: ${head}`, {
|
|
119
|
+
required: true
|
|
88
120
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// src/SignedBigInt.ts
|
|
93
|
-
import { hexToBigInt as hexToBigInt3, toHex } from "@xylabs/hex";
|
|
94
|
-
import { isObject } from "@xylabs/object";
|
|
95
|
-
var isNegativeBigInt = /* @__PURE__ */ __name((value) => {
|
|
96
|
-
return isObject(value) && "negative" in value && typeof value.negative === "string";
|
|
97
|
-
}, "isNegativeBigInt");
|
|
98
|
-
var isPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
99
|
-
return isObject(value) && "positive" in value && typeof value.positive === "string";
|
|
100
|
-
}, "isPositiveBigInt");
|
|
101
|
-
var parseSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
102
|
-
if (isNegativeBigInt(value)) {
|
|
103
|
-
return -hexToBigInt3(value.negative);
|
|
104
|
-
} else if (isPositiveBigInt(value)) {
|
|
105
|
-
return hexToBigInt3(value.positive);
|
|
106
|
-
} else {
|
|
107
|
-
throw new Error("Invalid balance type");
|
|
108
|
-
}
|
|
109
|
-
}, "parseSignedBigInt");
|
|
110
|
-
var toSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
111
|
-
return value < 0n ? {
|
|
112
|
-
negative: toHex(-value)
|
|
113
|
-
} : {
|
|
114
|
-
positive: toHex(value)
|
|
115
|
-
};
|
|
116
|
-
}, "toSignedBigInt");
|
|
117
|
-
var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
118
|
-
if (isNegativeBigInt(value)) {
|
|
119
|
-
return {
|
|
120
|
-
positive: toHex(0n)
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
if (isPositiveBigInt(value)) {
|
|
124
|
-
return {
|
|
125
|
-
positive: value.positive
|
|
126
|
-
};
|
|
121
|
+
if (currentBlock.block < blockNumber) {
|
|
122
|
+
throw new Error(`Error: Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
|
|
127
123
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
while (currentBlock.block > blockNumber) {
|
|
125
|
+
let jumpHash = currentBlock.previous;
|
|
126
|
+
let jumpBlockNumber = currentBlock.block - 1;
|
|
127
|
+
for (const [step, stepSize2] of StepSizes.entries()) {
|
|
128
|
+
const possibleJumpBlockNumber = currentBlock.block - stepSize2;
|
|
129
|
+
if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
|
|
130
|
+
jumpBlockNumber = possibleJumpBlockNumber;
|
|
131
|
+
jumpHash = asHash(currentBlock.step_hashes.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const newBlock = await context.store.chainMap.get(asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`));
|
|
135
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta2(newBlock, () => `Block not found for hash: ${jumpHash}`, {
|
|
136
|
+
required: true
|
|
137
|
+
});
|
|
138
|
+
if (currentBlock.block === blockNumber) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
if (currentBlock.block < blockNumber) {
|
|
142
|
+
throw new Error(`Block number ${blockNumber} is not a valid step block number for block ${context.head}.`);
|
|
143
|
+
}
|
|
132
144
|
}
|
|
133
|
-
|
|
134
|
-
}
|
|
145
|
+
return currentBlock;
|
|
146
|
+
}
|
|
147
|
+
__name(blockFromBlockNumber, "blockFromBlockNumber");
|
|
135
148
|
|
|
136
149
|
// src/block/primitives/frames/calculateFramesFromRange.ts
|
|
137
150
|
import { asXL1BlockNumber, stepSize } from "@xyo-network/xl1-protocol";
|
|
@@ -168,8 +181,8 @@ function calculateFramesFromRange(range, step) {
|
|
|
168
181
|
__name(calculateFramesFromRange, "calculateFramesFromRange");
|
|
169
182
|
|
|
170
183
|
// src/block/primitives/frames/deepCalculateFramesFromRange.ts
|
|
171
|
-
import { StepSizes } from "@xyo-network/xl1-protocol";
|
|
172
|
-
function deepCalculateFramesFromRange(range, startingStep =
|
|
184
|
+
import { StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
185
|
+
function deepCalculateFramesFromRange(range, startingStep = StepSizes2.length - 1) {
|
|
173
186
|
const fitted = [];
|
|
174
187
|
let remaining = [
|
|
175
188
|
range
|
|
@@ -195,51 +208,84 @@ function deepCalculateFramesFromRange(range, startingStep = StepSizes.length - 1
|
|
|
195
208
|
}
|
|
196
209
|
__name(deepCalculateFramesFromRange, "deepCalculateFramesFromRange");
|
|
197
210
|
|
|
198
|
-
// src/block/primitives/blockFromBlockNumber.ts
|
|
199
|
-
import { asHash } from "@xylabs/hex";
|
|
200
|
-
import { toSafeJsonString } from "@xylabs/object";
|
|
201
|
-
import { asBlockBoundWitnessWithStorageMeta, StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
202
|
-
async function blockFromBlockNumber(context, blockNumber) {
|
|
203
|
-
const head = await context.head();
|
|
204
|
-
const result = await context.store.chainMap.get(head);
|
|
205
|
-
let currentBlock = asBlockBoundWitnessWithStorageMeta(result, () => `Head block not found for hash: ${head}`, {
|
|
206
|
-
required: true
|
|
207
|
-
});
|
|
208
|
-
if (currentBlock.block < blockNumber) {
|
|
209
|
-
throw new Error(`Error: Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
|
|
210
|
-
}
|
|
211
|
-
while (currentBlock.block > blockNumber) {
|
|
212
|
-
let jumpHash = currentBlock.previous;
|
|
213
|
-
let jumpBlockNumber = currentBlock.block - 1;
|
|
214
|
-
for (const [step, stepSize2] of StepSizes2.entries()) {
|
|
215
|
-
const possibleJumpBlockNumber = currentBlock.block - stepSize2;
|
|
216
|
-
if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
|
|
217
|
-
jumpBlockNumber = possibleJumpBlockNumber;
|
|
218
|
-
jumpHash = asHash(currentBlock.step_hashes.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
const newBlock = await context.store.chainMap.get(asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`));
|
|
222
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(newBlock, () => `Block not found for hash: ${jumpHash}`, {
|
|
223
|
-
required: true
|
|
224
|
-
});
|
|
225
|
-
if (currentBlock.block === blockNumber) {
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
if (currentBlock.block < blockNumber) {
|
|
229
|
-
throw new Error(`Block number ${blockNumber} is not a valid step block number for block ${context.head}.`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return currentBlock;
|
|
233
|
-
}
|
|
234
|
-
__name(blockFromBlockNumber, "blockFromBlockNumber");
|
|
235
|
-
|
|
236
211
|
// src/block/primitives/hashFromBlockNumber.ts
|
|
237
212
|
async function hashFromBlockNumber(context, blockNumber) {
|
|
238
213
|
return (await blockFromBlockNumber(context, blockNumber))._hash;
|
|
239
214
|
}
|
|
240
215
|
__name(hashFromBlockNumber, "hashFromBlockNumber");
|
|
241
216
|
|
|
242
|
-
// src/block/primitives/
|
|
217
|
+
// src/block/primitives/model.ts
|
|
218
|
+
function isReadArchivist(value) {
|
|
219
|
+
return value.get !== void 0 && value.next !== void 0;
|
|
220
|
+
}
|
|
221
|
+
__name(isReadArchivist, "isReadArchivist");
|
|
222
|
+
function isWriteArchivist(value) {
|
|
223
|
+
return value.insert !== void 0;
|
|
224
|
+
}
|
|
225
|
+
__name(isWriteArchivist, "isWriteArchivist");
|
|
226
|
+
function isReadWriteArchivist(value) {
|
|
227
|
+
return isReadArchivist(value) && isWriteArchivist(value);
|
|
228
|
+
}
|
|
229
|
+
__name(isReadWriteArchivist, "isReadWriteArchivist");
|
|
230
|
+
|
|
231
|
+
// src/block/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
232
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
233
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
234
|
+
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
235
|
+
import { StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol";
|
|
236
|
+
|
|
237
|
+
// src/payloads/AddressPairPayload.ts
|
|
238
|
+
import { AsObjectFactory } from "@xylabs/object";
|
|
239
|
+
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
240
|
+
var AddressPairSchema = "network.xyo.address.pair";
|
|
241
|
+
var isAddressPairPayload = isPayloadOfSchemaType(AddressPairSchema);
|
|
242
|
+
var asAddressPairPayload = AsObjectFactory.create(isAddressPairPayload);
|
|
243
|
+
var asOptionalAddressPairPayload = AsObjectFactory.createOptional(isAddressPairPayload);
|
|
244
|
+
|
|
245
|
+
// src/payloads/netBalancesForPayloads.ts
|
|
246
|
+
import { hexToBigInt, toAddress } from "@xylabs/hex";
|
|
247
|
+
import { span } from "@xylabs/telemetry";
|
|
248
|
+
import { isTransfer } from "@xyo-network/xl1-protocol";
|
|
249
|
+
var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
250
|
+
return span("netBalancesForPayloads", () => {
|
|
251
|
+
const balances = {};
|
|
252
|
+
for (const payload of payloads) {
|
|
253
|
+
if (isTransfer(payload)) {
|
|
254
|
+
const { from } = payload;
|
|
255
|
+
for (let [address, amount] of Object.entries(payload.transfers)) {
|
|
256
|
+
balances[toAddress(address)] = (balances[toAddress(address)] ?? 0n) + hexToBigInt(amount);
|
|
257
|
+
balances[toAddress(from)] = (balances[toAddress(from)] ?? 0n) - hexToBigInt(amount);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return balances;
|
|
262
|
+
});
|
|
263
|
+
}, "netBalancesForPayloads");
|
|
264
|
+
|
|
265
|
+
// src/payloads/netTransfersForPayloads.ts
|
|
266
|
+
import { hexToBigInt as hexToBigInt2 } from "@xylabs/hex";
|
|
267
|
+
import { span as span2 } from "@xylabs/telemetry";
|
|
268
|
+
import { isTransfer as isTransfer2 } from "@xyo-network/xl1-protocol";
|
|
269
|
+
function netTransfersForPayloads(payloads) {
|
|
270
|
+
return span2("netTransfersForPayloads", () => {
|
|
271
|
+
const transfers = {};
|
|
272
|
+
for (const payload of payloads) {
|
|
273
|
+
if (isTransfer2(payload)) {
|
|
274
|
+
const { from } = payload;
|
|
275
|
+
transfers[from] = transfers[from] ?? {};
|
|
276
|
+
for (let [to, amount] of Object.entries(payload.transfers)) {
|
|
277
|
+
transfers[to] = transfers[to] ?? {};
|
|
278
|
+
transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt2(amount);
|
|
279
|
+
transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt2(amount);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return transfers;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
__name(netTransfersForPayloads, "netTransfersForPayloads");
|
|
287
|
+
|
|
288
|
+
// src/payloads/summary/BalancesStepSummary.ts
|
|
243
289
|
import { AsObjectFactory as AsObjectFactory2 } from "@xylabs/object";
|
|
244
290
|
import { isPayloadOfSchemaType as isPayloadOfSchemaType2, isStorageMeta } from "@xyo-network/payload-model";
|
|
245
291
|
var BalancesStepSummarySchema = "network.xyo.step.summary.balances";
|
|
@@ -250,10 +296,10 @@ var isBalancesStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
|
|
|
250
296
|
}, "isBalancesStepSummaryWithStorageMeta");
|
|
251
297
|
var asBalancesStepSummaryWithStorageMeta = AsObjectFactory2.create(isBalancesStepSummaryWithStorageMeta);
|
|
252
298
|
|
|
253
|
-
// src/
|
|
299
|
+
// src/payloads/summary/StepSummary.ts
|
|
254
300
|
var StepSummarySchema = "network.xyo.step.summary";
|
|
255
301
|
|
|
256
|
-
// src/
|
|
302
|
+
// src/payloads/summary/TransfersSummary.ts
|
|
257
303
|
import { AsObjectFactory as AsObjectFactory3 } from "@xylabs/object";
|
|
258
304
|
import { isPayloadOfSchemaType as isPayloadOfSchemaType3, isStorageMeta as isStorageMeta2 } from "@xyo-network/payload-model";
|
|
259
305
|
var TransfersStepSummarySchema = "network.xyo.step.summary.transfer";
|
|
@@ -264,105 +310,51 @@ var isTransfersStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
|
|
|
264
310
|
}, "isTransfersStepSummaryWithStorageMeta");
|
|
265
311
|
var asTransfersStepSummaryWithStorageMeta = AsObjectFactory3.create(isTransfersStepSummaryWithStorageMeta);
|
|
266
312
|
|
|
267
|
-
// src/
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
schema: BalancesStepSummarySchema,
|
|
282
|
-
hash: head,
|
|
283
|
-
stepSize: -1,
|
|
284
|
-
balances
|
|
285
|
-
};
|
|
313
|
+
// src/SignedBigInt.ts
|
|
314
|
+
import { hexToBigInt as hexToBigInt3, toHex } from "@xylabs/hex";
|
|
315
|
+
import { isObject } from "@xylabs/object";
|
|
316
|
+
var isNegativeBigInt = /* @__PURE__ */ __name((value) => {
|
|
317
|
+
return isObject(value) && "negative" in value && typeof value.negative === "string";
|
|
318
|
+
}, "isNegativeBigInt");
|
|
319
|
+
var isPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
320
|
+
return isObject(value) && "positive" in value && typeof value.positive === "string";
|
|
321
|
+
}, "isPositiveBigInt");
|
|
322
|
+
var parseSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
323
|
+
if (isNegativeBigInt(value)) {
|
|
324
|
+
return -hexToBigInt3(value.negative);
|
|
325
|
+
} else if (isPositiveBigInt(value)) {
|
|
326
|
+
return hexToBigInt3(value.positive);
|
|
286
327
|
} else {
|
|
287
|
-
|
|
288
|
-
assertEx2(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes3.join(", ")}`);
|
|
289
|
-
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
290
|
-
if (isAnyPayload(summaryResult)) {
|
|
291
|
-
result = summaryResult;
|
|
292
|
-
} else {
|
|
293
|
-
await context.stepSemaphores[step].acquire();
|
|
294
|
-
try {
|
|
295
|
-
const subRanges = deepCalculateFramesFromRange(range, step - 1);
|
|
296
|
-
const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(context, subRange));
|
|
297
|
-
const subResults = await Promise.all(promises);
|
|
298
|
-
const bigIntBalances = {};
|
|
299
|
-
for (const subResult of subResults) {
|
|
300
|
-
for (const [address, balance] of Object.entries(subResult.balances)) {
|
|
301
|
-
bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
const balances = {};
|
|
305
|
-
for (const [address, balance] of Object.entries(bigIntBalances)) {
|
|
306
|
-
balances[address] = toSignedBigInt(balance);
|
|
307
|
-
}
|
|
308
|
-
result = {
|
|
309
|
-
schema: BalancesStepSummarySchema,
|
|
310
|
-
hash: frameHeadHash,
|
|
311
|
-
stepSize: frameSize,
|
|
312
|
-
balances
|
|
313
|
-
};
|
|
314
|
-
await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
|
|
315
|
-
} finally {
|
|
316
|
-
context.stepSemaphores[step].release();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
328
|
+
throw new Error("Invalid balance type");
|
|
319
329
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const validAddress = asAddress(address, () => `Invalid address: ${address}`);
|
|
347
|
-
balances[validAddress] = (balances[validAddress] ?? 0n) + parseSignedBigInt(balance);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return balances;
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
__name(balancesSummary, "balancesSummary");
|
|
354
|
-
|
|
355
|
-
// src/block/primitives/model.ts
|
|
356
|
-
function isReadArchivist(obj) {
|
|
357
|
-
return obj.get !== void 0 && obj.next !== void 0;
|
|
358
|
-
}
|
|
359
|
-
__name(isReadArchivist, "isReadArchivist");
|
|
330
|
+
}, "parseSignedBigInt");
|
|
331
|
+
var toSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
332
|
+
return value < 0n ? {
|
|
333
|
+
negative: toHex(-value)
|
|
334
|
+
} : {
|
|
335
|
+
positive: toHex(value)
|
|
336
|
+
};
|
|
337
|
+
}, "toSignedBigInt");
|
|
338
|
+
var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
339
|
+
if (isNegativeBigInt(value)) {
|
|
340
|
+
return {
|
|
341
|
+
positive: toHex(0n)
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
if (isPositiveBigInt(value)) {
|
|
345
|
+
return {
|
|
346
|
+
positive: value.positive
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
if (typeof value === "bigint") {
|
|
350
|
+
return {
|
|
351
|
+
positive: toHex(value)
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
throw new Error("Invalid value for positive big int");
|
|
355
|
+
}, "toPositiveBigInt");
|
|
360
356
|
|
|
361
357
|
// src/block/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
362
|
-
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
363
|
-
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
364
|
-
import { isAnyPayload as isAnyPayload2 } from "@xyo-network/payload-model";
|
|
365
|
-
import { StepSizes as StepSizes4 } from "@xyo-network/xl1-protocol";
|
|
366
358
|
async function transfersStepSummaryFromRange(context, range) {
|
|
367
359
|
const frameHeadHash = await hashFromBlockNumber(context, range[1]);
|
|
368
360
|
const frameSize = range[1] - range[0] + 1;
|
|
@@ -385,10 +377,10 @@ async function transfersStepSummaryFromRange(context, range) {
|
|
|
385
377
|
transfers
|
|
386
378
|
};
|
|
387
379
|
} else {
|
|
388
|
-
const step =
|
|
389
|
-
|
|
380
|
+
const step = StepSizes3.indexOf(frameSize);
|
|
381
|
+
assertEx4(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes3.join(", ")}`);
|
|
390
382
|
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
391
|
-
if (
|
|
383
|
+
if (isAnyPayload(summaryResult)) {
|
|
392
384
|
result = summaryResult;
|
|
393
385
|
} else {
|
|
394
386
|
await context.stepSemaphores[step].acquire();
|
|
@@ -424,36 +416,36 @@ async function transfersStepSummaryFromRange(context, range) {
|
|
|
424
416
|
}
|
|
425
417
|
}
|
|
426
418
|
}
|
|
427
|
-
const finalResult = await
|
|
419
|
+
const finalResult = await PayloadBuilder.addStorageMeta(result);
|
|
428
420
|
return finalResult;
|
|
429
421
|
}
|
|
430
422
|
__name(transfersStepSummaryFromRange, "transfersStepSummaryFromRange");
|
|
431
423
|
|
|
432
424
|
// src/block/primitives/transfers/transfersSummary.ts
|
|
433
|
-
import { asAddress
|
|
434
|
-
import { spanRootAsync
|
|
435
|
-
import { isDefined
|
|
436
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockNumber as
|
|
425
|
+
import { asAddress } from "@xylabs/hex";
|
|
426
|
+
import { spanRootAsync } from "@xylabs/telemetry";
|
|
427
|
+
import { isDefined } from "@xylabs/typeof";
|
|
428
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockNumber as asXL1BlockNumber2 } from "@xyo-network/xl1-protocol";
|
|
437
429
|
async function transfersSummary(context) {
|
|
438
|
-
return await
|
|
430
|
+
return await spanRootAsync("transferSummary", async () => {
|
|
439
431
|
const head = await context.head();
|
|
440
432
|
const headResult = await context.store.chainMap.get(head);
|
|
441
433
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${context.head}`, {
|
|
442
434
|
required: true
|
|
443
435
|
});
|
|
444
|
-
const rangeStart =
|
|
436
|
+
const rangeStart = asXL1BlockNumber2(isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0);
|
|
445
437
|
const ranges = deepCalculateFramesFromRange([
|
|
446
438
|
rangeStart,
|
|
447
|
-
|
|
439
|
+
asXL1BlockNumber2(headBoundWitness.block)
|
|
448
440
|
]);
|
|
449
441
|
const summaries = await Promise.all(ranges.map((range) => transfersStepSummaryFromRange(context, range)));
|
|
450
442
|
const transfers = {};
|
|
451
443
|
for (let summary of summaries) {
|
|
452
444
|
for (const [from, toMap] of Object.entries(summary.transfers)) {
|
|
453
|
-
const validFrom =
|
|
445
|
+
const validFrom = asAddress(from, () => `Invalid address: ${from}`);
|
|
454
446
|
transfers[validFrom] = transfers[validFrom] ?? {};
|
|
455
447
|
for (const [to, transfer] of Object.entries(toMap)) {
|
|
456
|
-
const validTo =
|
|
448
|
+
const validTo = asAddress(to, () => `Invalid address: ${to}`);
|
|
457
449
|
transfers[validFrom][validTo] = (transfers[validFrom][validTo] ?? 0n) + parseSignedBigInt(transfer);
|
|
458
450
|
}
|
|
459
451
|
}
|
|
@@ -463,106 +455,6 @@ async function transfersSummary(context) {
|
|
|
463
455
|
}
|
|
464
456
|
__name(transfersSummary, "transfersSummary");
|
|
465
457
|
|
|
466
|
-
// src/block/hydrate/hydrateBlock.ts
|
|
467
|
-
function readPayloadMapFromStore(store) {
|
|
468
|
-
if (isReadArchivist(store)) {
|
|
469
|
-
return {
|
|
470
|
-
get: /* @__PURE__ */ __name(async (hash) => {
|
|
471
|
-
return (await store.get([
|
|
472
|
-
hash
|
|
473
|
-
]))[0];
|
|
474
|
-
}, "get"),
|
|
475
|
-
getMany: /* @__PURE__ */ __name(async (hashes) => {
|
|
476
|
-
return await store.get(hashes);
|
|
477
|
-
}, "getMany"),
|
|
478
|
-
has: /* @__PURE__ */ __name(async (hash) => {
|
|
479
|
-
return isDefined3((await store.get([
|
|
480
|
-
hash
|
|
481
|
-
]))[0]);
|
|
482
|
-
}, "has")
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
return store;
|
|
486
|
-
}
|
|
487
|
-
__name(readPayloadMapFromStore, "readPayloadMapFromStore");
|
|
488
|
-
var hydrateBlock = /* @__PURE__ */ __name(async ({ chainMap }, hash, maxDepth = 1, minDepth = maxDepth) => {
|
|
489
|
-
assertEx4(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
490
|
-
assertEx4(minDepth >= 0, () => "minDepth must be greater than or equal to 0");
|
|
491
|
-
assertEx4(maxDepth >= minDepth, () => "maxDepth must be greater than or equal to minDepth");
|
|
492
|
-
const bw = assertEx4(asBlockBoundWitnessWithStorageMeta4(assertEx4(await chainMap.get(hash), () => `block ${hash} not found`)), () => `hash ${hash} is not a BlockBoundWitness`);
|
|
493
|
-
if (maxDepth === 0) return [
|
|
494
|
-
bw,
|
|
495
|
-
[]
|
|
496
|
-
];
|
|
497
|
-
const blkPayloads = await chainMap.getMany(bw.payload_hashes);
|
|
498
|
-
if (minDepth === 1) assertEx4(allHashesPresent(bw.payload_hashes, blkPayloads), () => `Unable to find all payloads for block ${hash}`);
|
|
499
|
-
if (maxDepth === 1) return [
|
|
500
|
-
bw,
|
|
501
|
-
blkPayloads
|
|
502
|
-
];
|
|
503
|
-
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta2);
|
|
504
|
-
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
505
|
-
const transactionsPayloads = await chainMap.getMany(transactionsPayloadHashes);
|
|
506
|
-
assertEx4(allHashesPresent(transactionsPayloadHashes, transactionsPayloads), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
507
|
-
const allPayloadsHashes = new Set([
|
|
508
|
-
...blkPayloads,
|
|
509
|
-
...transactionsPayloads
|
|
510
|
-
].flatMap((p) => p._hash));
|
|
511
|
-
const allPayloads = await chainMap.getMany([
|
|
512
|
-
...allPayloadsHashes
|
|
513
|
-
]);
|
|
514
|
-
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
515
|
-
if (maxDepth === 2) assertEx4(allHashesPresent([
|
|
516
|
-
...allPayloadsHashes
|
|
517
|
-
], allPayloadsFiltered), () => `Unable to find all payloads for transactions in block ${hash}`);
|
|
518
|
-
return [
|
|
519
|
-
bw,
|
|
520
|
-
allPayloadsFiltered
|
|
521
|
-
];
|
|
522
|
-
}, "hydrateBlock");
|
|
523
|
-
|
|
524
|
-
// src/block/hydrate/transactionsFromHydratedBlock.ts
|
|
525
|
-
import { filterAs } from "@xylabs/array";
|
|
526
|
-
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
527
|
-
var transactionsFromHydratedBlock = /* @__PURE__ */ __name((block) => {
|
|
528
|
-
return filterAs(block[1], asTransactionBoundWitnessWithStorageMeta);
|
|
529
|
-
}, "transactionsFromHydratedBlock");
|
|
530
|
-
|
|
531
|
-
// src/block/hydrate/tryHydrateBlock.ts
|
|
532
|
-
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
533
|
-
import { isBlockBoundWitnessWithStorageMeta, isTransactionBoundWitnessWithStorageMeta as isTransactionBoundWitnessWithStorageMeta3 } from "@xyo-network/xl1-protocol";
|
|
534
|
-
var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth = 1) => {
|
|
535
|
-
assertEx5(maxDepth >= 0, () => "maxDepth must be greater than or equal to 0");
|
|
536
|
-
const bw = (await archivist.get([
|
|
537
|
-
hash
|
|
538
|
-
])).find(isBlockBoundWitnessWithStorageMeta);
|
|
539
|
-
if (!bw) return void 0;
|
|
540
|
-
if (maxDepth === 0) return [
|
|
541
|
-
bw,
|
|
542
|
-
[]
|
|
543
|
-
];
|
|
544
|
-
const blkPayloads = await archivist.get(bw.payload_hashes);
|
|
545
|
-
if (maxDepth === 1) return [
|
|
546
|
-
bw,
|
|
547
|
-
blkPayloads
|
|
548
|
-
];
|
|
549
|
-
const transactions = blkPayloads.filter(isTransactionBoundWitnessWithStorageMeta3);
|
|
550
|
-
const transactionsPayloadHashes = transactions.flatMap((tx) => tx.payload_hashes);
|
|
551
|
-
const transactionsPayloads = await archivist.get(transactionsPayloadHashes);
|
|
552
|
-
const allPayloadsHashes = new Set([
|
|
553
|
-
...blkPayloads,
|
|
554
|
-
...transactionsPayloads
|
|
555
|
-
].flatMap((p) => p._hash));
|
|
556
|
-
const allPayloads = await archivist.get([
|
|
557
|
-
...allPayloadsHashes
|
|
558
|
-
]);
|
|
559
|
-
const allPayloadsFiltered = allPayloads.filter((p) => allPayloadsHashes.has(p._hash));
|
|
560
|
-
return [
|
|
561
|
-
bw,
|
|
562
|
-
allPayloadsFiltered
|
|
563
|
-
];
|
|
564
|
-
}, "tryHydrateBlock");
|
|
565
|
-
|
|
566
458
|
// src/config/Config.ts
|
|
567
459
|
import * as z14 from "zod";
|
|
568
460
|
|
|
@@ -717,13 +609,13 @@ var LogConfigZod = z7.object({
|
|
|
717
609
|
});
|
|
718
610
|
|
|
719
611
|
// src/config/Producer.ts
|
|
720
|
-
import { AddressZod, asAddress as
|
|
612
|
+
import { AddressZod, asAddress as asAddress2 } from "@xylabs/hex";
|
|
721
613
|
import { globalRegistry as globalRegistry7 } from "zod";
|
|
722
614
|
import * as z8 from "zod";
|
|
723
615
|
var ProducerConfigZod = z8.object({
|
|
724
616
|
allowlist: z8.preprocess((val) => {
|
|
725
617
|
if (typeof val === "string") {
|
|
726
|
-
return val.split(",").map((s) =>
|
|
618
|
+
return val.split(",").map((s) => asAddress2(s.trim()));
|
|
727
619
|
}
|
|
728
620
|
return val;
|
|
729
621
|
}, z8.array(AddressZod).optional().register(globalRegistry7, {
|
|
@@ -803,12 +695,12 @@ var RewardRedemptionApiConfigZod = z9.object({
|
|
|
803
695
|
});
|
|
804
696
|
|
|
805
697
|
// src/config/storage/driver/Mongo.ts
|
|
806
|
-
import { isDefined as
|
|
698
|
+
import { isDefined as isDefined2, isUndefined } from "@xylabs/typeof";
|
|
807
699
|
import { globalRegistry as globalRegistry9 } from "zod";
|
|
808
700
|
import * as z10 from "zod";
|
|
809
701
|
var hasMongoConfig = /* @__PURE__ */ __name((config) => {
|
|
810
702
|
if (isUndefined(config)) return false;
|
|
811
|
-
return
|
|
703
|
+
return isDefined2(config.connectionString) && isDefined2(config.database) && isDefined2(config.domain) && isDefined2(config.password) && isDefined2(config.username);
|
|
812
704
|
}, "hasMongoConfig");
|
|
813
705
|
var MongoConfigZod = z10.object({
|
|
814
706
|
// TODO: Create from other arguments
|
|
@@ -868,13 +760,13 @@ var TelemetryConfigZod = z12.object({
|
|
|
868
760
|
}).describe("Telemetry configuration options");
|
|
869
761
|
|
|
870
762
|
// src/config/Validation.ts
|
|
871
|
-
import { AddressZod as AddressZod2, asAddress as
|
|
763
|
+
import { AddressZod as AddressZod2, asAddress as asAddress3 } from "@xylabs/hex";
|
|
872
764
|
import { globalRegistry as globalRegistry12 } from "zod";
|
|
873
765
|
import * as z13 from "zod";
|
|
874
766
|
var ValidationConfigZod = z13.object({
|
|
875
767
|
allowedRewardRedeemers: z13.preprocess((val) => {
|
|
876
768
|
if (typeof val === "string") {
|
|
877
|
-
return val.split(",").map((s) =>
|
|
769
|
+
return val.split(",").map((s) => asAddress3(s.trim()));
|
|
878
770
|
}
|
|
879
771
|
return val;
|
|
880
772
|
}, z13.array(AddressZod2).optional().register(globalRegistry12, {
|
|
@@ -884,7 +776,7 @@ var ValidationConfigZod = z13.object({
|
|
|
884
776
|
})),
|
|
885
777
|
allowedRewardEscrowAccountSigners: z13.preprocess((val) => {
|
|
886
778
|
if (typeof val === "string") {
|
|
887
|
-
return val.split(",").map((s) =>
|
|
779
|
+
return val.split(",").map((s) => asAddress3(s.trim()));
|
|
888
780
|
}
|
|
889
781
|
return val;
|
|
890
782
|
}, z13.array(AddressZod2).optional().register(globalRegistry12, {
|
|
@@ -954,6 +846,33 @@ __name(isUsageMeta, "isUsageMeta");
|
|
|
954
846
|
var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_EPOCH = 1760572800;
|
|
955
847
|
var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK = 107496;
|
|
956
848
|
|
|
849
|
+
// src/eip-712/Payload.ts
|
|
850
|
+
var EIP712PayloadSchema = "network.xyo.chains.ethereum.eip712.payload";
|
|
851
|
+
var EIP712SignaturePayloadSchema = "network.xyo.chains.ethereum.eip712.signaturePayload";
|
|
852
|
+
|
|
853
|
+
// src/eip-712/sign.ts
|
|
854
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
855
|
+
var signEIP712Message = /* @__PURE__ */ __name(async (signer, data) => {
|
|
856
|
+
const { schema, ...fields } = data;
|
|
857
|
+
const signature = await signer.signTypedData(fields.domain, fields.types, fields.values);
|
|
858
|
+
const hash = await PayloadBuilder2.hash(data);
|
|
859
|
+
return {
|
|
860
|
+
address: await signer.getAddress(),
|
|
861
|
+
signature,
|
|
862
|
+
schema: EIP712SignaturePayloadSchema,
|
|
863
|
+
hash
|
|
864
|
+
};
|
|
865
|
+
}, "signEIP712Message");
|
|
866
|
+
|
|
867
|
+
// src/eip-712/verify.ts
|
|
868
|
+
import { verifyTypedData } from "ethers/hash";
|
|
869
|
+
var verifyEIP712Message = /* @__PURE__ */ __name((data, sig) => {
|
|
870
|
+
const { address, signature } = sig;
|
|
871
|
+
const { schema, ...fields } = data;
|
|
872
|
+
const recoveredAddress = verifyTypedData(fields.domain, fields.types, fields.values, signature);
|
|
873
|
+
return recoveredAddress.toLowerCase() === address.toLowerCase();
|
|
874
|
+
}, "verifyEIP712Message");
|
|
875
|
+
|
|
957
876
|
// src/model/StakeEvents.ts
|
|
958
877
|
var StakeEventNames = [
|
|
959
878
|
"StakeAdded",
|
|
@@ -973,6 +892,30 @@ var RewardMultipliers = {
|
|
|
973
892
|
]
|
|
974
893
|
};
|
|
975
894
|
|
|
895
|
+
// src/primitives/readPayloadMapFromStore.ts
|
|
896
|
+
import { isDefined as isDefined3 } from "@xylabs/typeof";
|
|
897
|
+
function readPayloadMapFromStore(store) {
|
|
898
|
+
if (isReadArchivist(store)) {
|
|
899
|
+
return {
|
|
900
|
+
get: /* @__PURE__ */ __name(async (hash) => {
|
|
901
|
+
return (await store.get([
|
|
902
|
+
hash
|
|
903
|
+
]))[0];
|
|
904
|
+
}, "get"),
|
|
905
|
+
getMany: /* @__PURE__ */ __name(async (hashes) => {
|
|
906
|
+
return await store.get(hashes);
|
|
907
|
+
}, "getMany"),
|
|
908
|
+
has: /* @__PURE__ */ __name(async (hash) => {
|
|
909
|
+
return isDefined3((await store.get([
|
|
910
|
+
hash
|
|
911
|
+
]))[0]);
|
|
912
|
+
}, "has")
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
return store;
|
|
916
|
+
}
|
|
917
|
+
__name(readPayloadMapFromStore, "readPayloadMapFromStore");
|
|
918
|
+
|
|
976
919
|
// src/primitives/step/completedStepRewardAddress.ts
|
|
977
920
|
import { toAddress as toAddress2 } from "@xylabs/hex";
|
|
978
921
|
import { keccak256 } from "ethers";
|
|
@@ -986,10 +929,10 @@ __name(completedStepRewardAddress, "completedStepRewardAddress");
|
|
|
986
929
|
|
|
987
930
|
// src/primitives/step/derivedReceiveAddress.ts
|
|
988
931
|
import { toAddress as toAddress3 } from "@xylabs/hex";
|
|
989
|
-
import { isDefined as
|
|
932
|
+
import { isDefined as isDefined4 } from "@xylabs/typeof";
|
|
990
933
|
import { keccak256 as keccak2562 } from "ethers";
|
|
991
934
|
function derivedReceiveAddress(address, scope) {
|
|
992
|
-
const addressKey = new TextEncoder().encode(
|
|
935
|
+
const addressKey = new TextEncoder().encode(isDefined4(scope) ? `${scope}|${address}` : address);
|
|
993
936
|
return toAddress3(keccak2562(addressKey).slice(-40), {
|
|
994
937
|
prefix: false
|
|
995
938
|
});
|
|
@@ -997,9 +940,9 @@ function derivedReceiveAddress(address, scope) {
|
|
|
997
940
|
__name(derivedReceiveAddress, "derivedReceiveAddress");
|
|
998
941
|
|
|
999
942
|
// src/primitives/step/stepBlockRange.ts
|
|
1000
|
-
import { asXL1BlockRange, StepSizes as
|
|
943
|
+
import { asXL1BlockRange, StepSizes as StepSizes4 } from "@xyo-network/xl1-protocol";
|
|
1001
944
|
function stepBlockRange({ block, step }) {
|
|
1002
|
-
const stepSize2 =
|
|
945
|
+
const stepSize2 = StepSizes4[step];
|
|
1003
946
|
const start = block - stepSize2;
|
|
1004
947
|
return asXL1BlockRange([
|
|
1005
948
|
start,
|
|
@@ -1009,21 +952,21 @@ function stepBlockRange({ block, step }) {
|
|
|
1009
952
|
__name(stepBlockRange, "stepBlockRange");
|
|
1010
953
|
|
|
1011
954
|
// src/primitives/step/stepTransferIndex.ts
|
|
1012
|
-
import { assertEx as
|
|
1013
|
-
import { StepSizes as
|
|
955
|
+
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
956
|
+
import { StepSizes as StepSizes5 } from "@xyo-network/xl1-protocol";
|
|
1014
957
|
function stepTransferIndex(block, step) {
|
|
1015
958
|
let rewardTransferCount = 0;
|
|
1016
959
|
let rewardTransferIndex = -1;
|
|
1017
|
-
for (let i = 3; i <
|
|
1018
|
-
const stepSize2 =
|
|
960
|
+
for (let i = 3; i < StepSizes5.length; i++) {
|
|
961
|
+
const stepSize2 = StepSizes5[i];
|
|
1019
962
|
if (block % stepSize2 === 0) {
|
|
1020
|
-
if (stepSize2 ===
|
|
963
|
+
if (stepSize2 === StepSizes5[step]) {
|
|
1021
964
|
rewardTransferIndex = rewardTransferCount;
|
|
1022
965
|
}
|
|
1023
966
|
rewardTransferCount++;
|
|
1024
967
|
}
|
|
1025
968
|
}
|
|
1026
|
-
|
|
969
|
+
assertEx5(rewardTransferIndex >= 0, () => `Error: Could not find step size for step ${step} at block ${block}`);
|
|
1027
970
|
return [
|
|
1028
971
|
rewardTransferIndex,
|
|
1029
972
|
rewardTransferCount
|
|
@@ -1031,6 +974,98 @@ function stepTransferIndex(block, step) {
|
|
|
1031
974
|
}
|
|
1032
975
|
__name(stepTransferIndex, "stepTransferIndex");
|
|
1033
976
|
|
|
977
|
+
// src/primitives/summary/balances/balancesStepSummaryFromRange.ts
|
|
978
|
+
import { assertEx as assertEx6 } from "@xylabs/assert";
|
|
979
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
980
|
+
import { isAnyPayload as isAnyPayload2 } from "@xyo-network/payload-model";
|
|
981
|
+
import { StepSizes as StepSizes6 } from "@xyo-network/xl1-protocol";
|
|
982
|
+
async function balancesStepSummaryFromRange(context, range) {
|
|
983
|
+
const frameHeadHash = await hashFromBlockNumber(context, range[1]);
|
|
984
|
+
const frameSize = range[1] - range[0] + 1;
|
|
985
|
+
const head = await context.head();
|
|
986
|
+
let result = void 0;
|
|
987
|
+
if (frameSize === 1) {
|
|
988
|
+
const hash = await hashFromBlockNumber(context, range[0]);
|
|
989
|
+
const [, payloads] = await hydrateBlock(context.store, hash);
|
|
990
|
+
const balances = {};
|
|
991
|
+
for (const [address, balance] of Object.entries(netBalancesForPayloads(payloads))) {
|
|
992
|
+
balances[address] = toSignedBigInt(balance);
|
|
993
|
+
}
|
|
994
|
+
result = {
|
|
995
|
+
schema: BalancesStepSummarySchema,
|
|
996
|
+
hash: head,
|
|
997
|
+
stepSize: -1,
|
|
998
|
+
balances
|
|
999
|
+
};
|
|
1000
|
+
} else {
|
|
1001
|
+
const step = StepSizes6.indexOf(frameSize);
|
|
1002
|
+
assertEx6(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes6.join(", ")}`);
|
|
1003
|
+
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
1004
|
+
if (isAnyPayload2(summaryResult)) {
|
|
1005
|
+
result = summaryResult;
|
|
1006
|
+
} else {
|
|
1007
|
+
await context.stepSemaphores[step].acquire();
|
|
1008
|
+
try {
|
|
1009
|
+
const subRanges = deepCalculateFramesFromRange(range, step - 1);
|
|
1010
|
+
const promises = subRanges.map((subRange) => balancesStepSummaryFromRange(context, subRange));
|
|
1011
|
+
const subResults = await Promise.all(promises);
|
|
1012
|
+
const bigIntBalances = {};
|
|
1013
|
+
for (const subResult of subResults) {
|
|
1014
|
+
for (const [address, balance] of Object.entries(subResult.balances)) {
|
|
1015
|
+
bigIntBalances[address] = (bigIntBalances[address] ?? 0n) + parseSignedBigInt(balance);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
const balances = {};
|
|
1019
|
+
for (const [address, balance] of Object.entries(bigIntBalances)) {
|
|
1020
|
+
balances[address] = toSignedBigInt(balance);
|
|
1021
|
+
}
|
|
1022
|
+
result = {
|
|
1023
|
+
schema: BalancesStepSummarySchema,
|
|
1024
|
+
hash: frameHeadHash,
|
|
1025
|
+
stepSize: frameSize,
|
|
1026
|
+
balances
|
|
1027
|
+
};
|
|
1028
|
+
await context.summaryMap.set(`${frameHeadHash}|${frameSize}`, result);
|
|
1029
|
+
} finally {
|
|
1030
|
+
context.stepSemaphores[step].release();
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
const finalResult = await PayloadBuilder3.addStorageMeta(result);
|
|
1035
|
+
return finalResult;
|
|
1036
|
+
}
|
|
1037
|
+
__name(balancesStepSummaryFromRange, "balancesStepSummaryFromRange");
|
|
1038
|
+
|
|
1039
|
+
// src/primitives/summary/balances/balancesSummary.ts
|
|
1040
|
+
import { asAddress as asAddress4 } from "@xylabs/hex";
|
|
1041
|
+
import { spanRootAsync as spanRootAsync2 } from "@xylabs/telemetry";
|
|
1042
|
+
import { isDefined as isDefined5 } from "@xylabs/typeof";
|
|
1043
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockNumber as asXL1BlockNumber3 } from "@xyo-network/xl1-protocol";
|
|
1044
|
+
async function balancesSummary(context) {
|
|
1045
|
+
return await spanRootAsync2("balanceSummary", async () => {
|
|
1046
|
+
const head = await context.head();
|
|
1047
|
+
const headResult = await context.store.chainMap.get(head);
|
|
1048
|
+
const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(headResult, () => `Head block not found for hash: ${context.head}`, {
|
|
1049
|
+
required: true
|
|
1050
|
+
});
|
|
1051
|
+
const rangeStart = asXL1BlockNumber3(isDefined5(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0);
|
|
1052
|
+
const ranges = deepCalculateFramesFromRange([
|
|
1053
|
+
rangeStart,
|
|
1054
|
+
asXL1BlockNumber3(headBoundWitness.block)
|
|
1055
|
+
]);
|
|
1056
|
+
const summaries = await Promise.all(ranges.map((range) => balancesStepSummaryFromRange(context, range)));
|
|
1057
|
+
const balances = {};
|
|
1058
|
+
for (let summary of summaries) {
|
|
1059
|
+
for (const [address, balance] of Object.entries(summary.balances)) {
|
|
1060
|
+
const validAddress = asAddress4(address, () => `Invalid address: ${address}`);
|
|
1061
|
+
balances[validAddress] = (balances[validAddress] ?? 0n) + parseSignedBigInt(balance);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return balances;
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
__name(balancesSummary, "balancesSummary");
|
|
1068
|
+
|
|
1034
1069
|
// src/primitives/transaction/elevatedPayloads.ts
|
|
1035
1070
|
import { isAllowedBlockPayload } from "@xyo-network/xl1-protocol";
|
|
1036
1071
|
function elevatedPayloads([tx, payloads]) {
|
|
@@ -1069,7 +1104,7 @@ __name(xl1BlockNumberToEthBlockNumber, "xl1BlockNumberToEthBlockNumber");
|
|
|
1069
1104
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
1070
1105
|
import { toHex as toHex2 } from "@xylabs/hex";
|
|
1071
1106
|
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
1072
|
-
import { PayloadBuilder as
|
|
1107
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
1073
1108
|
import { defaultTransactionFees } from "@xyo-network/xl1-protocol";
|
|
1074
1109
|
async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer, nbf, exp, from, fees = defaultTransactionFees) {
|
|
1075
1110
|
if (from === void 0 && Array.isArray(signer)) {
|
|
@@ -1086,7 +1121,7 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
1086
1121
|
nbf,
|
|
1087
1122
|
exp
|
|
1088
1123
|
};
|
|
1089
|
-
const elevatedHashes = await
|
|
1124
|
+
const elevatedHashes = await PayloadBuilder4.hashes(onChainPayloads);
|
|
1090
1125
|
const script = [];
|
|
1091
1126
|
for (const elevatedHash of elevatedHashes) {
|
|
1092
1127
|
script.push(`elevate|${elevatedHash}`);
|
|
@@ -1107,8 +1142,8 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
1107
1142
|
signer
|
|
1108
1143
|
]).build();
|
|
1109
1144
|
return [
|
|
1110
|
-
await
|
|
1111
|
-
await
|
|
1145
|
+
await PayloadBuilder4.addStorageMeta(tx),
|
|
1146
|
+
await PayloadBuilder4.addStorageMeta(txPayloads)
|
|
1112
1147
|
];
|
|
1113
1148
|
}
|
|
1114
1149
|
__name(buildTransaction, "buildTransaction");
|
|
@@ -1116,7 +1151,7 @@ __name(buildTransaction, "buildTransaction");
|
|
|
1116
1151
|
// src/transaction/buildUnsignedTransaction.ts
|
|
1117
1152
|
import { toHex as toHex3 } from "@xylabs/hex";
|
|
1118
1153
|
import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
|
|
1119
|
-
import { PayloadBuilder as
|
|
1154
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1120
1155
|
import { defaultTransactionFees as defaultTransactionFees2 } from "@xyo-network/xl1-protocol";
|
|
1121
1156
|
async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads, nbf, exp, from, fees = defaultTransactionFees2) {
|
|
1122
1157
|
const txBoundWitnessFields = {
|
|
@@ -1130,7 +1165,7 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
1130
1165
|
nbf,
|
|
1131
1166
|
exp
|
|
1132
1167
|
};
|
|
1133
|
-
const elevatedHashes = await
|
|
1168
|
+
const elevatedHashes = await PayloadBuilder5.hashes(onChainPayloads);
|
|
1134
1169
|
const script = [];
|
|
1135
1170
|
for (const elevatedHash of elevatedHashes) {
|
|
1136
1171
|
script.push(`elevate|${elevatedHash}`);
|
|
@@ -1149,8 +1184,8 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
1149
1184
|
...offChainPayloads
|
|
1150
1185
|
]).build();
|
|
1151
1186
|
return [
|
|
1152
|
-
await
|
|
1153
|
-
await
|
|
1187
|
+
await PayloadBuilder5.addStorageMeta(tx),
|
|
1188
|
+
await PayloadBuilder5.addStorageMeta(txPayloads)
|
|
1154
1189
|
];
|
|
1155
1190
|
}
|
|
1156
1191
|
__name(buildUnsignedTransaction, "buildUnsignedTransaction");
|
|
@@ -1158,12 +1193,12 @@ __name(buildUnsignedTransaction, "buildUnsignedTransaction");
|
|
|
1158
1193
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
1159
1194
|
import { delay } from "@xylabs/delay";
|
|
1160
1195
|
import { isDefined as isDefined6 } from "@xylabs/typeof";
|
|
1161
|
-
import { PayloadBuilder as
|
|
1196
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
1162
1197
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
1163
1198
|
var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
|
|
1164
1199
|
var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, transaction, options) => {
|
|
1165
1200
|
const { attempts: maxAttempts = DEFAULT_CONFIRMATION_ATTEMPTS, delay: attemptDelay = DEFAULT_DELAY_BETWEEN_ATTEMPTS } = options || {};
|
|
1166
|
-
const txBWHash = await
|
|
1201
|
+
const txBWHash = await PayloadBuilder6.hash(transaction);
|
|
1167
1202
|
options?.logger?.log("\u{1F680} confirming transaction:", txBWHash, "\n");
|
|
1168
1203
|
let attempts = 0;
|
|
1169
1204
|
while (true) {
|
|
@@ -1248,11 +1283,11 @@ var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (context, hash) =>
|
|
|
1248
1283
|
}, "hydrateElevatedTransaction");
|
|
1249
1284
|
|
|
1250
1285
|
// src/transaction/primitives/transactionBlockByteCount.ts
|
|
1251
|
-
import { PayloadBuilder as
|
|
1286
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1252
1287
|
function transactionBlockByteCount([transaction, payloads]) {
|
|
1253
|
-
const cleanTransaction =
|
|
1288
|
+
const cleanTransaction = PayloadBuilder7.omitStorageMeta(transaction);
|
|
1254
1289
|
const transactionBytes = JSON.stringify(cleanTransaction).length;
|
|
1255
|
-
const cleanPayloads =
|
|
1290
|
+
const cleanPayloads = PayloadBuilder7.omitStorageMeta(payloads);
|
|
1256
1291
|
return cleanPayloads.reduce((acc, payload) => acc + JSON.stringify(payload).length, 0) + transactionBytes;
|
|
1257
1292
|
}
|
|
1258
1293
|
__name(transactionBlockByteCount, "transactionBlockByteCount");
|
|
@@ -1342,7 +1377,7 @@ var extractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
|
1342
1377
|
import { toArrayBuffer } from "@xylabs/arraybuffer";
|
|
1343
1378
|
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1344
1379
|
import { hexFromArrayBuffer } from "@xylabs/hex";
|
|
1345
|
-
import { PayloadBuilder as
|
|
1380
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
1346
1381
|
async function signTransaction(tx, account) {
|
|
1347
1382
|
assertEx11(tx.from === account.address, () => "Signer address does not match transaction from address");
|
|
1348
1383
|
const signedTx = structuredClone(tx);
|
|
@@ -1352,7 +1387,7 @@ async function signTransaction(tx, account) {
|
|
|
1352
1387
|
signedTx.previous_hashes = [
|
|
1353
1388
|
account.previousHash ?? null
|
|
1354
1389
|
];
|
|
1355
|
-
const hash = await
|
|
1390
|
+
const hash = await PayloadBuilder8.dataHash(signedTx);
|
|
1356
1391
|
const hashBytes = toArrayBuffer(hash);
|
|
1357
1392
|
const [signature] = await account.sign(hashBytes);
|
|
1358
1393
|
signedTx.$signatures = [
|
|
@@ -1398,6 +1433,8 @@ export {
|
|
|
1398
1433
|
COIN_TYPES,
|
|
1399
1434
|
ConfigZod,
|
|
1400
1435
|
DEFAULT_WALLET_PATH,
|
|
1436
|
+
EIP712PayloadSchema,
|
|
1437
|
+
EIP712SignaturePayloadSchema,
|
|
1401
1438
|
GlobalMetaSchema,
|
|
1402
1439
|
JSONSchemaMetaSchema,
|
|
1403
1440
|
MnemonicStringZod,
|
|
@@ -1456,13 +1493,16 @@ export {
|
|
|
1456
1493
|
isNegativeBigInt,
|
|
1457
1494
|
isPositiveBigInt,
|
|
1458
1495
|
isReadArchivist,
|
|
1496
|
+
isReadWriteArchivist,
|
|
1459
1497
|
isTransfersStepSummary,
|
|
1460
1498
|
isTransfersStepSummaryWithStorageMeta,
|
|
1461
1499
|
isUsageMeta,
|
|
1500
|
+
isWriteArchivist,
|
|
1462
1501
|
netBalancesForPayloads,
|
|
1463
1502
|
netTransfersForPayloads,
|
|
1464
1503
|
parseSignedBigInt,
|
|
1465
1504
|
readPayloadMapFromStore,
|
|
1505
|
+
signEIP712Message,
|
|
1466
1506
|
signTransaction,
|
|
1467
1507
|
stepBlockRange,
|
|
1468
1508
|
stepTransferIndex,
|
|
@@ -1481,6 +1521,7 @@ export {
|
|
|
1481
1521
|
tryHydrateBlock,
|
|
1482
1522
|
tryHydrateElevatedTransaction,
|
|
1483
1523
|
tryHydrateTransaction,
|
|
1524
|
+
verifyEIP712Message,
|
|
1484
1525
|
xl1BlockNumberToEthBlockNumber
|
|
1485
1526
|
};
|
|
1486
1527
|
//# sourceMappingURL=index.mjs.map
|