-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgr.go
81 lines (66 loc) · 1.69 KB
/
mgr.go
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
package walletmgr
import (
"fmt"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/txscript"
log "github.com/sirupsen/logrus"
)
const walletLen = 10
type WalletMgr struct {
net *chaincfg.Params
wallets []*Wallet
cache *Cache
}
func InitAndCacheWalletWif(cacheDir string, net *chaincfg.Params) error {
cache, err := InitCache(cacheDir)
if err != nil {
return err
}
var wallets []string
for i := 0; i < walletLen; i++ {
privateKey, err := btcec.NewPrivateKey()
if err != nil {
return err
}
privateKeyWIF, err := btcutil.NewWIF(txscript.TweakTaprootPrivKey(*privateKey, []byte{}), net, true)
wallets = append(wallets, privateKeyWIF.String())
}
return cache.WriteAllWalletWiF(wallets)
}
func InitWalletMgr(cacheDir string, net *chaincfg.Params) (*WalletMgr, error) {
cache, err := InitCache(cacheDir)
if err != nil {
return nil, err
}
var wallets []*Wallet
wifs, err := cache.ReadAllWalletWiF()
if err != nil {
return nil, err
}
for _, wif := range wifs {
wallet, err := InitWallet(wif, cache, net)
if err != nil {
return nil, err
}
wallets = append(wallets, wallet)
}
return &WalletMgr{
net: net,
wallets: wallets,
cache: cache,
}, nil
}
func (wm *WalletMgr) MintsRunes(cli *rpcclient.Client, runeId string, destination string) {
for i, wallet := range wm.wallets {
err := wallet.MintRunes(cli, runeId, destination)
if err != nil {
log.Info(fmt.Sprintf("wallet %d mint runes %s to %s failed", i, runeId, destination))
continue
}
}
}
func (wm *WalletMgr) GetMintProcessing(runeId string, destination string) {
}