Skip to content

Commit

Permalink
Fix poller and change block hash type to string
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeless committed Nov 27, 2023
1 parent fa90d90 commit 3997bc8
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/sf-data
/sf.yaml
/sfbtc

/localdata
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ go 1.21.0

require (
github.com/btcsuite/btcd v0.23.4
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/spf13/cobra v1.8.0
github.com/streamingfast/bstream v0.0.2-0.20231123130020-ad84cce9666d
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80
github.com/streamingfast/firehose-core v0.2.4-0.20231123151954-5bd6074c6f6d
github.com/streamingfast/firehose-core v0.2.4-0.20231127172139-31d5902bc074
github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091
github.com/streamingfast/shutter v1.5.0
github.com/stretchr/testify v1.8.4
github.com/test-go/testify v1.1.4
go.uber.org/zap v1.26.0
google.golang.org/protobuf v1.31.0
)
Expand Down Expand Up @@ -47,7 +50,6 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/btcutil v1.1.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/bufbuild/connect-go v1.10.0 // indirect
Expand Down Expand Up @@ -172,7 +174,6 @@ require (
github.com/streamingfast/sf-tracing v0.0.0-20230616174903-cd2ade641ca9 // indirect
github.com/streamingfast/snapshotter v0.0.0-20230316190750-5bcadfde44d0 // indirect
github.com/streamingfast/substreams v1.1.21-0.20231122013157-938ec26b0ef6 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf // indirect
github.com/tetratelabs/wazero v1.1.0 // indirect
Expand Down Expand Up @@ -230,3 +231,4 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/btcsuite/btcd => github.com/streamingfast/btcd v0.0.0-20231127171849-2aa489ba183d
28 changes: 9 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,19 @@ github.com/blendle/zapdriver v1.3.2-0.20200203083823-9200777f8a3d h1:fSlGu5ePbkj
github.com/blendle/zapdriver v1.3.2-0.20200203083823-9200777f8a3d/go.mod h1:yCBkgASmKHgUOFjK9h1sOytUVgA+JkQjqj3xYP4AdWY=
github.com/bobg/go-generics/v2 v2.1.1 h1:4rN9upY6Xm4TASSMeH+NzUghgO4h/SbNrQphIjRd/R0=
github.com/bobg/go-generics/v2 v2.1.1/go.mod h1:iPMSRVFlzkJSYOCXQ0n92RA3Vxw0RBv2E8j9ZODXgHk=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.4 h1:IzV6qqkfwbItOS/sg/aDfPDsjPP8twrCOE2R93hxMlQ=
github.com/btcsuite/btcd v0.23.4/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
github.com/btcsuite/btcd/btcutil v1.1.0 h1:MO4klnGY+EWJdoWF12Wkuf4AWDBPMpZNeN/jRLrklUU=
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
Expand Down Expand Up @@ -207,7 +199,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -386,6 +377,8 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
Expand All @@ -410,7 +403,6 @@ github.com/ipfs/go-cid v0.4.0 h1:a4pdZq0sx6ZSxbCizebnKiMCx/xI/aBBFlB73IgH4rA=
github.com/ipfs/go-cid v0.4.0/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/ipfs/go-ipfs-api v0.6.0 h1:JARgG0VTbjyVhO5ZfesnbXv9wTcMvoKRBLF1SzJqzmg=
github.com/ipfs/go-ipfs-api v0.6.0/go.mod h1:iDC2VMwN9LUpQV/GzEeZ2zNqd8NUdRmWcFM+K/6odf0=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jhump/gopoet v0.0.0-20190322174617-17282ff210b3/go.mod h1:me9yfT6IJSlOL3FCfrg+L6yzUEZ+5jW6WHt4Sk+UPUI=
github.com/jhump/gopoet v0.1.0/go.mod h1:me9yfT6IJSlOL3FCfrg+L6yzUEZ+5jW6WHt4Sk+UPUI=
Expand Down Expand Up @@ -530,7 +522,6 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
Expand Down Expand Up @@ -598,6 +589,8 @@ github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jH
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/streamingfast/bstream v0.0.2-0.20231123130020-ad84cce9666d h1:BvvIKTekSj8PAAda313Q6xd91w3gD1nDgOrG/5+YIZk=
github.com/streamingfast/bstream v0.0.2-0.20231123130020-ad84cce9666d/go.mod h1:08GVb+DXyz6jVNIsbf+2zlaC81UeEGu5o1h49KrSR3Y=
github.com/streamingfast/btcd v0.0.0-20231127171849-2aa489ba183d h1:1S0/NRRqh+a8vv7ioAMqpULlSeLE64nLhi8WMfbx5d4=
github.com/streamingfast/btcd v0.0.0-20231127171849-2aa489ba183d/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80 h1:UxJUTcEVkdZy8N77E3exz0iNlgQuxl4m220GPvzdZ2s=
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80/go.mod h1:QxjVH73Lkqk+mP8bndvhMuQDUINfkgsYhdCH/5TJFKI=
github.com/streamingfast/dauth v0.0.0-20230929180355-921f9c9be330 h1:49JYZkn8ALGe+LhcACZyX3L9B8tIxRZ3F3l+OxmNMhY=
Expand All @@ -618,12 +611,10 @@ github.com/streamingfast/dstore v0.1.1-0.20230620124109-3924b3b36c77 h1:u7FWLqz3
github.com/streamingfast/dstore v0.1.1-0.20230620124109-3924b3b36c77/go.mod h1:ngKU7WzHwVjOFpt2g+Wtob5mX4IvN90HYlnARcTRbmQ=
github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839 h1:K6mJPvh1jAL+/gBS7Bh9jyzWaTib6N47m06gZOTUPwQ=
github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839/go.mod h1:huOJyjMYS6K8upTuxDxaNd+emD65RrXoVBvh8f1/7Ns=
github.com/streamingfast/firehose-core v0.2.4-0.20231122193040-e2de0951c3e7 h1:W2JNHp1WRK9wfDZcQBzyAgNmdohbB5chaGQsE1oVXAI=
github.com/streamingfast/firehose-core v0.2.4-0.20231122193040-e2de0951c3e7/go.mod h1:kMwSujvQmtOaoCelp6BcRDyCcbKikTfs4OfDJb+oPPI=
github.com/streamingfast/firehose-core v0.2.4-0.20231123130335-3f07b24b6efe h1:01N9YZm5tmvHcVgVT4DsmXskP/dQioFNUfakr9UBUo4=
github.com/streamingfast/firehose-core v0.2.4-0.20231123130335-3f07b24b6efe/go.mod h1:A/uMNtHi+mTEgpqE9I5eyUPJbqcOCH1dV7IHVy/M+Wo=
github.com/streamingfast/firehose-core v0.2.4-0.20231123151954-5bd6074c6f6d h1:enkMiKoNVGCv9OQGDEUWhXcs0PJluRoowmClZgECQ0U=
github.com/streamingfast/firehose-core v0.2.4-0.20231123151954-5bd6074c6f6d/go.mod h1:A/uMNtHi+mTEgpqE9I5eyUPJbqcOCH1dV7IHVy/M+Wo=
github.com/streamingfast/firehose-core v0.2.4-0.20231127172139-31d5902bc074 h1:MNptL3h5Vko07pUMkjnwyhbGh+/vnpXGDrwrr08rjhY=
github.com/streamingfast/firehose-core v0.2.4-0.20231127172139-31d5902bc074/go.mod h1:A/uMNtHi+mTEgpqE9I5eyUPJbqcOCH1dV7IHVy/M+Wo=
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0 h1:g8eEYbFSykyzIyuxNMmHEUGGUvJE0ivmqZagLDK42gw=
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0/go.mod h1:cTNObq2Uofb330y05JbbZZ6RwE6QUXw5iVcHk1Fx3fk=
github.com/streamingfast/logging v0.0.0-20210811175431-f3b44b61606a/go.mod h1:4GdqELhZOXj4xwc4IaBmzofzdErGynnaSzuzxy0ZIBo=
Expand Down Expand Up @@ -660,6 +651,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
Expand Down Expand Up @@ -733,7 +725,6 @@ go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -787,7 +778,6 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
3 changes: 1 addition & 2 deletions pb/sf/bitcoin/type/v1/type.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pbbtc

import (
"encoding/hex"
"fmt"
"time"

Expand Down Expand Up @@ -39,7 +38,7 @@ func (b *Block) ToBstreamBlock() (*pbbstream.Block, error) {

return &pbbstream.Block{
Number: blkNum,
Id: hex.EncodeToString(b.Hash),
Id: b.Hash,
ParentId: b.PreviousHash,
Timestamp: timestamppb.New(time.Unix(b.Time, 0)),
LibNum: libNum,
Expand Down
10 changes: 6 additions & 4 deletions pb/sf/bitcoin/type/v1/type.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 37 additions & 27 deletions poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package poller
import (
"context"
"fmt"
"time"

"github.com/btcsuite/btcd/rpcclient"
"github.com/streamingfast/bstream"
Expand All @@ -22,17 +21,16 @@ type Reader struct {
startBlockNum uint64
rpcClient *rpcclient.Client
logger *zap.Logger
shutter *shutter.Shutter
}

func New(endpoint string, blockFetchRetryCount uint64, stateStoragePath string, startBlockNum uint64, logger *zap.Logger) *Reader {
return &Reader{
shutter: shutter.New(),
Shutter: shutter.New(),
endpoint: endpoint,
blockFetchRetryCount: blockFetchRetryCount,
stateStoragePath: stateStoragePath,
startBlockNum: startBlockNum,
logger: logger.Named("reader"),
logger: logger.Named("poller"),
}
}

Expand All @@ -55,11 +53,10 @@ func (r *Reader) Run(ctx context.Context) error {
})

connCfg := &rpcclient.ConnConfig{
Host: r.endpoint,
//User: "yourrpcuser",
//Pass: "yourrpcpass",
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
DisableTLS: true, // Bitcoin core does not provide TLS by default
Host: r.endpoint,
DisableAuth: true,
HTTPPostMode: true,
DisableTLS: true,
}

client, err := rpcclient.New(connCfg, nil)
Expand All @@ -78,17 +75,20 @@ func (r *Reader) Run(ctx context.Context) error {
return bp.Run(ctx, r.startBlockNum, finalizedBlk)
}

func (r *Reader) PollingInterval() time.Duration {
return 7 * time.Minute
}

func (r *Reader) GetFinalizedBlock() (bstream.BlockRef, error) {

blockHash, blockNum, err := r.rpcClient.GetBestBlock()
bestBlockHash, err := r.rpcClient.GetBestBlockHash()
if err != nil {
return nil, fmt.Errorf("unable to get best block hash: %w", err)
}
r.logger.Info("found best block hash", zap.Stringer("blockhash", bestBlockHash))

bestBlock, err := r.rpcClient.GetBlockVerbose(bestBlockHash)
if err != nil {
return nil, fmt.Errorf("unable to get best block: %w", err)
return nil, fmt.Errorf("unable to get best block %s: %w", bestBlockHash.String(), err)
}
return bstream.NewBlockRef(blockHash.String(), uint64(blockNum)), nil

return bstream.NewBlockRef(bestBlockHash.String(), uint64(bestBlock.Height)), nil
}

func (r *Reader) Fetch(_ context.Context, blkNum uint64) (*pbbstream.Block, error) {
Expand All @@ -98,15 +98,19 @@ func (r *Reader) Fetch(_ context.Context, blkNum uint64) (*pbbstream.Block, erro
return nil, fmt.Errorf("unable to get block hash for block %d: %w", blkNum, err)
}

r.logger.Debug("found block", zap.Uint64("block_num", blkNum))

rpcBlk, err := r.rpcClient.GetBlockVerboseTx(blkHash)
if err != nil {
return nil, fmt.Errorf("unable to get block %d (%s): %w", blkNum, blkHash.String(), err)
}

r.logger.Debug("found block",
zap.Int64("block_num", rpcBlk.Height),
zap.String("block_hash", rpcBlk.Hash),
zap.String("prev_hash", rpcBlk.PreviousHash),
)

blk := &pbbitcoin.Block{
Hash: blkHash.CloneBytes(),
Hash: blkHash.String(),
Size: rpcBlk.Size,
StrippedSize: rpcBlk.StrippedSize,
Weight: rpcBlk.Weight,
Expand Down Expand Up @@ -144,17 +148,23 @@ func (r *Reader) Fetch(_ context.Context, blkNum uint64) (*pbbstream.Block, erro
}

for _, vin := range tx.Vin {
trx.Vin = append(trx.Vin, &pbbitcoin.Vin{
Txid: vin.Txid,
Vout: vin.Vout,
ScriptSig: &pbbitcoin.ScriptSig{
Asm: vin.ScriptSig.Asm,
Hex: vin.ScriptSig.Hex,
},
pbvin := &pbbitcoin.Vin{
Txid: vin.Txid,
Vout: vin.Vout,
Sequence: vin.Sequence,
Txinwitness: vin.Witness,
Coinbase: vin.Coinbase,
})
}

if vin.ScriptSig != nil {
pbvin.ScriptSig = &pbbitcoin.ScriptSig{
Asm: vin.ScriptSig.Asm,
Hex: vin.ScriptSig.Hex,
}
}

trx.Vin = append(trx.Vin)

}

for _, vout := range tx.Vout {
Expand Down
4 changes: 3 additions & 1 deletion proto/sf/bitcoin/type/v1/type.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import "google/protobuf/timestamp.proto";

message Block {
//the block hash
bytes hash = 1;
// Bitcoin core reverses the byte order of the hash when printing it out has Hex, to prevent
// the end user from making a mistake we store it as a string directly
string hash = 1;

// NON-DETERMINISTIC: The number of confirmations, or -1 if the block is not on the main chain
// int64 confirmations = 2;
Expand Down

0 comments on commit 3997bc8

Please sign in to comment.