Welcome to your new PANORAMA BLOCK project and to the Internet Computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.
To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.
To learn more before you start working with icp-bitcoin-ai, see the following documentation available online:
If you want to start working on your project right away, you might want to try the following commands:
cd icp-bitcoin-ai/
dfx help
dfx canister --help
# Starts the replica, running in the background
dfx start --background
# Deploys your canisters to the replica and generates your candid interface
dfx deploy
If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:
- Set
DFX_NETWORK
toic
if you are using Webpack - Use your own preferred method to replace
process.env.DFX_NETWORK
in the autogenerated declarations - Setting
canisters -> {asset_canister_id} -> declarations -> env_override
to a string indfx.json
will replaceprocess.env.DFX_NETWORK
with the string in the autogenerated declarations
This application aims to collect data from the Bitcoin blockchain and store it on the ICP (Internet Computer Protocol) blockchain. The application consists of two main canisters: the backend canister, responsible for making requests and processing data, and the frontend canister, responsible for displaying the collected data to users.
Backend Canister:
- Makes HTTP requests to the Mempool.space API to obtain information about blocks and transactions from the Bitcoin blockchain.
- Transforms and processes the received data before storing it on the ICP blockchain.
- Has functions to set the current block hash, fetch information about blocks and transactions, and get address information.
Frontend Canister:
- User interface that allows viewing the information collected by the backend canister.
- Displays details about the latest blocks and transactions, as shown in the provided image.
Communication between the canisters is done through asynchronous function calls. The frontend canister calls functions from the backend canister to retrieve the necessary data and display it to users.
-
transform(raw: Types.TransformArgs): async Types.CanisterHttpResponsePayload
- Functionality: This function transforms the received HTTP response by adjusting the security headers. Adds headers such as Content-Security-Policy, Referrer-Policy, Permissions-Policy, Strict-Transport-Security, X-Frame-Options, and X-Content-Type-Options.
- Return: Returns a
Types.CanisterHttpResponsePayload
object that includes the status, body, and headers of the response.
-
set_block_hash(block_hash: Text): async Errors.Result<Text, Errors.MempoolError>
- Functionality: Sets the current block hash to be used in subsequent requests.
- Return: Returns a result indicating success or error. On success, returns the message "Block hash set successfully".
-
get_bitcoin_block_info(): async Errors.Result<Types.BitcoinBlock, Errors.MempoolError>
- Functionality: Retrieves information about the current block using the previously set hash. Makes an HTTP request to the Mempool.space API to fetch block data.
- Return: Returns a
Types.BitcoinBlock
object with the following information:{ "id": "00000000000000000007566f8f035a1dc38b351e6f54778b311fe6dbabd79b46", "height": 736941, "version": 536870916, "timestamp": 1652891466, "bits": 386466234, "nonce": 3514220842, "difficulty": 31251101365711.12, "merkle_root": "4a3072f98f60cbb639bb7f46180b8843d17c7502627ffb633db0ed86610cdd71", "tx_count": 2381, "size": 1709571, "weight": 3997770, "previousblockhash": "00000000000000000005ef14db0b4befcbbe1e9b8676eec67fcf810a899c4d5e" }
-
fetch_bitcoin_blocks(count: Nat): async Errors.Result<[Types.BitcoinBlock], Errors.MempoolError>
- Functionality: Fetches information about multiple blocks starting from the current block, going back in the chain for the specified number of blocks.
- Return: Returns a list of
Types.BitcoinBlock
objects with detailed block information.
-
get_bitcoin_block_transactions(): async Errors.Result<Types.Transactions, Errors.MempoolError>
- Functionality: Retrieves the IDs of the transactions included in the current block. Makes an HTTP request to the Mempool.space API to fetch the transaction IDs.
- Return: Returns a
Types.Transactions
object containing a list of transaction IDs.
-
get_bitcoin_transaction_info(txid: Text): async Errors.Result<?Text, Errors.MempoolError>
- Functionality: Retrieves detailed information about a specific transaction using its ID. Makes an HTTP request to the Mempool.space API to fetch the transaction data.
- Return: Returns a
Text
object with the transaction information in the following format:{ "txid": "15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521", "version": 1, "locktime": 0, "vin": [], "vout": [], "size": 884, "weight": 3536, "fee": 20000, "status": { "confirmed": true, "block_height": 363348, "block_hash": "0000000000000000139385d7aa78ffb45469e0c715b8d6ea6cb2ffa98acc7171", "block_time": 1435754650 } }
-
fetch_transactions(): async Errors.Result<[?Text], Errors.MempoolError>
- Functionality: Retrieves detailed information about all transactions included in the current block. Iterates over the transaction IDs and makes HTTP requests to fetch details of each.
- Return: Returns a list of
Text
objects containing the transaction details.
-
get_address_info(address: Text): async Errors.Result<Types.AddressInfo, Errors.MempoolError>
- Functionality: Retrieves information about a specific address on the Bitcoin blockchain. Makes an HTTP request to the Mempool.space API to fetch the address data.
- Return: Returns a
Types.AddressInfo
object with the following information:{ "address": "1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv", "chain_stats": { "funded_txo_count": 5, "funded_txo_sum": 15007599040, "spent_txo_count": 5, "spent_txo_sum": 15007599040, "tx_count": 7 }, "mempool_stats": { "funded_txo_count": 0, "funded_txo_sum": 0, "spent_txo_count": 0, "spent_txo_sum": 0, "tx_count": 0 } }
The application returns various information about the Bitcoin blockchain, including:
- Block details such as hash, timestamp, and previous block hash.
- Transaction IDs included in a specific block.
- Detailed information about specific transactions, such as inputs and outputs.
- Address information, such as balance and transaction history.
The application frontend, as shown in the provided image, displays the following information:
- Details of the latest processed blocks, including hash and timestamp.
- Graphs and tables showing the number of transactions in the last 100 blocks.
- General information about the Bitcoin network, such as total number of transactions, active addresses, and total transaction value.
This documentation provides a detailed view of the on-chain data collection application from the Bitcoin blockchain to the ICP blockchain. The combination of backend and frontend canisters provides a robust interface for efficiently monitoring and analyzing Bitcoin blockchain data.