Skip to content

Commit

Permalink
Add support for "Regtest" BTC network (#713)
Browse files Browse the repository at this point in the history
# Motivation

We want to use Regtest for local development in Oisy, but at the moment,
this network is not supported in the `BitcoinNetwork`.

# Changes

* Add `"regtest"` as supported BitcoinNetwork and change the mapper to
support the new value.

# Tests

No new functionality.

# Todos

- [ ] Add entry to changelog (if necessary).

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
lmuntaner and github-actions[bot] authored Sep 6, 2024
1 parent 90d1109 commit a5c26b3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Features

- Add support for `icrc21_canister_call_consent_message` to `@dfinity/ledger-icp` and `@dfinity/ledger-icrc`.
- Add support for `"regtest"` in `BitcoinNetwork`.

# 2024.09.02-0830Z

Expand Down
4 changes: 2 additions & 2 deletions packages/ckbtc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Parameters:

##### :gear: getUtxosQuery

Given a `get_utxos_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet` or `testnet`), the function returns all unspent transaction outputs (UTXOs) associated with the provided address in the specified Bitcoin network based on the current view of the Bitcoin blockchain available to the Bitcoin component.
Given a `get_utxos_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet`, `testnet` or `regtest`), the function returns all unspent transaction outputs (UTXOs) associated with the provided address in the specified Bitcoin network based on the current view of the Bitcoin blockchain available to the Bitcoin component.

⚠️ Note that this method does not support certified calls because only canisters are allowed to get UTXOs via update calls.

Expand All @@ -312,7 +312,7 @@ Parameters:

##### :gear: getBalanceQuery

Given a `get_balance_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet` or `testnet`), the function returns the current balance of this address in `Satoshi` (10^8 Satoshi = 1 Bitcoin) in the specified Bitcoin network.
Given a `get_balance_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet`, `testnet` or `regtest`), the function returns the current balance of this address in `Satoshi` (10^8 Satoshi = 1 Bitcoin) in the specified Bitcoin network.

⚠️ Note that this method does not support certified calls because only canisters are allowed to get Bitcoin balance via update calls.

Expand Down
4 changes: 2 additions & 2 deletions packages/ckbtc/src/bitcoin.canister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BitcoinCanister extends Canister<BitcoinService> {
}

/**
* Given a `get_utxos_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet` or `testnet`), the function returns all unspent transaction outputs (UTXOs) associated with the provided address in the specified Bitcoin network based on the current view of the Bitcoin blockchain available to the Bitcoin component.
* Given a `get_utxos_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet`, `testnet` or `regtest`), the function returns all unspent transaction outputs (UTXOs) associated with the provided address in the specified Bitcoin network based on the current view of the Bitcoin blockchain available to the Bitcoin component.
*
* ⚠️ Note that this method does not support certified calls because only canisters are allowed to get UTXOs via update calls.
*
Expand All @@ -49,7 +49,7 @@ export class BitcoinCanister extends Canister<BitcoinService> {
};

/**
* Given a `get_balance_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet` or `testnet`), the function returns the current balance of this address in `Satoshi` (10^8 Satoshi = 1 Bitcoin) in the specified Bitcoin network.
* Given a `get_balance_request`, which must specify a Bitcoin address and a Bitcoin network (`mainnet`, `testnet` or `regtest`), the function returns the current balance of this address in `Satoshi` (10^8 Satoshi = 1 Bitcoin) in the specified Bitcoin network.
*
* ⚠️ Note that this method does not support certified calls because only canisters are allowed to get Bitcoin balance via update calls.
*
Expand Down
11 changes: 7 additions & 4 deletions packages/ckbtc/src/types/bitcoin.params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import type {
network,
} from "../../candid/bitcoin";

export type BitcoinNetwork = "testnet" | "mainnet";
export type BitcoinNetwork = "testnet" | "mainnet" | "regtest";

const mapBitcoinNetwork = (network: BitcoinNetwork): network =>
network === "testnet" ? { testnet: null } : { mainnet: null };
const mapBitcoinNetwork: Record<BitcoinNetwork, network> = {
mainnet: { mainnet: null },
testnet: { testnet: null },
regtest: { regtest: null },
};

export type GetUtxosParams = Omit<get_utxos_request, "network" | "filter"> & {
network: BitcoinNetwork;
Expand Down Expand Up @@ -45,6 +48,6 @@ export const toGetBalanceParams = ({
...rest
}: GetBalanceParams): get_balance_request => ({
min_confirmations: toNullable(minConfirmations),
network: mapBitcoinNetwork(network),
network: mapBitcoinNetwork[network],
...rest,
});

0 comments on commit a5c26b3

Please sign in to comment.