Skip to content

Support BlockRef alongside ChainPoint in SDK helper methods #53

@yHSJ

Description

@yHSJ

More flexible block identification was added in utxorpc/spec#154, allowing BlockRef to use any combination of slot, hash, height, and timestamp. This isn't made accessible to end users though, since the SDK helper methods (followTip, fetchBlock, fetchHistory, etc.) still only accept ChainPoint.

I would propose having these methods accept some union type of sync.BlockRef (or watch.BlockRef, I think they're the same) and ChainPoint, something like:

type BlockRefLike = ChainPoint | sync.BlockRef;

function blockRefLikeToBlockRef(p: BlockRefLike) {
  if (p instanceof sync.BlockRef) return p;

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

async *followTip(intersect?: BlockRefLike[]): AsyncIterable<TipEvent> { ... }

This change would maintain backwards compatibility, if that's important here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions