Build Considerations

Estimating feeRate of Transaction:

Estimating the feeRate of transactions is a critical aspect of ensuring efficient and timely processing on the Bitcoin network. In Ordibank, this is theoretically addressed by utilizing relevant libraries and APIs to dynamically calculate the optimal feeRate based on network congestion:

codeimport { bitcoinLib, networkAPI } from 'ordibank-lib';

async function estimateTransactionFeeRate(): Promise<number> {
  const recommendedFeeRate = await networkAPI.getRecommendedFeeRate();
  return recommendedFeeRate;
}

Checking Exceptional Cases:

Handling exceptional cases is essential for robust error management. Ordibank employs TypeScript to implement custom error classes and thorough conditional checks to handle exceptional scenarios, ensuring clear and actionable error messages:

codeclass OrdibankError extends Error {}

function processTransaction(data: any): void {
  if (!data) {
    throw new OrdibankError('Invalid transaction data.');
  }

}

Decimal and Total Supply for BRC20:

Decimal and total supply management for BRC20 tokens in Ordibank is meticulously handled:

codeinterface BRC20Token {
  decimals: number;
  totalSupply: number;
}

function calculateTotalSupply(token: BRC20Token): number {
  const totalSupplyWithDecimals = token.totalSupply * Math.pow(10, token.decimals);
  return totalSupplyWithDecimals;
}

Handling PSBT on Ord Wallet :

As noted, handling PSBT on the Ord wallet is not necessary. However, if required in the future, Ordibank's architecture allows seamless integration with Bitcoin libraries for PSBT handling:


const unsignedPSBT = psbtLib.createUnsignedPSBT();

Getting BRC20 Token Price:

To fetch the BRC20 token price, Ordibank utilizes external APIs oracles. We make asynchronous calls to these APIs and process the returned data:

codeimport { oracleAPI } from 'ordibank-lib';

async function getBRC20TokenPrice(tokenAddress: string): Promise<number> {
  const price = await oracleAPI.fetchTokenPrice(tokenAddress);
  return price;
}

Getting Several API Keys of Unisat Service:

Fetching several API keys from the Unisat service is handled securely. An example demonstrates how API keys can be stored and retrieved:

codeconst unisatAPIKeys: string[] = ['key1', 'key2', 'key3'];

function getUnisatAPIKey(index: number): string {
  return unisatAPIKeys[index];
}

Checking PSBT Input and Output Before Signing with Vault (Implemented):

Checking PSBT input and output before signing with the vault is crucial for security. Ordibank enables thorough verification, as shown in the code snippet below:

{ vaultLib } from 'ordibank-lib';

function validatePSBTInputOutput(psbt: any): boolean {
  const isValid = vaultLib.validatePSBTInputOutput(psbt);
  return isValid;
}

Getting Inscriptionโ€™s Sats Correctly:

Accurate retrieval of inscription's sats is vital for proper functionality. Ordibank ensures precision in handling sats, as illustrated below:

 { inscriptionLib } from 'ordibank-lib';

function getInscriptionSats(inscription: any): number {
  const sats = inscriptionLib.extractSats(inscription);
  return sats;
}

Removing Iterating Idx from All For Closure (Implemented):

In Ordibank, the iteration index issue is addressed by leveraging modern constructs like forEach and arrow functions, which eliminate the need for index iteration:

codeconst array = [null];

for (let i = 0; i < array.length; i++) {
}

array.forEach((item) => {

});

Adding Function Name to Exceptional Log:

Logging function names in exceptional scenarios enhances debugging. Ordibank provides clear and maintainable solutions:

  codefunction performOperation() {

try {

  } catch (error) {
    console.error(`Error in performOperation: ${error.message}`);
  }
}

Adding Type to All Variables of Backend:

Ordibank ensures strong typing for backend variables, promoting code reliability and readability. An example of enforcing types:

 codeinterface User {
  id: number;
  name: string;
}

function processUserData(user: User): void {

}

Logging to File:

Logging to files in Ordibank is achieved through file system libraries. Below is a basic example:

 codeimport * as fs from 'fs';

function logToFile(message: string): void {
  fs.appendFileSync('log.txt', `${new Date().toISOString()}: ${message}\n`);
}

Backend Problems - BlockNumber Issue:

The blockNumber issue related to the Bitcoin network is addressed in Ordibank by using Bitcoin libraries to fetch the latest block number. Here's a simplified example:

 codeimport { bitcoinLib } from 'ordibank-lib';

async function getLatestBlockNumber(): Promise<number> {
  const latestBlockNumber = await bitcoinLib.fetchLatestBlockNumber();
  return latestBlockNumber;
}

Last updated