@xyo-network/xl1-rpc 1.2.4 → 1.2.6
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/browser/index.mjs +4 -147
- package/dist/browser/index.mjs.map +1 -1
- package/dist/neutral/index.mjs +4 -147
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index.mjs +4 -147
- package/dist/node/index.mjs.map +1 -1
- package/dist/types/provider/runner/MemoryXyoRunner.d.ts.map +1 -1
- package/dist/types/provider/runner/NodeXyoRunner.d.ts.map +1 -1
- package/dist/types/provider/viewer/index.d.ts +0 -1
- package/dist/types/provider/viewer/index.d.ts.map +1 -1
- package/knip.config.ts +15 -0
- package/package.json +10 -8
- package/src/provider/runner/MemoryXyoRunner.ts +1 -1
- package/src/provider/runner/NodeXyoRunner.ts +1 -1
- package/src/provider/viewer/index.ts +0 -1
- package/dist/types/provider/viewer/NodeXyoViewer.d.ts +0 -68
- package/dist/types/provider/viewer/NodeXyoViewer.d.ts.map +0 -1
- package/src/provider/viewer/NodeXyoViewer.ts +0 -168
package/dist/browser/index.mjs
CHANGED
|
@@ -749,8 +749,8 @@ var JsonRpcXyoRunner = class {
|
|
|
749
749
|
|
|
750
750
|
// src/provider/runner/MemoryXyoRunner.ts
|
|
751
751
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
752
|
-
import { flattenHydratedTransaction } from "@xyo-network/chain-protocol";
|
|
753
752
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
753
|
+
import { flattenHydratedTransaction } from "@xyo-network/xl1-protocol";
|
|
754
754
|
var MemoryXyoRunner = class {
|
|
755
755
|
static {
|
|
756
756
|
__name(this, "MemoryXyoRunner");
|
|
@@ -774,8 +774,8 @@ var MemoryXyoRunner = class {
|
|
|
774
774
|
// src/provider/runner/NodeXyoRunner.ts
|
|
775
775
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
776
776
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
777
|
-
import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/chain-protocol";
|
|
778
777
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
778
|
+
import { flattenHydratedTransaction as flattenHydratedTransaction2 } from "@xyo-network/xl1-protocol";
|
|
779
779
|
var NodeXyoRunner = class {
|
|
780
780
|
static {
|
|
781
781
|
__name(this, "NodeXyoRunner");
|
|
@@ -911,148 +911,6 @@ var JsonRpcXyoViewer = class {
|
|
|
911
911
|
}
|
|
912
912
|
};
|
|
913
913
|
|
|
914
|
-
// src/provider/viewer/NodeXyoViewer.ts
|
|
915
|
-
import { filterAs } from "@xylabs/array";
|
|
916
|
-
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
917
|
-
import { exists } from "@xylabs/exists";
|
|
918
|
-
import { hexToBigInt as hexToBigInt2 } from "@xylabs/hex";
|
|
919
|
-
import { asArchivistInstance as asArchivistInstance2 } from "@xyo-network/archivist-model";
|
|
920
|
-
import { BoundWitnessSchema as BoundWitnessSchema2 } from "@xyo-network/boundwitness-model";
|
|
921
|
-
import { analyzeChain, BalanceAnalyzer, findMostRecentBlock, hydrateBlock, hydrateTransaction, isChainSummaryBalances } from "@xyo-network/chain-protocol";
|
|
922
|
-
import { asDivinerInstance } from "@xyo-network/diviner-model";
|
|
923
|
-
import { asOptionalBlockBoundWitnessWithStorageMeta, asOptionalTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-model";
|
|
924
|
-
var WindowLimit = 1e3;
|
|
925
|
-
var WindowLimitBigInt = BigInt(WindowLimit);
|
|
926
|
-
var NodeXyoViewer = class {
|
|
927
|
-
static {
|
|
928
|
-
__name(this, "NodeXyoViewer");
|
|
929
|
-
}
|
|
930
|
-
// TODO: Make configurable with defaults
|
|
931
|
-
finalizedArchivistPath = "XYOChain:Chain:Finalized";
|
|
932
|
-
headValidationDivinerPath = "XYOChain:Chain:HeadValidationDiviner";
|
|
933
|
-
node;
|
|
934
|
-
_chainId;
|
|
935
|
-
_finalizedArchivist;
|
|
936
|
-
constructor(node) {
|
|
937
|
-
this.node = node;
|
|
938
|
-
}
|
|
939
|
-
async accountBalance(address, blockNumber, full) {
|
|
940
|
-
const head = await this.blockByNumber(blockNumber);
|
|
941
|
-
if (!head) {
|
|
942
|
-
throw new Error(`Error: Could not find block ${blockNumber}`);
|
|
943
|
-
}
|
|
944
|
-
const analysis = await analyzeChain(await this.getFinalizedArchivist(), [
|
|
945
|
-
new BalanceAnalyzer()
|
|
946
|
-
], head, null, full ? -1n : WindowLimitBigInt);
|
|
947
|
-
const balances = assertEx3(analysis.find(isChainSummaryBalances)?.balances, () => "Failed to sync balances");
|
|
948
|
-
return balances[address] ? hexToBigInt2(balances[address]) : 0n;
|
|
949
|
-
}
|
|
950
|
-
async blockByHash(hash) {
|
|
951
|
-
const finalizedArchivist = await this.getFinalizedArchivist();
|
|
952
|
-
return await hydrateBlock(finalizedArchivist, hash);
|
|
953
|
-
}
|
|
954
|
-
async blockByNumber(blockNumber) {
|
|
955
|
-
const finalizedArchivist = await this.getFinalizedArchivist();
|
|
956
|
-
const result = await this.currentBlock();
|
|
957
|
-
let currentBlock = result[0];
|
|
958
|
-
if (currentBlock.block === blockNumber) return result;
|
|
959
|
-
if (blockNumber > currentBlock.block) throw new Error(`Error: Block number ${blockNumber} is greater than current block number ${currentBlock.block}`);
|
|
960
|
-
if (blockNumber < 0) throw new Error(`Error: Block number ${blockNumber} is less than 0`);
|
|
961
|
-
if (blockNumber - currentBlock.block > WindowLimit) throw new Error(`Error: Block number ${blockNumber} is too far in the past`);
|
|
962
|
-
do {
|
|
963
|
-
const { previous } = currentBlock;
|
|
964
|
-
if (previous === null) return null;
|
|
965
|
-
const nextBlock = asOptionalBlockBoundWitnessWithStorageMeta((await finalizedArchivist.get([
|
|
966
|
-
previous
|
|
967
|
-
]))[0]);
|
|
968
|
-
if (!nextBlock) return null;
|
|
969
|
-
currentBlock = nextBlock;
|
|
970
|
-
} while (blockNumber != currentBlock.block);
|
|
971
|
-
return currentBlock.block === blockNumber ? await hydrateBlock(finalizedArchivist, currentBlock._hash) : null;
|
|
972
|
-
}
|
|
973
|
-
async blocksByHash(hash, limit = 10) {
|
|
974
|
-
assertEx3(limit > 0, () => "Error: limit must be greater than 0");
|
|
975
|
-
assertEx3(limit <= 100, () => "Error: limit must be less than 100");
|
|
976
|
-
const blocks = [];
|
|
977
|
-
let current = await this.blockByHash(hash);
|
|
978
|
-
while (current && blocks.length < limit) {
|
|
979
|
-
blocks.push(current);
|
|
980
|
-
const previousHash = current[0].previous;
|
|
981
|
-
if (!previousHash) break;
|
|
982
|
-
current = await this.blockByHash(previousHash);
|
|
983
|
-
}
|
|
984
|
-
return blocks;
|
|
985
|
-
}
|
|
986
|
-
async chainId() {
|
|
987
|
-
if (this._chainId) return this._chainId;
|
|
988
|
-
const finalizedArchivist = await this.getFinalizedArchivist();
|
|
989
|
-
const block = await findMostRecentBlock(finalizedArchivist);
|
|
990
|
-
if (!block) throw new Error("Error: Could not find most recent block");
|
|
991
|
-
this._chainId = block.chain;
|
|
992
|
-
return await Promise.resolve(this._chainId);
|
|
993
|
-
}
|
|
994
|
-
async currentBlock() {
|
|
995
|
-
const finalizedArchivist = await this.getFinalizedArchivist();
|
|
996
|
-
return await hydrateBlock(finalizedArchivist, await this.currentBlockHash());
|
|
997
|
-
}
|
|
998
|
-
async currentBlockHash() {
|
|
999
|
-
const finalizedArchivist = await this.getFinalizedArchivist();
|
|
1000
|
-
const block = assertEx3(await findMostRecentBlock(finalizedArchivist), () => "Error: Could not find most recent block");
|
|
1001
|
-
return block._hash;
|
|
1002
|
-
}
|
|
1003
|
-
async currentBlockNumber() {
|
|
1004
|
-
const finalizedArchivist = await this.getFinalizedArchivist();
|
|
1005
|
-
const block = assertEx3(await findMostRecentBlock(finalizedArchivist), () => "Error: Could not find most recent block");
|
|
1006
|
-
return block.block;
|
|
1007
|
-
}
|
|
1008
|
-
async transactionByBlockHashAndIndex(blockHash, transactionIndex = 0) {
|
|
1009
|
-
assertEx3(transactionIndex >= 0, () => "Error: transactionIndex must be greater than or equal to 0");
|
|
1010
|
-
try {
|
|
1011
|
-
const block = await this.blockByHash(blockHash);
|
|
1012
|
-
if (!block) return null;
|
|
1013
|
-
const blockBoundWitnessIndexes = block[0].payload_schemas.map((schema, index) => schema === BoundWitnessSchema2 ? index : void 0).filter(exists);
|
|
1014
|
-
const blockBoundWitnessHashes = new Set(blockBoundWitnessIndexes.map((index) => block[0].payload_hashes[index]));
|
|
1015
|
-
const blockBoundWitnesses = block[1].filter((payload) => blockBoundWitnessHashes.has(payload._hash) || blockBoundWitnessHashes.has(payload._dataHash));
|
|
1016
|
-
const blockTransactionBoundWitnesses = filterAs(blockBoundWitnesses, asOptionalTransactionBoundWitnessWithStorageMeta);
|
|
1017
|
-
const transaction = blockTransactionBoundWitnesses.at(transactionIndex);
|
|
1018
|
-
if (!transaction) return null;
|
|
1019
|
-
return await this.transactionByHash(transaction._hash);
|
|
1020
|
-
} catch {
|
|
1021
|
-
return null;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
async transactionByBlockNumberAndIndex(blockNumber, transactionIndex = 0) {
|
|
1025
|
-
try {
|
|
1026
|
-
const block = await this.blockByNumber(blockNumber);
|
|
1027
|
-
if (!block) return null;
|
|
1028
|
-
return await this.transactionByBlockHashAndIndex(block[0]._hash, transactionIndex);
|
|
1029
|
-
} catch {
|
|
1030
|
-
return null;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
async transactionByHash(transactionHash) {
|
|
1034
|
-
try {
|
|
1035
|
-
const finalizedArchivist = await this.getFinalizedArchivist();
|
|
1036
|
-
return await hydrateTransaction(finalizedArchivist, transactionHash);
|
|
1037
|
-
} catch {
|
|
1038
|
-
return null;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
getArchivist = /* @__PURE__ */ __name(async (identifier) => {
|
|
1042
|
-
const diviner = await this.node.resolve(identifier);
|
|
1043
|
-
return assertEx3(asArchivistInstance2(diviner), () => `Error: Could not resolve ${identifier} to an archivist instance`);
|
|
1044
|
-
}, "getArchivist");
|
|
1045
|
-
getDiviner = /* @__PURE__ */ __name(async (identifier) => {
|
|
1046
|
-
const diviner = await this.node.resolve(identifier);
|
|
1047
|
-
return assertEx3(asDivinerInstance(diviner), () => `Error: Could not resolve ${identifier} to a diviner instance`);
|
|
1048
|
-
}, "getDiviner");
|
|
1049
|
-
getFinalizedArchivist = /* @__PURE__ */ __name(async () => {
|
|
1050
|
-
if (this._finalizedArchivist) return this._finalizedArchivist;
|
|
1051
|
-
this._finalizedArchivist = await this.getArchivist(this.finalizedArchivistPath);
|
|
1052
|
-
return this._finalizedArchivist;
|
|
1053
|
-
}, "getFinalizedArchivist");
|
|
1054
|
-
};
|
|
1055
|
-
|
|
1056
914
|
// src/provider/wallet/JsonRpcXyoWallet.ts
|
|
1057
915
|
var JsonRpcXyoWallet = class {
|
|
1058
916
|
static {
|
|
@@ -1098,7 +956,7 @@ var JsonRpcXyoWallet = class {
|
|
|
1098
956
|
};
|
|
1099
957
|
|
|
1100
958
|
// src/provider/wallet/MemoryXyoWallet.ts
|
|
1101
|
-
import { assertEx as
|
|
959
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
1102
960
|
var MemoryXyoWallet = class {
|
|
1103
961
|
static {
|
|
1104
962
|
__name(this, "MemoryXyoWallet");
|
|
@@ -1119,7 +977,7 @@ var MemoryXyoWallet = class {
|
|
|
1119
977
|
return this.chains();
|
|
1120
978
|
}
|
|
1121
979
|
chain() {
|
|
1122
|
-
return
|
|
980
|
+
return assertEx3(this._chain, () => "Chain not set");
|
|
1123
981
|
}
|
|
1124
982
|
chains() {
|
|
1125
983
|
return this._chains;
|
|
@@ -1228,7 +1086,6 @@ export {
|
|
|
1228
1086
|
MemoryXyoSigner,
|
|
1229
1087
|
MemoryXyoWallet,
|
|
1230
1088
|
NodeXyoRunner,
|
|
1231
|
-
NodeXyoViewer,
|
|
1232
1089
|
XyoProviderRpcSchemas,
|
|
1233
1090
|
XyoRunnerRpcSchemas,
|
|
1234
1091
|
XyoSignerRpcSchemas,
|