Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions blindbit.example.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# possible values: trace, debug, info, warn, error
log_level = "debug"
# log_path = "<path to log directory>"
# log_to_console = true

# 0.0.0.0:8000 to expose outside of localhost
# default: "127.0.0.1:8000"
Expand Down
8 changes: 8 additions & 0 deletions cmd/blindbit-oracle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func init() {
if err != nil && !strings.Contains(err.Error(), "file exists") {
logging.L.Fatal().Err(err).Msg("error creating db path")
}

if config.LogsPath != "" {
if err := logging.SetLogOutput(config.LogsPath, "blindbit.log"); err != nil {
logging.L.Warn().Err(err).Msg("Failed to initialize file logging")
defer logging.Close()
}
}
logging.SetConsoleLogging(config.LogToConsole)
}

func main() {
Expand Down
5 changes: 4 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func LoadConfigs(pathToConfig string) {
viper.SetDefault("tweaks_full_with_dust_filter", false)
viper.SetDefault("tweaks_cut_through_with_dust_filter", false)
viper.SetDefault("log_level", "info")

viper.SetDefault("log_path", "")
viper.SetDefault("log_to_console", true)
// Bind viper keys to environment variables (optional, for backup)
viper.AutomaticEnv()
viper.BindEnv("http_host", "HTTP_HOST")
Expand All @@ -61,6 +62,8 @@ func LoadConfigs(pathToConfig string) {
HTTPHost = viper.GetString("http_host")
GRPCHost = viper.GetString("grpc_host")
LogLevel = viper.GetString("log_level")
LogsPath = viper.GetString("log_path")
LogToConsole = viper.GetBool("log_to_console")

// Performance
MaxParallelRequests = viper.GetUint16("max_parallel_requests")
Expand Down
1 change: 1 addition & 0 deletions internal/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
BaseDirectory = ""
DBPath = ""
LogsPath = ""
LogToConsole = true

HTTPHost = "127.0.0.1:8000"
GRPCHost = "" // default value is empty (deactivated)
Expand Down
17 changes: 7 additions & 10 deletions internal/core/tweak.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,18 +520,15 @@ func findSmallestOutpoint(tx types.Transaction) ([]byte, error) {
}
reversedTxid := utils.ReverseBytes(txidBytes)

// Serialize the Vout as little-endian bytes
voutBytes := new(bytes.Buffer)
err = binary.Write(voutBytes, binary.LittleEndian, vin.Vout)
if err != nil {
logging.L.Err(err).Msg("error serializing vout")
return nil, err
}
// Concatenate reversed Txid and Vout bytes
outpoint := append(reversedTxid, voutBytes.Bytes()...)
// Serialize outpoint: 32 bytes txid + 4 bytes vout
var outpoint [36]byte
copy(outpoint[:32], reversedTxid)

// Encode vout as 4-byte little-endian
binary.LittleEndian.PutUint32(outpoint[32:36], vin.Vout)

// Add the serialized outpoint to the slice
outpoints = append(outpoints, outpoint)
outpoints = append(outpoints, outpoint[:])
}

// Sort the slice of outpoints to find the lexicographically smallest one
Expand Down