From a5c26b332affa85df407e2b9b87b4fff7e0cefe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7=20Muntaner?= Date: Fri, 6 Sep 2024 15:49:43 +0200 Subject: [PATCH] Add support for "Regtest" BTC network (#713) # 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> --- CHANGELOG.md | 1 + packages/ckbtc/README.md | 4 ++-- packages/ckbtc/src/bitcoin.canister.ts | 4 ++-- packages/ckbtc/src/types/bitcoin.params.ts | 11 +++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79bb0361..08738727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/ckbtc/README.md b/packages/ckbtc/README.md index 8f66cb77..55c3f32c 100644 --- a/packages/ckbtc/README.md +++ b/packages/ckbtc/README.md @@ -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. @@ -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. diff --git a/packages/ckbtc/src/bitcoin.canister.ts b/packages/ckbtc/src/bitcoin.canister.ts index d39fa520..a4b4a070 100644 --- a/packages/ckbtc/src/bitcoin.canister.ts +++ b/packages/ckbtc/src/bitcoin.canister.ts @@ -27,7 +27,7 @@ export class BitcoinCanister extends Canister { } /** - * 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. * @@ -49,7 +49,7 @@ export class BitcoinCanister extends Canister { }; /** - * 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. * diff --git a/packages/ckbtc/src/types/bitcoin.params.ts b/packages/ckbtc/src/types/bitcoin.params.ts index 0754f53f..d0bce91e 100644 --- a/packages/ckbtc/src/types/bitcoin.params.ts +++ b/packages/ckbtc/src/types/bitcoin.params.ts @@ -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 = { + mainnet: { mainnet: null }, + testnet: { testnet: null }, + regtest: { regtest: null }, +}; export type GetUtxosParams = Omit & { network: BitcoinNetwork; @@ -45,6 +48,6 @@ export const toGetBalanceParams = ({ ...rest }: GetBalanceParams): get_balance_request => ({ min_confirmations: toNullable(minConfirmations), - network: mapBitcoinNetwork(network), + network: mapBitcoinNetwork[network], ...rest, });