Skip to content

Commit 93e0a1b

Browse files
authored
Merge pull request #3 from ottosch/cookie-file
Add support for cookie file
2 parents 08e84a5 + 1e6ca06 commit 93e0a1b

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

blindbit.example.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ host = "127.0.0.1:8000"
55
# (defaults to http://127.0.0.1:8332)
66
rpc_endpoint = "http://127.0.0.1:18443"
77

8+
# required, unless rpc_user and rpc_pass are set
9+
cookie_path = ""
810

9-
# required
11+
# required, unless cookie_path is set
1012
rpc_pass = "your-rpc-password"
1113

12-
# required
14+
# required, unless cookie_path is set
1315
rpc_user = "your-rpc-user"
1416

1517
# required (has to be >= 1)

src/common/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func LoadConfigs(pathToConfig string) {
2929
MaxParallelTweakComputations = viper.GetInt("max_parallel_tweak_computations")
3030

3131
RpcEndpoint = viper.GetString("rpc_endpoint")
32+
CookiePath = viper.GetString("cookie_path")
3233
RpcPass = viper.GetString("rpc_pass")
3334
RpcUser = viper.GetString("rpc_user")
3435

src/common/vars.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var TweaksOnly bool
1212

1313
var (
1414
RpcEndpoint = "http://127.0.0.1:8332" // default local node
15+
CookiePath = ""
1516
RpcUser = ""
1617
RpcPass = ""
1718

src/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ func init() {
7373
// open levelDB connections
7474
openLevelDBConnections()
7575

76+
if common.CookiePath != "" {
77+
data, err := os.ReadFile(common.CookiePath)
78+
if err != nil {
79+
panic(err)
80+
}
81+
82+
credentials := strings.Split(string(data), ":")
83+
if len(credentials) != 2 {
84+
panic("cookie file is invalid")
85+
}
86+
common.RpcUser = credentials[0]
87+
common.RpcPass = credentials[1]
88+
}
89+
7690
if common.RpcUser == "" {
7791
panic("rpc user not set") // todo use cookie file to circumvent this requirement
7892
}

0 commit comments

Comments
 (0)