getAncestors
Returns the transactions id history of the given revision.
Type
getAncestors(location: string, verbosity?: number): Promise<string[] | Map<string, string>>
Return Value
Given a location (revision or transaction id), returns a promise that resolves to an array of transaction ids representing the history of the given revision. If verbosity is set to 1, it returns a map where the keys are transaction ids and the values are their corresponding transaction hex strings.
Syntax
computer.getAncestors(rev)
computer.getAncestors(rev, 1)
Example
import { Computer, Contract } from '@bitcoin-computer/lib'
import { chain, expect, network, url } from '../../utils/index.js'
describe('getAncestors', () => {
class Counter extends Contract {
n: number
constructor() {
super({ n: 0 })
}
inc() {
this.n += 1
}
}
it('Should return the ancestor transactions id of a given revision', async () => {
const computer = new Computer({ chain, network, url })
await computer.faucet(1e8)
const counter = await computer.new(Counter, [])
await counter.inc()
await counter.inc()
const ancestors = await computer.getAncestors(counter._rev)
expect(ancestors).to.be.an('array').that.has.lengthOf(3)
expect(ancestors).includes(counter._id.substring(0, 64))
expect(ancestors).includes(counter._rev.substring(0, 64))
expect(ancestors).includes((await computer.prev(counter._rev))!.substring(0, 64))
})
})