Compare commits

..
182 Commits
Author SHA1 Message Date
Victor Shyba 27afc759ff fix peer search using inexistent variable, fix test to cover it 2019-05-10 14:23:40 -03:00
Victor Shyba 7abb28cb3e raise ban cap to 30 minutes 2019-05-10 14:23:40 -03:00
Jack Robison 7d2f592bb5 Merge pull request #2107 from lbryio/fix-update-file-we-dont-have
fix stream_update failing on metadata only updates for files we don't have
2019-05-10 12:28:53 -04:00
Jack Robison 1a182bc9bd bytes/str 2019-05-10 11:50:20 -04:00
Jack Robison 324cbdcdb2 only save the content claim if stream_hash isn't None
-stream_hash being none means we don't have the file in the database
2019-05-10 11:50:20 -04:00
Lex Berezhny 6c0c0ee322 added logging to publish command 2019-05-10 11:43:34 -04:00
Jack Robison 1e54271d8a Merge pull request #2105 from lbryio/fix-store-content-fee
fix store content fee
2019-05-09 18:47:30 -04:00
Jack Robison 54b9ed6cb2 fix store content fee 2019-05-09 18:14:54 -04:00
Lex Berezhny 558a02d187 correctly format lat/long and fee amounts in JSON RPC response 2019-05-09 16:19:49 -04:00
Jack Robison 3567b331c0 v0.37.0rc6 2019-05-09 11:52:34 -04:00
Jack Robison 9e4cf3c995 Merge pull request #2048 from lbryio/timeout_settings
Adjust default max_connections_per_download and peer_connect_timeout settings
2019-05-09 11:14:59 -04:00
Thomas Zarebczan db1d547b19 adjust the default max_connections_per_download and peer_connect_timeout 2019-05-09 10:38:32 -04:00
Jack Robison c31efd780b docs 2019-05-09 10:32:07 -04:00
Jack Robison 7cdb7987e3 Merge pull request #2102 from lbryio/shutdown_fast
Set a shutdown timeout for TCPSite to avoid hanging on exit
2019-05-09 10:24:13 -04:00
Victor Shyba ec07037e88 set shutdown_timeout on TCPSite 2019-05-09 01:01:07 -03:00
Lex Berezhny 9bb7b0571e fix integrat tests 2019-05-09 00:00:39 -04:00
Lex Berezhny d98162a118 stream_update --replace also clears the channel 2019-05-09 00:00:39 -04:00
Jack Robison c5ae59bff7 Merge pull request #2100 from lbryio/junction_fixes
DHT junction fixes for cases that can lock up
2019-05-08 23:52:54 -04:00
Victor Shyba efbf2f49a9 fix generator junction 2019-05-08 23:02:38 -03:00
Victor Shyba 77c69f661d add locking cases scenarios 2019-05-08 23:02:38 -03:00
Victor Shyba 2e09d2adfa close search on transport close 2019-05-08 23:02:38 -03:00
Jack Robison 8620a0e424 Merge pull request #2095 from lbryio/add-content-fee-and-saved-file-to-db
add saved_file and content_fee columns to file table
2019-05-08 20:37:56 -04:00
Jack Robison e2c123456b write decrypted blob data from run_in_executor 2019-05-08 16:07:32 -04:00
Jack Robison c9be79f062 prevent re-migrating 10 to 11 2019-05-08 15:13:07 -04:00
Jack Robison a2a1ef34ab fix tests 2019-05-08 14:55:09 -04:00
Jack Robison 761a2b235c set written_bytes, download_path, file_name, and download_directory to None if the file doesn't exist 2019-05-08 14:11:44 -04:00
Jack Robison 3ca2fee592 use stream size from claim if available 2019-05-08 14:11:39 -04:00
Jack Robison a480b2d25f fix race when closing blob client protocol after getting a response 2019-05-08 12:21:11 -04:00
Jack Robison d7032b12d7 add saved_file and content_fee columns to file table
-drop not null constraints for file_name and download_directory

-add migrator
2019-05-08 10:26:06 -04:00
Jack Robison 84381ff76c Merge pull request #2093 from lbryio/fix_announce_on_storage
Refactor announcer + fixups for last db migrator code
2019-05-07 10:46:12 -04:00
Victor Shyba 007dd43861 re-raise cancelled errors 2019-05-07 11:10:49 -03:00
Victor Shyba 1bc4e4b702 typo on logging, announcements logging is info, not warning 2019-05-07 11:10:49 -03:00
Victor Shyba b91f27219d use fetchall as there is an update while iterating 2019-05-07 11:10:49 -03:00
Victor Shyba dc4560cc9a refactor announcer 2019-05-07 11:10:49 -03:00
Victor Shyba 84b471d486 limit batch size on announcer test so it covers batching logic 2019-05-07 11:10:49 -03:00
Victor Shyba c6a3c05a0c add missing migrator line 2019-05-07 11:10:49 -03:00
Jack Robison dd665a758d Merge pull request #2065 from lbryio/streaming-bug-fixes
Streaming bug fixes
2019-05-07 10:10:39 -04:00
Jack Robison 32dc1297ec fix infinite loop 2019-05-06 18:46:26 -04:00
Jack Robison bef244ba77 dont make duplicate files 2019-05-06 18:46:26 -04:00
Jack Robison 3c231d6215 handle get with file_name/download_directory/save_file arg for a stream that is already running 2019-05-06 18:46:26 -04:00
Jack Robison a212cf6ba4 set content_fee attribute 2019-05-06 18:46:26 -04:00
Jack Robison bc060f1378 pay fee after downloading the sd blob/adding to the db 2019-05-06 18:46:26 -04:00
Jack Robison 22c701fd50 fix completed field for an item in file list 2019-05-06 18:46:26 -04:00
Jack Robison 4f0e8fce6e add optional download_directory argument to get 2019-05-06 18:46:26 -04:00
Jack Robison f642cfe9dd fix resuming save tasks on startup 2019-05-06 18:46:26 -04:00
Jack Robison 24e073680b add connection id workaround 2019-05-06 18:46:26 -04:00
Jack Robison b2f63a1545 fix tests 2019-05-06 18:46:26 -04:00
Jack Robison f506b3e6d4 tests 2019-05-06 18:46:26 -04:00
Jack Robison f7412514b3 fix partial content 0 padding 2019-05-06 18:46:26 -04:00
Jack Robison bd6a609b30 fix logging 2019-05-06 18:46:26 -04:00
Jack Robison 4e32b69d1d don't set running streams as stopped on startup 2019-05-06 18:46:26 -04:00
Jack Robison 1116c7f29e logging 2019-05-06 18:46:26 -04:00
Jack Robison d80c671cf2 look victor 2019-05-06 18:46:26 -04:00
Jack Robison 14b12cbea2 block /stream and /get requests on the stream manager starting 2019-05-06 18:46:26 -04:00
Jack Robison 1f7feafb67 force close open streaming requests and api calls on shutdown 2019-05-06 18:46:26 -04:00
Jack Robison cbe689ea7f logging 2019-05-06 18:46:26 -04:00
Jack Robison 9099ee2e8e fix/refactor starting and stopping files
-move partial content handling into ManagedStream
-add delayed stop test
2019-05-06 18:46:26 -04:00
Jack Robison b134e0c9c9 fix blob_get 2019-05-06 18:46:26 -04:00
Jack Robison f8c0e80cfc add __slots__ to BlobInfo, StreamDescriptor, and KademliaPeer 2019-05-06 18:46:26 -04:00
Jack Robison 1f266ebdad add logging for streams we already have 2019-05-06 18:46:26 -04:00
Jack Robison b09e1f8825 fix written_bytes never being 0 2019-05-06 18:46:26 -04:00
Jack Robison c496278a5b Merge pull request #2092 from lbryio/fix_announce_on_storage
Set should_announce=1 to head and descriptor blobs when saving a stream to database
2019-05-06 18:45:36 -04:00
Victor Shyba cacc65d45e fix edge case from test for single blob stream 2019-05-06 18:18:12 -03:00
Victor Shyba 2247b354b3 integration test for announcing both on publish and download 2019-05-06 17:27:12 -03:00
Victor Shyba 43111f0497 bump db revision 2019-05-06 17:19:40 -03:00
Victor Shyba 6c142b4477 add migrator for previous bugs 2019-05-06 17:12:04 -03:00
Victor Shyba e8683a24bd fix should_announce being set on stream creation 2019-05-06 16:49:52 -03:00
Victor Shyba a4d17d1705 re-enable tests for announcing on stream creation 2019-05-06 16:49:03 -03:00
Baltazar Gomez a030e13548 fix incorrect media-type of .cbr archives 2019-05-05 20:57:36 -04:00
Jack Robison 32b8601c38 Merge pull request #2083 from lbryio/fix_get_params
make save_file a parameter instead of a flag so it obeys conf
2019-05-05 19:44:29 -04:00
Victor Shyba f5bd28bfdb make save_file a parameter instead of a flag so it obeys conf 2019-05-05 19:46:42 -03:00
Lex Berezhny 6cbbe23c7c account_list defaults to 0 confirmations for balance 2019-05-04 18:08:33 -04:00
Lex Berezhny d7c2e4e9b3 fixed bug where lbrynet failed to start with single-key accounts in the wallet 2019-05-04 17:56:39 -04:00
Jack Robison d61ddbb950 Merge pull request #2076 from lbryio/download_improv
make ttfb configurable, fix race condition on writers, ban on time scales, remove idle code for getting unstuck on long downloads, fix foreign key error and improve downloader loop checks
2019-05-02 17:18:16 -04:00
Victor Shyba cf7bb6a391 fix tests and stream being deleted on data timeout 2019-05-02 16:41:48 -03:00
Victor Shyba 68d7328918 always close the write handle 2019-05-02 12:20:49 -03:00
Victor Shyba ff2985cc80 close protocol if transport reuse brings responses before requests 2019-05-02 12:13:33 -03:00
Victor Shyba ac69fcbc5f fix possible division by zero 2019-05-02 11:52:09 -03:00
Victor Shyba 609cf42868 cleanup downloader code 2019-05-01 18:04:45 -03:00
Victor Shyba e43b29fcd1 if the current writer is closed, its fine to open a new one 2019-05-01 15:09:11 -03:00
Victor Shyba 6594b7c50c test concurrency through races on getting a writer 2019-05-01 15:08:47 -03:00
Victor Shyba 971f2a1cef log download speed only if downloading full streams 2019-05-01 14:31:11 -03:00
Victor Shyba fc88261cc6 add head_blob_only to ttfb 2019-05-01 13:59:45 -03:00
Victor Shyba 895b3992c9 set type for stall download timeout 2019-05-01 13:26:51 -03:00
Victor Shyba 41951d8ec2 improve ttfb script confs 2019-05-01 13:17:13 -03:00
Victor Shyba ae2121c5c4 fix tests and new test 2019-05-01 13:16:45 -03:00
Victor Shyba 771fe935f4 test get-delete-get respects existing files 2019-05-01 13:16:32 -03:00
Victor Shyba 60f7766cf7 small adjustment to new_peer_or_finished 2019-05-01 02:55:51 -03:00
Victor Shyba 63bd983012 pylint 2019-05-01 00:42:51 -03:00
Victor Shyba 7ffce1040c fix foreign key error 2019-04-30 19:51:19 -03:00
Victor Shyba ac6835fa60 dont get stuck 2019-04-30 19:51:02 -03:00
Victor Shyba 3cf5c536c0 improve ban timing and downloader loop friction 2019-04-30 17:56:29 -03:00
Lex Berezhny 85cc1a4763 v0.37.0rc5 2019-04-29 17:22:47 -04:00
Lex Berezhny 180cfcfb72 fix chris45 tests 2019-04-29 16:01:59 -04:00
Lex Berezhny 864c1dd901 fix test_claim_commands integration tests 2019-04-29 16:01:59 -04:00
Lex Berezhny aeaa7ba986 switched from sha256 for unencrypted file hash to sha384 2019-04-29 16:01:59 -04:00
Lex Berezhny b8325c1f89 regenerated docs 2019-04-29 09:49:39 -04:00
Lex Berezhny a36936b5ff v0.37.0rc4 2019-04-29 00:27:53 -04:00
Victor Shyba 7cf245a0e9 encode timestamp and confirmations into file list 2019-04-29 00:26:14 -04:00
Victor Shyba 9f83cce574 test confirmations and timestamp on file list, being updated on resolve 2019-04-29 00:26:14 -04:00
Victor Shyba 30b113d64a depth -> confirmations 2019-04-29 00:26:14 -04:00
Victor Shyba ccd2023d37 add timestamp field to resolve 2019-04-29 00:26:14 -04:00
Victor Shyba 3127cd11cf test for timestamp field on resolve 2019-04-29 00:26:14 -04:00
Victor Shyba 6e483cba8d tests: add confirm parameters, like the other calls 2019-04-28 22:53:43 -04:00
Victor Shyba 46c03c0cb2 refactor: move generate to blockchain call 2019-04-28 22:53:43 -04:00
Victor Shyba c2ca0a9467 tests: replace sleep with the proper generate call 2019-04-28 22:53:43 -04:00
Victor Shyba b350e74aca fix stream update callback to update the main dict 2019-04-28 22:53:43 -04:00
Victor Shyba de9473f75a test resolve updates file list 2019-04-28 22:53:43 -04:00
Lex Berezhny bfc107fdb3 removed blockchain.block.get_block from wallet server API 2019-04-27 18:03:35 -04:00
Lex Berezhny 6a2efa54ab dropped block_show command from API, users should run a full node if they need access to blocks 2019-04-27 18:03:35 -04:00
Lex Berezhny 72f0e1ca14 added timestamp field to transaction output results from JSON RPC calls 2019-04-27 17:10:49 -04:00
Lex Berezhny 9a1262d557 regenerate docs 2019-04-27 13:13:20 -04:00
Lex Berezhny 706a8e52dc v0.37.0rc3 2019-04-27 13:12:27 -04:00
Lex Berezhny f3c8776878 fixed --preview mode on stream_create/update 2019-04-27 13:11:32 -04:00
Lex Berezhny 539ea04039 fixed signing streams using --channel_name argument 2019-04-27 11:52:29 -04:00
Lex Berezhny 8f96b07559 updating stream claim with new file now correctly updates file list removing old file 2019-04-27 10:55:20 -04:00
Lex Berezhny 0a1e97fe23 cli test fix 2019-04-26 23:37:10 -04:00
Lex Berezhny da637b9c0e added --replace option to stream_update and channel_update, publish defaults to --replace 2019-04-26 23:37:10 -04:00
Lex Berezhny 3618de1227 added --clear_fee ability to stream update command 2019-04-26 17:52:29 -04:00
Victor Shyba 3cb8a63bf9 add channel_name parameter on claim search 2019-04-26 17:30:21 -04:00
Victor Shyba bad99de5b3 add tests for channel_name, which should work for urls too 2019-04-26 17:30:21 -04:00
Lex Berezhny 3d1efbc9bb v0.37.0rc2 2019-04-25 20:40:07 -04:00
Victor Shyba 7bdef3146b fix ttfb 2019-04-25 20:38:33 -04:00
Victor Shyba 2145bfcabf install uvloop on wallet server docker image and default to it 2019-04-25 20:07:10 -04:00
Lex Berezhny b88832d0a9 regenerated docs/api.json 2019-04-24 23:03:30 -04:00
Lex Berezhny db08882f20 v0.37.0rc1 2019-04-24 21:35:59 -04:00
Jack Robison 6f52d36b22 Merge pull request #2020 from lbryio/download-range-requests
Support HTTP 206 partial content requests for streaming downloads
2019-04-24 14:21:41 -04:00
Jack Robison 056a629e87 remove unused property 2019-04-24 13:39:06 -04:00
Jack Robison 1ffb99f9f9 rename streaming_only setting -> save_files 2019-04-24 12:44:12 -04:00
Jack Robison a8e612773d test 2019-04-24 09:48:04 -04:00
Jack Robison 67088b2ca2 test_blob_writers_concurrency 2019-04-24 09:48:04 -04:00
Jack Robison dab49e812f set writer result or error before calling close_handle 2019-04-24 09:48:04 -04:00
Jack Robison 0f3f38d8a3 pylint 2019-04-24 09:48:04 -04:00
Jack Robison 7ba433c2e5 fix setting blob verified event and canceling blob writers
-raise OSError if multiple writers for one peer are opened for a blob
2019-04-24 09:48:04 -04:00
Jack Robison bb7649e8ad test file_save stopped before finished writing with streaming_only on/off 2019-04-24 09:48:04 -04:00
Jack Robison 832537a5cf set deleted downloads as streaming mode on startup 2019-04-24 09:48:04 -04:00
Jack Robison 3234d70270 add peer address/port to hash blob writer 2019-04-24 09:48:04 -04:00
Jack Robison 432fe444f8 fix cache_concurrent decorator 2019-04-24 09:48:04 -04:00
Jack Robison 861c25716e add unit tests for cache_concurrent decorator 2019-04-24 09:48:04 -04:00
Victor Shyba 9ba6653475 raise proper error when sd is not available 2019-04-24 09:48:04 -04:00
Jack Robison 8107e97304 remove debugging /streams endpoint 2019-04-24 09:48:04 -04:00
Jack Robison e2663f6d57 remove unnecessary except/raise 2019-04-24 09:48:04 -04:00
Jack Robison 35479dcbd2 add file_save integration tests 2019-04-24 09:48:04 -04:00
Jack Robison 3a997277aa reduce the amount of Blob objects created 2019-04-24 09:48:04 -04:00
Jack Robison a7d94f4514 add file_save 2019-04-24 09:48:04 -04:00
Jack Robison a0e3338177 only re-reflect streams if the sd blob is readable 2019-04-24 09:48:04 -04:00
Jack Robison d5a353066c missing await 2019-04-24 09:48:04 -04:00
Jack Robison bc29fc4465 type 2019-04-24 09:48:04 -04:00
Jack Robison 987f175fcc logging 2019-04-24 09:48:04 -04:00
Jack Robison 5b1398b588 rename test_streaming.py 2019-04-24 09:48:04 -04:00
Jack Robison 873b58efc9 update example_daemon_settings.yml 2019-04-24 09:48:04 -04:00
Jack Robison 01a81fceed more streaming_only + save_blobs integration testing 2019-04-24 09:48:04 -04:00
Jack Robison a14b0aa573 tests 2019-04-24 09:48:04 -04:00
Jack Robison a1abb7c8fb test range requests 2019-04-24 09:48:04 -04:00
Jack Robison 46b166952b non async blob_completed callback, tests 2019-04-24 09:48:04 -04:00
Jack Robison 1375153fda fix publish updates not being saved to the db, don't query the db for the stream hash 2019-04-24 09:48:04 -04:00
Jack Robison 1a14157d37 fix unawaited task 2019-04-24 09:48:04 -04:00
Jack Robison 40b9fa38b0 update mock dht 2019-04-24 09:48:04 -04:00
Jack Robison 4d0e9e0428 relative http redirect from /get -> /stream 2019-04-24 09:48:04 -04:00
Jack Robison 3a53ef5690 catch TransportNotConnected 2019-04-24 09:48:04 -04:00
Jack Robison 33a68b5cef handle dht is_closing 2019-04-24 09:48:04 -04:00
Jack Robison 63bf084a6a cancel dht response future 2019-04-24 09:48:04 -04:00
Jack Robison a882f2e8c5 merge conflicts 2019-04-24 09:48:04 -04:00
Jack Robison 119e0ec408 cancelled error 2019-04-24 09:48:04 -04:00
Jack Robison 7d782d516a track and close blob readers 2019-04-24 09:48:04 -04:00
Jack Robison d3eac48035 tests, add __slots__ to AbstractBlob 2019-04-24 09:48:04 -04:00
Jack Robison 60c9ae64b4 endpoint to call get and redirect to the partial content stream 2019-04-24 09:48:04 -04:00
Jack Robison 2d314dce60 add save_file argument to get 2019-04-24 09:48:04 -04:00
Jack Robison 287b89db66 fix tests 2019-04-24 09:48:04 -04:00
Jack Robison 7a160f7335 fix tests 2019-04-24 09:48:04 -04:00
Jack Robison 04ddee7d89 blob tests 2019-04-24 09:48:04 -04:00
Jack Robison 3a916a8e8e tests 2019-04-24 09:48:04 -04:00
Jack Robison f125468ebf fix claim not being saved to the db 2019-04-24 09:48:04 -04:00
Jack Robison f0e17cff9a support streaming downloads / range requests 2019-04-24 09:48:04 -04:00
Jack Robison 93267efe0b remove StreamAssembler, refactor ManagedStream and StreamDownloader (WIP) 2019-04-24 09:48:04 -04:00
Jack Robison c663e5a3cf add cache_concurrent decorator 2019-04-24 09:48:04 -04:00
Jack Robison 676f0015aa refactor BlobFile into AbstractBlob, BlobFile, and BlobBuffer classes 2019-04-24 09:48:04 -04:00
Jack Robison d44a79ada2 cache resolve_host, add async_timed_cache decorator 2019-04-24 09:48:04 -04:00
Jack Robison d7ed8ffaa6 add streaming_only and save_blobs settings 2019-04-24 09:48:04 -04:00
Jack Robison b230d8fbcb rename BlobFileManager -> BlobManager 2019-04-24 09:48:04 -04:00
Lex Berezhny 7d2428fd17 regenerate api.json 2019-04-23 23:49:39 -04:00
Lex Berezhny 4157045a41 block_show command example 2019-04-23 23:49:39 -04:00
73 changed files with 3458 additions and 1808 deletions

No files matched your search

+340 -230
View File
@@ -2,26 +2,6 @@
"main": {
"doc": "Ungrouped commands.",
"commands": [
{
"name": "block_show",
"description": "Get contents of a block",
"arguments": [
{
"name": "blockhash",
"type": "str",
"description": "hash of the block to look up",
"is_required": true
},
{
"name": "height",
"type": "int",
"description": "height of the block to look up",
"is_required": true
}
],
"returns": "(dict) Requested block",
"examples": []
},
{
"name": "get",
"description": "Download stream from a LBRY name.",
@@ -35,7 +15,13 @@
{
"name": "file_name",
"type": "str",
"description": "specified name for the downloaded file",
"description": "specified name for the downloaded file, overrides the stream file name",
"is_required": false
},
{
"name": "download_directory",
"type": "str",
"description": "full path to the directory to download into",
"is_required": false
},
{
@@ -43,22 +29,28 @@
"type": "int",
"description": "download timeout in number of seconds",
"is_required": false
},
{
"name": "save_file",
"type": "bool",
"description": "save the file to the downloads directory",
"is_required": false
}
],
"returns": " {\n \"completed\": \"(bool) true if download is completed\",\n \"file_name\": \"(str) name of file\",\n \"download_directory\": \"(str) download directory\",\n \"points_paid\": \"(float) credit paid to download file\",\n \"stopped\": \"(bool) true if download is stopped\",\n \"stream_hash\": \"(str) stream hash of file\",\n \"stream_name\": \"(str) stream name\",\n \"suggested_file_name\": \"(str) suggested file name\",\n \"sd_hash\": \"(str) sd hash of file\",\n \"download_path\": \"(str) download path of file\",\n \"mime_type\": \"(str) mime type of file\",\n \"key\": \"(str) key attached to file\",\n \"total_bytes_lower_bound\": \"(int) lower bound file size in bytes\",\n \"total_bytes\": \"(int) file upper bound size in bytes\",\n \"written_bytes\": \"(int) written size in bytes\",\n \"blobs_completed\": \"(int) number of fully downloaded blobs\",\n \"blobs_in_stream\": \"(int) total blobs on stream\",\n \"blobs_remaining\": \"(int) total blobs remaining to download\",\n \"status\": \"(str) downloader status\",\n \"claim_id\": \"(str) None if claim is not found else the claim id\",\n \"txid\": \"(str) None if claim is not found else the transaction id\",\n \"nout\": \"(int) None if claim is not found else the transaction output index\",\n \"outpoint\": \"(str) None if claim is not found else the tx and output\",\n \"metadata\": \"(dict) None if claim is not found else the claim metadata\",\n \"channel_claim_id\": \"(str) None if claim is not found or not signed\",\n \"channel_name\": \"(str) None if claim is not found or not signed\",\n \"claim_name\": \"(str) None if claim is not found else the claim name\"\n }",
"examples": [
{
"title": "Get a file",
"curl": "curl -d'{\"method\": \"get\", \"params\": {\"uri\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"}}' http://localhost:5279/",
"lbrynet": "lbrynet get astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"get\", \"params\": {\"uri\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_name\": \"astream\",\n \"completed\": false,\n \"download_directory\": \"/tmp/tmprlkz78lb\",\n \"download_path\": \"/tmp/tmprlkz78lb/tmpit97x87b\",\n \"file_name\": \"tmpit97x87b\",\n \"key\": \"40d70a655061b7981b6d36a84d985fdc\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01cf859b7d5b44ee82281311805c97781f222d24cce145c0ad7c3c76cd83b5f8044d097413f4198e39a8b4d8012e4055de83212fb94c12834f444142c49a9f46a786b31236b79c7612bdfccae897ef372792b9894e0a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"status\": \"running\",\n \"stopped\": false,\n \"stream_hash\": \"5bb823532eb1994bbb6c4a7ac44713249768f6e329e6e58a2c1e128ef9a029f850c30757909d0f961f7143a3b7ea439f\",\n \"stream_name\": \"tmpit97x87b\",\n \"suggested_file_name\": \"tmpit97x87b\",\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"tx\": null,\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"written_bytes\": 11\n }\n}"
"curl": "curl -d'{\"method\": \"get\", \"params\": {\"uri\": \"astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"}}' http://localhost:5279/",
"lbrynet": "lbrynet get astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"get\", \"params\": {\"uri\": \"astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"confirmations\": 3,\n \"content_fee\": null,\n \"download_directory\": \"/tmp/tmppe9osroo\",\n \"download_path\": \"/tmp/tmppe9osroo/tmpfmcqxqr9\",\n \"file_name\": \"tmpfmcqxqr9\",\n \"height\": 214,\n \"key\": \"de672c28f2060f41575f08bd9aab2cb8\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"65b6982a8fddae13c12390608c58a18f1368bcb73f53b31990d4be093827f3f1945eec69b84f1ca2996a1f070a3cd7f3\",\n \"stream_name\": \"tmpfmcqxqr9\",\n \"suggested_file_name\": \"tmpfmcqxqr9\",\n \"timestamp\": 1557412291,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"written_bytes\": 11\n }\n}"
}
]
},
{
"name": "publish",
"description": "Create or update a stream claim at a given name (use 'stream create/update' for more control).",
"description": "Create or replace a stream claim at a given name (use 'stream create/update' for more control).",
"arguments": [
{
"name": "name",
@@ -114,36 +106,18 @@
"description": "author of the publication. The usage for this field is not the same as for channels. The author field is used to credit an author who is not the publisher and is not represented by the channel. For example, a pdf file of 'The Odyssey' has an author of 'Homer' but may by published to a channel such as '@classics', or to no channel at all",
"is_required": false
},
{
"name": "clear_tags",
"type": "bool",
"description": "clear existing tags (prior to adding new ones)",
"is_required": false
},
{
"name": "tags",
"type": "list",
"description": "add content tags",
"is_required": false
},
{
"name": "clear_languages",
"type": "bool",
"description": "clear existing languages (prior to adding new ones)",
"is_required": false
},
{
"name": "languages",
"type": "list",
"description": "languages used by the channel, using RFC 5646 format, eg: for English `--languages=en` for Spanish (Spain) `--languages=es-ES` for Spanish (Mexican) `--languages=es-MX` for Chinese (Simplified) `--languages=zh-Hans` for Chinese (Traditional) `--languages=zh-Hant`",
"is_required": false
},
{
"name": "clear_locations",
"type": "bool",
"description": "clear existing locations (prior to adding new ones)",
"is_required": false
},
{
"name": "locations",
"type": "list",
@@ -233,10 +207,10 @@
"examples": [
{
"title": "Publish a file",
"curl": "curl -d'{\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpaus_fgla\", \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_account_id\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet publish a-new-stream --bid=1.0 --file_path=/tmp/tmpaus_fgla",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpaus_fgla\", \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_account_id\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001a195344fcc2aa208da963a9ca262a84fe56c3b03a65b242a739d426daa565059010000006a47304402201f3ab0570cfaa6a50563bbf0c32a7c49013d32480f782cb164341e38cddf340302201956aa452a4806f63f8ff5cedd0914f42e02b44738639c875162f9141e9870670121034fc65cb8aeeb5fc4d4b40b62be1a9b737c6bf66cfea38b1f7788374c61efeb84ffffffff0200e1f50500000000adb50c612d6e65772d73747265616d4c82000a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706175735f66676c61180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2e3c653b012ca01628a02ffe19052ceea10595583fe3b30a00cbeb5fc0c5b7edda2b625c1bc28286b7a3c93a7c104446d7576a914588cf101f723605e989369e9a6100bbb13d452c488ace0b46217000000001976a914e0b1ec0abfeede4d75e67d97ca0dfe22ea0fcbc088ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mushjCzKC83rDwJxoYeC6JRp8R6AEA9Ecw\",\n \"amount\": \"4.947555\",\n \"confirmations\": 4,\n \"height\": 215,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"595056aa6d429d732a245ba6033b6ce54fa862a29c3a96da08a22acc4f3495a1\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mobAbiapbJhWi96iWmm6kS4kPA853qnDD6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"c3876e43947871868bba4e42a76b10b9a0aa0947\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"a-new-stream\",\n \"nout\": 0,\n \"permanent_url\": \"a-new-stream#c3876e43947871868bba4e42a76b10b9a0aa0947\",\n \"txid\": \"9f5d3bb201aa0a1246ba470c702690ec41f7481668ad6b1b191dfb9349f8aa8d\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpaus_fgla\",\n \"sd_hash\": \"a2e3c653b012ca01628a02ffe19052ceea10595583fe3b30a00cbeb5fc0c5b7edda2b625c1bc28286b7a3c93a7c10444\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"n212oGGTLcpCzjPgnt1HHkn1wdvFxyf3hm\",\n \"amount\": \"3.923448\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"9f5d3bb201aa0a1246ba470c702690ec41f7481668ad6b1b191dfb9349f8aa8d\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.024107\",\n \"total_input\": \"4.947555\",\n \"total_output\": \"4.923448\",\n \"txid\": \"9f5d3bb201aa0a1246ba470c702690ec41f7481668ad6b1b191dfb9349f8aa8d\"\n }\n}"
"curl": "curl -d'{\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpzyae0q0y\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet publish a-new-stream --bid=1.0 --file_path=/tmp/tmpzyae0q0y",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpzyae0q0y\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001d7f8c932dde56ae69417f75de96abe606aa537e35f627bec962ef1218c6a92c8010000006b483045022100d0f33199022e2cbc91caa20aaa50779c2a70e58e345f685b7c79c5fcbe462ba50220462fc04149319ce1b36d137e52e1a8e6ca719091f859554372fee5a34a47a66d0121037ad50cdfa11808327c70f57e94b7c2462492a0b14da955eeed83ebce84494d7affffffff0200e1f50500000000bfb50c612d6e65772d73747265616d4c94000a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d707a79616530713079180b22186170706c69636174696f6e2f6f637465742d73747265616d3230168ea3c6b9a41509af29bb6b0d2c3c000d52d0b77c3f85c327b83ceb996300e113f82f240e20e18bc253f0a800100fb86d7576a9148cd833cc0b92c8955e6a3977bb991a275444ec5e88ace0b46217000000001976a9147ce9d453a27810ecc9e2ec216b50316f3e8f220e88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"msv3BiuJ4RHWEbdYE665DaxxGQbmTjtPW2\",\n \"amount\": \"4.947555\",\n \"confirmations\": 4,\n \"height\": 215,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1557412291,\n \"txid\": \"c8926a8c21f12e96ec7b625fe337a56a60be6ae95df71794e66ae5dd32c9f8d7\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mtMftuq8irZSZGMqRV4kbv558i2THU94hW\",\n \"amount\": \"1.0\",\n \"claim_id\": \"f1d4b94f0a1a6cbda837d67a2714bba180ea8e9c\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"a-new-stream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://a-new-stream#f1d4b94f0a1a6cbda837d67a2714bba180ea8e9c\",\n \"timestamp\": null,\n \"txid\": \"70c642a80f01d3cc1e77e6a8961fbfbdc40461ad017f0a58eccd192b7a404636\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzyae0q0y\",\n \"sd_hash\": \"168ea3c6b9a41509af29bb6b0d2c3c000d52d0b77c3f85c327b83ceb996300e113f82f240e20e18bc253f0a800100fb8\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mruSCbKo6azmjoYfnd1Br48qyQa4FTVUE8\",\n \"amount\": \"3.923448\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"70c642a80f01d3cc1e77e6a8961fbfbdc40461ad017f0a58eccd192b7a404636\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.024107\",\n \"total_input\": \"4.947555\",\n \"total_output\": \"4.923448\",\n \"txid\": \"70c642a80f01d3cc1e77e6a8961fbfbdc40461ad017f0a58eccd192b7a404636\"\n }\n}"
}
]
},
@@ -251,14 +225,14 @@
"is_required": false
}
],
"returns": "Dictionary of results, keyed by url\n '<url>': {\n If a resolution error occurs:\n 'error': Error message\n\n If the url resolves to a channel or a claim in a channel:\n 'certificate': {\n 'address': (str) claim address,\n 'amount': (float) claim amount,\n 'effective_amount': (float) claim amount including supports,\n 'claim_id': (str) claim id,\n 'claim_sequence': (int) claim sequence number (or -1 if unknown),\n 'decoded_claim': (bool) whether or not the claim value was decoded,\n 'height': (int) claim height,\n 'depth': (int) claim depth,\n 'has_signature': (bool) included if decoded_claim\n 'name': (str) claim name,\n 'permanent_url': (str) permanent url of the certificate claim,\n 'supports: (list) list of supports [{'txid': (str) txid,\n 'nout': (int) nout,\n 'amount': (float) amount}],\n 'txid': (str) claim txid,\n 'nout': (str) claim nout,\n 'signature_is_valid': (bool), included if has_signature,\n 'value': ClaimDict if decoded, otherwise hex string\n }\n\n If the url resolves to a channel:\n 'claims_in_channel': (int) number of claims in the channel,\n\n If the url resolves to a claim:\n 'claim': {\n 'address': (str) claim address,\n 'amount': (float) claim amount,\n 'effective_amount': (float) claim amount including supports,\n 'claim_id': (str) claim id,\n 'claim_sequence': (int) claim sequence number (or -1 if unknown),\n 'decoded_claim': (bool) whether or not the claim value was decoded,\n 'height': (int) claim height,\n 'depth': (int) claim depth,\n 'has_signature': (bool) included if decoded_claim\n 'name': (str) claim name,\n 'permanent_url': (str) permanent url of the claim,\n 'channel_name': (str) channel name if claim is in a channel\n 'supports: (list) list of supports [{'txid': (str) txid,\n 'nout': (int) nout,\n 'amount': (float) amount}]\n 'txid': (str) claim txid,\n 'nout': (str) claim nout,\n 'signature_is_valid': (bool), included if has_signature,\n 'value': ClaimDict if decoded, otherwise hex string\n }\n }",
"returns": "Dictionary of results, keyed by url\n '<url>': {\n If a resolution error occurs:\n 'error': Error message\n\n If the url resolves to a channel or a claim in a channel:\n 'certificate': {\n 'address': (str) claim address,\n 'amount': (float) claim amount,\n 'effective_amount': (float) claim amount including supports,\n 'claim_id': (str) claim id,\n 'claim_sequence': (int) claim sequence number (or -1 if unknown),\n 'decoded_claim': (bool) whether or not the claim value was decoded,\n 'height': (int) claim height,\n 'confirmations': (int) claim depth,\n 'timestamp': (int) timestamp of the block that included this claim tx,\n 'has_signature': (bool) included if decoded_claim\n 'name': (str) claim name,\n 'permanent_url': (str) permanent url of the certificate claim,\n 'supports: (list) list of supports [{'txid': (str) txid,\n 'nout': (int) nout,\n 'amount': (float) amount}],\n 'txid': (str) claim txid,\n 'nout': (str) claim nout,\n 'signature_is_valid': (bool), included if has_signature,\n 'value': ClaimDict if decoded, otherwise hex string\n }\n\n If the url resolves to a channel:\n 'claims_in_channel': (int) number of claims in the channel,\n\n If the url resolves to a claim:\n 'claim': {\n 'address': (str) claim address,\n 'amount': (float) claim amount,\n 'effective_amount': (float) claim amount including supports,\n 'claim_id': (str) claim id,\n 'claim_sequence': (int) claim sequence number (or -1 if unknown),\n 'decoded_claim': (bool) whether or not the claim value was decoded,\n 'height': (int) claim height,\n 'depth': (int) claim depth,\n 'has_signature': (bool) included if decoded_claim\n 'name': (str) claim name,\n 'permanent_url': (str) permanent url of the claim,\n 'channel_name': (str) channel name if claim is in a channel\n 'supports: (list) list of supports [{'txid': (str) txid,\n 'nout': (int) nout,\n 'amount': (float) amount}]\n 'txid': (str) claim txid,\n 'nout': (str) claim nout,\n 'signature_is_valid': (bool), included if has_signature,\n 'value': ClaimDict if decoded, otherwise hex string\n }\n }",
"examples": [
{
"title": "Resolve a claim",
"curl": "curl -d'{\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"]}}' http://localhost:5279/",
"lbrynet": "lbrynet resolve astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"]}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\": {\n \"certificate\": {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_sequence\": -1,\n \"decoded_claim\": true,\n \"depth\": 7,\n \"effective_amount\": \"1.0\",\n \"has_signature\": false,\n \"height\": 210,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"protobuf\": \"00125a0a583056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119420b4e6577204368616e6e656c\",\n \"supports\": [],\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\",\n \"valid_at_height\": 210,\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"claim\": {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_sequence\": -1,\n \"decoded_claim\": true,\n \"depth\": 3,\n \"effective_amount\": \"1.0\",\n \"has_signature\": true,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"protobuf\": \"01cf859b7d5b44ee82281311805c97781f222d24cce145c0ad7c3c76cd83b5f8044d097413f4198e39a8b4d8012e4055de83212fb94c12834f444142c49a9f46a786b31236b79c7612bdfccae897ef372792b9894e0a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"signature_is_valid\": true,\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"supports\": [],\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"valid_at_height\": 214,\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n }\n },\n \"claims_in_channel\": 0\n }\n }\n}"
"curl": "curl -d'{\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"]}}' http://localhost:5279/",
"lbrynet": "lbrynet resolve astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"]}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\": {\n \"certificate\": {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_sequence\": -1,\n \"confirmations\": 7,\n \"decoded_claim\": true,\n \"effective_amount\": \"1.0\",\n \"has_signature\": false,\n \"height\": 210,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"protobuf\": \"00125a0a583056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46420b4e6577204368616e6e656c\",\n \"supports\": [],\n \"timestamp\": 1557412290,\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\",\n \"valid_at_height\": 210,\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"claim\": {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_sequence\": -1,\n \"confirmations\": 3,\n \"decoded_claim\": true,\n \"effective_amount\": \"1.0\",\n \"has_signature\": true,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"signature_is_valid\": true,\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"supports\": [],\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"valid_at_height\": 214,\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n }\n },\n \"claims_in_channel\": 0\n }\n }\n}"
}
]
},
@@ -280,7 +254,7 @@
"curl": "curl -d'{\"method\": \"status\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet status",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"status\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"blob_manager\": {\n \"finished_blobs\": 0\n },\n \"connection_status\": {\n \"code\": \"connected\",\n \"message\": \"No connection problems detected\"\n },\n \"installation_id\": \"4tp3Nb4VFzDHH7K5sifwzWn4do28CSQ9LuWRBiQGhthLh6Stwe4TWz3j76sjRDUHtx\",\n \"is_running\": true,\n \"skipped_components\": [\n \"dht\",\n \"upnp\",\n \"hash_announcer\",\n \"peer_protocol_server\"\n ],\n \"startup_status\": {\n \"blob_manager\": true,\n \"blockchain_headers\": true,\n \"database\": true,\n \"exchange_rate_manager\": true,\n \"stream_manager\": true,\n \"wallet\": true\n },\n \"stream_manager\": {\n \"managed_files\": 0\n },\n \"wallet\": {\n \"best_blockhash\": \"02af940c99fbb24c6b15bae251bb20b5118e71bada9078035da2934b4a8f66c8\",\n \"blocks\": 206,\n \"blocks_behind\": 0,\n \"is_encrypted\": false,\n \"is_locked\": false\n }\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"blob_manager\": {\n \"finished_blobs\": 0\n },\n \"connection_status\": {\n \"code\": \"connected\",\n \"message\": \"No connection problems detected\"\n },\n \"installation_id\": \"2Aw32Z949cPi5dj1K8LfW3AnAyy2MnsUYFMHDbBj97fWWA9oP4YLviNc17x953kwoV\",\n \"is_running\": true,\n \"skipped_components\": [\n \"dht\",\n \"upnp\",\n \"hash_announcer\",\n \"peer_protocol_server\"\n ],\n \"startup_status\": {\n \"blob_manager\": true,\n \"blockchain_headers\": true,\n \"database\": true,\n \"exchange_rate_manager\": true,\n \"stream_manager\": true,\n \"wallet\": true\n },\n \"stream_manager\": {\n \"managed_files\": 0\n },\n \"wallet\": {\n \"best_blockhash\": \"e9bf8976351ca1f215a0c26463b371aedff0752d0a046090da58f0d50f76d710\",\n \"blocks\": 206,\n \"blocks_behind\": 0,\n \"is_encrypted\": false,\n \"is_locked\": false\n }\n }\n}"
}
]
},
@@ -302,7 +276,7 @@
"curl": "curl -d'{\"method\": \"version\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet version",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"version\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"build\": \"dev\",\n \"desktop\": \"GNOME\",\n \"distro\": {\n \"codename\": \"xenial\",\n \"id\": \"ubuntu\",\n \"like\": \"debian\",\n \"version\": \"16.04\",\n \"version_parts\": {\n \"build_number\": \"\",\n \"major\": \"16\",\n \"minor\": \"04\"\n }\n },\n \"lbrynet_version\": \"0.36.0rc3\",\n \"os_release\": \"4.4.0-116-generic\",\n \"os_system\": \"Linux\",\n \"platform\": \"Linux-4.4.0-116-generic-x86_64-with-Ubuntu-16.04-xenial\",\n \"processor\": \"x86_64\",\n \"python_version\": \"3.7.2\"\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"build\": \"dev\",\n \"desktop\": \"ubuntu:GNOME\",\n \"distro\": {\n \"codename\": \"bionic\",\n \"id\": \"ubuntu\",\n \"like\": \"debian\",\n \"version\": \"18.04\",\n \"version_parts\": {\n \"build_number\": \"\",\n \"major\": \"18\",\n \"minor\": \"04\"\n }\n },\n \"lbrynet_version\": \"0.37.0rc5\",\n \"os_release\": \"4.15.15-041515-generic\",\n \"os_system\": \"Linux\",\n \"platform\": \"Linux-4.15.15-041515-generic-x86_64-with-debian-buster-sid\",\n \"processor\": \"x86_64\",\n \"python_version\": \"3.7.0\"\n }\n}"
}
]
}
@@ -350,10 +324,10 @@
"examples": [
{
"title": "Add an account from seed",
"curl": "curl -d'{\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"chimney shoe next upgrade oil toe since scatter banana mix cloth banana\", \"single_key\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet account add \"new account\" --seed=\"chimney shoe next upgrade oil toe since scatter banana mix cloth banana\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"chimney shoe next upgrade oil toe since scatter banana mix cloth banana\", \"single_key\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1555941584.139002,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeS4f6CHZms9bqnK6UjAfa1a6zU8SFsZHRUMKNMUhs7t4a7Uq7EfjpKzNoLJH27D1SAhWASFPiUUy6PJcEY6jBkGryJyadTF\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Xu6SyqxABGoiQoq2e4Ma9KAtGzAjg9MgFxc5zkJJ3cVvkH8zrXE5pUeyKSv8zqDA5N1WWUW3ZYdge2BzyuiPmSCe7bj9UZe\",\n \"seed\": \"chimney shoe next upgrade oil toe since scatter banana mix cloth banana\"\n }\n}"
"curl": "curl -d'{\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"concert caution silent security delay egg bus category bean double bargain lunch\", \"single_key\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet account add \"new account\" --seed=\"concert caution silent security delay egg bus category bean double bargain lunch\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"concert caution silent security delay egg bus category bean double bargain lunch\", \"single_key\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1557412257.1639874,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeSga9d4YgRVnsaZW25naWk1zDAaHRntf4zT3dQJKttbge4SfANdGPPkqYGUL8TAwqVnXYiSUAS3HqU4V31K27obgU8JtsRQ\",\n \"public_key\": \"tpubD6NzVbkrYhZ4XuiN3Gj95q9uSc5SBQyV63cmVgcar4h3uUhpFo7v5PDYpBGmnjWU6AvPJGsDfhFGhQeZreu9Yj73qRHgUbTPvoeGp5zqWwL\",\n \"seed\": \"concert caution silent security delay egg bus category bean double bargain lunch\"\n }\n}"
}
]
},
@@ -385,9 +359,9 @@
},
{
"title": "Get balance for specific account by id",
"curl": "curl -d'{\"method\": \"account_balance\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"}}' http://localhost:5279/",
"lbrynet": "lbrynet account balance \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_balance\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"}}).json()",
"curl": "curl -d'{\"method\": \"account_balance\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"}}' http://localhost:5279/",
"lbrynet": "lbrynet account balance \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_balance\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"2.0\"\n}"
}
]
@@ -416,7 +390,7 @@
"curl": "curl -d'{\"method\": \"account_create\", \"params\": {\"account_name\": \"generated account\", \"single_key\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet account create \"generated account\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_create\", \"params\": {\"account_name\": \"generated account\", \"single_key\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1555941584.0031657,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeS4f6CHZms9bqnK6UjAfa1a6zU8SFsZHRUMKNMUhs7t4a7Uq7EfjpKzNoLJH27D1SAhWASFPiUUy6PJcEY6jBkGryJyadTF\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Xu6SyqxABGoiQoq2e4Ma9KAtGzAjg9MgFxc5zkJJ3cVvkH8zrXE5pUeyKSv8zqDA5N1WWUW3ZYdge2BzyuiPmSCe7bj9UZe\",\n \"seed\": \"chimney shoe next upgrade oil toe since scatter banana mix cloth banana\"\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1557412257.0474465,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeSga9d4YgRVnsaZW25naWk1zDAaHRntf4zT3dQJKttbge4SfANdGPPkqYGUL8TAwqVnXYiSUAS3HqU4V31K27obgU8JtsRQ\",\n \"public_key\": \"tpubD6NzVbkrYhZ4XuiN3Gj95q9uSc5SBQyV63cmVgcar4h3uUhpFo7v5PDYpBGmnjWU6AvPJGsDfhFGhQeZreu9Yj73qRHgUbTPvoeGp5zqWwL\",\n \"seed\": \"concert caution silent security delay egg bus category bean double bargain lunch\"\n }\n}"
}
]
},
@@ -499,24 +473,24 @@
"examples": [
{
"title": "Transfer 2 LBC from default account to specific account",
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}' http://localhost:5279/",
"lbrynet": "lbrynet account fund --to_account=\"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\" --amount=2.0 --broadcast",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001ac37a139c2674777d4c7789f5427005b4aa36642f614e9e147ab96b686173dc6010000006b483045022100f5a53db541d74e1be29cdfecbcd204914ba6d1f8ec8da8328d672de85120115a02206987b289030bda1e3beb059792cbb6300a7bd69a4db5badd2429d1d54a8bd7ad012102267211abbf788bda05f11be874cb53f1cb193bcf447e75a97011ba99d097b28cffffffff0200c2eb0b000000001976a9148942a5f74b3ac0884e6a1ed6f5e3f1a6859d5d6888ac90d7ae2f000000001976a91405a7e8221c667027351dc275ef165f841ec0d61088ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mrUJMH9thbp8N36pUWEwLbWhHS34396nrL\",\n \"amount\": \"10.0\",\n \"confirmations\": 6,\n \"height\": 201,\n \"is_change\": false,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"c63d1786b696ab47e1e914f64266a34a5b0027549f78c7d4774767c239a137ac\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mt2ii95pM4P7G8MUAB7usLP8zLsYyPHVk8\",\n \"amount\": \"2.0\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"txid\": \"54077accaaa814dd35b2cc6bc59db0e6ff9bbcf0aed151b2e22465579b58341e\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mg2rpNzx5bSBdqV1CADR98pRjtG8USWWUL\",\n \"amount\": \"7.999876\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"54077accaaa814dd35b2cc6bc59db0e6ff9bbcf0aed151b2e22465579b58341e\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000124\",\n \"total_input\": \"10.0\",\n \"total_output\": \"9.999876\",\n \"txid\": \"54077accaaa814dd35b2cc6bc59db0e6ff9bbcf0aed151b2e22465579b58341e\"\n }\n}"
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}' http://localhost:5279/",
"lbrynet": "lbrynet account fund --to_account=\"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\" --amount=2.0 --broadcast",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001b06f630c6b29be941ceb4f1fb4357e1b804ed618943bd9d4e77cbf16e3393195000000006a47304402201df99b64f2287a581f910988d875053424a2a6703f0e94edf1c347af283ad41502207e5d24ca551492df3f2026bbdd8ef9b67d1fb942fff5bcb4e03eb5a2bc74567c012103a9394113d9e2fccb7d4a81031a667c676ebd35014fdf2cede3b8034a8b68668bffffffff0200c2eb0b000000001976a91424076ae8e5d1812aed9085683d93090e8cbfee9e88ac90d7ae2f000000001976a914a9889d05d4a60dd24d61f475baa6a02d238b7ffd88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mjJRfy3fpDc1QqpSKfExmdhcTXyossEqTp\",\n \"amount\": \"10.0\",\n \"confirmations\": 6,\n \"height\": 201,\n \"is_change\": false,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1557412289,\n \"txid\": \"953139e316bf7ce7d4d93b9418d64e801b7e35b41f4feb1c94be296b0c636fb0\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"2.0\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"96f08b9501099985f2bf805281076aa4a41760d2ddf1396ed8e38f789b0e49ea\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mvyN9Y5pUWo4XTok2fAJYHmrhiKMUPqivB\",\n \"amount\": \"7.999876\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"96f08b9501099985f2bf805281076aa4a41760d2ddf1396ed8e38f789b0e49ea\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000124\",\n \"total_input\": \"10.0\",\n \"total_output\": \"9.999876\",\n \"txid\": \"96f08b9501099985f2bf805281076aa4a41760d2ddf1396ed8e38f789b0e49ea\"\n }\n}"
},
{
"title": "Spread LBC between multiple addresses",
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"from_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}' http://localhost:5279/",
"lbrynet": "lbrynet account fund --to_account=\"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\" --from_account=\"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\" --amount=1.5 --outputs=2 --broadcast",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"from_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000011e34589b576524e2b251d1aef0bc9bffe6b09dc56bccb235dd14a8aacc7a0754000000006b48304502210082b574cba7cd91fea5b5e8f1bee080e708ca1cc8be5965a2f86dc0b5a30ba63d02207ed9c512a8173aab4877b9d248c695cd24841a2a30020ed5a8fd3dbb5d5c9985012103f2b3ef3d1fa473c97fd1c263b023362ffc636ffa8a751de8f2e345e79a18552dffffffff03c0687804000000001976a9147a54ff72598e0ddda1c88c5a3bffeec278e3599988acc0687804000000001976a9147a54ff72598e0ddda1c88c5a3bffeec278e3599988ac6cb9fa02000000001976a9148942a5f74b3ac0884e6a1ed6f5e3f1a6859d5d6888ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mt2ii95pM4P7G8MUAB7usLP8zLsYyPHVk8\",\n \"amount\": \"2.0\",\n \"confirmations\": 1,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"txid\": \"54077accaaa814dd35b2cc6bc59db0e6ff9bbcf0aed151b2e22465579b58341e\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mrfnZDB2FMuaiZQgcytQyQGCucHQ86cxg9\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"txid\": \"dc3cbb02781b19136026723e2a0bc461fc12a4caad6d3b5afb5ea2a40e12ee8f\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mrfnZDB2FMuaiZQgcytQyQGCucHQ86cxg9\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"dc3cbb02781b19136026723e2a0bc461fc12a4caad6d3b5afb5ea2a40e12ee8f\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mt2ii95pM4P7G8MUAB7usLP8zLsYyPHVk8\",\n \"amount\": \"0.499859\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 2,\n \"txid\": \"dc3cbb02781b19136026723e2a0bc461fc12a4caad6d3b5afb5ea2a40e12ee8f\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000141\",\n \"total_input\": \"2.0\",\n \"total_output\": \"1.999859\",\n \"txid\": \"dc3cbb02781b19136026723e2a0bc461fc12a4caad6d3b5afb5ea2a40e12ee8f\"\n }\n}"
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"from_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}' http://localhost:5279/",
"lbrynet": "lbrynet account fund --to_account=\"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\" --from_account=\"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\" --amount=1.5 --outputs=2 --broadcast",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"from_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001ea490e9b788fe3d86e39f1ddd26017a4a46a07815280bff285990901958bf096000000006a473044022001401269e53f0fe7c03ffc8cfcaf45a24857ae794c4608e4addbf4bab6a57907022061ae8c55a3c913159abecf3038dd52fe5def995cc9eeca1b05f3ea5d7e60b411012102503f19a6af2d83f0f6e0a0d1208245ada4829b69e3540ce46b3b42e1a2854f6dffffffff03c0687804000000001976a91424076ae8e5d1812aed9085683d93090e8cbfee9e88acc0687804000000001976a91424076ae8e5d1812aed9085683d93090e8cbfee9e88ac6cb9fa02000000001976a91424076ae8e5d1812aed9085683d93090e8cbfee9e88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"2.0\",\n \"confirmations\": 1,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1557412290,\n \"txid\": \"96f08b9501099985f2bf805281076aa4a41760d2ddf1396ed8e38f789b0e49ea\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"d4428cae32a8b39cd8bf8f31934d5c80d0b56094369908c90416e8a2d22a5b71\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"d4428cae32a8b39cd8bf8f31934d5c80d0b56094369908c90416e8a2d22a5b71\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"0.499859\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 2,\n \"timestamp\": null,\n \"txid\": \"d4428cae32a8b39cd8bf8f31934d5c80d0b56094369908c90416e8a2d22a5b71\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000141\",\n \"total_input\": \"2.0\",\n \"total_output\": \"1.999859\",\n \"txid\": \"d4428cae32a8b39cd8bf8f31934d5c80d0b56094369908c90416e8a2d22a5b71\"\n }\n}"
},
{
"title": "Transfer all LBC to a specified account",
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"from_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"everything\": true, \"broadcast\": true}}' http://localhost:5279/",
"lbrynet": "lbrynet account fund --from_account=\"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\" --everything --broadcast",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"from_account\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"everything\": true, \"broadcast\": true}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000038fee120ea4a25efb5a3b6dadcaa412fc61c40b2a3e72266013191b7802bb3cdc020000006b483045022100c638c7a287b504ea99ea2ca7511e1f92f507c3d3452a5c17e72e2932769585d002203e37276b2bc0c8f1be1a0f781571dddbeaa042b35e6798169d7b7a48f2f84e02012103f2b3ef3d1fa473c97fd1c263b023362ffc636ffa8a751de8f2e345e79a18552dffffffff8fee120ea4a25efb5a3b6dadcaa412fc61c40b2a3e72266013191b7802bb3cdc000000006b483045022100b502e32233264508364efb6b4732320640ece56bb21e090d0ea5b14accc2c97002201d5d217466c9a86d986fa142d7522f0a5f4af49f7196433219283039c02a5e760121031fce1fedfb98ef06fb195ab1a6961b0af6e79865c6f8b358a45d588356065e2effffffff8fee120ea4a25efb5a3b6dadcaa412fc61c40b2a3e72266013191b7802bb3cdc010000006a473044022008d73060fc43c4bed279fe4a5c4e1eb56a92c90b734967a58ea637348ea45c39022039bd2ae74e70912ef654eda88965b7e331bd7720f85d069c0b61edcef32495fc0121031fce1fedfb98ef06fb195ab1a6961b0af6e79865c6f8b358a45d588356065e2effffffff015027eb0b000000001976a91449264b778030006ea39e77e4e291528d4238dab688ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mt2ii95pM4P7G8MUAB7usLP8zLsYyPHVk8\",\n \"amount\": \"0.499859\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 2,\n \"txid\": \"dc3cbb02781b19136026723e2a0bc461fc12a4caad6d3b5afb5ea2a40e12ee8f\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mrfnZDB2FMuaiZQgcytQyQGCucHQ86cxg9\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"txid\": \"dc3cbb02781b19136026723e2a0bc461fc12a4caad6d3b5afb5ea2a40e12ee8f\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mrfnZDB2FMuaiZQgcytQyQGCucHQ86cxg9\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"dc3cbb02781b19136026723e2a0bc461fc12a4caad6d3b5afb5ea2a40e12ee8f\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mnBjVptRpCyzSdVFR8uwqNkmDpScxHHYG9\",\n \"amount\": \"1.999604\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"txid\": \"4bb57d779f5ac678d49a02c71070833935e3f7525ba28f9cb0cbd8b09d6c94eb\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000255\",\n \"total_input\": \"1.999859\",\n \"total_output\": \"1.999604\",\n \"txid\": \"4bb57d779f5ac678d49a02c71070833935e3f7525ba28f9cb0cbd8b09d6c94eb\"\n }\n}"
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"from_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"everything\": true, \"broadcast\": true}}' http://localhost:5279/",
"lbrynet": "lbrynet account fund --from_account=\"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\" --everything --broadcast",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"from_account\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"everything\": true, \"broadcast\": true}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000003715b2ad2a2e81604c90899369460b5d0805c4d93318fbfd89cb3a832ae8c42d4000000006b4830450221009eac41c57796e11bef3fb42dca572e421927c38beffffcc1ecdb8a33c940b09e0220072dde889627cbe1a8d2199d9958a1f9bf2070f9a1e72bc82466a720ee5fab58012102503f19a6af2d83f0f6e0a0d1208245ada4829b69e3540ce46b3b42e1a2854f6dffffffff715b2ad2a2e81604c90899369460b5d0805c4d93318fbfd89cb3a832ae8c42d4010000006b483045022100a6d6075c3e0cca3fff08cfdac4655fb849e101fbc47ec74aa995a51eb6023b6d022062206ae3641f2c0e60d783eec1429299866da1c38f25b9174a67095ed8da726f012102503f19a6af2d83f0f6e0a0d1208245ada4829b69e3540ce46b3b42e1a2854f6dffffffff715b2ad2a2e81604c90899369460b5d0805c4d93318fbfd89cb3a832ae8c42d4020000006b483045022100eaf594ddab83fd806147c9a9f0cb729c1b3c91f2a8cb425a9c92affb744a490602206adf92a18f5b46ef0b7af7e5acd0655011259066278b11e7405ef729878a5feb012102503f19a6af2d83f0f6e0a0d1208245ada4829b69e3540ce46b3b42e1a2854f6dffffffff015027eb0b000000001976a914f6e8134b423b2b5052396954d35477fb9f0637b988ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1557412290,\n \"txid\": \"d4428cae32a8b39cd8bf8f31934d5c80d0b56094369908c90416e8a2d22a5b71\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1557412290,\n \"txid\": \"d4428cae32a8b39cd8bf8f31934d5c80d0b56094369908c90416e8a2d22a5b71\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"amount\": \"0.499859\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 2,\n \"timestamp\": 1557412290,\n \"txid\": \"d4428cae32a8b39cd8bf8f31934d5c80d0b56094369908c90416e8a2d22a5b71\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"n42UY87hnpSR9fbacE6WCJDc8cyfHVa4a1\",\n \"amount\": \"1.999604\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"a3378429d2d818d2ed85196ef9c8224e120c76f5674f3a577079242abd7fa7b7\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000255\",\n \"total_input\": \"1.999859\",\n \"total_output\": \"1.999604\",\n \"txid\": \"a3378429d2d818d2ed85196ef9c8224e120c76f5674f3a577079242abd7fa7b7\"\n }\n}"
}
]
},
@@ -556,7 +530,7 @@
"curl": "curl -d'{\"method\": \"account_list\", \"params\": {\"include_claims\": false, \"show_seed\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet account list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_list\", \"params\": {\"include_claims\": false, \"show_seed\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"lbc_regtest\": [\n {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"certificates\": 0,\n \"coins\": 10.0,\n \"encrypted\": false,\n \"id\": \"mq9sbgNnMwy5ZsWW5YgS4vRQykSmhjqTz5\",\n \"is_default\": true,\n \"name\": \"Account #mq9sbgNnMwy5ZsWW5YgS4vRQykSmhjqTz5\",\n \"public_key\": \"tpubD6NzVbkrYhZ4XGEmJycdW7mbyM7Y3tmDFUfbwXFxtbr1jdKfEAh9FGKeAzM2UdEx4fVDkL1wGdL72fdDoA5jSoLrjw2PXJkg7CbmqWjaPE2\",\n \"satoshis\": 1000000000\n }\n ]\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"lbc_regtest\": [\n {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"certificates\": 0,\n \"coins\": 10.0,\n \"encrypted\": false,\n \"id\": \"mnNeA4p7qkBSFti1texZcMaij5XP4TTLRs\",\n \"is_default\": true,\n \"name\": \"Account #mnNeA4p7qkBSFti1texZcMaij5XP4TTLRs\",\n \"public_key\": \"tpubD6NzVbkrYhZ4WMwJZ78QVYU65ofkdQWhLwzvEm9R8gBPAVaUqFdoje93iUzpf2oGFBntAV7hi8YsVLK4gSa2JC9JS5ZR2ZJc9qaWEswouus\",\n \"satoshis\": 1000000000\n }\n ]\n }\n}"
}
]
},
@@ -603,10 +577,10 @@
"examples": [
{
"title": "Remove an account",
"curl": "curl -d'{\"method\": \"account_remove\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"}}' http://localhost:5279/",
"lbrynet": "lbrynet account remove mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_remove\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1555941584.0031657,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeS4f6CHZms9bqnK6UjAfa1a6zU8SFsZHRUMKNMUhs7t4a7Uq7EfjpKzNoLJH27D1SAhWASFPiUUy6PJcEY6jBkGryJyadTF\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Xu6SyqxABGoiQoq2e4Ma9KAtGzAjg9MgFxc5zkJJ3cVvkH8zrXE5pUeyKSv8zqDA5N1WWUW3ZYdge2BzyuiPmSCe7bj9UZe\",\n \"seed\": \"chimney shoe next upgrade oil toe since scatter banana mix cloth banana\"\n }\n}"
"curl": "curl -d'{\"method\": \"account_remove\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"}}' http://localhost:5279/",
"lbrynet": "lbrynet account remove mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_remove\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 1\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1557412257.0474465,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeSga9d4YgRVnsaZW25naWk1zDAaHRntf4zT3dQJKttbge4SfANdGPPkqYGUL8TAwqVnXYiSUAS3HqU4V31K27obgU8JtsRQ\",\n \"public_key\": \"tpubD6NzVbkrYhZ4XuiN3Gj95q9uSc5SBQyV63cmVgcar4h3uUhpFo7v5PDYpBGmnjWU6AvPJGsDfhFGhQeZreu9Yj73qRHgUbTPvoeGp5zqWwL\",\n \"seed\": \"concert caution silent security delay egg bus category bean double bargain lunch\"\n }\n}"
}
]
},
@@ -681,10 +655,10 @@
"examples": [
{
"title": "Modify maximum number of times a change address can be reused",
"curl": "curl -d'{\"method\": \"account_set\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"default\": false, \"change_max_uses\": 10}}' http://localhost:5279/",
"lbrynet": "lbrynet account set mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB --change_max_uses=10",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_set\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\", \"default\": false, \"change_max_uses\": 10}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 10\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1555941584.2003748,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeS4f6CHZms9bqnK6UjAfa1a6zU8SFsZHRUMKNMUhs7t4a7Uq7EfjpKzNoLJH27D1SAhWASFPiUUy6PJcEY6jBkGryJyadTF\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Xu6SyqxABGoiQoq2e4Ma9KAtGzAjg9MgFxc5zkJJ3cVvkH8zrXE5pUeyKSv8zqDA5N1WWUW3ZYdge2BzyuiPmSCe7bj9UZe\",\n \"seed\": \"chimney shoe next upgrade oil toe since scatter banana mix cloth banana\"\n }\n}"
"curl": "curl -d'{\"method\": \"account_set\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"default\": false, \"change_max_uses\": 10}}' http://localhost:5279/",
"lbrynet": "lbrynet account set mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF --change_max_uses=10",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_set\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\", \"default\": false, \"change_max_uses\": 10}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"address_generator\": {\n \"change\": {\n \"gap\": 6,\n \"maximum_uses_per_address\": 10\n },\n \"name\": \"deterministic-chain\",\n \"receiving\": {\n \"gap\": 20,\n \"maximum_uses_per_address\": 1\n }\n },\n \"encrypted\": false,\n \"id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1557412257.2121701,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPeSga9d4YgRVnsaZW25naWk1zDAaHRntf4zT3dQJKttbge4SfANdGPPkqYGUL8TAwqVnXYiSUAS3HqU4V31K27obgU8JtsRQ\",\n \"public_key\": \"tpubD6NzVbkrYhZ4XuiN3Gj95q9uSc5SBQyV63cmVgcar4h3uUhpFo7v5PDYpBGmnjWU6AvPJGsDfhFGhQeZreu9Yj73qRHgUbTPvoeGp5zqWwL\",\n \"seed\": \"concert caution silent security delay egg bus category bean double bargain lunch\"\n }\n}"
}
]
},
@@ -734,9 +708,9 @@
"examples": [
{
"title": "Check if address is mine",
"curl": "curl -d'{\"method\": \"address_is_mine\", \"params\": {\"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\"}}' http://localhost:5279/",
"lbrynet": "lbrynet address is_mine mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_is_mine\", \"params\": {\"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\"}}).json()",
"curl": "curl -d'{\"method\": \"address_is_mine\", \"params\": {\"address\": \"mruESV2uxBZioC97PDsbuqjGKRCkviYRos\"}}' http://localhost:5279/",
"lbrynet": "lbrynet address is_mine mruESV2uxBZioC97PDsbuqjGKRCkviYRos",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_is_mine\", \"params\": {\"address\": \"mruESV2uxBZioC97PDsbuqjGKRCkviYRos\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": true\n}"
}
]
@@ -771,14 +745,14 @@
"curl": "curl -d'{\"method\": \"address_list\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet address list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_list\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"mrUJMH9thbp8N36pUWEwLbWhHS34396nrL\",\n \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"mjP4LqHLgiZh9Yt85dPKoEQfyXZWYvW26o\",\n \"motpLKY7NjMuAAikKCEctEsN7AgZZ8z9Fh\",\n \"mobAbiapbJhWi96iWmm6kS4kPA853qnDD6\",\n \"n3kXMe4wUH8PUcCMeGPUXWjKmjtay6qiiC\",\n \"mqtMpfGy9u4edrqx6disinppzoPw1dM5TA\",\n \"mx5gqJc4wqFVKJatCBX1wEVQUUbUWvLdpT\",\n \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"mgVPGtphs522HG6G9dEpLomsRjzRtNvyaD\",\n \"mxEMUZnfrUqZ7LgGSJKpftTzhxN9ksL7u8\",\n \"muZky9x51Anyg4e7vBmE7hvXDRyP5ob3Xt\",\n \"mv3F3Amp2JPSMUz1BHRLfYFrdgoxUTHh4b\",\n \"mfdcQg5Yw1eyxX1HkTUX4ifoMXcc7ckuvh\",\n \"mtvUjchQiRbsQZwKXqCH5WCFmfbLiU5GSx\",\n \"mk91amE4fy8ByNSyK2SFtQ5xx4DLLRVKxz\",\n \"mzeJaFRZMKpA6vuhXszQn1b88My7PTUgVJ\",\n \"n4Ustw8dtG4ZW4au3k1zPM3RcT1VrLNVSh\",\n \"mpZxHB6QXGr8ZUoQa9RdHRxMiMd6SVMHZ9\",\n \"mjCW8QbSjcGrDmpdzHcSiWT6d9XP2Bsw2P\",\n \"mushjCzKC83rDwJxoYeC6JRp8R6AEA9Ecw\",\n \"mwsrVmDgbmDB6Rc9PTQDfmq959XxZddN1e\",\n \"mnBjVptRpCyzSdVFR8uwqNkmDpScxHHYG9\",\n \"mgTmDwGvzP8dVkJz5kLf1PXGvW4X3Vi3a2\",\n \"mjZ83yJJcNyft8kRd6NKSZUghFfePspvxU\",\n \"mg2rpNzx5bSBdqV1CADR98pRjtG8USWWUL\",\n \"mfhkhk4NyH3yqz8izDQRytx9b1e3GvN1ho\"\n ]\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"mjJRfy3fpDc1QqpSKfExmdhcTXyossEqTp\",\n \"n3fKziJ6gTJXNMFD5uTT2SzsCm35BUqBMC\",\n \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"myA5CAex5LcxzWfsLytgzyMxSJcNQqsKHt\",\n \"mpcGVMt4WM16pUaEbQz77wNuwajDCG75EN\",\n \"miGb9wRahD39Hs4ZaQ9CFQuBkttwmLwTZs\",\n \"mybA14ZrM1TF8sxDcHLiY31bMztURhxxY3\",\n \"myhdrdTx5ZmfKaVcg4QgYiub2EBYPnkywQ\",\n \"mruESV2uxBZioC97PDsbuqjGKRCkviYRos\",\n \"mjbUc8iTY9yqsTsNNhKH9iehJrNvEoGZwq\",\n \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"mtMftuq8irZSZGMqRV4kbv558i2THU94hW\",\n \"mxwcZA9JejJ4qdLreAMcurk1LyFVYxB8MF\",\n \"moZXCin3xSUiUhDUtbMMg3pvcXWmpXJ8Ah\",\n \"mwVdTBKHwRVY1EDGTnrPDx6EVvsKMTRTg7\",\n \"mref6paiwNMQzTCgxM7BokGNqtFbUrTqdd\",\n \"mpgHxbSf9AMGqtg7tKFW9urQ2DdBxjtGAN\",\n \"mpoDuuAwpWSQFjmdfVD8DDo8bfJQhcvHVF\",\n \"mnENyzt7Lg7RbS9h8VX9GHWXrGcCKtg3U5\",\n \"mohQDtnEwVVqFJ155RDUtDYFvCmpzMAMSv\",\n \"miZ926v6sAnfowtQ52L42Sy9JDe7xPKN7P\",\n \"mqL999ZnSc6rAWKYzekqgAHRM2JYQwPWAW\",\n \"mvyN9Y5pUWo4XTok2fAJYHmrhiKMUPqivB\",\n \"msv3BiuJ4RHWEbdYE665DaxxGQbmTjtPW2\",\n \"miSnDhW4U5DDhjvUpZkGqeVXWYbe37yaRS\",\n \"mmd1DmjigWXF11iiqTT2MgVrh86i2USVMf\",\n \"micK9zMw8jAoyeL7csPp2aB2sYW4fHXH4J\"\n ]\n}"
},
{
"title": "List addresses in specified account",
"curl": "curl -d'{\"method\": \"address_list\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"}}' http://localhost:5279/",
"lbrynet": "lbrynet address list --account_id=\"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_list\", \"params\": {\"account_id\": \"mhDFwjypfcWake48LfTCuJhc5bKMJLpVvB\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"mvwqqZrxQrPsJaBFLbTKgY1AJEGT4rnbsD\",\n \"mqTmZM5pRxjq4NrfUb2Mcu7uQJARbsVt9f\",\n \"mmCaKwj1vziBChTDYaXrC35jrFiMSGB1Mx\",\n \"mjJxrDE3Wt4j9v43EMJEX99XEkLEgLTWjh\",\n \"mtb4b8Yv56zT5fe1vfHHeLf1aah84ZYRZk\",\n \"mvwj1crj6fvnSF1TmHQ8oBBcLFYVQvw9pN\",\n \"n3Mgh9yu5x18TvKLraHcn9aat83LqPHbAN\",\n \"myTBkGpVk8Wbyg1LRp8pw58ScSjY47ftNT\",\n \"mh1tNuT5FmHQ7aU97nmW5KJ7xNude5XAv6\",\n \"mxkHjdQg7CN4jrQfVYonvyNC1AB3VmoH5P\",\n \"mwChpQjWbQPrsrPB3eNqAUZRyM3Rj8UtGp\",\n \"n1zpHU7pYXAtkSd8mPhozdgnKyFThiuam3\",\n \"mpNvMpyUMqhoR4bTk3YK1CstB58cwacffG\",\n \"msxE3wXHvYjwmGXtNYZzjQGd4sAoKuuCnj\",\n \"n29Pgfu8LuZKA1m2XWNYJrm2UMGbhnyZ5W\",\n \"miBmBvRPMFJcV8ojLbaLX2i2HuZHr1ELKp\",\n \"n3Z2Rqhb8Amv9hnMRKpoWCeDB799Gc74kj\",\n \"n3NHngAEZZ281sJNZ1viDek48G9sBhaidT\",\n \"myEeoD166ZWmUbSZ7oWtdFGRxaZyiMGCiP\",\n \"mwRaG2iDvqmPNTKhKP76ofvycWZoH4inN1\",\n \"mpc68vNDe4zi558iyt4vPvoHixDVtgxHj1\",\n \"mt2ii95pM4P7G8MUAB7usLP8zLsYyPHVk8\",\n \"muyLFYW9FMsnqGHwUL4Y58jbUnduQkqd5a\",\n \"mkkLV3379AM15f8ZWQEQxjXMpn6ne134TE\",\n \"mfqxZzekYyVg4MExnN44uLZr9n6jBukjNY\",\n \"mfuXXWuGsCDkVUqGoPLV1fZ5FU8zSyciV2\"\n ]\n}"
"curl": "curl -d'{\"method\": \"address_list\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"}}' http://localhost:5279/",
"lbrynet": "lbrynet address list --account_id=\"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_list\", \"params\": {\"account_id\": \"mfeYAtr97JTR3wPYQMafz4sqxVw9sKxnnF\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"mnAJ3Uit18ZLhzeDNxtZFSPW8pyAZ1s3b1\",\n \"mioTWLxbBBkwBxzGVtfAhgJcfyXqfAVkVF\",\n \"mwA5FJ3C8dgzEzkdaLsTuvVTNSkSRVV9Hz\",\n \"mh6BL728vsFYzMD5coxFXmLpKxgYKWJsxk\",\n \"n2jHfxeNm8W4EbdhD3jFBiAmbHdgnQppAY\",\n \"mx5D2R8x54kXyKkPZRmed57fDFrLGTs16M\",\n \"mnTUtc4N5G8ktZaQEasckeLtnYvHY2zfps\",\n \"mnKJyfbHmY7tPqdaCfuxZAzRt7zMh3zvo1\",\n \"myGFZQj1XzsjEpyFV5qcecNs6eHRDbd9e9\",\n \"mpoFsBE3p85BS6NLhZyU7fYgK8FFFNiRo2\",\n \"mrKDmuenR5D8L8FuSu5gBn6QGxk2Y91dF2\",\n \"mxrTiTua6oPYjH9CoW9FvP6kMj2HA2qPNf\",\n \"mtnMjFABczz6WAuGHTf8gmCE6A4ZMey1jz\",\n \"mgCMxT5m14Y5buhQN5KTGp7u1fFgLzbmU5\",\n \"mvQKoAUe89VWi7yHWdn8yhFmKk7Q2dC7Pk\",\n \"mjJLJmpb5AvjubuQxooaqxRwRwfWhCrXvC\",\n \"n1sAHnV9Jn7ummJhPrwMaBiYDURx8fFFRi\",\n \"mtonAnGVr5HEv17UGcstLmXC5whqJv8UuM\",\n \"mqUgc6Xp2qFyGQgxytRYMDXGmaUderJ4iU\",\n \"mpaGuh2UMrvM8ehcvSdHdEPpKzSmmAoez4\",\n \"mnoTc3oBdzUa42UuDLm9MQzCgmfko8EV9U\",\n \"msP6swJtRWxSk5gv5bwXa1tQSm8VpaMyta\",\n \"n1JAGuN5UxbuW5SbWsGVC5jTURWtSSSdde\",\n \"mk58t3DXcPepvpo7c8QvoW35L6vJMq3EYS\",\n \"mj4QmYHJKFgDq65H4J26CcmTryBtmKYGnW\",\n \"n1fnnx3YFazDuz2hd5AUAvenkGnZXk9syN\"\n ]\n}"
}
]
},
@@ -800,7 +774,7 @@
"curl": "curl -d'{\"method\": \"address_unused\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet address unused",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_unused\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\"\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"mruESV2uxBZioC97PDsbuqjGKRCkviYRos\"\n}"
}
]
}
@@ -850,10 +824,10 @@
"examples": [
{
"title": "Delete a blob",
"curl": "curl -d'{\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\"}}' http://localhost:5279/",
"lbrynet": "lbrynet blob delete a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"Deleted a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\"\n}"
"curl": "curl -d'{\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"e53d7a88c1d5e8ae309ed3fe326bd71aa29f8f969c2dc657f600ac4166725ff879b081599b12e5368e1ecd292fa5e310\"}}' http://localhost:5279/",
"lbrynet": "lbrynet blob delete e53d7a88c1d5e8ae309ed3fe326bd71aa29f8f969c2dc657f600ac4166725ff879b081599b12e5368e1ecd292fa5e310",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"e53d7a88c1d5e8ae309ed3fe326bd71aa29f8f969c2dc657f600ac4166725ff879b081599b12e5368e1ecd292fa5e310\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"Deleted e53d7a88c1d5e8ae309ed3fe326bd71aa29f8f969c2dc657f600ac4166725ff879b081599b12e5368e1ecd292fa5e310\"\n}"
}
]
},
@@ -931,7 +905,7 @@
"curl": "curl -d'{\"method\": \"blob_list\", \"params\": {\"needed\": false, \"finished\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet blob list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"blob_list\", \"params\": {\"needed\": false, \"finished\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"e7d65f3d04d139b44959ea980e36b21a76873e5dc6482c13012646e664513e1a6fecb1df22e74e61289c67c647171356\",\n \"e09cdf12ee46f82ea9b22d67c315cce59be725cdadd409c4637d345ec5dbde159012719541390abe74a5c1df5c9085e6\",\n \"43d2c339ceaeff2dcf08f522f6fcf69471e1c6379c0c4eb8cda961e2939336a571f0c2cd4bf041a4b73be3995b55c5ee\"\n ]\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"e53d7a88c1d5e8ae309ed3fe326bd71aa29f8f969c2dc657f600ac4166725ff879b081599b12e5368e1ecd292fa5e310\",\n \"135a9740f563155af8fb9b2f31c7a942e6c955aca13b86caf6e879af966e850a5efb5401ff7b6b69f9e531d31bf4f081\",\n \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"2217e7fc6e556852849910b734b428604fd3704cab831d71a44149622a9285067d961f7cb720bbe151139ce5a832ae25\"\n ]\n}"
}
]
},
@@ -1006,10 +980,10 @@
"examples": [
{
"title": "Abandon a channel claim",
"curl": "curl -d'{\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet channel abandon cc242d221f78975c8011132882ee445b7d9b85cf",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"preview\": false, \"blocking\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001774ef780f69060a79f87351e45aabb64f8a625dd76719ca1e5ad18d938950bc8000000006b4830450221009c6a9b91d142c9bd226aa99a611ceca754b70f508d5d50e384e7f1156f675717022060ad22efd0b40ce972f1b1f6a19c6a284ffc3c70835b6fff03d597edff122d2a012102c8a246a5c6ad5cbbdc09c81397c3c4a833e85c569e4cd4698c873fbcdba80754ffffffff0134b7f505000000001976a9142c497ade76734a21d2e4191044a5649be92a457c88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"update\",\n \"confirmations\": 8,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mjZ83yJJcNyft8kRd6NKSZUghFfePspvxU\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"txid\": \"ab057975078bab66a8aecaef82cd022a1f59c0d1c2fb81b085eca024be62d746\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"ab057975078bab66a8aecaef82cd022a1f59c0d1c2fb81b085eca024be62d746\"\n }\n}"
"curl": "curl -d'{\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet channel abandon 3f6710c07d83e45e0434983d62b6b29530794121",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"preview\": false, \"blocking\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000012e623434c3ef9e6c0305fade6e8b1028fde34963746f25025771d28bb2cf9b47000000006b483045022100a8587da6a1f1ac023e83fe02babd02452f0d82877ac1e998dbd7f1c94bc181b1022058eaf1c53497bb85cce8fc4d221ba11b932ef4bda80ac9a758470546ad5ab9e701210356872df7d60c6022803123324524702308a57d453cd77de9a57185fc67d045aaffffffff0134b7f505000000001976a91422edc806fbf7009d40a85f930333927485ffb45688ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"update\",\n \"confirmations\": 8,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": 1557412290,\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mihe7uzo2CeWPAdCpPPwh7MkLwH53NoYHs\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"6a0a4765ae298fb8ce5fd45f56e5d0d823cf551a65d53766fc71cb89646c3a02\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"6a0a4765ae298fb8ce5fd45f56e5d0d823cf551a65d53766fc71cb89646c3a02\"\n }\n}"
}
]
},
@@ -1023,18 +997,18 @@
"description": "name of the channel prefixed with '@'",
"is_required": true
},
{
"name": "allow_duplicate_name",
"type": "bool",
"description": "create new channel even if one already exists with given name. default: false.",
"is_required": false
},
{
"name": "bid",
"type": "decimal",
"description": "amount to back the claim",
"is_required": true
},
{
"name": "allow_duplicate_name",
"type": "bool",
"description": "create new channel even if one already exists with given name. default: false.",
"is_required": false
},
{
"name": "title",
"type": "str",
@@ -1047,6 +1021,18 @@
"description": "description of the publication",
"is_required": false
},
{
"name": "email",
"type": "str",
"description": "email of channel owner",
"is_required": false
},
{
"name": "website_url",
"type": "str",
"description": "website url",
"is_required": false
},
{
"name": "featured",
"type": "list",
@@ -1071,18 +1057,6 @@
"description": "locations of the channel, consisting of 2 letter `country` code and a `state`, `city` and a postal `code` along with a `latitude` and `longitude`. for JSON RPC: pass a dictionary with aforementioned attributes as keys, eg: ... \"locations\": [{'country': 'US', 'state': 'NH'}] ... for command line: pass a colon delimited list with values in the following order: \"COUNTRY:STATE:CITY:CODE:LATITUDE:LONGITUDE\" making sure to include colon for blank values, for example to provide only the city: ... --locations=\"::Manchester\" with all values set: ... --locations=\"US:NH:Manchester:03101:42.990605:-71.460989\" optionally, you can just pass the \"LATITUDE:LONGITUDE\": ... --locations=\"42.990605:-71.460989\" finally, you can also pass JSON string of dictionary on the command line as you would via JSON RPC ... --locations=\"{'country': 'US', 'state': 'NH'}\"",
"is_required": false
},
{
"name": "email",
"type": "str",
"description": "email of channel owner",
"is_required": false
},
{
"name": "website_url",
"type": "str",
"description": "website url",
"is_required": false
},
{
"name": "thumbnail_url",
"type": "str",
@@ -1121,14 +1095,14 @@
"curl": "curl -d'{\"method\": \"channel_create\", \"params\": {\"name\": \"@channel\", \"bid\": \"1.0\", \"featured\": [], \"tags\": [], \"languages\": [], \"locations\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet channel create @channel 1.0",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_create\", \"params\": {\"name\": \"@channel\", \"bid\": \"1.0\", \"featured\": [], \"tags\": [], \"languages\": [], \"locations\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000011e34589b576524e2b251d1aef0bc9bffe6b09dc56bccb235dd14a8aacc7a0754010000006b48304502210096d195d46f432e15cf9407382c017e61581c62d12d9a6d7885f5fa2fddc2f5b1022004b05c768b55e91c0d192af8304e520c4ef5fc01243056d915f1b1e8a57b78e901210345c3879495bf78c69c37ab70132b02814887288fbe73bb8bad53c7eab3c8ea63ffffffff0200e1f5050000000084b508406368616e6e656c4c5d00125a0a583056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface61196d7576a91445ffef5669ef4c0b24960544e5b345408ec824f588acc462a029000000001976a9140a5da2e4a1f3ca9339fa6b9220cf7e7d286c5f5288ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mg2rpNzx5bSBdqV1CADR98pRjtG8USWWUL\",\n \"amount\": \"7.999876\",\n \"confirmations\": 2,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"54077accaaa814dd35b2cc6bc59db0e6ff9bbcf0aed151b2e22465579b58341e\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"3f4cef7bf01622c5c489ae4e8f6342f408903e17cfe0b62b8e2d9bfae86faa8d\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mgTmDwGvzP8dVkJz5kLf1PXGvW4X3Vi3a2\",\n \"amount\": \"6.983769\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"3f4cef7bf01622c5c489ae4e8f6342f408903e17cfe0b62b8e2d9bfae86faa8d\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.016107\",\n \"total_input\": \"7.999876\",\n \"total_output\": \"7.983769\",\n \"txid\": \"3f4cef7bf01622c5c489ae4e8f6342f408903e17cfe0b62b8e2d9bfae86faa8d\"\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001ea490e9b788fe3d86e39f1ddd26017a4a46a07815280bff285990901958bf096010000006a47304402201ddaf5c437e4d4de5de8d95da2eb46bddd3b3534cf6a4eb13f60a6abd6a2dfd5022026ae5018f82db4ca984f598f9afd571eb9a6ad7344c6fdb207a45665f7ac9501012102365c65f8694b4fb51051c8646320b6eedb1f75b08e59710315665668133f80deffffffff0200e1f5050000000084b508406368616e6e656c4c5d00125a0a583056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d466d7576a91491bb608a97377923f480cb50987ec466f97ae2e088acc462a029000000001976a914f6e8134b423b2b5052396954d35477fb9f0637b988ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mvyN9Y5pUWo4XTok2fAJYHmrhiKMUPqivB\",\n \"amount\": \"7.999876\",\n \"confirmations\": 2,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1557412290,\n \"txid\": \"96f08b9501099985f2bf805281076aa4a41760d2ddf1396ed8e38f789b0e49ea\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": null,\n \"txid\": \"f88531e59946176bc269a2a38518fa86fcb4b909ecf7d52dba2e34273cd813be\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"n42UY87hnpSR9fbacE6WCJDc8cyfHVa4a1\",\n \"amount\": \"6.983769\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"f88531e59946176bc269a2a38518fa86fcb4b909ecf7d52dba2e34273cd813be\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.016107\",\n \"total_input\": \"7.999876\",\n \"total_output\": \"7.983769\",\n \"txid\": \"f88531e59946176bc269a2a38518fa86fcb4b909ecf7d52dba2e34273cd813be\"\n }\n}"
},
{
"title": "Create a channel claim with all metadata",
"curl": "curl -d'{\"method\": \"channel_create\", \"params\": {\"name\": \"@bigchannel\", \"bid\": \"1.0\", \"title\": \"Big Channel\", \"description\": \"A channel with lots of videos.\", \"email\": \"creator@smallmedia.com\", \"featured\": [], \"tags\": [\"music\", \"art\"], \"languages\": [\"pt-BR\", \"uk\"], \"locations\": [\"BR\", \"UA::Kiyv\"], \"website_url\": \"http://smallmedia.com\", \"thumbnail_url\": \"http://smallmedia.com/logo.jpg\", \"cover_url\": \"http://smallmedia.com/logo.jpg\", \"preview\": false}}' http://localhost:5279/",
"curl": "curl -d'{\"method\": \"channel_create\", \"params\": {\"name\": \"@bigchannel\", \"bid\": \"1.0\", \"title\": \"Big Channel\", \"description\": \"A channel with lots of videos.\", \"email\": \"creator@smallmedia.com\", \"website_url\": \"http://smallmedia.com\", \"featured\": [], \"tags\": [\"music\", \"art\"], \"languages\": [\"pt-BR\", \"uk\"], \"locations\": [\"BR\", \"UA::Kiyv\"], \"thumbnail_url\": \"http://smallmedia.com/logo.jpg\", \"cover_url\": \"http://smallmedia.com/logo.jpg\", \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet channel create @bigchannel 1.0 --title=\"Big Channel\" --description=\"A channel with lots of videos.\" --email=\"creator@smallmedia.com\" --tags=music --tags=art --languages=pt-BR --languages=uk --locations=BR --locations=UA::Kiyv --website_url=\"http://smallmedia.com\" --thumbnail_url=\"http://smallmedia.com/logo.jpg\" --cover_url=\"http://smallmedia.com/logo.jpg\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_create\", \"params\": {\"name\": \"@bigchannel\", \"bid\": \"1.0\", \"title\": \"Big Channel\", \"description\": \"A channel with lots of videos.\", \"email\": \"creator@smallmedia.com\", \"featured\": [], \"tags\": [\"music\", \"art\"], \"languages\": [\"pt-BR\", \"uk\"], \"locations\": [\"BR\", \"UA::Kiyv\"], \"website_url\": \"http://smallmedia.com\", \"thumbnail_url\": \"http://smallmedia.com/logo.jpg\", \"cover_url\": \"http://smallmedia.com/logo.jpg\", \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001774ef780f69060a79f87351e45aabb64f8a625dd76719ca1e5ad18d938950bc8010000006b483045022100b3a9686f4f612ea691cb8850ddb3cc6c2b2f36d9b411ad4dfb0fc5e1b0a76b8c022023043747f9484052076e83a03cf5c10875bb18e035bb7fd61dbfd298262d91c7012103b0126d336c930ac4ff55a29fe0b24a9bca8b8abfa80c08fe998085bcdd04d08cffffffff0200e1f50500000000fd5001b50b406269676368616e6e656c4d25010012ab010a583056301006072a8648ce3d020106052b8104000a0342000469f71f2fe4e72111f0a743a799d1aacdb385aa9eb72d5e052c3b6e719a03e9c8507e74b162e39cd89c398cc023b9e12371fca741bac00bd8b5558db620fc5f24121663726561746f7240736d616c6c6d656469612e636f6d1a15687474703a2f2f736d616c6c6d656469612e636f6d22202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a7067420b426967204368616e6e656c4a1e41206368616e6e656c2077697468206c6f7473206f6620766964656f732e52202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a70675a056d757369635a0361727462050883011820620308ab016a0208206a0908e9011a044b6979766d7576a9142a6239574e39be4cb366a1c3f7e18bbe7efdc9a588ace221d305000000001976a914242c749c579ccaada560e0f3d4bfc447ae3f26c988ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mmQY6H5ZrVJgHHAWKQtmZB2nj4YAwq7SWz\",\n \"amount\": \"1.9993355\",\n \"confirmations\": 1,\n \"height\": 210,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mjP4LqHLgiZh9Yt85dPKoEQfyXZWYvW26o\",\n \"amount\": \"1.0\",\n \"claim_id\": \"f59a5a51dacbc14ca6858271f1d6da918071473c\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"@bigchannel\",\n \"nout\": 0,\n \"permanent_url\": \"@bigchannel#f59a5a51dacbc14ca6858271f1d6da918071473c\",\n \"txid\": \"02988e06db8b452191fc25cc12301896f64751bc8fb7a0345130b2c0e1680231\",\n \"type\": \"claim\",\n \"value\": {\n \"cover\": {\n \"url\": \"http://smallmedia.com/logo.jpg\"\n },\n \"description\": \"A channel with lots of videos.\",\n \"email\": \"creator@smallmedia.com\",\n \"languages\": [\n \"pt-BR\",\n \"uk\"\n ],\n \"locations\": [\n {\n \"country\": \"BR\"\n },\n {\n \"city\": \"Kiyv\",\n \"country\": \"UA\"\n }\n ],\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000469f71f2fe4e72111f0a743a799d1aacdb385aa9eb72d5e052c3b6e719a03e9c8507e74b162e39cd89c398cc023b9e12371fca741bac00bd8b5558db620fc5f24\",\n \"tags\": [\n \"music\",\n \"art\"\n ],\n \"thumbnail\": {\n \"url\": \"http://smallmedia.com/logo.jpg\"\n },\n \"title\": \"Big Channel\",\n \"website_url\": \"http://smallmedia.com\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mipDsnN5CyVPiXcD4WNB3swqCCmzM8w44w\",\n \"amount\": \"0.9772285\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"02988e06db8b452191fc25cc12301896f64751bc8fb7a0345130b2c0e1680231\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.022107\",\n \"total_input\": \"1.9993355\",\n \"total_output\": \"1.9772285\",\n \"txid\": \"02988e06db8b452191fc25cc12301896f64751bc8fb7a0345130b2c0e1680231\"\n }\n}"
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_create\", \"params\": {\"name\": \"@bigchannel\", \"bid\": \"1.0\", \"title\": \"Big Channel\", \"description\": \"A channel with lots of videos.\", \"email\": \"creator@smallmedia.com\", \"website_url\": \"http://smallmedia.com\", \"featured\": [], \"tags\": [\"music\", \"art\"], \"languages\": [\"pt-BR\", \"uk\"], \"locations\": [\"BR\", \"UA::Kiyv\"], \"thumbnail_url\": \"http://smallmedia.com/logo.jpg\", \"cover_url\": \"http://smallmedia.com/logo.jpg\", \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000012e623434c3ef9e6c0305fade6e8b1028fde34963746f25025771d28bb2cf9b47010000006a47304402207cc90fd6f98c1cf0d1ec4e306d34d91a772deee7df74512ce74e80e55d0761ab0220040c3b4c5205a19579f81a80b00fae3a3aa5210b12bd9ce093014ff614b3cf7b0121024e7978a5afa717e117ce4ce7c2a746872fdf51f5000a1929aab16b0dbadd09cfffffffff0200e1f50500000000fd5001b50b406269676368616e6e656c4d25010012ab010a583056301006072a8648ce3d020106052b8104000a0342000427e280bc4603d321e21866526bd8356241a60bb685f80e8850999c09cb4fd02d4682610a1db0b490fca59053ccae1405b0e56fd537129d1674afe5b1ad19f518121663726561746f7240736d616c6c6d656469612e636f6d1a15687474703a2f2f736d616c6c6d656469612e636f6d22202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a7067420b426967204368616e6e656c4a1e41206368616e6e656c2077697468206c6f7473206f6620766964656f732e52202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a70675a056d757369635a0361727462050883011820620308ab016a0208206a0908e9011a044b6979766d7576a9142cbb784d8075dc6da01c74007d125b6d577a515788ace221d305000000001976a914a0011029dbc52632024beb82ce65e35e618c8ddd88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"miZ926v6sAnfowtQ52L42Sy9JDe7xPKN7P\",\n \"amount\": \"1.9993355\",\n \"confirmations\": 1,\n \"height\": 210,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1557412290,\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mjbUc8iTY9yqsTsNNhKH9iehJrNvEoGZwq\",\n \"amount\": \"1.0\",\n \"claim_id\": \"d5b2bf1bdb558fb989addf7404cc1459a78bcf8e\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"@bigchannel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@bigchannel#d5b2bf1bdb558fb989addf7404cc1459a78bcf8e\",\n \"timestamp\": null,\n \"txid\": \"6add0aeef9de275b1fde43517fc7bdac32bb92c1f52783ad155e585f79b90a72\",\n \"type\": \"claim\",\n \"value\": {\n \"cover\": {\n \"url\": \"http://smallmedia.com/logo.jpg\"\n },\n \"description\": \"A channel with lots of videos.\",\n \"email\": \"creator@smallmedia.com\",\n \"languages\": [\n \"pt-BR\",\n \"uk\"\n ],\n \"locations\": [\n {\n \"country\": \"BR\"\n },\n {\n \"city\": \"Kiyv\",\n \"country\": \"UA\"\n }\n ],\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000427e280bc4603d321e21866526bd8356241a60bb685f80e8850999c09cb4fd02d4682610a1db0b490fca59053ccae1405b0e56fd537129d1674afe5b1ad19f518\",\n \"tags\": [\n \"music\",\n \"art\"\n ],\n \"thumbnail\": {\n \"url\": \"http://smallmedia.com/logo.jpg\"\n },\n \"title\": \"Big Channel\",\n \"website_url\": \"http://smallmedia.com\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mv6ygcdKPPGwnT1QvJWdE8SUjuaGUH2G4n\",\n \"amount\": \"0.9772285\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"6add0aeef9de275b1fde43517fc7bdac32bb92c1f52783ad155e585f79b90a72\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.022107\",\n \"total_input\": \"1.9993355\",\n \"total_output\": \"1.9772285\",\n \"txid\": \"6add0aeef9de275b1fde43517fc7bdac32bb92c1f52783ad155e585f79b90a72\"\n }\n}"
}
]
},
@@ -1190,14 +1164,14 @@
"curl": "curl -d'{\"method\": \"channel_list\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet channel list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_list\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"3f4cef7bf01622c5c489ae4e8f6342f408903e17cfe0b62b8e2d9bfae86faa8d\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\"\n },\n \"value_type\": \"channel\"\n }\n ]\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": 1557412290,\n \"txid\": \"f88531e59946176bc269a2a38518fa86fcb4b909ecf7d52dba2e34273cd813be\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\"\n },\n \"value_type\": \"channel\"\n }\n ]\n}"
},
{
"title": "Paginate your channel claims",
"curl": "curl -d'{\"method\": \"channel_list\", \"params\": {\"page\": 1, \"page_size\": 20}}' http://localhost:5279/",
"lbrynet": "lbrynet channel list --page=1 --page_size=20",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_list\", \"params\": {\"page\": 1, \"page_size\": 20}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"3f4cef7bf01622c5c489ae4e8f6342f408903e17cfe0b62b8e2d9bfae86faa8d\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_pages\": 1\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": 1557412290,\n \"txid\": \"f88531e59946176bc269a2a38518fa86fcb4b909ecf7d52dba2e34273cd813be\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_pages\": 1\n }\n}"
}
]
},
@@ -1229,54 +1203,6 @@
"description": "description of the publication",
"is_required": false
},
{
"name": "clear_featured",
"type": "bool",
"description": "clear existing featured content (prior to adding new ones)",
"is_required": false
},
{
"name": "featured",
"type": "list",
"description": "claim_ids of featured content in channel",
"is_required": false
},
{
"name": "clear_tags",
"type": "bool",
"description": "clear existing tags (prior to adding new ones)",
"is_required": false
},
{
"name": "tags",
"type": "list",
"description": "add content tags",
"is_required": false
},
{
"name": "clear_languages",
"type": "bool",
"description": "clear existing languages (prior to adding new ones)",
"is_required": false
},
{
"name": "languages",
"type": "list",
"description": "languages used by the channel, using RFC 5646 format, eg: for English `--languages=en` for Spanish (Spain) `--languages=es-ES` for Spanish (Mexican) `--languages=es-MX` for Chinese (Simplified) `--languages=zh-Hans` for Chinese (Traditional) `--languages=zh-Hant`",
"is_required": false
},
{
"name": "clear_locations",
"type": "bool",
"description": "clear existing locations (prior to adding new ones)",
"is_required": false
},
{
"name": "locations",
"type": "list",
"description": "locations of the channel, consisting of 2 letter `country` code and a `state`, `city` and a postal `code` along with a `latitude` and `longitude`. for JSON RPC: pass a dictionary with aforementioned attributes as keys, eg: ... \"locations\": [{'country': 'US', 'state': 'NH'}] ... for command line: pass a colon delimited list with values in the following order: \"COUNTRY:STATE:CITY:CODE:LATITUDE:LONGITUDE\" making sure to include colon for blank values, for example to provide only the city: ... --locations=\"::Manchester\" with all values set: ... --locations=\"US:NH:Manchester:03101:42.990605:-71.460989\" optionally, you can just pass the \"LATITUDE:LONGITUDE\": ... --locations=\"42.990605:-71.460989\" finally, you can also pass JSON string of dictionary on the command line as you would via JSON RPC ... --locations=\"{'country': 'US', 'state': 'NH'}\"",
"is_required": false
},
{
"name": "email",
"type": "str",
@@ -1289,6 +1215,54 @@
"description": "website url",
"is_required": false
},
{
"name": "featured",
"type": "list",
"description": "claim_ids of featured content in channel",
"is_required": false
},
{
"name": "clear_featured",
"type": "bool",
"description": "clear existing featured content (prior to adding new ones)",
"is_required": false
},
{
"name": "tags",
"type": "list",
"description": "add content tags",
"is_required": false
},
{
"name": "clear_tags",
"type": "bool",
"description": "clear existing tags (prior to adding new ones)",
"is_required": false
},
{
"name": "languages",
"type": "list",
"description": "languages used by the channel, using RFC 5646 format, eg: for English `--languages=en` for Spanish (Spain) `--languages=es-ES` for Spanish (Mexican) `--languages=es-MX` for Chinese (Simplified) `--languages=zh-Hans` for Chinese (Traditional) `--languages=zh-Hant`",
"is_required": false
},
{
"name": "clear_languages",
"type": "bool",
"description": "clear existing languages (prior to adding new ones)",
"is_required": false
},
{
"name": "locations",
"type": "list",
"description": "locations of the channel, consisting of 2 letter `country` code and a `state`, `city` and a postal `code` along with a `latitude` and `longitude`. for JSON RPC: pass a dictionary with aforementioned attributes as keys, eg: ... \"locations\": [{'country': 'US', 'state': 'NH'}] ... for command line: pass a colon delimited list with values in the following order: \"COUNTRY:STATE:CITY:CODE:LATITUDE:LONGITUDE\" making sure to include colon for blank values, for example to provide only the city: ... --locations=\"::Manchester\" with all values set: ... --locations=\"US:NH:Manchester:03101:42.990605:-71.460989\" optionally, you can just pass the \"LATITUDE:LONGITUDE\": ... --locations=\"42.990605:-71.460989\" finally, you can also pass JSON string of dictionary on the command line as you would via JSON RPC ... --locations=\"{'country': 'US', 'state': 'NH'}\"",
"is_required": false
},
{
"name": "clear_locations",
"type": "bool",
"description": "clear existing locations (prior to adding new ones)",
"is_required": false
},
{
"name": "thumbnail_url",
"type": "str",
@@ -1324,16 +1298,22 @@
"type": "bool",
"description": "do not broadcast the transaction",
"is_required": false
},
{
"name": "replace",
"type": "bool",
"description": "instead of modifying specific values on the channel, this will clear all existing values and only save passed in values, useful for form submissions where all values are always set",
"is_required": false
}
],
"returns": " {\n \"txid\": \"hash of transaction in hex\",\n \"height\": \"block where transaction was recorded\",\n \"inputs\": [\n {\n \"txid\": \"hash of transaction in hex\",\n \"nout\": \"position in the transaction\",\n \"height\": \"block where transaction was recorded\",\n \"amount\": \"value of the txo as a decimal\",\n \"address\": \"address of who can spend the txo\",\n \"confirmations\": \"number of confirmed blocks\",\n \"is_change\": \"payment to change address, only available when it can be determined\",\n \"is_mine\": \"payment to one of your accounts, only available when it can be determined\",\n \"type\": \"one of 'claim', 'support' or 'payment'\",\n \"name\": \"when type is 'claim' or 'support', this is the claim name\",\n \"claim_id\": \"when type is 'claim' or 'support', this is the claim id\",\n \"claim_op\": \"when type is 'claim', this determines if it is 'create' or 'update'\",\n \"value\": \"when type is 'claim' or 'support' with payload, this is the decoded protobuf payload\",\n \"value_type\": \"determines the type of the 'value' field: 'channel', 'stream', etc\",\n \"protobuf\": \"hex encoded raw protobuf version of 'value' field\",\n \"permanent_url\": \"when type is 'claim' or 'support', this is the long permanent claim URL\",\n \"signing_channel\": \"for signed claims only, metadata of signing channel\",\n \"is_channel_signature_valid\": \"for signed claims only, whether signature is valid\"\n }\n ],\n \"outputs\": [\n {\n \"txid\": \"hash of transaction in hex\",\n \"nout\": \"position in the transaction\",\n \"height\": \"block where transaction was recorded\",\n \"amount\": \"value of the txo as a decimal\",\n \"address\": \"address of who can spend the txo\",\n \"confirmations\": \"number of confirmed blocks\",\n \"is_change\": \"payment to change address, only available when it can be determined\",\n \"is_mine\": \"payment to one of your accounts, only available when it can be determined\",\n \"type\": \"one of 'claim', 'support' or 'payment'\",\n \"name\": \"when type is 'claim' or 'support', this is the claim name\",\n \"claim_id\": \"when type is 'claim' or 'support', this is the claim id\",\n \"claim_op\": \"when type is 'claim', this determines if it is 'create' or 'update'\",\n \"value\": \"when type is 'claim' or 'support' with payload, this is the decoded protobuf payload\",\n \"value_type\": \"determines the type of the 'value' field: 'channel', 'stream', etc\",\n \"protobuf\": \"hex encoded raw protobuf version of 'value' field\",\n \"permanent_url\": \"when type is 'claim' or 'support', this is the long permanent claim URL\",\n \"signing_channel\": \"for signed claims only, metadata of signing channel\",\n \"is_channel_signature_valid\": \"for signed claims only, whether signature is valid\"\n }\n ],\n \"total_input\": \"sum of inputs as a decimal\",\n \"total_output\": \"sum of outputs, sans fee, as a decimal\",\n \"total_fee\": \"fee amount\",\n \"hex\": \"entire transaction encoded in hex\"\n }",
"examples": [
{
"title": "Update a channel claim",
"curl": "curl -d'{\"method\": \"channel_update\", \"params\": {\"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"title\": \"New Channel\", \"featured\": [], \"clear_featured\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"new_signing_key\": false, \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet channel update cc242d221f78975c8011132882ee445b7d9b85cf --title=\"New Channel\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_update\", \"params\": {\"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"title\": \"New Channel\", \"featured\": [], \"clear_featured\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"new_signing_key\": false, \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000028daa6fe8fa9b2d8e2bb6e0cf173e9008f442638f4eae89c4c52216f07bef4c3f000000006a4730440220474b8f26edfa30227a371649f5e84281b8415fd93efb732ad62b3a8926847f7802200532015915560e9d38e54066cdefa2e96e4a979d23eecf543b536e57cde5f16a012102c8a246a5c6ad5cbbdc09c81397c3c4a833e85c569e4cd4698c873fbcdba80754ffffffffeb946c9db0d8cbb09c8fa25b52f7e33539837010c7029ad478c65a9f777db54b000000006a473044022046a8d75ae6750844e818d454dca8f5e4cbbd98784ecadec36f3811e0867add1f02206221a9c7e3bbe37c103c3732160e72987b52d8c275cf7d7bc1c3ead3b18387680121020d84aaf3307820862e274b5a1f960d3f162fa629aaf48f57e43d9449b9b2590effffffff0200e1f50500000000a6b708406368616e6e656c14cf859b7d5b44ee82281311805c97781f222d24cc4c6a00125a0a583056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119420b4e6577204368616e6e656c6d6d76a91445ffef5669ef4c0b24960544e5b345408ec824f588ac6ebeea0b000000001976a914409a0e2548c192053f575b43ea7a9e3213563e9d88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"3f4cef7bf01622c5c489ae4e8f6342f408903e17cfe0b62b8e2d9bfae86faa8d\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mnBjVptRpCyzSdVFR8uwqNkmDpScxHHYG9\",\n \"amount\": \"1.999604\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"txid\": \"4bb57d779f5ac678d49a02c71070833935e3f7525ba28f9cb0cbd8b09d6c94eb\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mmQY6H5ZrVJgHHAWKQtmZB2nj4YAwq7SWz\",\n \"amount\": \"1.9993355\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.0002685\",\n \"total_input\": \"2.999604\",\n \"total_output\": \"2.9993355\",\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\"\n }\n}"
"curl": "curl -d'{\"method\": \"channel_update\", \"params\": {\"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"title\": \"New Channel\", \"featured\": [], \"clear_featured\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"new_signing_key\": false, \"preview\": false, \"replace\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet channel update 3f6710c07d83e45e0434983d62b6b29530794121 --title=\"New Channel\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_update\", \"params\": {\"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"title\": \"New Channel\", \"featured\": [], \"clear_featured\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"new_signing_key\": false, \"preview\": false, \"replace\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000002be13d83c27342eba2dd5f7ec09b9b4fc86fa1885a3a269c26b174699e53185f8000000006b483045022100960ca95f03525474e75d2648171edf82471a91b687d6573953dd2f65af7d341502201ec36a31b49127f83d311bec01330cac8688db14e04395f36da6b651c149ccda01210356872df7d60c6022803123324524702308a57d453cd77de9a57185fc67d045aaffffffffb7a77fbd2a247970573a4f67f5760c124e22c8f96e1985edd218d8d2298437a3000000006b48304502210085d8e789ecc0533f12399c12eb22cf7e611090d3aa08d03b55ee9e965597740c022053492e3c5fd1812d35c6c1ddf99a7fed5c27d8bcb463e1175d161555391f74e40121034f42fe5f87754a38a9e4ff74c92641e5b7cce0cb1fac01f7b42ea3209ef5443cffffffff0200e1f50500000000a6b708406368616e6e656c142141793095b2b6623d9834045ee4837dc010673f4c6a00125a0a583056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46420b4e6577204368616e6e656c6d6d76a91491bb608a97377923f480cb50987ec466f97ae2e088ac6ebeea0b000000001976a9142152297b3b1a61303c5958bc1640c9c382e85d6688ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": 1557412290,\n \"txid\": \"f88531e59946176bc269a2a38518fa86fcb4b909ecf7d52dba2e34273cd813be\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"n42UY87hnpSR9fbacE6WCJDc8cyfHVa4a1\",\n \"amount\": \"1.999604\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1557412290,\n \"txid\": \"a3378429d2d818d2ed85196ef9c8224e120c76f5674f3a577079242abd7fa7b7\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": null,\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"miZ926v6sAnfowtQ52L42Sy9JDe7xPKN7P\",\n \"amount\": \"1.9993355\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.0002685\",\n \"total_input\": \"2.999604\",\n \"total_output\": \"2.9993355\",\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\"\n }\n}"
}
]
}
@@ -1372,20 +1352,20 @@
"curl": "curl -d'{\"method\": \"claim_list\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet claim list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"claim_list\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ]\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": 1557412290,\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ]\n}"
},
{
"title": "Paginate your claims",
"curl": "curl -d'{\"method\": \"claim_list\", \"params\": {\"page\": 1, \"page_size\": 20}}' http://localhost:5279/",
"lbrynet": "lbrynet claim list --page=1 --page_size=20",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"claim_list\", \"params\": {\"page\": 1, \"page_size\": 20}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mmu5Wxcx5pxSWi11kVSNR3VJjEqenqfr6N\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"@channel#cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"txid\": \"c80b9538d918ade5a19c7176dd25a6f864bbaa451e35879fa76090f680f74e77\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_pages\": 1\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mtoWk4QmGYMGsw89PJ8QKQuHQmaTTDPrUA\",\n \"amount\": \"1.0\",\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#3f6710c07d83e45e0434983d62b6b29530794121\",\n \"timestamp\": 1557412290,\n \"txid\": \"479bcfb28bd2715702256f746349e3fd28108b6edefa05036c9eefc33434622e\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_pages\": 1\n }\n}"
}
]
},
{
"name": "claim_search",
"description": "Search for stream and channel claims on the blockchain.\n\nUse --channel_id=<channel_id> to list all stream claims in a channel.",
"description": "Search for stream and channel claims on the blockchain.\n\nUse --channel_id=<channel_id> or --channel_name=<channel_name> to list all stream claims in a channel.",
"arguments": [
{
"name": "name",
@@ -1417,6 +1397,12 @@
"description": "limit search to specific channel claim id (returns stream claims)",
"is_required": false
},
{
"name": "channel_name",
"type": "str",
"description": "limit search to specific channel name (returns stream claims)",
"is_required": false
},
{
"name": "winning",
"type": "bool",
@@ -1440,17 +1426,17 @@
"examples": [
{
"title": "Search for all claims in channel",
"curl": "curl -d'{\"method\": \"claim_search\", \"params\": {\"channel_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"winning\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet claim search --channel_id=\"cc242d221f78975c8011132882ee445b7d9b85cf\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"claim_search\", \"params\": {\"channel_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"winning\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"absolute_channel_position\": 0,\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_sequence\": -1,\n \"decoded_claim\": true,\n \"depth\": 1,\n \"effective_amount\": \"1.0\",\n \"has_signature\": true,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"protobuf\": \"01cf859b7d5b44ee82281311805c97781f222d24cce145c0ad7c3c76cd83b5f8044d097413f4198e39a8b4d8012e4055de83212fb94c12834f444142c49a9f46a786b31236b79c7612bdfccae897ef372792b9894e0a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"signature_is_valid\": true,\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"supports\": [],\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"valid_at_height\": 214,\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n }\n }\n ],\n \"page\": 1,\n \"page_size\": 10,\n \"total_pages\": 1\n }\n}"
"curl": "curl -d'{\"method\": \"claim_search\", \"params\": {\"channel_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"winning\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet claim search --channel_id=\"3f6710c07d83e45e0434983d62b6b29530794121\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"claim_search\", \"params\": {\"channel_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"winning\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"absolute_channel_position\": 0,\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_sequence\": -1,\n \"confirmations\": 1,\n \"decoded_claim\": true,\n \"effective_amount\": \"1.0\",\n \"has_signature\": true,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"signature_is_valid\": true,\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"supports\": [],\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"valid_at_height\": 214,\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n }\n }\n ],\n \"page\": 1,\n \"page_size\": 10,\n \"total_pages\": 1\n }\n}"
},
{
"title": "Search for claims matching a name",
"curl": "curl -d'{\"method\": \"claim_search\", \"params\": {\"name\": \"astream\", \"winning\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet claim search --name=\"astream\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"claim_search\", \"params\": {\"name\": \"astream\", \"winning\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_sequence\": -1,\n \"decoded_claim\": true,\n \"depth\": 1,\n \"effective_amount\": \"1.0\",\n \"has_signature\": true,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"protobuf\": \"01cf859b7d5b44ee82281311805c97781f222d24cce145c0ad7c3c76cd83b5f8044d097413f4198e39a8b4d8012e4055de83212fb94c12834f444142c49a9f46a786b31236b79c7612bdfccae897ef372792b9894e0a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"signature_is_valid\": true,\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"supports\": [],\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"valid_at_height\": 214,\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n }\n }\n ],\n \"page\": 1,\n \"page_size\": 1,\n \"total_pages\": 1\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_sequence\": -1,\n \"confirmations\": 1,\n \"decoded_claim\": true,\n \"effective_amount\": \"1.0\",\n \"has_signature\": true,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"signature_is_valid\": true,\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"supports\": [],\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"valid_at_height\": 214,\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n }\n }\n ],\n \"page\": 1,\n \"page_size\": 1,\n \"total_pages\": 1\n }\n}"
}
]
}
@@ -1597,9 +1583,9 @@
"examples": [
{
"title": "Delete a file",
"curl": "curl -d'{\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"}}' http://localhost:5279/",
"lbrynet": "lbrynet file delete --claim_id=\"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"}}).json()",
"curl": "curl -d'{\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"}}' http://localhost:5279/",
"lbrynet": "lbrynet file delete --claim_id=\"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": true\n}"
}
]
@@ -1706,14 +1692,14 @@
"curl": "curl -d'{\"method\": \"file_list\", \"params\": {\"reverse\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet file list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_list\", \"params\": {\"reverse\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"download_directory\": \"/tmp\",\n \"download_path\": null,\n \"file_name\": \"tmpit97x87b\",\n \"key\": \"40d70a655061b7981b6d36a84d985fdc\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01cf859b7d5b44ee82281311805c97781f222d24cce145c0ad7c3c76cd83b5f8044d097413f4198e39a8b4d8012e4055de83212fb94c12834f444142c49a9f46a786b31236b79c7612bdfccae897ef372792b9894e0a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"5bb823532eb1994bbb6c4a7ac44713249768f6e329e6e58a2c1e128ef9a029f850c30757909d0f961f7143a3b7ea439f\",\n \"stream_name\": \"tmpit97x87b\",\n \"suggested_file_name\": \"tmpit97x87b\",\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"tx\": null,\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"written_bytes\": null\n },\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"63395891e9172ef41f70197c08a528fd24bed596\",\n \"claim_name\": \"blank-image\",\n \"completed\": true,\n \"download_directory\": \"/tmp\",\n \"download_path\": null,\n \"file_name\": \"tmpx0pcyp9a.png\",\n \"key\": \"041b8782776581110cc00f7dec47fefa\",\n \"metadata\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"mv3F3Amp2JPSMUz1BHRLfYFrdgoxUTHh4b\",\n \"amount\": 0.3,\n \"currency\": \"LBC\"\n },\n \"image\": {\n \"height\": 7,\n \"width\": 5\n },\n \"languages\": [\n \"en\"\n ],\n \"license\": \"Public Domain\",\n \"license_url\": \"http://public-domain.org\",\n \"locations\": [\n {\n \"city\": \"Manchester\",\n \"country\": \"US\",\n \"state\": \"NH\"\n }\n ],\n \"release_time\": \"1555941592\",\n \"source\": {\n \"hash\": \"06003bbee8aece0543ed9d9cecc48be1d996cfeff9837a1aed1d961caeda82af\",\n \"media_type\": \"image/png\",\n \"name\": \"tmpx0pcyp9a.png\",\n \"sd_hash\": \"e09cdf12ee46f82ea9b22d67c315cce59be725cdadd409c4637d345ec5dbde159012719541390abe74a5c1df5c9085e6\",\n \"size\": \"99\"\n },\n \"stream_type\": \"image\",\n \"tags\": [\n \"blank\",\n \"art\"\n ],\n \"thumbnail\": {\n \"url\": \"http://smallmedia.com/thumbnail.jpg\"\n },\n \"title\": \"Blank Image\"\n },\n \"mime_type\": \"image/png\",\n \"nout\": 0,\n \"outpoint\": \"595056aa6d429d732a245ba6033b6ce54fa862a29c3a96da08a22acc4f3495a1:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01cf859b7d5b44ee82281311805c97781f222d24cc291bbb2c67e9438461d61d7fbb1e8ccd889c432eda03f0ba66909a59ce9c1ac0c375a06a6f9c8a877a973e9cdad15070bca4367f6de301d56932055e782430d90ad5010a720a2006003bbee8aece0543ed9d9cecc48be1d996cfeff9837a1aed1d961caeda82af120f746d7078307063797039612e706e6718632209696d6167652f706e673230e09cdf12ee46f82ea9b22d67c315cce59be725cdadd409c4637d345ec5dbde159012719541390abe74a5c1df5c9085e6120650696361736f1a0d5075626c696320446f6d61696e2218687474703a2f2f7075626c69632d646f6d61696e2e6f726728d891f7e5053222080112196f9f4c376b984270e4ec75c870f0b5faac1b3dd6985c747a30188087a70e520408051007420b426c616e6b20496d6167654a184120626c616e6b20504e472074686174206973203578372e52252Line truncated
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"confirmations\": 3,\n \"content_fee\": null,\n \"download_directory\": null,\n \"download_path\": null,\n \"file_name\": null,\n \"height\": 214,\n \"key\": \"de672c28f2060f41575f08bd9aab2cb8\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"65b6982a8fddae13c12390608c58a18f1368bcb73f53b31990d4be093827f3f1945eec69b84f1ca2996a1f070a3cd7f3\",\n \"stream_name\": \"tmpfmcqxqr9\",\n \"suggested_file_name\": \"tmpfmcqxqr9\",\n \"timestamp\": 1557412291,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"written_bytes\": null\n },\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"cce9db7375721826197b998d2425809892bbdc93\",\n \"claim_name\": \"blank-image\",\n \"completed\": true,\n \"confirmations\": -1,\n \"content_fee\": null,\n \"download_directory\": null,\n \"download_path\": null,\n \"file_name\": null,\n \"height\": -1,\n \"key\": \"532aced13a8b5f9c63d7e95879f3d251\",\n \"metadata\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"n3fKziJ6gTJXNMFD5uTT2SzsCm35BUqBMC\",\n \"amount\": 0.3,\n \"currency\": \"LBC\"\n },\n \"image\": {\n \"height\": 7,\n \"width\": 5\n },\n \"languages\": [\n \"en\"\n ],\n \"license\": \"Public Domain\",\n \"license_url\": \"http://public-domain.org\",\n \"locations\": [\n {\n \"city\": \"Manchester\",\n \"country\": \"US\",\n \"state\": \"NH\"\n }\n ],\n \"release_time\": \"1557412265\",\n \"source\": {\n \"hash\": \"6c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545\",\n \"media_type\": \"image/png\",\n \"name\": \"tmp61vr1_8a.png\",\n \"sd_hash\": \"135a9740f563155af8fb9b2f31c7a942e6c955aca13b86caf6e879af966e850a5efb5401ff7b6b69f9e531d31bf4f081\",\n \"size\": \"99\"\n },\n \"stream_type\": \"image\",\n \"tags\": [\n \"blank\",\n \"art\"\n ],\n \"thumbnail\": {\n \"url\": \"http://smallmedia.com/thumbnail.jpg\"\n },\n \"title\": \"Blank Image\"\n },\n \"mime_type\": \"image/png\",\n \"nout\": 0,\n \"outpoint\": \"c8926a8c21f12e96ec7b625fe337a56a60be6ae95df71794e66ae5dd32c9f8d7:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673fe1cd9b2bb7577c6eec2b6b13aa37b7723c785934ba1598e25e4274d2d03dde331b6915f66ef5da0d8a288c4e5de567284a6ef557617f49467f83f77a33e4791a0ae6010a82010a306c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545120f746d7036317672315f38612e706e6718632209696d6167652f706e673230135a9740f563155af8fb9b2f31c7a942e6c955aca13b86caf6e879af966e850a5efb5401ff7b6b69f9e531d31bf4f0Line truncated
},
{
"title": "List files matching a parameter",
"curl": "curl -d'{\"method\": \"file_list\", \"params\": {\"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\", \"reverse\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet file list --claim_id=\"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_list\", \"params\": {\"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\", \"reverse\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"download_directory\": \"/tmp\",\n \"download_path\": null,\n \"file_name\": \"tmpit97x87b\",\n \"key\": \"40d70a655061b7981b6d36a84d985fdc\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01cf859b7d5b44ee82281311805c97781f222d24cce145c0ad7c3c76cd83b5f8044d097413f4198e39a8b4d8012e4055de83212fb94c12834f444142c49a9f46a786b31236b79c7612bdfccae897ef372792b9894e0a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"5bb823532eb1994bbb6c4a7ac44713249768f6e329e6e58a2c1e128ef9a029f850c30757909d0f961f7143a3b7ea439f\",\n \"stream_name\": \"tmpit97x87b\",\n \"suggested_file_name\": \"tmpit97x87b\",\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"tx\": null,\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"written_bytes\": null\n }\n ]\n}"
"curl": "curl -d'{\"method\": \"file_list\", \"params\": {\"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\", \"reverse\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet file list --claim_id=\"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_list\", \"params\": {\"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\", \"reverse\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"confirmations\": 3,\n \"content_fee\": null,\n \"download_directory\": null,\n \"download_path\": null,\n \"file_name\": null,\n \"height\": 214,\n \"key\": \"de672c28f2060f41575f08bd9aab2cb8\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"65b6982a8fddae13c12390608c58a18f1368bcb73f53b31990d4be093827f3f1945eec69b84f1ca2996a1f070a3cd7f3\",\n \"stream_name\": \"tmpfmcqxqr9\",\n \"suggested_file_name\": \"tmpfmcqxqr9\",\n \"timestamp\": 1557412291,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"written_bytes\": null\n }\n ]\n}"
}
]
},
@@ -1755,6 +1741,88 @@
"returns": "(list) list of blobs reflected",
"examples": []
},
{
"name": "file_save",
"description": "Output a download to a file",
"arguments": [
{
"name": "file_name",
"type": "str",
"description": "delete by file name in downloads folder",
"is_required": false
},
{
"name": "download_directory",
"type": "str",
"description": "delete by file name in downloads folder",
"is_required": false
},
{
"name": "sd_hash",
"type": "str",
"description": "delete by file sd hash",
"is_required": false
},
{
"name": "stream_hash",
"type": "str",
"description": "delete by file stream hash",
"is_required": false
},
{
"name": "rowid",
"type": "int",
"description": "delete by file row id",
"is_required": false
},
{
"name": "claim_id",
"type": "str",
"description": "delete by file claim id",
"is_required": false
},
{
"name": "txid",
"type": "str",
"description": "delete by file claim txid",
"is_required": false
},
{
"name": "nout",
"type": "int",
"description": "delete by file claim nout",
"is_required": false
},
{
"name": "claim_name",
"type": "str",
"description": "delete by file claim name",
"is_required": false
},
{
"name": "channel_claim_id",
"type": "str",
"description": "delete by file channel claim id",
"is_required": false
},
{
"name": "channel_name",
"type": "str",
"description": "delete by file channel claim name",
"is_required": false
}
],
"returns": " {\n \"completed\": \"(bool) true if download is completed\",\n \"file_name\": \"(str) name of file\",\n \"download_directory\": \"(str) download directory\",\n \"points_paid\": \"(float) credit paid to download file\",\n \"stopped\": \"(bool) true if download is stopped\",\n \"stream_hash\": \"(str) stream hash of file\",\n \"stream_name\": \"(str) stream name\",\n \"suggested_file_name\": \"(str) suggested file name\",\n \"sd_hash\": \"(str) sd hash of file\",\n \"download_path\": \"(str) download path of file\",\n \"mime_type\": \"(str) mime type of file\",\n \"key\": \"(str) key attached to file\",\n \"total_bytes_lower_bound\": \"(int) lower bound file size in bytes\",\n \"total_bytes\": \"(int) file upper bound size in bytes\",\n \"written_bytes\": \"(int) written size in bytes\",\n \"blobs_completed\": \"(int) number of fully downloaded blobs\",\n \"blobs_in_stream\": \"(int) total blobs on stream\",\n \"blobs_remaining\": \"(int) total blobs remaining to download\",\n \"status\": \"(str) downloader status\",\n \"claim_id\": \"(str) None if claim is not found else the claim id\",\n \"txid\": \"(str) None if claim is not found else the transaction id\",\n \"nout\": \"(int) None if claim is not found else the transaction output index\",\n \"outpoint\": \"(str) None if claim is not found else the tx and output\",\n \"metadata\": \"(dict) None if claim is not found else the claim metadata\",\n \"channel_claim_id\": \"(str) None if claim is not found or not signed\",\n \"channel_name\": \"(str) None if claim is not found or not signed\",\n \"claim_name\": \"(str) None if claim is not found else the claim name\"\n }",
"examples": [
{
"title": "Save a file to the downloads directory",
"curl": "curl -d'{\"method\": \"file_save\", \"params\": {\"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\"}}' http://localhost:5279/",
"lbrynet": "lbrynet file save --sd_hash=\"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_save\", \"params\": {\"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\"}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"confirmations\": 3,\n \"content_fee\": null,\n \"download_directory\": null,\n \"download_path\": null,\n \"file_name\": null,\n \"height\": 214,\n \"key\": \"de672c28f2060f41575f08bd9aab2cb8\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"status\": \"running\",\n \"stopped\": false,\n \"stream_hash\": \"65b6982a8fddae13c12390608c58a18f1368bcb73f53b31990d4be093827f3f1945eec69b84f1ca2996a1f070a3cd7f3\",\n \"stream_name\": \"tmpfmcqxqr9\",\n \"suggested_file_name\": \"tmpfmcqxqr9\",\n \"timestamp\": 1557412291,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"written_bytes\": null\n }\n}"
}
]
},
{
"name": "file_set_status",
"description": "Start or stop downloading a file",
@@ -1841,7 +1909,7 @@
"curl": "curl -d'{\"method\": \"settings_get\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet settings get",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"settings_get\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"announce_head_and_sd_only\": true,\n \"api\": \"localhost:5279\",\n \"blob_download_timeout\": 30.0,\n \"blockchain_name\": \"lbrycrd_regtest\",\n \"cache_time\": 150,\n \"comment_server\": \"http://comments.lbry.com:2903/api\",\n \"components_to_skip\": [\n \"dht\",\n \"upnp\",\n \"hash_announcer\",\n \"peer_protocol_server\"\n ],\n \"concurrent_blob_announcers\": 10,\n \"concurrent_reflector_uploads\": 10,\n \"config\": \"/home/lex/.local/share/lbry/lbrynet/daemon_settings.yml\",\n \"data_dir\": \"/tmp/tmprlkz78lb\",\n \"download_dir\": \"/tmp/tmprlkz78lb\",\n \"download_timeout\": 30.0,\n \"fixed_peer_delay\": 2.0,\n \"known_dht_nodes\": [],\n \"lbryum_servers\": [\n [\n \"127.0.0.1\",\n 50001\n ]\n ],\n \"max_connections_per_download\": 8,\n \"max_key_fee\": {\n \"amount\": 50.0,\n \"currency\": \"USD\"\n },\n \"network_interface\": \"0.0.0.0\",\n \"node_rpc_timeout\": 5.0,\n \"peer_connect_timeout\": 2.0,\n \"reflect_streams\": true,\n \"reflector_servers\": [\n [\n \"127.0.0.1\",\n 5566\n ]\n ],\n \"s3_headers_depth\": 960,\n \"share_usage_data\": false,\n \"split_buckets_under_index\": 1,\n \"tcp_port\": 3333,\n \"udp_port\": 4444,\n \"use_upnp\": false,\n \"wallet_dir\": \"/tmp/tmprlkz78lb\"\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"announce_head_and_sd_only\": true,\n \"api\": \"localhost:5279\",\n \"blob_download_timeout\": 30.0,\n \"blockchain_name\": \"lbrycrd_regtest\",\n \"cache_time\": 150,\n \"comment_server\": \"http://comments.lbry.com:2903/api\",\n \"components_to_skip\": [\n \"dht\",\n \"upnp\",\n \"hash_announcer\",\n \"peer_protocol_server\"\n ],\n \"concurrent_blob_announcers\": 10,\n \"concurrent_reflector_uploads\": 10,\n \"config\": \"/home/jack/.lbrynet/daemon_settings.yml\",\n \"data_dir\": \"/tmp/tmppe9osroo\",\n \"download_dir\": \"/tmp/tmppe9osroo\",\n \"download_timeout\": 30.0,\n \"fixed_peer_delay\": 2.0,\n \"known_dht_nodes\": [],\n \"lbryum_servers\": [\n [\n \"127.0.0.1\",\n 50001\n ]\n ],\n \"max_connections_per_download\": 8,\n \"max_key_fee\": {\n \"amount\": 50.0,\n \"currency\": \"USD\"\n },\n \"network_interface\": \"0.0.0.0\",\n \"node_rpc_timeout\": 5.0,\n \"peer_connect_timeout\": 2.0,\n \"reflect_streams\": true,\n \"reflector_servers\": [\n [\n \"127.0.0.1\",\n 5566\n ]\n ],\n \"s3_headers_depth\": 960,\n \"save_blobs\": true,\n \"save_files\": true,\n \"share_usage_data\": false,\n \"split_buckets_under_index\": 1,\n \"tcp_port\": 3333,\n \"udp_port\": 4444,\n \"use_upnp\": false,\n \"wallet_dir\": \"/tmp/tmppe9osroo\"\n }\n}"
}
]
},
@@ -1902,10 +1970,10 @@
"examples": [
{
"title": "Abandon a stream claim",
"curl": "curl -d'{\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream abandon e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\", \"preview\": false, \"blocking\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"010000000198b89d19b4e5685b304e7583c9b57087ff6ba60ef8eaadc59bea88755ef22feb000000006a47304402201aeff9426e7c8508da8beb8dd1ebcddeea80019c76fd2b780cfad179b93e3ab20220760c3547cae27826dd671a99592220825d91c419b334889f5fbad9d9b7652754012103480815803999a8661f93bc2ab3c7c31eb09ac4091db1851fd716c848e9123eb1ffffffff0134b7f505000000001976a9146a36a7e81ab9086de0c5aded6fde84fad4c0d09788ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"update\",\n \"confirmations\": 3,\n \"height\": 214,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mqCZPwo3NaCVSA8aJQwE6YYghRG6YKoZem\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"txid\": \"16533cc68da2df19345be236978786c41b285ff0ccb44e41ff9f976c0f7e263b\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"16533cc68da2df19345be236978786c41b285ff0ccb44e41ff9f976c0f7e263b\"\n }\n}"
"curl": "curl -d'{\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream abandon ed10be11aef6501957c61077a1a8d0ae2ee69a9a",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\", \"preview\": false, \"blocking\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000016bfeb1c5a9f6ba9993982efcf6b3d263af20959caa96ca2f3e119cdb2a9bb5a9000000006b483045022100ce0d0e3c393ca028471d656bc8f0cf98128d6c4ac191b72d1729a8ad1d29fc6402201803d1e5f6b571786abc3ed99f69b44d7002d3fffb91ef188f4462511adf94da012103ee840c67b3bf07f9be296c33298dc25fa4cc10759079fe0b490030f5c0ed243bffffffff0134b7f505000000001976a914201e4da198f796d551193a574289f1a57b8ef8ef88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"update\",\n \"confirmations\": 3,\n \"height\": 214,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"miSnDhW4U5DDhjvUpZkGqeVXWYbe37yaRS\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"f6baccc6e166ffc59cb21ac6e6f3de44d817095c485881ece50e6bd7b0ca4180\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"f6baccc6e166ffc59cb21ac6e6f3de44d817095c485881ece50e6bd7b0ca4180\"\n }\n}"
}
]
},
@@ -1933,12 +2001,6 @@
"description": "name of the content (can only consist of a-z A-Z 0-9 and -(dash))",
"is_required": true
},
{
"name": "allow_duplicate_name",
"type": "bool",
"description": "create new claim even if one already exists with given name. default: false.",
"is_required": false
},
{
"name": "bid",
"type": "decimal",
@@ -1951,6 +2013,12 @@
"description": "path to file to be associated with name.",
"is_required": true
},
{
"name": "allow_duplicate_name",
"type": "bool",
"description": "create new claim even if one already exists with given name. default: false.",
"is_required": false
},
{
"name": "fee_currency",
"type": "string",
@@ -2053,6 +2121,12 @@
"description": "claim id of the publisher channel",
"is_required": false
},
{
"name": "channel_name",
"type": "str",
"description": "name of the publisher channel",
"is_required": false
},
{
"name": "channel_account_id",
"type": "str",
@@ -2082,17 +2156,17 @@
"examples": [
{
"title": "Create a stream claim without metadata",
"curl": "curl -d'{\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpit97x87b\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream create astream 1.0 /tmp/tmpit97x87b",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpit97x87b\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000018daa6fe8fa9b2d8e2bb6e0cf173e9008f442638f4eae89c4c52216f07bef4c3f010000006a4730440220322f0be42de2a348dffdac061501a120ad1b9bea997e01178df1bc5e96923d6902201e03f86f72c1f7fd33866bf50939188b1ef55b765125499590ae8946467eeed2012103ef7ff17b5897e6bb9da37754e118ac2d9cda4a53ffa110b1554e413125465d5dffffffff0200e1f50500000000a8b5076173747265616d4c82000a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc76d7576a914b122754d9d7432f98eec4e87c21b4982c8b9280e88ac38fb9423000000001976a9149da5548b96964cf84f10bd44674c38a0edc2236488ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mgTmDwGvzP8dVkJz5kLf1PXGvW4X3Vi3a2\",\n \"amount\": \"6.983769\",\n \"confirmations\": 4,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"3f4cef7bf01622c5c489ae4e8f6342f408903e17cfe0b62b8e2d9bfae86faa8d\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"txid\": \"7c5483e4adc6d351c7d60466db23dca36379e2ec7a48ecd3642a007bedac5724\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mutWSX3pmSpGejnTgrMP8s1xCbPkuuzuH5\",\n \"amount\": \"5.969662\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"7c5483e4adc6d351c7d60466db23dca36379e2ec7a48ecd3642a007bedac5724\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.014107\",\n \"total_input\": \"6.983769\",\n \"total_output\": \"6.969662\",\n \"txid\": \"7c5483e4adc6d351c7d60466db23dca36379e2ec7a48ecd3642a007bedac5724\"\n }\n}"
"curl": "curl -d'{\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpfmcqxqr9\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream create astream 1.0 /tmp/tmpfmcqxqr9",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpfmcqxqr9\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001be13d83c27342eba2dd5f7ec09b9b4fc86fa1885a3a269c26b174699e53185f8010000006b4830450221009276471c41cb424518112603ca931b5555c48378966363a73425c746475c7b8b02207f1267c3b65260369b86a8a428764006888ca3b9e1f5be94d141697f5ac144070121034f42fe5f87754a38a9e4ff74c92641e5b7cce0cb1fac01f7b42ea3209ef5443cffffffff0200e1f50500000000bab5076173747265616d4c94000a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa6d7576a9143c2e372b4add56043ac276a706e1bb2750339e0188ac38fb9423000000001976a914799309e5d6680b2cc6cad9de3ff681c77ac5145b88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"n42UY87hnpSR9fbacE6WCJDc8cyfHVa4a1\",\n \"amount\": \"6.983769\",\n \"confirmations\": 4,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1557412290,\n \"txid\": \"f88531e59946176bc269a2a38518fa86fcb4b909ecf7d52dba2e34273cd813be\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"timestamp\": null,\n \"txid\": \"ad78dfa585175ec1a1f97f051f809eecd47d18f7bc8bd6986146f5077cae3f8e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mrbnCh2Z3Tqo3JqW8YZefRLk8zv7P7fVvA\",\n \"amount\": \"5.969662\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"ad78dfa585175ec1a1f97f051f809eecd47d18f7bc8bd6986146f5077cae3f8e\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.014107\",\n \"total_input\": \"6.983769\",\n \"total_output\": \"6.969662\",\n \"txid\": \"ad78dfa585175ec1a1f97f051f809eecd47d18f7bc8bd6986146f5077cae3f8e\"\n }\n}"
},
{
"title": "Create an image stream claim with all metadata and fee",
"curl": "curl -d'{\"method\": \"stream_create\", \"params\": {\"name\": \"blank-image\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpx0pcyp9a.png\", \"tags\": [\"blank\", \"art\"], \"languages\": [\"en\"], \"locations\": [\"US:NH:Manchester\"], \"fee_currency\": \"LBC\", \"fee_amount\": \"0.3\", \"title\": \"Blank Image\", \"description\": \"A blank PNG that is 5x7.\", \"author\": \"Picaso\", \"license\": \"Public Domain\", \"license_url\": \"http://public-domain.org\", \"thumbnail_url\": \"http://smallmedia.com/thumbnail.jpg\", \"release_time\": 1555941592, \"channel_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"channel_account_id\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream create blank-image 1.0 /tmp/tmpx0pcyp9a.png --tags=blank --tags=art --languages=en --locations=US:NH:Manchester --fee_currency=LBC --fee_amount=0.3 --title=\"Blank Image\" --description=\"A blank PNG that is 5x7.\" --author=Picaso --license=\"Public Domain\" --license_url=http://public-domain.org --thumbnail_url=\"http://smallmedia.com/thumbnail.jpg\" --release_time=1555941592 --channel_id=\"cc242d221f78975c8011132882ee445b7d9b85cf\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"blank-image\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpx0pcyp9a.png\", \"tags\": [\"blank\", \"art\"], \"languages\": [\"en\"], \"locations\": [\"US:NH:Manchester\"], \"fee_currency\": \"LBC\", \"fee_amount\": \"0.3\", \"title\": \"Blank Image\", \"description\": \"A blank PNG that is 5x7.\", \"author\": \"Picaso\", \"license\": \"Public Domain\", \"license_url\": \"http://public-domain.org\", \"thumbnail_url\": \"http://smallmedia.com/thumbnail.jpg\", \"release_time\": 1555941592, \"channel_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"channel_account_id\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000012457aced7b002a64d3ec487aece27963a3dc23db6604d6c751d3c6ade483547c010000006b483045022100860084c5e55a394c847e4e3fa1270a9b506013b48db7eb3428ebfa9621968f4f0220643de2010dd115f00773e8d11b67968f83cbf9cf36cf15105c7f70ab92bcb08e01210374980952dc354c690da1ab318a3968bbee1589d2bb94d74d178e3cee757515bdffffffff0200e1f50500000000fdcb01b50b626c616e6b2d696d6167654da00101cf859b7d5b44ee82281311805c97781f222d24cc291bbb2c67e9438461d61d7fbb1e8ccd889c432eda03f0ba66909a59ce9c1ac0c375a06a6f9c8a877a973e9cdad15070bca4367f6de301d56932055e782430d90ad5010a720a2006003bbee8aece0543ed9d9cecc48be1d996cfeff9837a1aed1d961caeda82af120f746d7078307063797039612e706e6718632209696d6167652f706e673230e09cdf12ee46f82ea9b22d67c315cce59be725cdadd409c4637d345ec5dbde159012719541390abe74a5c1df5c9085e6120650696361736f1a0d5075626c696320446f6d61696e2218687474703a2f2f7075626c69632d646f6d61696e2e6f726728d891f7e5053222080112196f9f4c376b984270e4ec75c870f0b5faac1b3dd6985c747a30188087a70e520408051007420b426c616e6b20496d6167654a184120626c616e6b20504e472074686174206973203578372e52252a23687474703a2f2f736d616c6c6d656469612e636f6d2f7468756d626e61696c2e6a70675a05626c616e6b5a03617274620208016a1308ec0112024e481a0a4d616e636865737465726d7576a9149f4c376b984270e4ec75c870f0b5faac1b3dd69888acac5e7d1d000000001976a9149d7e5639ce7ebcca168cc5a23d42e0b4525a323e88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mutWSX3pmSpGejnTgrMP8s1xCbPkuuzuH5\",\n \"amount\": \"5.969662\",\n \"confirmations\": 2,\n \"height\": 213,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"7c5483e4adc6d351c7d60466db23dca36379e2ec7a48ecd3642a007bedac5724\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mv3F3Amp2JPSMUz1BHRLfYFrdgoxUTHh4b\",\n \"amount\": \"1.0\",\n \"claim_id\": \"63395891e9172ef41f70197c08a528fd24bed596\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"name\": \"blank-image\",\n \"nout\": 0,\n \"permanent_url\": \"blank-image#63395891e9172ef41f70197c08a528fd24bed596\",\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"txid\": \"595056aa6d429d732a245ba6033b6ce54fa862a29c3a96da08a22acc4f3495a1\",\n \"type\": \"claim\",\n \"value\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"mv3F3Amp2JPSMUz1BHRLfYFrdgoxUTHh4b\",\n \"amount\": 0.3,\n \"currency\": \"LBC\"\n },\n \"image\": {\n \"height\": 7,\n \"width\": 5\n },\n \"languages\": [\n \"en\"\n ],\n \"license\": \"Public Domain\",\n \"license_url\": \"http://public-domain.org\",\n \"locations\": [\n {\n \"city\": \"Manchester\",\n \"country\": \"US\",\n \"state\": \"NH\"\n }\n ],\n \"release_time\": \"1555941592\",\n \"source\": {\n \"hash\": \"06003bbee8aece0543ed9d9cecc48be1d996cfeff9837a1aed1d961caeda82af\",\n \"media_type\": \"image/png\",\n \"name\": \"tmpx0pcyp9a.png\",\n \"sd_hash\": \"e09cdf12ee46f82ea9b22d67c315cce59be725cdadd409c4637d345ec5dbde159012719541390abe74a5c1df5c9085e6\",\n \"size\": \"99\"\n },\n \"stream_type\": \"image\",\n \"tags\": [\n \"blank\",\n \"art\"\n ],\n \"thumbnail\": {\n \"url\": \"http://smallmedia.com/thumbnail.jpg\"\n },\n \"title\": \"Blank Image\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mushjCzKC83rDwJxoYeC6JRp8R6AEA9Ecw\",\n \"amount\": \"4.947555\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"595056aa6d429d732a245ba6033b6ce54fa862a29c3a96da08a22acc4f3495a1\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.022107\",\n \"total_input\": \"5.969662\",\n \"total_output\": \"5.947555\",\n \"txid\": \"595056aa6d429d732a245ba6033b6ce54fa862a29c3a96da08a22acc4f3495a1\"\n }\n}"
"curl": "curl -d'{\"method\": \"stream_create\", \"params\": {\"name\": \"blank-image\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmp61vr1_8a.png\", \"fee_currency\": \"LBC\", \"fee_amount\": \"0.3\", \"title\": \"Blank Image\", \"description\": \"A blank PNG that is 5x7.\", \"author\": \"Picaso\", \"tags\": [\"blank\", \"art\"], \"languages\": [\"en\"], \"locations\": [\"US:NH:Manchester\"], \"license\": \"Public Domain\", \"license_url\": \"http://public-domain.org\", \"thumbnail_url\": \"http://smallmedia.com/thumbnail.jpg\", \"release_time\": 1557412265, \"channel_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"channel_account_id\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream create blank-image 1.0 /tmp/tmp61vr1_8a.png --tags=blank --tags=art --languages=en --locations=US:NH:Manchester --fee_currency=LBC --fee_amount=0.3 --title=\"Blank Image\" --description=\"A blank PNG that is 5x7.\" --author=Picaso --license=\"Public Domain\" --license_url=http://public-domain.org --thumbnail_url=\"http://smallmedia.com/thumbnail.jpg\" --release_time=1557412265 --channel_id=\"3f6710c07d83e45e0434983d62b6b29530794121\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"blank-image\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmp61vr1_8a.png\", \"fee_currency\": \"LBC\", \"fee_amount\": \"0.3\", \"title\": \"Blank Image\", \"description\": \"A blank PNG that is 5x7.\", \"author\": \"Picaso\", \"tags\": [\"blank\", \"art\"], \"languages\": [\"en\"], \"locations\": [\"US:NH:Manchester\"], \"license\": \"Public Domain\", \"license_url\": \"http://public-domain.org\", \"thumbnail_url\": \"http://smallmedia.com/thumbnail.jpg\", \"release_time\": 1557412265, \"channel_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"channel_account_id\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000018e3fae7c07f5466198d68bbcf7187dd4ec9e801f057ff9a1c15e1785a5df78ad010000006b483045022100a4c76abe1d8d8108612e41c4aa16adb14cca338c5a9d9aaa05ae54a8ed5c72bb0220308cf38219d9f7e893a418a3b857c8c541e2178e74be666938cee245fe27e5640121024992dc4c1592aed07c4bf9f0a29df780e1c804d1a7e8b4d4532940bfd3a60721ffffffff0200e1f50500000000fddc01b50b626c616e6b2d696d6167654db101012141793095b2b6623d9834045ee4837dc010673fe1cd9b2bb7577c6eec2b6b13aa37b7723c785934ba1598e25e4274d2d03dde331b6915f66ef5da0d8a288c4e5de567284a6ef557617f49467f83f77a33e4791a0ae6010a82010a306c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545120f746d7036317672315f38612e706e6718632209696d6167652f706e673230135a9740f563155af8fb9b2f31c7a942e6c955aca13b86caf6e879af966e850a5efb5401ff7b6b69f9e531d31bf4f081120650696361736f1a0d5075626c696320446f6d61696e2218687474703a2f2f7075626c69632d646f6d61696e2e6f726728a9f3d0e6053222080112196ff2e835c499324eba9344a2525e0ff67b8696acd823cc406b188087a70e520408051007420b426c616e6b20496d6167654a184120626c616e6b20504e472074686174206973203578372e52252a23687474703a2f2f736d616c6c6d656469612e636f6d2f7468756d626e61696c2e6a70675a05626c616e6b5a03617274620208016a1308ec0112024e481a0a4d616e636865737465726d7576a914f2e835c499324eba9344a2525e0ff67b8696acd888acac5e7d1d000000001976a91487ff28c16efc769df297e43ab5d6f7a51833e2ab88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mrbnCh2Z3Tqo3JqW8YZefRLk8zv7P7fVvA\",\n \"amount\": \"5.969662\",\n \"confirmations\": 2,\n \"height\": 213,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1557412291,\n \"txid\": \"ad78dfa585175ec1a1f97f051f809eecd47d18f7bc8bd6986146f5077cae3f8e\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"n3fKziJ6gTJXNMFD5uTT2SzsCm35BUqBMC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"cce9db7375721826197b998d2425809892bbdc93\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"name\": \"blank-image\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://blank-image#cce9db7375721826197b998d2425809892bbdc93\",\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"timestamp\": null,\n \"txid\": \"c8926a8c21f12e96ec7b625fe337a56a60be6ae95df71794e66ae5dd32c9f8d7\",\n \"type\": \"claim\",\n \"value\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"n3fKziJ6gTJXNMFD5uTT2SzsCm35BUqBMC\",\n \"amount\": 0.3,\n \"currency\": \"LBC\"\n },\n \"image\": {\n \"height\": 7,\n \"width\": 5\n },\n \"languages\": [\n \"en\"\n ],\n \"license\": \"Public Domain\",\n \"license_url\": \"http://public-domain.org\",\n \"locations\": [\n {\n \"city\": \"Manchester\",\n \"country\": \"US\",\n \"state\": \"NH\"\n }\n ],\n \"release_time\": \"1557412265\",\n \"source\": {\n \"hash\": \"6c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545\",\n \"media_type\": \"image/png\",\n \"name\": \"tmp61vr1_8a.png\",\n \"sd_hash\": \"135a9740f563155af8fb9b2f31c7a942e6c955aca13b86caf6e879af966e850a5efb5401ff7b6b69f9e531d31bf4f081\",\n \"size\": \"99\"\n },\n \"stream_type\": \"image\",\n \"tags\": [\n \"blank\",\n \"art\"\n ],\n \"thumbnail\": {\n \"url\": \"http://smallmedia.com/thumbnail.jpg\"\n },\n \"title\": \"Blank Image\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"msv3BiuJ4RHWEbdYE665DaxxGQbmTjtPW2\",\n \"amount\": \"4.947555\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"c8926a8c21f12e96ec7b625fe337a56a60be6ae95df71794e66ae5dd32c9f8d7\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.022107\",\n \"total_input\": \"5.969662\",\n \"total_output\": \"5.947555\",\n \"txid\": \"c8926a8c21f12e96ec7b625fe337a56a60be6ae95df71794Line truncated
}
]
},
@@ -2126,14 +2200,14 @@
"curl": "curl -d'{\"method\": \"stream_list\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet stream list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_list\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n }\n ]\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n }\n ]\n}"
},
{
"title": "Paginate your stream claims",
"curl": "curl -d'{\"method\": \"stream_list\", \"params\": {\"page\": 1, \"page_size\": 20}}' http://localhost:5279/",
"lbrynet": "lbrynet stream list --page=1 --page_size=20",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_list\", \"params\": {\"page\": 1, \"page_size\": 20}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_pages\": 1\n }\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_change\": false,\n \"is_channel_signature_valid\": true,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"timestamp\": 1557412291,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_pages\": 1\n }\n}"
}
]
},
@@ -2159,6 +2233,24 @@
"description": "path to file to be associated with name.",
"is_required": false
},
{
"name": "file_name",
"type": "str",
"description": "override file name, defaults to name from file_path.",
"is_required": false
},
{
"name": "file_size",
"type": "str",
"description": "override file size, otherwise automatically computed.",
"is_required": false
},
{
"name": "file_hash",
"type": "str",
"description": "override file hash, otherwise automatically computed.",
"is_required": false
},
{
"name": "fee_currency",
"type": "string",
@@ -2177,6 +2269,12 @@
"description": "address where to send fee payments, will use value from --claim_address if not provided",
"is_required": false
},
{
"name": "clear_fee",
"type": "bool",
"description": "clear previously set fee",
"is_required": false
},
{
"name": "title",
"type": "str",
@@ -2195,12 +2293,6 @@
"description": "author of the publication. The usage for this field is not the same as for channels. The author field is used to credit an author who is not the publisher and is not represented by the channel. For example, a pdf file of 'The Odyssey' has an author of 'Homer' but may by published to a channel such as '@classics', or to no channel at all",
"is_required": false
},
{
"name": "clear_tags",
"type": "bool",
"description": "clear existing tags (prior to adding new ones)",
"is_required": false
},
{
"name": "tags",
"type": "list",
@@ -2208,9 +2300,9 @@
"is_required": false
},
{
"name": "clear_languages",
"name": "clear_tags",
"type": "bool",
"description": "clear existing languages (prior to adding new ones)",
"description": "clear existing tags (prior to adding new ones)",
"is_required": false
},
{
@@ -2220,9 +2312,9 @@
"is_required": false
},
{
"name": "clear_locations",
"name": "clear_languages",
"type": "bool",
"description": "clear existing locations (prior to adding new ones)",
"description": "clear existing languages (prior to adding new ones)",
"is_required": false
},
{
@@ -2231,6 +2323,12 @@
"description": "locations relevant to the stream, consisting of 2 letter `country` code and a `state`, `city` and a postal `code` along with a `latitude` and `longitude`. for JSON RPC: pass a dictionary with aforementioned attributes as keys, eg: ... \"locations\": [{'country': 'US', 'state': 'NH'}] ... for command line: pass a colon delimited list with values in the following order: \"COUNTRY:STATE:CITY:CODE:LATITUDE:LONGITUDE\" making sure to include colon for blank values, for example to provide only the city: ... --locations=\"::Manchester\" with all values set: ... --locations=\"US:NH:Manchester:03101:42.990605:-71.460989\" optionally, you can just pass the \"LATITUDE:LONGITUDE\": ... --locations=\"42.990605:-71.460989\" finally, you can also pass JSON string of dictionary on the command line as you would via JSON RPC ... --locations=\"{'country': 'US', 'state': 'NH'}\"",
"is_required": false
},
{
"name": "clear_locations",
"type": "bool",
"description": "clear existing locations (prior to adding new ones)",
"is_required": false
},
{
"name": "license",
"type": "str",
@@ -2279,6 +2377,12 @@
"description": "claim id of the publisher channel",
"is_required": false
},
{
"name": "channel_name",
"type": "str",
"description": "name of the publisher channel",
"is_required": false
},
{
"name": "clear_channel",
"type": "bool",
@@ -2308,16 +2412,22 @@
"type": "bool",
"description": "do not broadcast the transaction",
"is_required": false
},
{
"name": "replace",
"type": "bool",
"description": "instead of modifying specific values on the stream, this will clear all existing values and only save passed in values, useful for form submissions where all values are always set",
"is_required": false
}
],
"returns": " {\n \"txid\": \"hash of transaction in hex\",\n \"height\": \"block where transaction was recorded\",\n \"inputs\": [\n {\n \"txid\": \"hash of transaction in hex\",\n \"nout\": \"position in the transaction\",\n \"height\": \"block where transaction was recorded\",\n \"amount\": \"value of the txo as a decimal\",\n \"address\": \"address of who can spend the txo\",\n \"confirmations\": \"number of confirmed blocks\",\n \"is_change\": \"payment to change address, only available when it can be determined\",\n \"is_mine\": \"payment to one of your accounts, only available when it can be determined\",\n \"type\": \"one of 'claim', 'support' or 'payment'\",\n \"name\": \"when type is 'claim' or 'support', this is the claim name\",\n \"claim_id\": \"when type is 'claim' or 'support', this is the claim id\",\n \"claim_op\": \"when type is 'claim', this determines if it is 'create' or 'update'\",\n \"value\": \"when type is 'claim' or 'support' with payload, this is the decoded protobuf payload\",\n \"value_type\": \"determines the type of the 'value' field: 'channel', 'stream', etc\",\n \"protobuf\": \"hex encoded raw protobuf version of 'value' field\",\n \"permanent_url\": \"when type is 'claim' or 'support', this is the long permanent claim URL\",\n \"signing_channel\": \"for signed claims only, metadata of signing channel\",\n \"is_channel_signature_valid\": \"for signed claims only, whether signature is valid\"\n }\n ],\n \"outputs\": [\n {\n \"txid\": \"hash of transaction in hex\",\n \"nout\": \"position in the transaction\",\n \"height\": \"block where transaction was recorded\",\n \"amount\": \"value of the txo as a decimal\",\n \"address\": \"address of who can spend the txo\",\n \"confirmations\": \"number of confirmed blocks\",\n \"is_change\": \"payment to change address, only available when it can be determined\",\n \"is_mine\": \"payment to one of your accounts, only available when it can be determined\",\n \"type\": \"one of 'claim', 'support' or 'payment'\",\n \"name\": \"when type is 'claim' or 'support', this is the claim name\",\n \"claim_id\": \"when type is 'claim' or 'support', this is the claim id\",\n \"claim_op\": \"when type is 'claim', this determines if it is 'create' or 'update'\",\n \"value\": \"when type is 'claim' or 'support' with payload, this is the decoded protobuf payload\",\n \"value_type\": \"determines the type of the 'value' field: 'channel', 'stream', etc\",\n \"protobuf\": \"hex encoded raw protobuf version of 'value' field\",\n \"permanent_url\": \"when type is 'claim' or 'support', this is the long permanent claim URL\",\n \"signing_channel\": \"for signed claims only, metadata of signing channel\",\n \"is_channel_signature_valid\": \"for signed claims only, whether signature is valid\"\n }\n ],\n \"total_input\": \"sum of inputs as a decimal\",\n \"total_output\": \"sum of outputs, sans fee, as a decimal\",\n \"total_fee\": \"fee amount\",\n \"hex\": \"entire transaction encoded in hex\"\n }",
"examples": [
{
"title": "Update a stream claim to add channel",
"curl": "curl -d'{\"method\": \"stream_update\", \"params\": {\"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\", \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"clear_channel\": false, \"channel_account_id\": [], \"preview\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream update e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806 --channel_id=\"cc242d221f78975c8011132882ee445b7d9b85cf\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_update\", \"params\": {\"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\", \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\", \"clear_channel\": false, \"channel_account_id\": [], \"preview\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000022457aced7b002a64d3ec487aece27963a3dc23db6604d6c751d3c6ade483547c000000006a47304402203447e5a488e894ee593afbcd77d55ef5df396aae03f85deebbc98bc44024717d022017dedf59c6e1c7912383e27e9fb71153fd0bd4966bedd4eb90d1daf078363006012103480815803999a8661f93bc2ab3c7c31eb09ac4091db1851fd716c848e9123eb1ffffffff310268e1c0b2305134a0b78fbc5147f696183012cc25fc9121458bdb068e9802010000006b483045022100d6699a1ccf10bfef8e10068e5143daa4079a2f946648b62448a08b4e67bde35c02201525dc2739959425b09b39ac02f0371db17e0672b8facac652a0c2248466dd38012102b5ce454bb07852af21afda5712266262f68d348d4b86e12f6216c2ca72656a1cffffffff0200e1f50500000000fd1101b7076173747265616d1406f86ca8a34023b87bf9da5fb1cb7b30a3e8f3e34cd601cf859b7d5b44ee82281311805c97781f222d24cce145c0ad7c3c76cd83b5f8044d097413f4198e39a8b4d8012e4055de83212fb94c12834f444142c49a9f46a786b31236b79c7612bdfccae897ef372792b9894e0a7f0a7d0a20b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9120b746d706974393778383762180b22186170706c69636174696f6e2f6f637465742d73747265616d3230a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc76d6d76a914b122754d9d7432f98eec4e87c21b4982c8b9280e88acb6a3d205000000001976a914562905c720fc14ccdc15f7a450968d0a65709bb488ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 213,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"txid\": \"7c5483e4adc6d351c7d60466db23dca36379e2ec7a48ecd3642a007bedac5724\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mipDsnN5CyVPiXcD4WNB3swqCCmzM8w44w\",\n \"amount\": \"0.9772285\",\n \"confirmations\": 3,\n \"height\": 211,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"txid\": \"02988e06db8b452191fc25cc12301896f64751bc8fb7a0345130b2c0e1680231\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mwfZBCwuyWaCV9X91UAK2GTkYcRekL3Vj9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"astream#e3f3e8a3307bcbb15fdaf97bb82340a3a86cf806\",\n \"signing_channel\": {\n \"claim_id\": \"cc242d221f78975c8011132882ee445b7d9b85cf\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a03420004e6ab4d7651711fcd98a4b679ff1af1de0d3d0881211e53bba9a45f19e37521e6fa8a7c42483a064974d386098348bab6c6fe53eafe304ebde031dd9aface6119\",\n \"title\": \"New Channel\"\n }\n },\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpit97x87b\",\n \"sd_hash\": \"a2d66638a51b1621538a92fe3fc4f7a34926dc415652d107b89e28d0bd962074b5bb758adfb3de55053f5cd4dfd97cc7\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"moNXYrE94UaXdKrzS81cZKkmWLWSSSYe8n\",\n \"amount\": \"0.9769055\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000323\",\n \"total_input\": \"1.9772285\",\n \"total_output\": \"1.9769055\",\n \"txid\": \"eb2ff25e7588ea9bc5adeaf80ea66bff8770b5c983754e305b68e5b4199db898\"\n }\n}"
"curl": "curl -d'{\"method\": \"stream_update\", \"params\": {\"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\", \"clear_fee\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"clear_channel\": false, \"channel_account_id\": [], \"preview\": false, \"replace\": false}}' http://localhost:5279/",
"lbrynet": "lbrynet stream update ed10be11aef6501957c61077a1a8d0ae2ee69a9a --channel_id=\"3f6710c07d83e45e0434983d62b6b29530794121\"",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_update\", \"params\": {\"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\", \"clear_fee\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\", \"clear_channel\": false, \"channel_account_id\": [], \"preview\": false, \"replace\": false}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000028e3fae7c07f5466198d68bbcf7187dd4ec9e801f057ff9a1c15e1785a5df78ad000000006a47304402202023c676b2bd9e303bf9857f94c45beb55b68ed42409b3fd257d94f6f25d2ec00220452a9064f2908deec9e8060babf128dff66188a78e92ae6237f9fee0e2f431ac012103ee840c67b3bf07f9be296c33298dc25fa4cc10759079fe0b490030f5c0ed243bffffffff720ab9795f585e15ad8327f5c192bb32acbdc77f5143de1f5b27def9ee0add6a010000006a473044022073e4f0819fa1338bc63f19810741500734fcf4f8b527b907963adaae769a4f7d02204e34e00e71c83c9a46a67ca340512ec41ec90266c0383af5c1dbd9896b7b87ab012103d581ddc113506f32d8b215d97316f3df4559ff4b161fdfbecf29ebcc689a3827ffffffff0200e1f50500000000fd2301b7076173747265616d149a9ae62eaed0a8a17710c6571950f6ae11be10ed4ce8012141793095b2b6623d9834045ee4837dc010673f69741f82a15c92d092bc923e9d31c39d8367e5b29c9159efa878c5a4556fc742cde21b4046ca582e62c72b134fbb4fc78ec968cf172bf646f0da28f9ea5778a80a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d70666d637178717239180b22186170706c69636174696f6e2f6f637465742d73747265616d3230564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa6d6d76a9143c2e372b4add56043ac276a706e1bb2750339e0188ac32a0d205000000001976a91460dbfd055c18945c66046497c015fb7d9f95b98788ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 213,\n \"is_change\": false,\n \"is_mine\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"timestamp\": 1557412291,\n \"txid\": \"ad78dfa585175ec1a1f97f051f809eecd47d18f7bc8bd6986146f5077cae3f8e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mv6ygcdKPPGwnT1QvJWdE8SUjuaGUH2G4n\",\n \"amount\": \"0.9772285\",\n \"confirmations\": 3,\n \"height\": 211,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1557412290,\n \"txid\": \"6add0aeef9de275b1fde43517fc7bdac32bb92c1f52783ad155e585f79b90a72\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mm1ACg1WdL9cunAY9q9kuDSokVPMWEMTB3\",\n \"amount\": \"1.0\",\n \"claim_id\": \"ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#ed10be11aef6501957c61077a1a8d0ae2ee69a9a\",\n \"signing_channel\": {\n \"claim_id\": \"3f6710c07d83e45e0434983d62b6b29530794121\",\n \"name\": \"@channel\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000445e2d150380e5ac43f5bd01da23ab1f2900bee84671d223a8d30065d80d1ddba9d1d6424d171d34328d34135ba1eadc7d7dbfe603d6f15d0d484b45958361d46\",\n \"title\": \"New Channel\"\n }\n },\n \"timestamp\": null,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpfmcqxqr9\",\n \"sd_hash\": \"564fb55561e9f6c0b2ecd932fc784573124f33e81ddd72579c48e2a27360c5f64d243330c40842617bc9a7d29963e4aa\",\n \"size\": \"11\"\n }\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mpM6hXeP4zjRPrLeHh26dxdngnvS7AfceT\",\n \"amount\": \"0.9768965\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"a9b59b2adb9c113e2fca96aa9c9520af63d2b3f6fc2e989399baf6a9c5b1fe6b\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000332\",\n \"total_input\": \"1.9772285\",\n \"total_output\": \"1.9768965\",\n \"txid\": \"a9b59bLine truncated
}
]
}
@@ -2513,7 +2623,7 @@
"curl": "curl -d'{\"method\": \"transaction_list\", \"params\": {}}' http://localhost:5279/",
"lbrynet": "lbrynet transaction list",
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"transaction_list\", \"params\": {}}).json()",
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"abandon_info\": [],\n \"claim_info\": [],\n \"confirmations\": 1,\n \"date\": \"2019-04-22 10:00\",\n \"fee\": \"-0.000124\",\n \"support_info\": [],\n \"timestamp\": 1555941617,\n \"txid\": \"54077accaaa814dd35b2cc6bc59db0e6ff9bbcf0aed151b2e22465579b58341e\",\n \"update_info\": [],\n \"value\": \"-2.0\"\n },\n {\n \"abandon_info\": [],\n \"claim_info\": [],\n \"confirmations\": 7,\n \"date\": \"2019-04-22 10:00\",\n \"fee\": \"0.0\",\n \"support_info\": [],\n \"timestamp\": 1555941616,\n \"txid\": \"c63d1786b696ab47e1e914f64266a34a5b0027549f78c7d4774767c239a137ac\",\n \"update_info\": [],\n \"value\": \"10.0\"\n }\n ]\n}"
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"abandon_info\": [],\n \"claim_info\": [],\n \"confirmations\": 1,\n \"date\": \"2019-05-09 10:31\",\n \"fee\": \"-0.000124\",\n \"support_info\": [],\n \"timestamp\": 1557412290,\n \"txid\": \"96f08b9501099985f2bf805281076aa4a41760d2ddf1396ed8e38f789b0e49ea\",\n \"update_info\": [],\n \"value\": \"-2.0\"\n },\n {\n \"abandon_info\": [],\n \"claim_info\": [],\n \"confirmations\": 7,\n \"date\": \"2019-05-09 10:31\",\n \"fee\": \"0.0\",\n \"support_info\": [],\n \"timestamp\": 1557412289,\n \"txid\": \"953139e316bf7ce7d4d93b9418d64e801b7e35b41f4feb1c94be296b0c636fb0\",\n \"update_info\": [],\n \"value\": \"10.0\"\n }\n ]\n}"
}
]
},
+4 -3
View File
@@ -12,12 +12,13 @@ blockchain_name: lbrycrd_main
data_dir: /home/lbry/.lbrynet
download_directory: /home/lbry/downloads
delete_blobs_on_remove: True
save_blobs: true
save_files: false
dht_node_port: 4444
peer_port: 3333
use_upnp: True
use_upnp: true
#components_to_skip:
# - peer_protocol_server
# - hash_announcer
# - blob_server
# - dht
+1 -1
View File
@@ -1,4 +1,4 @@
__name__ = "lbrynet"
__version__ = "0.36.0"
__version__ = "0.37.0rc6"
version = tuple(__version__.split('.'))
+270 -132
View File
@@ -4,6 +4,8 @@ import asyncio
import binascii
import logging
import typing
import contextlib
from io import BytesIO
from cryptography.hazmat.primitives.ciphers import Cipher, modes
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.padding import PKCS7
@@ -21,10 +23,6 @@ log = logging.getLogger(__name__)
_hexmatch = re.compile("^[a-f,0-9]+$")
def is_valid_hashcharacter(char: str) -> bool:
return len(char) == 1 and _hexmatch.match(char)
def is_valid_blobhash(blobhash: str) -> bool:
"""Checks whether the blobhash is the correct length and contains only
valid characters (0-9, a-f)
@@ -46,143 +44,74 @@ def encrypt_blob_bytes(key: bytes, iv: bytes, unencrypted: bytes) -> typing.Tupl
return encrypted, digest.hexdigest()
class BlobFile:
"""
A chunk of data available on the network which is specified by a hashsum
def decrypt_blob_bytes(data: bytes, length: int, key: bytes, iv: bytes) -> bytes:
if len(data) != length:
raise ValueError("unexpected length")
cipher = Cipher(AES(key), modes.CBC(iv), backend=backend)
unpadder = PKCS7(AES.block_size).unpadder()
decryptor = cipher.decryptor()
return unpadder.update(decryptor.update(data) + decryptor.finalize()) + unpadder.finalize()
This class is used to create blobs on the local filesystem
when we already know the blob hash before hand (i.e., when downloading blobs)
Also can be used for reading from blobs on the local filesystem
"""
def __init__(self, loop: asyncio.BaseEventLoop, blob_dir: str, blob_hash: str,
length: typing.Optional[int] = None,
blob_completed_callback: typing.Optional[typing.Callable[['BlobFile'], typing.Awaitable]] = None):
if not is_valid_blobhash(blob_hash):
raise InvalidBlobHashError(blob_hash)
class AbstractBlob:
"""
A chunk of data (up to 2MB) available on the network which is specified by a sha384 hash
This class is non-io specific
"""
__slots__ = [
'loop',
'blob_hash',
'length',
'blob_completed_callback',
'blob_directory',
'writers',
'verified',
'writing',
'readers'
]
def __init__(self, loop: asyncio.BaseEventLoop, blob_hash: str, length: typing.Optional[int] = None,
blob_completed_callback: typing.Optional[typing.Callable[['AbstractBlob'], asyncio.Task]] = None,
blob_directory: typing.Optional[str] = None):
self.loop = loop
self.blob_hash = blob_hash
self.length = length
self.blob_dir = blob_dir
self.file_path = os.path.join(blob_dir, self.blob_hash)
self.writers: typing.List[HashBlobWriter] = []
self.verified: asyncio.Event = asyncio.Event(loop=self.loop)
self.finished_writing = asyncio.Event(loop=loop)
self.blob_write_lock = asyncio.Lock(loop=loop)
if self.file_exists:
length = int(os.stat(os.path.join(blob_dir, blob_hash)).st_size)
self.length = length
self.verified.set()
self.finished_writing.set()
self.saved_verified_blob = False
self.blob_completed_callback = blob_completed_callback
self.blob_directory = blob_directory
self.writers: typing.Dict[typing.Tuple[typing.Optional[str], typing.Optional[int]], HashBlobWriter] = {}
self.verified: asyncio.Event = asyncio.Event(loop=self.loop)
self.writing: asyncio.Event = asyncio.Event(loop=self.loop)
self.readers: typing.List[typing.BinaryIO] = []
@property
def file_exists(self):
return os.path.isfile(self.file_path)
if not is_valid_blobhash(blob_hash):
raise InvalidBlobHashError(blob_hash)
def writer_finished(self, writer: HashBlobWriter):
def callback(finished: asyncio.Future):
def __del__(self):
if self.writers or self.readers:
log.warning("%s not closed before being garbage collected", self.blob_hash)
self.close()
@contextlib.contextmanager
def _reader_context(self) -> typing.ContextManager[typing.BinaryIO]:
raise NotImplementedError()
@contextlib.contextmanager
def reader_context(self) -> typing.ContextManager[typing.BinaryIO]:
if not self.is_readable():
raise OSError(f"{str(type(self))} not readable, {len(self.readers)} readers {len(self.writers)} writers")
with self._reader_context() as reader:
try:
error = finished.exception()
except Exception as err:
error = err
if writer in self.writers: # remove this download attempt
self.writers.remove(writer)
if not error: # the blob downloaded, cancel all the other download attempts and set the result
while self.writers:
other = self.writers.pop()
other.finished.cancel()
t = self.loop.create_task(self.save_verified_blob(writer, finished.result()))
t.add_done_callback(lambda *_: self.finished_writing.set())
return
if isinstance(error, (InvalidBlobHashError, InvalidDataError)):
log.debug("writer error downloading %s: %s", self.blob_hash[:8], str(error))
elif not isinstance(error, (DownloadCancelledError, asyncio.CancelledError, asyncio.TimeoutError)):
log.exception("something else")
raise error
return callback
self.readers.append(reader)
yield reader
finally:
if reader in self.readers:
self.readers.remove(reader)
async def save_verified_blob(self, writer, verified_bytes: bytes):
def _save_verified():
# log.debug(f"write blob file {self.blob_hash[:8]} from {writer.peer.address}")
if not self.saved_verified_blob and not os.path.isfile(self.file_path):
if self.get_length() == len(verified_bytes):
with open(self.file_path, 'wb') as write_handle:
write_handle.write(verified_bytes)
self.saved_verified_blob = True
else:
raise Exception("length mismatch")
def _write_blob(self, blob_bytes: bytes):
raise NotImplementedError()
async with self.blob_write_lock:
if self.verified.is_set():
return
await self.loop.run_in_executor(None, _save_verified)
if self.blob_completed_callback:
await self.blob_completed_callback(self)
self.verified.set()
def open_for_writing(self) -> HashBlobWriter:
if self.file_exists:
raise OSError(f"File already exists '{self.file_path}'")
fut = asyncio.Future(loop=self.loop)
writer = HashBlobWriter(self.blob_hash, self.get_length, fut)
self.writers.append(writer)
fut.add_done_callback(self.writer_finished(writer))
return writer
async def sendfile(self, writer: asyncio.StreamWriter) -> int:
"""
Read and send the file to the writer and return the number of bytes sent
"""
with open(self.file_path, 'rb') as handle:
return await self.loop.sendfile(writer.transport, handle, count=self.get_length())
def close(self):
while self.writers:
self.writers.pop().finished.cancel()
def delete(self):
self.close()
self.saved_verified_blob = False
if os.path.isfile(self.file_path):
os.remove(self.file_path)
self.verified.clear()
self.finished_writing.clear()
self.length = None
def decrypt(self, key: bytes, iv: bytes) -> bytes:
"""
Decrypt a BlobFile to plaintext bytes
"""
with open(self.file_path, "rb") as f:
buff = f.read()
if len(buff) != self.length:
raise ValueError("unexpected length")
cipher = Cipher(AES(key), modes.CBC(iv), backend=backend)
unpadder = PKCS7(AES.block_size).unpadder()
decryptor = cipher.decryptor()
return unpadder.update(decryptor.update(buff) + decryptor.finalize()) + unpadder.finalize()
@classmethod
async def create_from_unencrypted(cls, loop: asyncio.BaseEventLoop, blob_dir: str, key: bytes,
iv: bytes, unencrypted: bytes, blob_num: int) -> BlobInfo:
"""
Create an encrypted BlobFile from plaintext bytes
"""
blob_bytes, blob_hash = encrypt_blob_bytes(key, iv, unencrypted)
length = len(blob_bytes)
blob = cls(loop, blob_dir, blob_hash, length)
writer = blob.open_for_writing()
writer.write(blob_bytes)
await blob.verified.wait()
return BlobInfo(blob_num, length, binascii.hexlify(iv).decode(), blob_hash)
def set_length(self, length):
def set_length(self, length) -> None:
if self.length is not None and length == self.length:
return
if self.length is None and 0 <= length <= MAX_BLOB_SIZE:
@@ -190,8 +119,217 @@ class BlobFile:
return
log.warning("Got an invalid length. Previous length: %s, Invalid length: %s", self.length, length)
def get_length(self):
def get_length(self) -> typing.Optional[int]:
return self.length
def get_is_verified(self):
def get_is_verified(self) -> bool:
return self.verified.is_set()
def is_readable(self) -> bool:
return self.verified.is_set()
def is_writeable(self) -> bool:
return not self.writing.is_set()
def write_blob(self, blob_bytes: bytes):
if not self.is_writeable():
raise OSError("cannot open blob for writing")
try:
self.writing.set()
self._write_blob(blob_bytes)
finally:
self.writing.clear()
def close(self):
while self.writers:
peer, writer = self.writers.popitem()
if writer and writer.finished and not writer.finished.done() and not self.loop.is_closed():
writer.finished.cancel()
while self.readers:
reader = self.readers.pop()
if reader:
reader.close()
def delete(self):
self.close()
self.verified.clear()
self.length = None
async def sendfile(self, writer: asyncio.StreamWriter) -> int:
"""
Read and send the file to the writer and return the number of bytes sent
"""
if not self.is_readable():
raise OSError('blob files cannot be read')
with self.reader_context() as handle:
return await self.loop.sendfile(writer.transport, handle, count=self.get_length())
def decrypt(self, key: bytes, iv: bytes) -> bytes:
"""
Decrypt a BlobFile to plaintext bytes
"""
with self.reader_context() as reader:
return decrypt_blob_bytes(reader.read(), self.length, key, iv)
@classmethod
async def create_from_unencrypted(
cls, loop: asyncio.BaseEventLoop, blob_dir: typing.Optional[str], key: bytes, iv: bytes,
unencrypted: bytes, blob_num: int,
blob_completed_callback: typing.Optional[typing.Callable[['AbstractBlob'], None]] = None) -> BlobInfo:
"""
Create an encrypted BlobFile from plaintext bytes
"""
blob_bytes, blob_hash = encrypt_blob_bytes(key, iv, unencrypted)
length = len(blob_bytes)
blob = cls(loop, blob_hash, length, blob_completed_callback, blob_dir)
writer = blob.get_blob_writer()
writer.write(blob_bytes)
await blob.verified.wait()
return BlobInfo(blob_num, length, binascii.hexlify(iv).decode(), blob_hash)
def save_verified_blob(self, verified_bytes: bytes):
if self.verified.is_set():
return
if self.is_writeable():
self._write_blob(verified_bytes)
self.verified.set()
if self.blob_completed_callback:
self.blob_completed_callback(self)
def get_blob_writer(self, peer_address: typing.Optional[str] = None,
peer_port: typing.Optional[int] = None) -> HashBlobWriter:
if (peer_address, peer_port) in self.writers and not self.writers[(peer_address, peer_port)].closed():
raise OSError(f"attempted to download blob twice from {peer_address}:{peer_port}")
fut = asyncio.Future(loop=self.loop)
writer = HashBlobWriter(self.blob_hash, self.get_length, fut)
self.writers[(peer_address, peer_port)] = writer
def remove_writer(_):
if (peer_address, peer_port) in self.writers:
del self.writers[(peer_address, peer_port)]
fut.add_done_callback(remove_writer)
def writer_finished_callback(finished: asyncio.Future):
try:
err = finished.exception()
if err:
raise err
verified_bytes = finished.result()
while self.writers:
_, other = self.writers.popitem()
if other is not writer:
other.close_handle()
self.save_verified_blob(verified_bytes)
except (InvalidBlobHashError, InvalidDataError) as error:
log.warning("writer error downloading %s: %s", self.blob_hash[:8], str(error))
except (DownloadCancelledError, asyncio.CancelledError, asyncio.TimeoutError):
pass
fut.add_done_callback(writer_finished_callback)
return writer
class BlobBuffer(AbstractBlob):
"""
An in-memory only blob
"""
def __init__(self, loop: asyncio.BaseEventLoop, blob_hash: str, length: typing.Optional[int] = None,
blob_completed_callback: typing.Optional[typing.Callable[['AbstractBlob'], asyncio.Task]] = None,
blob_directory: typing.Optional[str] = None):
self._verified_bytes: typing.Optional[BytesIO] = None
super().__init__(loop, blob_hash, length, blob_completed_callback, blob_directory)
@contextlib.contextmanager
def _reader_context(self) -> typing.ContextManager[typing.BinaryIO]:
if not self.is_readable():
raise OSError("cannot open blob for reading")
try:
yield self._verified_bytes
finally:
if self._verified_bytes:
self._verified_bytes.close()
self._verified_bytes = None
self.verified.clear()
def _write_blob(self, blob_bytes: bytes):
if self._verified_bytes:
raise OSError("already have bytes for blob")
self._verified_bytes = BytesIO(blob_bytes)
def delete(self):
if self._verified_bytes:
self._verified_bytes.close()
self._verified_bytes = None
return super().delete()
def __del__(self):
super().__del__()
if self._verified_bytes:
self.delete()
class BlobFile(AbstractBlob):
"""
A blob existing on the local file system
"""
def __init__(self, loop: asyncio.BaseEventLoop, blob_hash: str, length: typing.Optional[int] = None,
blob_completed_callback: typing.Optional[typing.Callable[['AbstractBlob'], asyncio.Task]] = None,
blob_directory: typing.Optional[str] = None):
super().__init__(loop, blob_hash, length, blob_completed_callback, blob_directory)
if not blob_directory or not os.path.isdir(blob_directory):
raise OSError(f"invalid blob directory '{blob_directory}'")
self.file_path = os.path.join(self.blob_directory, self.blob_hash)
if self.file_exists:
file_size = int(os.stat(self.file_path).st_size)
if length and length != file_size:
log.warning("expected %s to be %s bytes, file has %s", self.blob_hash, length, file_size)
self.delete()
else:
self.length = file_size
self.verified.set()
@property
def file_exists(self):
return os.path.isfile(self.file_path)
def is_writeable(self) -> bool:
return super().is_writeable() and not os.path.isfile(self.file_path)
def get_blob_writer(self, peer_address: typing.Optional[str] = None,
peer_port: typing.Optional[str] = None) -> HashBlobWriter:
if self.file_exists:
raise OSError(f"File already exists '{self.file_path}'")
return super().get_blob_writer(peer_address, peer_port)
@contextlib.contextmanager
def _reader_context(self) -> typing.ContextManager[typing.BinaryIO]:
handle = open(self.file_path, 'rb')
try:
yield handle
finally:
handle.close()
def _write_blob(self, blob_bytes: bytes):
with open(self.file_path, 'wb') as f:
f.write(blob_bytes)
def delete(self):
if os.path.isfile(self.file_path):
os.remove(self.file_path)
return super().delete()
@classmethod
async def create_from_unencrypted(
cls, loop: asyncio.BaseEventLoop, blob_dir: typing.Optional[str], key: bytes, iv: bytes,
unencrypted: bytes, blob_num: int,
blob_completed_callback: typing.Optional[typing.Callable[['AbstractBlob'],
asyncio.Task]] = None) -> BlobInfo:
if not blob_dir or not os.path.isdir(blob_dir):
raise OSError(f"cannot create blob in directory: '{blob_dir}'")
return await super().create_from_unencrypted(
loop, blob_dir, key, iv, unencrypted, blob_num, blob_completed_callback
)
+7
View File
@@ -2,6 +2,13 @@ import typing
class BlobInfo:
__slots__ = [
'blob_hash',
'blob_num',
'length',
'iv',
]
def __init__(self, blob_num: int, length: int, iv: str, blob_hash: typing.Optional[str] = None):
self.blob_hash = blob_hash
self.blob_num = blob_num
+60 -22
View File
@@ -2,18 +2,19 @@ import os
import typing
import asyncio
import logging
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_file import BlobFile, is_valid_blobhash
from lbrynet.blob.blob_file import is_valid_blobhash, BlobFile, BlobBuffer, AbstractBlob
from lbrynet.stream.descriptor import StreamDescriptor
if typing.TYPE_CHECKING:
from lbrynet.conf import Config
from lbrynet.dht.protocol.data_store import DictDataStore
from lbrynet.extras.daemon.storage import SQLiteStorage
log = logging.getLogger(__name__)
class BlobFileManager:
def __init__(self, loop: asyncio.BaseEventLoop, blob_dir: str, storage: SQLiteStorage,
class BlobManager:
def __init__(self, loop: asyncio.BaseEventLoop, blob_dir: str, storage: 'SQLiteStorage', config: 'Config',
node_data_store: typing.Optional['DictDataStore'] = None):
"""
This class stores blobs on the hard disk
@@ -27,16 +28,59 @@ class BlobFileManager:
self._node_data_store = node_data_store
self.completed_blob_hashes: typing.Set[str] = set() if not self._node_data_store\
else self._node_data_store.completed_blobs
self.blobs: typing.Dict[str, BlobFile] = {}
self.blobs: typing.Dict[str, AbstractBlob] = {}
self.config = config
def _get_blob(self, blob_hash: str, length: typing.Optional[int] = None):
if self.config.save_blobs:
return BlobFile(
self.loop, blob_hash, length, self.blob_completed, self.blob_dir
)
else:
if is_valid_blobhash(blob_hash) and os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
return BlobFile(
self.loop, blob_hash, length, self.blob_completed, self.blob_dir
)
return BlobBuffer(
self.loop, blob_hash, length, self.blob_completed, self.blob_dir
)
def get_blob(self, blob_hash, length: typing.Optional[int] = None):
if blob_hash in self.blobs:
if self.config.save_blobs and isinstance(self.blobs[blob_hash], BlobBuffer):
buffer = self.blobs.pop(blob_hash)
if blob_hash in self.completed_blob_hashes:
self.completed_blob_hashes.remove(blob_hash)
self.blobs[blob_hash] = self._get_blob(blob_hash, length)
if buffer.is_readable():
with buffer.reader_context() as reader:
self.blobs[blob_hash].write_blob(reader.read())
if length and self.blobs[blob_hash].length is None:
self.blobs[blob_hash].set_length(length)
else:
self.blobs[blob_hash] = self._get_blob(blob_hash, length)
return self.blobs[blob_hash]
def is_blob_verified(self, blob_hash: str, length: typing.Optional[int] = None) -> bool:
if not is_valid_blobhash(blob_hash):
raise ValueError(blob_hash)
if blob_hash in self.blobs:
return self.blobs[blob_hash].get_is_verified()
if not os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
return False
return self._get_blob(blob_hash, length).get_is_verified()
async def setup(self) -> bool:
def get_files_in_blob_dir() -> typing.Set[str]:
if not self.blob_dir:
return set()
return {
item.name for item in os.scandir(self.blob_dir) if is_valid_blobhash(item.name)
}
in_blobfiles_dir = await self.loop.run_in_executor(None, get_files_in_blob_dir)
self.completed_blob_hashes.update(await self.storage.sync_missing_blobs(in_blobfiles_dir))
to_add = await self.storage.sync_missing_blobs(in_blobfiles_dir)
if to_add:
self.completed_blob_hashes.update(to_add)
return True
def stop(self):
@@ -45,37 +89,31 @@ class BlobFileManager:
blob.close()
self.completed_blob_hashes.clear()
def get_blob(self, blob_hash, length: typing.Optional[int] = None):
if blob_hash in self.blobs:
if length and self.blobs[blob_hash].length is None:
self.blobs[blob_hash].set_length(length)
else:
self.blobs[blob_hash] = BlobFile(self.loop, self.blob_dir, blob_hash, length, self.blob_completed)
return self.blobs[blob_hash]
def get_stream_descriptor(self, sd_hash):
return StreamDescriptor.from_stream_descriptor_blob(self.loop, self.blob_dir, self.get_blob(sd_hash))
async def blob_completed(self, blob: BlobFile):
def blob_completed(self, blob: AbstractBlob) -> asyncio.Task:
if blob.blob_hash is None:
raise Exception("Blob hash is None")
if not blob.length:
raise Exception("Blob has a length of 0")
if blob.blob_hash not in self.completed_blob_hashes:
self.completed_blob_hashes.add(blob.blob_hash)
await self.storage.add_completed_blob(blob.blob_hash, blob.length)
if isinstance(blob, BlobFile):
if blob.blob_hash not in self.completed_blob_hashes:
self.completed_blob_hashes.add(blob.blob_hash)
return self.loop.create_task(self.storage.add_blobs((blob.blob_hash, blob.length), finished=True))
else:
return self.loop.create_task(self.storage.add_blobs((blob.blob_hash, blob.length), finished=False))
def check_completed_blobs(self, blob_hashes: typing.List[str]) -> typing.List[str]:
"""Returns of the blobhashes_to_check, which are valid"""
blobs = [self.get_blob(b) for b in blob_hashes]
return [blob.blob_hash for blob in blobs if blob.get_is_verified()]
return [blob_hash for blob_hash in blob_hashes if self.is_blob_verified(blob_hash)]
def delete_blob(self, blob_hash: str):
if not is_valid_blobhash(blob_hash):
raise Exception("invalid blob hash to delete")
if blob_hash not in self.blobs:
if os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
if self.blob_dir and os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
os.remove(os.path.join(self.blob_dir, blob_hash))
else:
self.blobs.pop(blob_hash).delete()
+3 -2
View File
@@ -44,16 +44,15 @@ class HashBlobWriter:
self._hashsum.update(data)
self.len_so_far += len(data)
if self.len_so_far > expected_length:
self.close_handle()
self.finished.set_exception(InvalidDataError(
f'Length so far is greater than the expected length. {self.len_so_far} to {expected_length}'
))
self.close_handle()
return
self.buffer.write(data)
if self.len_so_far == expected_length:
blob_hash = self.calculate_blob_hash()
if blob_hash != self.expected_blob_hash:
self.close_handle()
self.finished.set_exception(InvalidBlobHashError(
f"blob hash is {blob_hash} vs expected {self.expected_blob_hash}"
))
@@ -62,6 +61,8 @@ class HashBlobWriter:
self.close_handle()
def close_handle(self):
if not self.finished.done():
self.finished.cancel()
if self.buffer is not None:
self.buffer.close()
self.buffer = None
+36 -16
View File
@@ -4,8 +4,9 @@ import typing
import binascii
from lbrynet.error import InvalidBlobHashError, InvalidDataError
from lbrynet.blob_exchange.serialization import BlobResponse, BlobRequest
from lbrynet.utils import cache_concurrent
if typing.TYPE_CHECKING:
from lbrynet.blob.blob_file import BlobFile
from lbrynet.blob.blob_file import AbstractBlob
from lbrynet.blob.writer import HashBlobWriter
log = logging.getLogger(__name__)
@@ -17,15 +18,18 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
self.peer_port: typing.Optional[int] = None
self.peer_address: typing.Optional[str] = None
self.peer_timeout = peer_timeout
self.transport: asyncio.Transport = None
self.transport: typing.Optional[asyncio.Transport] = None
self.writer: 'HashBlobWriter' = None
self.blob: 'BlobFile' = None
self.writer: typing.Optional['HashBlobWriter'] = None
self.blob: typing.Optional['AbstractBlob'] = None
self._blob_bytes_received = 0
self._response_fut: asyncio.Future = None
self._response_fut: typing.Optional[asyncio.Future] = None
self.buf = b''
# this is here to handle the race when the downloader is closed right as response_fut gets a result
self.closed = asyncio.Event(loop=self.loop)
def data_received(self, data: bytes):
log.debug("%s:%d -- got %s bytes -- %s bytes on buffer -- %s blob bytes received",
self.peer_address, self.peer_port, len(data), len(self.buf), self._blob_bytes_received)
@@ -35,6 +39,9 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
if self._response_fut and not self._response_fut.done():
self._response_fut.cancel()
return
if not self._response_fut:
log.warning("Protocol received data before expected, probable race on keep alive. Closing transport.")
return self.close()
if self._blob_bytes_received and not self.writer.closed():
return self._write(data)
@@ -63,8 +70,7 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
# write blob bytes if we're writing a blob and have blob bytes to write
self._write(response.blob_data)
def _write(self, data):
def _write(self, data: bytes):
if len(data) > (self.blob.get_length() - self._blob_bytes_received):
data = data[:(self.blob.get_length() - self._blob_bytes_received)]
log.warning("got more than asked from %s:%d, probable sendfile bug", self.peer_address, self.peer_port)
@@ -87,6 +93,7 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
:return: download success (bool), keep connection (bool)
"""
request = BlobRequest.make_request_for_blob_hash(self.blob.blob_hash)
blob_hash = self.blob.blob_hash
try:
msg = request.serialize()
log.debug("send request to %s:%i -> %s", self.peer_address, self.peer_port, msg.decode())
@@ -95,6 +102,10 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
availability_response = response.get_availability_response()
price_response = response.get_price_response()
blob_response = response.get_blob_response()
if self.closed.is_set():
msg = f"cancelled blob request for {blob_hash} immediately after we got a response"
log.warning(msg)
raise asyncio.CancelledError(msg)
if (not blob_response or blob_response.error) and\
(not availability_response or not availability_response.available_blobs):
log.warning("%s not in availability response from %s:%i", self.blob.blob_hash, self.peer_address,
@@ -133,6 +144,7 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
return self._blob_bytes_received, self.close()
def close(self):
self.closed.set()
if self._response_fut and not self._response_fut.done():
self._response_fut.cancel()
if self.writer and not self.writer.closed():
@@ -145,18 +157,21 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
self.transport = None
self.buf = b''
async def download_blob(self, blob: 'BlobFile') -> typing.Tuple[int, typing.Optional[asyncio.Transport]]:
if blob.get_is_verified() or blob.file_exists or blob.blob_write_lock.locked():
async def download_blob(self, blob: 'AbstractBlob') -> typing.Tuple[int, typing.Optional[asyncio.Transport]]:
self.closed.clear()
blob_hash = blob.blob_hash
if blob.get_is_verified() or not blob.is_writeable():
return 0, self.transport
try:
self.blob, self.writer, self._blob_bytes_received = blob, blob.open_for_writing(), 0
self._blob_bytes_received = 0
self.blob, self.writer = blob, blob.get_blob_writer(self.peer_address, self.peer_port)
self._response_fut = asyncio.Future(loop=self.loop)
return await self._download_blob()
except OSError as e:
log.error("race happened downloading from %s:%i", self.peer_address, self.peer_port)
# i'm not sure how to fix this race condition - jack
log.exception(e)
return self._blob_bytes_received, self.transport
log.warning("race happened downloading %s from %s:%i", blob_hash, self.peer_address, self.peer_port)
# return self._blob_bytes_received, self.transport
raise
except asyncio.TimeoutError:
if self._response_fut and not self._response_fut.done():
self._response_fut.cancel()
@@ -165,6 +180,10 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
except asyncio.CancelledError:
self.close()
raise
finally:
if self.writer and not self.writer.closed():
self.writer.close_handle()
self.writer = None
def connection_made(self, transport: asyncio.Transport):
self.transport = transport
@@ -177,9 +196,10 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
self.close()
async def request_blob(loop: asyncio.BaseEventLoop, blob: 'BlobFile', address: str, tcp_port: int,
@cache_concurrent
async def request_blob(loop: asyncio.BaseEventLoop, blob: 'AbstractBlob', address: str, tcp_port: int,
peer_connect_timeout: float, blob_download_timeout: float,
connected_transport: asyncio.Transport = None)\
connected_transport: asyncio.Transport = None, connection_id: int = 0)\
-> typing.Tuple[int, typing.Optional[asyncio.Transport]]:
"""
Returns [<downloaded blob>, <keep connection>]
@@ -196,7 +216,7 @@ async def request_blob(loop: asyncio.BaseEventLoop, blob: 'BlobFile', address: s
if not connected_transport:
await asyncio.wait_for(loop.create_connection(lambda: protocol, address, tcp_port),
peer_connect_timeout, loop=loop)
if blob.get_is_verified() or blob.file_exists:
if blob.get_is_verified() or not blob.is_writeable():
# file exists but not verified means someone is writing right now, give it time, come back later
return 0, connected_transport
return await protocol.download_blob(blob)
+41 -56
View File
@@ -1,21 +1,23 @@
import asyncio
import typing
import logging
from lbrynet.utils import drain_tasks
from lbrynet.utils import cache_concurrent
from lbrynet.blob_exchange.client import request_blob
if typing.TYPE_CHECKING:
from lbrynet.conf import Config
from lbrynet.dht.node import Node
from lbrynet.dht.peer import KademliaPeer
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_file import BlobFile
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob.blob_file import AbstractBlob
log = logging.getLogger(__name__)
class BlobDownloader:
BAN_TIME = 10.0 # fixme: when connection manager gets implemented, move it out from here
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobFileManager',
BAN_FACTOR = 2.0 # fixme: when connection manager gets implemented, move it out from here
BAN_CAP = 30.0*60.0 # maximum time a node remains banned before being retried
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
peer_queue: asyncio.Queue):
self.loop = loop
self.config = config
@@ -24,21 +26,16 @@ class BlobDownloader:
self.active_connections: typing.Dict['KademliaPeer', asyncio.Task] = {} # active request_blob calls
self.ignored: typing.Dict['KademliaPeer', int] = {}
self.scores: typing.Dict['KademliaPeer', int] = {}
self.failures: typing.Dict['KademliaPeer', int] = {}
self.connections: typing.Dict['KademliaPeer', asyncio.Transport] = {}
self.time_since_last_blob = loop.time()
self.is_running = asyncio.Event(loop=self.loop)
def should_race_continue(self, blob: 'BlobFile'):
def should_race_continue(self, blob: 'AbstractBlob'):
if len(self.active_connections) >= self.config.max_connections_per_download:
return False
# if a peer won 3 or more blob races and is active as a downloader, stop the race so bandwidth improves
# the safe net side is that any failure will reset the peer score, triggering the race back
# TODO: this is a good idea for low bandwidth, but doesnt play nice on high bandwidth
# for peer, task in self.active_connections.items():
# if self.scores.get(peer, 0) >= 0 and self.rounds_won.get(peer, 0) >= 3 and not task.done():
# return False
return not (blob.get_is_verified() or blob.file_exists)
return not (blob.get_is_verified() or not blob.is_writeable())
async def request_blob_from_peer(self, blob: 'BlobFile', peer: 'KademliaPeer'):
async def request_blob_from_peer(self, blob: 'AbstractBlob', peer: 'KademliaPeer', connection_id: int = 0):
if blob.get_is_verified():
return
self.scores[peer] = self.scores.get(peer, 0) - 1 # starts losing score, to account for cancelled ones
@@ -46,92 +43,80 @@ class BlobDownloader:
start = self.loop.time()
bytes_received, transport = await request_blob(
self.loop, blob, peer.address, peer.tcp_port, self.config.peer_connect_timeout,
self.config.blob_download_timeout, connected_transport=transport
self.config.blob_download_timeout, connected_transport=transport, connection_id=connection_id
)
if bytes_received == blob.get_length():
self.time_since_last_blob = self.loop.time()
if not transport and peer not in self.ignored:
self.ignored[peer] = self.loop.time()
log.debug("drop peer %s:%i", peer.address, peer.tcp_port)
self.failures[peer] = self.failures.get(peer, 0) + 1
if peer in self.connections:
del self.connections[peer]
elif transport:
log.debug("keep peer %s:%i", peer.address, peer.tcp_port)
self.failures[peer] = 0
self.connections[peer] = transport
rough_speed = (bytes_received / (self.loop.time() - start)) if bytes_received else 0
self.scores[peer] = rough_speed
elapsed = self.loop.time() - start
self.scores[peer] = bytes_received / elapsed if bytes_received and elapsed else 0
async def new_peer_or_finished(self, blob: 'BlobFile'):
async def get_and_re_add_peers():
try:
new_peers = await asyncio.wait_for(self.peer_queue.get(), timeout=1.0)
self.peer_queue.put_nowait(new_peers)
except asyncio.TimeoutError:
pass
tasks = [self.loop.create_task(get_and_re_add_peers()), self.loop.create_task(blob.verified.wait())]
active_tasks = list(self.active_connections.values())
try:
await asyncio.wait(tasks + active_tasks, loop=self.loop, return_when='FIRST_COMPLETED')
finally:
drain_tasks(tasks)
async def new_peer_or_finished(self):
active_tasks = list(self.active_connections.values()) + [asyncio.sleep(1)]
await asyncio.wait(active_tasks, loop=self.loop, return_when='FIRST_COMPLETED')
def cleanup_active(self):
to_remove = [peer for (peer, task) in self.active_connections.items() if task.done()]
for peer in to_remove:
del self.active_connections[peer]
self.clearbanned()
def clearbanned(self):
now = self.loop.time()
if now - self.time_since_last_blob > 60.0:
return
forgiven = [banned_peer for banned_peer, when in self.ignored.items() if now - when > self.BAN_TIME]
self.peer_queue.put_nowait(forgiven)
for banned_peer in forgiven:
self.ignored.pop(banned_peer)
self.ignored = dict((
(peer, when) for (peer, when) in self.ignored.items()
if (now - when) < min(self.BAN_CAP, (self.failures.get(peer, 0) ** self.BAN_FACTOR))
))
async def download_blob(self, blob_hash: str, length: typing.Optional[int] = None) -> 'BlobFile':
@cache_concurrent
async def download_blob(self, blob_hash: str, length: typing.Optional[int] = None,
connection_id: int = 0) -> 'AbstractBlob':
blob = self.blob_manager.get_blob(blob_hash, length)
if blob.get_is_verified():
return blob
self.is_running.set()
try:
while not blob.get_is_verified():
batch: typing.List['KademliaPeer'] = []
while not blob.get_is_verified() and self.is_running.is_set():
batch: typing.Set['KademliaPeer'] = set()
while not self.peer_queue.empty():
batch.extend(self.peer_queue.get_nowait())
batch.sort(key=lambda peer: self.scores.get(peer, 0), reverse=True)
batch.update(self.peer_queue.get_nowait())
if batch:
self.peer_queue.put_nowait(list(batch))
log.debug(
"running, %d peers, %d ignored, %d active",
len(batch), len(self.ignored), len(self.active_connections)
)
for peer in batch:
for peer in sorted(batch, key=lambda peer: self.scores.get(peer, 0), reverse=True):
if not self.should_race_continue(blob):
break
if peer not in self.active_connections and peer not in self.ignored:
log.debug("request %s from %s:%i", blob_hash[:8], peer.address, peer.tcp_port)
t = self.loop.create_task(self.request_blob_from_peer(blob, peer))
t = self.loop.create_task(self.request_blob_from_peer(blob, peer, connection_id))
self.active_connections[peer] = t
await self.new_peer_or_finished(blob)
await self.new_peer_or_finished()
self.cleanup_active()
if batch:
self.peer_queue.put_nowait(set(batch).difference(self.ignored))
else:
self.clearbanned()
blob.close()
log.debug("downloaded %s", blob_hash[:8])
return blob
finally:
while self.active_connections:
self.active_connections.popitem()[1].cancel()
blob.close()
def close(self):
self.scores.clear()
self.ignored.clear()
self.is_running.clear()
for transport in self.connections.values():
transport.close()
async def download_blob(loop, config: 'Config', blob_manager: 'BlobFileManager', node: 'Node',
blob_hash: str) -> 'BlobFile':
async def download_blob(loop, config: 'Config', blob_manager: 'BlobManager', node: 'Node',
blob_hash: str) -> 'AbstractBlob':
search_queue = asyncio.Queue(loop=loop, maxsize=config.max_connections_per_download)
search_queue.put_nowait(blob_hash)
peer_queue, accumulate_task = node.accumulate_peers(search_queue)
+3 -3
View File
@@ -8,13 +8,13 @@ from lbrynet.blob_exchange.serialization import BlobAvailabilityResponse, BlobPr
BlobPaymentAddressResponse
if typing.TYPE_CHECKING:
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
log = logging.getLogger(__name__)
class BlobServerProtocol(asyncio.Protocol):
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobFileManager', lbrycrd_address: str):
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str):
self.loop = loop
self.blob_manager = blob_manager
self.server_task: asyncio.Task = None
@@ -94,7 +94,7 @@ class BlobServerProtocol(asyncio.Protocol):
class BlobServer:
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobFileManager', lbrycrd_address: str):
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str):
self.loop = loop
self.blob_manager = blob_manager
self.server_task: asyncio.Task = None
+5 -2
View File
@@ -480,10 +480,12 @@ class Config(CLIConfig):
# protocol timeouts
download_timeout = Float("Cumulative timeout for a stream to begin downloading before giving up", 30.0)
blob_download_timeout = Float("Timeout to download a blob from a peer", 30.0)
peer_connect_timeout = Float("Timeout to establish a TCP connection to a peer", 2.0)
peer_connect_timeout = Float("Timeout to establish a TCP connection to a peer", 3.0)
node_rpc_timeout = Float("Timeout when making a DHT request", constants.rpc_timeout)
# blob announcement and download
save_blobs = Toggle("Save encrypted blob files for hosting, otherwise download blobs to memory only.", True)
announce_head_and_sd_only = Toggle(
"Announce only the descriptor and first (rather than all) data blob for a stream to the DHT", True,
previous_names=['announce_head_blobs_only']
@@ -493,7 +495,7 @@ class Config(CLIConfig):
previous_names=['concurrent_announcers']
)
max_connections_per_download = Integer(
"Maximum number of peers to connect to while downloading a blob", 8,
"Maximum number of peers to connect to while downloading a blob", 4,
previous_names=['max_connections_per_stream']
)
fixed_peer_delay = Float(
@@ -537,6 +539,7 @@ class Config(CLIConfig):
cache_time = Integer("Time to cache resolved claims", 150) # TODO: use this
# daemon
save_files = Toggle("Save downloaded files when calling `get` by default", True)
components_to_skip = Strings("components which will be skipped during start-up of daemon", [])
share_usage_data = Toggle(
"Whether to share usage stats and diagnostic info with LBRY.", True,
+33 -44
View File
@@ -13,55 +13,44 @@ class BlobAnnouncer:
self.loop = loop
self.node = node
self.storage = storage
self.pending_call: asyncio.Handle = None
self.announce_task: asyncio.Task = None
self.running = False
self.announce_queue: typing.List[str] = []
async def _announce(self, batch_size: typing.Optional[int] = 10):
if not batch_size:
return
if not self.node.joined.is_set():
await self.node.joined.wait()
blob_hashes = await self.storage.get_blobs_to_announce()
if blob_hashes:
self.announce_queue.extend(blob_hashes)
log.info("%i blobs to announce", len(blob_hashes))
batch = []
while len(self.announce_queue):
cnt = 0
announced = []
while self.announce_queue and cnt < batch_size:
blob_hash = self.announce_queue.pop()
announced.append(blob_hash)
batch.append(self.node.announce_blob(blob_hash))
cnt += 1
to_await = []
while batch:
to_await.append(batch.pop())
if to_await:
await asyncio.gather(*tuple(to_await), loop=self.loop)
await self.storage.update_last_announced_blobs(announced)
log.info("announced %i blobs", len(announced))
if self.running:
self.pending_call = self.loop.call_later(60, self.announce, batch_size)
async def _submit_announcement(self, blob_hash):
try:
peers = len(await self.node.announce_blob(blob_hash))
if peers > 4:
return blob_hash
else:
log.warning("failed to announce %s, could only find %d peers, retrying soon.", blob_hash[:8], peers)
except Exception as err:
if isinstance(err, asyncio.CancelledError):
raise err
log.warning("error announcing %s: %s", blob_hash[:8], str(err))
def announce(self, batch_size: typing.Optional[int] = 10):
self.announce_task = self.loop.create_task(self._announce(batch_size))
async def _announce(self, batch_size: typing.Optional[int] = 10):
while batch_size:
if not self.node.joined.is_set():
await self.node.joined.wait()
self.announce_queue.extend(await self.storage.get_blobs_to_announce())
log.debug("announcer task wake up, %d blobs to announce", len(self.announce_queue))
while len(self.announce_queue):
log.info("%i blobs to announce", len(self.announce_queue))
announced = await asyncio.gather(*[
self._submit_announcement(
self.announce_queue.pop()) for _ in range(batch_size) if self.announce_queue
], loop=self.loop)
announced = list(filter(None, announced))
if announced:
await self.storage.update_last_announced_blobs(announced)
log.info("announced %i blobs", len(announced))
await asyncio.sleep(60)
def start(self, batch_size: typing.Optional[int] = 10):
if self.running:
raise Exception("already running")
self.running = True
self.announce(batch_size)
assert not self.announce_task or self.announce_task.done(), "already running"
self.announce_task = self.loop.create_task(self._announce(batch_size))
def stop(self):
self.running = False
if self.pending_call:
if not self.pending_call.cancelled():
self.pending_call.cancel()
self.pending_call = None
if self.announce_task:
if not (self.announce_task.done() or self.announce_task.cancelled()):
self.announce_task.cancel()
self.announce_task = None
if self.announce_task and not self.announce_task.done():
self.announce_task.cancel()
-1
View File
@@ -201,7 +201,6 @@ class Node:
try:
async with peer_generator as junction:
yield junction
await peer_generator.finished.wait()
finally:
if add_hashes_task and not (add_hashes_task.done() or add_hashes_task.cancelled()):
add_hashes_task.cancel()
+9
View File
@@ -135,6 +135,15 @@ class PeerManager:
class KademliaPeer:
__slots__ = [
'loop',
'_node_id',
'address',
'udp_port',
'tcp_port',
'protocol_version',
]
def __init__(self, loop: asyncio.BaseEventLoop, address: str, node_id: typing.Optional[bytes] = None,
udp_port: typing.Optional[int] = None, tcp_port: typing.Optional[int] = None):
if node_id is not None:
@@ -26,12 +26,11 @@ class AsyncGeneratorJunction:
def __init__(self, loop: asyncio.BaseEventLoop, queue: typing.Optional[asyncio.Queue] = None):
self.loop = loop
self.__iterator_queue = asyncio.Queue(loop=loop)
self.result_queue = queue or asyncio.Queue(loop=loop)
self.tasks: typing.List[asyncio.Task] = []
self.running_iterators: typing.Dict[typing.AsyncGenerator, bool] = {}
self.generator_queue: asyncio.Queue = asyncio.Queue(loop=self.loop)
self.can_iterate = asyncio.Event(loop=self.loop)
self.finished = asyncio.Event(loop=self.loop)
@property
def running(self):
@@ -42,15 +41,16 @@ class AsyncGeneratorJunction:
try:
async for item in iterator:
self.result_queue.put_nowait(item)
self.__iterator_queue.put_nowait(item)
finally:
self.running_iterators[iterator] = False
if not self.running:
self.__iterator_queue.put_nowait(StopAsyncIteration)
while True:
async_gen: typing.Union[typing.AsyncGenerator, 'AsyncGeneratorType'] = await self.generator_queue.get()
self.running_iterators[async_gen] = True
self.tasks.append(self.loop.create_task(iterate(async_gen)))
if not self.can_iterate.is_set():
self.can_iterate.set()
def add_generator(self, async_gen: typing.Union[typing.AsyncGenerator, 'AsyncGeneratorType']):
"""
@@ -62,14 +62,10 @@ class AsyncGeneratorJunction:
return self
async def __anext__(self):
if not self.can_iterate.is_set():
await self.can_iterate.wait()
if not self.running:
raise StopAsyncIteration()
try:
return await self.result_queue.get()
finally:
self.awaiting = None
result = await self.__iterator_queue.get()
if result is StopAsyncIteration:
raise result
return result
def aclose(self):
async def _aclose():
@@ -80,8 +76,6 @@ class AsyncGeneratorJunction:
self.running_iterators[iterator] = False
drain_tasks(self.tasks)
raise StopAsyncIteration()
if not self.finished.is_set():
self.finished.set()
return self.loop.create_task(_aclose())
async def __aenter__(self):
+4 -2
View File
@@ -5,7 +5,7 @@ from itertools import chain
import typing
import logging
from lbrynet.dht import constants
from lbrynet.dht.error import RemoteException
from lbrynet.dht.error import RemoteException, TransportNotConnected
from lbrynet.dht.protocol.distance import Distance
from typing import TYPE_CHECKING
@@ -169,6 +169,8 @@ class IterativeFinder:
log.warning(str(err))
self.active.discard(peer)
return
except TransportNotConnected:
return self.aclose()
except RemoteException:
return
return await self._handle_probe_result(peer, response)
@@ -215,7 +217,7 @@ class IterativeFinder:
await self._search_round()
if self.running:
self.delayed_calls.append(self.loop.call_later(delay, self._search))
except (asyncio.CancelledError, StopAsyncIteration):
except (asyncio.CancelledError, StopAsyncIteration, TransportNotConnected):
if self.running:
self.loop.call_soon(self.aclose)
+5 -1
View File
@@ -524,6 +524,10 @@ class KademliaProtocol(DatagramProtocol):
response = await asyncio.wait_for(response_fut, self.rpc_timeout)
self.peer_manager.report_last_replied(peer.address, peer.udp_port)
return response
except asyncio.CancelledError:
if not response_fut.done():
response_fut.cancel()
raise
except (asyncio.TimeoutError, RemoteException):
self.peer_manager.report_failure(peer.address, peer.udp_port)
if self.peer_manager.peer_is_good(peer) is False:
@@ -540,7 +544,7 @@ class KademliaProtocol(DatagramProtocol):
async def _send(self, peer: 'KademliaPeer', message: typing.Union[RequestDatagram, ResponseDatagram,
ErrorDatagram]):
if not self.transport:
if not self.transport or self.transport.is_closing():
raise TransportNotConnected()
data = message.bencode()
+6
View File
@@ -32,6 +32,12 @@ class DownloadDataTimeout(Exception):
self.download = download
class ResolveTimeout(Exception):
def __init__(self, uri):
super().__init__(f'Failed to resolve "{uri}" within the timeout')
self.uri = uri
class RequestCanceledError(Exception):
pass
+3 -6
View File
@@ -25,7 +25,7 @@ def display(data):
print(json.dumps(data, indent=2))
async def execute_command(conf, method, params):
async def execute_command(conf, method, params, callback=display):
async with aiohttp.ClientSession() as session:
try:
message = {'method': method, 'params': params}
@@ -33,12 +33,9 @@ async def execute_command(conf, method, params):
try:
data = await resp.json()
if 'result' in data:
display(data['result'])
return callback(data['result'])
elif 'error' in data:
if 'message' in data['error']:
display(data['error']['message'])
else:
display(data['error'])
return callback(data['error'])
except Exception as e:
log.exception('Could not process response from server:', exc_info=e)
except aiohttp.ClientConnectionError:
+11 -9
View File
@@ -16,7 +16,7 @@ from lbrynet import utils
from lbrynet.conf import HEADERS_FILE_SHA256_CHECKSUM
from lbrynet.dht.node import Node
from lbrynet.dht.blob_announcer import BlobAnnouncer
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob_exchange.server import BlobServer
from lbrynet.stream.stream_manager import StreamManager
from lbrynet.extras.daemon.Component import Component
@@ -63,7 +63,7 @@ class DatabaseComponent(Component):
@staticmethod
def get_current_db_revision():
return 9
return 11
@property
def revision_filename(self):
@@ -278,10 +278,10 @@ class BlobComponent(Component):
def __init__(self, component_manager):
super().__init__(component_manager)
self.blob_manager: BlobFileManager = None
self.blob_manager: BlobManager = None
@property
def component(self) -> typing.Optional[BlobFileManager]:
def component(self) -> typing.Optional[BlobManager]:
return self.blob_manager
async def start(self):
@@ -291,8 +291,10 @@ class BlobComponent(Component):
dht_node: Node = self.component_manager.get_component(DHT_COMPONENT)
if dht_node:
data_store = dht_node.protocol.data_store
self.blob_manager = BlobFileManager(asyncio.get_event_loop(), os.path.join(self.conf.data_dir, "blobfiles"),
storage, data_store)
blob_dir = os.path.join(self.conf.data_dir, 'blobfiles')
if not os.path.isdir(blob_dir):
os.mkdir(blob_dir)
self.blob_manager = BlobManager(asyncio.get_event_loop(), blob_dir, storage, self.conf, data_store)
return await self.blob_manager.setup()
async def stop(self):
@@ -451,7 +453,7 @@ class PeerProtocolServerComponent(Component):
async def start(self):
log.info("start blob server")
upnp = self.component_manager.get_component(UPNP_COMPONENT)
blob_manager: BlobFileManager = self.component_manager.get_component(BLOB_COMPONENT)
blob_manager: BlobManager = self.component_manager.get_component(BLOB_COMPONENT)
wallet: LbryWalletManager = self.component_manager.get_component(WALLET_COMPONENT)
peer_port = self.conf.tcp_port
address = await wallet.get_unused_address()
@@ -485,7 +487,7 @@ class UPnPComponent(Component):
while True:
if now:
await self._maintain_redirects()
await asyncio.sleep(360)
await asyncio.sleep(360, loop=self.component_manager.loop)
async def _maintain_redirects(self):
# setup the gateway if necessary
@@ -528,7 +530,7 @@ class UPnPComponent(Component):
self.upnp_redirects.update(upnp_redirects)
except (asyncio.TimeoutError, UPnPError):
self.upnp = None
return self._maintain_redirects()
return
elif self.upnp: # check existing redirects are still active
found = set()
mappings = await self.upnp.get_redirects()
+222 -107
View File
@@ -18,7 +18,7 @@ from torba.client.baseaccount import SingleKey, HierarchicalDeterministic
from lbrynet import utils
from lbrynet.conf import Config, Setting
from lbrynet.blob.blob_file import is_valid_blobhash
from lbrynet.blob.blob_file import is_valid_blobhash, BlobBuffer
from lbrynet.blob_exchange.downloader import download_blob
from lbrynet.error import DownloadSDTimeout, ComponentsNotStarted
from lbrynet.error import NullFundsError, NegativeFundsError, ComponentStartConditionNotMet
@@ -40,7 +40,7 @@ from lbrynet.extras.daemon.comment_client import jsonrpc_batch, jsonrpc_post, rp
if typing.TYPE_CHECKING:
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.dht.node import Node
from lbrynet.extras.daemon.Components import UPnPComponent
from lbrynet.extras.daemon.exchange_rate_manager import ExchangeRateManager
@@ -48,6 +48,7 @@ if typing.TYPE_CHECKING:
from lbrynet.wallet.manager import LbryWalletManager
from lbrynet.wallet.ledger import MainNetLedger
from lbrynet.stream.stream_manager import StreamManager
from lbrynet.stream.managed_stream import ManagedStream
log = logging.getLogger(__name__)
@@ -198,7 +199,7 @@ class JSONRPCError:
self.data = {} if data is None else data
self.traceback = []
if traceback is not None:
trace_lines = traceback.split("\n")
self.traceback = trace_lines = traceback.split("\n")
for i, t in enumerate(trace_lines):
if "--- <exception caught here> ---" in t:
if len(trace_lines) > i + 1:
@@ -272,6 +273,9 @@ class Daemon(metaclass=JSONRPCServerType):
app = web.Application()
app.router.add_get('/lbryapi', self.handle_old_jsonrpc)
app.router.add_post('/lbryapi', self.handle_old_jsonrpc)
app.router.add_get('/get/{claim_name}', self.handle_stream_get_request)
app.router.add_get('/get/{claim_name}/{claim_id}', self.handle_stream_get_request)
app.router.add_get('/stream/{sd_hash}', self.handle_stream_range_request)
app.router.add_post('/', self.handle_old_jsonrpc)
self.runner = web.AppRunner(app)
@@ -296,7 +300,7 @@ class Daemon(metaclass=JSONRPCServerType):
return self.component_manager.get_component(EXCHANGE_RATE_MANAGER_COMPONENT)
@property
def blob_manager(self) -> typing.Optional['BlobFileManager']:
def blob_manager(self) -> typing.Optional['BlobManager']:
return self.component_manager.get_component(BLOB_COMPONENT)
@property
@@ -306,7 +310,7 @@ class Daemon(metaclass=JSONRPCServerType):
@classmethod
def get_api_definitions(cls):
prefix = 'jsonrpc_'
not_grouped = ['block_show', 'report_bug', 'routing_table_get']
not_grouped = ['routing_table_get']
api = {
'groups': {
group_name[:-len('_DOC')].lower(): getattr(cls, group_name).strip()
@@ -399,7 +403,7 @@ class Daemon(metaclass=JSONRPCServerType):
await self.runner.setup()
try:
site = web.TCPSite(self.runner, self.conf.api_host, self.conf.api_port)
site = web.TCPSite(self.runner, self.conf.api_host, self.conf.api_port, shutdown_timeout=.5)
await site.start()
log.info('lbrynet API listening on TCP %s:%i', *site._server.sockets[0].getsockname()[:2])
except OSError as e:
@@ -429,15 +433,20 @@ class Daemon(metaclass=JSONRPCServerType):
self.component_startup_task = asyncio.create_task(self.component_manager.start())
await self.component_startup_task
async def stop(self):
async def stop(self, shutdown_runner=True):
if self.component_startup_task is not None:
if self.component_startup_task.done():
await self.component_manager.stop()
else:
self.component_startup_task.cancel()
log.info("stopped api components")
if shutdown_runner:
await self.runner.shutdown()
await self.runner.cleanup()
log.info("stopped api server")
if self.analytics_manager.is_started:
self.analytics_manager.stop()
log.info("finished shutting down")
async def handle_old_jsonrpc(self, request):
data = await request.json()
@@ -447,11 +456,42 @@ class Daemon(metaclass=JSONRPCServerType):
if 'wallet' in self.component_manager.get_components_status():
# self.ledger only available if wallet component is not skipped
ledger = self.ledger
try:
encoded_result = jsonrpc_dumps_pretty(
result, ledger=ledger, include_protobuf=include_protobuf)
except:
log.exception('Failed to encode JSON RPC result:')
encoded_result = jsonrpc_dumps_pretty(JSONRPCError(
'After successfully executing the command, failed to encode result for JSON RPC response.',
JSONRPCError.CODE_APPLICATION_ERROR, format_exc()
), ledger=ledger)
return web.Response(
text=jsonrpc_dumps_pretty(result, ledger=ledger, include_protobuf=include_protobuf),
text=encoded_result,
content_type='application/json'
)
async def handle_stream_get_request(self, request: web.Request):
name_and_claim_id = request.path.split("/get/")[1]
if "/" not in name_and_claim_id:
uri = f"lbry://{name_and_claim_id}"
else:
name, claim_id = name_and_claim_id.split("/")
uri = f"lbry://{name}#{claim_id}"
if not self.stream_manager.started.is_set():
await self.stream_manager.started.wait()
stream = await self.jsonrpc_get(uri)
if isinstance(stream, dict):
raise web.HTTPServerError(text=stream['error'])
raise web.HTTPFound(f"/stream/{stream.sd_hash}")
async def handle_stream_range_request(self, request: web.Request):
sd_hash = request.path.split("/stream/")[1]
if not self.stream_manager.started.is_set():
await self.stream_manager.started.wait()
if sd_hash not in self.stream_manager.streams:
return web.HTTPNotFound()
return await self.stream_manager.stream_partial_content(request, sd_hash)
async def _process_rpc_call(self, data):
args = data.get('params', {})
@@ -763,7 +803,8 @@ class Daemon(metaclass=JSONRPCServerType):
'claim_sequence': (int) claim sequence number (or -1 if unknown),
'decoded_claim': (bool) whether or not the claim value was decoded,
'height': (int) claim height,
'depth': (int) claim depth,
'confirmations': (int) claim depth,
'timestamp': (int) timestamp of the block that included this claim tx,
'has_signature': (bool) included if decoded_claim
'name': (str) claim name,
'permanent_url': (str) permanent url of the certificate claim,
@@ -827,24 +868,30 @@ class Daemon(metaclass=JSONRPCServerType):
@requires(WALLET_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, BLOB_COMPONENT, DATABASE_COMPONENT,
STREAM_MANAGER_COMPONENT,
conditions=[WALLET_IS_UNLOCKED])
async def jsonrpc_get(self, uri, file_name=None, timeout=None):
async def jsonrpc_get(self, uri, file_name=None, download_directory=None, timeout=None, save_file=None):
"""
Download stream from a LBRY name.
Usage:
get <uri> [<file_name> | --file_name=<file_name>] [<timeout> | --timeout=<timeout>]
get <uri> [<file_name> | --file_name=<file_name>]
[<download_directory> | --download_directory=<download_directory>] [<timeout> | --timeout=<timeout>]
[--save_file=<save_file>]
Options:
--uri=<uri> : (str) uri of the content to download
--file_name=<file_name> : (str) specified name for the downloaded file
--file_name=<file_name> : (str) specified name for the downloaded file, overrides the stream file name
--download_directory=<download_directory> : (str) full path to the directory to download into
--timeout=<timeout> : (int) download timeout in number of seconds
--save_file=<save_file> : (bool) save the file to the downloads directory
Returns: {File}
"""
if download_directory and not os.path.isdir(download_directory):
return {"error": f"specified download directory \"{download_directory}\" does not exist"}
try:
stream = await self.stream_manager.download_stream_from_uri(
uri, self.exchange_rate_manager, file_name, timeout
uri, self.exchange_rate_manager, timeout, file_name, download_directory, save_file=save_file
)
if not stream:
raise DownloadSDTimeout(uri)
@@ -897,7 +944,7 @@ class Daemon(metaclass=JSONRPCServerType):
"""
@requires("wallet")
def jsonrpc_account_list(self, account_id=None, confirmations=6,
def jsonrpc_account_list(self, account_id=None, confirmations=0,
include_claims=False, show_seed=False):
"""
List details of all of the accounts or a specific account.
@@ -1468,10 +1515,10 @@ class Daemon(metaclass=JSONRPCServerType):
raise Exception(f'Unable to find a file for {kwargs}')
stream = streams[0]
if status == 'start' and not stream.running:
await self.stream_manager.start_stream(stream)
await stream.save_file(node=self.stream_manager.node)
msg = "Resumed download"
elif status == 'stop' and stream.running:
await self.stream_manager.stop_stream(stream)
await stream.stop()
msg = "Stopped download"
else:
msg = (
@@ -1534,6 +1581,45 @@ class Daemon(metaclass=JSONRPCServerType):
result = True
return result
@requires(STREAM_MANAGER_COMPONENT)
async def jsonrpc_file_save(self, file_name=None, download_directory=None, **kwargs):
"""
Output a download to a file
Usage:
file_save [--file_name=<file_name>] [--download_directory=<download_directory>] [--sd_hash=<sd_hash>]
[--stream_hash=<stream_hash>] [--rowid=<rowid>] [--claim_id=<claim_id>] [--txid=<txid>]
[--nout=<nout>] [--claim_name=<claim_name>] [--channel_claim_id=<channel_claim_id>]
[--channel_name=<channel_name>]
Options:
--file_name=<file_name> : (str) delete by file name in downloads folder
--download_directory=<download_directory> : (str) delete by file name in downloads folder
--sd_hash=<sd_hash> : (str) delete by file sd hash
--stream_hash=<stream_hash> : (str) delete by file stream hash
--rowid=<rowid> : (int) delete by file row id
--claim_id=<claim_id> : (str) delete by file claim id
--txid=<txid> : (str) delete by file claim txid
--nout=<nout> : (int) delete by file claim nout
--claim_name=<claim_name> : (str) delete by file claim name
--channel_claim_id=<channel_claim_id> : (str) delete by file channel claim id
--channel_name=<channel_name> : (str) delete by file channel claim name
Returns: {File}
"""
streams = self.stream_manager.get_filtered_streams(**kwargs)
if len(streams) > 1:
log.warning("There are %i matching files, use narrower filters to select one", len(streams))
return False
if not streams:
log.warning("There is no file to save")
return False
stream = streams[0]
await stream.save_file(file_name, download_directory)
return stream
CLAIM_DOC = """
List and search all types of claims.
"""
@@ -1564,25 +1650,27 @@ class Daemon(metaclass=JSONRPCServerType):
@requires(WALLET_COMPONENT)
async def jsonrpc_claim_search(
self, name=None, claim_id=None, txid=None, nout=None,
channel_id=None, winning=False, page=1, page_size=10):
channel_id=None, channel_name=None, winning=False, page=1, page_size=10):
"""
Search for stream and channel claims on the blockchain.
Use --channel_id=<channel_id> to list all stream claims in a channel.
Use --channel_id=<channel_id> or --channel_name=<channel_name> to list all stream claims in a channel.
Usage:
claim_search [<name> | --name=<name>] [--claim_id=<claim_id>] [--txid=<txid> --nout=<nout>]
[--channel_id=<channel_id>] [--winning] [--page=<page>] [--page_size=<page_size>]
[--channel_id=<channel_id>] [--channel_name=<channel_name>] [--winning] [--page=<page>]
[--page_size=<page_size>]
Options:
--name=<name> : (str) find claims with this name
--claim_id=<claim_id> : (str) find a claim with this claim_id
--txid=<txid> : (str) find a claim with this txid:nout
--nout=<nout> : (str) find a claim with this txid:nout
--channel_id=<channel_id> : (str) limit search to specific channel claim id (returns stream claims)
--winning : (bool) limit to winning claims
--page=<page> : (int) page to return during paginating
--page_size=<page_size> : (int) number of items on page during pagination
--name=<name> : (str) find claims with this name
--claim_id=<claim_id> : (str) find a claim with this claim_id
--txid=<txid> : (str) find a claim with this txid:nout
--nout=<nout> : (str) find a claim with this txid:nout
--channel_id=<channel_id> : (str) limit search to specific channel claim id (returns stream claims)
--channel_name=<channel_name> : (str) limit search to specific channel name (returns stream claims)
--winning : (bool) limit to winning claims
--page=<page> : (int) page to return during paginating
--page_size=<page_size> : (int) number of items on page during pagination
Returns: {Paginated[Output]}
"""
@@ -1597,10 +1685,13 @@ class Daemon(metaclass=JSONRPCServerType):
claim = await self.wallet_manager.get_claim_by_outpoint(txid, int(nout))
if claim and claim != 'claim not found':
claims = {'claims': [claim]}
elif channel_id is not None:
claim = await self.wallet_manager.get_claim_by_claim_id(channel_id)
if claim and claim != 'claim not found':
channel_url = f"{claim['name']}#{claim['claim_id']}"
elif channel_id is not None or channel_name is not None:
channel_url = f"{channel_name}{('#' + str(channel_id)) if channel_id else ''}" if channel_name else None
if channel_id and not channel_name:
claim = await self.wallet_manager.get_claim_by_claim_id(channel_id)
if claim and claim != 'claim not found':
channel_url = f"{claim['name']}#{claim['claim_id']}"
if channel_url:
resolve = await self.resolve(channel_url, page=page, page_size=page_size)
resolve = resolve.get(channel_url, {})
claims = resolve.get('claims_in_channel', []) or []
@@ -1635,18 +1726,21 @@ class Daemon(metaclass=JSONRPCServerType):
Usage:
channel_create (<name> | --name=<name>) (<bid> | --bid=<bid>)
[--allow_duplicate_name=<allow_duplicate_name>]
[--title=<title>] [--description=<description>] [--email=<email>] [--featured=<featured>...]
[--title=<title>] [--description=<description>] [--email=<email>]
[--website_url=<website_url>] [--featured=<featured>...]
[--tags=<tags>...] [--languages=<languages>...] [--locations=<locations>...]
[--website_url=<website_url>] [--thumbnail_url=<thumbnail_url>] [--cover_url=<cover_url>]
[--thumbnail_url=<thumbnail_url>] [--cover_url=<cover_url>]
[--account_id=<account_id>] [--claim_address=<claim_address>] [--preview]
Options:
--name=<name> : (str) name of the channel prefixed with '@'
--bid=<bid> : (decimal) amount to back the claim
--allow_duplicate_name=<allow_duplicate_name> : (bool) create new channel even if one already exists with
given name. default: false.
--bid=<bid> : (decimal) amount to back the claim
--title=<title> : (str) title of the publication
--description=<description> : (str) description of the publication
--email=<email> : (str) email of channel owner
--website_url=<website_url> : (str) website url
--featured=<featured> : (list) claim_ids of featured content in channel
--tags=<tags> : (list) content tags
--languages=<languages> : (list) languages used by the channel,
@@ -1687,8 +1781,6 @@ class Daemon(metaclass=JSONRPCServerType):
... --locations="{'country': 'US', 'state': 'NH'}"
--email=<email> : (str) email of channel owner
--website_url=<website_url> : (str) website url
--thumbnail_url=<thumbnail_url>: (str) thumbnail url
--cover_url=<cover_url> : (str) url of cover image
--account_id=<account_id> : (str) id of the account to store channel
@@ -1736,31 +1828,33 @@ class Daemon(metaclass=JSONRPCServerType):
@requires(WALLET_COMPONENT, conditions=[WALLET_IS_UNLOCKED])
async def jsonrpc_channel_update(
self, claim_id, bid=None, account_id=None, claim_address=None,
new_signing_key=False, preview=False, **kwargs):
new_signing_key=False, preview=False, replace=False, **kwargs):
"""
Update an existing channel claim.
Usage:
channel_update (<claim_id> | --claim_id=<claim_id>) [<bid> | --bid=<bid>]
[--title=<title>] [--description=<description>]
[--title=<title>] [--description=<description>] [--email=<email>]
[--website_url=<website_url>]
[--featured=<featured>...] [--clear_featured]
[--tags=<tags>...] [--clear_tags]
[--languages=<languages>...] [--clear_languages]
[--locations=<locations>...] [--clear_locations]
[--email=<email>]
[--website_url=<website_url>] [--thumbnail_url=<thumbnail_url>] [--cover_url=<cover_url>]
[--account_id=<account_id>] [--claim_address=<claim_address>] [--new_signing_key] [--preview]
[--thumbnail_url=<thumbnail_url>] [--cover_url=<cover_url>]
[--account_id=<account_id>] [--claim_address=<claim_address>] [--new_signing_key]
[--preview] [--replace]
Options:
--claim_id=<claim_id> : (str) claim_id of the channel to update
--bid=<bid> : (decimal) amount to back the claim
--title=<title> : (str) title of the publication
--description=<description> : (str) description of the publication
--clear_featured : (bool) clear existing featured content (prior to adding new ones)
--email=<email> : (str) email of channel owner
--website_url=<website_url> : (str) website url
--featured=<featured> : (list) claim_ids of featured content in channel
--clear_tags : (bool) clear existing tags (prior to adding new ones)
--clear_featured : (bool) clear existing featured content (prior to adding new ones)
--tags=<tags> : (list) add content tags
--clear_languages : (bool) clear existing languages (prior to adding new ones)
--clear_tags : (bool) clear existing tags (prior to adding new ones)
--languages=<languages> : (list) languages used by the channel,
using RFC 5646 format, eg:
for English `--languages=en`
@@ -1768,7 +1862,7 @@ class Daemon(metaclass=JSONRPCServerType):
for Spanish (Mexican) `--languages=es-MX`
for Chinese (Simplified) `--languages=zh-Hans`
for Chinese (Traditional) `--languages=zh-Hant`
--clear_locations : (bool) clear existing locations (prior to adding new ones)
--clear_languages : (bool) clear existing languages (prior to adding new ones)
--locations=<locations> : (list) locations of the channel, consisting of 2 letter
`country` code and a `state`, `city` and a postal
`code` along with a `latitude` and `longitude`.
@@ -1800,14 +1894,17 @@ class Daemon(metaclass=JSONRPCServerType):
... --locations="{'country': 'US', 'state': 'NH'}"
--email=<email> : (str) email of channel owner
--website_url=<website_url> : (str) website url
--clear_locations : (bool) clear existing locations (prior to adding new ones)
--thumbnail_url=<thumbnail_url>: (str) thumbnail url
--cover_url=<cover_url> : (str) url of cover image
--account_id=<account_id> : (str) id of the account to store channel
--claim_address=<claim_address>: (str) address where the channel is sent
--new_signing_key : (bool) generate a new signing key, will invalidate all previous publishes
--preview : (bool) do not broadcast the transaction
--replace : (bool) instead of modifying specific values on
the channel, this will clear all existing values
and only save passed in values, useful for form
submissions where all values are always set
Returns: {Transaction}
"""
@@ -1834,7 +1931,11 @@ class Daemon(metaclass=JSONRPCServerType):
else:
claim_address = old_txo.get_address(account.ledger)
claim = Claim.from_bytes(old_txo.claim.to_bytes())
if replace:
claim = Claim()
claim.channel.public_key_bytes = old_txo.claim.channel.public_key_bytes
else:
claim = Claim.from_bytes(old_txo.claim.to_bytes())
claim.channel.update(**kwargs)
tx = await Transaction.claim_update(
old_txo, claim, amount, claim_address, [account], account
@@ -1976,18 +2077,16 @@ class Daemon(metaclass=JSONRPCServerType):
conditions=[WALLET_IS_UNLOCKED])
async def jsonrpc_publish(self, name, **kwargs):
"""
Create or update a stream claim at a given name (use 'stream create/update' for more control).
Create or replace a stream claim at a given name (use 'stream create/update' for more control).
Usage:
publish (<name> | --name=<name>) [--bid=<bid>] [--file_path=<file_path>]
[--tags=<tags>...] [--clear_tags]
[--languages=<languages>...] [--clear_languages]
[--locations=<locations>...] [--clear_locations]
[--fee_currency=<fee_currency>] [--fee_amount=<fee_amount>] [--fee_address=<fee_address>]
[--title=<title>] [--description=<description>] [--author=<author>] [--language=<language>]
[--title=<title>] [--description=<description>] [--author=<author>]
[--tags=<tags>...] [--languages=<languages>...] [--locations=<locations>...]
[--license=<license>] [--license_url=<license_url>] [--thumbnail_url=<thumbnail_url>]
[--release_time=<release_time>] [--width=<width>] [--height=<height>] [--duration=<duration>]
[--channel_id=<channel_id>] [--channel_name=<channel_name>]
[--channel_id=<channel_id> | --channel_name=<channel_name>]
[--channel_account_id=<channel_account_id>...]
[--account_id=<account_id>] [--claim_address=<claim_address>] [--preview]
@@ -2006,9 +2105,7 @@ class Daemon(metaclass=JSONRPCServerType):
who is not the publisher and is not represented by the channel. For
example, a pdf file of 'The Odyssey' has an author of 'Homer' but may
by published to a channel such as '@classics', or to no channel at all
--clear_tags : (bool) clear existing tags (prior to adding new ones)
--tags=<tags> : (list) add content tags
--clear_languages : (bool) clear existing languages (prior to adding new ones)
--languages=<languages> : (list) languages used by the channel,
using RFC 5646 format, eg:
for English `--languages=en`
@@ -2016,7 +2113,6 @@ class Daemon(metaclass=JSONRPCServerType):
for Spanish (Mexican) `--languages=es-MX`
for Chinese (Simplified) `--languages=zh-Hans`
for Chinese (Traditional) `--languages=zh-Hant`
--clear_locations : (bool) clear existing locations (prior to adding new ones)
--locations=<locations> : (list) locations relevant to the stream, consisting of 2 letter
`country` code and a `state`, `city` and a postal
`code` along with a `latitude` and `longitude`.
@@ -2066,6 +2162,7 @@ class Daemon(metaclass=JSONRPCServerType):
Returns: {Transaction}
"""
log.info("publishing: name: %s params: %s", name, kwargs)
self.valid_stream_name_or_error(name)
account = self.get_account_or_default(kwargs.get('account_id'))
claims = await account.get_claims(claim_name=name)
@@ -2077,7 +2174,7 @@ class Daemon(metaclass=JSONRPCServerType):
return await self.jsonrpc_stream_create(name, **kwargs)
elif len(claims) == 1:
assert claims[0].claim.is_stream, f"Claim at name '{name}' is not a stream claim."
return await self.jsonrpc_stream_update(claims[0].claim_id, **kwargs)
return await self.jsonrpc_stream_update(claims[0].claim_id, replace=True, **kwargs)
raise Exception(
f"There are {len(claims)} claims for '{name}', please use 'stream update' command "
f"to update a specific stream claim."
@@ -2095,21 +2192,21 @@ class Daemon(metaclass=JSONRPCServerType):
Usage:
stream_create (<name> | --name=<name>) (<bid> | --bid=<bid>) (<file_path> | --file_path=<file_path>)
[--allow_duplicate_name=<allow_duplicate_name>]
[--tags=<tags>...] [--languages=<languages>...] [--locations=<locations>...]
[--fee_currency=<fee_currency>] [--fee_amount=<fee_amount>] [--fee_address=<fee_address>]
[--title=<title>] [--description=<description>] [--author=<author>]
[--tags=<tags>...] [--languages=<languages>...] [--locations=<locations>...]
[--license=<license>] [--license_url=<license_url>] [--thumbnail_url=<thumbnail_url>]
[--release_time=<release_time>] [--width=<width>] [--height=<height>] [--duration=<duration>]
[--channel_id=<channel_id>] [--channel_name=<channel_name>]
[--channel_id=<channel_id> | --channel_name=<channel_name>]
[--channel_account_id=<channel_account_id>...]
[--account_id=<account_id>] [--claim_address=<claim_address>] [--preview]
Options:
--name=<name> : (str) name of the content (can only consist of a-z A-Z 0-9 and -(dash))
--allow_duplicate_name=<allow_duplicate_name> : (bool) create new claim even if one already exists with
given name. default: false.
--bid=<bid> : (decimal) amount to back the claim
--file_path=<file_path> : (str) path to file to be associated with name.
--allow_duplicate_name=<allow_duplicate_name> : (bool) create new claim even if one already exists with
given name. default: false.
--fee_currency=<fee_currency> : (string) specify fee currency
--fee_amount=<fee_amount> : (decimal) content download fee
--fee_address=<fee_address> : (str) address where to send fee payments, will use
@@ -2168,6 +2265,7 @@ class Daemon(metaclass=JSONRPCServerType):
--height=<height> : (int) image/video height, automatically calculated from media file
--duration=<duration> : (int) audio/video duration in seconds, automatically calculated
--channel_id=<channel_id> : (str) claim id of the publisher channel
--channel_name=<channel_name> : (str) name of the publisher channel
--channel_account_id=<channel_id>: (str) one or more account ids for accounts to look in
for channel certificates, defaults to all accounts.
--account_id=<account_id> : (str) account to use for funding the transaction
@@ -2199,20 +2297,22 @@ class Daemon(metaclass=JSONRPCServerType):
)
new_txo = tx.outputs[0]
file_stream = None
if not preview:
file_stream = await self.stream_manager.create_stream(file_path)
claim.stream.source.sd_hash = file_stream.sd_hash
new_txo.script.generate()
if channel:
new_txo.sign(channel)
await tx.sign([account])
if channel:
new_txo.sign(channel)
await tx.sign([account])
if not preview:
await account.ledger.broadcast(tx)
await self.storage.save_claims([self._old_get_temp_claim_info(
tx, new_txo, claim_address, claim, name, dewies_to_lbc(amount)
)])
stream_hash = await self.storage.get_stream_hash_for_sd_hash(claim.stream.source.sd_hash)
if stream_hash:
await self.storage.save_content_claim(stream_hash, new_txo.id)
await self.storage.save_content_claim(file_stream.stream_hash, new_txo.id)
await self.analytics_manager.send_claim_action('publish')
else:
await account.ledger.release_tx(tx)
@@ -2225,23 +2325,25 @@ class Daemon(metaclass=JSONRPCServerType):
self, claim_id, bid=None, file_path=None,
channel_id=None, channel_name=None, channel_account_id=None, clear_channel=False,
account_id=None, claim_address=None,
preview=False, **kwargs):
preview=False, replace=False, **kwargs):
"""
Update an existing stream claim and if a new file is provided announce it to lbrynet.
Usage:
stream_update (<claim_id> | --claim_id=<claim_id>) [--bid=<bid>] [--file_path=<file_path>]
[--file_name=<file_name>] [--file_size=<file_size>] [--file_hash=<file_hash>]
[--fee_currency=<fee_currency>] [--fee_amount=<fee_amount>]
[--fee_address=<fee_address>] [--clear_fee]
[--title=<title>] [--description=<description>] [--author=<author>]
[--tags=<tags>...] [--clear_tags]
[--languages=<languages>...] [--clear_languages]
[--locations=<locations>...] [--clear_locations]
[--fee_currency=<fee_currency>] [--fee_amount=<fee_amount>] [--fee_address=<fee_address>]
[--title=<title>] [--description=<description>] [--author=<author>] [--language=<language>]
[--license=<license>] [--license_url=<license_url>] [--thumbnail_url=<thumbnail_url>]
[--release_time=<release_time>] [--width=<width>] [--height=<height>] [--duration=<duration>]
[--channel_id=<channel_id>] [--channel_name=<channel_name>] [--clear_channel]
[--channel_id=<channel_id> | --channel_name=<channel_name> | --clear_channel]
[--channel_account_id=<channel_account_id>...]
[--account_id=<account_id>] [--claim_address=<claim_address>] [--preview]
[--account_id=<account_id>] [--claim_address=<claim_address>]
[--preview] [--replace]
Options:
--claim_id=<claim_id> : (str) id of the stream claim to update
@@ -2254,6 +2356,7 @@ class Daemon(metaclass=JSONRPCServerType):
--fee_amount=<fee_amount> : (decimal) content download fee
--fee_address=<fee_address> : (str) address where to send fee payments, will use
value from --claim_address if not provided
--clear_fee : (bool) clear previously set fee
--title=<title> : (str) title of the publication
--description=<description> : (str) description of the publication
--author=<author> : (str) author of the publication. The usage for this field is not
@@ -2261,9 +2364,8 @@ class Daemon(metaclass=JSONRPCServerType):
who is not the publisher and is not represented by the channel. For
example, a pdf file of 'The Odyssey' has an author of 'Homer' but may
by published to a channel such as '@classics', or to no channel at all
--clear_tags : (bool) clear existing tags (prior to adding new ones)
--tags=<tags> : (list) add content tags
--clear_languages : (bool) clear existing languages (prior to adding new ones)
--clear_tags : (bool) clear existing tags (prior to adding new ones)
--languages=<languages> : (list) languages used by the channel,
using RFC 5646 format, eg:
for English `--languages=en`
@@ -2271,7 +2373,7 @@ class Daemon(metaclass=JSONRPCServerType):
for Spanish (Mexican) `--languages=es-MX`
for Chinese (Simplified) `--languages=zh-Hans`
for Chinese (Traditional) `--languages=zh-Hant`
--clear_locations : (bool) clear existing locations (prior to adding new ones)
--clear_languages : (bool) clear existing languages (prior to adding new ones)
--locations=<locations> : (list) locations relevant to the stream, consisting of 2 letter
`country` code and a `state`, `city` and a postal
`code` along with a `latitude` and `longitude`.
@@ -2303,6 +2405,7 @@ class Daemon(metaclass=JSONRPCServerType):
... --locations="{'country': 'US', 'state': 'NH'}"
--clear_locations : (bool) clear existing locations (prior to adding new ones)
--license=<license> : (str) publication license
--license_url=<license_url> : (str) publication license url
--thumbnail_url=<thumbnail_url>: (str) thumbnail url
@@ -2311,6 +2414,7 @@ class Daemon(metaclass=JSONRPCServerType):
--height=<height> : (int) image/video height, automatically calculated from media file
--duration=<duration> : (int) audio/video duration in seconds, automatically calculated
--channel_id=<channel_id> : (str) claim id of the publisher channel
--channel_name=<channel_name> : (str) name of the publisher channel
--clear_channel : (bool) remove channel signature
--channel_account_id=<channel_id>: (str) one or more account ids for accounts to look in
for channel certificates, defaults to all accounts.
@@ -2318,6 +2422,10 @@ class Daemon(metaclass=JSONRPCServerType):
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
it will be determined automatically from the account
--preview : (bool) do not broadcast the transaction
--replace : (bool) instead of modifying specific values on
the stream, this will clear all existing values
and only save passed in values, useful for form
submissions where all values are always set
Returns: {Transaction}
"""
@@ -2326,7 +2434,7 @@ class Daemon(metaclass=JSONRPCServerType):
existing_claims = await account.get_claims(claim_id=claim_id)
if len(existing_claims) != 1:
raise Exception(
f"Can't find the claim '{claim_id}' in account '{account_id}'."
f"Can't find the claim '{claim_id}' in account '{account.id}'."
)
old_txo = existing_claims[0]
if not old_txo.claim.is_stream:
@@ -2347,32 +2455,54 @@ class Daemon(metaclass=JSONRPCServerType):
channel = None
if channel_id or channel_name:
channel = await self.get_channel_or_error(channel_account_id, channel_id, channel_name, for_signing=True)
elif old_txo.claim.is_signed and not clear_channel:
elif old_txo.claim.is_signed and not clear_channel and not replace:
channel = old_txo.channel
if 'fee_address' in kwargs:
self.valid_address_or_error(kwargs['fee_address'])
claim = Claim.from_bytes(old_txo.claim.to_bytes())
claim.stream.update(file_path=file_path, **kwargs)
if replace:
claim = Claim()
claim.stream.message.source.CopyFrom(
old_txo.claim.stream.message.source
)
stream_type = old_txo.claim.stream.stream_type
if stream_type:
old_stream_type = getattr(old_txo.claim.stream.message, stream_type)
new_stream_type = getattr(claim.stream.message, stream_type)
new_stream_type.CopyFrom(old_stream_type)
claim.stream.update(file_path=file_path, **kwargs)
else:
claim = Claim.from_bytes(old_txo.claim.to_bytes())
claim.stream.update(file_path=file_path, **kwargs)
tx = await Transaction.claim_update(
old_txo, claim, amount, claim_address, [account], account, channel
)
new_txo = tx.outputs[0]
stream_hash = None
if not preview:
old_stream_hash = await self.storage.get_stream_hash_for_sd_hash(old_txo.claim.stream.source.sd_hash)
if file_path is not None:
if old_stream_hash:
stream_to_delete = self.stream_manager.get_stream_by_stream_hash(old_stream_hash)
await self.stream_manager.delete_stream(stream_to_delete, delete_file=False)
file_stream = await self.stream_manager.create_stream(file_path)
new_txo.claim.stream.source.sd_hash = file_stream.sd_hash
new_txo.script.generate()
if channel:
new_txo.sign(channel)
await tx.sign([account])
stream_hash = file_stream.stream_hash
else:
stream_hash = old_stream_hash
if channel:
new_txo.sign(channel)
await tx.sign([account])
if not preview:
await account.ledger.broadcast(tx)
await self.storage.save_claims([self._old_get_temp_claim_info(
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)
)])
stream_hash = await self.storage.get_stream_hash_for_sd_hash(new_txo.claim.stream.source.sd_hash)
if stream_hash:
await self.storage.save_content_claim(stream_hash, new_txo.id)
await self.analytics_manager.send_claim_action('publish')
@@ -2740,23 +2870,6 @@ class Daemon(metaclass=JSONRPCServerType):
"""
return self.get_account_or_default(account_id).release_all_outputs()
@requires(WALLET_COMPONENT)
def jsonrpc_block_show(self, blockhash=None, height=None):
"""
Get contents of a block
Usage:
block_show (<blockhash> | --blockhash=<blockhash>) | (<height> | --height=<height>)
Options:
--blockhash=<blockhash> : (str) hash of the block to look up
--height=<height> : (int) height of the block to look up
Returns:
(dict) Requested block
"""
return self.wallet_manager.get_block(blockhash, height)
BLOB_DOC = """
Blob management.
"""
@@ -2780,10 +2893,12 @@ class Daemon(metaclass=JSONRPCServerType):
blob = await download_blob(asyncio.get_event_loop(), self.conf, self.blob_manager, self.dht_node, blob_hash)
if read:
with open(blob.file_path, 'rb') as handle:
with blob.reader_context() as handle:
return handle.read().decode()
else:
return "Downloaded blob %s" % blob_hash
elif isinstance(blob, BlobBuffer):
log.warning("manually downloaded blob buffer could have missed garbage collection, clearing it")
blob.delete()
return "Downloaded blob %s" % blob_hash
@requires(BLOB_COMPONENT, DATABASE_COMPONENT)
async def jsonrpc_blob_delete(self, blob_hash):
@@ -2934,9 +3049,9 @@ class Daemon(metaclass=JSONRPCServerType):
else:
blobs = list(self.blob_manager.completed_blob_hashes)
if needed:
blobs = [blob_hash for blob_hash in blobs if not self.blob_manager.get_blob(blob_hash).get_is_verified()]
blobs = [blob_hash for blob_hash in blobs if not self.blob_manager.is_blob_verified(blob_hash)]
if finished:
blobs = [blob_hash for blob_hash in blobs if self.blob_manager.get_blob(blob_hash).get_is_verified()]
blobs = [blob_hash for blob_hash in blobs if self.blob_manager.is_blob_verified(blob_hash)]
page_size = page_size or len(blobs)
page = page or 0
start_index = page * page_size
@@ -3312,7 +3427,7 @@ class Daemon(metaclass=JSONRPCServerType):
async def get_channel_or_none(self, account_ids: List[str], channel_id: str = None, channel_name: str = None,
for_signing: bool = False) -> Output:
if channel_id is not None:
if channel_id is not None or channel_name is not None:
return await self.get_channel_or_error(account_ids, channel_id, channel_name, for_signing)
async def get_channel_or_error(self, account_ids: List[str], channel_id: str = None, channel_name: str = None,
+3 -24
View File
@@ -1,27 +1,6 @@
import aiohttp
import logging
from lbrynet.conf import Config
log = logging.getLogger(__name__)
USER_AGENT = "AuthServiceProxy/0.1"
TWISTED_SECURE_SESSION = "TWISTED_SECURE_SESSION"
TWISTED_SESSION = "TWISTED_SESSION"
LBRY_SECRET = "LBRY_SECRET"
HTTP_TIMEOUT = 30
from lbrynet.extras.cli import execute_command
class JSONRPCException(Exception):
def __init__(self, rpc_error):
super().__init__()
self.error = rpc_error
async def daemon_rpc(conf: Config, method: str, *args, **kwargs):
async with aiohttp.ClientSession() as session:
message = {'method': method, 'params': [args, kwargs]}
async with session.get(conf.api_connection_url, json=message) as resp:
data = await resp.json()
if 'result' in data:
return data['result']
elif 'error' in data:
raise JSONRPCException(data['error'])
def daemon_rpc(conf: Config, method: str, **kwargs):
return execute_command(conf, method, kwargs, callback=lambda data: data)
+12 -4
View File
@@ -144,7 +144,8 @@ class JSONResponseEncoder(JSONEncoder):
'height': tx_height,
'amount': dewies_to_lbc(txo.amount),
'address': txo.get_address(self.ledger),
'confirmations': (best_height+1) - tx_height if tx_height > 0 else tx_height
'confirmations': (best_height+1) - tx_height if tx_height > 0 else tx_height,
'timestamp': self.ledger.headers[tx_height]['timestamp'] if tx_height > 0 else None
}
if txo.is_change is not None:
output['is_change'] = txo.is_change
@@ -205,9 +206,16 @@ class JSONResponseEncoder(JSONEncoder):
result['is_default'] = self.ledger.accounts[0] == account
return result
@staticmethod
def encode_file(managed_stream):
return managed_stream.as_dict()
def encode_file(self, managed_stream):
file = managed_stream.as_dict()
tx_height = managed_stream.stream_claim_info.height
best_height = self.ledger.headers.height
file.update({
'height': tx_height,
'confirmations': (best_height+1) - tx_height if tx_height > 0 else tx_height,
'timestamp': self.ledger.headers[tx_height]['timestamp'] if tx_height > 0 else None
})
return file
@staticmethod
def encode_claim(claim):
@@ -22,6 +22,10 @@ def migrate_db(conf, start, end):
from .migrate7to8 import do_migration
elif current == 8:
from .migrate8to9 import do_migration
elif current == 9:
from .migrate9to10 import do_migration
elif current == 10:
from .migrate10to11 import do_migration
else:
raise Exception("DB migration of version {} to {} is not available".format(current,
current+1))
@@ -0,0 +1,54 @@
import sqlite3
import os
import binascii
def do_migration(conf):
db_path = os.path.join(conf.data_dir, "lbrynet.sqlite")
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
current_columns = []
for col_info in cursor.execute("pragma table_info('file');").fetchall():
current_columns.append(col_info[1])
if 'content_fee' in current_columns or 'saved_file' in current_columns:
connection.close()
print("already migrated")
return
cursor.execute(
"pragma foreign_keys=off;"
)
cursor.execute("""
create table if not exists new_file (
stream_hash text primary key not null references stream,
file_name text,
download_directory text,
blob_data_rate real not null,
status text not null,
saved_file integer not null,
content_fee text
);
""")
for (stream_hash, file_name, download_dir, data_rate, status) in cursor.execute("select * from file").fetchall():
saved_file = 0
if download_dir != '{stream}' and file_name != '{stream}':
try:
if os.path.isfile(os.path.join(binascii.unhexlify(download_dir).decode(),
binascii.unhexlify(file_name).decode())):
saved_file = 1
else:
download_dir, file_name = None, None
except Exception:
download_dir, file_name = None, None
else:
download_dir, file_name = None, None
cursor.execute(
"insert into new_file values (?, ?, ?, ?, ?, ?, NULL)",
(stream_hash, file_name, download_dir, data_rate, status, saved_file)
)
cursor.execute("drop table file")
cursor.execute("alter table new_file rename to file")
connection.commit()
connection.close()
@@ -0,0 +1,20 @@
import sqlite3
import os
def do_migration(conf):
db_path = os.path.join(conf.data_dir, "lbrynet.sqlite")
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
query = "select stream_hash, sd_hash from main.stream"
for stream_hash, sd_hash in cursor.execute(query).fetchall():
head_blob_hash = cursor.execute(
"select blob_hash from stream_blob where position = 0 and stream_hash = ?",
(stream_hash,)
).fetchone()
if not head_blob_hash:
continue
cursor.execute("update blob set should_announce=1 where blob_hash in (?, ?)", (sd_hash, head_blob_hash[0],))
connection.commit()
connection.close()
+138 -56
View File
@@ -8,6 +8,7 @@ import time
from torba.client.basedatabase import SQLiteMixin
from lbrynet.conf import Config
from lbrynet.wallet.dewies import dewies_to_lbc, lbc_to_dewies
from lbrynet.wallet.transaction import Transaction
from lbrynet.schema.claim import Claim
from lbrynet.dht.constants import data_expiration
from lbrynet.blob.blob_info import BlobInfo
@@ -54,10 +55,6 @@ class StoredStreamClaim:
def nout(self) -> typing.Optional[int]:
return None if not self.outpoint else int(self.outpoint.split(":")[1])
@property
def metadata(self) -> typing.Optional[typing.Dict]:
return None if not self.claim else self.claim.claim_dict['stream']['metadata']
def as_dict(self) -> typing.Dict:
return {
"name": self.claim_name,
@@ -118,8 +115,8 @@ def _batched_select(transaction, query, parameters, batch_size=900):
def get_all_lbry_files(transaction: sqlite3.Connection) -> typing.List[typing.Dict]:
files = []
signed_claims = {}
for (rowid, stream_hash, file_name, download_dir, data_rate, status, _, sd_hash, stream_key,
stream_name, suggested_file_name, *claim_args) in _batched_select(
for (rowid, stream_hash, file_name, download_dir, data_rate, status, saved_file, raw_content_fee, _,
sd_hash, stream_key, stream_name, suggested_file_name, *claim_args) in _batched_select(
transaction, "select file.rowid, file.*, stream.*, c.* "
"from file inner join stream on file.stream_hash=stream.stream_hash "
"inner join content_claim cc on file.stream_hash=cc.stream_hash "
@@ -145,7 +142,11 @@ def get_all_lbry_files(transaction: sqlite3.Connection) -> typing.List[typing.Di
"key": stream_key,
"stream_name": stream_name, # hex
"suggested_file_name": suggested_file_name, # hex
"claim": claim
"claim": claim,
"saved_file": bool(saved_file),
"content_fee": None if not raw_content_fee else Transaction(
binascii.unhexlify(raw_content_fee)
)
}
)
for claim_name, claim_id in _batched_select(
@@ -157,21 +158,12 @@ def get_all_lbry_files(transaction: sqlite3.Connection) -> typing.List[typing.Di
def store_stream(transaction: sqlite3.Connection, sd_blob: 'BlobFile', descriptor: 'StreamDescriptor'):
# add the head blob and set it to be announced
transaction.execute(
"insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?)",
(
sd_blob.blob_hash, sd_blob.length, 0, 1, "pending", 0, 0,
descriptor.blobs[0].blob_hash, descriptor.blobs[0].length, 0, 1, "pending", 0, 0
)
# add all blobs, except the last one, which is empty
transaction.executemany(
"insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?)",
[(blob.blob_hash, blob.length, 0, 0, "pending", 0, 0)
for blob in (descriptor.blobs[:-1] if len(descriptor.blobs) > 1 else descriptor.blobs) + [sd_blob]]
)
# add the rest of the blobs with announcement off
if len(descriptor.blobs) > 2:
transaction.executemany(
"insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?)",
[(blob.blob_hash, blob.length, 0, 0, "pending", 0, 0)
for blob in descriptor.blobs[1:-1]]
)
# associate the blobs to the stream
transaction.execute("insert or ignore into stream values (?, ?, ?, ?, ?)",
(descriptor.stream_hash, sd_blob.blob_hash, descriptor.key,
@@ -183,6 +175,11 @@ def store_stream(transaction: sqlite3.Connection, sd_blob: 'BlobFile', descripto
[(descriptor.stream_hash, blob.blob_hash, blob.blob_num, blob.iv)
for blob in descriptor.blobs]
)
# ensure should_announce is set regardless if insert was ignored
transaction.execute(
"update blob set should_announce=1 where blob_hash in (?, ?)",
(sd_blob.blob_hash, descriptor.blobs[0].blob_hash,)
)
def delete_stream(transaction: sqlite3.Connection, descriptor: 'StreamDescriptor'):
@@ -195,13 +192,21 @@ def delete_stream(transaction: sqlite3.Connection, descriptor: 'StreamDescriptor
transaction.executemany("delete from blob where blob_hash=?", blob_hashes)
def store_file(transaction: sqlite3.Connection, stream_hash: str, file_name: str, download_directory: str,
data_payment_rate: float, status: str) -> int:
def store_file(transaction: sqlite3.Connection, stream_hash: str, file_name: typing.Optional[str],
download_directory: typing.Optional[str], data_payment_rate: float, status: str,
content_fee: typing.Optional[Transaction]) -> int:
if not file_name and not download_directory:
encoded_file_name, encoded_download_dir = None, None
else:
encoded_file_name = binascii.hexlify(file_name.encode()).decode()
encoded_download_dir = binascii.hexlify(download_directory.encode()).decode()
transaction.execute(
"insert or replace into file values (?, ?, ?, ?, ?)",
(stream_hash, binascii.hexlify(file_name.encode()).decode(),
binascii.hexlify(download_directory.encode()).decode(), data_payment_rate, status)
"insert or replace into file values (?, ?, ?, ?, ?, ?, ?)",
(stream_hash, encoded_file_name, encoded_download_dir, data_payment_rate, status,
1 if (file_name and download_directory and os.path.isfile(os.path.join(download_directory, file_name))) else 0,
None if not content_fee else binascii.hexlify(content_fee.raw).decode())
)
return transaction.execute("select rowid from file where stream_hash=?", (stream_hash, )).fetchone()[0]
@@ -250,10 +255,12 @@ class SQLiteStorage(SQLiteMixin):
create table if not exists file (
stream_hash text primary key not null references stream,
file_name text not null,
download_directory text not null,
file_name text,
download_directory text,
blob_data_rate real not null,
status text not null
status text not null,
saved_file integer not null,
content_fee text
);
create table if not exists content_claim (
@@ -296,27 +303,28 @@ class SQLiteStorage(SQLiteMixin):
# # # # # # # # # blob functions # # # # # # # # #
def add_completed_blob(self, blob_hash: str, length: int):
def _add_blob(transaction: sqlite3.Connection):
transaction.execute(
async def add_blobs(self, *blob_hashes_and_lengths: typing.Tuple[str, int], finished=False):
def _add_blobs(transaction: sqlite3.Connection):
transaction.executemany(
"insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?)",
(blob_hash, length, 0, 0, "pending", 0, 0)
[
(blob_hash, length, 0, 0, "pending" if not finished else "finished", 0, 0)
for blob_hash, length in blob_hashes_and_lengths
]
)
transaction.execute(
"update blob set status='finished' where blob.blob_hash=?", (blob_hash, )
)
return self.db.run(_add_blob)
if finished:
transaction.executemany(
"update blob set status='finished' where blob.blob_hash=?", [
(blob_hash, ) for blob_hash, _ in blob_hashes_and_lengths
]
)
return await self.db.run(_add_blobs)
def get_blob_status(self, blob_hash: str):
return self.run_and_return_one_or_none(
"select status from blob where blob_hash=?", blob_hash
)
def add_known_blob(self, blob_hash: str, length: int):
return self.db.execute(
"insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?)", (blob_hash, length, 0, 0, "pending", 0, 0)
)
def should_announce(self, blob_hash: str):
return self.run_and_return_one_or_none(
"select should_announce from blob where blob_hash=?", blob_hash
@@ -419,6 +427,26 @@ class SQLiteStorage(SQLiteMixin):
}
return self.db.run(_sync_blobs)
def sync_files_to_blobs(self):
def _sync_blobs(transaction: sqlite3.Connection):
transaction.executemany(
"update file set status='stopped' where stream_hash=?",
transaction.execute(
"select distinct sb.stream_hash from stream_blob sb "
"inner join blob b on b.blob_hash=sb.blob_hash and b.status=='pending'"
).fetchall()
)
return self.db.run(_sync_blobs)
def set_files_as_streaming(self, stream_hashes: typing.List[str]):
def _set_streaming(transaction: sqlite3.Connection):
transaction.executemany(
"update file set file_name=null, download_directory=null where stream_hash=?",
[(stream_hash, ) for stream_hash in stream_hashes]
)
return self.db.run(_set_streaming)
# # # # # # # # # stream functions # # # # # # # # #
async def stream_exists(self, sd_hash: str) -> bool:
@@ -481,20 +509,53 @@ class SQLiteStorage(SQLiteMixin):
"select stream_hash from stream where sd_hash = ?", sd_blob_hash
)
def get_stream_info_for_sd_hash(self, sd_blob_hash):
return self.run_and_return_one_or_none(
"select stream_hash, stream_name, suggested_filename, stream_key from stream where sd_hash = ?",
sd_blob_hash
)
def delete_stream(self, descriptor: 'StreamDescriptor'):
return self.db.run_with_foreign_keys_disabled(delete_stream, descriptor)
# # # # # # # # # file stuff # # # # # # # # #
def save_downloaded_file(self, stream_hash, file_name, download_directory,
data_payment_rate) -> typing.Awaitable[int]:
def save_downloaded_file(self, stream_hash: str, file_name: typing.Optional[str],
download_directory: typing.Optional[str], data_payment_rate: float,
content_fee: typing.Optional[Transaction] = None) -> typing.Awaitable[int]:
return self.save_published_file(
stream_hash, file_name, download_directory, data_payment_rate, status="running"
stream_hash, file_name, download_directory, data_payment_rate, status="running",
content_fee=content_fee
)
def save_published_file(self, stream_hash: str, file_name: str, download_directory: str, data_payment_rate: float,
status="finished") -> typing.Awaitable[int]:
return self.db.run(store_file, stream_hash, file_name, download_directory, data_payment_rate, status)
def save_published_file(self, stream_hash: str, file_name: typing.Optional[str],
download_directory: typing.Optional[str], data_payment_rate: float,
status: str = "finished",
content_fee: typing.Optional[Transaction] = None) -> typing.Awaitable[int]:
return self.db.run(store_file, stream_hash, file_name, download_directory, data_payment_rate, status,
content_fee)
async def update_manually_removed_files_since_last_run(self):
"""
Update files that have been removed from the downloads directory since the last run
"""
def update_manually_removed_files(transaction: sqlite3.Connection):
removed = []
for (stream_hash, download_directory, file_name) in transaction.execute(
"select stream_hash, download_directory, file_name from file where saved_file=1"
).fetchall():
if download_directory and file_name and os.path.isfile(
os.path.join(binascii.unhexlify(download_directory).decode(),
binascii.unhexlify(file_name).decode())):
continue
else:
removed.append((stream_hash,))
if removed:
transaction.executemany(
"update file set file_name=null, download_directory=null, saved_file=0 where stream_hash=?",
removed
)
return await self.db.run(update_manually_removed_files)
def get_all_lbry_files(self) -> typing.Awaitable[typing.List[typing.Dict]]:
return self.db.run(get_all_lbry_files)
@@ -503,24 +564,45 @@ class SQLiteStorage(SQLiteMixin):
log.debug("update file status %s -> %s", stream_hash, new_status)
return self.db.execute("update file set status=? where stream_hash=?", (new_status, stream_hash))
def change_file_download_dir_and_file_name(self, stream_hash: str, download_dir: str, file_name: str):
return self.db.execute("update file set download_directory=?, file_name=? where stream_hash=?", (
binascii.hexlify(download_dir.encode()).decode(), binascii.hexlify(file_name.encode()).decode(),
stream_hash
async def change_file_download_dir_and_file_name(self, stream_hash: str, download_dir: typing.Optional[str],
file_name: typing.Optional[str]):
if not file_name or not download_dir:
encoded_file_name, encoded_download_dir = None, None
else:
encoded_file_name = binascii.hexlify(file_name.encode()).decode()
encoded_download_dir = binascii.hexlify(download_dir.encode()).decode()
return await self.db.execute("update file set download_directory=?, file_name=? where stream_hash=?", (
encoded_download_dir, encoded_file_name, stream_hash,
))
async def recover_streams(self, descriptors_and_sds: typing.List[typing.Tuple['StreamDescriptor', 'BlobFile']],
async def save_content_fee(self, stream_hash: str, content_fee: Transaction):
return await self.db.execute("update file set content_fee=? where stream_hash=?", (
binascii.hexlify(content_fee.raw), stream_hash,
))
async def set_saved_file(self, stream_hash: str):
return await self.db.execute("update file set saved_file=1 where stream_hash=?", (
stream_hash,
))
async def clear_saved_file(self, stream_hash: str):
return await self.db.execute("update file set saved_file=0 where stream_hash=?", (
stream_hash,
))
async def recover_streams(self, descriptors_and_sds: typing.List[typing.Tuple['StreamDescriptor', 'BlobFile',
typing.Optional[Transaction]]],
download_directory: str):
def _recover(transaction: sqlite3.Connection):
stream_hashes = [d.stream_hash for d, s in descriptors_and_sds]
for descriptor, sd_blob in descriptors_and_sds:
stream_hashes = [x[0].stream_hash for x in descriptors_and_sds]
for descriptor, sd_blob, content_fee in descriptors_and_sds:
content_claim = transaction.execute(
"select * from content_claim where stream_hash=?", (descriptor.stream_hash, )
).fetchone()
delete_stream(transaction, descriptor) # this will also delete the content claim
store_stream(transaction, sd_blob, descriptor)
store_file(transaction, descriptor.stream_hash, os.path.basename(descriptor.suggested_file_name),
download_directory, 0.0, 'stopped')
download_directory, 0.0, 'stopped', content_fee=content_fee)
if content_claim:
transaction.execute("insert or ignore into content_claim values (?, ?)", content_claim)
transaction.executemany(
+15 -6
View File
@@ -6,6 +6,7 @@ from typing import Tuple, List
from string import ascii_letters
from decimal import Decimal, ROUND_UP
from binascii import hexlify, unhexlify
from google.protobuf.json_format import MessageToDict
from torba.client.hash import Base58
from torba.client.constants import COIN
@@ -22,12 +23,12 @@ from lbrynet.schema.types.v2.claim_pb2 import (
log = logging.getLogger(__name__)
def calculate_sha256_file_hash(file_path):
sha256 = hashlib.sha256()
def calculate_sha384_file_hash(file_path):
sha384 = hashlib.sha384()
with open(file_path, 'rb') as f:
for chunk in iter(lambda: f.read(128 * sha256.block_size), b''):
sha256.update(chunk)
return sha256.digest()
for chunk in iter(lambda: f.read(128 * sha384.block_size), b''):
sha384.update(chunk)
return sha384.digest()
class Dimmensional(Metadata):
@@ -130,7 +131,7 @@ class Source(Metadata):
self.size = os.path.getsize(file_path)
if self.size == 0:
raise Exception(f"Cannot publish empty file: {file_path}")
self.file_hash_bytes = calculate_sha256_file_hash(file_path)
self.file_hash_bytes = calculate_sha384_file_hash(file_path)
return stream_type
@property
@@ -446,6 +447,14 @@ class Location(Metadata):
else:
raise ValueError(f'Could not parse country value: {value}')
def to_dict(self):
d = MessageToDict(self.message)
if self.message.longitude:
d['longitude'] = self.longitude
if self.message.latitude:
d['latitude'] = self.latitude
return d
@property
def country(self) -> str:
if self.message.country:
+23 -12
View File
@@ -115,6 +115,8 @@ class BaseClaim:
claim.update(claim.pop(self.claim_type))
if 'languages' in claim:
claim['languages'] = self.langtags
if 'locations' in claim:
claim['locations'] = [l.to_dict() for l in self.locations]
return claim
def update(self, **kwargs):
@@ -197,23 +199,24 @@ class Stream(BaseClaim):
if 'address' in fee:
fee['address'] = self.fee.address
if 'amount' in fee:
fee['amount'] = self.fee.amount
fee['amount'] = str(self.fee.amount)
stream_type = self.message.WhichOneof('type')
if stream_type:
claim['stream_type'] = stream_type
return claim
def update(self, file_path=None, height=None, width=None, duration=None, **kwargs):
self.fee.update(
kwargs.pop('fee_address', None),
kwargs.pop('fee_currency', None),
kwargs.pop('fee_amount', None)
)
if kwargs.pop('clear_fee', False):
self.message.ClearField('fee')
else:
self.fee.update(
kwargs.pop('fee_address', None),
kwargs.pop('fee_currency', None),
kwargs.pop('fee_amount', None)
)
if 'sd_hash' in kwargs:
self.source.sd_hash = kwargs.pop('sd_hash')
if 'file_size' in kwargs:
self.source.size = kwargs.pop('file_size')
if 'file_name' in kwargs:
self.source.name = kwargs.pop('file_name')
if 'file_hash' in kwargs:
@@ -227,13 +230,17 @@ class Stream(BaseClaim):
elif self.source.media_type:
stream_type = guess_stream_type(self.source.media_type)
if 'file_size' in kwargs:
self.source.size = kwargs.pop('file_size')
if stream_type in ('image', 'video', 'audio'):
media = getattr(self, stream_type)
media_args = {'file_metadata': None}
try:
media_args['file_metadata'] = binary_file_metadata(binary_file_parser(file_path))
except:
log.exception('Could not read file metadata.')
if file_path is not None:
try:
media_args['file_metadata'] = binary_file_metadata(binary_file_parser(file_path))
except:
log.exception('Could not read file metadata.')
if isinstance(media, Playable):
media_args['duration'] = duration
if isinstance(media, Dimmensional):
@@ -287,6 +294,10 @@ class Stream(BaseClaim):
def source(self) -> Source:
return Source(self.message.source)
@property
def stream_type(self) -> str:
return self.message.WhichOneof('type')
@property
def image(self) -> Image:
return Image(self.message.image)
+1 -1
View File
@@ -137,7 +137,7 @@ types_map = {
'.zip': ('application/zip', 'binary'),
# These are non-standard types, commonly found in the wild.
'.cbr': ('application/vnd.comicbook+zip', 'document'),
'.cbr': ('application/vnd.comicbook-rar', 'document'),
'.cbz': ('application/vnd.comicbook+zip', 'document'),
'.lbry': ('application/x-ext-lbry', 'document'),
'.mid': ('audio/midi', 'audio'),
-136
View File
@@ -1,136 +0,0 @@
import os
import binascii
import logging
import typing
import asyncio
from lbrynet.blob import MAX_BLOB_SIZE
from lbrynet.stream.descriptor import StreamDescriptor
if typing.TYPE_CHECKING:
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_info import BlobInfo
from lbrynet.blob.blob_file import BlobFile
log = logging.getLogger(__name__)
def _get_next_available_file_name(download_directory: str, file_name: str) -> str:
base_name, ext = os.path.splitext(os.path.basename(file_name))
i = 0
while os.path.isfile(os.path.join(download_directory, file_name)):
i += 1
file_name = "%s_%i%s" % (base_name, i, ext)
return file_name
async def get_next_available_file_name(loop: asyncio.BaseEventLoop, download_directory: str, file_name: str) -> str:
return await loop.run_in_executor(None, _get_next_available_file_name, download_directory, file_name)
class StreamAssembler:
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobFileManager', sd_hash: str,
output_file_name: typing.Optional[str] = None):
self.output_file_name = output_file_name
self.loop = loop
self.blob_manager = blob_manager
self.sd_hash = sd_hash
self.sd_blob: 'BlobFile' = None
self.descriptor: StreamDescriptor = None
self.got_descriptor = asyncio.Event(loop=self.loop)
self.wrote_bytes_event = asyncio.Event(loop=self.loop)
self.stream_finished_event = asyncio.Event(loop=self.loop)
self.output_path = ''
self.stream_handle = None
self.written_bytes: int = 0
async def _decrypt_blob(self, blob: 'BlobFile', blob_info: 'BlobInfo', key: str):
if not blob or not self.stream_handle or self.stream_handle.closed:
return False
def _decrypt_and_write():
offset = blob_info.blob_num * (MAX_BLOB_SIZE - 1)
self.stream_handle.seek(offset)
_decrypted = blob.decrypt(
binascii.unhexlify(key), binascii.unhexlify(blob_info.iv.encode())
)
self.stream_handle.write(_decrypted)
self.stream_handle.flush()
self.written_bytes += len(_decrypted)
log.debug("decrypted %s", blob.blob_hash[:8])
await self.loop.run_in_executor(None, _decrypt_and_write)
return True
async def setup(self):
pass
async def after_got_descriptor(self):
pass
async def after_finished(self):
pass
async def assemble_decrypted_stream(self, output_dir: str, output_file_name: typing.Optional[str] = None):
if not os.path.isdir(output_dir):
raise OSError(f"output directory does not exist: '{output_dir}' '{output_file_name}'")
await self.setup()
self.sd_blob = await self.get_blob(self.sd_hash)
self.descriptor = await StreamDescriptor.from_stream_descriptor_blob(self.loop, self.blob_manager.blob_dir,
self.sd_blob)
await self.after_got_descriptor()
self.output_file_name = output_file_name or self.descriptor.suggested_file_name
self.output_file_name = await get_next_available_file_name(self.loop, output_dir, self.output_file_name)
self.output_path = os.path.join(output_dir, self.output_file_name)
if not self.got_descriptor.is_set():
self.got_descriptor.set()
await self.blob_manager.storage.store_stream(
self.sd_blob, self.descriptor
)
await self.blob_manager.blob_completed(self.sd_blob)
written_blobs = None
save_tasks = []
try:
with open(self.output_path, 'wb') as stream_handle:
self.stream_handle = stream_handle
for i, blob_info in enumerate(self.descriptor.blobs[:-1]):
if blob_info.blob_num != i:
log.error("sd blob %s is invalid, cannot assemble stream", self.descriptor.sd_hash)
return
while self.stream_handle and not self.stream_handle.closed:
try:
blob = await self.get_blob(blob_info.blob_hash, blob_info.length)
if blob and blob.length != blob_info.length:
log.warning("Found incomplete, deleting: %s", blob_info.blob_hash)
await self.blob_manager.delete_blobs([blob_info.blob_hash])
continue
if await self._decrypt_blob(blob, blob_info, self.descriptor.key):
save_tasks.append(asyncio.ensure_future(self.blob_manager.blob_completed(blob)))
written_blobs = i
if not self.wrote_bytes_event.is_set():
self.wrote_bytes_event.set()
log.debug("written %i/%i", written_blobs, len(self.descriptor.blobs) - 2)
break
except FileNotFoundError:
log.debug("stream assembler stopped")
return
except (ValueError, IOError, OSError):
log.warning("failed to decrypt blob %s for stream %s", blob_info.blob_hash,
self.descriptor.sd_hash)
continue
finally:
if written_blobs == len(self.descriptor.blobs) - 2:
log.debug("finished decrypting and assembling stream")
if save_tasks:
await asyncio.wait(save_tasks)
await self.after_finished()
self.stream_finished_event.set()
else:
log.debug("stream decryption and assembly did not finish (%i/%i blobs are done)", written_blobs or 0,
len(self.descriptor.blobs) - 2)
if self.output_path and os.path.isfile(self.output_path):
log.debug("erasing incomplete file assembly: %s", self.output_path)
os.unlink(self.output_path)
async def get_blob(self, blob_hash: str, length: typing.Optional[int] = None) -> 'BlobFile':
return self.blob_manager.get_blob(blob_hash, length)
+34 -19
View File
@@ -8,7 +8,7 @@ from collections import OrderedDict
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from lbrynet.blob import MAX_BLOB_SIZE
from lbrynet.blob.blob_info import BlobInfo
from lbrynet.blob.blob_file import BlobFile
from lbrynet.blob.blob_file import AbstractBlob, BlobFile
from lbrynet.cryptoutils import get_lbry_hash_obj
from lbrynet.error import InvalidStreamDescriptorError
@@ -47,6 +47,17 @@ def file_reader(file_path: str):
class StreamDescriptor:
__slots__ = [
'loop',
'blob_dir',
'stream_name',
'key',
'suggested_file_name',
'blobs',
'stream_hash',
'sd_hash'
]
def __init__(self, loop: asyncio.BaseEventLoop, blob_dir: str, stream_name: str, key: str,
suggested_file_name: str, blobs: typing.List[BlobInfo], stream_hash: typing.Optional[str] = None,
sd_hash: typing.Optional[str] = None):
@@ -108,29 +119,30 @@ class StreamDescriptor:
h.update(self.old_sort_json())
return h.hexdigest()
async def make_sd_blob(self, blob_file_obj: typing.Optional[BlobFile] = None,
old_sort: typing.Optional[bool] = False):
async def make_sd_blob(self, blob_file_obj: typing.Optional[AbstractBlob] = None,
old_sort: typing.Optional[bool] = False,
blob_completed_callback: typing.Optional[typing.Callable[['AbstractBlob'], None]] = None):
sd_hash = self.calculate_sd_hash() if not old_sort else self.calculate_old_sort_sd_hash()
if not old_sort:
sd_data = self.as_json()
else:
sd_data = self.old_sort_json()
sd_blob = blob_file_obj or BlobFile(self.loop, self.blob_dir, sd_hash, len(sd_data))
sd_blob = blob_file_obj or BlobFile(self.loop, sd_hash, len(sd_data), blob_completed_callback, self.blob_dir)
if blob_file_obj:
blob_file_obj.set_length(len(sd_data))
if not sd_blob.get_is_verified():
writer = sd_blob.open_for_writing()
writer = sd_blob.get_blob_writer()
writer.write(sd_data)
await sd_blob.verified.wait()
sd_blob.close()
return sd_blob
@classmethod
def _from_stream_descriptor_blob(cls, loop: asyncio.BaseEventLoop, blob_dir: str,
blob: BlobFile) -> 'StreamDescriptor':
assert os.path.isfile(blob.file_path)
with open(blob.file_path, 'rb') as f:
json_bytes = f.read()
blob: AbstractBlob) -> 'StreamDescriptor':
with blob.reader_context() as blob_reader:
json_bytes = blob_reader.read()
try:
decoded = json.loads(json_bytes.decode())
except json.JSONDecodeError:
@@ -160,8 +172,10 @@ class StreamDescriptor:
@classmethod
async def from_stream_descriptor_blob(cls, loop: asyncio.BaseEventLoop, blob_dir: str,
blob: BlobFile) -> 'StreamDescriptor':
return await loop.run_in_executor(None, lambda: cls._from_stream_descriptor_blob(loop, blob_dir, blob))
blob: AbstractBlob) -> 'StreamDescriptor':
if not blob.is_readable():
raise InvalidStreamDescriptorError(f"unreadable/missing blob: {blob.blob_hash}")
return await loop.run_in_executor(None, cls._from_stream_descriptor_blob, loop, blob_dir, blob)
@staticmethod
def get_blob_hashsum(b: typing.Dict):
@@ -194,11 +208,12 @@ class StreamDescriptor:
return h.hexdigest()
@classmethod
async def create_stream(cls, loop: asyncio.BaseEventLoop, blob_dir: str,
file_path: str, key: typing.Optional[bytes] = None,
iv_generator: typing.Optional[typing.Generator[bytes, None, None]] = None,
old_sort: bool = False) -> 'StreamDescriptor':
async def create_stream(
cls, loop: asyncio.BaseEventLoop, blob_dir: str, file_path: str, key: typing.Optional[bytes] = None,
iv_generator: typing.Optional[typing.Generator[bytes, None, None]] = None,
old_sort: bool = False,
blob_completed_callback: typing.Optional[typing.Callable[['AbstractBlob'],
asyncio.Task]] = None) -> 'StreamDescriptor':
blobs: typing.List[BlobInfo] = []
iv_generator = iv_generator or random_iv_generator()
@@ -207,7 +222,7 @@ class StreamDescriptor:
for blob_bytes in file_reader(file_path):
blob_num += 1
blob_info = await BlobFile.create_from_unencrypted(
loop, blob_dir, key, next(iv_generator), blob_bytes, blob_num
loop, blob_dir, key, next(iv_generator), blob_bytes, blob_num, blob_completed_callback
)
blobs.append(blob_info)
blobs.append(
@@ -216,7 +231,7 @@ class StreamDescriptor:
loop, blob_dir, os.path.basename(file_path), binascii.hexlify(key).decode(), os.path.basename(file_path),
blobs
)
sd_blob = await descriptor.make_sd_blob(old_sort=old_sort)
sd_blob = await descriptor.make_sd_blob(old_sort=old_sort, blob_completed_callback=blob_completed_callback)
descriptor.sd_hash = sd_blob.blob_hash
return descriptor
@@ -228,7 +243,7 @@ class StreamDescriptor:
return self.lower_bound_decrypted_length() + (AES.block_size // 8)
@classmethod
async def recover(cls, blob_dir: str, sd_blob: 'BlobFile', stream_hash: str, stream_name: str,
async def recover(cls, blob_dir: str, sd_blob: 'AbstractBlob', stream_hash: str, stream_name: str,
suggested_file_name: str, key: str,
blobs: typing.List['BlobInfo']) -> typing.Optional['StreamDescriptor']:
descriptor = cls(asyncio.get_event_loop(), blob_dir, stream_name, key, suggested_file_name,
+103 -79
View File
@@ -1,108 +1,132 @@
import os
import asyncio
import typing
import logging
import binascii
from lbrynet.error import DownloadSDTimeout
from lbrynet.utils import resolve_host
from lbrynet.stream.assembler import StreamAssembler
from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.blob_exchange.downloader import BlobDownloader
from lbrynet.dht.peer import KademliaPeer
if typing.TYPE_CHECKING:
from lbrynet.conf import Config
from lbrynet.dht.node import Node
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_file import BlobFile
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob.blob_file import AbstractBlob
from lbrynet.blob.blob_info import BlobInfo
log = logging.getLogger(__name__)
def drain_into(a: list, b: list):
while a:
b.append(a.pop())
class StreamDownloader(StreamAssembler):
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobFileManager', sd_hash: str,
output_dir: typing.Optional[str] = None, output_file_name: typing.Optional[str] = None):
super().__init__(loop, blob_manager, sd_hash, output_file_name)
class StreamDownloader:
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager', sd_hash: str,
descriptor: typing.Optional[StreamDescriptor] = None):
self.loop = loop
self.config = config
self.output_dir = output_dir or self.config.download_dir
self.output_file_name = output_file_name
self.blob_downloader: typing.Optional[BlobDownloader] = None
self.search_queue = asyncio.Queue(loop=loop)
self.peer_queue = asyncio.Queue(loop=loop)
self.accumulate_task: typing.Optional[asyncio.Task] = None
self.descriptor: typing.Optional[StreamDescriptor]
self.blob_manager = blob_manager
self.sd_hash = sd_hash
self.search_queue = asyncio.Queue(loop=loop) # blob hashes to feed into the iterative finder
self.peer_queue = asyncio.Queue(loop=loop) # new peers to try
self.blob_downloader = BlobDownloader(self.loop, self.config, self.blob_manager, self.peer_queue)
self.descriptor: typing.Optional[StreamDescriptor] = descriptor
self.node: typing.Optional['Node'] = None
self.assemble_task: typing.Optional[asyncio.Task] = None
self.accumulate_task: typing.Optional[asyncio.Task] = None
self.fixed_peers_handle: typing.Optional[asyncio.Handle] = None
self.fixed_peers_delay: typing.Optional[float] = None
self.added_fixed_peers = False
self.time_to_descriptor: typing.Optional[float] = None
self.time_to_first_bytes: typing.Optional[float] = None
async def setup(self): # start the peer accumulator and initialize the downloader
if self.blob_downloader:
raise Exception("downloader is already set up")
if self.node:
_, self.accumulate_task = self.node.accumulate_peers(self.search_queue, self.peer_queue)
self.blob_downloader = BlobDownloader(self.loop, self.config, self.blob_manager, self.peer_queue)
self.search_queue.put_nowait(self.sd_hash)
async def add_fixed_peers(self):
def _delayed_add_fixed_peers():
self.added_fixed_peers = True
self.peer_queue.put_nowait([
KademliaPeer(self.loop, address=address, tcp_port=port + 1)
for address, port in addresses
])
async def after_got_descriptor(self):
self.search_queue.put_nowait(self.descriptor.blobs[0].blob_hash)
log.info("added head blob to search")
async def after_finished(self):
log.info("downloaded stream %s -> %s", self.sd_hash, self.output_path)
await self.blob_manager.storage.change_file_status(self.descriptor.stream_hash, 'finished')
self.blob_downloader.close()
def stop(self):
if self.accumulate_task:
self.accumulate_task.cancel()
self.accumulate_task = None
if self.assemble_task:
self.assemble_task.cancel()
self.assemble_task = None
if self.fixed_peers_handle:
self.fixed_peers_handle.cancel()
self.fixed_peers_handle = None
self.blob_downloader = None
if self.stream_handle:
if not self.stream_handle.closed:
self.stream_handle.close()
self.stream_handle = None
if not self.stream_finished_event.is_set() and self.wrote_bytes_event.is_set() and \
self.output_path and os.path.isfile(self.output_path):
os.remove(self.output_path)
async def get_blob(self, blob_hash: str, length: typing.Optional[int] = None) -> 'BlobFile':
return await self.blob_downloader.download_blob(blob_hash, length)
def add_fixed_peers(self):
async def _add_fixed_peers():
addresses = [
(await resolve_host(url, port + 1, proto='tcp'), port)
for url, port in self.config.reflector_servers
]
def _delayed_add_fixed_peers():
self.added_fixed_peers = True
self.peer_queue.put_nowait([
KademliaPeer(self.loop, address=address, tcp_port=port + 1)
for address, port in addresses
])
self.fixed_peers_handle = self.loop.call_later(self.fixed_peers_delay, _delayed_add_fixed_peers)
if not self.config.reflector_servers:
return
addresses = [
(await resolve_host(url, port + 1, proto='tcp'), port)
for url, port in self.config.reflector_servers
]
if 'dht' in self.config.components_to_skip or not self.node or not \
len(self.node.protocol.routing_table.get_peers()):
self.fixed_peers_delay = 0.0
else:
self.fixed_peers_delay = self.config.fixed_peer_delay
self.loop.create_task(_add_fixed_peers())
def download(self, node: typing.Optional['Node'] = None):
self.node = node
self.assemble_task = self.loop.create_task(self.assemble_decrypted_stream(self.config.download_dir))
self.add_fixed_peers()
self.fixed_peers_handle = self.loop.call_later(self.fixed_peers_delay, _delayed_add_fixed_peers)
async def load_descriptor(self, connection_id: int = 0):
# download or get the sd blob
sd_blob = self.blob_manager.get_blob(self.sd_hash)
if not sd_blob.get_is_verified():
try:
now = self.loop.time()
sd_blob = await asyncio.wait_for(
self.blob_downloader.download_blob(self.sd_hash, connection_id),
self.config.blob_download_timeout, loop=self.loop
)
log.info("downloaded sd blob %s", self.sd_hash)
self.time_to_descriptor = self.loop.time() - now
except asyncio.TimeoutError:
raise DownloadSDTimeout(self.sd_hash)
# parse the descriptor
self.descriptor = await StreamDescriptor.from_stream_descriptor_blob(
self.loop, self.blob_manager.blob_dir, sd_blob
)
log.info("loaded stream manifest %s", self.sd_hash)
async def start(self, node: typing.Optional['Node'] = None, connection_id: int = 0):
# set up peer accumulation
if node:
self.node = node
_, self.accumulate_task = self.node.accumulate_peers(self.search_queue, self.peer_queue)
await self.add_fixed_peers()
# start searching for peers for the sd hash
self.search_queue.put_nowait(self.sd_hash)
log.info("searching for peers for stream %s", self.sd_hash)
if not self.descriptor:
await self.load_descriptor(connection_id)
# add the head blob to the peer search
self.search_queue.put_nowait(self.descriptor.blobs[0].blob_hash)
log.info("added head blob to peer search for stream %s", self.sd_hash)
if not await self.blob_manager.storage.stream_exists(self.sd_hash):
await self.blob_manager.storage.store_stream(
self.blob_manager.get_blob(self.sd_hash, length=self.descriptor.length), self.descriptor
)
async def download_stream_blob(self, blob_info: 'BlobInfo', connection_id: int = 0) -> 'AbstractBlob':
if not filter(lambda blob: blob.blob_hash == blob_info.blob_hash, self.descriptor.blobs[:-1]):
raise ValueError(f"blob {blob_info.blob_hash} is not part of stream with sd hash {self.sd_hash}")
blob = await self.blob_downloader.download_blob(blob_info.blob_hash, blob_info.length, connection_id)
return blob
def decrypt_blob(self, blob_info: 'BlobInfo', blob: 'AbstractBlob') -> bytes:
return blob.decrypt(
binascii.unhexlify(self.descriptor.key.encode()), binascii.unhexlify(blob_info.iv.encode())
)
async def read_blob(self, blob_info: 'BlobInfo', connection_id: int = 0) -> bytes:
start = None
if self.time_to_first_bytes is None:
start = self.loop.time()
blob = await self.download_stream_blob(blob_info, connection_id)
decrypted = self.decrypt_blob(blob_info, blob)
if start:
self.time_to_first_bytes = self.loop.time() - start
return decrypted
def stop(self):
if self.accumulate_task:
self.accumulate_task.cancel()
self.accumulate_task = None
if self.fixed_peers_handle:
self.fixed_peers_handle.cancel()
self.fixed_peers_handle = None
self.blob_downloader.close()
+317 -50
View File
@@ -3,56 +3,124 @@ import asyncio
import typing
import logging
import binascii
from aiohttp.web import Request, StreamResponse
from lbrynet.utils import generate_id
from lbrynet.error import DownloadSDTimeout
from lbrynet.schema.mime_types import guess_media_type
from lbrynet.stream.downloader import StreamDownloader
from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.stream.reflector.client import StreamReflectorClient
from lbrynet.extras.daemon.storage import StoredStreamClaim
if typing.TYPE_CHECKING:
from lbrynet.conf import Config
from lbrynet.schema.claim import Claim
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob.blob_info import BlobInfo
from lbrynet.dht.node import Node
from lbrynet.extras.daemon.analytics import AnalyticsManager
from lbrynet.wallet.transaction import Transaction
log = logging.getLogger(__name__)
def _get_next_available_file_name(download_directory: str, file_name: str) -> str:
base_name, ext = os.path.splitext(os.path.basename(file_name))
i = 0
while os.path.isfile(os.path.join(download_directory, file_name)):
i += 1
file_name = "%s_%i%s" % (base_name, i, ext)
return file_name
async def get_next_available_file_name(loop: asyncio.BaseEventLoop, download_directory: str, file_name: str) -> str:
return await loop.run_in_executor(None, _get_next_available_file_name, download_directory, file_name)
class ManagedStream:
STATUS_RUNNING = "running"
STATUS_STOPPED = "stopped"
STATUS_FINISHED = "finished"
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobFileManager', rowid: int,
descriptor: 'StreamDescriptor', download_directory: str, file_name: typing.Optional[str],
downloader: typing.Optional[StreamDownloader] = None,
__slots__ = [
'loop',
'config',
'blob_manager',
'sd_hash',
'download_directory',
'_file_name',
'_status',
'stream_claim_info',
'download_id',
'rowid',
'written_bytes',
'content_fee',
'downloader',
'analytics_manager',
'fully_reflected',
'file_output_task',
'delayed_stop_task',
'streaming_responses',
'streaming',
'_running',
'saving',
'finished_writing',
'started_writing',
]
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
sd_hash: str, download_directory: typing.Optional[str] = None, file_name: typing.Optional[str] = None,
status: typing.Optional[str] = STATUS_STOPPED, claim: typing.Optional[StoredStreamClaim] = None,
download_id: typing.Optional[str] = None):
download_id: typing.Optional[str] = None, rowid: typing.Optional[int] = None,
descriptor: typing.Optional[StreamDescriptor] = None,
content_fee: typing.Optional['Transaction'] = None,
analytics_manager: typing.Optional['AnalyticsManager'] = None):
self.loop = loop
self.config = config
self.blob_manager = blob_manager
self.rowid = rowid
self.sd_hash = sd_hash
self.download_directory = download_directory
self._file_name = file_name
self.descriptor = descriptor
self.downloader = downloader
self.stream_hash = descriptor.stream_hash
self.stream_claim_info = claim
self._status = status
self.stream_claim_info = claim
self.download_id = download_id or binascii.hexlify(generate_id()).decode()
self.rowid = rowid
self.written_bytes = 0
self.content_fee = content_fee
self.downloader = StreamDownloader(self.loop, self.config, self.blob_manager, sd_hash, descriptor)
self.analytics_manager = analytics_manager
self.fully_reflected = asyncio.Event(loop=self.loop)
self.tx = None
self.download_id = download_id or binascii.hexlify(generate_id()).decode()
self.file_output_task: typing.Optional[asyncio.Task] = None
self.delayed_stop_task: typing.Optional[asyncio.Task] = None
self.streaming_responses: typing.List[typing.Tuple[Request, StreamResponse]] = []
self.streaming = asyncio.Event(loop=self.loop)
self._running = asyncio.Event(loop=self.loop)
self.saving = asyncio.Event(loop=self.loop)
self.finished_writing = asyncio.Event(loop=self.loop)
self.started_writing = asyncio.Event(loop=self.loop)
@property
def descriptor(self) -> StreamDescriptor:
return self.downloader.descriptor
@property
def stream_hash(self) -> str:
return self.descriptor.stream_hash
@property
def file_name(self) -> typing.Optional[str]:
return self.downloader.output_file_name if self.downloader else self._file_name
return self._file_name or (self.descriptor.suggested_file_name if self.descriptor else None)
@property
def status(self) -> str:
return self._status
def update_status(self, status: str):
async def update_status(self, status: str):
assert status in [self.STATUS_RUNNING, self.STATUS_STOPPED, self.STATUS_FINISHED]
self._status = status
await self.blob_manager.storage.change_file_status(self.stream_hash, status)
@property
def finished(self) -> bool:
@@ -95,7 +163,7 @@ class ManagedStream:
return None if not self.stream_claim_info else self.stream_claim_info.claim_name
@property
def metadata(self) ->typing.Optional[typing.Dict]:
def metadata(self) -> typing.Optional[typing.Dict]:
return None if not self.stream_claim_info else self.stream_claim_info.claim.stream.to_dict()
@property
@@ -105,52 +173,57 @@ class ManagedStream:
@property
def blobs_completed(self) -> int:
return sum([1 if self.blob_manager.get_blob(b.blob_hash).get_is_verified() else 0
return sum([1 if self.blob_manager.is_blob_verified(b.blob_hash) else 0
for b in self.descriptor.blobs[:-1]])
@property
def blobs_in_stream(self) -> int:
return len(self.descriptor.blobs) - 1
@property
def sd_hash(self):
return self.descriptor.sd_hash
@property
def blobs_remaining(self) -> int:
return self.blobs_in_stream - self.blobs_completed
@property
def full_path(self) -> typing.Optional[str]:
return os.path.join(self.download_directory, os.path.basename(self.file_name)) if self.file_name else None
return os.path.join(self.download_directory, os.path.basename(self.file_name)) \
if self.file_name and self.download_directory else None
@property
def output_file_exists(self):
return os.path.isfile(self.full_path) if self.full_path else False
def as_dict(self) -> typing.Dict:
full_path = self.full_path if self.output_file_exists else None
mime_type = guess_media_type(os.path.basename(self.descriptor.suggested_file_name))[0]
@property
def mime_type(self):
return guess_media_type(os.path.basename(self.descriptor.suggested_file_name))[0]
if self.downloader and self.downloader.written_bytes:
written_bytes = self.downloader.written_bytes
elif full_path:
written_bytes = os.stat(full_path).st_size
def as_dict(self) -> typing.Dict:
full_path = self.full_path
file_name = self.file_name
download_directory = self.download_directory
if self.full_path and self.output_file_exists:
if self.written_bytes:
written_bytes = self.written_bytes
else:
written_bytes = os.stat(self.full_path).st_size
else:
full_path = None
file_name = None
download_directory = None
written_bytes = None
return {
'completed': self.finished,
'file_name': self.file_name,
'download_directory': self.download_directory,
'completed': (self.output_file_exists and self.status in ('stopped', 'finished')) or all(
self.blob_manager.is_blob_verified(b.blob_hash) for b in self.descriptor.blobs[:-1]),
'file_name': file_name,
'download_directory': download_directory,
'points_paid': 0.0,
'tx': self.tx,
'stopped': not self.running,
'stream_hash': self.stream_hash,
'stream_name': self.descriptor.stream_name,
'suggested_file_name': self.descriptor.suggested_file_name,
'sd_hash': self.descriptor.sd_hash,
'download_path': full_path,
'mime_type': mime_type,
'mime_type': self.mime_type,
'key': self.descriptor.key,
'total_bytes_lower_bound': self.descriptor.lower_bound_decrypted_length(),
'total_bytes': self.descriptor.upper_bound_decrypted_length(),
@@ -167,36 +240,177 @@ class ManagedStream:
'protobuf': self.metadata_protobuf,
'channel_claim_id': self.channel_claim_id,
'channel_name': self.channel_name,
'claim_name': self.claim_name
'claim_name': self.claim_name,
'content_fee': self.content_fee
}
@classmethod
async def create(cls, loop: asyncio.BaseEventLoop, blob_manager: 'BlobFileManager',
async def create(cls, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
file_path: str, key: typing.Optional[bytes] = None,
iv_generator: typing.Optional[typing.Generator[bytes, None, None]] = None) -> 'ManagedStream':
descriptor = await StreamDescriptor.create_stream(
loop, blob_manager.blob_dir, file_path, key=key, iv_generator=iv_generator
loop, blob_manager.blob_dir, file_path, key=key, iv_generator=iv_generator,
blob_completed_callback=blob_manager.blob_completed
)
sd_blob = blob_manager.get_blob(descriptor.sd_hash)
await blob_manager.storage.store_stream(
blob_manager.get_blob(descriptor.sd_hash), descriptor
)
await blob_manager.blob_completed(sd_blob)
for blob in descriptor.blobs[:-1]:
await blob_manager.blob_completed(blob_manager.get_blob(blob.blob_hash, blob.length))
row_id = await blob_manager.storage.save_published_file(descriptor.stream_hash, os.path.basename(file_path),
os.path.dirname(file_path), 0)
return cls(loop, blob_manager, row_id, descriptor, os.path.dirname(file_path), os.path.basename(file_path),
status=cls.STATUS_FINISHED)
return cls(loop, config, blob_manager, descriptor.sd_hash, os.path.dirname(file_path),
os.path.basename(file_path), status=cls.STATUS_FINISHED, rowid=row_id, descriptor=descriptor)
def start_download(self, node: typing.Optional['Node']):
self.downloader.download(node)
self.update_status(self.STATUS_RUNNING)
async def start(self, node: typing.Optional['Node'] = None, timeout: typing.Optional[float] = None,
save_now: bool = False):
timeout = timeout or self.config.download_timeout
if self._running.is_set():
return
log.info("start downloader for stream (sd hash: %s)", self.sd_hash)
self._running.set()
try:
await asyncio.wait_for(self.downloader.start(node), timeout, loop=self.loop)
except asyncio.TimeoutError:
self._running.clear()
raise DownloadSDTimeout(self.sd_hash)
def stop_download(self):
if self.downloader:
self.downloader.stop()
self.downloader = None
if self.delayed_stop_task and not self.delayed_stop_task.done():
self.delayed_stop_task.cancel()
self.delayed_stop_task = self.loop.create_task(self._delayed_stop())
if not await self.blob_manager.storage.file_exists(self.sd_hash):
if save_now:
file_name, download_dir = self._file_name, self.download_directory
else:
file_name, download_dir = None, None
self.rowid = await self.blob_manager.storage.save_downloaded_file(
self.stream_hash, file_name, download_dir, 0.0
)
if self.status != self.STATUS_RUNNING:
await self.update_status(self.STATUS_RUNNING)
async def stop(self, finished: bool = False):
"""
Stop any running save/stream tasks as well as the downloader and update the status in the database
"""
self.stop_tasks()
if (finished and self.status != self.STATUS_FINISHED) or self.status == self.STATUS_RUNNING:
await self.update_status(self.STATUS_FINISHED if finished else self.STATUS_STOPPED)
async def _aiter_read_stream(self, start_blob_num: typing.Optional[int] = 0, connection_id: int = 0)\
-> typing.AsyncIterator[typing.Tuple['BlobInfo', bytes]]:
if start_blob_num >= len(self.descriptor.blobs[:-1]):
raise IndexError(start_blob_num)
for i, blob_info in enumerate(self.descriptor.blobs[start_blob_num:-1]):
assert i + start_blob_num == blob_info.blob_num
decrypted = await self.downloader.read_blob(blob_info, connection_id)
yield (blob_info, decrypted)
async def stream_file(self, request: Request, node: typing.Optional['Node'] = None) -> StreamResponse:
log.info("stream file to browser for lbry://%s#%s (sd hash %s...)", self.claim_name, self.claim_id,
self.sd_hash[:6])
await self.start(node)
headers, size, skip_blobs = self._prepare_range_response_headers(request.headers.get('range', 'bytes=0-'))
response = StreamResponse(
status=206,
headers=headers
)
await response.prepare(request)
self.streaming_responses.append((request, response))
self.streaming.set()
try:
wrote = 0
async for blob_info, decrypted in self._aiter_read_stream(skip_blobs, connection_id=2):
if (blob_info.blob_num == len(self.descriptor.blobs) - 2) or (len(decrypted) + wrote >= size):
decrypted += (b'\x00' * (size - len(decrypted) - wrote - (skip_blobs * 2097151)))
await response.write_eof(decrypted)
else:
await response.write(decrypted)
wrote += len(decrypted)
log.info("sent browser %sblob %i/%i", "(final) " if response._eof_sent else "",
blob_info.blob_num + 1, len(self.descriptor.blobs) - 1)
if response._eof_sent:
break
return response
finally:
response.force_close()
if (request, response) in self.streaming_responses:
self.streaming_responses.remove((request, response))
if not self.streaming_responses:
self.streaming.clear()
@staticmethod
def _write_decrypted_blob(handle: typing.IO, data: bytes):
handle.write(data)
handle.flush()
async def _save_file(self, output_path: str):
log.info("save file for lbry://%s#%s (sd hash %s...) -> %s", self.claim_name, self.claim_id, self.sd_hash[:6],
output_path)
self.saving.set()
self.finished_writing.clear()
self.started_writing.clear()
try:
with open(output_path, 'wb') as file_write_handle:
async for blob_info, decrypted in self._aiter_read_stream(connection_id=1):
log.info("write blob %i/%i", blob_info.blob_num + 1, len(self.descriptor.blobs) - 1)
await self.loop.run_in_executor(None, self._write_decrypted_blob, file_write_handle, decrypted)
self.written_bytes += len(decrypted)
if not self.started_writing.is_set():
self.started_writing.set()
await self.update_status(ManagedStream.STATUS_FINISHED)
if self.analytics_manager:
self.loop.create_task(self.analytics_manager.send_download_finished(
self.download_id, self.claim_name, self.sd_hash
))
self.finished_writing.set()
log.info("finished saving file for lbry://%s#%s (sd hash %s...) -> %s", self.claim_name, self.claim_id,
self.sd_hash[:6], self.full_path)
await self.blob_manager.storage.set_saved_file(self.stream_hash)
except Exception as err:
if os.path.isfile(output_path):
log.warning("removing incomplete download %s for %s", output_path, self.sd_hash)
os.remove(output_path)
if not isinstance(err, asyncio.CancelledError):
log.exception("unexpected error encountered writing file for stream %s", self.sd_hash)
raise err
finally:
self.saving.clear()
async def save_file(self, file_name: typing.Optional[str] = None, download_directory: typing.Optional[str] = None,
node: typing.Optional['Node'] = None):
await self.start(node)
if self.file_output_task and not self.file_output_task.done(): # cancel an already running save task
self.file_output_task.cancel()
self.download_directory = download_directory or self.download_directory or self.config.download_dir
if not self.download_directory:
raise ValueError("no directory to download to")
if not (file_name or self._file_name or self.descriptor.suggested_file_name):
raise ValueError("no file name to download to")
if not os.path.isdir(self.download_directory):
log.warning("download directory '%s' does not exist, attempting to make it", self.download_directory)
os.mkdir(self.download_directory)
self._file_name = await get_next_available_file_name(
self.loop, self.download_directory,
file_name or self.descriptor.suggested_file_name
)
await self.blob_manager.storage.change_file_download_dir_and_file_name(
self.stream_hash, self.download_directory, self.file_name
)
await self.update_status(ManagedStream.STATUS_RUNNING)
self.written_bytes = 0
self.file_output_task = self.loop.create_task(self._save_file(self.full_path))
await self.started_writing.wait()
def stop_tasks(self):
if self.file_output_task and not self.file_output_task.done():
self.file_output_task.cancel()
self.file_output_task = None
while self.streaming_responses:
req, response = self.streaming_responses.pop()
response.force_close()
req.transport.close()
self.downloader.stop()
self._running.clear()
async def upload_to_reflector(self, host: str, port: int) -> typing.List[str]:
sent = []
@@ -212,7 +426,9 @@ class ManagedStream:
self.fully_reflected.set()
await self.blob_manager.storage.update_reflected_stream(self.sd_hash, f"{host}:{port}")
return []
we_have = [blob_hash for blob_hash in needed if blob_hash in self.blob_manager.completed_blob_hashes]
we_have = [
blob_hash for blob_hash in needed if blob_hash in self.blob_manager.completed_blob_hashes
]
for blob_hash in we_have:
await protocol.send_blob(blob_hash)
sent.append(blob_hash)
@@ -235,3 +451,54 @@ class ManagedStream:
binascii.hexlify(claim.to_bytes()).decode(), claim.signing_channel_id, claim_info['address'],
claim_info['claim_sequence'], claim_info.get('channel_name')
)
async def update_content_claim(self, claim_info: typing.Optional[typing.Dict] = None):
if not claim_info:
claim_info = await self.blob_manager.storage.get_content_claim(self.stream_hash)
self.set_claim(claim_info, claim_info['value'])
async def _delayed_stop(self):
stalled_count = 0
while self._running.is_set():
if self.saving.is_set() or self.streaming.is_set():
stalled_count = 0
else:
stalled_count += 1
if stalled_count > 1:
log.info("stopping inactive download for lbry://%s#%s (%s...)", self.claim_name, self.claim_id,
self.sd_hash[:6])
await self.stop()
return
await asyncio.sleep(1, loop=self.loop)
def _prepare_range_response_headers(self, get_range: str) -> typing.Tuple[typing.Dict[str, str], int, int]:
if '=' in get_range:
get_range = get_range.split('=')[1]
start, end = get_range.split('-')
size = 0
for blob in self.descriptor.blobs[:-1]:
size += blob.length - 1
if self.stream_claim_info and self.stream_claim_info.claim.stream.source.size:
size_from_claim = int(self.stream_claim_info.claim.stream.source.size)
if not size_from_claim <= size <= size_from_claim + 16:
raise ValueError("claim contains implausible stream size")
log.debug("using stream size from claim")
size = size_from_claim
elif self.stream_claim_info:
log.debug("estimating stream size")
start = int(start)
end = int(end) if end else size - 1
skip_blobs = start // 2097150
skip = skip_blobs * 2097151
start = skip
final_size = end - start + 1
headers = {
'Accept-Ranges': 'bytes',
'Content-Range': f'bytes {start}-{end}/{size}',
'Content-Length': str(final_size),
'Content-Type': self.mime_type
}
return headers, size, skip_blobs
+5 -5
View File
@@ -4,7 +4,7 @@ import logging
import typing
if typing.TYPE_CHECKING:
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.stream.descriptor import StreamDescriptor
REFLECTOR_V1 = 0
@@ -14,7 +14,7 @@ log = logging.getLogger(__name__)
class StreamReflectorClient(asyncio.Protocol):
def __init__(self, blob_manager: 'BlobFileManager', descriptor: 'StreamDescriptor'):
def __init__(self, blob_manager: 'BlobManager', descriptor: 'StreamDescriptor'):
self.loop = asyncio.get_event_loop()
self.transport: asyncio.StreamWriter = None
self.blob_manager = blob_manager
@@ -64,7 +64,7 @@ class StreamReflectorClient(asyncio.Protocol):
async def send_descriptor(self) -> typing.Tuple[bool, typing.List[str]]: # returns a list of needed blob hashes
sd_blob = self.blob_manager.get_blob(self.descriptor.sd_hash)
assert sd_blob.get_is_verified(), "need to have a sd blob to send at this point"
assert self.blob_manager.is_blob_verified(self.descriptor.sd_hash), "need to have sd blob to send at this point"
response = await self.send_request({
'sd_blob_hash': sd_blob.blob_hash,
'sd_blob_size': sd_blob.length
@@ -80,7 +80,7 @@ class StreamReflectorClient(asyncio.Protocol):
sent_sd = True
if not needed:
for blob in self.descriptor.blobs[:-1]:
if self.blob_manager.get_blob(blob.blob_hash, blob.length).get_is_verified():
if self.blob_manager.is_blob_verified(blob.blob_hash, blob.length):
needed.append(blob.blob_hash)
log.info("Sent reflector descriptor %s", sd_blob.blob_hash[:8])
self.reflected_blobs.append(sd_blob.blob_hash)
@@ -91,8 +91,8 @@ class StreamReflectorClient(asyncio.Protocol):
return sent_sd, needed
async def send_blob(self, blob_hash: str):
assert self.blob_manager.is_blob_verified(blob_hash), "need to have a blob to send at this point"
blob = self.blob_manager.get_blob(blob_hash)
assert blob.get_is_verified(), "need to have a blob to send at this point"
response = await self.send_request({
'blob_hash': blob.blob_hash,
'blob_size': blob.length
+7 -7
View File
@@ -7,7 +7,7 @@ from lbrynet.stream.descriptor import StreamDescriptor
if typing.TYPE_CHECKING:
from lbrynet.blob.blob_file import BlobFile
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob.writer import HashBlobWriter
@@ -15,7 +15,7 @@ log = logging.getLogger(__name__)
class ReflectorServerProtocol(asyncio.Protocol):
def __init__(self, blob_manager: 'BlobFileManager'):
def __init__(self, blob_manager: 'BlobManager'):
self.loop = asyncio.get_event_loop()
self.blob_manager = blob_manager
self.server_task: asyncio.Task = None
@@ -63,11 +63,11 @@ class ReflectorServerProtocol(asyncio.Protocol):
return
self.sd_blob = self.blob_manager.get_blob(request['sd_blob_hash'], request['sd_blob_size'])
if not self.sd_blob.get_is_verified():
self.writer = self.sd_blob.open_for_writing()
self.writer = self.sd_blob.get_blob_writer(self.transport.get_extra_info('peername'))
self.incoming.set()
self.send_response({"send_sd_blob": True})
try:
await asyncio.wait_for(self.sd_blob.finished_writing.wait(), 30, loop=self.loop)
await asyncio.wait_for(self.sd_blob.verified.wait(), 30, loop=self.loop)
self.descriptor = await StreamDescriptor.from_stream_descriptor_blob(
self.loop, self.blob_manager.blob_dir, self.sd_blob
)
@@ -102,11 +102,11 @@ class ReflectorServerProtocol(asyncio.Protocol):
return
blob = self.blob_manager.get_blob(request['blob_hash'], request['blob_size'])
if not blob.get_is_verified():
self.writer = blob.open_for_writing()
self.writer = blob.get_blob_writer(self.transport.get_extra_info('peername'))
self.incoming.set()
self.send_response({"send_blob": True})
try:
await asyncio.wait_for(blob.finished_writing.wait(), 30, loop=self.loop)
await asyncio.wait_for(blob.verified.wait(), 30, loop=self.loop)
self.send_response({"received_blob": True})
except asyncio.TimeoutError:
self.send_response({"received_blob": False})
@@ -121,7 +121,7 @@ class ReflectorServerProtocol(asyncio.Protocol):
class ReflectorServer:
def __init__(self, blob_manager: 'BlobFileManager'):
def __init__(self, blob_manager: 'BlobManager'):
self.loop = asyncio.get_event_loop()
self.blob_manager = blob_manager
self.server_task: asyncio.Task = None
+225 -302
View File
@@ -5,22 +5,23 @@ import binascii
import logging
import random
from decimal import Decimal
from lbrynet.error import ResolveError, InvalidStreamDescriptorError, KeyFeeAboveMaxAllowed, InsufficientFundsError, \
DownloadDataTimeout, DownloadSDTimeout
from lbrynet.utils import generate_id
from aiohttp.web import Request
from lbrynet.error import ResolveError, InvalidStreamDescriptorError, KeyFeeAboveMaxAllowed, InsufficientFundsError
from lbrynet.error import ResolveTimeout, DownloadDataTimeout
from lbrynet.utils import cache_concurrent
from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.stream.downloader import StreamDownloader
from lbrynet.stream.managed_stream import ManagedStream
from lbrynet.schema.claim import Claim
from lbrynet.schema.uri import parse_lbry_uri
from lbrynet.extras.daemon.storage import lbc_to_dewies
if typing.TYPE_CHECKING:
from lbrynet.conf import Config
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.dht.node import Node
from lbrynet.extras.daemon.analytics import AnalyticsManager
from lbrynet.extras.daemon.storage import SQLiteStorage, StoredStreamClaim
from lbrynet.wallet import LbryWalletManager
from lbrynet.wallet.transaction import Transaction
from lbrynet.extras.daemon.exchange_rate_manager import ExchangeRateManager
log = logging.getLogger(__name__)
@@ -54,8 +55,14 @@ comparison_operators = {
}
def path_or_none(p) -> typing.Optional[str]:
if not p:
return
return binascii.unhexlify(p).decode()
class StreamManager:
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobFileManager',
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
wallet: 'LbryWalletManager', storage: 'SQLiteStorage', node: typing.Optional['Node'],
analytics_manager: typing.Optional['AnalyticsManager'] = None):
self.loop = loop
@@ -65,79 +72,23 @@ class StreamManager:
self.storage = storage
self.node = node
self.analytics_manager = analytics_manager
self.streams: typing.Set[ManagedStream] = set()
self.starting_streams: typing.Dict[str, asyncio.Future] = {}
self.resume_downloading_task: asyncio.Task = None
self.re_reflect_task: asyncio.Task = None
self.streams: typing.Dict[str, ManagedStream] = {}
self.resume_saving_task: typing.Optional[asyncio.Task] = None
self.re_reflect_task: typing.Optional[asyncio.Task] = None
self.update_stream_finished_futs: typing.List[asyncio.Future] = []
self.running_reflector_uploads: typing.List[asyncio.Task] = []
self.started = asyncio.Event(loop=self.loop)
async def _update_content_claim(self, stream: ManagedStream):
claim_info = await self.storage.get_content_claim(stream.stream_hash)
stream.set_claim(claim_info, claim_info['value'])
async def start_stream(self, stream: ManagedStream) -> bool:
"""
Resume or rebuild a partial or completed stream
"""
if not stream.running and not stream.output_file_exists:
if stream.downloader:
stream.downloader.stop()
stream.downloader = None
# the directory is gone, can happen when the folder that contains a published file is deleted
# reset the download directory to the default and update the file name
if not os.path.isdir(stream.download_directory):
stream.download_directory = self.config.download_dir
stream.downloader = self.make_downloader(
stream.sd_hash, stream.download_directory, stream.descriptor.suggested_file_name
)
if stream.status != ManagedStream.STATUS_FINISHED:
await self.storage.change_file_status(stream.stream_hash, 'running')
stream.update_status('running')
stream.start_download(self.node)
try:
await asyncio.wait_for(self.loop.create_task(stream.downloader.wrote_bytes_event.wait()),
self.config.download_timeout)
except asyncio.TimeoutError:
await self.stop_stream(stream)
if stream in self.streams:
self.streams.remove(stream)
return False
file_name = os.path.basename(stream.downloader.output_path)
output_dir = os.path.dirname(stream.downloader.output_path)
await self.storage.change_file_download_dir_and_file_name(
stream.stream_hash, output_dir, file_name
)
stream._file_name = file_name
stream.download_directory = output_dir
self.wait_for_stream_finished(stream)
return True
return True
async def stop_stream(self, stream: ManagedStream):
stream.stop_download()
if not stream.finished and stream.output_file_exists:
try:
os.remove(stream.full_path)
except OSError as err:
log.warning("Failed to delete partial download %s from downloads directory: %s", stream.full_path,
str(err))
if stream.running:
stream.update_status(ManagedStream.STATUS_STOPPED)
await self.storage.change_file_status(stream.stream_hash, ManagedStream.STATUS_STOPPED)
def make_downloader(self, sd_hash: str, download_directory: str, file_name: str):
return StreamDownloader(
self.loop, self.config, self.blob_manager, sd_hash, download_directory, file_name
)
self.streams.setdefault(stream.sd_hash, stream).set_claim(claim_info, claim_info['value'])
async def recover_streams(self, file_infos: typing.List[typing.Dict]):
to_restore = []
async def recover_stream(sd_hash: str, stream_hash: str, stream_name: str,
suggested_file_name: str, key: str) -> typing.Optional[StreamDescriptor]:
suggested_file_name: str, key: str,
content_fee: typing.Optional['Transaction']) -> typing.Optional[StreamDescriptor]:
sd_blob = self.blob_manager.get_blob(sd_hash)
blobs = await self.storage.get_blobs_for_stream(stream_hash)
descriptor = await StreamDescriptor.recover(
@@ -145,116 +96,126 @@ class StreamManager:
)
if not descriptor:
return
to_restore.append((descriptor, sd_blob))
to_restore.append((descriptor, sd_blob, content_fee))
await asyncio.gather(*[
recover_stream(
file_info['sd_hash'], file_info['stream_hash'], binascii.unhexlify(file_info['stream_name']).decode(),
binascii.unhexlify(file_info['suggested_file_name']).decode(), file_info['key']
binascii.unhexlify(file_info['suggested_file_name']).decode(), file_info['key'],
file_info['content_fee']
) for file_info in file_infos
])
if to_restore:
await self.storage.recover_streams(to_restore, self.config.download_dir)
log.info("Recovered %i/%i attempted streams", len(to_restore), len(file_infos))
async def add_stream(self, rowid: int, sd_hash: str, file_name: str, download_directory: str, status: str,
claim: typing.Optional['StoredStreamClaim']):
sd_blob = self.blob_manager.get_blob(sd_hash)
if not sd_blob.get_is_verified():
return
# if self.blob_manager._save_blobs:
# log.info("Recovered %i/%i attempted streams", len(to_restore), len(file_infos))
async def add_stream(self, rowid: int, sd_hash: str, file_name: typing.Optional[str],
download_directory: typing.Optional[str], status: str,
claim: typing.Optional['StoredStreamClaim'], content_fee: typing.Optional['Transaction']):
try:
descriptor = await self.blob_manager.get_stream_descriptor(sd_blob.blob_hash)
descriptor = await self.blob_manager.get_stream_descriptor(sd_hash)
except InvalidStreamDescriptorError as err:
log.warning("Failed to start stream for sd %s - %s", sd_hash, str(err))
return
if status == ManagedStream.STATUS_RUNNING:
downloader = self.make_downloader(descriptor.sd_hash, download_directory, file_name)
else:
downloader = None
stream = ManagedStream(
self.loop, self.blob_manager, rowid, descriptor, download_directory, file_name, downloader, status, claim
self.loop, self.config, self.blob_manager, descriptor.sd_hash, download_directory, file_name, status,
claim, content_fee=content_fee, rowid=rowid, descriptor=descriptor,
analytics_manager=self.analytics_manager
)
self.streams.add(stream)
self.streams[sd_hash] = stream
self.storage.content_claim_callbacks[stream.stream_hash] = lambda: self._update_content_claim(stream)
async def load_streams_from_database(self):
async def load_and_resume_streams_from_database(self):
to_recover = []
for file_info in await self.storage.get_all_lbry_files():
if not self.blob_manager.get_blob(file_info['sd_hash']).get_is_verified():
to_recover.append(file_info)
to_start = []
await self.storage.update_manually_removed_files_since_last_run()
for file_info in await self.storage.get_all_lbry_files():
# if the sd blob is not verified, try to reconstruct it from the database
# this could either be because the blob files were deleted manually or save_blobs was not true when
# the stream was downloaded
if not self.blob_manager.is_blob_verified(file_info['sd_hash']):
to_recover.append(file_info)
to_start.append(file_info)
if to_recover:
log.info("Attempting to recover %i streams", len(to_recover))
await self.recover_streams(to_recover)
to_start = []
for file_info in await self.storage.get_all_lbry_files():
if self.blob_manager.get_blob(file_info['sd_hash']).get_is_verified():
to_start.append(file_info)
log.info("Initializing %i files", len(to_start))
await asyncio.gather(*[
self.add_stream(
file_info['rowid'], file_info['sd_hash'], binascii.unhexlify(file_info['file_name']).decode(),
binascii.unhexlify(file_info['download_directory']).decode(), file_info['status'],
file_info['claim']
) for file_info in to_start
])
to_resume_saving = []
add_stream_tasks = []
for file_info in to_start:
file_name = path_or_none(file_info['file_name'])
download_directory = path_or_none(file_info['download_directory'])
if file_name and download_directory and not file_info['saved_file'] and file_info['status'] == 'running':
to_resume_saving.append((file_name, download_directory, file_info['sd_hash']))
add_stream_tasks.append(self.loop.create_task(self.add_stream(
file_info['rowid'], file_info['sd_hash'], file_name,
download_directory, file_info['status'],
file_info['claim'], file_info['content_fee']
)))
if add_stream_tasks:
await asyncio.gather(*add_stream_tasks, loop=self.loop)
log.info("Started stream manager with %i files", len(self.streams))
async def resume(self):
if self.node:
await self.node.joined.wait()
else:
if not self.node:
log.warning("no DHT node given, resuming downloads trusting that we can contact reflector")
t = [
(stream.start_download(self.node), self.wait_for_stream_finished(stream))
for stream in self.streams if stream.status == ManagedStream.STATUS_RUNNING
]
if t:
log.info("resuming %i downloads", len(t))
if to_resume_saving:
self.resume_saving_task = self.loop.create_task(self.resume(to_resume_saving))
async def resume(self, to_resume_saving):
log.info("Resuming saving %i files", len(to_resume_saving))
await asyncio.gather(
*(self.streams[sd_hash].save_file(file_name, download_directory, node=self.node)
for (file_name, download_directory, sd_hash) in to_resume_saving),
loop=self.loop
)
async def reflect_streams(self):
while True:
if self.config.reflect_streams and self.config.reflector_servers:
sd_hashes = await self.storage.get_streams_to_re_reflect()
streams = list(filter(lambda s: s.sd_hash in sd_hashes, self.streams))
sd_hashes = [sd for sd in sd_hashes if sd in self.streams]
batch = []
while streams:
stream = streams.pop()
if not stream.fully_reflected.is_set():
host, port = random.choice(self.config.reflector_servers)
batch.append(stream.upload_to_reflector(host, port))
while sd_hashes:
stream = self.streams[sd_hashes.pop()]
if self.blob_manager.is_blob_verified(stream.sd_hash) and stream.blobs_completed:
if not stream.fully_reflected.is_set():
host, port = random.choice(self.config.reflector_servers)
batch.append(stream.upload_to_reflector(host, port))
if len(batch) >= self.config.concurrent_reflector_uploads:
await asyncio.gather(*batch)
await asyncio.gather(*batch, loop=self.loop)
batch = []
if batch:
await asyncio.gather(*batch)
await asyncio.gather(*batch, loop=self.loop)
await asyncio.sleep(300, loop=self.loop)
async def start(self):
await self.load_streams_from_database()
self.resume_downloading_task = self.loop.create_task(self.resume())
await self.load_and_resume_streams_from_database()
self.re_reflect_task = self.loop.create_task(self.reflect_streams())
self.started.set()
def stop(self):
if self.resume_downloading_task and not self.resume_downloading_task.done():
self.resume_downloading_task.cancel()
if self.resume_saving_task and not self.resume_saving_task.done():
self.resume_saving_task.cancel()
if self.re_reflect_task and not self.re_reflect_task.done():
self.re_reflect_task.cancel()
while self.streams:
stream = self.streams.pop()
stream.stop_download()
_, stream = self.streams.popitem()
stream.stop_tasks()
while self.update_stream_finished_futs:
self.update_stream_finished_futs.pop().cancel()
while self.running_reflector_uploads:
self.running_reflector_uploads.pop().cancel()
self.started.clear()
log.info("finished stopping the stream manager")
async def create_stream(self, file_path: str, key: typing.Optional[bytes] = None,
iv_generator: typing.Optional[typing.Generator[bytes, None, None]] = None) -> ManagedStream:
stream = await ManagedStream.create(self.loop, self.blob_manager, file_path, key, iv_generator)
self.streams.add(stream)
stream = await ManagedStream.create(self.loop, self.config, self.blob_manager, file_path, key, iv_generator)
self.streams[stream.sd_hash] = stream
self.storage.content_claim_callbacks[stream.stream_hash] = lambda: self._update_content_claim(stream)
if self.config.reflect_streams and self.config.reflector_servers:
host, port = random.choice(self.config.reflector_servers)
@@ -267,9 +228,9 @@ class StreamManager:
return stream
async def delete_stream(self, stream: ManagedStream, delete_file: typing.Optional[bool] = False):
await self.stop_stream(stream)
if stream in self.streams:
self.streams.remove(stream)
stream.stop_tasks()
if stream.sd_hash in self.streams:
del self.streams[stream.sd_hash]
blob_hashes = [stream.sd_hash] + [b.blob_hash for b in stream.descriptor.blobs[:-1]]
await self.blob_manager.delete_blobs(blob_hashes, delete_from_db=False)
await self.storage.delete_stream(stream.descriptor)
@@ -277,7 +238,7 @@ class StreamManager:
os.remove(stream.full_path)
def get_stream_by_stream_hash(self, stream_hash: str) -> typing.Optional[ManagedStream]:
streams = tuple(filter(lambda stream: stream.stream_hash == stream_hash, self.streams))
streams = tuple(filter(lambda stream: stream.stream_hash == stream_hash, self.streams.values()))
if streams:
return streams[0]
@@ -304,66 +265,33 @@ class StreamManager:
if search_by:
comparison = comparison or 'eq'
streams = []
for stream in self.streams:
for stream in self.streams.values():
for search, val in search_by.items():
if comparison_operators[comparison](getattr(stream, search), val):
streams.append(stream)
break
else:
streams = list(self.streams)
streams = list(self.streams.values())
if sort_by:
streams.sort(key=lambda s: getattr(s, sort_by))
if reverse:
streams.reverse()
return streams
def wait_for_stream_finished(self, stream: ManagedStream):
async def _wait_for_stream_finished():
if stream.downloader and stream.running:
await stream.downloader.stream_finished_event.wait()
stream.update_status(ManagedStream.STATUS_FINISHED)
if self.analytics_manager:
self.loop.create_task(self.analytics_manager.send_download_finished(
stream.download_id, stream.claim_name, stream.sd_hash
))
task = self.loop.create_task(_wait_for_stream_finished())
self.update_stream_finished_futs.append(task)
task.add_done_callback(
lambda _: None if task not in self.update_stream_finished_futs else
self.update_stream_finished_futs.remove(task)
)
async def _store_stream(self, downloader: StreamDownloader) -> int:
file_name = os.path.basename(downloader.output_path)
download_directory = os.path.dirname(downloader.output_path)
if not await self.storage.stream_exists(downloader.sd_hash):
await self.storage.store_stream(downloader.sd_blob, downloader.descriptor)
if not await self.storage.file_exists(downloader.sd_hash):
return await self.storage.save_downloaded_file(
downloader.descriptor.stream_hash, file_name, download_directory,
0.0
)
else:
return await self.storage.rowid_for_stream(downloader.descriptor.stream_hash)
async def _check_update_or_replace(self, outpoint: str, claim_id: str, claim: Claim) -> typing.Tuple[
typing.Optional[ManagedStream], typing.Optional[ManagedStream]]:
existing = self.get_filtered_streams(outpoint=outpoint)
if existing:
await self.start_stream(existing[0])
return existing[0], None
existing = self.get_filtered_streams(sd_hash=claim.stream.source.sd_hash)
if existing and existing[0].claim_id != claim_id:
raise ResolveError(f"stream for {existing[0].claim_id} collides with existing "
f"download {claim_id}")
raise ResolveError(f"stream for {existing[0].claim_id} collides with existing download {claim_id}")
if existing:
log.info("claim contains a metadata only update to a stream we have")
await self.storage.save_content_claim(
existing[0].stream_hash, outpoint
)
await self._update_content_claim(existing[0])
await self.start_stream(existing[0])
return existing[0], None
else:
existing_for_claim_id = self.get_filtered_streams(claim_id=claim_id)
@@ -372,142 +300,137 @@ class StreamManager:
return None, existing_for_claim_id[0]
return None, None
async def start_downloader(self, got_descriptor_time: asyncio.Future, downloader: StreamDownloader,
download_id: str, outpoint: str, claim: Claim, resolved: typing.Dict,
file_name: typing.Optional[str] = None) -> ManagedStream:
start_time = self.loop.time()
downloader.download(self.node)
await downloader.got_descriptor.wait()
got_descriptor_time.set_result(self.loop.time() - start_time)
rowid = await self._store_stream(downloader)
await self.storage.save_content_claim(
downloader.descriptor.stream_hash, outpoint
)
stream = ManagedStream(self.loop, self.blob_manager, rowid, downloader.descriptor, self.config.download_dir,
file_name, downloader, ManagedStream.STATUS_RUNNING, download_id=download_id)
stream.set_claim(resolved, claim)
await stream.downloader.wrote_bytes_event.wait()
self.streams.add(stream)
return stream
async def _download_stream_from_uri(self, uri, timeout: float, exchange_rate_manager: 'ExchangeRateManager',
file_name: typing.Optional[str] = None) -> ManagedStream:
start_time = self.loop.time()
parsed_uri = parse_lbry_uri(uri)
if parsed_uri.is_channel:
raise ResolveError("cannot download a channel claim, specify a /path")
# resolve the claim
resolved = (await self.wallet.ledger.resolve(0, 10, uri)).get(uri, {})
resolved = resolved if 'value' in resolved else resolved.get('claim')
if not resolved:
raise ResolveError(f"Failed to resolve stream at '{uri}'")
if 'error' in resolved:
raise ResolveError(f"error resolving stream: {resolved['error']}")
claim = Claim.from_bytes(binascii.unhexlify(resolved['protobuf']))
outpoint = f"{resolved['txid']}:{resolved['nout']}"
resolved_time = self.loop.time() - start_time
# resume or update an existing stream, if the stream changed download it and delete the old one after
updated_stream, to_replace = await self._check_update_or_replace(outpoint, resolved['claim_id'], claim)
if updated_stream:
return updated_stream
# check that the fee is payable
fee_amount, fee_address = None, None
if claim.stream.has_fee:
fee_amount = round(exchange_rate_manager.convert_currency(
claim.stream.fee.currency, "LBC", claim.stream.fee.amount
), 5)
max_fee_amount = round(exchange_rate_manager.convert_currency(
self.config.max_key_fee['currency'], "LBC", Decimal(self.config.max_key_fee['amount'])
), 5)
if fee_amount > max_fee_amount:
msg = f"fee of {fee_amount} exceeds max configured to allow of {max_fee_amount}"
log.warning(msg)
raise KeyFeeAboveMaxAllowed(msg)
balance = await self.wallet.default_account.get_balance()
if lbc_to_dewies(str(fee_amount)) > balance:
msg = f"fee of {fee_amount} exceeds max available balance"
log.warning(msg)
raise InsufficientFundsError(msg)
fee_address = claim.stream.fee.address
# download the stream
download_id = binascii.hexlify(generate_id()).decode()
downloader = StreamDownloader(self.loop, self.config, self.blob_manager, claim.stream.source.sd_hash,
self.config.download_dir, file_name)
stream = None
descriptor_time_fut = self.loop.create_future()
start_download_time = self.loop.time()
time_to_descriptor = None
time_to_first_bytes = None
error = None
try:
stream = await asyncio.wait_for(
asyncio.ensure_future(
self.start_downloader(descriptor_time_fut, downloader, download_id, outpoint, claim, resolved,
file_name)
), timeout
)
time_to_descriptor = await descriptor_time_fut
time_to_first_bytes = self.loop.time() - start_download_time - time_to_descriptor
self.wait_for_stream_finished(stream)
if fee_address and fee_amount and not to_replace:
stream.tx = await self.wallet.send_amount_to_address(
lbc_to_dewies(str(fee_amount)), fee_address.encode('latin1'))
elif to_replace: # delete old stream now that the replacement has started downloading
await self.delete_stream(to_replace)
except asyncio.TimeoutError:
if descriptor_time_fut.done():
time_to_descriptor = descriptor_time_fut.result()
error = DownloadDataTimeout(downloader.sd_hash)
self.blob_manager.delete_blob(downloader.sd_hash)
await self.storage.delete_stream(downloader.descriptor)
else:
descriptor_time_fut.cancel()
error = DownloadSDTimeout(downloader.sd_hash)
if stream:
await self.stop_stream(stream)
else:
downloader.stop()
if error:
log.warning(error)
if self.analytics_manager:
self.loop.create_task(
self.analytics_manager.send_time_to_first_bytes(
resolved_time, self.loop.time() - start_time, download_id, parse_lbry_uri(uri).name, outpoint,
None if not stream else len(stream.downloader.blob_downloader.active_connections),
None if not stream else len(stream.downloader.blob_downloader.scores),
False if not downloader else downloader.added_fixed_peers,
self.config.fixed_peer_delay if not downloader else downloader.fixed_peers_delay,
claim.stream.source.sd_hash, time_to_descriptor,
None if not (stream and stream.descriptor) else stream.descriptor.blobs[0].blob_hash,
None if not (stream and stream.descriptor) else stream.descriptor.blobs[0].length,
time_to_first_bytes, None if not error else error.__class__.__name__
)
)
if error:
raise error
return stream
@cache_concurrent
async def download_stream_from_uri(self, uri, exchange_rate_manager: 'ExchangeRateManager',
timeout: typing.Optional[float] = None,
file_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = None) -> ManagedStream:
download_directory: typing.Optional[str] = None,
save_file: typing.Optional[bool] = None,
resolve_timeout: float = 3.0) -> ManagedStream:
timeout = timeout or self.config.download_timeout
if uri in self.starting_streams:
return await self.starting_streams[uri]
fut = asyncio.Future(loop=self.loop)
self.starting_streams[uri] = fut
start_time = self.loop.time()
resolved_time = None
stream = None
error = None
outpoint = None
if save_file is None:
save_file = self.config.save_files
if file_name and not save_file:
save_file = True
if save_file:
download_directory = download_directory or self.config.download_dir
else:
download_directory = None
try:
stream = await self._download_stream_from_uri(uri, timeout, exchange_rate_manager, file_name)
fut.set_result(stream)
except Exception as err:
fut.set_exception(err)
try:
return await fut
# resolve the claim
parsed_uri = parse_lbry_uri(uri)
if parsed_uri.is_channel:
raise ResolveError("cannot download a channel claim, specify a /path")
try:
resolved_result = await asyncio.wait_for(self.wallet.ledger.resolve(0, 1, uri), resolve_timeout)
except asyncio.TimeoutError:
raise ResolveTimeout(uri)
await self.storage.save_claims_for_resolve([
value for value in resolved_result.values() if 'error' not in value
])
resolved = resolved_result.get(uri, {})
resolved = resolved if 'value' in resolved else resolved.get('claim')
if not resolved:
raise ResolveError(f"Failed to resolve stream at '{uri}'")
if 'error' in resolved:
raise ResolveError(f"error resolving stream: {resolved['error']}")
claim = Claim.from_bytes(binascii.unhexlify(resolved['protobuf']))
outpoint = f"{resolved['txid']}:{resolved['nout']}"
resolved_time = self.loop.time() - start_time
# resume or update an existing stream, if the stream changed download it and delete the old one after
updated_stream, to_replace = await self._check_update_or_replace(outpoint, resolved['claim_id'], claim)
if updated_stream:
log.info("already have stream for %s", uri)
if save_file and updated_stream.output_file_exists:
save_file = False
await updated_stream.start(node=self.node, timeout=timeout, save_now=save_file)
if not updated_stream.output_file_exists and (save_file or file_name or download_directory):
await updated_stream.save_file(
file_name=file_name, download_directory=download_directory, node=self.node
)
return updated_stream
content_fee = None
fee_amount, fee_address = None, None
# check that the fee is payable
if not to_replace and claim.stream.has_fee:
fee_amount = round(exchange_rate_manager.convert_currency(
claim.stream.fee.currency, "LBC", claim.stream.fee.amount
), 5)
max_fee_amount = round(exchange_rate_manager.convert_currency(
self.config.max_key_fee['currency'], "LBC", Decimal(self.config.max_key_fee['amount'])
), 5)
if fee_amount > max_fee_amount:
msg = f"fee of {fee_amount} exceeds max configured to allow of {max_fee_amount}"
log.warning(msg)
raise KeyFeeAboveMaxAllowed(msg)
balance = await self.wallet.default_account.get_balance()
if lbc_to_dewies(str(fee_amount)) > balance:
msg = f"fee of {fee_amount} exceeds max available balance"
log.warning(msg)
raise InsufficientFundsError(msg)
fee_address = claim.stream.fee.address
stream = ManagedStream(
self.loop, self.config, self.blob_manager, claim.stream.source.sd_hash, download_directory,
file_name, ManagedStream.STATUS_RUNNING, content_fee=content_fee,
analytics_manager=self.analytics_manager
)
log.info("starting download for %s", uri)
before_download = self.loop.time()
await stream.start(self.node, timeout)
stream.set_claim(resolved, claim)
if to_replace: # delete old stream now that the replacement has started downloading
await self.delete_stream(to_replace)
elif fee_address:
stream.content_fee = await self.wallet.send_amount_to_address(
lbc_to_dewies(str(fee_amount)), fee_address.encode('latin1')
)
log.info("paid fee of %s for %s", fee_amount, uri)
await self.storage.save_content_fee(stream.stream_hash, stream.content_fee)
self.streams[stream.sd_hash] = stream
self.storage.content_claim_callbacks[stream.stream_hash] = lambda: self._update_content_claim(stream)
await self.storage.save_content_claim(stream.stream_hash, outpoint)
if save_file:
await asyncio.wait_for(stream.save_file(node=self.node), timeout - (self.loop.time() - before_download),
loop=self.loop)
return stream
except asyncio.TimeoutError:
error = DownloadDataTimeout(stream.sd_hash)
raise error
except Exception as err: # forgive data timeout, dont delete stream
error = err
raise
finally:
del self.starting_streams[uri]
if self.analytics_manager and (error or (stream and (stream.downloader.time_to_descriptor or
stream.downloader.time_to_first_bytes))):
self.loop.create_task(
self.analytics_manager.send_time_to_first_bytes(
resolved_time, self.loop.time() - start_time, None if not stream else stream.download_id,
uri, outpoint,
None if not stream else len(stream.downloader.blob_downloader.active_connections),
None if not stream else len(stream.downloader.blob_downloader.scores),
False if not stream else stream.downloader.added_fixed_peers,
self.config.fixed_peer_delay if not stream else stream.downloader.fixed_peers_delay,
None if not stream else stream.sd_hash,
None if not stream else stream.downloader.time_to_descriptor,
None if not (stream and stream.descriptor) else stream.descriptor.blobs[0].blob_hash,
None if not (stream and stream.descriptor) else stream.descriptor.blobs[0].length,
None if not stream else stream.downloader.time_to_first_bytes,
None if not error else error.__class__.__name__
)
)
async def stream_partial_content(self, request: Request, sd_hash: str):
return await self.streams[sd_hash].stream_file(request, self.node)
+51 -24
View File
@@ -18,7 +18,7 @@ from lbrynet.extras.daemon.Components import (
)
from lbrynet.extras.daemon.ComponentManager import ComponentManager
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.stream.reflector.server import ReflectorServer
from lbrynet.blob_exchange.server import BlobServer
@@ -107,9 +107,11 @@ class CommandTestCase(IntegrationTestCase):
server_tmp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, server_tmp_dir)
self.server_storage = SQLiteStorage(Config(), ':memory:')
self.server_config = Config()
self.server_storage = SQLiteStorage(self.server_config, ':memory:')
await self.server_storage.open()
self.server_blob_manager = BlobFileManager(self.loop, server_tmp_dir, self.server_storage)
self.server_blob_manager = BlobManager(self.loop, server_tmp_dir, self.server_storage, self.server_config)
self.server = BlobServer(self.loop, self.server_blob_manager, 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
self.server.start_server(5567, '127.0.0.1')
await self.server.started_listening.wait()
@@ -122,7 +124,7 @@ class CommandTestCase(IntegrationTestCase):
async def asyncTearDown(self):
await super().asyncTearDown()
self.wallet_component._running = False
await self.daemon.stop()
await self.daemon.stop(shutdown_runner=False)
async def confirm_tx(self, txid):
""" Wait for tx to be in mempool, then generate a block, wait for tx to be in a block. """
@@ -149,8 +151,17 @@ class CommandTestCase(IntegrationTestCase):
await self.blockchain.generate(blocks)
await self.ledger.on_header.where(self.blockchain.is_expected_block)
def blockchain_claim_name(self, name: str, value: str, amount: str):
return self.blockchain._cli_cmnd('claimname', name, value, amount)
async def blockchain_claim_name(self, name: str, value: str, amount: str, confirm=True):
txid = await self.blockchain._cli_cmnd('claimname', name, value, amount)
if confirm:
await self.generate(1)
return txid
async def blockchain_update_name(self, txid: str, value: str, amount: str, confirm=True):
txid = await self.blockchain._cli_cmnd('updateclaim', txid, value, amount)
if confirm:
await self.generate(1)
return txid
async def out(self, awaitable):
""" Serializes lbrynet API results to JSON then loads and returns it as dictionary. """
@@ -161,27 +172,43 @@ class CommandTestCase(IntegrationTestCase):
return json.loads(jsonrpc_dumps_pretty(value, ledger=self.ledger))['result']
async def stream_create(self, name='hovercraft', bid='1.0', data=b'hi!', confirm=True, **kwargs):
with tempfile.NamedTemporaryFile() as file:
file.write(data)
file.flush()
claim = await self.out(
self.daemon.jsonrpc_stream_create(name, bid, file_path=file.name, **kwargs)
)
self.assertEqual(claim['outputs'][0]['name'], name)
if confirm:
await self.on_transaction_dict(claim)
await self.generate(1)
await self.on_transaction_dict(claim)
return claim
file = tempfile.NamedTemporaryFile()
def cleanup():
try:
file.close()
except FileNotFoundError:
pass
self.addCleanup(cleanup)
file.write(data)
file.flush()
claim = await self.out(
self.daemon.jsonrpc_stream_create(name, bid, file_path=file.name, **kwargs)
)
self.assertEqual(claim['outputs'][0]['name'], name)
if confirm:
await self.on_transaction_dict(claim)
await self.generate(1)
await self.on_transaction_dict(claim)
return claim
async def stream_update(self, claim_id, data=None, confirm=True, **kwargs):
if data:
with tempfile.NamedTemporaryFile() as file:
file.write(data)
file.flush()
claim = await self.out(
self.daemon.jsonrpc_stream_update(claim_id, file_path=file.name, **kwargs)
)
file = tempfile.NamedTemporaryFile()
file.write(data)
file.flush()
def cleanup():
try:
file.close()
except FileNotFoundError:
pass
self.addCleanup(cleanup)
claim = await self.out(
self.daemon.jsonrpc_stream_update(claim_id, file_path=file.name, **kwargs)
)
else:
claim = await self.out(self.daemon.jsonrpc_stream_update(claim_id, **kwargs))
self.assertIsNotNone(claim['outputs'][0]['name'])
+39
View File
@@ -14,6 +14,7 @@ import pkg_resources
import contextlib
import certifi
import aiohttp
import functools
from lbrynet.schema.claim import Claim
from lbrynet.cryptoutils import get_lbry_hash_obj
@@ -146,6 +147,44 @@ def drain_tasks(tasks: typing.List[typing.Optional[asyncio.Task]]):
cancel_task(tasks.pop())
def async_timed_cache(duration: int):
def wrapper(fn):
cache: typing.Dict[typing.Tuple,
typing.Tuple[typing.Any, float]] = {}
@functools.wraps(fn)
async def _inner(*args, **kwargs) -> typing.Any:
loop = asyncio.get_running_loop()
now = loop.time()
key = tuple([args, tuple([tuple([k, kwargs[k]]) for k in kwargs])])
if key in cache and (now - cache[key][1] < duration):
return cache[key][0]
to_cache = await fn(*args, **kwargs)
cache[key] = to_cache, now
return to_cache
return _inner
return wrapper
def cache_concurrent(async_fn):
"""
When the decorated function has concurrent calls made to it with the same arguments, only run it once
"""
cache: typing.Dict = {}
@functools.wraps(async_fn)
async def wrapper(*args, **kwargs):
key = tuple([args, tuple([tuple([k, kwargs[k]]) for k in kwargs])])
cache[key] = cache.get(key) or asyncio.create_task(async_fn(*args, **kwargs))
try:
return await cache[key]
finally:
cache.pop(key, None)
return wrapper
@async_timed_cache(300)
async def resolve_host(url: str, port: int, proto: str) -> str:
if proto not in ['udp', 'tcp']:
raise Exception("invalid protocol")
+6 -5
View File
@@ -4,7 +4,7 @@ import binascii
from hashlib import sha256
from string import hexdigits
from torba.client.baseaccount import BaseAccount
from torba.client.baseaccount import BaseAccount, HierarchicalDeterministic
from torba.client.basetransaction import TXORef
@@ -167,10 +167,11 @@ class Account(BaseAccount):
))
async def save_max_gap(self):
gap = await self.get_max_gap()
self.receiving.gap = max(20, gap['max_receiving_gap'] + 1)
self.change.gap = max(6, gap['max_change_gap'] + 1)
self.wallet.save()
if issubclass(self.address_generator, HierarchicalDeterministic):
gap = await self.get_max_gap()
self.receiving.gap = max(20, gap['max_receiving_gap'] + 1)
self.change.gap = max(6, gap['max_change_gap'] + 1)
self.wallet.save()
def get_balance(self, confirmations=0, include_claims=False, **constraints):
if not include_claims:
-7
View File
@@ -308,13 +308,6 @@ class LbryWalletManager(BaseWalletManager):
for wallet in self.wallets:
wallet.save()
def get_block(self, block_hash=None, height=None):
if height is None:
height = self.ledger.headers.height
if block_hash is None:
block_hash = self.ledger.headers.hash(height).decode()
return self.ledger.network.get_block(block_hash)
def get_claim_by_claim_id(self, claim_id):
return self.ledger.get_claim_by_claim_id(claim_id)
-3
View File
@@ -3,9 +3,6 @@ from torba.client.basenetwork import BaseNetwork
class Network(BaseNetwork):
def get_block(self, block_hash):
return self.rpc('blockchain.block.get_block', block_hash)
def get_server_height(self):
return self.rpc('blockchain.block.get_server_height')
+6 -1
View File
@@ -152,6 +152,10 @@ class Resolver:
if not claim_result or 'value' not in claim_result:
return claim_result
claim_result = _decode_claim_result(claim_result)
if claim_result.get('height'):
claim_result['timestamp'] = self.ledger.headers[claim_result['height']]['timestamp']
if claim_result.get('depth'):
claim_result['confirmations'] = claim_result.pop('depth')
if claim_result['value']:
claim_result['has_signature'] = False
@@ -296,10 +300,11 @@ def _verify_proof(name, claim_trie_root, result, ledger):
'amount': output.amount,
'effective_amount': output.amount + support_amount,
'height': result['height'],
'depth': result['depth'],
'confirmations': result['depth'],
'claim_sequence': result['claim_sequence'],
'address': output.get_address(ledger),
'valid_at_height': result['valid_at_height'],
'timestamp': ledger.headers[result['height']]['timestamp'],
'supports': result['supports']
}
return r
-4
View File
@@ -41,7 +41,6 @@ class LBRYElectrumX(ElectrumX):
'blockchain.claimtrie.getvaluesforuris': self.claimtrie_getvalueforuris,
'blockchain.claimtrie.getclaimssignedbyid': self.claimtrie_getclaimssignedbyid,
'blockchain.block.get_server_height': self.get_server_height,
'blockchain.block.get_block': self.get_block,
}
# fixme: methods we use but shouldnt be using anymore. To be removed when torba goes out
handlers.update({
@@ -104,9 +103,6 @@ class LBRYElectrumX(ElectrumX):
verbose = False
return await self.daemon_request('getrawtransaction', tx_hash, verbose)
async def get_block(self, block_hash):
return await self.daemon.deserialised_block(block_hash)
async def get_server_height(self):
return self.bp.height
+4
View File
@@ -25,6 +25,9 @@ RUN python3.7 -m pip install --upgrade pip setuptools
# get torba
RUN python3.7 -m pip install --user git+https://github.com/lbryio/torba.git#egg=torba
# get uvloop
RUN python3.7 -m pip install --user uvloop
# copy lbrynet
RUN mkdir projects/
COPY . projects/lbry
@@ -46,4 +49,5 @@ ENV DB_DIRECTORY=$db_dir
ENV BANDWIDTH_LIMIT=1000000000000000000000000000000000000000000
ENV MAX_SESSIONS=1000000000
ENV MAX_SEND=1000000000000000000
ENV EVENT_LOOP_POLICY=uvloop
ENTRYPOINT ["/home/lbry/.local/bin/torba-server"]
+2 -2
View File
@@ -5,7 +5,7 @@ import socket
import ipaddress
from lbrynet.conf import Config
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob_exchange.client import BlobExchangeClientProtocol, request_blob
import logging
@@ -32,7 +32,7 @@ async def main(blob_hash: str, url: str):
host = host_info[0][4][0]
storage = SQLiteStorage(conf, os.path.join(conf.data_dir, "lbrynet.sqlite"))
blob_manager = BlobFileManager(loop, os.path.join(conf.data_dir, "blobfiles"), storage)
blob_manager = BlobManager(loop, os.path.join(conf.data_dir, "blobfiles"), storage)
await storage.open()
await blob_manager.setup()
+5
View File
@@ -321,6 +321,11 @@ class Examples(CommandTestCase):
'get', file_uri
)
await r(
'Save a file to the downloads directory',
'file', 'save', f"--sd_hash=\"{file_list_result[0]['sd_hash']}\""
)
# blobs
bloblist = await r(
+2 -2
View File
@@ -1,7 +1,7 @@
import sys
import os
import asyncio
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob_exchange.server import BlobServer
from lbrynet.schema.address import decode_address
from lbrynet.extras.daemon.storage import SQLiteStorage
@@ -17,7 +17,7 @@ async def main(address: str):
storage = SQLiteStorage(os.path.expanduser("~/.lbrynet/lbrynet.sqlite"))
await storage.open()
blob_manager = BlobFileManager(loop, os.path.expanduser("~/.lbrynet/blobfiles"), storage)
blob_manager = BlobManager(loop, os.path.expanduser("~/.lbrynet/blobfiles"), storage)
await blob_manager.setup()
server = await loop.create_server(
+42 -32
View File
@@ -11,7 +11,7 @@ from lbrynet.blob.blob_file import MAX_BLOB_SIZE
from lbrynet.conf import Config
from lbrynet.schema.uri import parse_lbry_uri
from lbrynet.extras.daemon.client import daemon_rpc
from lbrynet.extras import system_info, cli
from lbrynet.extras import system_info
def extract_uris(response):
@@ -58,7 +58,7 @@ def variance(times):
return round(sum(((i - mean) ** 2.0 for i in times)) / (len(times) - 1), 3)
async def wait_for_done(conf, uri):
async def wait_for_done(conf, uri, timeout):
name = uri.split("#")[0]
last_complete = 0
hang_count = 0
@@ -73,11 +73,11 @@ async def wait_for_done(conf, uri):
else:
hang_count += 1
await asyncio.sleep(1.0)
if hang_count > 10:
if hang_count > timeout:
return False, file['blobs_completed'], file['blobs_in_stream']
async def main(uris=None, allow_fees=False):
async def main(uris=None, cmd_args=None):
if not uris:
uris = await get_frontpage_uris()
conf = Config()
@@ -90,15 +90,16 @@ async def main(uris=None, allow_fees=False):
print("**********************************************")
resolvable = []
for name in uris:
resolved = await daemon_rpc(conf, 'resolve', name)
async def __resolve(name):
resolved = await daemon_rpc(conf, 'resolve', urls=[name])
if 'error' not in resolved.get(name, {}):
if ("fee" not in resolved[name]['claim']['value']['stream']) or allow_fees:
if ("fee" not in resolved[name]['claim']['value']) or cmd_args.allow_fees:
resolvable.append(name)
else:
print(f"{name} has a fee, skipping it")
else:
print(f"failed to resolve {name}: {resolved[name]['error']}")
await asyncio.gather(*(__resolve(name) for name in uris))
print(f"attempting to download {len(resolvable)}/{len(uris)} frontpage streams")
first_byte_times = []
@@ -113,24 +114,29 @@ async def main(uris=None, allow_fees=False):
for i, uri in enumerate(resolvable):
start = time.time()
try:
await daemon_rpc(conf, 'get', uri)
await daemon_rpc(conf, 'get', uri=uri, save_file=True)
first_byte = time.time()
first_byte_times.append(first_byte - start)
print(f"{i + 1}/{len(resolvable)} - {first_byte - start} {uri}")
downloaded, amount_downloaded, blobs_in_stream = await wait_for_done(conf, uri)
if downloaded:
download_successes.append(uri)
else:
download_failures.append(uri)
mbs = round((blobs_in_stream * (MAX_BLOB_SIZE - 1)) / (time.time() - start) / 1000000, 2)
download_speeds.append(mbs)
print(f"downloaded {amount_downloaded}/{blobs_in_stream} blobs for {uri} at "
f"{mbs}mb/s")
except:
print(f"{i + 1}/{len(uris)} - failed to start {uri}")
if not cmd_args.head_blob_only:
downloaded, amount_downloaded, blobs_in_stream = await wait_for_done(
conf, uri, cmd_args.stall_download_timeout
)
if downloaded:
download_successes.append(uri)
else:
download_failures.append(uri)
mbs = round((blobs_in_stream * (MAX_BLOB_SIZE - 1)) / (time.time() - start) / 1000000, 2)
download_speeds.append(mbs)
print(f"downloaded {amount_downloaded}/{blobs_in_stream} blobs for {uri} at "
f"{mbs}mb/s")
except Exception as e:
print(f"{i + 1}/{len(uris)} - failed to start {uri}: {e}")
failed_to_start.append(uri)
return
# await daemon_rpc(conf, 'file_delete', delete_from_download_dir=True, claim_name=parse_lbry_uri(uri).name)
if cmd_args.exit_on_error:
return
if cmd_args.delete_after_download or cmd_args.head_blob_only:
await daemon_rpc(conf, 'file_delete', delete_from_download_dir=True, claim_name=parse_lbry_uri(uri).name)
await asyncio.sleep(0.1)
print("**********************************************")
@@ -139,12 +145,13 @@ async def main(uris=None, allow_fees=False):
f"Best first byte time: {round(min(first_byte_times), 2)}\n" \
f"95% confidence time-to-first-byte: {confidence(first_byte_times, 1.984)}s\n" \
f"99% confidence time-to-first-byte: {confidence(first_byte_times, 2.626)}s\n" \
f"Variance: {variance(first_byte_times)}\n" \
f"Downloaded {len(download_successes)}/{len(resolvable)}\n" \
f"Best stream download speed: {round(max(download_speeds), 2)}mb/s\n" \
f"Worst stream download speed: {round(min(download_speeds), 2)}mb/s\n" \
f"95% confidence download speed: {confidence(download_speeds, 1.984, False)}mb/s\n" \
f"99% confidence download speed: {confidence(download_speeds, 2.626, False)}mb/s\n"
f"Variance: {variance(first_byte_times)}\n"
if not cmd_args.head_blob_only:
result += f"Downloaded {len(download_successes)}/{len(resolvable)}\n" \
f"Best stream download speed: {round(max(download_speeds), 2)}mb/s\n" \
f"Worst stream download speed: {round(min(download_speeds), 2)}mb/s\n" \
f"95% confidence download speed: {confidence(download_speeds, 1.984, False)}mb/s\n" \
f"99% confidence download speed: {confidence(download_speeds, 2.626, False)}mb/s\n"
if failed_to_start:
result += "\nFailed to start:" + "\n".join([f for f in failed_to_start])
@@ -159,9 +166,12 @@ async def main(uris=None, allow_fees=False):
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--data_dir")
parser.add_argument("--wallet_dir")
parser.add_argument("--download_directory")
#parser.add_argument("--data_dir")
#parser.add_argument("--wallet_dir")
#parser.add_argument("--download_directory")
parser.add_argument("--allow_fees", action='store_true')
args = parser.parse_args()
asyncio.run(main(allow_fees=args.allow_fees))
parser.add_argument("--exit_on_error", action='store_true')
parser.add_argument("--stall_download_timeout", default=10, type=int)
parser.add_argument("--delete_after_download", action='store_true')
parser.add_argument("--head_blob_only", action='store_true')
asyncio.run(main(cmd_args=parser.parse_args()))
+1
View File
@@ -61,6 +61,7 @@ def mock_network_loop(loop: asyncio.BaseEventLoop):
protocol = proto_lam()
transport = asyncio.DatagramTransport(extra={'socket': mock_sock})
transport.is_closing = lambda: False
transport.close = lambda: mock_sock.close()
mock_sock.sendto = sendto
transport.sendto = mock_sock.sendto
+2 -2
View File
@@ -92,7 +92,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
# After abandoning he just waits for his LBCs to be returned to his account
await self.generate(5)
result = await self.daemon.jsonrpc_account_balance()
self.assertEqual(result, '8.9693545')
self.assertEqual(result, '8.9693455')
# Amidst all this Chris receives a call from his friend Ramsey
# who says that it is of utmost urgency that Chris transfer him
@@ -108,7 +108,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
await self.generate(5)
result = await self.daemon.jsonrpc_account_balance()
# Chris' balance was correct
self.assertEqual(result, '7.9692305')
self.assertEqual(result, '7.9692215')
# Ramsey too assured him that he had received the 1 LBC and thanks him
result = await self.daemon.jsonrpc_account_balance(ramsey_account_id)
+153 -28
View File
@@ -125,6 +125,13 @@ class ChannelCommands(CommandTestCase):
channel = tx['outputs'][0]['value']
self.assertNotEqual(channel['public_key'], fixed_values['public_key'])
# replace mode (clears everything except public_key)
tx = await self.out(self.channel_update(claim_id, replace=True, title='foo', email='new@email.com'))
self.assertEqual(
tx['outputs'][0]['value'],
{'public_key': channel['public_key'], 'title': 'foo', 'email': 'new@email.com'}
)
# send channel to someone else
new_account = await self.out(self.daemon.jsonrpc_account_create('second account'))
account2_id, account2 = new_account['id'], self.daemon.get_account_or_error(new_account['id'])
@@ -207,14 +214,14 @@ class StreamCommands(CommandTestCase):
tx = await self.stream_update(claim_id, bid='3.0')
self.assertEqual(tx['outputs'][0]['amount'], '3.0')
await self.assertBalance(self.account, '6.993337')
await self.assertBalance(self.account, '6.993319')
# not enough funds
with self.assertRaisesRegex(
InsufficientFundsError, "Not enough funds to cover this transaction."):
await self.stream_create('foo2', '9.0')
self.assertEqual(len(await self.daemon.jsonrpc_claim_list()), 1)
await self.assertBalance(self.account, '6.993337')
await self.assertBalance(self.account, '6.993319')
# spend exactly amount available, no change
tx = await self.stream_create('foo3', '6.98523')
@@ -251,16 +258,57 @@ class StreamCommands(CommandTestCase):
self.assertEqual(channels[0]['name'], '@baz')
# defaults to using all accounts to lookup channel
await self.stream_create('hovercraft1', channel_id=baz_id)
await self.stream_create('hovercraft1', '0.1', channel_id=baz_id)
self.assertEqual((await self.claim_search('hovercraft1'))[0]['channel_name'], '@baz')
# uses only the specific accounts which contains the channel
await self.stream_create('hovercraft2', channel_id=baz_id, channel_account_id=[account2_id])
# lookup by channel_name in all accounts
await self.stream_create('hovercraft2', '0.1', channel_name='@baz')
self.assertEqual((await self.claim_search('hovercraft2'))[0]['channel_name'], '@baz')
# uses only the specific accounts which contains the channel
await self.stream_create('hovercraft3', '0.1', channel_id=baz_id, channel_account_id=[account2_id])
self.assertEqual((await self.claim_search('hovercraft3'))[0]['channel_name'], '@baz')
# lookup by channel_name in specific account
await self.stream_create('hovercraft4', '0.1', channel_name='@baz', channel_account_id=[account2_id])
self.assertEqual((await self.claim_search('hovercraft4'))[0]['channel_name'], '@baz')
# fails when specifying account which does not contain channel
with self.assertRaisesRegex(ValueError, "Couldn't find channel with channel_id"):
await self.stream_create(
'hovercraft3', channel_id=baz_id, channel_account_id=[account1_id]
'hovercraft5', '0.1', channel_id=baz_id, channel_account_id=[account1_id]
)
# fail with channel_name
with self.assertRaisesRegex(ValueError, "Couldn't find channel with channel_name '@baz'"):
await self.stream_create(
'hovercraft5', '0.1', channel_name='@baz', channel_account_id=[account1_id]
)
async def test_preview_works_with_signed_streams(self):
await self.out(self.channel_create('@spam', '1.0'))
signed = await self.out(self.stream_create('bar', '1.0', channel_name='@spam', preview=True, confirm=False))
self.assertTrue(signed['outputs'][0]['is_channel_signature_valid'])
async def test_publish_updates_file_list(self):
tx = await self.out(self.stream_create(title='created'))
txo = tx['outputs'][0]
claim_id, expected = txo['claim_id'], txo['value']
files = self.sout(self.daemon.jsonrpc_file_list())
self.assertEqual(1, len(files))
self.assertEqual(tx['txid'], files[0]['txid'])
self.assertEqual(expected, files[0]['metadata'])
# update with metadata-only changes
tx = await self.out(self.stream_update(claim_id, title='update 1'))
files = self.sout(self.daemon.jsonrpc_file_list())
expected['title'] = 'update 1'
self.assertEqual(1, len(files))
self.assertEqual(tx['txid'], files[0]['txid'])
self.assertEqual(expected, files[0]['metadata'])
# update with new data
tx = await self.out(self.stream_update(claim_id, title='update 2', data=b'updated data'))
expected = tx['outputs'][0]['value']
files = self.sout(self.daemon.jsonrpc_file_list())
self.assertEqual(1, len(files))
self.assertEqual(tx['txid'], files[0]['txid'])
self.assertEqual(expected, files[0]['metadata'])
async def test_setting_stream_fields(self):
values = {
@@ -269,7 +317,7 @@ class StreamCommands(CommandTestCase):
'thumbnail_url': "https://co.ol/thumbnail.png",
'tags': ["cool", "awesome"],
'languages': ["en"],
'locations': ['{"country": "US"}'],
'locations': ['US:NH:Manchester:03101:42.990605:-71.460989'],
'author': "Jules Verne",
'license': 'Public Domain',
@@ -281,17 +329,24 @@ class StreamCommands(CommandTestCase):
'fee_address': 'mmCsWAiXMUVecFQ3fVzUwvpT9XFMXno2Ca',
}
fixed_values = values.copy()
fixed_values['locations'] = [{'country': 'US'}]
fixed_values['locations'] = [{
'country': 'US',
'state': 'NH',
'city': 'Manchester',
'code': '03101',
'latitude': '42.990605',
'longitude': '-71.460989'
}]
fixed_values['thumbnail'] = {'url': fixed_values.pop('thumbnail_url')}
fixed_values['release_time'] = str(values['release_time'])
fixed_values['source'] = {
'hash': 'c0ddd62c7717180e7ffb8a15bb9674d3ec92592e0b7ac7d1d5289836b4553be2',
'hash': '56bf5dbae43f77a63d075b0f2ae9c7c3e3098db93779c7f9840da0f4db9c2f8c8454f4edd1373e2b64ee2e68350d916e',
'media_type': 'application/octet-stream',
'size': '3'
}
fixed_values['fee'] = {
'address': fixed_values.pop('fee_address'),
'amount': float(fixed_values.pop('fee_amount')),
'amount': fixed_values.pop('fee_amount'),
'currency': fixed_values.pop('fee_currency').upper()
}
@@ -311,7 +366,7 @@ class StreamCommands(CommandTestCase):
'size': '3',
'media_type': 'application/octet-stream',
'name': stream['source']['name'],
'hash': 'c0ddd62c7717180e7ffb8a15bb9674d3ec92592e0b7ac7d1d5289836b4553be2',
'hash': '56bf5dbae43f77a63d075b0f2ae9c7c3e3098db93779c7f9840da0f4db9c2f8c8454f4edd1373e2b64ee2e68350d916e',
'sd_hash': stream['source']['sd_hash']
},
}
@@ -329,7 +384,7 @@ class StreamCommands(CommandTestCase):
'size': '3',
'media_type': 'application/octet-stream',
'name': fixed_values['source']['name'],
'hash': 'c0ddd62c7717180e7ffb8a15bb9674d3ec92592e0b7ac7d1d5289836b4553be2',
'hash': '56bf5dbae43f77a63d075b0f2ae9c7c3e3098db93779c7f9840da0f4db9c2f8c8454f4edd1373e2b64ee2e68350d916e',
'sd_hash': fixed_values['source']['sd_hash'],
},
'tags': ['blah'],
@@ -346,7 +401,7 @@ class StreamCommands(CommandTestCase):
fixed_values['locations'].insert(0, {'country': 'UA', 'city': 'Kyiv'}) # existing location
self.assertEqual(stream, fixed_values)
# clearing and settings tags
# clearing and settings tags, languages and locations
tx = await self.out(self.stream_update(
claim_id, tags='single', clear_tags=True,
languages='pt', clear_languages=True,
@@ -358,6 +413,12 @@ class StreamCommands(CommandTestCase):
fixed_values['locations'] = [{'country': 'BR'}]
self.assertEqual(txo['value'], fixed_values)
# clearing fee
tx = await self.out(self.stream_update(claim_id, clear_fee=True))
txo = tx['outputs'][0]
del fixed_values['fee']
self.assertEqual(txo['value'], fixed_values)
# modifying hash/size/name
fixed_values['source']['name'] = 'changed_name'
fixed_values['source']['hash'] = 'cafebeef'
@@ -367,19 +428,27 @@ class StreamCommands(CommandTestCase):
))
self.assertEqual(tx['outputs'][0]['value'], fixed_values)
# stream_update re-signs with the same channel
channel_id = (await self.channel_create('@chan'))['outputs'][0]['claim_id']
tx = await self.stream_update(claim_id, channel_id=channel_id)
self.assertEqual(tx['outputs'][0]['signing_channel']['name'], '@chan')
tx = await self.stream_update(claim_id, title='channel re-signs')
self.assertEqual(tx['outputs'][0]['value']['title'], 'channel re-signs')
self.assertEqual(tx['outputs'][0]['signing_channel']['name'], '@chan')
# send claim to someone else
new_account = await self.out(self.daemon.jsonrpc_account_create('second account'))
account2_id, account2 = new_account['id'], self.daemon.get_account_or_error(new_account['id'])
# before sending
self.assertEqual(len(await self.daemon.jsonrpc_claim_list()), 3)
self.assertEqual(len(await self.daemon.jsonrpc_claim_list()), 4)
self.assertEqual(len(await self.daemon.jsonrpc_claim_list(account_id=account2_id)), 0)
other_address = await account2.receiving.get_or_create_usable_address()
tx = await self.out(self.stream_update(claim_id, claim_address=other_address))
# after sending
self.assertEqual(len(await self.daemon.jsonrpc_claim_list()), 2)
self.assertEqual(len(await self.daemon.jsonrpc_claim_list()), 3)
self.assertEqual(len(await self.daemon.jsonrpc_claim_list(account_id=account2_id)), 1)
async def test_automatic_type_and_metadata_detection_for_image(self):
@@ -403,7 +472,7 @@ class StreamCommands(CommandTestCase):
'size': '99',
'name': os.path.basename(file.name),
'media_type': 'image/png',
'hash': '06003bbee8aece0543ed9d9cecc48be1d996cfeff9837a1aed1d961caeda82af',
'hash': '6c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545',
'sd_hash': txo['value']['source']['sd_hash'],
},
'stream_type': 'image',
@@ -427,7 +496,7 @@ class StreamCommands(CommandTestCase):
'size': '2299653',
'name': 'ForBiggerEscapes.mp4',
'media_type': 'video/mp4',
'hash': 'f846d9c7f5ed28f0ed47e9d9b4198a03075e6df967ac54078af85ea1bf0ddd87',
'hash': '5f6811c83c1616df06f10bf5309ca61edb5ff949a9c1212ce784602d837bfdfc1c3db1e0580ef7bd1dadde41d8acf315',
'sd_hash': txo['value']['source']['sd_hash'],
},
'stream_type': 'video',
@@ -452,7 +521,7 @@ class StreamCommands(CommandTestCase):
'size': '2299653',
'name': 'ForBiggerEscapes.mp4',
'media_type': 'video/mp4',
'hash': 'f846d9c7f5ed28f0ed47e9d9b4198a03075e6df967ac54078af85ea1bf0ddd87',
'hash': '5f6811c83c1616df06f10bf5309ca61edb5ff949a9c1212ce784602d837bfdfc1c3db1e0580ef7bd1dadde41d8acf315',
'sd_hash': txo['value']['source']['sd_hash'],
},
'stream_type': 'video',
@@ -464,6 +533,46 @@ class StreamCommands(CommandTestCase):
}
)
async def test_replace_mode_preserves_source_and_type(self):
expected = {
'tags': ['blah'],
'languages': ['uk'],
'locations': [{'country': 'UA', 'city': 'Kyiv'}],
'source': {
'size': '2299653',
'name': 'ForBiggerEscapes.mp4',
'media_type': 'video/mp4',
'hash': '5f6811c83c1616df06f10bf5309ca61edb5ff949a9c1212ce784602d837bfdfc1c3db1e0580ef7bd1dadde41d8acf315',
},
'stream_type': 'video',
'video': {
'width': 1280,
'height': 720,
'duration': 15
}
}
channel = await self.channel_create('@chan')
tx = await self.out(self.daemon.jsonrpc_stream_create(
'chrome', '1.0', file_path=self.video_file_name,
tags='blah', languages='uk', locations='UA::Kyiv',
channel_id=channel['outputs'][0]['claim_id']
))
await self.on_transaction_dict(tx)
txo = tx['outputs'][0]
expected['source']['sd_hash'] = txo['value']['source']['sd_hash']
self.assertEqual(txo['value'], expected)
self.assertEqual(txo['signing_channel']['name'], '@chan')
tx = await self.out(self.daemon.jsonrpc_stream_update(
txo['claim_id'], title='new title', replace=True
))
txo = tx['outputs'][0]
expected['title'] = 'new title'
del expected['tags']
del expected['languages']
del expected['locations']
self.assertEqual(txo['value'], expected)
self.assertNotIn('signing_channel', txo)
async def test_create_update_and_abandon_stream(self):
await self.assertBalance(self.account, '10.0')
@@ -477,6 +586,10 @@ class StreamCommands(CommandTestCase):
self.assertEqual(txs[0]['value'], '0.0')
self.assertEqual(txs[0]['fee'], '-0.020107')
await self.assertBalance(self.account, '7.479893')
self.assertEqual(1, len(self.daemon.jsonrpc_file_list()))
await self.daemon.jsonrpc_file_delete(delete_all=True)
self.assertEqual(0, len(self.daemon.jsonrpc_file_list()))
await self.stream_update(claim_id, bid='1.0') # updates previous claim
txs = await self.out(self.daemon.jsonrpc_transaction_list())
@@ -484,8 +597,8 @@ class StreamCommands(CommandTestCase):
self.assertEqual(txs[0]['update_info'][0]['balance_delta'], '1.5')
self.assertEqual(txs[0]['update_info'][0]['claim_id'], claim_id)
self.assertEqual(txs[0]['value'], '0.0')
self.assertEqual(txs[0]['fee'], '-0.0002075')
await self.assertBalance(self.account, '8.9796855')
self.assertEqual(txs[0]['fee'], '-0.0002165')
await self.assertBalance(self.account, '8.9796765')
await self.stream_abandon(claim_id)
txs = await self.out(self.daemon.jsonrpc_transaction_list())
@@ -494,7 +607,7 @@ class StreamCommands(CommandTestCase):
self.assertEqual(txs[0]['abandon_info'][0]['claim_id'], claim_id)
self.assertEqual(txs[0]['value'], '0.0')
self.assertEqual(txs[0]['fee'], '-0.000107')
await self.assertBalance(self.account, '9.9795785')
await self.assertBalance(self.account, '9.9795695')
async def test_abandoning_stream_at_loss(self):
await self.assertBalance(self.account, '10.0')
@@ -518,8 +631,12 @@ class StreamCommands(CommandTestCase):
file.flush()
tx1 = await self.publish('foo', bid='1.0', file_path=file.name)
self.assertEqual(1, len(self.daemon.jsonrpc_file_list()))
# doesn't error on missing arguments when doing an update stream
tx2 = await self.publish('foo', tags='updated')
self.assertEqual(1, len(self.daemon.jsonrpc_file_list()))
self.assertEqual(
tx1['outputs'][0]['claim_id'],
tx2['outputs'][0]['claim_id']
@@ -530,25 +647,27 @@ class StreamCommands(CommandTestCase):
with self.assertRaisesRegex(Exception, "There are 2 claims for 'foo'"):
await self.daemon.jsonrpc_publish('foo')
self.assertEqual(2, len(self.daemon.jsonrpc_file_list()))
# abandon duplicate stream
await self.stream_abandon(tx3['outputs'][0]['claim_id'])
# publish to a channel
await self.channel_create('@abc')
tx3 = await self.publish('foo', channel_name='@abc')
self.assertEqual(2, len(self.daemon.jsonrpc_file_list()))
r = await self.resolve('lbry://@abc/foo')
self.assertEqual(
r['lbry://@abc/foo']['claim']['claim_id'],
tx3['outputs'][0]['claim_id']
)
# publishing again re-signs with the same channel
# publishing again clears channel
tx4 = await self.publish('foo', languages='uk-UA')
r = await self.resolve('lbry://@abc/foo')
claim = r['lbry://@abc/foo']['claim']
self.assertEqual(2, len(self.daemon.jsonrpc_file_list()))
r = await self.resolve('lbry://foo')
claim = r['lbry://foo']['claim']
self.assertEqual(claim['txid'], tx4['outputs'][0]['txid'])
self.assertEqual(claim['channel_name'], '@abc')
self.assertEqual(claim['signature_is_valid'], True)
self.assertNotIn('channel_name', claim)
self.assertEqual(claim['value']['languages'], ['uk-UA'])
async def test_claim_search(self):
@@ -588,6 +707,13 @@ class StreamCommands(CommandTestCase):
claims = await self.claim_search(channel_id=channel_id)
self.assertEqual(len(claims), 3)
# same is expected using name or name#claim_id urls
claims = await self.claim_search(channel_name="@abc")
self.assertEqual(len(claims), 3)
claims = await self.claim_search(channel_name="@abc", channel_id=channel_id)
self.assertEqual(len(claims), 3)
claims = await self.claim_search(channel_name=f"@abc#{channel_id}")
self.assertEqual(len(claims), 3)
await self.stream_abandon(claim_id=claims[0]['claim_id'])
await self.stream_abandon(claim_id=claims[1]['claim_id'])
@@ -679,8 +805,7 @@ class StreamCommands(CommandTestCase):
self.assertNotEqual(r1c, r2c)
await self.generate(50)
head = await self.daemon.jsonrpc_block_show()
self.assertTrue(head['height'] > 250)
self.assertTrue(self.ledger.headers.height > 250)
r3 = await self.daemon.jsonrpc_resolve(urls='lbry://ΣίσυφοςfiÆ')
r4 = await self.daemon.jsonrpc_resolve(urls='lbry://ΣΊΣΥΦΟσFIæ')
+1 -1
View File
@@ -29,7 +29,7 @@ class CLIIntegrationTest(AsyncioTestCase):
await self.daemon.start()
async def asyncTearDown(self):
await self.daemon.stop()
await self.daemon.stop(shutdown_runner=False)
def test_cli_status_command_with_auth(self):
actual_output = StringIO()
+93 -24
View File
@@ -1,7 +1,9 @@
import asyncio
import logging
import os
from binascii import unhexlify, hexlify
from lbrynet.schema import Claim
from lbrynet.testcase import CommandTestCase
from lbrynet.blob_exchange.downloader import BlobDownloader
@@ -26,6 +28,67 @@ class FileCommands(CommandTestCase):
await self.daemon.jsonrpc_get('lbry://foo')
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)
async def test_announces(self):
# announces on publish
self.assertEqual(await self.daemon.storage.get_blobs_to_announce(), [])
await self.stream_create('foo', '0.01')
stream = self.daemon.jsonrpc_file_list()[0]
self.assertSetEqual(
set(await self.daemon.storage.get_blobs_to_announce()),
{stream.sd_hash, stream.descriptor.blobs[0].blob_hash}
)
self.assertTrue(await self.daemon.jsonrpc_file_delete(delete_all=True))
# announces on download
self.assertEqual(await self.daemon.storage.get_blobs_to_announce(), [])
stream = await self.daemon.jsonrpc_get('foo')
self.assertSetEqual(
set(await self.daemon.storage.get_blobs_to_announce()),
{stream.sd_hash, stream.descriptor.blobs[0].blob_hash}
)
async def test_file_list_fields(self):
await self.stream_create('foo', '0.01')
file_list = self.sout(self.daemon.jsonrpc_file_list())
self.assertEqual(
file_list[0]['timestamp'],
None
)
self.assertEqual(file_list[0]['confirmations'], -1)
await self.daemon.jsonrpc_resolve('foo')
file_list = self.sout(self.daemon.jsonrpc_file_list())
self.assertEqual(
file_list[0]['timestamp'],
self.ledger.headers[file_list[0]['height']]['timestamp']
)
self.assertEqual(file_list[0]['confirmations'], 1)
async def test_get_doesnt_touch_user_written_files_between_calls(self):
await self.stream_create('foo', '0.01', data=bytes([0] * (2 << 23)))
self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'))
first_path = (await self.daemon.jsonrpc_get('lbry://foo', save_file=True)).full_path
await self.wait_files_to_complete()
self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'))
with open(first_path, 'wb') as f:
f.write(b' ')
f.flush()
second_path = await self.daemon.jsonrpc_get('lbry://foo', save_file=True)
await self.wait_files_to_complete()
self.assertNotEquals(first_path, second_path)
async def test_file_list_updated_metadata_on_resolve(self):
await self.stream_create('foo', '0.01')
claim = await self.daemon.resolve('lbry://foo')
claim = claim['lbry://foo']['claim']['protobuf'].decode()
await self.daemon.jsonrpc_file_delete(claim_name='foo')
txid = await self.blockchain_claim_name('bar', claim, '0.01')
await self.daemon.jsonrpc_get('lbry://bar')
claim = Claim.from_bytes(unhexlify(claim))
claim.stream.description = "fix typos, fix the world"
await self.blockchain_update_name(txid, hexlify(claim.to_bytes()).decode(), '0.01')
await self.daemon.jsonrpc_resolve('lbry://bar')
file_list = self.daemon.jsonrpc_file_list()
self.assertEqual(file_list[0].stream_claim_info.claim.stream.description, claim.stream.description)
async def test_download_different_timeouts(self):
tx = await self.stream_create('foo', '0.01')
sd_hash = tx['outputs'][0]['value']['source']['sd_hash']
@@ -34,14 +97,14 @@ class FileCommands(CommandTestCase):
blob_hash for blob_hash in self.server.blob_manager.completed_blob_hashes if blob_hash != sd_hash
]
await self.server.blob_manager.delete_blobs(all_except_sd)
resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2)
resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2, save_file=True)
self.assertIn('error', resp)
self.assertEquals('Failed to download data blobs for sd hash %s within timeout' % sd_hash, resp['error'])
await self.daemon.jsonrpc_file_delete(claim_name='foo')
self.assertEqual('Failed to download data blobs for sd hash %s within timeout' % sd_hash, resp['error'])
self.assertTrue(await self.daemon.jsonrpc_file_delete(claim_name='foo'), "data timeout didnt create a file")
await self.server.blob_manager.delete_blobs([sd_hash])
resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2)
resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2, save_file=True)
self.assertIn('error', resp)
self.assertEquals('Failed to download sd blob %s within timeout' % sd_hash, resp['error'])
self.assertEqual('Failed to download sd blob %s within timeout' % sd_hash, resp['error'])
async def wait_files_to_complete(self):
while self.sout(self.daemon.jsonrpc_file_list(status='running')):
@@ -59,17 +122,14 @@ class FileCommands(CommandTestCase):
await self.daemon.stream_manager.start()
await asyncio.wait_for(self.wait_files_to_complete(), timeout=5) # if this hangs, file didnt get set completed
# check that internal state got through up to the file list API
downloader = self.daemon.stream_manager.get_stream_by_stream_hash(file_info['stream_hash']).downloader
file_info = self.sout(self.daemon.jsonrpc_file_list())[0]
self.assertEqual(downloader.output_file_name, file_info['file_name'])
stream = self.daemon.stream_manager.get_stream_by_stream_hash(file_info['stream_hash'])
file_info = self.sout(self.daemon.jsonrpc_file_list()[0])
self.assertEqual(stream.file_name, file_info['file_name'])
# checks if what the API shows is what he have at the very internal level.
self.assertEqual(downloader.output_path, file_info['download_path'])
# if you got here refactoring just change above, but ensure what gets set internally gets reflected externally!
self.assertTrue(downloader.output_path.endswith(downloader.output_file_name))
# this used to be inconsistent, if it becomes again it would create weird bugs, so worth checking
self.assertEqual(stream.full_path, file_info['download_path'])
async def test_incomplete_downloads_erases_output_file_on_stop(self):
tx = await self.stream_create('foo', '0.01')
tx = await self.stream_create('foo', '0.01', data=b'deadbeef' * 1000000)
sd_hash = tx['outputs'][0]['value']['source']['sd_hash']
file_info = self.sout(self.daemon.jsonrpc_file_list())[0]
await self.daemon.jsonrpc_file_delete(claim_name='foo')
@@ -77,25 +137,27 @@ class FileCommands(CommandTestCase):
await self.server_storage.get_stream_hash_for_sd_hash(sd_hash)
)
all_except_sd_and_head = [
blob.blob_hash for blob in blobs[1:] if blob.blob_hash
blob.blob_hash for blob in blobs[1:-1]
]
await self.server.blob_manager.delete_blobs(all_except_sd_and_head)
self.assertFalse(os.path.isfile(os.path.join(self.daemon.conf.download_dir, file_info['file_name'])))
path = os.path.join(self.daemon.conf.download_dir, file_info['file_name'])
self.assertFalse(os.path.isfile(path))
resp = await self.out(self.daemon.jsonrpc_get('lbry://foo', timeout=2))
self.assertNotIn('error', resp)
self.assertTrue(os.path.isfile(os.path.join(self.daemon.conf.download_dir, file_info['file_name'])))
self.assertTrue(os.path.isfile(path))
self.daemon.stream_manager.stop()
self.assertFalse(os.path.isfile(os.path.join(self.daemon.conf.download_dir, file_info['file_name'])))
await asyncio.sleep(0.01, loop=self.loop) # FIXME: this sleep should not be needed
self.assertFalse(os.path.isfile(path))
async def test_incomplete_downloads_retry(self):
tx = await self.stream_create('foo', '0.01')
tx = await self.stream_create('foo', '0.01', data=b'deadbeef' * 1000000)
sd_hash = tx['outputs'][0]['value']['source']['sd_hash']
await self.daemon.jsonrpc_file_delete(claim_name='foo')
blobs = await self.server_storage.get_blobs_for_stream(
await self.server_storage.get_stream_hash_for_sd_hash(sd_hash)
)
all_except_sd_and_head = [
blob.blob_hash for blob in blobs[1:] if blob.blob_hash
blob.blob_hash for blob in blobs[1:-1]
]
# backup server blobs
@@ -127,7 +189,7 @@ class FileCommands(CommandTestCase):
self.assertEqual('finished', file_info['status'])
async def test_unban_recovers_stream(self):
BlobDownloader.BAN_TIME = .5 # fixme: temporary field, will move to connection manager or a conf
BlobDownloader.BAN_FACTOR = .5 # fixme: temporary field, will move to connection manager or a conf
tx = await self.stream_create('foo', '0.01', data=bytes([0] * (1 << 23)))
sd_hash = tx['outputs'][0]['value']['source']['sd_hash']
missing_blob_hash = (await self.daemon.jsonrpc_blob_list(sd_hash=sd_hash))[-2]
@@ -143,7 +205,7 @@ class FileCommands(CommandTestCase):
os.rename(missing_blob.file_path + '__', missing_blob.file_path)
self.server_blob_manager.blobs.clear()
missing_blob = self.server_blob_manager.get_blob(missing_blob_hash)
await self.server_blob_manager.blob_completed(missing_blob)
self.server_blob_manager.blob_completed(missing_blob)
await asyncio.wait_for(self.wait_files_to_complete(), timeout=1)
async def test_paid_download(self):
@@ -176,9 +238,9 @@ class FileCommands(CommandTestCase):
)
await self.daemon.jsonrpc_file_delete(claim_name='icanpay')
await self.assertBalance(self.account, '9.925679')
response = await self.out(self.daemon.jsonrpc_get('lbry://icanpay'))
self.assertNotIn('error', response)
await self.on_transaction_dict(response['tx'])
response = await self.daemon.jsonrpc_get('lbry://icanpay')
raw_content_fee = response.content_fee.raw
await self.ledger.wait(response.content_fee)
await self.assertBalance(self.account, '8.925555')
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)
@@ -191,3 +253,10 @@ class FileCommands(CommandTestCase):
self.assertEqual(
await self.blockchain.get_balance(), starting_balance + block_reward_and_claim_fee
)
# restart the daemon and make sure the fee is still there
self.daemon.stream_manager.stop()
await self.daemon.stream_manager.start()
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)
self.assertEqual(self.daemon.jsonrpc_file_list()[0].content_fee.raw, raw_content_fee)
+10 -3
View File
@@ -38,6 +38,14 @@ class ResolveCommand(CommandTestCase):
self.assertEqual(claim['claim']['channel_name'], '@abc')
self.assertEqual(claim['certificate']['name'], '@abc')
self.assertEqual(claim['claims_in_channel'], 0)
self.assertEqual(
claim['claim']['timestamp'],
self.ledger.headers[claim['claim']['height']]['timestamp']
)
self.assertEqual(
claim['certificate']['timestamp'],
self.ledger.headers[claim['certificate']['height']]['timestamp']
)
# resolving claim foo by itself
response = await self.resolve('lbry://foo')
@@ -65,14 +73,13 @@ class ResolveCommand(CommandTestCase):
self.assertEqual(claim['certificate']['name'], '@abc')
self.assertEqual(claim['claims_in_channel'], 0)
# resolve has correct depth
# resolve has correct confirmations
tx_details = await self.blockchain.get_raw_transaction(claim['claim']['txid'])
self.assertEqual(claim['claim']['depth'], json.loads(tx_details)['confirmations'])
self.assertEqual(claim['claim']['confirmations'], json.loads(tx_details)['confirmations'])
# resolve handles invalid data
txid = await self.blockchain_claim_name(
"gibberish", hexlify(b"{'invalid':'json'}").decode(), "0.1")
await self.generate(1)
response = await self.resolve("lbry://gibberish")
self.assertSetEqual({'lbry://gibberish'}, set(response))
claim = response['lbry://gibberish']['claim']
+366
View File
@@ -0,0 +1,366 @@
import os
import hashlib
import aiohttp
import aiohttp.web
from lbrynet.utils import aiohttp_request
from lbrynet.blob.blob_file import MAX_BLOB_SIZE
from lbrynet.testcase import CommandTestCase
def get_random_bytes(n: int) -> bytes:
result = b''.join(hashlib.sha256(os.urandom(4)).digest() for _ in range(n // 16))
if len(result) < n:
result += os.urandom(n - len(result))
elif len(result) > n:
result = result[:-(len(result) - n)]
assert len(result) == n, (n, len(result))
return result
class RangeRequests(CommandTestCase):
async def _restart_stream_manager(self):
self.daemon.stream_manager.stop()
await self.daemon.stream_manager.start()
return
async def _setup_stream(self, data: bytes, save_blobs: bool = True, save_files: bool = False, file_size=0):
self.daemon.conf.save_blobs = save_blobs
self.daemon.conf.save_files = save_files
self.data = data
await self.stream_create('foo', '0.01', data=self.data, file_size=file_size)
if save_blobs:
self.assertTrue(len(os.listdir(self.daemon.blob_manager.blob_dir)) > 1)
await self.daemon.jsonrpc_file_list()[0].fully_reflected.wait()
await self.daemon.jsonrpc_file_delete(delete_from_download_dir=True, claim_name='foo')
self.assertEqual(0, len(os.listdir(self.daemon.blob_manager.blob_dir)))
# await self._restart_stream_manager()
await self.daemon.runner.setup()
site = aiohttp.web.TCPSite(self.daemon.runner, self.daemon.conf.api_host, self.daemon.conf.api_port)
await site.start()
self.assertListEqual(self.daemon.jsonrpc_file_list(), [])
async def _test_range_requests(self):
name = 'foo'
url = f'http://{self.daemon.conf.api_host}:{self.daemon.conf.api_port}/get/{name}'
async with aiohttp_request('get', url) as req:
self.assertEqual(req.headers.get('Content-Type'), 'application/octet-stream')
content_range = req.headers.get('Content-Range')
content_length = int(req.headers.get('Content-Length'))
streamed_bytes = await req.content.read()
self.assertEqual(content_length, len(streamed_bytes))
return streamed_bytes, content_range, content_length
async def test_range_requests_2_byte(self):
self.data = b'hi'
await self._setup_stream(self.data)
streamed, content_range, content_length = await self._test_range_requests()
self.assertEqual(15, content_length)
self.assertEqual(b'hi\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', streamed)
self.assertEqual('bytes 0-14/15', content_range)
async def test_range_requests_15_byte(self):
self.data = b'123456789abcdef'
await self._setup_stream(self.data)
streamed, content_range, content_length = await self._test_range_requests()
self.assertEqual(15, content_length)
self.assertEqual(15, len(streamed))
self.assertEqual(self.data, streamed)
self.assertEqual('bytes 0-14/15', content_range)
async def test_range_requests_0_padded_bytes(self, size: int = (MAX_BLOB_SIZE - 1) * 4,
expected_range: str = 'bytes 0-8388603/8388604', padding=b'',
file_size=0):
self.data = get_random_bytes(size)
await self._setup_stream(self.data, file_size=file_size)
streamed, content_range, content_length = await self._test_range_requests()
self.assertEqual(len(self.data + padding), content_length)
self.assertEqual(streamed, self.data + padding)
self.assertEqual(expected_range, content_range)
async def test_range_requests_1_padded_bytes(self):
await self.test_range_requests_0_padded_bytes(
((MAX_BLOB_SIZE - 1) * 4) - 1, padding=b'\x00'
)
async def test_range_requests_2_padded_bytes(self):
await self.test_range_requests_0_padded_bytes(
((MAX_BLOB_SIZE - 1) * 4) - 2, padding=b'\x00' * 2
)
async def test_range_requests_14_padded_bytes(self):
await self.test_range_requests_0_padded_bytes(
((MAX_BLOB_SIZE - 1) * 4) - 14, padding=b'\x00' * 14
)
async def test_range_requests_no_padding_size_from_claim(self):
size = ((MAX_BLOB_SIZE - 1) * 4) - 14
await self.test_range_requests_0_padded_bytes(size, padding=b'', file_size=size,
expected_range=f"bytes 0-{size-1}/{size}")
async def test_range_requests_15_padded_bytes(self):
await self.test_range_requests_0_padded_bytes(
((MAX_BLOB_SIZE - 1) * 4) - 15, padding=b'\x00' * 15
)
async def test_range_requests_last_block_of_last_blob_padding(self):
self.data = get_random_bytes(((MAX_BLOB_SIZE - 1) * 4) - 16)
await self._setup_stream(self.data)
streamed, content_range, content_length = await self._test_range_requests()
self.assertEqual(len(self.data), content_length)
self.assertEqual(streamed, self.data)
self.assertEqual('bytes 0-8388587/8388588', content_range)
async def test_streaming_only_with_blobs(self):
self.data = get_random_bytes((MAX_BLOB_SIZE - 1) * 4)
await self._setup_stream(self.data)
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
# test that repeated range requests do not create duplicate files
for _ in range(3):
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
# test that a range request after restart does not create a duplicate file
await self._restart_stream_manager()
current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
stream = self.daemon.jsonrpc_file_list()[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
async def test_streaming_only_without_blobs(self):
self.data = get_random_bytes((MAX_BLOB_SIZE - 1) * 4)
await self._setup_stream(self.data, save_blobs=False)
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
# test that repeated range requests do not create duplicate files
for _ in range(3):
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
# test that a range request after restart does not create a duplicate file
await self._restart_stream_manager()
current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNone(stream.download_directory)
self.assertIsNone(stream.full_path)
current_files_in_download_dir = list(os.scandir(os.path.dirname(self.daemon.conf.data_dir)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
async def test_stream_and_save_file_with_blobs(self):
self.data = get_random_bytes((MAX_BLOB_SIZE - 1) * 4)
await self._setup_stream(self.data, save_files=True)
await self._test_range_requests()
streams = self.daemon.jsonrpc_file_list()
self.assertEqual(1, len(streams))
stream = streams[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
full_path = stream.full_path
files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
for _ in range(3):
await self._test_range_requests()
streams = self.daemon.jsonrpc_file_list()
self.assertEqual(1, len(streams))
stream = streams[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
current_files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
await self._restart_stream_manager()
current_files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
streams = self.daemon.jsonrpc_file_list()
self.assertEqual(1, len(streams))
stream = streams[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
await self._test_range_requests()
streams = self.daemon.jsonrpc_file_list()
self.assertEqual(1, len(streams))
stream = streams[0]
self.assertTrue(os.path.isfile(self.daemon.blob_manager.get_blob(stream.sd_hash).file_path))
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
current_files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
with open(stream.full_path, 'rb') as f:
self.assertEqual(self.data, f.read())
async def test_stream_and_save_file_without_blobs(self):
self.data = get_random_bytes((MAX_BLOB_SIZE - 1) * 4)
await self._setup_stream(self.data, save_files=True)
self.daemon.conf.save_blobs = False
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
full_path = stream.full_path
files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
for _ in range(3):
await self._test_range_requests()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
current_files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
await self._restart_stream_manager()
current_files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
streams = self.daemon.jsonrpc_file_list()
self.assertEqual(1, len(streams))
stream = streams[0]
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
await self._test_range_requests()
streams = self.daemon.jsonrpc_file_list()
self.assertEqual(1, len(streams))
stream = streams[0]
self.assertTrue(os.path.isdir(stream.download_directory))
self.assertTrue(os.path.isfile(stream.full_path))
current_files_in_download_dir = list(os.scandir(os.path.dirname(full_path)))
self.assertEqual(
len(files_in_download_dir), len(current_files_in_download_dir)
)
with open(stream.full_path, 'rb') as f:
self.assertEqual(self.data, f.read())
async def test_switch_save_blobs_while_running(self):
await self.test_streaming_only_without_blobs()
self.daemon.conf.save_blobs = True
blobs_in_stream = self.daemon.jsonrpc_file_list()[0].blobs_in_stream
sd_hash = self.daemon.jsonrpc_file_list()[0].sd_hash
start_file_count = len(os.listdir(self.daemon.blob_manager.blob_dir))
await self._test_range_requests()
self.assertEqual(start_file_count + blobs_in_stream, len(os.listdir(self.daemon.blob_manager.blob_dir)))
self.assertEqual(0, self.daemon.jsonrpc_file_list()[0].blobs_remaining)
# switch back
self.daemon.conf.save_blobs = False
await self._test_range_requests()
self.assertEqual(start_file_count + blobs_in_stream, len(os.listdir(self.daemon.blob_manager.blob_dir)))
self.assertEqual(0, self.daemon.jsonrpc_file_list()[0].blobs_remaining)
await self.daemon.jsonrpc_file_delete(delete_from_download_dir=True, sd_hash=sd_hash)
self.assertEqual(start_file_count, len(os.listdir(self.daemon.blob_manager.blob_dir)))
await self._test_range_requests()
self.assertEqual(start_file_count, len(os.listdir(self.daemon.blob_manager.blob_dir)))
self.assertEqual(blobs_in_stream, self.daemon.jsonrpc_file_list()[0].blobs_remaining)
async def test_file_save_streaming_only_save_blobs(self):
await self.test_streaming_only_with_blobs()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNone(stream.full_path)
self.server.stop_server()
await self.daemon.jsonrpc_file_save('test', self.daemon.conf.data_dir)
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNotNone(stream.full_path)
await stream.finished_writing.wait()
with open(stream.full_path, 'rb') as f:
self.assertEqual(self.data, f.read())
await self.daemon.jsonrpc_file_delete(delete_from_download_dir=True, sd_hash=stream.sd_hash)
async def test_file_save_stop_before_finished_streaming_only(self, wait_for_start_writing=False):
await self.test_streaming_only_with_blobs()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNone(stream.full_path)
self.server.stop_server()
await self.daemon.jsonrpc_file_save('test', self.daemon.conf.data_dir)
stream = self.daemon.jsonrpc_file_list()[0]
path = stream.full_path
self.assertIsNotNone(path)
if wait_for_start_writing:
await stream.started_writing.wait()
self.assertTrue(os.path.isfile(path))
await self._restart_stream_manager()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNotNone(stream.full_path)
self.assertFalse(os.path.isfile(path))
if wait_for_start_writing:
await stream.started_writing.wait()
self.assertTrue(os.path.isfile(path))
async def test_file_save_stop_before_finished_streaming_only_wait_for_start(self):
return await self.test_file_save_stop_before_finished_streaming_only(wait_for_start_writing=True)
async def test_file_save_streaming_only_dont_save_blobs(self):
await self.test_streaming_only_without_blobs()
stream = self.daemon.jsonrpc_file_list()[0]
self.assertIsNone(stream.full_path)
await self.daemon.jsonrpc_file_save('test', self.daemon.conf.data_dir)
stream = self.daemon.jsonrpc_file_list()[0]
await stream.finished_writing.wait()
with open(stream.full_path, 'rb') as f:
self.assertEqual(self.data, f.read())
+1 -1
View File
@@ -54,7 +54,7 @@ class AccountSynchronization(AsyncioTestCase):
async def asyncTearDown(self):
self.wallet_component._running = False
await self.daemon.stop()
await self.daemon.stop(shutdown_runner=False)
@mock.patch('time.time', mock.Mock(return_value=12345))
def test_sync(self):
+209 -20
View File
@@ -3,34 +3,223 @@ import tempfile
import shutil
import os
from torba.testcase import AsyncioTestCase
from lbrynet.error import InvalidDataError, InvalidBlobHashError
from lbrynet.conf import Config
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob.blob_file import BlobFile, BlobBuffer, AbstractBlob
class TestBlobfile(AsyncioTestCase):
async def test_create_blob(self):
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
class TestBlob(AsyncioTestCase):
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
async def asyncSetUp(self):
self.tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(self.tmp_dir))
self.loop = asyncio.get_running_loop()
self.config = Config()
self.storage = SQLiteStorage(self.config, ":memory:", self.loop)
self.blob_manager = BlobManager(self.loop, self.tmp_dir, self.storage, self.config)
await self.storage.open()
def _get_blob(self, blob_class=AbstractBlob, blob_directory=None):
blob = blob_class(self.loop, self.blob_hash, len(self.blob_bytes), self.blob_manager.blob_completed,
blob_directory=blob_directory)
self.assertFalse(blob.get_is_verified())
self.addCleanup(blob.close)
return blob
async def _test_create_blob(self, blob_class=AbstractBlob, blob_directory=None):
blob = self._get_blob(blob_class, blob_directory)
writer = blob.get_blob_writer()
writer.write(self.blob_bytes)
await blob.verified.wait()
self.assertTrue(blob.get_is_verified())
await asyncio.sleep(0, loop=self.loop) # wait for the db save task
return blob
async def _test_close_writers_on_finished(self, blob_class=AbstractBlob, blob_directory=None):
blob = self._get_blob(blob_class, blob_directory=blob_directory)
writers = [blob.get_blob_writer('1.2.3.4', port) for port in range(5)]
self.assertEqual(5, len(blob.writers))
# test that writing too much causes the writer to fail with InvalidDataError and to be removed
with self.assertRaises(InvalidDataError):
writers[1].write(self.blob_bytes * 2)
await writers[1].finished
await asyncio.sleep(0, loop=self.loop)
self.assertEqual(4, len(blob.writers))
# write the blob
other = writers[2]
writers[3].write(self.blob_bytes)
await blob.verified.wait()
self.assertTrue(blob.get_is_verified())
self.assertEqual(0, len(blob.writers))
with self.assertRaises(IOError):
other.write(self.blob_bytes)
def _test_ioerror_if_length_not_set(self, blob_class=AbstractBlob, blob_directory=None):
blob = blob_class(
self.loop, self.blob_hash, blob_completed_callback=self.blob_manager.blob_completed,
blob_directory=blob_directory
)
self.addCleanup(blob.close)
writer = blob.get_blob_writer()
with self.assertRaises(IOError):
writer.write(b'')
async def _test_invalid_blob_bytes(self, blob_class=AbstractBlob, blob_directory=None):
blob = blob_class(
self.loop, self.blob_hash, len(self.blob_bytes), blob_completed_callback=self.blob_manager.blob_completed,
blob_directory=blob_directory
)
self.addCleanup(blob.close)
writer = blob.get_blob_writer()
writer.write(self.blob_bytes[:-4] + b'fake')
with self.assertRaises(InvalidBlobHashError):
await writer.finished
async def test_add_blob_buffer_to_db(self):
blob = await self._test_create_blob(BlobBuffer)
db_status = await self.storage.get_blob_status(blob.blob_hash)
self.assertEqual(db_status, 'pending')
async def test_add_blob_file_to_db(self):
blob = await self._test_create_blob(BlobFile, self.tmp_dir)
db_status = await self.storage.get_blob_status(blob.blob_hash)
self.assertEqual(db_status, 'finished')
async def test_invalid_blob_bytes(self):
await self._test_invalid_blob_bytes(BlobBuffer)
await self._test_invalid_blob_bytes(BlobFile, self.tmp_dir)
def test_ioerror_if_length_not_set(self):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
self._test_ioerror_if_length_not_set(BlobBuffer)
self._test_ioerror_if_length_not_set(BlobFile, tmp_dir)
async def test_create_blob_file(self):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
blob = await self._test_create_blob(BlobFile, tmp_dir)
self.assertIsInstance(blob, BlobFile)
self.assertTrue(os.path.isfile(blob.file_path))
for _ in range(2):
with blob.reader_context() as reader:
self.assertEqual(self.blob_bytes, reader.read())
async def test_create_blob_buffer(self):
blob = await self._test_create_blob(BlobBuffer)
self.assertIsInstance(blob, BlobBuffer)
self.assertIsNotNone(blob._verified_bytes)
# check we can only read the bytes once, and that the buffer is torn down
with blob.reader_context() as reader:
self.assertEqual(self.blob_bytes, reader.read())
self.assertIsNone(blob._verified_bytes)
with self.assertRaises(OSError):
with blob.reader_context() as reader:
self.assertEqual(self.blob_bytes, reader.read())
self.assertIsNone(blob._verified_bytes)
async def test_close_writers_on_finished(self):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
await self._test_close_writers_on_finished(BlobBuffer)
await self._test_close_writers_on_finished(BlobFile, tmp_dir)
async def test_concurrency_and_premature_closes(self):
blob_directory = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(blob_directory))
blob = self._get_blob(BlobBuffer, blob_directory=blob_directory)
writer = blob.get_blob_writer('1.1.1.1', 1337)
self.assertEqual(1, len(blob.writers))
with self.assertRaises(OSError):
blob.get_blob_writer('1.1.1.1', 1337)
writer.close_handle()
self.assertTrue(blob.writers[('1.1.1.1', 1337)].closed())
writer = blob.get_blob_writer('1.1.1.1', 1337)
self.assertEqual(blob.writers[('1.1.1.1', 1337)], writer)
writer.close_handle()
await asyncio.sleep(0.000000001) # flush callbacks
self.assertEqual(0, len(blob.writers))
async def test_delete(self):
blob_buffer = await self._test_create_blob(BlobBuffer)
self.assertIsInstance(blob_buffer, BlobBuffer)
self.assertIsNotNone(blob_buffer._verified_bytes)
self.assertTrue(blob_buffer.get_is_verified())
blob_buffer.delete()
self.assertIsNone(blob_buffer._verified_bytes)
self.assertFalse(blob_buffer.get_is_verified())
loop = asyncio.get_event_loop()
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
storage = SQLiteStorage(Config(), os.path.join(tmp_dir, "lbrynet.sqlite"))
blob_manager = BlobFileManager(loop, tmp_dir, storage)
blob_file = await self._test_create_blob(BlobFile, tmp_dir)
self.assertIsInstance(blob_file, BlobFile)
self.assertTrue(os.path.isfile(blob_file.file_path))
self.assertTrue(blob_file.get_is_verified())
blob_file.delete()
self.assertFalse(os.path.isfile(blob_file.file_path))
self.assertFalse(blob_file.get_is_verified())
await storage.open()
await blob_manager.setup()
async def test_delete_corrupt(self):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
blob = BlobFile(
self.loop, self.blob_hash, len(self.blob_bytes), blob_completed_callback=self.blob_manager.blob_completed,
blob_directory=tmp_dir
)
writer = blob.get_blob_writer()
writer.write(self.blob_bytes)
await blob.verified.wait()
blob.close()
blob = BlobFile(
self.loop, self.blob_hash, len(self.blob_bytes), blob_completed_callback=self.blob_manager.blob_completed,
blob_directory=tmp_dir
)
self.assertTrue(blob.get_is_verified())
# add the blob on the server
blob = blob_manager.get_blob(blob_hash, len(blob_bytes))
self.assertEqual(blob.get_is_verified(), False)
self.assertNotIn(blob_hash, blob_manager.completed_blob_hashes)
with open(blob.file_path, 'wb+') as f:
f.write(b'\x00')
blob = BlobFile(
self.loop, self.blob_hash, len(self.blob_bytes), blob_completed_callback=self.blob_manager.blob_completed,
blob_directory=tmp_dir
)
self.assertFalse(blob.get_is_verified())
self.assertFalse(os.path.isfile(blob.file_path))
writer = blob.open_for_writing()
writer.write(blob_bytes)
await blob.finished_writing.wait()
self.assertTrue(os.path.isfile(blob.file_path), True)
self.assertEqual(blob.get_is_verified(), True)
self.assertIn(blob_hash, blob_manager.completed_blob_hashes)
def test_invalid_blob_hash(self):
self.assertRaises(InvalidBlobHashError, BlobBuffer, self.loop, '', len(self.blob_bytes))
self.assertRaises(InvalidBlobHashError, BlobBuffer, self.loop, 'x' * 96, len(self.blob_bytes))
self.assertRaises(InvalidBlobHashError, BlobBuffer, self.loop, 'a' * 97, len(self.blob_bytes))
async def _test_close_reader(self, blob_class=AbstractBlob, blob_directory=None):
blob = await self._test_create_blob(blob_class, blob_directory)
reader = blob.reader_context()
self.assertEqual(0, len(blob.readers))
async def read_blob_buffer():
with reader as read_handle:
self.assertEqual(1, len(blob.readers))
await asyncio.sleep(2, loop=self.loop)
self.assertEqual(0, len(blob.readers))
return read_handle.read()
self.loop.call_later(1, blob.close)
with self.assertRaises(ValueError) as err:
read_task = self.loop.create_task(read_blob_buffer())
await read_task
self.assertEqual(err.exception, ValueError("I/O operation on closed file"))
async def test_close_reader(self):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
await self._test_close_reader(BlobBuffer)
await self._test_close_reader(BlobFile, tmp_dir)
+23 -20
View File
@@ -5,50 +5,53 @@ import os
from torba.testcase import AsyncioTestCase
from lbrynet.conf import Config
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
class TestBlobManager(AsyncioTestCase):
async def test_sync_blob_manager_on_startup(self):
loop = asyncio.get_event_loop()
async def setup_blob_manager(self, save_blobs=True):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
self.config = Config(save_blobs=save_blobs)
self.storage = SQLiteStorage(self.config, os.path.join(tmp_dir, "lbrynet.sqlite"))
self.blob_manager = BlobManager(self.loop, tmp_dir, self.storage, self.config)
await self.storage.open()
storage = SQLiteStorage(Config(), os.path.join(tmp_dir, "lbrynet.sqlite"))
blob_manager = BlobFileManager(loop, tmp_dir, storage)
async def test_sync_blob_file_manager_on_startup(self):
await self.setup_blob_manager(save_blobs=True)
# add a blob file
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
with open(os.path.join(blob_manager.blob_dir, blob_hash), 'wb') as f:
with open(os.path.join(self.blob_manager.blob_dir, blob_hash), 'wb') as f:
f.write(blob_bytes)
# it should not have been added automatically on startup
await storage.open()
await blob_manager.setup()
self.assertSetEqual(blob_manager.completed_blob_hashes, set())
await self.blob_manager.setup()
self.assertSetEqual(self.blob_manager.completed_blob_hashes, set())
# make sure we can add the blob
await blob_manager.blob_completed(blob_manager.get_blob(blob_hash, len(blob_bytes)))
self.assertSetEqual(blob_manager.completed_blob_hashes, {blob_hash})
await self.blob_manager.blob_completed(self.blob_manager.get_blob(blob_hash, len(blob_bytes)))
self.assertSetEqual(self.blob_manager.completed_blob_hashes, {blob_hash})
# stop the blob manager and restart it, make sure the blob is there
blob_manager.stop()
self.assertSetEqual(blob_manager.completed_blob_hashes, set())
await blob_manager.setup()
self.assertSetEqual(blob_manager.completed_blob_hashes, {blob_hash})
self.blob_manager.stop()
self.assertSetEqual(self.blob_manager.completed_blob_hashes, set())
await self.blob_manager.setup()
self.assertSetEqual(self.blob_manager.completed_blob_hashes, {blob_hash})
# test that the blob is removed upon the next startup after the file being manually deleted
blob_manager.stop()
self.blob_manager.stop()
# manually delete the blob file and restart the blob manager
os.remove(os.path.join(blob_manager.blob_dir, blob_hash))
await blob_manager.setup()
self.assertSetEqual(blob_manager.completed_blob_hashes, set())
os.remove(os.path.join(self.blob_manager.blob_dir, blob_hash))
await self.blob_manager.setup()
self.assertSetEqual(self.blob_manager.completed_blob_hashes, set())
# check that the deleted blob was updated in the database
self.assertEqual(
'pending', (
await storage.run_and_return_one_or_none('select status from blob where blob_hash=?', blob_hash)
await self.storage.run_and_return_one_or_none('select status from blob where blob_hash=?', blob_hash)
)
)
+83 -17
View File
@@ -9,9 +9,9 @@ from lbrynet.blob_exchange.serialization import BlobRequest
from torba.testcase import AsyncioTestCase
from lbrynet.conf import Config
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.blob_exchange.server import BlobServer, BlobServerProtocol
from lbrynet.blob_exchange.client import BlobExchangeClientProtocol, request_blob
from lbrynet.blob_exchange.client import request_blob
from lbrynet.dht.peer import KademliaPeer, PeerManager
# import logging
@@ -35,13 +35,13 @@ class BlobExchangeTestBase(AsyncioTestCase):
self.server_config = Config(data_dir=self.server_dir, download_dir=self.server_dir, wallet=self.server_dir,
reflector_servers=[])
self.server_storage = SQLiteStorage(self.server_config, os.path.join(self.server_dir, "lbrynet.sqlite"))
self.server_blob_manager = BlobFileManager(self.loop, self.server_dir, self.server_storage)
self.server_blob_manager = BlobManager(self.loop, self.server_dir, self.server_storage, self.server_config)
self.server = BlobServer(self.loop, self.server_blob_manager, 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
self.client_config = Config(data_dir=self.client_dir, download_dir=self.client_dir, wallet=self.client_dir,
reflector_servers=[])
self.client_storage = SQLiteStorage(self.client_config, os.path.join(self.client_dir, "lbrynet.sqlite"))
self.client_blob_manager = BlobFileManager(self.loop, self.client_dir, self.client_storage)
self.client_blob_manager = BlobManager(self.loop, self.client_dir, self.client_storage, self.client_config)
self.client_peer_manager = PeerManager(self.loop)
self.server_from_client = KademliaPeer(self.loop, "127.0.0.1", b'1' * 48, tcp_port=33333)
@@ -51,6 +51,7 @@ class BlobExchangeTestBase(AsyncioTestCase):
await self.server_blob_manager.setup()
self.server.start_server(33333, '127.0.0.1')
self.addCleanup(self.server.stop_server)
await self.server.started_listening.wait()
@@ -58,21 +59,25 @@ class TestBlobExchange(BlobExchangeTestBase):
async def _add_blob_to_server(self, blob_hash: str, blob_bytes: bytes):
# add the blob on the server
server_blob = self.server_blob_manager.get_blob(blob_hash, len(blob_bytes))
writer = server_blob.open_for_writing()
writer = server_blob.get_blob_writer()
writer.write(blob_bytes)
await server_blob.finished_writing.wait()
await server_blob.verified.wait()
self.assertTrue(os.path.isfile(server_blob.file_path))
self.assertEqual(server_blob.get_is_verified(), True)
self.assertTrue(writer.closed())
async def _test_transfer_blob(self, blob_hash: str):
client_blob = self.client_blob_manager.get_blob(blob_hash)
# download the blob
downloaded = await request_blob(self.loop, client_blob, self.server_from_client.address,
self.server_from_client.tcp_port, 2, 3)
await client_blob.finished_writing.wait()
downloaded, transport = await request_blob(self.loop, client_blob, self.server_from_client.address,
self.server_from_client.tcp_port, 2, 3)
self.assertIsNotNone(transport)
self.addCleanup(transport.close)
await client_blob.verified.wait()
self.assertEqual(client_blob.get_is_verified(), True)
self.assertTrue(downloaded)
client_blob.close()
async def test_transfer_sd_blob(self):
sd_hash = "3e2706157a59aaa47ef52bc264fce488078b4026c0b9bab649a8f2fe1ecc5e5cad7182a2bb7722460f856831a1ac0f02"
@@ -92,9 +97,11 @@ class TestBlobExchange(BlobExchangeTestBase):
second_client_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, second_client_dir)
second_client_storage = SQLiteStorage(Config(), os.path.join(second_client_dir, "lbrynet.sqlite"))
second_client_blob_manager = BlobFileManager(self.loop, second_client_dir, second_client_storage)
second_client_conf = Config()
second_client_storage = SQLiteStorage(second_client_conf, os.path.join(second_client_dir, "lbrynet.sqlite"))
second_client_blob_manager = BlobManager(
self.loop, second_client_dir, second_client_storage, second_client_conf
)
server_from_second_client = KademliaPeer(self.loop, "127.0.0.1", b'1' * 48, tcp_port=33333)
await second_client_storage.open()
@@ -102,7 +109,7 @@ class TestBlobExchange(BlobExchangeTestBase):
await self._add_blob_to_server(blob_hash, mock_blob_bytes)
second_client_blob = self.client_blob_manager.get_blob(blob_hash)
second_client_blob = second_client_blob_manager.get_blob(blob_hash)
# download the blob
await asyncio.gather(
@@ -112,9 +119,65 @@ class TestBlobExchange(BlobExchangeTestBase):
),
self._test_transfer_blob(blob_hash)
)
await second_client_blob.finished_writing.wait()
await second_client_blob.verified.wait()
self.assertEqual(second_client_blob.get_is_verified(), True)
async def test_blob_writers_concurrency(self):
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
mock_blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
blob = self.server_blob_manager.get_blob(blob_hash)
write_blob = blob._write_blob
write_called_count = 0
def wrap_write_blob(blob_bytes):
nonlocal write_called_count
write_called_count += 1
write_blob(blob_bytes)
blob._write_blob = wrap_write_blob
writer1 = blob.get_blob_writer(peer_port=1)
writer2 = blob.get_blob_writer(peer_port=2)
reader1_ctx_before_write = blob.reader_context()
with self.assertRaises(OSError):
blob.get_blob_writer(peer_port=2)
with self.assertRaises(OSError):
with blob.reader_context():
pass
blob.set_length(len(mock_blob_bytes))
results = {}
def check_finished_callback(writer, num):
def inner(writer_future: asyncio.Future):
results[num] = writer_future.result()
writer.finished.add_done_callback(inner)
check_finished_callback(writer1, 1)
check_finished_callback(writer2, 2)
def write_task(writer):
async def _inner():
writer.write(mock_blob_bytes)
return self.loop.create_task(_inner())
await asyncio.gather(write_task(writer1), write_task(writer2), loop=self.loop)
self.assertDictEqual({1: mock_blob_bytes, 2: mock_blob_bytes}, results)
self.assertEqual(1, write_called_count)
self.assertTrue(blob.get_is_verified())
self.assertDictEqual({}, blob.writers)
with reader1_ctx_before_write as f:
self.assertEqual(mock_blob_bytes, f.read())
with blob.reader_context() as f:
self.assertEqual(mock_blob_bytes, f.read())
with blob.reader_context() as f:
blob.close()
with self.assertRaises(ValueError):
f.read()
self.assertListEqual([], blob.readers)
async def test_host_different_blobs_to_multiple_peers_at_once(self):
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
mock_blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
@@ -124,9 +187,12 @@ class TestBlobExchange(BlobExchangeTestBase):
second_client_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, second_client_dir)
second_client_conf = Config()
second_client_storage = SQLiteStorage(Config(), os.path.join(second_client_dir, "lbrynet.sqlite"))
second_client_blob_manager = BlobFileManager(self.loop, second_client_dir, second_client_storage)
second_client_storage = SQLiteStorage(second_client_conf, os.path.join(second_client_dir, "lbrynet.sqlite"))
second_client_blob_manager = BlobManager(
self.loop, second_client_dir, second_client_storage, second_client_conf
)
server_from_second_client = KademliaPeer(self.loop, "127.0.0.1", b'1' * 48, tcp_port=33333)
await second_client_storage.open()
@@ -143,7 +209,7 @@ class TestBlobExchange(BlobExchangeTestBase):
server_from_second_client.tcp_port, 2, 3
),
self._test_transfer_blob(sd_hash),
second_client_blob.finished_writing.wait()
second_client_blob.verified.wait()
)
self.assertEqual(second_client_blob.get_is_verified(), True)
+76 -2
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from lbrynet import utils
import unittest
import asyncio
from lbrynet import utils
from torba.testcase import AsyncioTestCase
class CompareVersionTest(unittest.TestCase):
@@ -61,3 +62,76 @@ class SdHashTests(unittest.TestCase):
}
}
self.assertIsNone(utils.get_sd_hash(claim))
class CacheConcurrentDecoratorTests(AsyncioTestCase):
def setUp(self):
self.called = []
self.finished = []
self.counter = 0
@utils.cache_concurrent
async def foo(self, arg1, arg2=None, delay=1):
self.called.append((arg1, arg2, delay))
await asyncio.sleep(delay, loop=self.loop)
self.counter += 1
self.finished.append((arg1, arg2, delay))
return object()
async def test_gather_duplicates(self):
result = await asyncio.gather(
self.loop.create_task(self.foo(1)), self.loop.create_task(self.foo(1)), loop=self.loop
)
self.assertEqual(1, len(self.called))
self.assertEqual(1, len(self.finished))
self.assertEqual(1, self.counter)
self.assertIs(result[0], result[1])
self.assertEqual(2, len(result))
async def test_one_cancelled_all_cancel(self):
t1 = self.loop.create_task(self.foo(1))
self.loop.call_later(0.1, t1.cancel)
with self.assertRaises(asyncio.CancelledError):
await asyncio.gather(
t1, self.loop.create_task(self.foo(1)), loop=self.loop
)
self.assertEqual(1, len(self.called))
self.assertEqual(0, len(self.finished))
self.assertEqual(0, self.counter)
async def test_error_after_success(self):
def cause_type_error():
self.counter = ""
self.loop.call_later(0.1, cause_type_error)
t1 = self.loop.create_task(self.foo(1))
t2 = self.loop.create_task(self.foo(1))
with self.assertRaises(TypeError):
await t2
self.assertEqual(1, len(self.called))
self.assertEqual(0, len(self.finished))
self.assertTrue(t1.done())
self.assertEqual("", self.counter)
# test that the task is run fresh, it should not error
self.counter = 0
t3 = self.loop.create_task(self.foo(1))
self.assertTrue((await t3))
self.assertEqual(1, self.counter)
# the previously failed call should still raise if awaited
with self.assertRaises(TypeError):
await t1
self.assertEqual(1, self.counter)
async def test_break_it(self):
t1 = self.loop.create_task(self.foo(1))
t2 = self.loop.create_task(self.foo(1))
t3 = self.loop.create_task(self.foo(2, delay=0))
t3.add_done_callback(lambda _: t2.cancel())
with self.assertRaises(asyncio.CancelledError):
await asyncio.gather(t1, t2, t3)
+5 -4
View File
@@ -7,7 +7,7 @@ from torba.testcase import AsyncioTestCase
from lbrynet.conf import Config
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_info import BlobInfo
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.stream.descriptor import StreamDescriptor
from tests.test_utils import random_lbry_hash
@@ -68,17 +68,18 @@ fake_claim_info = {
class StorageTest(AsyncioTestCase):
async def asyncSetUp(self):
self.storage = SQLiteStorage(Config(), ':memory:')
self.conf = Config()
self.storage = SQLiteStorage(self.conf, ':memory:')
self.blob_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.blob_dir)
self.blob_manager = BlobFileManager(asyncio.get_event_loop(), self.blob_dir, self.storage)
self.blob_manager = BlobManager(asyncio.get_event_loop(), self.blob_dir, self.storage, self.conf)
await self.storage.open()
async def asyncTearDown(self):
await self.storage.close()
async def store_fake_blob(self, blob_hash, length=100):
await self.storage.add_completed_blob(blob_hash, length)
await self.storage.add_blobs((blob_hash, length), finished=True)
async def store_fake_stream(self, stream_hash, blobs=None, file_name="fake_file", key="DEADBEEF"):
blobs = blobs or [BlobInfo(1, 100, "DEADBEEF", random_lbry_hash())]
@@ -17,10 +17,10 @@ class MockAsyncGen:
return self
async def __anext__(self):
await asyncio.sleep(self.delay, loop=self.loop)
if self.count > self.stop_cnt - 1:
raise StopAsyncIteration()
self.count += 1
await asyncio.sleep(self.delay, loop=self.loop)
return self.result
async def aclose(self):
@@ -48,6 +48,18 @@ class TestAsyncGeneratorJunction(AsyncioTestCase):
self.assertEqual(fast_gen.called_close, True)
self.assertEqual(slow_gen.called_close, True)
async def test_nothing_to_yield(self):
async def __nothing():
for _ in []:
yield self.fail("nada")
await self._test_junction([], __nothing())
async def test_fast_iteratiors(self):
async def __gotta_go_fast():
for _ in range(10):
yield 0
await self._test_junction([0]*40, __gotta_go_fast(), __gotta_go_fast(), __gotta_go_fast(), __gotta_go_fast())
@unittest.SkipTest
async def test_one_stopped_first(self):
expected_order = [1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2]
+4 -3
View File
@@ -1,12 +1,13 @@
import asyncio
from torba.testcase import AsyncioTestCase
from unittest import mock, TestCase
from lbrynet.dht.protocol.data_store import DictDataStore
from lbrynet.dht.peer import PeerManager
class DataStoreTests(AsyncioTestCase):
class DataStoreTests(TestCase):
def setUp(self):
self.loop = asyncio.get_event_loop()
self.loop = mock.Mock(spec=asyncio.BaseEventLoop)
self.loop.time = lambda: 0.0
self.peer_manager = PeerManager(self.loop)
self.data_store = DictDataStore(self.loop, self.peer_manager)
+3 -4
View File
@@ -78,15 +78,14 @@ class TestBlobAnnouncer(AsyncioTestCase):
blob2 = binascii.hexlify(b'2' * 48).decode()
async with self._test_network_context():
await self.storage.add_completed_blob(blob1, 1024)
await self.storage.add_completed_blob(blob2, 1024)
await self.storage.add_blobs((blob1, 1024), (blob2, 1024), finished=True)
await self.storage.db.execute(
"update blob set next_announce_time=0, should_announce=1 where blob_hash in (?, ?)",
(blob1, blob2)
)
to_announce = await self.storage.get_blobs_to_announce()
self.assertEqual(2, len(to_announce))
self.blob_announcer.start()
self.blob_announcer.start(batch_size=1) # so it covers batching logic
await self.advance(61.0)
to_announce = await self.storage.get_blobs_to_announce()
self.assertEqual(0, len(to_announce))
@@ -106,7 +105,7 @@ class TestBlobAnnouncer(AsyncioTestCase):
_, task = last.accumulate_peers(search_q, peer_q)
found_peers = await peer_q.get()
task.cancel()
await task
self.assertEqual(1, len(found_peers))
self.assertEqual(self.node.protocol.node_id, found_peers[0].node_id)
-117
View File
@@ -1,117 +0,0 @@
import os
import asyncio
import tempfile
import shutil
from torba.testcase import AsyncioTestCase
from lbrynet.conf import Config
from lbrynet.blob.blob_file import MAX_BLOB_SIZE
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.stream.assembler import StreamAssembler
from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.stream.stream_manager import StreamManager
class TestStreamAssembler(AsyncioTestCase):
def setUp(self):
self.loop = asyncio.get_event_loop()
self.key = b'deadbeef' * 4
self.cleartext = b'test'
async def test_create_and_decrypt_one_blob_stream(self, corrupt=False):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
self.storage = SQLiteStorage(Config(), ":memory:")
await self.storage.open()
self.blob_manager = BlobFileManager(self.loop, tmp_dir, self.storage)
download_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(download_dir))
# create the stream
file_path = os.path.join(tmp_dir, "test_file")
with open(file_path, 'wb') as f:
f.write(self.cleartext)
sd = await StreamDescriptor.create_stream(self.loop, tmp_dir, file_path, key=self.key)
# copy blob files
sd_hash = sd.calculate_sd_hash()
shutil.copy(os.path.join(tmp_dir, sd_hash), os.path.join(download_dir, sd_hash))
for blob_info in sd.blobs:
if blob_info.blob_hash:
shutil.copy(os.path.join(tmp_dir, blob_info.blob_hash), os.path.join(download_dir, blob_info.blob_hash))
if corrupt and blob_info.length == MAX_BLOB_SIZE:
with open(os.path.join(download_dir, blob_info.blob_hash), "rb+") as handle:
handle.truncate()
handle.flush()
downloader_storage = SQLiteStorage(Config(), os.path.join(download_dir, "lbrynet.sqlite"))
await downloader_storage.open()
# add the blobs to the blob table (this would happen upon a blob download finishing)
downloader_blob_manager = BlobFileManager(self.loop, download_dir, downloader_storage)
descriptor = await downloader_blob_manager.get_stream_descriptor(sd_hash)
# assemble the decrypted file
assembler = StreamAssembler(self.loop, downloader_blob_manager, descriptor.sd_hash)
await assembler.assemble_decrypted_stream(download_dir)
if corrupt:
return self.assertFalse(os.path.isfile(os.path.join(download_dir, "test_file")))
with open(os.path.join(download_dir, "test_file"), "rb") as f:
decrypted = f.read()
self.assertEqual(decrypted, self.cleartext)
self.assertEqual(True, self.blob_manager.get_blob(sd_hash).get_is_verified())
self.assertEqual(True, self.blob_manager.get_blob(descriptor.blobs[0].blob_hash).get_is_verified())
# its all blobs + sd blob - last blob, which is the same size as descriptor.blobs
self.assertEqual(len(descriptor.blobs), len(await downloader_storage.get_all_finished_blobs()))
self.assertEqual(
[descriptor.sd_hash, descriptor.blobs[0].blob_hash], await downloader_storage.get_blobs_to_announce()
)
await downloader_storage.close()
await self.storage.close()
async def test_create_and_decrypt_multi_blob_stream(self):
self.cleartext = b'test\n' * 20000000
await self.test_create_and_decrypt_one_blob_stream()
async def test_create_and_decrypt_padding(self):
for i in range(16):
self.cleartext = os.urandom((MAX_BLOB_SIZE*2) + i)
await self.test_create_and_decrypt_one_blob_stream()
for i in range(16):
self.cleartext = os.urandom((MAX_BLOB_SIZE*2) - i)
await self.test_create_and_decrypt_one_blob_stream()
async def test_create_and_decrypt_random(self):
self.cleartext = os.urandom(20000000)
await self.test_create_and_decrypt_one_blob_stream()
async def test_create_managed_stream_announces(self):
# setup a blob manager
storage = SQLiteStorage(Config(), ":memory:")
await storage.open()
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
blob_manager = BlobFileManager(self.loop, tmp_dir, storage)
stream_manager = StreamManager(self.loop, Config(), blob_manager, None, storage, None)
# create the stream
download_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(download_dir))
file_path = os.path.join(download_dir, "test_file")
with open(file_path, 'wb') as f:
f.write(b'testtest')
stream = await stream_manager.create_stream(file_path)
self.assertEqual(
[stream.sd_hash, stream.descriptor.blobs[0].blob_hash],
await storage.get_blobs_to_announce())
async def test_create_truncate_and_handle_stream(self):
self.cleartext = b'potato' * 1337 * 5279
# The purpose of this test is just to make sure it can finish even if a blob is corrupt/truncated
await asyncio.wait_for(self.test_create_and_decrypt_one_blob_stream(corrupt=True), timeout=5)
-102
View File
@@ -1,102 +0,0 @@
import os
import time
import unittest
from unittest import mock
import asyncio
from lbrynet.blob_exchange.serialization import BlobResponse
from lbrynet.blob_exchange.server import BlobServerProtocol
from lbrynet.conf import Config
from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.stream.downloader import StreamDownloader
from lbrynet.dht.node import Node
from lbrynet.dht.peer import KademliaPeer
from lbrynet.blob.blob_file import MAX_BLOB_SIZE
from tests.unit.blob_exchange.test_transfer_blob import BlobExchangeTestBase
class TestStreamDownloader(BlobExchangeTestBase):
async def setup_stream(self, blob_count: int = 10):
self.stream_bytes = b''
for _ in range(blob_count):
self.stream_bytes += os.urandom((MAX_BLOB_SIZE - 1))
# create the stream
file_path = os.path.join(self.server_dir, "test_file")
with open(file_path, 'wb') as f:
f.write(self.stream_bytes)
descriptor = await StreamDescriptor.create_stream(self.loop, self.server_blob_manager.blob_dir, file_path)
self.sd_hash = descriptor.calculate_sd_hash()
conf = Config(data_dir=self.server_dir, wallet_dir=self.server_dir, download_dir=self.server_dir,
reflector_servers=[])
self.downloader = StreamDownloader(self.loop, conf, self.client_blob_manager, self.sd_hash)
async def _test_transfer_stream(self, blob_count: int, mock_accumulate_peers=None):
await self.setup_stream(blob_count)
mock_node = mock.Mock(spec=Node)
def _mock_accumulate_peers(q1, q2):
async def _task():
pass
q2.put_nowait([self.server_from_client])
return q2, self.loop.create_task(_task())
mock_node.accumulate_peers = mock_accumulate_peers or _mock_accumulate_peers
self.downloader.download(mock_node)
await self.downloader.stream_finished_event.wait()
self.assertTrue(self.downloader.stream_handle.closed)
self.assertTrue(os.path.isfile(self.downloader.output_path))
self.downloader.stop()
self.assertIs(self.downloader.stream_handle, None)
self.assertTrue(os.path.isfile(self.downloader.output_path))
with open(self.downloader.output_path, 'rb') as f:
self.assertEqual(f.read(), self.stream_bytes)
await asyncio.sleep(0.01)
async def test_transfer_stream(self):
await self._test_transfer_stream(10)
@unittest.SkipTest
async def test_transfer_hundred_blob_stream(self):
await self._test_transfer_stream(100)
async def test_transfer_stream_bad_first_peer_good_second(self):
await self.setup_stream(2)
mock_node = mock.Mock(spec=Node)
q = asyncio.Queue()
bad_peer = KademliaPeer(self.loop, "127.0.0.1", b'2' * 48, tcp_port=3334)
def _mock_accumulate_peers(q1, q2):
async def _task():
pass
q2.put_nowait([bad_peer])
self.loop.call_later(1, q2.put_nowait, [self.server_from_client])
return q2, self.loop.create_task(_task())
mock_node.accumulate_peers = _mock_accumulate_peers
self.downloader.download(mock_node)
await self.downloader.stream_finished_event.wait()
self.assertTrue(os.path.isfile(self.downloader.output_path))
with open(self.downloader.output_path, 'rb') as f:
self.assertEqual(f.read(), self.stream_bytes)
# self.assertIs(self.server_from_client.tcp_last_down, None)
# self.assertIsNot(bad_peer.tcp_last_down, None)
async def test_client_chunked_response(self):
self.server.stop_server()
class ChunkedServerProtocol(BlobServerProtocol):
def send_response(self, responses):
to_send = []
while responses:
to_send.append(responses.pop())
for byte in BlobResponse(to_send).serialize():
self.transport.write(bytes([byte]))
self.server.server_protocol_class = ChunkedServerProtocol
self.server.start_server(33333, '127.0.0.1')
self.assertEqual(0, len(self.client_blob_manager.completed_blob_hashes))
await asyncio.wait_for(self._test_transfer_stream(10), timeout=2)
self.assertEqual(11, len(self.client_blob_manager.completed_blob_hashes))
+170
View File
@@ -0,0 +1,170 @@
import os
import shutil
import unittest
from unittest import mock
import asyncio
from lbrynet.blob.blob_file import MAX_BLOB_SIZE
from lbrynet.blob_exchange.serialization import BlobResponse
from lbrynet.blob_exchange.server import BlobServerProtocol
from lbrynet.dht.node import Node
from lbrynet.dht.peer import KademliaPeer
from lbrynet.extras.daemon.storage import StoredStreamClaim
from lbrynet.stream.managed_stream import ManagedStream
from lbrynet.stream.descriptor import StreamDescriptor
from tests.unit.blob_exchange.test_transfer_blob import BlobExchangeTestBase
def get_mock_node(loop):
mock_node = mock.Mock(spec=Node)
mock_node.joined = asyncio.Event(loop=loop)
mock_node.joined.set()
return mock_node
class TestManagedStream(BlobExchangeTestBase):
async def create_stream(self, blob_count: int = 10):
self.stream_bytes = b''
for _ in range(blob_count):
self.stream_bytes += os.urandom((MAX_BLOB_SIZE - 1))
# create the stream
file_path = os.path.join(self.server_dir, "test_file")
with open(file_path, 'wb') as f:
f.write(self.stream_bytes)
descriptor = await StreamDescriptor.create_stream(self.loop, self.server_blob_manager.blob_dir, file_path)
self.sd_hash = descriptor.calculate_sd_hash()
return descriptor
async def setup_stream(self, blob_count: int = 10):
await self.create_stream(blob_count)
self.stream = ManagedStream(
self.loop, self.client_config, self.client_blob_manager, self.sd_hash, self.client_dir
)
async def _test_transfer_stream(self, blob_count: int, mock_accumulate_peers=None, stop_when_done=True):
await self.setup_stream(blob_count)
mock_node = mock.Mock(spec=Node)
def _mock_accumulate_peers(q1, q2):
async def _task():
pass
q2.put_nowait([self.server_from_client])
return q2, self.loop.create_task(_task())
mock_node.accumulate_peers = mock_accumulate_peers or _mock_accumulate_peers
await self.stream.save_file(node=mock_node)
await self.stream.finished_writing.wait()
self.assertTrue(os.path.isfile(self.stream.full_path))
if stop_when_done:
await self.stream.stop()
self.assertTrue(os.path.isfile(self.stream.full_path))
with open(self.stream.full_path, 'rb') as f:
self.assertEqual(f.read(), self.stream_bytes)
await asyncio.sleep(0.01)
async def test_transfer_stream(self):
await self._test_transfer_stream(10)
self.assertEqual(self.stream.status, "finished")
self.assertFalse(self.stream._running.is_set())
async def test_delayed_stop(self):
await self._test_transfer_stream(10, stop_when_done=False)
self.assertEqual(self.stream.status, "finished")
self.assertTrue(self.stream._running.is_set())
await asyncio.sleep(0.5, loop=self.loop)
self.assertTrue(self.stream._running.is_set())
await asyncio.sleep(0.6, loop=self.loop)
self.assertEqual(self.stream.status, "finished")
self.assertFalse(self.stream._running.is_set())
@unittest.SkipTest
async def test_transfer_hundred_blob_stream(self):
await self._test_transfer_stream(100)
async def test_transfer_stream_bad_first_peer_good_second(self):
await self.setup_stream(2)
mock_node = mock.Mock(spec=Node)
q = asyncio.Queue()
bad_peer = KademliaPeer(self.loop, "127.0.0.1", b'2' * 48, tcp_port=3334)
def _mock_accumulate_peers(q1, q2):
async def _task():
pass
q2.put_nowait([bad_peer])
self.loop.call_later(1, q2.put_nowait, [self.server_from_client])
return q2, self.loop.create_task(_task())
mock_node.accumulate_peers = _mock_accumulate_peers
await self.stream.save_file(node=mock_node)
await self.stream.finished_writing.wait()
self.assertTrue(os.path.isfile(self.stream.full_path))
with open(self.stream.full_path, 'rb') as f:
self.assertEqual(f.read(), self.stream_bytes)
await self.stream.stop()
# self.assertIs(self.server_from_client.tcp_last_down, None)
# self.assertIsNot(bad_peer.tcp_last_down, None)
async def test_client_chunked_response(self):
self.server.stop_server()
class ChunkedServerProtocol(BlobServerProtocol):
def send_response(self, responses):
to_send = []
while responses:
to_send.append(responses.pop())
for byte in BlobResponse(to_send).serialize():
self.transport.write(bytes([byte]))
self.server.server_protocol_class = ChunkedServerProtocol
self.server.start_server(33333, '127.0.0.1')
self.assertEqual(0, len(self.client_blob_manager.completed_blob_hashes))
await asyncio.wait_for(self._test_transfer_stream(10), timeout=2)
self.assertEqual(11, len(self.client_blob_manager.completed_blob_hashes))
async def test_create_and_decrypt_one_blob_stream(self, blobs=1, corrupt=False):
descriptor = await self.create_stream(blobs)
# copy blob files
shutil.copy(os.path.join(self.server_blob_manager.blob_dir, self.sd_hash),
os.path.join(self.client_blob_manager.blob_dir, self.sd_hash))
self.stream = ManagedStream(self.loop, self.client_config, self.client_blob_manager, self.sd_hash,
self.client_dir)
for blob_info in descriptor.blobs[:-1]:
shutil.copy(os.path.join(self.server_blob_manager.blob_dir, blob_info.blob_hash),
os.path.join(self.client_blob_manager.blob_dir, blob_info.blob_hash))
if corrupt and blob_info.length == MAX_BLOB_SIZE:
with open(os.path.join(self.client_blob_manager.blob_dir, blob_info.blob_hash), "rb+") as handle:
handle.truncate()
handle.flush()
await self.stream.save_file()
await self.stream.finished_writing.wait()
if corrupt:
return self.assertFalse(os.path.isfile(os.path.join(self.client_dir, "test_file")))
with open(os.path.join(self.client_dir, "test_file"), "rb") as f:
decrypted = f.read()
self.assertEqual(decrypted, self.stream_bytes)
self.assertEqual(True, self.client_blob_manager.get_blob(self.sd_hash).get_is_verified())
self.assertEqual(
True, self.client_blob_manager.get_blob(self.stream.descriptor.blobs[0].blob_hash).get_is_verified()
)
#
# # its all blobs + sd blob - last blob, which is the same size as descriptor.blobs
# self.assertEqual(len(descriptor.blobs), len(await downloader_storage.get_all_finished_blobs()))
# self.assertEqual(
# [descriptor.sd_hash, descriptor.blobs[0].blob_hash], await downloader_storage.get_blobs_to_announce()
# )
#
# await downloader_storage.close()
# await self.storage.close()
async def test_create_and_decrypt_multi_blob_stream(self):
await self.test_create_and_decrypt_one_blob_stream(10)
# async def test_create_truncate_and_handle_stream(self):
# # The purpose of this test is just to make sure it can finish even if a blob is corrupt/truncated
# await asyncio.wait_for(self.test_create_and_decrypt_one_blob_stream(corrupt=True), timeout=5)
+12 -5
View File
@@ -5,7 +5,7 @@ import shutil
from torba.testcase import AsyncioTestCase
from lbrynet.conf import Config
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.stream.stream_manager import StreamManager
from lbrynet.stream.reflector.server import ReflectorServer
@@ -18,16 +18,18 @@ class TestStreamAssembler(AsyncioTestCase):
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
self.storage = SQLiteStorage(Config(), os.path.join(tmp_dir, "lbrynet.sqlite"))
self.conf = Config()
self.storage = SQLiteStorage(self.conf, os.path.join(tmp_dir, "lbrynet.sqlite"))
await self.storage.open()
self.blob_manager = BlobFileManager(self.loop, tmp_dir, self.storage)
self.blob_manager = BlobManager(self.loop, tmp_dir, self.storage, self.conf)
self.stream_manager = StreamManager(self.loop, Config(), self.blob_manager, None, self.storage, None)
server_tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(server_tmp_dir))
self.server_storage = SQLiteStorage(Config(), os.path.join(server_tmp_dir, "lbrynet.sqlite"))
self.server_conf = Config()
self.server_storage = SQLiteStorage(self.server_conf, os.path.join(server_tmp_dir, "lbrynet.sqlite"))
await self.server_storage.open()
self.server_blob_manager = BlobFileManager(self.loop, server_tmp_dir, self.server_storage)
self.server_blob_manager = BlobManager(self.loop, server_tmp_dir, self.server_storage, self.server_conf)
download_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(download_dir))
@@ -60,3 +62,8 @@ class TestStreamAssembler(AsyncioTestCase):
sent = await self.stream.upload_to_reflector('127.0.0.1', 5566)
self.assertListEqual(sent, [])
async def test_announces(self):
to_announce = await self.storage.get_blobs_to_announce()
self.assertIn(self.stream.sd_hash, to_announce, "sd blob not set to announce")
self.assertIn(self.stream.descriptor.blobs[0].blob_hash, to_announce, "head blob not set to announce")
+9 -7
View File
@@ -9,7 +9,7 @@ from torba.testcase import AsyncioTestCase
from lbrynet.conf import Config
from lbrynet.error import InvalidStreamDescriptorError
from lbrynet.extras.daemon.storage import SQLiteStorage
from lbrynet.blob.blob_manager import BlobFileManager
from lbrynet.blob.blob_manager import BlobManager
from lbrynet.stream.descriptor import StreamDescriptor
@@ -20,9 +20,10 @@ class TestStreamDescriptor(AsyncioTestCase):
self.cleartext = os.urandom(20000000)
self.tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(self.tmp_dir))
self.storage = SQLiteStorage(Config(), ":memory:")
self.conf = Config()
self.storage = SQLiteStorage(self.conf, ":memory:")
await self.storage.open()
self.blob_manager = BlobFileManager(self.loop, self.tmp_dir, self.storage)
self.blob_manager = BlobManager(self.loop, self.tmp_dir, self.storage, self.conf)
self.file_path = os.path.join(self.tmp_dir, "test_file")
with open(self.file_path, 'wb') as f:
@@ -83,9 +84,10 @@ class TestRecoverOldStreamDescriptors(AsyncioTestCase):
loop = asyncio.get_event_loop()
tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir))
storage = SQLiteStorage(Config(), ":memory:")
self.conf = Config()
storage = SQLiteStorage(self.conf, ":memory:")
await storage.open()
blob_manager = BlobFileManager(loop, tmp_dir, storage)
blob_manager = BlobManager(loop, tmp_dir, storage, self.conf)
sd_bytes = b'{"stream_name": "4f62616d6120446f6e6b65792d322e73746c", "blobs": [{"length": 1153488, "blob_num' \
b'": 0, "blob_hash": "9fa32a249ce3f2d4e46b78599800f368b72f2a7f22b81df443c7f6bdbef496bd61b4c0079c7' \
@@ -99,7 +101,7 @@ class TestRecoverOldStreamDescriptors(AsyncioTestCase):
blob = blob_manager.get_blob(sd_hash)
blob.set_length(len(sd_bytes))
writer = blob.open_for_writing()
writer = blob.get_blob_writer()
writer.write(sd_bytes)
await blob.verified.wait()
descriptor = await StreamDescriptor.from_stream_descriptor_blob(
@@ -116,7 +118,7 @@ class TestRecoverOldStreamDescriptors(AsyncioTestCase):
sd_hash = '9313d1807551186126acc3662e74d9de29cede78d4f133349ace846273ef116b9bb86be86c54509eb84840e4b032f6b2'
with open(os.path.join(tmp_dir, sd_hash), 'wb') as handle:
handle.write(b'doesnt work')
blob = BlobFile(loop, tmp_dir, sd_hash)
blob = BlobFile(loop, sd_hash, blob_directory=tmp_dir)
self.assertTrue(blob.file_exists)
self.assertIsNotNone(blob.length)
with self.assertRaises(InvalidStreamDescriptorError):
+17 -14
View File
@@ -45,7 +45,7 @@ def get_mock_wallet(sd_hash, storage, balance=10.0, fee=None):
"claim_id": "c49566d631226492317d06ad7fdbe1ed32925124",
"claim_sequence": 1,
"decoded_claim": True,
"depth": 1057,
"confirmations": 1057,
"effective_amount": "0.1",
"has_signature": False,
"height": 514081,
@@ -192,8 +192,8 @@ class TestStreamManager(BlobExchangeTestBase):
def check_post(event):
self.assertEqual(event['event'], 'Time To First Bytes')
self.assertEqual(event['properties']['error'], 'DownloadSDTimeout')
self.assertEqual(event['properties']['tried_peers_count'], None)
self.assertEqual(event['properties']['active_peer_count'], None)
self.assertEqual(event['properties']['tried_peers_count'], 0)
self.assertEqual(event['properties']['active_peer_count'], 0)
self.assertEqual(event['properties']['use_fixed_peers'], False)
self.assertEqual(event['properties']['added_fixed_peers'], False)
self.assertEqual(event['properties']['fixed_peer_delay'], None)
@@ -213,10 +213,10 @@ class TestStreamManager(BlobExchangeTestBase):
self.stream_manager.analytics_manager._post = check_post
self.assertSetEqual(self.stream_manager.streams, set())
self.assertDictEqual(self.stream_manager.streams, {})
stream = await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager)
stream_hash = stream.stream_hash
self.assertSetEqual(self.stream_manager.streams, {stream})
self.assertDictEqual(self.stream_manager.streams, {stream.sd_hash: stream})
self.assertTrue(stream.running)
self.assertFalse(stream.finished)
self.assertTrue(os.path.isfile(os.path.join(self.client_dir, "test_file")))
@@ -225,7 +225,7 @@ class TestStreamManager(BlobExchangeTestBase):
)
self.assertEqual(stored_status, "running")
await self.stream_manager.stop_stream(stream)
await stream.stop()
self.assertFalse(stream.finished)
self.assertFalse(stream.running)
@@ -235,8 +235,8 @@ class TestStreamManager(BlobExchangeTestBase):
)
self.assertEqual(stored_status, "stopped")
await self.stream_manager.start_stream(stream)
await stream.downloader.stream_finished_event.wait()
await stream.save_file(node=self.stream_manager.node)
await stream.finished_writing.wait()
await asyncio.sleep(0, loop=self.loop)
self.assertTrue(stream.finished)
self.assertFalse(stream.running)
@@ -247,7 +247,7 @@ class TestStreamManager(BlobExchangeTestBase):
self.assertEqual(stored_status, "finished")
await self.stream_manager.delete_stream(stream, True)
self.assertSetEqual(self.stream_manager.streams, set())
self.assertDictEqual(self.stream_manager.streams, {})
self.assertFalse(os.path.isfile(os.path.join(self.client_dir, "test_file")))
stored_status = await self.client_storage.run_and_return_one_or_none(
"select status from file where stream_hash=?", stream_hash
@@ -257,7 +257,7 @@ class TestStreamManager(BlobExchangeTestBase):
async def _test_download_error_on_start(self, expected_error, timeout=None):
with self.assertRaises(expected_error):
await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager, timeout=timeout)
await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager, timeout)
async def _test_download_error_analytics_on_start(self, expected_error, timeout=None):
received = []
@@ -321,9 +321,9 @@ class TestStreamManager(BlobExchangeTestBase):
await self.setup_stream_manager(old_sort=old_sort)
self.stream_manager.analytics_manager._post = check_post
self.assertSetEqual(self.stream_manager.streams, set())
self.assertDictEqual(self.stream_manager.streams, {})
stream = await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager)
await stream.downloader.stream_finished_event.wait()
await stream.finished_writing.wait()
await asyncio.sleep(0, loop=self.loop)
self.stream_manager.stop()
self.client_blob_manager.stop()
@@ -333,8 +333,11 @@ class TestStreamManager(BlobExchangeTestBase):
await self.client_blob_manager.setup()
await self.stream_manager.start()
self.assertEqual(1, len(self.stream_manager.streams))
self.assertEqual(stream.sd_hash, list(self.stream_manager.streams)[0].sd_hash)
self.assertEqual('stopped', list(self.stream_manager.streams)[0].status)
self.assertListEqual([self.sd_hash], list(self.stream_manager.streams.keys()))
for blob_hash in [stream.sd_hash] + [b.blob_hash for b in stream.descriptor.blobs[:-1]]:
blob_status = await self.client_storage.get_blob_status(blob_hash)
self.assertEqual('pending', blob_status)
self.assertEqual('finished', self.stream_manager.streams[self.sd_hash].status)
sd_blob = self.client_blob_manager.get_blob(stream.sd_hash)
self.assertTrue(sd_blob.file_exists)
+1 -1
View File
@@ -61,7 +61,7 @@ class CLITest(AsyncioTestCase):
# publish is ungrouped command, returns usage only implicitly
self.assertIn('publish (<name> | --name=<name>)', self.shell(['publish']))
# publish is ungrouped command, with explicit --help
self.assertIn('Create or update a stream claim at a given name', self.shell(['publish', '--help']))
self.assertIn('Create or replace a stream claim at a given name', self.shell(['publish', '--help']))
# account is a group, returns help implicitly
self.assertIn('Return the balance of an account', self.shell(['account']))
# account is a group, with explicit --help
+17
View File
@@ -95,3 +95,20 @@ class TestAccount(AsyncioTestCase):
account = Account.from_dict(self.ledger, Wallet(), account_data)
account_data['ledger'] = 'lbc_mainnet'
self.assertDictEqual(account_data, account.to_dict())
async def test_save_max_gap(self):
account = Account.generate(
self.ledger, Wallet(), 'lbryum', {
'name': 'deterministic-chain',
'receiving': {'gap': 3, 'maximum_uses_per_address': 2},
'change': {'gap': 4, 'maximum_uses_per_address': 2}
}
)
self.assertEqual(account.receiving.gap, 3)
self.assertEqual(account.change.gap, 4)
await account.save_max_gap()
self.assertEqual(account.receiving.gap, 20)
self.assertEqual(account.change.gap, 6)
# doesn't fail for single-address account
account2 = Account.generate(self.ledger, Wallet(), 'lbryum', {'name': 'single-address'})
await account2.save_max_gap()