Skip to content

Commit 23038df

Browse files
committed
remove mege
added shell script changed config.example.json fixed code fixed bugs for chosen gas changed fee rate clean code change fee range step changed base gas changed create commands update wallet path bump docker shared memory to 1g updated create.command.ts 1. Enhance the create wallet command with optional settings for mnemonic and path_index updated docker-compose add the -reindex command to trigger a reindexing process when the full node encounters conflicts. Delete packages/cli/config.example.json Delete packages/cli/script.sh changed config.example.json Update config.example.json to default params Update config.example.json to default params feat: add `getOpenApiHost` method Fix: cli mint fail; tracker owner pkh Fix: cli mint too small remainingSupply add log update tips updated code 1. added scripts for the automated deployment environment. 2. added environment variables to .env to minimize changes to docker-compose.yaml. 3. modify the naming of some parameters. cp bitcoin.conf to bitcoin dir fix bugs for init_script.sh updated tracker configs updated: remove the reindex command in bitcoind removed init_cat20.sh
1 parent 8251506 commit 23038df

File tree

14 files changed

+223
-78
lines changed

14 files changed

+223
-78
lines changed

packages/cli/config.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
"username": "bitcoin",
99
"password": "opcatAwesome"
1010
}
11-
}
11+
}

packages/cli/src/commands/mint/mint.command.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ export class MintCommand extends BoardcastCommand {
125125

126126
const limit = scaledInfo.limit;
127127

128+
if (minter.state.data.remainingSupply < limit) {
129+
console.warn(
130+
`small limit of ${unScaleByDecimals(limit, token.info.decimals)} in the minter UTXO!`,
131+
);
132+
log(`retry to mint token [${token.info.symbol}] ...`);
133+
continue;
134+
}
135+
128136
if (!minter.state.data.isPremined && scaledInfo.premine > 0n) {
129137
if (typeof amount === 'bigint') {
130138
if (amount !== scaledInfo.premine) {

packages/cli/src/commands/wallet/create.command.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as bip39 from 'bip39';
88

99
interface CreateCommandOptions extends BaseCommandOptions {
1010
name: string;
11+
path_index: number;
12+
mnemonic: string;
1113
}
1214

1315
@SubCommand({
@@ -39,10 +41,18 @@ export class CreateCommand extends BaseCommand {
3941
? options.name
4042
: `cat-${randomBytes(4).toString('hex')}`;
4143

44+
const path_index = options.path_index
45+
? options.path_index
46+
: 0;
47+
48+
const mnemonic = options.mnemonic
49+
? options.mnemonic
50+
: bip39.generateMnemonic();
51+
4252
const wallet: Wallet = {
43-
accountPath: "m/44'/0'/0'/0/0",
53+
accountPath: `m/86'/0'/0'/0/${path_index}`,
4454
name: name,
45-
mnemonic: bip39.generateMnemonic(),
55+
mnemonic: mnemonic,
4656
};
4757

4858
this.walletService.createWallet(wallet);
@@ -72,4 +82,27 @@ export class CreateCommand extends BaseCommand {
7282

7383
return val;
7484
}
75-
}
85+
@Option({
86+
flags: '-p,--path_index [path_index]',
87+
description: 'path index',
88+
})
89+
parsePathIndex(val: number): number {
90+
if (!val || val < 0) {
91+
logerror("path index can't be empty!", new Error('invalid path_index option'));
92+
process.exit(0);
93+
}
94+
return val;
95+
}
96+
97+
@Option({
98+
flags: '-m,--mnemonic [mnemonic]',
99+
description: 'mnemonic',
100+
})
101+
parseMnemonic(val: string): string {
102+
if (!val) {
103+
logerror("mnemonic can't be empty!", new Error('invalid mnemonic option'));
104+
process.exit(0);
105+
}
106+
return val;
107+
}
108+
}

packages/cli/src/common/apis-tracker.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
toP2tr,
1515
} from './utils';
1616
import { byteString2Int } from 'scrypt-ts';
17-
import { createOpenMinterState } from 'src/commands/mint/ft.open-minter';
1817
import { findTokenMetadataById, scaleConfig } from 'src/token';
1918
import { logerror } from './log';
2019
import { ConfigService, SpendService, WalletService } from 'src/providers';
@@ -130,48 +129,25 @@ const fetchOpenMinterState = async function (
130129
const tx = new btc.Transaction(txhex);
131130

132131
const REMAININGSUPPLY_WITNESS_INDEX = 16;
133-
const MINTAMOUNT_WITNESS_INDEX = 6;
134132

135-
let newMinter = 0;
136-
137-
for (let i = 0; i < tx.outputs.length; i++) {
138-
const output = tx.outputs[i];
139-
if (output.script.toHex() === minterP2TR) {
140-
newMinter++;
141-
}
142-
}
143133
for (let i = 0; i < tx.inputs.length; i++) {
144134
const witnesses = tx.inputs[i].getWitnesses();
145135

146136
if (witnesses.length > 2) {
147137
const lockingScriptBuffer = witnesses[witnesses.length - 2];
148138
const { p2tr } = script2P2TR(lockingScriptBuffer);
149139
if (p2tr === minterP2TR) {
150-
const mintAmount = byteString2Int(
151-
witnesses[MINTAMOUNT_WITNESS_INDEX].toString('hex'),
152-
);
153-
154140
const preState: OpenMinterState = {
155141
tokenScript:
156142
witnesses[REMAININGSUPPLY_WITNESS_INDEX - 2].toString('hex'),
157143
isPremined:
158144
witnesses[REMAININGSUPPLY_WITNESS_INDEX - 1].toString('hex') == '01'
159145
? true
160146
: false,
161-
remainingSupply: byteString2Int(
162-
witnesses[REMAININGSUPPLY_WITNESS_INDEX].toString('hex'),
163-
),
147+
remainingSupply: byteString2Int(witnesses[6 + vout].toString('hex')),
164148
};
165149

166-
const { minterStates } = createOpenMinterState(
167-
mintAmount,
168-
preState.isPremined,
169-
preState.remainingSupply,
170-
metadata,
171-
newMinter,
172-
);
173-
174-
return minterStates[vout - 1] || null;
150+
return preState;
175151
}
176152
}
177153
}

packages/cli/src/common/apis.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getFeeRate = async function (
2424
return feeRate;
2525
}
2626

27-
const url = `${config.getApiHost()}/api/v1/fees/recommended`;
27+
const url = `${config.getMempoolApiHost()}/api/v1/fees/recommended`;
2828
const feeRate: any = await fetch(url, config.withProxy())
2929
.then((res) => {
3030
if (res.status === 200) {
@@ -50,7 +50,7 @@ export const getFractalUtxos = async function (
5050
): Promise<UTXO[]> {
5151
const script = new btc.Script(address).toHex();
5252

53-
const url = `https://open-api-fractal-testnet.unisat.io/v1/indexer/address/${address}/utxo-data?cursor=0&size=16`;
53+
const url = `${config.getOpenApiHost()}/v1/indexer/address/${address}/utxo-data?cursor=0&size=16`;
5454
const utxos: Array<any> = await fetch(
5555
url,
5656
config.withProxy({
@@ -118,7 +118,7 @@ export const getUtxos = async function (
118118

119119
const script = new btc.Script(address).toHex();
120120

121-
const url = `${config.getApiHost()}/api/address/${address}/utxo`;
121+
const url = `${config.getMempoolApiHost()}/api/address/${address}/utxo`;
122122
const utxos: Array<any> = await fetch(url, config.withProxy())
123123
.then(async (res) => {
124124
const contentType = res.headers.get('content-type');
@@ -156,7 +156,7 @@ export const getRawTransaction = async function (
156156
if (config.useRpc()) {
157157
return rpc_getrawtransaction(config, wallet.getWalletName(), txid);
158158
}
159-
const url = `${config.getApiHost()}/api/tx/${txid}/hex`;
159+
const url = `${config.getMempoolApiHost()}/api/tx/${txid}/hex`;
160160
return (
161161
fetch(url, config.withProxy())
162162
.then((res) => {
@@ -206,7 +206,7 @@ export async function broadcast(
206206
return rpc_broadcast(config, wallet.getWalletName(), txHex);
207207
}
208208

209-
const url = `${config.getApiHost()}/api/tx`;
209+
const url = `${config.getMempoolApiHost()}/api/tx`;
210210
return fetch(
211211
url,
212212
config.withProxy({

packages/cli/src/providers/configService.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@ export class ConfigService {
5555
return this.cliConfig;
5656
}
5757

58-
getApiHost = () => {
58+
getOpenApiHost = () => {
59+
const config = this.getCliConfig();
60+
if (config.network === 'fractal-testnet') {
61+
return 'https://open-api-fractal-testnet.unisat.io';
62+
} else if (config.network === 'fractal-mainnet') {
63+
return 'https://open-api-fractal.unisat.io';
64+
} else {
65+
throw new Error(`Unsupport network: ${config.network}`);
66+
}
67+
};
68+
69+
getMempoolApiHost = () => {
5970
const config = this.getCliConfig();
6071
if (config.network === 'btc-signet') {
6172
return 'https://mempool.space/signet';

packages/tracker/.env.example

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
1+
# FB Full Node image
2+
FB_FULL_NODE_IMAGE=fractalbitcoin/fractal:v0.2.1
3+
POSTGRES_IMAGE=postgres:16
4+
5+
# TODO: DEVS need to update this to their own paths
6+
USER_HOME=/home/ubuntu
7+
DATABASE_VOLUME_PATH=$USER_HOME/data/pgdata
8+
BITCOIND_DATA_DIR=$USER_HOME/data/bitcoin
9+
DATABASE_DATA_DIR=/var/lib/postgresql/data/pgdata
10+
11+
# POSTGRES
112
DATABASE_TYPE=postgres
213
DATABASE_HOST=127.0.0.1
314
DATABASE_PORT=5432
415
DATABASE_DB=postgres
516
DATABASE_USERNAME=postgres
617
DATABASE_PASSWORD=postgres
718

8-
RPC_HOST=127.0.0.1
9-
RPC_PORT=8332
10-
RPC_USER=bitcoin
11-
RPC_PASSWORD=opcatAwesome
1219

13-
NETWORK=mainnet
14-
API_PORT=3000
15-
GENESIS_BLOCK_HEIGHT=0 # the height of block that CAT protocol launches
20+
# TODO: DEVS needs to update this accord their machine resources
21+
DATABASE_SHM_SIZE=1g
22+
23+
24+
# TODO: DEVS
25+
# BITCOIND default config in CAT protocol
26+
BITCOIND_RPC_HOST=127.0.0.1
27+
BITCOIND_RPC_PORT=8332
28+
BITCOIND_RPC_USER=bitcoin
29+
BITCOIND_RPC_PASSWORD=opcatAwesome
30+
31+
BITCOIND_ZMQ_PUB_HASH_BLOCK_PORT=8330
32+
BITCOIND_ZMQ_PUB_RAW_TX_PORT=8331
33+
BITCOIND_P2P_PORT=8333
34+
35+
# TODO: DEVS needs to update this accord their machine resources
36+
BITCOIND_RESOURCES_LIMITS_MEMORY=60G
37+
BITCOIND_RESOURCES_LIMITS_CPU=4.0
38+
BITCOIND_RESOURCES_RESERVATIONS_MEMORY=40G
39+
BITCOIND_RESOURCES_RESERVATIONS_CPU=2.0
40+
41+
BITCOIND_MEMSWAP_LIMIT=80G
42+
BITCOIND_MEM_SWAPPINESS=100
43+
44+
# TODO: DEVS needs to update this accord their machine resources
45+
CAT_PROTOCOL_NETWORK=mainnet
46+
CAT_PROTOCOL_API_PORT=3000
47+
CAT_PROTOCOL_GENESIS_BLOCK_HEIGHT=0
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
1+
networks:
2+
cat20_network:
3+
external: true
4+
15
services:
26
postgres:
3-
image: postgres:16
7+
image: $POSTGRES_IMAGE
8+
shm_size: $DATABASE_SHM_SIZE
49
restart: always
510
environment:
611
POSTGRES_USER: $DATABASE_USERNAME
712
POSTGRES_PASSWORD: $DATABASE_PASSWORD
813
POSTGRES_DB: $DATABASE_DB
9-
PGDATA: /var/lib/postgresql/data/pgdata
14+
PGDATA: $DATABASE_DATA_DIR
1015
ports:
11-
- "5432:5432"
16+
- "${DATABASE_PORT}:${DATABASE_PORT}"
1217
volumes:
13-
- ./docker/pgdata:/var/lib/postgresql/data
18+
- $DATABASE_VOLUME_PATH:$DATABASE_DATA_DIR
19+
networks:
20+
- cat20_network
1421
bitcoind:
15-
image: fractalbitcoin/fractal:v0.2.1
22+
image: $FB_FULL_NODE_IMAGE
1623
restart: always
1724
entrypoint: ["bitcoind", "-datadir=/data/", "-maxtipage=504576000"]
1825
command: ""
1926
healthcheck:
2027
test: ["CMD", "bitcoin-cli", "-datadir=/data/", "getblockchaininfo"]
2128
ports:
22-
- "8330:8330"
23-
- "8331:8331"
24-
- "8332:8332"
25-
- "8333:8333"
29+
- "${BITCOIND_ZMQ_PUB_HASH_BLOCK_PORT}:${BITCOIND_ZMQ_PUB_HASH_BLOCK_PORT}"
30+
- "${BITCOIND_ZMQ_PUB_RAW_TX_PORT}:${BITCOIND_ZMQ_PUB_RAW_TX_PORT}"
31+
- "${BITCOIND_RPC_PORT}:${BITCOIND_RPC_PORT}"
32+
- "${BITCOIND_P2P_PORT}:${BITCOIND_P2P_PORT}"
2633
deploy:
2734
resources:
2835
limits:
29-
memory: 40G
30-
memswap_limit: 60G
31-
mem_swappiness: 100
36+
memory: $BITCOIND_RESOURCES_LIMITS_MEMORY
37+
cpus: '${BITCOIND_RESOURCES_LIMITS_CPU}'
38+
reservations:
39+
memory: $BITCOIND_RESOURCES_RESERVATIONS_MEMORY
40+
cpus: '${BITCOIND_RESOURCES_RESERVATIONS_CPU}'
41+
memswap_limit: $BITCOIND_MEMSWAP_LIMIT
42+
mem_swappiness: $BITCOIND_MEM_SWAPPINESS
3243
volumes:
33-
- ./docker/data:/data
44+
- $BITCOIND_DATA_DIR:/data
3445
logging:
3546
driver: "json-file"
3647
options:
3748
labels: "env,filebeat,name"
3849
max-size: "1g"
3950
max-file: "3"
51+
networks:
52+
- cat20_network

packages/tracker/init_script.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
path=$(pwd)
4+
ENV_FILE="$path/.env"
5+
6+
if [ ! -f "$ENV_FILE" ]; then
7+
echo ".env file not found: $ENV_FILE"
8+
exit 1
9+
fi
10+
11+
USER_HOME=$(grep -E '^USER_HOME=' "$ENV_FILE" | cut -d '=' -f 2)
12+
DATABASE_VOLUME_PATH=$(grep -E '^DATABASE_VOLUME_PATH=' "$ENV_FILE" | cut -d '=' -f 2)
13+
BITCOIND_DATA_DIR=$(grep -E '^BITCOIND_DATA_DIR=' "$ENV_FILE" | cut -d '=' -f 2)
14+
15+
NESTED_DIRS=("$USER_HOME/data/pgdata" "$USER_HOME/data/bitcoin")
16+
for DIR in "${NESTED_DIRS[@]}"; do
17+
if [ -d "$DIR" ]; then
18+
echo "Checking directory: $DIR"
19+
if [ ! -w "$DIR" ]; then
20+
echo "Changing permissions: $DIR"
21+
sudo chmod -R 777 "$DIR"
22+
else
23+
echo "Permissions are correct: $DIR"
24+
fi
25+
else
26+
echo "Directory does not exist: $DIR"
27+
echo "Creating directory: $DIR"
28+
sudo mkdir -p "$DIR"
29+
sudo chmod -R 777 "$DIR"
30+
fi
31+
done
32+
33+
echo "Check completed"
34+
35+
sudo cp docker/data/bitcoin.conf "${NESTED_DIRS[1]}"
36+
echo "Starting services"
37+
38+
docker compose down
39+
40+
# Check if the network exists
41+
if ! docker network ls | grep -q cat20_network; then
42+
echo "Creating network cat20_network"
43+
docker network create cat20_network
44+
else
45+
echo "Network cat20_network already exists"
46+
fi
47+
48+
docker compose up -d
49+
50+
cd ../../
51+
echo "Building tracker service"
52+
docker build -t tracker:latest .
53+
echo "Starting tracker service"
54+
55+
if docker ps -a | grep -q tracker; then
56+
echo "Tracker service already exists, removing..."
57+
docker rm -f tracker
58+
fi
59+
60+
docker run -d \
61+
--name tracker \
62+
--network cat20_network \
63+
--add-host="host.docker.internal:host-gateway" \
64+
-e DATABASE_HOST="host.docker.internal" \
65+
-e BITCOIND_RPC_HOST="bitcoind" \
66+
-p 3000:3000 \
67+
tracker:latest
68+
69+
echo "Tracker service started"

0 commit comments

Comments
 (0)