This repository was archived by the owner on Jun 1, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +56
-2
lines changed Expand file tree Collapse file tree 4 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 6
6
"sync"
7
7
"time"
8
8
9
+ "github.com/btcsuite/btcutil"
10
+
9
11
"github.com/btcsuite/btcd/chaincfg/chainhash"
10
12
11
13
"github.com/ledgerhq/satstack/config"
@@ -336,3 +338,47 @@ func (b *Bus) descriptors(account config.Account) ([]descriptor, error) {
336
338
337
339
return ret , nil
338
340
}
341
+
342
+ // RunTheNumbers performs inflation checks against the connected full node.
343
+ //
344
+ // It does NOT perform any equality comparison between expected and actual
345
+ // supply.
346
+ func (b * Bus ) RunTheNumbers () error {
347
+ client := b .getClient ()
348
+ defer b .recycleClient (client )
349
+
350
+ log .Info ("Running inflation checks" )
351
+
352
+ info , err := client .GetTxOutSetInfo ()
353
+ if err != nil {
354
+ return err
355
+ }
356
+
357
+ const halvingBlocks = 210000
358
+
359
+ var (
360
+ subsidy float64 = 50
361
+ supply float64 = 0
362
+ )
363
+
364
+ i := int64 (0 )
365
+ for ; i < info .Height / halvingBlocks ; i ++ {
366
+ supply += halvingBlocks * subsidy
367
+ subsidy /= 2
368
+ }
369
+
370
+ supply += subsidy * float64 (info .Height - (halvingBlocks * i ))
371
+
372
+ supplyBTC , err := btcutil .NewAmount (supply )
373
+ if err != nil {
374
+ return err
375
+ }
376
+
377
+ log .WithFields (log.Fields {
378
+ "height" : info .Height ,
379
+ "expectedSupply" : supplyBTC ,
380
+ "actualSupply" : info .TotalAmount ,
381
+ }).Info ("#RunTheNumbers OK️" )
382
+
383
+ return nil
384
+ }
Original file line number Diff line number Diff line change @@ -68,6 +68,12 @@ func main() {
68
68
69
69
b .Status = bus .PendingScan
70
70
71
+ if err := b .RunTheNumbers (); err != nil {
72
+ log .WithFields (log.Fields {
73
+ "error" : err ,
74
+ }).Fatal ("Inflation checks failed" )
75
+ }
76
+
71
77
// Skip import of descriptors, if no account config found. SatStack
72
78
// will run in zero-configuration mode.
73
79
if configuration .Accounts == nil {
Original file line number Diff line number Diff line change @@ -19,3 +19,5 @@ require (
19
19
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
20
20
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
21
21
)
22
+
23
+ replace github.com/btcsuite/btcd v0.21.0-beta.0.20200925161806-e9a51e8dcd67 => github.com/onyb/btcd v0.20.1-beta.0.20200928132705-7b5f3feb11c0
Original file line number Diff line number Diff line change 1
1
github.com/aead/siphash v1.0.1 /go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII =
2
2
github.com/btcsuite/btcd v0.20.1-beta /go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ =
3
- github.com/btcsuite/btcd v0.21.0-beta.0.20200925161806-e9a51e8dcd67 h1:Dl9SKb/DS8dGvQgpCCgBXbgE05OAsl8fqMgBFwsI2wo =
4
- github.com/btcsuite/btcd v0.21.0-beta.0.20200925161806-e9a51e8dcd67 /go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94 =
5
3
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo =
6
4
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f /go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA =
7
5
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d /go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg =
@@ -83,6 +81,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
83
81
github.com/onsi/gomega v1.4.1 /go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA =
84
82
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU =
85
83
github.com/onsi/gomega v1.4.3 /go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY =
84
+ github.com/onyb/btcd v0.20.1-beta.0.20200928132705-7b5f3feb11c0 h1:0LJRBFvQaMFjoa6iADdYLrq6SzeyqCp+RTmhy6zuqJU =
85
+ github.com/onyb/btcd v0.20.1-beta.0.20200928132705-7b5f3feb11c0 /go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94 =
86
86
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc =
87
87
github.com/patrickmn/go-cache v2.1.0+incompatible /go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ =
88
88
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
You can’t perform that action at this time.
0 commit comments