findPath

@twine-protocol/twine-core v0.1.0Docs


twine-js / @twine-protocol/twine-core / findPath

Function: findPath()

findPath(start, target, resolver): Promise<Path | null>

Find a path between two pulses

This function is a convenience function that uses the crawl function to find a path between two pulses. It will return a path if one is found, or null if no path is found.

Parameters

Parameter
Type
Description

start

The starting pulse, or a query for the starting pulse

target

The target pulse, or a query for the target pulse

resolver

The resolver to use for resolving pulses

Returns

Promise<Path | null>

  • A path if one is found, or null if no path is found

Example

import { findPath } from '@twine-protocol/twine-core'
import { HttpStore } from '@twine-protocol/twine-http-store'

const resolver = new HttpStore('https://someapi.io')
const start = { chain: 'chaincid', pulse: 'startpulsecid' }
const target = { chain: 'chaincid', pulse: 'targetpulsecid' }

const path = await findPath(start, target, resolver)
if (path) {
  console.log('Path found:', path)
} else {
  console.log('No path found')
}

Defined in

packages/twine-core/src/crawl.ts:357

Last updated