wallet-toolbox-examples

Janitor Example: BSV Wallet Toolbox API Documentation

The documentation is split into various pages, this page covers the janitorial function of verifying your wallet’s unspent change outputs.

Each BRC-100 wallet manages a ‘default’ basket of outputs to be used to fund new transaction and into which excess funding is returned.

We continue to work to make it impossible to lose track of valid transaction outputs, but this example may help if you find transactions failing due to invalid (unspendable) outputs in your change basket. This may happen while developing a new application and experimenting with createAction.

Return To Top

API

Links: API, Interfaces, Functions

Interfaces

Functions

 
janitor
janitorOnIdentity
release
releaseMain1
releaseMain2
releaseOnIdentity
releaseTest1
releaseTest2

Links: API, Interfaces, Functions


Function: janitor

Run this function using the following command:

npx tsx janitor
export async function janitor(): Promise<void> {
    for (const env of [Setup.getEnv("test"), Setup.getEnv("main")]) {
        for (const identityKey of [env.identityKey, env.identityKey2]) {
            if (!identityKey)
                continue;
            await janitorOnIdentity(identityKey, env.chain);
        }
    }
}

See also: janitorOnIdentity

Links: API, Interfaces, Functions


Function: janitorOnIdentity

Uses a special operation mode of the listOutputs function to list all the invalid change outputs.

Note that if any un-spendable outputs are found, they can be “released” by running the release function.

export async function janitorOnIdentity(identityKey: string, chain: sdk.Chain): Promise<void> {
    const env = Setup.getEnv(chain);
    const setup = await Setup.createWalletClient({
        env,
        rootKeyHex: env.devKeys[identityKey]
    });
    const change = await setup.wallet.listOutputs({ basket: specOpInvalidChange });
    console.log(`

Janitor list invalid change outputs for:
.env ${env.chain} ${identityKey} ${setup.storage.getActiveStoreName()}
`);
    if (change.totalOutputs === 0) {
        console.log("no invalid change outputs found.");
    }
    else {
        if (!setup.storage.isActiveEnabled) {
            console.log("ACTIVE STORAGE IS NOT ENABLED! Wallet is not configured with currently active storage provider!");
        }
        console.log("  satoshis |  vout | txid");
        console.log("-----------|-------|--------------------------------------------");
        for (const o of change.outputs) {
            const { txid, vout } = parseWalletOutpoint(o.outpoint);
            console.log(`${ar(o.satoshis, 10)} | ${ar(vout, 5)} | ${txid}`);
        }
    }
}

See also: ar

Argument Details

Links: API, Interfaces, Functions


Function: release

Releases all invalid change outputs for wallets in the .env file: ‘identityKey’ and ‘identityKey2’ values for both ‘test’ and ‘main’ chains.

Run this function using the following command:

npx tsx janitor release
export async function release(): Promise<void> {
    for (const env of [Setup.getEnv("test"), Setup.getEnv("main")]) {
        for (const identityKey of [env.identityKey, env.identityKey2]) {
            if (!identityKey)
                continue;
            await releaseOnIdentity(identityKey, env.chain);
        }
    }
}

See also: releaseOnIdentity

Links: API, Interfaces, Functions


Function: releaseMain1

Releases all invalid change outputs for the .env ‘main’, ‘identityKey’ wallet.

Run this function using the following command:

npx tsx janitor releaseMain1
export async function releaseMain1(): Promise<void> {
    const env = Setup.getEnv("main");
    releaseOnIdentity(env.identityKey, env.chain);
}

See also: releaseOnIdentity

Links: API, Interfaces, Functions


Function: releaseMain2

Releases all invalid change outputs for the .env ‘main’, ‘identityKey2’ wallet.

Run this function using the following command:

npx tsx janitor releaseMain2
export async function releaseMain2(): Promise<void> {
    const env = Setup.getEnv("main");
    releaseOnIdentity(env.identityKey2, env.chain);
}

See also: releaseOnIdentity

Links: API, Interfaces, Functions


Function: releaseOnIdentity
export async function releaseOnIdentity(identityKey: string, chain: sdk.Chain): Promise<void> 

Links: API, Interfaces, Functions


Function: releaseTest1

Releases all invalid change outputs for the .env ‘test’, ‘identityKey’ wallet.

Run this function using the following command:

npx tsx janitor releaseTest1
export async function releaseTest1(): Promise<void> {
    const env = Setup.getEnv("test");
    releaseOnIdentity(env.identityKey, env.chain);
}

See also: releaseOnIdentity

Links: API, Interfaces, Functions


Function: releaseTest2

Releases all invalid change outputs for the .env ‘test’, ‘identityKey2’ wallet.

Run this function using the following command:

npx tsx janitor releaseTest2
export async function releaseTest2(): Promise<void> {
    const env = Setup.getEnv("test");
    releaseOnIdentity(env.identityKey2, env.chain);
}

See also: releaseOnIdentity

Links: API, Interfaces, Functions