-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.ts
125 lines (115 loc) · 3.76 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
import * as commander from "commander";
import { stake } from "./src/stake";
import { redeem } from "./src/redeem";
import { BitcoinNetworkMap, CoreNetworkMap, FeeSpeedMap } from "./src/constant";
const program = new commander.Command();
program
.version("1.0.0")
.description("Core chain self custody BTC staking command line tool.");
program
.command("stake")
.description("Stake BTC")
.requiredOption(
"-acc, --account <account>",
"The Bitcon address used to stake."
)
.requiredOption(
"-privkey, --privatekey <privatekey>",
"The private key used to sign the transaction, which should be associated with --account. Hex format."
)
.requiredOption(
"-amt, --amount <amount>",
"Amount of BTC to stake, measured in SAT."
)
.option(
"-bn, --bitcoinnetwork <bitcoinnetwork>",
"The Bitcoin network to operate on, choose between 1~2. 1)Mainnet 2)Testnet, default to 1)Mainnet."
)
.option(
"-cn, --corenetwork <corenetwork>",
"The Core network to transmit the stake transaction to, choose between 1~3. 1)Mainnet 2)Devnet 3)Testnet, default to 1)Mainnet."
)
.requiredOption(
"-lt, --locktime <locktime>",
"The unix timestamp in seconds to lock the BTC assets up to. e.g. 1711983981"
)
.option(
"-pubkey, --publickey <publickey>",
"The public key used to redeem the BTC assets when locktime expires. Default to the public key associated with --privatekey."
)
.requiredOption(
"-raddr, --rewardaddress <rewardaddress>",
"Core address used to claim staking rewards."
)
.requiredOption(
"-vaddr, --validatoraddress <validatoraddress>",
"Core validator address to stake to."
)
.option("-w, --witness", "Use segwit or not.")
.option(
"-br, --bitcoinrpc <bitcoinrpc>",
"The Bitcoin RPC service to use, default to https://mempool.space/. "
)
.option(
"--fee <fee>",
"Transaction fee s)slow a)average f)fast, please choose in (s, a ,f) OR a customized number in SAT, default to a)average."
)
.action(async (args) => {
const bitcoinnetwork = BitcoinNetworkMap[args.bitcoinnetwork];
const corenetwork = CoreNetworkMap[args.corenetwork];
const fee = FeeSpeedMap[args.fee];
await stake({
lockTime: args.locktime,
amount: args.amount,
validatorAddress: args.validatoraddress,
rewardAddress: args.rewardaddress,
publicKey: args.publickey,
account: args.account,
bitcoinNetwork: bitcoinnetwork,
coreNetwork: corenetwork,
privateKey: args.privatekey,
witness: args.witness,
bitcoinRpc: args.bitcoinrpc,
fee: fee || args.fee,
});
});
program
.command("redeem")
.description("Redeem BTC")
.requiredOption(
"-acc, --account <account>",
"The locked P2SH/P2WSH script address."
)
.requiredOption(
"-r, --redeemscript <redeemscript>",
"The redeem script which was returned in the stake action."
)
.requiredOption(
"-privkey, --privatekey <privatekey>",
"The private key associated --publickey in the stake action. Hex format."
)
.requiredOption(
"-d, --destaddress <destaddress>",
"The Bitcoin address to receive the redeemed BTC assets."
)
.option(
"-br, --bitcoinrpc <bitcoinrpc>",
"The Bitcoin RPC service to use, default to https://mempool.space/. "
)
.option(
"--fee <fee>",
"Transaction fee s)slow a)average f)fast, please choose in (s, a ,f) OR a customized number in SAT, default to a)average."
)
.action(async (args) => {
const fee = FeeSpeedMap[args.fee];
await redeem({
account: args.account,
redeemScript: args.redeemscript,
privateKey: args.privatekey,
destAddress: args.destaddress,
bitcoinRpc: args.bitcoinRpc,
fee: fee || args.fee,
});
});
program.parse(process.argv);