Add some blockchain RPC handlers and DB fetching routines #55

Merged
moodyjon merged 15 commits from blockchain_rpc1 into master 2022-09-14 17:23:35 +02:00
moodyjon commented 2022-08-29 22:00:04 +02:00 (Migrated from github.com)

Mempool transactions fetching is not implemented yet.

Fixes #52

Now integrated with basic gorilla/rpc support.

Mempool transactions fetching is not implemented yet. Fixes #52 Now integrated with basic gorilla/rpc support.
lyoshenka (Migrated from github.com) reviewed 2022-08-29 22:00:04 +02:00
moodyjon commented 2022-09-01 21:29:34 +02:00 (Migrated from github.com)

Tests are currently based on a snapshot of mainnet at height 599529. I just picked out a couple of addresses I saw in the block explorer. Still looking for a better way to get test data. The regression tests in lbry-sdk cleanup after every test if I am not mistaken, so it's not so easy to get a sizable test data set.

=== RUN   TestGetBalance
...snip...
time="2022-09-01T14:30:40-05:00" level=info msg="len(db.TxCounts), cap(db.TxCounts): 599530 1200000"
time="2022-09-01T14:30:40-05:00" level=info msg="Time to get txCounts: 591.624125ms"
    blockchain_test.go:108: address: bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG resp: {
            "confirmed": 100000000000,
            "unconfirmed": 0
        }
    blockchain_test.go:108: address: bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV resp: {
            "confirmed": 43284,
            "unconfirmed": 0
        }
--- PASS: TestGetBalance (9.80s)
=== RUN   TestGetHistory
...snip...
time="2022-09-01T14:30:50-05:00" level=info msg="len(db.TxCounts), cap(db.TxCounts): 599530 1200000"
time="2022-09-01T14:30:50-05:00" level=info msg="Time to get txCounts: 660.530541ms"
    blockchain_test.go:144: address: bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG resp: {
            "confirmed": [
                {
                    "tx_hash": "c7b866b0b4a9ab5aa236e7f2918affa341c492cfc09f9e0336d80a10df894716",
                    "height": 588897
                }
            ],
            "unconfirmed": []
        }
    blockchain_test.go:144: address: bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV resp: {
            "confirmed": [
                {
                    "tx_hash": "4747d58e6bfcaa75fa78f05b2bbc9353aa22b3fd6cfc84d280d6cc6f1c88725c",
                    "height": 586663
                },
                {
                    "tx_hash": "7647ab721b1b73dc83cbb3e4d1b4449565b6e44acb5a4bb1885cc77864c30774",
                    "height": 586663
                }
            ],
            "unconfirmed": []
        }
--- PASS: TestGetHistory (10.10s)
=== RUN   TestListUnspent
...snip...
time="2022-09-01T14:31:00-05:00" level=info msg="len(db.TxCounts), cap(db.TxCounts): 599530 1200000"
time="2022-09-01T14:31:00-05:00" level=info msg="Time to get txCounts: 587.998333ms"
    blockchain_test.go:180: address: bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG resp: [
            {
                "tx_hash": "c7b866b0b4a9ab5aa236e7f2918affa341c492cfc09f9e0336d80a10df894716",
                "tx_pos": 0,
                "height": 588897,
                "value": 100000000000
            }
        ]
    blockchain_test.go:180: address: bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV resp: [
            {
                "tx_hash": "a2b9847d5278d30f974248866305f3490a470d8403fcd6e719c86743af880dbd",
                "tx_pos": 6,
                "height": 42100,
                "value": 43284
            }
        ]
--- PASS: TestListUnspent (9.91s)
Tests are currently based on a snapshot of mainnet at height 599529. I just picked out a couple of addresses I saw in the block explorer. Still looking for a better way to get test data. The regression tests in lbry-sdk cleanup after every test if I am not mistaken, so it's not so easy to get a sizable test data set. ``` === RUN TestGetBalance ...snip... time="2022-09-01T14:30:40-05:00" level=info msg="len(db.TxCounts), cap(db.TxCounts): 599530 1200000" time="2022-09-01T14:30:40-05:00" level=info msg="Time to get txCounts: 591.624125ms" blockchain_test.go:108: address: bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG resp: { "confirmed": 100000000000, "unconfirmed": 0 } blockchain_test.go:108: address: bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV resp: { "confirmed": 43284, "unconfirmed": 0 } --- PASS: TestGetBalance (9.80s) === RUN TestGetHistory ...snip... time="2022-09-01T14:30:50-05:00" level=info msg="len(db.TxCounts), cap(db.TxCounts): 599530 1200000" time="2022-09-01T14:30:50-05:00" level=info msg="Time to get txCounts: 660.530541ms" blockchain_test.go:144: address: bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG resp: { "confirmed": [ { "tx_hash": "c7b866b0b4a9ab5aa236e7f2918affa341c492cfc09f9e0336d80a10df894716", "height": 588897 } ], "unconfirmed": [] } blockchain_test.go:144: address: bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV resp: { "confirmed": [ { "tx_hash": "4747d58e6bfcaa75fa78f05b2bbc9353aa22b3fd6cfc84d280d6cc6f1c88725c", "height": 586663 }, { "tx_hash": "7647ab721b1b73dc83cbb3e4d1b4449565b6e44acb5a4bb1885cc77864c30774", "height": 586663 } ], "unconfirmed": [] } --- PASS: TestGetHistory (10.10s) === RUN TestListUnspent ...snip... time="2022-09-01T14:31:00-05:00" level=info msg="len(db.TxCounts), cap(db.TxCounts): 599530 1200000" time="2022-09-01T14:31:00-05:00" level=info msg="Time to get txCounts: 587.998333ms" blockchain_test.go:180: address: bCoyqs8Pv4pss5EbNuyuokkdkCqEpDoHmG resp: [ { "tx_hash": "c7b866b0b4a9ab5aa236e7f2918affa341c492cfc09f9e0336d80a10df894716", "tx_pos": 0, "height": 588897, "value": 100000000000 } ] blockchain_test.go:180: address: bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV resp: [ { "tx_hash": "a2b9847d5278d30f974248866305f3490a470d8403fcd6e719c86743af880dbd", "tx_pos": 6, "height": 42100, "value": 43284 } ] --- PASS: TestListUnspent (9.91s) ```
moodyjon commented 2022-09-07 22:13:43 +02:00 (Migrated from github.com)

More or less ready for review. Need to see whether the gorilla/rpc integration works (does the right method get called, etc).

More or less ready for review. Need to see whether the gorilla/rpc integration works (does the right method get called, etc).
moodyjon commented 2022-09-08 19:05:10 +02:00 (Migrated from github.com)

Here are some manual tests showing the RPC handlers are registered & called:

swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.get_chunk", "params":[0], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc             
{"result":"010000000000000000000000000000000000000000000000000000000000000000000000cc59e59ff97ac092b55e423aa5495151ed6fb80570a5bb78cd5bd1c3821c21b8010000000000000000000000000000000000000000000000000000000000000033193156ffff001f070500000000002063f4346a4db34fdfce29a70f5e8d11f065f6b91602b7036c7f22f3a03b28899cba888e2f9c037f831046f8ad09f6d378f79c728d003b177a64d29621f481da5d01000000000000000000000000000000000000000000000000000000000000003c406b5746e1001f5b4f000000000020246cb85843ac936d55388f2ff288b011add5b1b20cca9cfd19a403ca2c9ecbde09d8734d81b5f2eb1b653caf17491544ddfbc72f2f4c0c3f22a3362db5ba9d4701000000000000000000000000000000000000000000000000000000000000003d406b57ffff001f4ff20000000000200044e1258b865d262587c28ff98853bc52bb31266230c1c648cc9004047a5[...snip...]b80ac0801000000000000000000000000000000000000000000000000000000000000009d536b57880b201da339ba000000002059d8db981097fcb9320789087be66766c02323f2dfd9b48a44b18c3b48515b86f131ae91a4e922fb75913c1f5c00f3de43d547534f97fdf0aba06d19aaf2f6980100000000000000000000000000000000000000000000000000000000000000d7536b573f7b1d1d648ed9000000002076550868bb84f856cacb5832dd6436952fe999d22db2e207e65cd7a074810212c58ea8159e744bf4f0b6785f498e3cfe3e1de2a3094a23ac64c6ed151496839f01000000000000000000000000000000000000000000000000000000000000004f546b57c8511b1d9675c801","error":null,"id":1}

swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.get_header", "params":[10], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc
{"result":{"version":536870912,"prev_block_hash":"fdab1b38bcf236bc85b6bcd52fe8ec19bcb0b6c7352e913de05fa5a4e5ae8d55","merkle_root":"f4d8fded6a181d4a8a2817a0eb423cc0f414af29490004a620e66c35c498a554","claim_trie_root":"0000000000000000000000000000000000000000000000000000000000000001","timestamp":1466646593,"bits":509349720,"nonce":75838,"block_height":10},"error":null,"id":1}

swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.headers", "params":[{"start_height":10,"count":10,"cp_height":20,"b64":false}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc
{"result":{"hex":"00000020558daee5a4a55fe03d912e35c7b6b0bc19ece82fd5bcb685bc36f2bc381babfd54a598c4356ce620a604004929af14f4c03c42eba017288a4a1d186aedfdd8f4010000000000000000000000000000000000000000000000000000000000000041406b57580f5c1e3e280100000000200381bfc0b2f10c9a3c0fc2dc8ad06388aff8ea5a9f7dba6a945073b021796197364b79f33ff3f3a7ccb676fc0a37b7d831bd5942a05eac314658c6a7e4c4b1a4010000000000000000000000000000000000000000000000000000000000000041406b574303511ec0ae0100000000202aae02063ae0f1025e6acecd5e8e2305956ecaefd185bb47a64ea2ae953233891df3d4c1fc547ab3bbca027c8bbba744c051add8615d289b567f97c64929dcf2010000000000000000000000000000000000000000000000000000000000000042406b578c4a471e04ee00000000002016603ef45d5a7c02bfbb30f422016746872ff37f8b0b5824a0f70caa668eea5415aad300e70f7d8755d93645d1fd21eda9c40c5d0ed797acd0e07ace34585aaf010000000000000000000000000000000000000000000000000000000000000042406b577bbc3e1ea163000000000020cad8863b312914f2fd2aad6e9420b64859039effd67ac4681a7cf60e42b09b7e7bafa1e8d5131f477785d8338294da0f998844a85b39d2426e839b370e014e3b010000000000000000000000000000000000000000000000000000000000000042406b573935371e20e900000000002053d5e608ce5a12eda5931f86ee81198fdd231fea64cf096e9aeae321cf2efbe241e888d5aaf495e4c2a9f11b932db979d7483aeb446f479179b0c0b8d24bfa0e010000000000000000000000000000000000000000000000000000000000000045406b573c95301e34af0a0000000020df0e494c02ff79e3929bc1f2491077ec4f6a607d7a1a5e1be96536642c98f86e533febd715f8a234028fd52046708551c6b6ac415480a6568aaa35cb94dc720301000000000000000000000000000000000000000000000000000000000000004f406b57c4c02a1ec54d230000000020341f7d8e7d242e5e46343c40840c44f07e7e7306eb2355521b51502e8070e569485ba7eec4efdff0fc755af6e73e38b381a88b0925a68193a25da19d0f616e9f010000000000000000000000000000000000000000000000000000000000000050406b575be8251e1f61010000000020cd399f8078166ca5f0bdd1080ab1bb22d3c271b9729b6000b44f4592cc9fab08c00ebab1e7cd88677e3b77c1598c7ac58660567f49f3a30ec46a48a1ae7652fe010000000000000000000000000000000000000000000000000000000000000052406b57d55b211e6f53090000000020c6c14ed4a53bbb4f181acf2bbfd8b74d13826732f2114140ca99ca371f7dd87c51d18a05a1a6ffa37c041877fa33c2229a45a0ab66b5530f914200a8d6639a6f010000000000000000000000000000000000000000000000000000000000000055406b570d5b1d1eff1c0900","count":10,"max":40960},"error":null,"id":1}

swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.headers", "params":[{"start_height":10,"count":10,"cp_height":20,"b64":true}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc
{"result":{"base64":"eJxiYGBQCO1d93TJ0vgHthP1TI9v27BH8s0L/at7trXuMfu0x0J69d+QpTOOmOY8U1jGwuCpuV7kywEbp9cLxDW6vGQlst7+vfGFkQE/cHTIDo/gj5Gz0wCrVGBu3H9g00eeWTb8h+50XUjuWP/jVdT82l1ZUwKKNyhWJk438678bP/58/Iz28r+cJlvv2G4N9JpQdwaQ7eIY8ufHNm4hBj7nJkD5Q6sg9intY6JzerBR6a4rHNn4/qUWafmnXp/sXW3+zK/ReumGhl3yn6+cvBPSNXm3aeYarp3L3c5ELj2RmKsxuyw+unHPDXvfCJkn5NDdniPl7scyzswV0Eswe5LbFQN0/7dBl+UGNPd2vU/13dzR6gs+M6zKq3vVYjoqssMz/lr20Nvmrle/Kv4duURnli+69PXXHhQdc4kImo9MfZV77GTW5gMse/UjTZrQ02RT3+11uZNUdjmEck87/+1qiMZUjXf+Jw2zK6rXr/wxVVheffy1hvGTVNu8c/scFkRbXnJKa95tjkfo581MfZZmprLKbyE2Bd89RnHuSiht0sny7e9a5Tsv6ss/yrlPGferFePFc/r/X7k+KLj6qovU58cWvlRerLuzsrrHlavXfLdJ1ZuOLDjkvcvPkL2uTpkh9tMNZAzWc8Ftu8+n6cP0//Kx5NmH/zkKVD+xj8robZKKk76ZapZis6MH3nB9q+vi/5YZMLUf1XBraA18Ni2NY4hDcvCulaZnp5yp4iZkH3+DtnhRw5oyR31VQbbZyJf21erohfnZmLj0MLj8qGurpjttXJokHRggF5DwdNMj+jl7468v//hT2nUt+d2FpsbV3Rzqi5rnLwoduFc/sS8+YTsC3DIDo9+oSonnwhJn2ct5zdUiOUs/bD3IgfXxt1Klw8V7iyancCwxd910pn5qzkO8O3a+PxsR3qddfnByJ6qo20JYfWenxfzHcnyWLiuLOgfIfuCHLLDr0YryuUHc4LtO3bQ78pS693+ElLntfff2O4r3JRu9EnQ0eHUzFPm8rU3agIvdrEuXPZ/cQ2LRPkv40NKs1wXrE7bGsw/0YlhxbXkWfmE7At1yA7njZaV+y/DyQAIAAD//1kpZYU=","count":10,"max":40960},"error":null,"id":1}

swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.get_balance", "params":[{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc
{"result":{"confirmed":43284,"unconfirmed":0},"error":null,"id":1}

swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.get_history", "params":[{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc
{"result":{"confirmed":[{"tx_hash":"5c72881c6fccd680d284fc6cfdb322aa5393bc2b5bf078fa75aafc6b8ed54747","height":586663},{"tx_hash":"7407c36478c75c88b14b5acb4ae4b6659544b4d1e4b3cb83dc731b1b72ab4776","height":586663}],"unconfirmed":[]},"error":null,"id":1}

swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.listunspent", "params":[{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc
{"result":[{"tx_hash":"bd0d88af4367c819e7d6fc03840d470a49f30563864842970fd378527d84b9a2","tx_pos":6,"height":42100,"value":43284}],"error":null,"id":1}
Here are some manual tests showing the RPC handlers are registered & called: ``` swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.get_chunk", "params":[0], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":"010000000000000000000000000000000000000000000000000000000000000000000000cc59e59ff97ac092b55e423aa5495151ed6fb80570a5bb78cd5bd1c3821c21b8010000000000000000000000000000000000000000000000000000000000000033193156ffff001f070500000000002063f4346a4db34fdfce29a70f5e8d11f065f6b91602b7036c7f22f3a03b28899cba888e2f9c037f831046f8ad09f6d378f79c728d003b177a64d29621f481da5d01000000000000000000000000000000000000000000000000000000000000003c406b5746e1001f5b4f000000000020246cb85843ac936d55388f2ff288b011add5b1b20cca9cfd19a403ca2c9ecbde09d8734d81b5f2eb1b653caf17491544ddfbc72f2f4c0c3f22a3362db5ba9d4701000000000000000000000000000000000000000000000000000000000000003d406b57ffff001f4ff20000000000200044e1258b865d262587c28ff98853bc52bb31266230c1c648cc9004047a5[...snip...]b80ac0801000000000000000000000000000000000000000000000000000000000000009d536b57880b201da339ba000000002059d8db981097fcb9320789087be66766c02323f2dfd9b48a44b18c3b48515b86f131ae91a4e922fb75913c1f5c00f3de43d547534f97fdf0aba06d19aaf2f6980100000000000000000000000000000000000000000000000000000000000000d7536b573f7b1d1d648ed9000000002076550868bb84f856cacb5832dd6436952fe999d22db2e207e65cd7a074810212c58ea8159e744bf4f0b6785f498e3cfe3e1de2a3094a23ac64c6ed151496839f01000000000000000000000000000000000000000000000000000000000000004f546b57c8511b1d9675c801","error":null,"id":1} swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.get_header", "params":[10], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":{"version":536870912,"prev_block_hash":"fdab1b38bcf236bc85b6bcd52fe8ec19bcb0b6c7352e913de05fa5a4e5ae8d55","merkle_root":"f4d8fded6a181d4a8a2817a0eb423cc0f414af29490004a620e66c35c498a554","claim_trie_root":"0000000000000000000000000000000000000000000000000000000000000001","timestamp":1466646593,"bits":509349720,"nonce":75838,"block_height":10},"error":null,"id":1} swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.headers", "params":[{"start_height":10,"count":10,"cp_height":20,"b64":false}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":{"hex":"00000020558daee5a4a55fe03d912e35c7b6b0bc19ece82fd5bcb685bc36f2bc381babfd54a598c4356ce620a604004929af14f4c03c42eba017288a4a1d186aedfdd8f4010000000000000000000000000000000000000000000000000000000000000041406b57580f5c1e3e280100000000200381bfc0b2f10c9a3c0fc2dc8ad06388aff8ea5a9f7dba6a945073b021796197364b79f33ff3f3a7ccb676fc0a37b7d831bd5942a05eac314658c6a7e4c4b1a4010000000000000000000000000000000000000000000000000000000000000041406b574303511ec0ae0100000000202aae02063ae0f1025e6acecd5e8e2305956ecaefd185bb47a64ea2ae953233891df3d4c1fc547ab3bbca027c8bbba744c051add8615d289b567f97c64929dcf2010000000000000000000000000000000000000000000000000000000000000042406b578c4a471e04ee00000000002016603ef45d5a7c02bfbb30f422016746872ff37f8b0b5824a0f70caa668eea5415aad300e70f7d8755d93645d1fd21eda9c40c5d0ed797acd0e07ace34585aaf010000000000000000000000000000000000000000000000000000000000000042406b577bbc3e1ea163000000000020cad8863b312914f2fd2aad6e9420b64859039effd67ac4681a7cf60e42b09b7e7bafa1e8d5131f477785d8338294da0f998844a85b39d2426e839b370e014e3b010000000000000000000000000000000000000000000000000000000000000042406b573935371e20e900000000002053d5e608ce5a12eda5931f86ee81198fdd231fea64cf096e9aeae321cf2efbe241e888d5aaf495e4c2a9f11b932db979d7483aeb446f479179b0c0b8d24bfa0e010000000000000000000000000000000000000000000000000000000000000045406b573c95301e34af0a0000000020df0e494c02ff79e3929bc1f2491077ec4f6a607d7a1a5e1be96536642c98f86e533febd715f8a234028fd52046708551c6b6ac415480a6568aaa35cb94dc720301000000000000000000000000000000000000000000000000000000000000004f406b57c4c02a1ec54d230000000020341f7d8e7d242e5e46343c40840c44f07e7e7306eb2355521b51502e8070e569485ba7eec4efdff0fc755af6e73e38b381a88b0925a68193a25da19d0f616e9f010000000000000000000000000000000000000000000000000000000000000050406b575be8251e1f61010000000020cd399f8078166ca5f0bdd1080ab1bb22d3c271b9729b6000b44f4592cc9fab08c00ebab1e7cd88677e3b77c1598c7ac58660567f49f3a30ec46a48a1ae7652fe010000000000000000000000000000000000000000000000000000000000000052406b57d55b211e6f53090000000020c6c14ed4a53bbb4f181acf2bbfd8b74d13826732f2114140ca99ca371f7dd87c51d18a05a1a6ffa37c041877fa33c2229a45a0ab66b5530f914200a8d6639a6f010000000000000000000000000000000000000000000000000000000000000055406b570d5b1d1eff1c0900","count":10,"max":40960},"error":null,"id":1} swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.headers", "params":[{"start_height":10,"count":10,"cp_height":20,"b64":true}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":{"base64":"eJxiYGBQCO1d93TJ0vgHthP1TI9v27BH8s0L/at7trXuMfu0x0J69d+QpTOOmOY8U1jGwuCpuV7kywEbp9cLxDW6vGQlst7+vfGFkQE/cHTIDo/gj5Gz0wCrVGBu3H9g00eeWTb8h+50XUjuWP/jVdT82l1ZUwKKNyhWJk438678bP/58/Iz28r+cJlvv2G4N9JpQdwaQ7eIY8ufHNm4hBj7nJkD5Q6sg9intY6JzerBR6a4rHNn4/qUWafmnXp/sXW3+zK/ReumGhl3yn6+cvBPSNXm3aeYarp3L3c5ELj2RmKsxuyw+unHPDXvfCJkn5NDdniPl7scyzswV0Eswe5LbFQN0/7dBl+UGNPd2vU/13dzR6gs+M6zKq3vVYjoqssMz/lr20Nvmrle/Kv4duURnli+69PXXHhQdc4kImo9MfZV77GTW5gMse/UjTZrQ02RT3+11uZNUdjmEck87/+1qiMZUjXf+Jw2zK6rXr/wxVVheffy1hvGTVNu8c/scFkRbXnJKa95tjkfo581MfZZmprLKbyE2Bd89RnHuSiht0sny7e9a5Tsv6ss/yrlPGferFePFc/r/X7k+KLj6qovU58cWvlRerLuzsrrHlavXfLdJ1ZuOLDjkvcvPkL2uTpkh9tMNZAzWc8Ftu8+n6cP0//Kx5NmH/zkKVD+xj8robZKKk76ZapZis6MH3nB9q+vi/5YZMLUf1XBraA18Ni2NY4hDcvCulaZnp5yp4iZkH3+DtnhRw5oyR31VQbbZyJf21erohfnZmLj0MLj8qGurpjttXJokHRggF5DwdNMj+jl7468v//hT2nUt+d2FpsbV3Rzqi5rnLwoduFc/sS8+YTsC3DIDo9+oSonnwhJn2ct5zdUiOUs/bD3IgfXxt1Klw8V7iyancCwxd910pn5qzkO8O3a+PxsR3qddfnByJ6qo20JYfWenxfzHcnyWLiuLOgfIfuCHLLDr0YryuUHc4LtO3bQ78pS693+ElLntfff2O4r3JRu9EnQ0eHUzFPm8rU3agIvdrEuXPZ/cQ2LRPkv40NKs1wXrE7bGsw/0YlhxbXkWfmE7At1yA7njZaV+y/DyQAIAAD//1kpZYU=","count":10,"max":40960},"error":null,"id":1} swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.get_balance", "params":[{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":{"confirmed":43284,"unconfirmed":0},"error":null,"id":1} swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.get_history", "params":[{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":{"confirmed":[{"tx_hash":"5c72881c6fccd680d284fc6cfdb322aa5393bc2b5bf078fa75aafc6b8ed54747","height":586663},{"tx_hash":"7407c36478c75c88b14b5acb4ae4b6659544b4d1e4b3cb83dc731b1b72ab4776","height":586663}],"unconfirmed":[]},"error":null,"id":1} swdev1@Jonathans-Mac-mini herald % curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.listunspent", "params":[{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":[{"tx_hash":"bd0d88af4367c819e7d6fc03840d470a49f30563864842970fd378527d84b9a2","tx_pos":6,"height":42100,"value":43284}],"error":null,"id":1} ```
moodyjon commented 2022-09-08 19:15:04 +02:00 (Migrated from github.com)

It's on the way to being compatible with (python) herald, but I have seen some squirrelly behavior with how errors are emitted, and how params are handled:

curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.listunspent", "params":{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}, "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc 
json: cannot unmarshal object into Go value of type [1]interface {}%

It's supposed to be possible to specify params as an object/dict in jsonrpc v2. But the only thing I can get to work is:
[<json_val>]
or
[{"field1": <json_val>, "field2": <json_val>, ...}]

Also, extra params are ignored:

curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.get_header", "params":[10,10,20,false], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc
{"result":{"version":536870912,"prev_block_hash":"fdab1b38bcf236bc85b6bcd52fe8ec19bcb0b6c7352e913de05fa5a4e5ae8d55","merkle_root":"f4d8fded6a181d4a8a2817a0eb423cc0f414af29490004a620e66c35c498a554","claim_trie_root":"0000000000000000000000000000000000000000000000000000000000000001","timestamp":1466646593,"bits":509349720,"nonce":75838,"block_height":10},"error":null,"id":1}
It's on the way to being compatible with (python) herald, but I have seen some squirrelly behavior with how errors are emitted, and how params are handled: ``` curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.address.listunspent", "params":{"address":"bJr6cLth1UmR7wJ14BMc7ch73xBEEV77fV"}, "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc json: cannot unmarshal object into Go value of type [1]interface {}% ``` It's supposed to be possible to specify params as an object/dict in jsonrpc v2. But the only thing I can get to work is: `[<json_val>]` or `[{"field1": <json_val>, "field2": <json_val>, ...}]` Also, extra params are ignored: ``` curl --data-raw '{"jsonrpc":"2.0", "method":"blockchain.block.get_header", "params":[10,10,20,false], "id":1}' --header 'Content-Type: application/json' localhost:50001/rpc {"result":{"version":536870912,"prev_block_hash":"fdab1b38bcf236bc85b6bcd52fe8ec19bcb0b6c7352e913de05fa5a4e5ae8d55","merkle_root":"f4d8fded6a181d4a8a2817a0eb423cc0f414af29490004a620e66c35c498a554","claim_trie_root":"0000000000000000000000000000000000000000000000000000000000000001","timestamp":1466646593,"bits":509349720,"nonce":75838,"block_height":10},"error":null,"id":1} ```
jeffreypicard (Migrated from github.com) requested changes 2022-09-12 18:00:34 +02:00
jeffreypicard (Migrated from github.com) left a comment

see comments

see comments
jeffreypicard (Migrated from github.com) commented 2022-09-09 10:05:19 +02:00

Are these tests not running in the ci? This isn't going to work when run in the ci.

Are these tests not running in the ci? This isn't going to work when run in the ci.
jeffreypicard (Migrated from github.com) commented 2022-09-11 12:30:05 +02:00

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there.

     jsonrpc_blockchain_test.go:18: DB not found
--- SKIP: TestServerGetHeight (0.00s)
=== RUN   TestGetChunk
    jsonrpc_blockchain_test.go:48: DB not found
--- SKIP: TestGetChunk (0.00s)
=== RUN   TestGetHeader
    jsonrpc_blockchain_test.go:83: DB not found
--- SKIP: TestGetHeader (0.00s)
=== RUN   TestGetBalance
    jsonrpc_blockchain_test.go:115: DB not found
--- SKIP: TestGetBalance (0.00s)
=== RUN   TestGetHistory
    jsonrpc_blockchain_test.go:154: DB not found
--- SKIP: TestGetHistory (0.00s)
=== RUN   TestListUnspent
    jsonrpc_blockchain_test.go:193: DB not found
--- SKIP: TestListUnspent (0.00s)

let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.

So I checked out your branch and ran the tests, it all passes, but it skips these tests because the DB isn't there. ``` jsonrpc_blockchain_test.go:18: DB not found --- SKIP: TestServerGetHeight (0.00s) === RUN TestGetChunk jsonrpc_blockchain_test.go:48: DB not found --- SKIP: TestGetChunk (0.00s) === RUN TestGetHeader jsonrpc_blockchain_test.go:83: DB not found --- SKIP: TestGetHeader (0.00s) === RUN TestGetBalance jsonrpc_blockchain_test.go:115: DB not found --- SKIP: TestGetBalance (0.00s) === RUN TestGetHistory jsonrpc_blockchain_test.go:154: DB not found --- SKIP: TestGetHistory (0.00s) === RUN TestListUnspent jsonrpc_blockchain_test.go:193: DB not found --- SKIP: TestListUnspent (0.00s) ``` let's get figure out a way to get some test data in there, or at least download it or something so we can run those tests, and then this looks good.
moodyjon (Migrated from github.com) reviewed 2022-09-12 23:14:23 +02:00
moodyjon (Migrated from github.com) commented 2022-09-12 23:14:23 +02:00

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history".

I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.

I have a technique to get test data from lbry-sdk test "test_variety_of_transactions_and_longish_history". I'm waiting for the EffectiveAmount & RepostedCount to be stabilized. Then I will regenerate from that version of scribe.
moodyjon (Migrated from github.com) reviewed 2022-09-13 22:08:13 +02:00
moodyjon (Migrated from github.com) commented 2022-09-13 22:08:13 +02:00

Added sample data from lbry-sdk integration test. Reworked tests to match.

Added sample data from lbry-sdk integration test. Reworked tests to match.
moodyjon commented 2022-09-13 22:50:07 +02:00 (Migrated from github.com)

spv17 is down (for upgrade?), so I added a Skip if the ping fails:

    udp_test.go:43: ping failed: read udp 172.17.0.2:34175->216.19.244.226:50001: i/o timeout
[1935](https://github.com/lbryio/herald.go/actions/runs/3048223395/jobs/4913052275#step:3:1936)
--- PASS: TestUDPPing (1.03s)
[1936](https://github.com/lbryio/herald.go/actions/runs/3048223395/jobs/4913052275#step:3:1937)
    --- SKIP: TestUDPPing/Correctly_parse_information_from_production_server. (1.03s)
spv17 is down (for upgrade?), so I added a Skip if the ping fails: ``` udp_test.go:43: ping failed: read udp 172.17.0.2:34175->216.19.244.226:50001: i/o timeout [1935](https://github.com/lbryio/herald.go/actions/runs/3048223395/jobs/4913052275#step:3:1936) --- PASS: TestUDPPing (1.03s) [1936](https://github.com/lbryio/herald.go/actions/runs/3048223395/jobs/4913052275#step:3:1937) --- SKIP: TestUDPPing/Correctly_parse_information_from_production_server. (1.03s) ```
jeffreypicard (Migrated from github.com) approved these changes 2022-09-14 15:09:27 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/herald.go#55
No description provided.