Skip to content

Commit 8f5f8f6

Browse files
committed
Small changes
- changed logger - added block-hash endpoint - included commit for gzip
1 parent 403670d commit 8f5f8f6

File tree

7 files changed

+138
-42
lines changed

7 files changed

+138
-42
lines changed

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The installation process is still very manual. Will be improved based on feedbac
1313

1414
- Endpoints were expanded and have a slightly different syntax now [see endpoints](#endpoints)
1515

16-
### Requirements
16+
## Requirements
1717

1818
- RPC access to a bitcoin full node
1919
- unpruned because we need the prevouts for every transaction in the block with a taproot output
@@ -45,10 +45,6 @@ You still have to set up a config file in any case as the rpc users can't and **
4545

4646
You can now also decide which index you want to run. This setting can be set in the config file (blindbit.toml).
4747

48-
## Known Errors
49-
50-
No known issues.
51-
5248
## Todos
5349

5450
- [ ] Add flags to control setup
@@ -88,6 +84,7 @@ No known issues.
8884
```text
8985
GET("/info") // returns basic information about the oracle instance
9086
GET("/block-height") // returns the height of the indexing server
87+
GET("/block-hash/:blockheight") // returns the block-hash for a certain block-height
9188
GET("/tweaks/:blockheight?dustLimit=<sat_amount>") // returns tweak data (cut-through); optional parameter dustLimit can be omitted; filtering happens per request, so virtually any amount can be specified
9289
GET("/tweak-index/:blockheight?dustLimit=<sat_amount>") // returns the full tweak index (no cut-through); optional parameter dustLimit can be omitted; filtering happens per request, so virtually any amount can be specified
9390
GET("/spent-index/:blockheight") // returns the spent outpoints index (see https://github.com/setavenger/BIP0352-light-client-specification?tab=readme-ov-file#spent-utxos)

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
module SilentPaymentAppBackend
22

3-
go 1.21.0
3+
go 1.22.4
44

5-
toolchain go1.24.0
5+
toolchain go1.22.4
66

77
require (
88
github.com/btcsuite/btcd/btcec/v2 v2.3.3
99
github.com/btcsuite/btcd/btcutil v1.1.5
1010
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
1111
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
1212
github.com/gin-contrib/cors v1.7.2
13-
github.com/gin-gonic/gin v1.10.0
13+
github.com/gin-gonic/gin v1.9.1
14+
github.com/setavenger/go-bip352 v0.1.6
1415
github.com/shopspring/decimal v1.3.1
1516
github.com/spf13/viper v1.18.2
1617
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
@@ -49,7 +50,6 @@ require (
4950
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
5051
github.com/sagikazarmark/locafero v0.4.0 // indirect
5152
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
52-
github.com/setavenger/go-bip352 v0.1.6 // indirect
5353
github.com/sourcegraph/conc v0.3.0 // indirect
5454
github.com/spf13/afero v1.11.0 // indirect
5555
github.com/spf13/cast v1.6.0 // indirect

go.sum

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@ github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg=
22
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
33
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
44
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
5-
github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
6-
github.com/btcsuite/btcd v0.23.4 h1:IzV6qqkfwbItOS/sg/aDfPDsjPP8twrCOE2R93hxMlQ=
7-
github.com/btcsuite/btcd v0.23.4/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
85
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd h1:js1gPwhcFflTZ7Nzl7WHaOTlTr5hIrR4n1NM4v9n4Kw=
96
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
107
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
118
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
12-
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
13-
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
149
github.com/btcsuite/btcd/btcec/v2 v2.3.3 h1:6+iXlDKE8RMtKsvK0gshlXIuPbyWM/h84Ensb7o3sC0=
1510
github.com/btcsuite/btcd/btcec/v2 v2.3.3/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
1611
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
1712
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
18-
github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ=
19-
github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0=
2013
github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8=
2114
github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00=
2215
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
23-
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
2416
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
2517
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
2618
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
@@ -51,12 +43,14 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2
5143
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5244
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5345
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
46+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5447
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
5548
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
5649
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
5750
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
5851
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
5952
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
53+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
6054
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
6155
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
6256
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
@@ -78,6 +72,7 @@ github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SU
7872
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
7973
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
8074
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
75+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
8176
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
8277
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
8378
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
@@ -104,6 +99,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
10499
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
105100
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
106101
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
102+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
107103
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
108104
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
109105
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
@@ -123,7 +119,9 @@ github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kK
123119
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
124120
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
125121
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
122+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
126123
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
124+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
127125
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
128126
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
129127
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
@@ -155,7 +153,9 @@ github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNH
155153
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
156154
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
157155
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
156+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
158157
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
158+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
159159
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
160160
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
161161
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
@@ -249,6 +249,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
249249
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
250250
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
251251
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
252+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
252253
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
253254
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
254255
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -261,6 +262,7 @@ google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTm
261262
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
262263
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
263264
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
265+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
264266
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
265267
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
266268
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

src/common/logger.go

+93-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,99 @@
11
package common
22

3-
import "log"
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
"time"
48

5-
//import (
6-
// "log/slog"
7-
// "os"
8-
//)
9-
//
10-
//var Logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: true, Level: slog.LevelDebug}))
9+
"github.com/rs/zerolog"
10+
)
1111

1212
var (
13-
DebugLogger *log.Logger
14-
InfoLogger *log.Logger
15-
WarningLogger *log.Logger
16-
ErrorLogger *log.Logger
13+
MainLogger zerolog.Logger
14+
DebugLogger *LoggerDebug
15+
InfoLogger *LoggerInfo
16+
WarningLogger *LoggerWarn
17+
ErrorLogger *LoggerError
1718
)
19+
20+
func init() {
21+
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
22+
MainLogger = zerolog.New(output).With().Timestamp().Caller().Logger()
23+
}
24+
25+
type LoggerDebug struct{}
26+
27+
func (l *LoggerDebug) Println(v ...any) {
28+
ev := MainLogger.Debug().CallerSkipFrame(1)
29+
for i, val := range v {
30+
ev.Any(fmt.Sprintf("val_%d", i), val)
31+
}
32+
ev.Msg("")
33+
}
34+
35+
func (l *LoggerDebug) Printf(templ string, v ...any) {
36+
templ = strings.TrimSuffix(templ, "\n")
37+
MainLogger.Debug().CallerSkipFrame(1).Msgf(templ, v...)
38+
}
39+
40+
type LoggerInfo struct{}
41+
42+
func (l *LoggerInfo) Println(v ...any) {
43+
ev := MainLogger.Info().CallerSkipFrame(1)
44+
for i, val := range v {
45+
ev.Any(fmt.Sprintf("val_%d", i), val)
46+
}
47+
ev.Msg("")
48+
}
49+
50+
func (l *LoggerInfo) Printf(templ string, v ...any) {
51+
templ = strings.TrimSuffix(templ, "\n")
52+
MainLogger.Info().CallerSkipFrame(1).Msgf(templ, v...)
53+
}
54+
55+
type LoggerWarn struct{}
56+
57+
func (l *LoggerWarn) Println(v ...any) {
58+
ev := MainLogger.Warn().CallerSkipFrame(1)
59+
for i, val := range v {
60+
ev.Any(fmt.Sprintf("val_%d", i), val)
61+
}
62+
ev.Msg("")
63+
}
64+
65+
func (l *LoggerWarn) Printf(templ string, v ...any) {
66+
templ = strings.TrimSuffix(templ, "\n")
67+
MainLogger.Warn().CallerSkipFrame(1).Msgf(templ, v...)
68+
}
69+
70+
type LoggerError struct{}
71+
72+
func (l *LoggerError) Println(v ...any) {
73+
ev := MainLogger.Error().CallerSkipFrame(1)
74+
for i, val := range v {
75+
ev.Any(fmt.Sprintf("val_%d", i), val)
76+
}
77+
ev.Msg("")
78+
}
79+
80+
func (l *LoggerError) Printf(templ string, v ...any) {
81+
templ = strings.TrimSuffix(templ, "\n")
82+
MainLogger.Error().CallerSkipFrame(1).Msgf(templ, v...)
83+
}
84+
85+
func (l *LoggerError) Fatal(v ...any) {
86+
ev := MainLogger.Fatal().CallerSkipFrame(1)
87+
for i, val := range v {
88+
ev.Any(fmt.Sprintf("val_%d", i), val)
89+
}
90+
ev.Msg("")
91+
}
92+
93+
func (l *LoggerError) Fatalln(v ...any) {
94+
ev := MainLogger.Fatal().CallerSkipFrame(1)
95+
for i, val := range v {
96+
ev.Any(fmt.Sprintf("val_%d", i), val)
97+
}
98+
ev.Msg("")
99+
}

src/main.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"SilentPaymentAppBackend/src/server"
99
"flag"
1010
"fmt"
11-
"io"
1211
"log"
1312
"path"
1413

@@ -49,22 +48,22 @@ func init() {
4948
log.Fatal(err)
5049
}
5150

52-
file, err := os.OpenFile(fmt.Sprintf("%s/logs.log", common.LogsPath), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
53-
if err != nil {
54-
log.Fatal(err)
55-
}
56-
fileDebug, err := os.OpenFile(fmt.Sprintf("%s/logs-debug.log", common.LogsPath), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
57-
if err != nil {
58-
log.Fatal(err)
59-
}
51+
// file, err := os.OpenFile(fmt.Sprintf("%s/logs.log", common.LogsPath), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
52+
// if err != nil {
53+
// log.Fatal(err)
54+
// }
55+
// fileDebug, err := os.OpenFile(fmt.Sprintf("%s/logs-debug.log", common.LogsPath), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
56+
// if err != nil {
57+
// log.Fatal(err)
58+
// }
6059

61-
multi := io.MultiWriter(file, os.Stdout)
60+
// multi := io.MultiWriter(file, os.Stdout)
6261
//multiDebug := io.MultiWriter(fileDebug, os.Stdout)
6362

64-
common.DebugLogger = log.New(fileDebug, "[DEBUG] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix)
65-
common.InfoLogger = log.New(multi, "[INFO] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix)
66-
common.WarningLogger = log.New(multi, "[WARNING] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix)
67-
common.ErrorLogger = log.New(multi, "[ERROR] ", log.Ldate|log.Lmicroseconds|log.Llongfile|log.Lmsgprefix)
63+
// common.DebugLogger = log.New(fileDebug, "[DEBUG] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix)
64+
// common.InfoLogger = log.New(multi, "[INFO] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix)
65+
// common.WarningLogger = log.New(multi, "[WARNING] ", log.Ldate|log.Lmicroseconds|log.Lshortfile|log.Lmsgprefix)
66+
// common.ErrorLogger = log.New(multi, "[ERROR] ", log.Ldate|log.Lmicroseconds|log.Llongfile|log.Lmsgprefix)
6867

6968
common.InfoLogger.Println("base directory", common.BaseDirectory)
7069

src/server/api.go

+15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ func (h *ApiHandler) GetBestBlockHeight(c *gin.Context) {
6262
})
6363
}
6464

65+
func (h *ApiHandler) GetBlockHashByHeight(c *gin.Context) {
66+
headerInv, exists := c.Get("headerInv")
67+
if !exists {
68+
c.JSON(http.StatusInternalServerError, gin.H{"error": "headerInv not found"})
69+
return
70+
}
71+
hInv, ok := headerInv.(types.BlockHeaderInv) // Assuming HeaderInventory is the expected type
72+
if !ok {
73+
c.JSON(http.StatusInternalServerError, gin.H{"error": "invalid headerInv type"})
74+
return
75+
}
76+
77+
c.JSON(http.StatusOK, gin.H{"block_hash": hInv.Hash})
78+
}
79+
6580
func (h *ApiHandler) GetCFilterByHeight(c *gin.Context) {
6681
headerInv, exists := c.Get("headerInv")
6782
if !exists {

src/server/run.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func RunServer(api *ApiHandler) {
2222

2323
router.GET("/info", api.GetInfo)
2424
router.GET("/block-height", api.GetBestBlockHeight)
25+
router.GET("/block-hash/:blockheight", FetchHeaderInvMiddleware, api.GetBlockHashByHeight)
2526
router.GET("/tweaks/:blockheight", FetchHeaderInvMiddleware, api.GetTweakDataByHeight)
2627
router.GET("/tweak-index/:blockheight", FetchHeaderInvMiddleware, api.GetTweakIndexDataByHeight)
2728
router.GET("/filter/:type/:blockheight", FetchHeaderInvMiddleware, api.GetCFilterByHeight)

0 commit comments

Comments
 (0)