Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@connectrpc/connect": "1.4",
"@connectrpc/connect-node": "1.4",
"@connectrpc/connect-web": "1.4",
"@utxorpc/spec": "0.16.0",
"@utxorpc/spec": "0.17.0",
"buffer": "^6.0.3"
},
"exports": {
Expand Down
26 changes: 23 additions & 3 deletions src/cardano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ function anyChainToBlock(msg: sync.AnyChainBlock) {

function pointToBlockRef(p: ChainPoint) {
return new sync.BlockRef({
index: BigInt(p.slot),
slot: BigInt(p.slot),
hash: new Uint8Array(Buffer.from(p.hash, "hex")),
});
}

function blockRefToPoint(r: sync.BlockRef) {
return {
slot: r.index.toString(),
slot: r.slot.toString(),
hash: Buffer.from(r.hash).toString("hex"),
};
}
Expand Down Expand Up @@ -155,7 +155,7 @@ export class SyncClient {
async fetchHistory(p: ChainPoint | undefined, maxItems = 1): Promise<cardano.Block> {
const req = new sync.DumpHistoryRequest({
startToken: p ? new sync.BlockRef({
index: BigInt(p.slot),
slot: BigInt(p.slot),
hash: Buffer.from(p.hash, "hex"),
}) : undefined,
maxItems: maxItems,
Expand Down Expand Up @@ -293,6 +293,26 @@ export class QueryClient {
asset: (policyId && name) ? { policyId: policyId, assetName: name } : policyId ? { policyId } : { assetName: name },
});
}

async readGenesis(): Promise<cardano.Genesis> {
const res = await this.inner.readGenesis({});

if (!res.config || res.config.case !== "cardano") {
throw new Error("Genesis config is not Cardano data");
}

return res.config.value;
}

async readErasummary(): Promise<cardano.EraSummary[]> {
const res = await this.inner.readEraSummary({});

if (!res.summary || res.summary.case !== "cardano") {
throw new Error("Era summary is not Cardano data");
}

return res.summary.value.summaries;
}
}

export class SubmitClient {
Expand Down