-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstruct.go
61 lines (55 loc) · 1.55 KB
/
construct.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
package paywall
import (
"time"
"github.com/opd-ai/paywall/wallet"
)
// ConstructPaywall creates and initializes a new Paywall instance.
// Unlike "NewPaywall" ConstructPaywall automatically configures a
// persistent wallet with a file backed store.
// Parameters:
// - config: Configuration options for the paywall
//
// Returns:
// - *Paywall: Initialized paywall instance
// - error: If initialization fails
//
// Errors:
// - If random seed generation fails
// - If HD wallet creation fails
// - If template parsing fails
//
// Related types: Config, Paywall
func ConstructPaywall() (*Paywall, error) {
key, err := wallet.GenerateEncryptionKey()
if err != nil {
return nil, err
}
storageConfig := wallet.StorageConfig{
DataDir: "./paywallet",
EncryptionKey: key,
}
fileStore := NewFileStore()
// Initialize paywall with minimal config
pw, err := NewPaywall(Config{
PriceInBTC: 0.0001, // 0.0001 BTC
PriceInXMR: .005,
TestNet: false, // Use testnet
Store: fileStore, // Required for payment tracking
PaymentTimeout: time.Hour * 2,
MinConfirmations: 1,
})
if err != nil {
return nil, err
}
// Attempt to load wallet from disk, if it fails store the new one
if HDWallet, err := wallet.LoadFromFile(storageConfig); err != nil {
// Save newly generated wallet
if err := pw.HDWallets[wallet.Bitcoin].(*wallet.BTCHDWallet).SaveToFile(storageConfig); err != nil {
return nil, err
}
} else {
// Load stored wallet from disk
pw.HDWallets[wallet.Bitcoin] = HDWallet
}
return pw, nil
}