diff --git a/blindbit.example.toml b/blindbit.example.toml index b0936d5..cbb01d6 100644 --- a/blindbit.example.toml +++ b/blindbit.example.toml @@ -1,5 +1,7 @@ # possible values: trace, debug, info, warn, error log_level = "debug" +# log_path = "" +# log_to_console = true # 0.0.0.0:8000 to expose outside of localhost # default: "127.0.0.1:8000" diff --git a/cmd/blindbit-oracle/main.go b/cmd/blindbit-oracle/main.go index c90eafa..9bc473a 100644 --- a/cmd/blindbit-oracle/main.go +++ b/cmd/blindbit-oracle/main.go @@ -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() { diff --git a/internal/config/config.go b/internal/config/config.go index efba425..aa7ca87 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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") @@ -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") diff --git a/internal/config/vars.go b/internal/config/vars.go index 39740da..aa8a999 100644 --- a/internal/config/vars.go +++ b/internal/config/vars.go @@ -39,6 +39,7 @@ var ( BaseDirectory = "" DBPath = "" LogsPath = "" + LogToConsole = true HTTPHost = "127.0.0.1:8000" GRPCHost = "" // default value is empty (deactivated) diff --git a/internal/core/tweak.go b/internal/core/tweak.go index 1eba2ac..e83a078 100644 --- a/internal/core/tweak.go +++ b/internal/core/tweak.go @@ -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