@xyo-network/chain-services 1.15.2 → 1.15.3
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/README.md +5302 -2235
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +3 -5
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts +3 -2
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts +3 -6
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts +3 -3
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/spec/BaseBlockProducerService.spec.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +3 -3
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts +3 -2
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +2 -2
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +14 -13
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +2 -2
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/index.mjs +102 -144
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +40 -40
- package/src/AccountBalance/BaseAccountBalanceService.ts +6 -8
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +18 -33
- package/src/AccountTransfers/BaseAccountTransfersService.ts +4 -12
- package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +18 -35
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +62 -8
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +11 -11
- package/src/ChainBlockNumberIteration/model/Params.ts +3 -2
- package/src/ChainValidator/XyoValidator.ts +2 -2
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +20 -14
- package/src/PendingTransactions/BasePendingTransactions.ts +2 -2
- package/src/StakeIntent/XyoStakeIntentService.ts +3 -1
package/dist/neutral/index.mjs
CHANGED
|
@@ -2,10 +2,9 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/AccountBalance/accountBalanceServiceFromArchivist.ts
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { LRUCache } from "lru-cache";
|
|
5
|
+
import { ZERO_HASH } from "@xylabs/hex";
|
|
6
|
+
import { LruCacheMap } from "@xyo-network/chain-protocol";
|
|
7
|
+
import { readPayloadMapFromStore } from "@xyo-network/xl1-protocol-sdk";
|
|
9
8
|
|
|
10
9
|
// src/AccountBalance/BaseAccountBalanceService.ts
|
|
11
10
|
import { creatable as creatable2 } from "@xylabs/creatable";
|
|
@@ -80,11 +79,7 @@ var BaseAccountBalanceService = class extends BaseService {
|
|
|
80
79
|
}
|
|
81
80
|
async balances(head, address) {
|
|
82
81
|
return await spanRootAsync2("balances", async () => {
|
|
83
|
-
const summary = await balancesSummary(
|
|
84
|
-
chainArchivist: this.params.chainArchivist,
|
|
85
|
-
summaryRepository: this.params.summaryRepository,
|
|
86
|
-
head
|
|
87
|
-
});
|
|
82
|
+
const summary = await balancesSummary(this.params.context);
|
|
88
83
|
const result = {};
|
|
89
84
|
for (const addr of address) {
|
|
90
85
|
const summaryBalance = summary[addr] ?? 0n;
|
|
@@ -99,46 +94,31 @@ BaseAccountBalanceService = _ts_decorate2([
|
|
|
99
94
|
], BaseAccountBalanceService);
|
|
100
95
|
|
|
101
96
|
// src/AccountBalance/accountBalanceServiceFromArchivist.ts
|
|
102
|
-
var
|
|
103
|
-
const
|
|
97
|
+
var accountBalancesServiceFromArchivist = /* @__PURE__ */ __name(async (chainId, archivist) => {
|
|
98
|
+
const summaryMap = new LruCacheMap({
|
|
104
99
|
max: 1e5,
|
|
105
100
|
allowStale: true,
|
|
106
101
|
noDisposeOnSet: false,
|
|
107
102
|
updateAgeOnGet: true
|
|
108
103
|
});
|
|
109
|
-
const
|
|
110
|
-
get: /* @__PURE__ */ __name((hashes) => {
|
|
111
|
-
const results = hashes.map((hash) => {
|
|
112
|
-
return summaryArchivistCache.get(hash);
|
|
113
|
-
}).filter(exists);
|
|
114
|
-
return results;
|
|
115
|
-
}, "get"),
|
|
116
|
-
insert: /* @__PURE__ */ __name(async (payloads) => {
|
|
117
|
-
const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
|
|
118
|
-
const hash = asHash(payload.hash);
|
|
119
|
-
if (isHash(hash)) {
|
|
120
|
-
summaryArchivistCache.set(hash, payload);
|
|
121
|
-
return payload;
|
|
122
|
-
}
|
|
123
|
-
}).filter(exists);
|
|
124
|
-
return results;
|
|
125
|
-
}, "insert"),
|
|
126
|
-
next: /* @__PURE__ */ __name(() => {
|
|
127
|
-
throw new Error("Not implemented");
|
|
128
|
-
}, "next")
|
|
129
|
-
};
|
|
104
|
+
const chainMap = readPayloadMapFromStore(archivist);
|
|
130
105
|
const service = await BaseAccountBalanceService.create({
|
|
131
|
-
|
|
132
|
-
|
|
106
|
+
context: {
|
|
107
|
+
chainId,
|
|
108
|
+
store: {
|
|
109
|
+
chainMap
|
|
110
|
+
},
|
|
111
|
+
summaryMap,
|
|
112
|
+
head: /* @__PURE__ */ __name(() => ZERO_HASH, "head")
|
|
113
|
+
}
|
|
133
114
|
});
|
|
134
115
|
return service;
|
|
135
|
-
}, "
|
|
116
|
+
}, "accountBalancesServiceFromArchivist");
|
|
136
117
|
|
|
137
118
|
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
138
|
-
import {
|
|
139
|
-
import {
|
|
140
|
-
import {
|
|
141
|
-
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
119
|
+
import { ZERO_HASH as ZERO_HASH2 } from "@xylabs/hex";
|
|
120
|
+
import { LruCacheMap as LruCacheMap2 } from "@xyo-network/chain-protocol";
|
|
121
|
+
import { readPayloadMapFromStore as readPayloadMapFromStore2 } from "@xyo-network/xl1-protocol-sdk";
|
|
142
122
|
|
|
143
123
|
// src/AccountTransfers/BaseAccountTransfersService.ts
|
|
144
124
|
import { creatable as creatable3 } from "@xylabs/creatable";
|
|
@@ -163,13 +143,7 @@ var BaseAccountTransfersService = class extends BaseService {
|
|
|
163
143
|
}
|
|
164
144
|
async transfers(head, addresses) {
|
|
165
145
|
return await spanRootAsync3("transfers", async () => {
|
|
166
|
-
const
|
|
167
|
-
const summary = await transfersSummary({
|
|
168
|
-
chainArchivist,
|
|
169
|
-
summaryRepository,
|
|
170
|
-
head,
|
|
171
|
-
account
|
|
172
|
-
});
|
|
146
|
+
const summary = await transfersSummary(this.params.context);
|
|
173
147
|
const result = {};
|
|
174
148
|
for (const addr of addresses) {
|
|
175
149
|
const summaryBalance = summary[addr] ?? 0n;
|
|
@@ -184,65 +158,50 @@ BaseAccountTransfersService = _ts_decorate3([
|
|
|
184
158
|
], BaseAccountTransfersService);
|
|
185
159
|
|
|
186
160
|
// src/AccountTransfers/accountTransfersServiceFromArchivist.ts
|
|
187
|
-
var
|
|
188
|
-
const
|
|
161
|
+
var accountTransfersServiceFromArchivist = /* @__PURE__ */ __name(async (chainId, archivist) => {
|
|
162
|
+
const summaryMap = new LruCacheMap2({
|
|
189
163
|
max: 1e5,
|
|
190
164
|
allowStale: true,
|
|
191
165
|
noDisposeOnSet: false,
|
|
192
166
|
updateAgeOnGet: true
|
|
193
167
|
});
|
|
194
|
-
const
|
|
195
|
-
get: /* @__PURE__ */ __name((hashes) => {
|
|
196
|
-
const results = hashes.map((hash) => {
|
|
197
|
-
return summaryArchivistCache.get(hash);
|
|
198
|
-
}).filter(exists2);
|
|
199
|
-
return results;
|
|
200
|
-
}, "get"),
|
|
201
|
-
insert: /* @__PURE__ */ __name(async (payloads) => {
|
|
202
|
-
const results = (await PayloadBuilder2.addStorageMeta(payloads)).map((payload) => {
|
|
203
|
-
const hash = asHash2(payload.hash);
|
|
204
|
-
if (isHash2(hash)) {
|
|
205
|
-
summaryArchivistCache.set(hash, payload);
|
|
206
|
-
return payload;
|
|
207
|
-
}
|
|
208
|
-
}).filter(exists2);
|
|
209
|
-
return results;
|
|
210
|
-
}, "insert"),
|
|
211
|
-
next: /* @__PURE__ */ __name(() => {
|
|
212
|
-
throw new Error("Not implemented");
|
|
213
|
-
}, "next")
|
|
214
|
-
};
|
|
168
|
+
const chainMap = readPayloadMapFromStore2(archivist);
|
|
215
169
|
const service = await BaseAccountTransfersService.create({
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
170
|
+
context: {
|
|
171
|
+
chainId,
|
|
172
|
+
store: {
|
|
173
|
+
chainMap
|
|
174
|
+
},
|
|
175
|
+
summaryMap,
|
|
176
|
+
head: /* @__PURE__ */ __name(() => ZERO_HASH2, "head")
|
|
177
|
+
}
|
|
219
178
|
});
|
|
220
179
|
return service;
|
|
221
|
-
}, "
|
|
180
|
+
}, "accountTransfersServiceFromArchivist");
|
|
222
181
|
|
|
223
182
|
// src/BlockProducer/BaseBlockProducerService.ts
|
|
224
183
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
225
184
|
import { creatable as creatable4 } from "@xylabs/creatable";
|
|
226
|
-
import { exists
|
|
185
|
+
import { exists } from "@xylabs/exists";
|
|
227
186
|
import { hexToBigInt, toHex } from "@xylabs/hex";
|
|
228
187
|
import { isDefined } from "@xylabs/typeof";
|
|
229
188
|
import { FixedPercentageBlockRewardDiviner, FixedPercentageBlockRewardDivinerConfigSchema } from "@xyo-network/chain-modules";
|
|
230
189
|
import { buildNextBlock, createDeclarationIntent } from "@xyo-network/chain-protocol";
|
|
231
|
-
import { PayloadBuilder as
|
|
190
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
232
191
|
import { asBlockBoundWitness, AttoXL1 as AttoXL13, BlockNumberSchema, defaultRewardRatio, TimeSchema, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
233
192
|
|
|
234
193
|
// src/BlockProducer/generateTransactionFeeTransfers.ts
|
|
235
194
|
import { assertEx } from "@xylabs/assert";
|
|
236
195
|
import { hexFromBigInt } from "@xylabs/hex";
|
|
237
|
-
import { PayloadBuilder
|
|
196
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
238
197
|
import { TransferSchema, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
239
198
|
import { transactionRequiredGas } from "@xyo-network/xl1-protocol-sdk";
|
|
240
199
|
import { HydratedTransactionWrapper } from "@xyo-network/xl1-wrappers";
|
|
241
200
|
async function generateTransactionFeeTransfers(address, transactions) {
|
|
242
201
|
const txs = await Promise.all(transactions.map(async (tx) => {
|
|
243
202
|
return HydratedTransactionWrapper.parse([
|
|
244
|
-
await
|
|
245
|
-
await
|
|
203
|
+
await PayloadBuilder.addStorageMeta(tx[0]),
|
|
204
|
+
await PayloadBuilder.addStorageMeta(tx[1])
|
|
246
205
|
]);
|
|
247
206
|
}));
|
|
248
207
|
const txBaseFeeCosts = {};
|
|
@@ -369,7 +328,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
369
328
|
});
|
|
370
329
|
}
|
|
371
330
|
const blockHex = assertEx2(toHex(block), () => "Failed to convert block to hex");
|
|
372
|
-
const blockId = new
|
|
331
|
+
const blockId = new PayloadBuilder2({
|
|
373
332
|
schema: BlockNumberSchema
|
|
374
333
|
}).fields({
|
|
375
334
|
block: blockHex
|
|
@@ -454,7 +413,7 @@ var BaseBlockProducerService = class _BaseBlockProducerService extends BaseServi
|
|
|
454
413
|
fundedTransfers.push(transfer);
|
|
455
414
|
return tx;
|
|
456
415
|
}
|
|
457
|
-
}))).filter(
|
|
416
|
+
}))).filter(exists);
|
|
458
417
|
this.logger?.info(`Filtered ${txs.length} transactions to ${fundedTransactions.length} funded transactions in ${Date.now() - start}ms`);
|
|
459
418
|
return [
|
|
460
419
|
fundedTransactions,
|
|
@@ -618,33 +577,31 @@ MemoryBlockRewardService = _ts_decorate7([
|
|
|
618
577
|
// src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts
|
|
619
578
|
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
620
579
|
import { isDefined as isDefined2, isNull, isUndefined } from "@xylabs/typeof";
|
|
621
|
-
import { PayloadBuilder as
|
|
580
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
622
581
|
import { asBlockBoundWitness as asBlockBoundWitness2, asBlockBoundWitnessWithStorageMeta, isBlockBoundWitnessWithHashStorageMeta } from "@xyo-network/xl1-protocol";
|
|
623
|
-
import { LRUCache
|
|
582
|
+
import { LRUCache } from "lru-cache";
|
|
624
583
|
var ChainBlockNumberIterationService = class extends BaseService {
|
|
625
584
|
static {
|
|
626
585
|
__name(this, "ChainBlockNumberIterationService");
|
|
627
586
|
}
|
|
628
|
-
_blocksByBlockNumber = new
|
|
587
|
+
_blocksByBlockNumber = new LRUCache({
|
|
629
588
|
max: 1e4
|
|
630
589
|
});
|
|
631
590
|
_currentHead;
|
|
632
|
-
get chainArchivist() {
|
|
633
|
-
return assertEx5(this.params.chainArchivist);
|
|
634
|
-
}
|
|
635
591
|
get chainId() {
|
|
636
592
|
return assertEx5(this._currentHead?.chain ?? this.params?.head?.chain, () => "Current head is not set");
|
|
637
593
|
}
|
|
594
|
+
get chainMap() {
|
|
595
|
+
return assertEx5(this.params.chainMap);
|
|
596
|
+
}
|
|
638
597
|
async get(block) {
|
|
639
598
|
const head = await this.head();
|
|
640
599
|
assertEx5(head.block >= block, () => `Block requested is newer than the current head [${block}]`);
|
|
641
600
|
const cached = this._blocksByBlockNumber.get(block);
|
|
642
601
|
if (cached) return cached;
|
|
643
602
|
const startingBlock = head;
|
|
644
|
-
const currentBlockHash = await
|
|
645
|
-
let currentBlock =
|
|
646
|
-
currentBlockHash
|
|
647
|
-
])).at(0);
|
|
603
|
+
const currentBlockHash = await PayloadBuilder3.hash(startingBlock);
|
|
604
|
+
let currentBlock = await this.chainMap.get(currentBlockHash);
|
|
648
605
|
while (isDefined2(currentBlock)) {
|
|
649
606
|
assertEx5(asBlockBoundWitness2(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`);
|
|
650
607
|
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
@@ -654,9 +611,7 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
654
611
|
}
|
|
655
612
|
const { previous } = currentBlock;
|
|
656
613
|
if (isNull(previous)) break;
|
|
657
|
-
currentBlock =
|
|
658
|
-
previous
|
|
659
|
-
])).at(0);
|
|
614
|
+
currentBlock = await this.chainMap.get(previous);
|
|
660
615
|
}
|
|
661
616
|
}
|
|
662
617
|
throw new Error(`Block not found: ${block}`);
|
|
@@ -680,17 +635,15 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
680
635
|
async previous(block = void 0, count = 1) {
|
|
681
636
|
const results = [];
|
|
682
637
|
let currentBlock = isDefined2(block) ? await this.get(block) : await this.head();
|
|
683
|
-
while (currentBlock && results.length < count) {
|
|
638
|
+
while (isDefined2(currentBlock) && results.length < count) {
|
|
684
639
|
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
685
640
|
results.push(currentBlock);
|
|
686
641
|
const { previous } = currentBlock;
|
|
687
642
|
if (isNull(previous)) break;
|
|
688
|
-
const nextBlock = await this.
|
|
689
|
-
|
|
690
|
-
]);
|
|
691
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock[0]);
|
|
643
|
+
const nextBlock = await this.chainMap.get(previous);
|
|
644
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock);
|
|
692
645
|
} else {
|
|
693
|
-
const hash =
|
|
646
|
+
const hash = PayloadBuilder3.hash(currentBlock);
|
|
694
647
|
assertEx5(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`);
|
|
695
648
|
}
|
|
696
649
|
}
|
|
@@ -706,10 +659,8 @@ var ChainBlockNumberIterationService = class extends BaseService {
|
|
|
706
659
|
});
|
|
707
660
|
}
|
|
708
661
|
async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head) {
|
|
709
|
-
const hash = await
|
|
710
|
-
const stored =
|
|
711
|
-
hash
|
|
712
|
-
])).at(-1);
|
|
662
|
+
const hash = await PayloadBuilder3.hash(head);
|
|
663
|
+
const stored = await this.chainMap.get(hash);
|
|
713
664
|
const newHead = asBlockBoundWitnessWithStorageMeta(stored);
|
|
714
665
|
if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`);
|
|
715
666
|
return newHead;
|
|
@@ -912,7 +863,7 @@ XyoValidator = _ts_decorate8([
|
|
|
912
863
|
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
913
864
|
import { creatable as creatable9 } from "@xylabs/creatable";
|
|
914
865
|
import { hexToLast4BytesInt, shuffleWithSeed } from "@xyo-network/chain-utils";
|
|
915
|
-
import { PayloadBuilder as
|
|
866
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
916
867
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
917
868
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
918
869
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -937,7 +888,7 @@ var BaseElectionService = class extends BaseService {
|
|
|
937
888
|
return await this.spanAsync("getCreatorCommitteeForNextBlock", async () => {
|
|
938
889
|
const nextBlock = current.block + 1;
|
|
939
890
|
const candidates = await this.stakeIntentService.getDeclaredCandidatesForBlock(nextBlock, "producer");
|
|
940
|
-
const previousBlockHash = await
|
|
891
|
+
const previousBlockHash = await PayloadBuilder4.hash(current);
|
|
941
892
|
return this.generateCreatorCommittee(candidates, previousBlockHash);
|
|
942
893
|
});
|
|
943
894
|
}
|
|
@@ -965,43 +916,46 @@ var BaseNetworkStakeStepRewardService = class extends BaseService {
|
|
|
965
916
|
static {
|
|
966
917
|
__name(this, "BaseNetworkStakeStepRewardService");
|
|
967
918
|
}
|
|
968
|
-
|
|
919
|
+
networkStakeStepRewardAddressHistory(_address) {
|
|
969
920
|
throw new Error("Method not implemented.");
|
|
970
921
|
}
|
|
971
|
-
|
|
922
|
+
networkStakeStepRewardAddressReward(_context, _address) {
|
|
972
923
|
throw new Error("Method not implemented.");
|
|
973
924
|
}
|
|
974
|
-
|
|
925
|
+
networkStakeStepRewardAddressShare(_context, _address) {
|
|
975
926
|
throw new Error("Method not implemented.");
|
|
976
927
|
}
|
|
977
|
-
|
|
928
|
+
networkStakeStepRewardClaimedByAddress(_address) {
|
|
978
929
|
throw new Error("Method not implemented.");
|
|
979
930
|
}
|
|
980
|
-
|
|
931
|
+
networkStakeStepRewardForStep(_context) {
|
|
981
932
|
throw new Error("Method not implemented.");
|
|
982
933
|
}
|
|
983
|
-
|
|
934
|
+
networkStakeStepRewardForStepForPosition(_context, _position) {
|
|
984
935
|
throw new Error("Method not implemented.");
|
|
985
936
|
}
|
|
986
|
-
|
|
937
|
+
networkStakeStepRewardPoolRewards(_context) {
|
|
987
938
|
throw new Error("Method not implemented.");
|
|
988
939
|
}
|
|
989
|
-
|
|
940
|
+
networkStakeStepRewardPoolShares(_context) {
|
|
990
941
|
throw new Error("Method not implemented.");
|
|
991
942
|
}
|
|
992
|
-
|
|
943
|
+
networkStakeStepRewardPositionWeight(_context, _position) {
|
|
993
944
|
throw new Error("Method not implemented.");
|
|
994
945
|
}
|
|
995
|
-
|
|
946
|
+
networkStakeStepRewardPotentialPositionLoss(_context, _position) {
|
|
996
947
|
throw new Error("Method not implemented.");
|
|
997
948
|
}
|
|
998
|
-
|
|
949
|
+
networkStakeStepRewardRandomizer(_context) {
|
|
999
950
|
throw new Error("Method not implemented.");
|
|
1000
951
|
}
|
|
1001
|
-
|
|
952
|
+
networkStakeStepRewardStakerCount(_context) {
|
|
1002
953
|
throw new Error("Method not implemented.");
|
|
1003
954
|
}
|
|
1004
|
-
|
|
955
|
+
networkStakeStepRewardUnclaimedByAddress(_address) {
|
|
956
|
+
throw new Error("Method not implemented.");
|
|
957
|
+
}
|
|
958
|
+
networkStakeStepRewardWeightForAddress(_context, _address) {
|
|
1005
959
|
throw new Error("Method not implemented.");
|
|
1006
960
|
}
|
|
1007
961
|
};
|
|
@@ -1014,7 +968,7 @@ import { ValueType } from "@opentelemetry/api";
|
|
|
1014
968
|
import { filterAs, filterAsync } from "@xylabs/array";
|
|
1015
969
|
import { assertEx as assertEx9 } from "@xylabs/assert";
|
|
1016
970
|
import { creatable as creatable11 } from "@xylabs/creatable";
|
|
1017
|
-
import { exists as
|
|
971
|
+
import { exists as exists2 } from "@xylabs/exists";
|
|
1018
972
|
import { forget } from "@xylabs/forget";
|
|
1019
973
|
import { isDefined as isDefined3, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
1020
974
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
@@ -1024,10 +978,10 @@ import { TransactionJsonSchemaValidator, validateTransaction } from "@xyo-networ
|
|
|
1024
978
|
import { Mutex as Mutex2 } from "async-mutex";
|
|
1025
979
|
|
|
1026
980
|
// src/PendingTransactions/bundledPayloadToHydratedTransaction.ts
|
|
1027
|
-
import { PayloadBuilder as
|
|
981
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
1028
982
|
import { asTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
1029
983
|
var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload) => {
|
|
1030
|
-
const withStorageMeta = await
|
|
984
|
+
const withStorageMeta = await PayloadBuilder5.addStorageMeta(payload.payloads);
|
|
1031
985
|
const tx = asTransactionBoundWitnessWithStorageMeta(withStorageMeta.find((p) => p._hash === payload.root));
|
|
1032
986
|
if (tx) {
|
|
1033
987
|
return [
|
|
@@ -1038,7 +992,7 @@ var bundledPayloadToHydratedTransaction = /* @__PURE__ */ __name(async (payload)
|
|
|
1038
992
|
}, "bundledPayloadToHydratedTransaction");
|
|
1039
993
|
|
|
1040
994
|
// src/PendingTransactions/hydratedTransactionToPayloadBundle.ts
|
|
1041
|
-
import { PayloadBuilder as
|
|
995
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
1042
996
|
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
1043
997
|
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
1044
998
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
@@ -1046,8 +1000,8 @@ var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) =>
|
|
|
1046
1000
|
return bundle(root, transaction);
|
|
1047
1001
|
}, "hydratedTransactionToPayloadBundle");
|
|
1048
1002
|
var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
1049
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) =>
|
|
1050
|
-
return new
|
|
1003
|
+
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder6.omitStorageMeta(p));
|
|
1004
|
+
return new PayloadBuilder6({
|
|
1051
1005
|
schema: PayloadBundleSchema
|
|
1052
1006
|
}).fields({
|
|
1053
1007
|
payloads,
|
|
@@ -1169,7 +1123,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1169
1123
|
if (pendingBundledTransactions.length === 0) break;
|
|
1170
1124
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
1171
1125
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
1172
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1126
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists2);
|
|
1173
1127
|
const activeTransactions = transactions.filter(isTransactionActive(lastHead.block + 1));
|
|
1174
1128
|
foundPendingTransactions.push(...activeTransactions);
|
|
1175
1129
|
}
|
|
@@ -1210,7 +1164,7 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1210
1164
|
const unprocessedTransactions = await this.filterAlreadyFinalizedTransactions(payloads);
|
|
1211
1165
|
const hydratedUnprocessedTransactions = (await Promise.all(unprocessedTransactions.map(async (tx) => {
|
|
1212
1166
|
return await bundledPayloadToHydratedTransaction(tx);
|
|
1213
|
-
}))).filter(
|
|
1167
|
+
}))).filter(exists2);
|
|
1214
1168
|
const validTransactions = await filterAsync(hydratedUnprocessedTransactions, async (tx) => {
|
|
1215
1169
|
const errors = await validateTransaction(tx, this.chainId, [
|
|
1216
1170
|
TransactionJsonSchemaValidator
|
|
@@ -1257,14 +1211,14 @@ var BasePendingTransactionsService = class _BasePendingTransactionsService exten
|
|
|
1257
1211
|
}
|
|
1258
1212
|
cursor = pendingBundledTransactions.at(-1)?._sequence;
|
|
1259
1213
|
const deletedTransactionBundles = pendingBundledTransactions.filter((tx) => this._removablePendingTransactionHashes.has(tx.root));
|
|
1260
|
-
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(
|
|
1214
|
+
foundPendingTransactionsToDeleteHashes.push(...deletedTransactionBundles.map((tx) => tx._hash).filter(exists2));
|
|
1261
1215
|
const undeletedTransactionBundles = pendingBundledTransactions.filter((tx) => !this._removablePendingTransactionHashes.has(tx.root));
|
|
1262
|
-
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(
|
|
1216
|
+
const transactions = (await Promise.all(undeletedTransactionBundles.map((p) => bundledPayloadToHydratedTransaction(p)))).filter(exists2);
|
|
1263
1217
|
const expiredTransactions = transactions.filter(isTransactionExpired(lastHead.block + 1));
|
|
1264
1218
|
const expiredBundleHashes = expiredTransactions.map((expiredHydratedTx) => (
|
|
1265
1219
|
// Find the corresponding payload bundle hash for the expired transaction
|
|
1266
1220
|
pendingBundledTransactions.find((bundledTx) => bundledTx.root === expiredHydratedTx[0]._hash)?._hash
|
|
1267
|
-
)).filter(
|
|
1221
|
+
)).filter(exists2);
|
|
1268
1222
|
foundPendingTransactionsToDeleteHashes.push(...expiredBundleHashes);
|
|
1269
1223
|
}
|
|
1270
1224
|
const deletedHashes = await this.pendingBundledTransactionsLocalArchivist.delete(foundPendingTransactionsToDeleteHashes);
|
|
@@ -1288,7 +1242,7 @@ var isTransactionActive = /* @__PURE__ */ __name((block) => ([txBw]) => txBw.nbf
|
|
|
1288
1242
|
|
|
1289
1243
|
// src/StakeIntent/lib/getBlockSignedStakeDeclarations.ts
|
|
1290
1244
|
import { filterAs as filterAs2 } from "@xylabs/array";
|
|
1291
|
-
import { exists as
|
|
1245
|
+
import { exists as exists3 } from "@xylabs/exists";
|
|
1292
1246
|
import { asOptionalBoundWitness } from "@xyo-network/boundwitness-model";
|
|
1293
1247
|
import { payloadSchemasContains } from "@xyo-network/boundwitness-validator";
|
|
1294
1248
|
import { BoundWitnessWrapper } from "@xyo-network/boundwitness-wrapper";
|
|
@@ -1299,7 +1253,7 @@ var getBlockSignedStakeDeclarations = /* @__PURE__ */ __name(async (block, archi
|
|
|
1299
1253
|
const bwsFromBlockWithDeclarations = bwsFromBlock.filter((bw) => payloadSchemasContains(bw, ChainStakeIntentSchema));
|
|
1300
1254
|
const validBlockBwsWithDeclarations = await filterToValidSignedBoundWitnesses(bwsFromBlockWithDeclarations);
|
|
1301
1255
|
return (await Promise.all(validBlockBwsWithDeclarations.map(async (bw) => {
|
|
1302
|
-
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(
|
|
1256
|
+
const stakeIntentHashes = validBlockBwsWithDeclarations.flatMap(mapBoundWitnessToStakeIntentHashes).filter(exists3);
|
|
1303
1257
|
const payloads = await archivist.get(stakeIntentHashes);
|
|
1304
1258
|
const stakeIntents = filterAs2(payloads, asChainStakeIntent).filter((p) => p.intent === intent).filter((p) => bw.addresses.includes(p.from));
|
|
1305
1259
|
return stakeIntents;
|
|
@@ -1321,10 +1275,11 @@ import { asAddress } from "@xylabs/hex";
|
|
|
1321
1275
|
import { isUndefined as isUndefined3 } from "@xylabs/typeof";
|
|
1322
1276
|
import { analyzeChain, ChainStakeIntentAnalyzer, isChainSummaryStakeIntent } from "@xyo-network/chain-analyze";
|
|
1323
1277
|
import { DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS, findFirstMatching, IntervalMap } from "@xyo-network/chain-utils";
|
|
1324
|
-
import { PayloadBuilder as
|
|
1278
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
1325
1279
|
import { asBlockBoundWitness as asBlockBoundWitness3, asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asChainIndexingServiceStateWithStorageMeta, asChainStakeIntent as asChainStakeIntent2, ChainIndexingServiceStateSchema, isChainIndexingServiceState } from "@xyo-network/xl1-protocol";
|
|
1280
|
+
import { readPayloadMapFromStore as readPayloadMapFromStore3 } from "@xyo-network/xl1-protocol-sdk";
|
|
1326
1281
|
import { Mutex as Mutex3 } from "async-mutex";
|
|
1327
|
-
import { LRUCache as
|
|
1282
|
+
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
1328
1283
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
1329
1284
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1330
1285
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1349,7 +1304,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1349
1304
|
// in performance for small sets, and (most importantly) easily
|
|
1350
1305
|
// persisted so we can recover state on restart.
|
|
1351
1306
|
_producers = new IntervalMap();
|
|
1352
|
-
_stakeCache = new
|
|
1307
|
+
_stakeCache = new LRUCache2({
|
|
1353
1308
|
max: STAKE_CACHE_MAX_ENTRIES
|
|
1354
1309
|
});
|
|
1355
1310
|
_updateMutex = new Mutex3();
|
|
@@ -1371,7 +1326,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1371
1326
|
});
|
|
1372
1327
|
const head = await this.chainIterator.head();
|
|
1373
1328
|
if (isUndefined3(head)) return;
|
|
1374
|
-
const headHash = await
|
|
1329
|
+
const headHash = await PayloadBuilder7.hash(head);
|
|
1375
1330
|
await this.recoverState(headHash);
|
|
1376
1331
|
}
|
|
1377
1332
|
async getDeclaredCandidateRanges(address, intent) {
|
|
@@ -1436,7 +1391,7 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1436
1391
|
}
|
|
1437
1392
|
async persistState(current) {
|
|
1438
1393
|
const state = this._producers.serialize();
|
|
1439
|
-
const payload = new
|
|
1394
|
+
const payload = new PayloadBuilder7({
|
|
1440
1395
|
schema: ChainIndexingServiceStateSchema
|
|
1441
1396
|
}).fields({
|
|
1442
1397
|
endBlockHash: current,
|
|
@@ -1488,8 +1443,11 @@ var XyoStakeIntentService = class extends BaseService {
|
|
|
1488
1443
|
return await this.spanAsync("updateIndex", async () => {
|
|
1489
1444
|
const currentHead = await this.chainIterator.head();
|
|
1490
1445
|
if (isUndefined3(currentHead)) return;
|
|
1491
|
-
const currentHeadHash = await
|
|
1492
|
-
const
|
|
1446
|
+
const currentHeadHash = await PayloadBuilder7.hash(currentHead);
|
|
1447
|
+
const chainMap = readPayloadMapFromStore3(this.chainArchivist);
|
|
1448
|
+
const result = await analyzeChain({
|
|
1449
|
+
chainMap
|
|
1450
|
+
}, [
|
|
1493
1451
|
new ChainStakeIntentAnalyzer("producer")
|
|
1494
1452
|
], currentHeadHash, this._lastIndexedBlockHash);
|
|
1495
1453
|
const signedDeclarations = filterAs3(result.find(isChainSummaryStakeIntent)?.intents ?? [], asChainStakeIntent2);
|
|
@@ -1541,8 +1499,8 @@ BaseStepStakeService = _ts_decorate13([
|
|
|
1541
1499
|
// src/Time/BaseTimeSyncService.ts
|
|
1542
1500
|
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
1543
1501
|
import { creatable as creatable14 } from "@xylabs/creatable";
|
|
1544
|
-
import { asHash
|
|
1545
|
-
import { PayloadBuilder as
|
|
1502
|
+
import { asHash } from "@xylabs/hex";
|
|
1503
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
1546
1504
|
import { asTimePayload, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
1547
1505
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
1548
1506
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1626,7 +1584,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1626
1584
|
const head = await this.chainIterator.head();
|
|
1627
1585
|
return [
|
|
1628
1586
|
head.block,
|
|
1629
|
-
await
|
|
1587
|
+
await PayloadBuilder8.hash(head)
|
|
1630
1588
|
];
|
|
1631
1589
|
}
|
|
1632
1590
|
case "epoch": {
|
|
@@ -1639,7 +1597,7 @@ var BaseTimeSyncService = class extends BaseService {
|
|
|
1639
1597
|
const provider = assertEx11(this.ethProvider, () => "Ethereum provider not configured");
|
|
1640
1598
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
1641
1599
|
const block = await provider.getBlock(blockNumber);
|
|
1642
|
-
const blockHash =
|
|
1600
|
+
const blockHash = asHash(assertEx11(block?.hash, () => "Block hash not found"), true);
|
|
1643
1601
|
return [
|
|
1644
1602
|
blockNumber,
|
|
1645
1603
|
blockHash
|
|
@@ -1679,8 +1637,8 @@ export {
|
|
|
1679
1637
|
XYO_PRODUCER_REDECLARATION_WINDOW,
|
|
1680
1638
|
XyoStakeIntentService,
|
|
1681
1639
|
XyoValidator,
|
|
1682
|
-
|
|
1683
|
-
|
|
1640
|
+
accountBalancesServiceFromArchivist,
|
|
1641
|
+
accountTransfersServiceFromArchivist,
|
|
1684
1642
|
creatableService,
|
|
1685
1643
|
getBlockSignedStakeDeclarations
|
|
1686
1644
|
};
|