Skip to content

Commit

Permalink
fix estimatefees: should never return null.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Jul 16, 2024
1 parent feeff0b commit 726f07e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ apt install lightningd
mkdir -p ~/.lightning/plugins
echo 'disable-plugin=bcli' >> .lightning/config
cd ~/.lightning/plugins
wget https://github.com/nbd-wtf/trustedcoin/releases/download/v0.8.0/trustedcoin-v0.8.0-linux-amd64.tar.gz
tar -xvf trustedcoin-v0.8.0-linux-amd64.tar.gz
wget https://github.com/nbd-wtf/trustedcoin/releases/download/v0.8.1/trustedcoin-v0.8.1-linux-amd64.tar.gz
tar -xvf trustedcoin-v0.8.1-linux-amd64.tar.gz
cd
lightningd
```
57 changes: 24 additions & 33 deletions estimatefees.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

type EstimatedFees struct {
FeeRateFloor *int `json:"feerate_floor"`
FeeRates []struct {
Blocks *int `json:"blocks"`
FeeRate *int `json:"feerate"`
} `json:"feerates"`
FeeRateFloor int `json:"feerate_floor"`
FeeRates []FeeRate `json:"feerates"`
}

var intp = func(x int) *int { return &x }
type FeeRate struct {
Blocks int `json:"blocks"`
FeeRate int `json:"feerate"`
}

func getFeeRates() (*EstimatedFees, error) {
// try bitcoind first
Expand All @@ -28,21 +28,17 @@ func getFeeRates() (*EstimatedFees, error) {
if err2 == nil && err6 == nil && err12 == nil && err100 == nil &&
in2.FeeRate != nil && in6.FeeRate != nil && in12.FeeRate != nil && in100.FeeRate != nil {

satPerKbP := func(r *btcjson.EstimateSmartFeeResult) *int {
x := int(*r.FeeRate * float64(100000000))
return &x
satPerKbP := func(r *btcjson.EstimateSmartFeeResult) int {
return int(*r.FeeRate * float64(100000000))
}

return &EstimatedFees{
FeeRateFloor: satPerKbP(in100),
FeeRates: []struct {
Blocks *int `json:"blocks"`
FeeRate *int `json:"feerate"`
}{
{Blocks: intp(2), FeeRate: satPerKbP(in2)},
{Blocks: intp(6), FeeRate: satPerKbP(in6)},
{Blocks: intp(12), FeeRate: satPerKbP(in12)},
{Blocks: intp(100), FeeRate: satPerKbP(in100)},
FeeRates: []FeeRate{
{Blocks: 2, FeeRate: satPerKbP(in2)},
{Blocks: 6, FeeRate: satPerKbP(in6)},
{Blocks: 12, FeeRate: satPerKbP(in12)},
{Blocks: 100, FeeRate: satPerKbP(in100)},
},
}, nil
}
Expand All @@ -55,24 +51,19 @@ func getFeeRates() (*EstimatedFees, error) {
return nil, err
}

var (
slow = int(feerates["504"] * 1000)
normal = int(feerates["10"] * 1000)
urgent = int(feerates["5"] * 1000)
very_urgent = int(feerates["2"] * 1000)
)

// actually let's be a little more patient here than sauron is
slow := int(feerates["504"] * 1000)
normal := int(feerates["10"] * 1000)
urgent := int(feerates["5"] * 1000)
veryUrgent := int(feerates["2"] * 1000)

return &EstimatedFees{
FeeRateFloor: intp(slow),
FeeRates: []struct {
Blocks *int `json:"blocks"`
FeeRate *int `json:"feerate"`
}{
{Blocks: intp(2), FeeRate: intp(very_urgent)},
{Blocks: intp(5), FeeRate: intp(urgent)},
{Blocks: intp(10), FeeRate: intp(normal)},
{Blocks: intp(504), FeeRate: intp(slow)},
FeeRateFloor: slow,
FeeRates: []FeeRate{
{Blocks: 2, FeeRate: veryUrgent},
{Blocks: 5, FeeRate: urgent},
{Blocks: 10, FeeRate: normal},
{Blocks: 504, FeeRate: slow},
},
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/fiatjaf/lightningd-gjson-rpc/plugin"
)

const version = "0.8.0"
const version = "0.8.1"

var (
network string
Expand Down

0 comments on commit 726f07e

Please sign in to comment.