Compare commits
315
Commits
v0.38.0
...
tracemalloc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5718be1c61 | ||
|
|
5c151a3a09 | ||
|
|
3c46c6cbb9 | ||
|
|
d31f09c174 | ||
|
|
063eeb34ec | ||
|
|
f06192601c | ||
|
|
091221ba2c | ||
|
|
7c22111ae0 | ||
|
|
daac3eed09 | ||
|
|
32ee7feea8 | ||
|
|
2026848a77 | ||
|
|
a7b205603c | ||
|
|
291d14f2d4 | ||
|
|
4a68137cfa | ||
|
|
b2f0374426 | ||
|
|
5fcca6ed0c | ||
|
|
a05c44ad1e | ||
|
|
f9880c8931 | ||
|
|
b876896628 | ||
|
|
375c2a3363 | ||
|
|
5dbc749000 | ||
|
|
36fbd91280 | ||
|
|
d2ad3e7ff1 | ||
|
|
072f1f112e | ||
|
|
6c79f98d3c | ||
|
|
8edebbb684 | ||
|
|
4839ca631a | ||
|
|
5018fe90de | ||
|
|
379144bcfe | ||
|
|
d2cd0ece5f | ||
|
|
10b7ccaa92 | ||
|
|
925eb618de | ||
|
|
96800de052 | ||
|
|
9df659b647 | ||
|
|
aec0bd5d11 | ||
|
|
c1c9c2c578 | ||
|
|
c739fa3ca1 | ||
|
|
355dfcb6c1 | ||
|
|
8f7c291e33 | ||
|
|
71fbb3df24 | ||
|
|
9cfa9b2c57 | ||
|
|
b9b8178e30 | ||
|
|
089cefb77b | ||
|
|
ee9ea1faab | ||
|
|
22b2cf8b0c | ||
|
|
10bd3c9dda | ||
|
|
6c3147fcf4 | ||
|
|
5e8d169c50 | ||
|
|
8657a35fd7 | ||
|
|
97c0b60a22 | ||
|
|
8a284d6c49 | ||
|
|
ff4b2f2dec | ||
|
|
aedce256af | ||
|
|
48b4b97132 | ||
|
|
6b1f88df66 | ||
|
|
d246c46227 | ||
|
|
7fdd9dc293 | ||
|
|
202861a900 | ||
|
|
4c41e7cb29 | ||
|
|
92823dcea9 | ||
|
|
795a5227bc | ||
|
|
bbd4bb99b7 | ||
|
|
f7443061ef | ||
|
|
416c3c16ab | ||
|
|
a11956ece0 | ||
|
|
c4e0c659a7 | ||
|
|
f6ba09b171 | ||
|
|
b827881024 | ||
|
|
89e395b5f4 | ||
|
|
c590954eb9 | ||
|
|
a5af3866fd | ||
|
|
1bef56f030 | ||
|
|
9045737504 | ||
|
|
0e48772c84 | ||
|
|
72690b5cff | ||
|
|
07bae26fd3 | ||
|
|
7b0e4617d3 | ||
|
|
af797296ed | ||
|
|
c826c7da0d | ||
|
|
20af1396b9 | ||
|
|
f567aca532 | ||
|
|
c60b658443 | ||
|
|
fde8c34088 | ||
|
|
deb6a07160 | ||
|
|
0a66e1b24c | ||
|
|
819a551b77 | ||
|
|
5119b71035 | ||
|
|
33945e14d3 | ||
|
|
1d9705fb17 | ||
|
|
1949937b5e | ||
|
|
956e21269e | ||
|
|
ff73418fc1 | ||
|
|
76d40f44d8 | ||
|
|
ab6944b7b0 | ||
|
|
4d741bd200 | ||
|
|
f3a163b382 | ||
|
|
011b7f090f | ||
|
|
4ead92cfbe | ||
|
|
9ee2f30df4 | ||
|
|
4a749f6c38 | ||
|
|
cf924373f6 | ||
|
|
d1f5b25418 | ||
|
|
822f53c888 | ||
|
|
f04c5ee902 | ||
|
|
022d60ec2c | ||
|
|
8fce374cae | ||
|
|
e78e2738ef | ||
|
|
5728493abb | ||
|
|
af1c8ec35c | ||
|
|
cb84abfb88 | ||
|
|
df1e349470 | ||
|
|
357ce881a6 | ||
|
|
aa417f5410 | ||
|
|
0ca29b9518 | ||
|
|
22db04068e | ||
|
|
65e74281e0 | ||
|
|
46d89929ba | ||
|
|
1c941a355b | ||
|
|
0d6248fbeb | ||
|
|
98d4d00f96 | ||
|
|
e2d618f472 | ||
|
|
79d643db6c | ||
|
|
13891330d9 | ||
|
|
6fd0c2bf77 | ||
|
|
b8b42a1fd2 | ||
|
|
fba1b28615 | ||
|
|
98828387e3 | ||
|
|
1c12247b71 | ||
|
|
ee10ebd5d7 | ||
|
|
9937ad6e85 | ||
|
|
60ce393531 | ||
|
|
bc33cad999 | ||
|
|
4261b50d9d | ||
|
|
e2b3141536 | ||
|
|
266aa1b15d | ||
|
|
b57a7475c5 | ||
|
|
8cf48eb5f7 | ||
|
|
35541bbbb9 | ||
|
|
59424a3e73 | ||
|
|
2056888667 | ||
|
|
1e54785742 | ||
|
|
a58ed6f331 | ||
|
|
9a79b71d9f | ||
|
|
e9098887fb | ||
|
|
9e8a3ef7fc | ||
|
|
221585908a | ||
|
|
f4c111f04c | ||
|
|
de12e25450 | ||
|
|
2545ebbece | ||
|
|
14ec6ce43b | ||
|
|
0cac1e65aa | ||
|
|
1e4d57ab83 | ||
|
|
49b42b7e03 | ||
|
|
89c0b5dbdf | ||
|
|
8138675808 | ||
|
|
726129836a | ||
|
|
356b3c85e5 | ||
|
|
1a0680ead9 | ||
|
|
c876d891fa | ||
|
|
a08232f164 | ||
|
|
0f8cf46626 | ||
|
|
95017b5fc8 | ||
|
|
1374d337d8 | ||
|
|
35e7cc685f | ||
|
|
2ac4883bda | ||
|
|
5a7212aebb | ||
|
|
3f39cc2955 | ||
|
|
8a5bfe884a | ||
|
|
046dd53913 | ||
|
|
d2f174635c | ||
|
|
01a760d8f0 | ||
|
|
9215d2c9f9 | ||
|
|
0bb09ae91e | ||
|
|
afeff61268 | ||
|
|
6f5a595975 | ||
|
|
8a69ec062e | ||
|
|
45fb673e49 | ||
|
|
93b5f1809e | ||
|
|
ff05eaae48 | ||
|
|
b48b67ed10 | ||
|
|
3ead6f63b6 | ||
|
|
77235f0ad8 | ||
|
|
f6a80ba929 | ||
|
|
295ceb90d5 | ||
|
|
df41a82b23 | ||
|
|
34500e07c6 | ||
|
|
1e6097e3b2 | ||
|
|
521facedc4 | ||
|
|
de80a2ba97 | ||
|
|
3afd615447 | ||
|
|
87e52bec0a | ||
|
|
b89f04b1f1 | ||
|
|
e4f802e5f4 | ||
|
|
16fc2c456f | ||
|
|
ef7656ae98 | ||
|
|
ad2df4871e | ||
|
|
8d5f50b695 | ||
|
|
bbc056eef0 | ||
|
|
82fd3c632e | ||
|
|
dbae939808 | ||
|
|
c2dcacb0de | ||
|
|
8f45618cd0 | ||
|
|
29a87c850c | ||
|
|
395518ff76 | ||
|
|
08da763327 | ||
|
|
d7ec3c182d | ||
|
|
ffe6418392 | ||
|
|
88adf3ee27 | ||
|
|
f406db85dc | ||
|
|
d5f8af471a | ||
|
|
046459a72d | ||
|
|
49b0f59790 | ||
|
|
71551058ce | ||
|
|
2a9e6473eb | ||
|
|
576ef9c4ed | ||
|
|
4d64fca9de | ||
|
|
8b1307e1ca | ||
|
|
eae4ed7b27 | ||
|
|
6997ea608d | ||
|
|
d97d738880 | ||
|
|
f72b07d0f4 | ||
|
|
b89916a3d7 | ||
|
|
e4aeb66257 | ||
|
|
578f8f4062 | ||
|
|
8fbf82f4ea | ||
|
|
478ae7e657 | ||
|
|
d319761483 | ||
|
|
16fb716872 | ||
|
|
b8d9d097d8 | ||
|
|
ec79a1d0e8 | ||
|
|
31284e0c5e | ||
|
|
8e64b1840d | ||
|
|
dd9bf04e35 | ||
|
|
76a27fdef1 | ||
|
|
f96443515a | ||
|
|
0f1bde2274 | ||
|
|
6fb94e445f | ||
|
|
e02a4e44c0 | ||
|
|
71dc882d5d | ||
|
|
ae4a29d41c | ||
|
|
d27a3b6421 | ||
|
|
03a58cf50a | ||
|
|
f43e370e89 | ||
|
|
45bdb9023a | ||
|
|
6d7aa93157 | ||
|
|
d083910255 | ||
|
|
db3f9af174 | ||
|
|
7d2ad5e4ed | ||
|
|
84d3771984 | ||
|
|
1eebe006ae | ||
|
|
0327ce53a6 | ||
|
|
85442c1d07 | ||
|
|
a6ed51b7a7 | ||
|
|
dc8b4b5252 | ||
|
|
8ca74d3de2 | ||
|
|
1923e6f152 | ||
|
|
0d621e085b | ||
|
|
8749c78622 | ||
|
|
510d88fff1 | ||
|
|
d9460dcd9e | ||
|
|
d0607b6fec | ||
|
|
2481305a1a | ||
|
|
9990889cce | ||
|
|
14f743c493 | ||
|
|
df8fe2e3ef | ||
|
|
906fea972e | ||
|
|
04a82d5c23 | ||
|
|
f2944fd33b | ||
|
|
dcb1e53aba | ||
|
|
a4d8508b40 | ||
|
|
f109aa1f73 | ||
|
|
f09c18539b | ||
|
|
c5aeac6898 | ||
|
|
b81c801f2d | ||
|
|
f3cedf2f44 | ||
|
|
910999e7e4 | ||
|
|
5bceb06fc5 | ||
|
|
cc098f3090 | ||
|
|
a73c5aec27 | ||
|
|
68b29d9529 | ||
|
|
57f069d750 | ||
|
|
67e12bc590 | ||
|
|
ff2a08747b | ||
|
|
3791d22713 | ||
|
|
638ecafb69 | ||
|
|
5176feed81 | ||
|
|
8c63033461 | ||
|
|
8c878f8e25 | ||
|
|
c1c7e30ec9 | ||
|
|
28ae7f81e9 | ||
|
|
71de4d769d | ||
|
|
f502944c5b | ||
|
|
99d21e93f3 | ||
|
|
350e610f15 | ||
|
|
4f208b6b31 | ||
|
|
dcb781a57e | ||
|
|
09db71ae7f | ||
|
|
60dc43340d | ||
|
|
256b10bd7d | ||
|
|
77adcaeb50 | ||
|
|
abf2ca40a2 | ||
|
|
d5183123fa | ||
|
|
8b0d96acba | ||
|
|
66122a45ed | ||
|
|
a2953ac9ac | ||
|
|
c51db5294f | ||
|
|
8cba43bfed | ||
|
|
4b1c7aa6c5 | ||
|
|
14c1e95841 | ||
|
|
4f5a4d9ce0 | ||
|
|
82f2ad21e1 | ||
|
|
8a5b803788 | ||
|
|
86b46ebf19 | ||
|
|
ca999053ae | ||
|
|
8b152f3c96 |
No files matched your search
@@ -1 +1,2 @@
|
||||
/.idea
|
||||
/.DS_Store
|
||||
+5
-5
@@ -25,6 +25,7 @@ jobs:
|
||||
- name: "LBRY Integration Tests"
|
||||
install:
|
||||
- pip install coverage tox-travis
|
||||
- sudo mount -o mode=1777,nosuid,nodev -t tmpfs tmpfs /tmp
|
||||
script: cd lbry && tox
|
||||
after_success:
|
||||
- coverage combine lbry
|
||||
@@ -78,7 +79,8 @@ jobs:
|
||||
- aws s3 cp lbrynet-${OS}.zip s3://build.lbry.io/${S3_PATH}/lbrynet-${OS}.zip
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key: $GITHUB_OAUTH_TOKEN
|
||||
api_key:
|
||||
secure: "unnR+aSJ1937Cl1PyBBZzGuZvV5W5TGcXELhXTgyOeeI6FgO/j80qmbNxJDA7qdFH/hvVicQFWoflhZu2dxN5rYP5BQJW3q3XoOLY3XAc1s1vicFkwqn3TIfdFiJTz+/D9eBUBBhHKeYFxm3M+thvklTLgjKl6fflh14NfGuNTevK9yQke8wewW3f9UmFTo1qNOPF1OsTZRbwua6oQYa59P+KukoPt4Dsu1VtILtTkj7hfEsUL79cjotwO3gkhYftxbl/xeDSZWOt+9Nhb8ZKmQG/uDx4JiTMm5lWRk4QB7pUujZ1CftxCYWz/lJx9nuJpdCOgP624tcHymErNlD+vGLwMTNslcXGYkAJH6xvGyxBJ+Obc8vRVnZbRM26BfH34TcPK1ueRxHSrDUbzMIIUsgcoZAxBuim8uDPp+K7bGqiygzSs2vQfr9U5Jhe9/F8sPdtNctfJZEfgmthNTeVFjyNsGIfIt754uGSfACqM7wDLh6fbKx7M+FHlNyOdvYCrbKUOAYXmTikYIpVDvlaaeMO+N+uW8Rhvm1j+JU7CVwhMavLySaPVc6Dt5OxiMMmxw9mVrjW9bBPjS5AkrS5MOA13T5wapoLzH6+gE92U4HzA6ilMcwRaQPSFnK2JU7tzyt2Wy1PH4MjHowXI2WyICG1x510dD3tX1P/1px8ro="
|
||||
file: lbrynet-${OS}.zip
|
||||
skip_cleanup: true
|
||||
overwrite: true
|
||||
@@ -106,12 +108,10 @@ jobs:
|
||||
language: shell
|
||||
env:
|
||||
- OS=windows
|
||||
- PATH=/C/Users/travis/AppData/Roaming/Python/Python37/Scripts:/c/Python37:/c/Python37/Scripts:/C/Windows/System32/downlevel:$PATH
|
||||
- PATH=/c/Python37:/c/Python37/Scripts:/C/Windows/System32/downlevel:$PATH
|
||||
before_install:
|
||||
- choco install python --x86
|
||||
- pip install --user --upgrade pip virtualenv
|
||||
- virtualenv $HOME/venv
|
||||
- source $HOME/venv/Scripts/activate
|
||||
- python -m pip install --upgrade pip
|
||||
- pip install pywin32
|
||||
script:
|
||||
- pyinstaller --additional-hooks-dir=scripts/. --icon=icons/lbry256.ico -F -n lbrynet lbry/extras/cli.py
|
||||
|
||||
@@ -9,6 +9,10 @@ lint:
|
||||
cd torba && pylint --rcfile=setup.cfg torba
|
||||
cd torba && mypy --ignore-missing-imports torba
|
||||
|
||||
test:
|
||||
cd lbry && tox
|
||||
cd torba && tox
|
||||
|
||||
idea:
|
||||
mkdir -p .idea
|
||||
cp -r lbry/scripts/idea/* .idea
|
||||
+289
-126
@@ -41,10 +41,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Get a file",
|
||||
"curl": "curl -d'{\"method\": \"get\", \"params\": {\"uri\": \"astream#5d64500fb723eded83a41b0d5055f1783f019191\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet get astream#5d64500fb723eded83a41b0d5055f1783f019191",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"get\", \"params\": {\"uri\": \"astream#5d64500fb723eded83a41b0d5055f1783f019191\"}}).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\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"confirmations\": 3,\n \"content_fee\": null,\n \"download_directory\": \"/tmp/tmpfjnst0c0\",\n \"download_path\": \"/tmp/tmpfjnst0c0/tmpzj1qbxfj\",\n \"file_name\": \"tmpzj1qbxfj\",\n \"height\": 214,\n \"key\": \"e8b365259d5b8644a6a1eb5d2f77459f\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"015e32d5a47f2cd3e1242457498c97578d4594d77ee519fc56b21384e97c75d5c1b6450f2138e209f7bbd2adb588609ba36d1982a2187070c391a89793a0b569f09fef656fe041eab1809e3964f6346ae0fb3d20f30a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d707a6a31716278666a180b22186170706c69636174696f6e2f6f637465742d73747265616d3230d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"8b7dee36b0985027ad1476590ee5759359b57e4cb6507d5288ffe1508c32177f5a39ef20772cf90da72987f6f55ce1ba\",\n \"stream_name\": \"tmpzj1qbxfj\",\n \"streaming_url\": \"http://localhost:5280/stream/d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"suggested_file_name\": \"tmpzj1qbxfj\",\n \"timestamp\": 1561485090,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"written_bytes\": 11\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"get\", \"params\": {\"uri\": \"astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet get astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"get\", \"params\": {\"uri\": \"astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"}}).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\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_name\": \"astream\",\n \"completed\": true,\n \"confirmations\": 3,\n \"content_fee\": null,\n \"download_directory\": \"/tmp/tmptn5ym8in\",\n \"download_path\": \"/tmp/tmptn5ym8in/tmpmjego0ff\",\n \"file_name\": \"tmpmjego0ff\",\n \"height\": 214,\n \"key\": \"44c98cff66e9387514d212369d4af15e\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01af0811078a69759a18595d052af6945827d31218a49f0b990dfb596d464fa5c166a752b4835b01f02dcabd712d4345b09c18ce4096395d25caf4fb962732f54d58df839f9dd7cc2ef1d4303c89e4dd553865ed060a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d706d6a65676f306666180b22186170706c69636174696f6e2f6f637465742d73747265616d32302ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"d2fdfe280a77e5dd71f82cd531782ec5f71db1b2f9b6bf4da71240b5ad6fb21367d4b53e6f84fa83cc190aff004dd7bd\",\n \"stream_name\": \"tmpmjego0ff\",\n \"streaming_url\": \"http://localhost:5280/stream/2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"suggested_file_name\": \"tmpmjego0ff\",\n \"timestamp\": 1567524492,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"written_bytes\": 11\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -187,7 +187,13 @@
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "account to use for funding the transaction",
|
||||
"description": "account to use for holding the transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "funding_account_ids",
|
||||
"type": "list",
|
||||
"description": "ids of accounts to fund this transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
@@ -213,10 +219,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Publish a file",
|
||||
"curl": "curl -d'{\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpj0rdjqc7\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet publish a-new-stream --bid=1.0 --file_path=/tmp/tmpj0rdjqc7",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpj0rdjqc7\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000010f6edeb77e3d75b4cdfd5704e4d14ff2fa21948a5b26335aa3e69c8749d6a662010000006b483045022100d85e9ac9781bbaab17e5001055399ecd14b2a31077475734b6a6ccc7e668250e02200d6649e3deea9ca557aa897a32312aed841c56d94d095062c390b718f83e4ea0012102eea5cb67d3c756c1de57f503d4899d9560f1c689c38dfa9339d8020c04cf60e6ffffffff0200e1f50500000000bfb50c612d6e65772d73747265616d4c94000a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d706a3072646a716337180b22186170706c69636174696f6e2f6f637465742d73747265616d32303f3b7f11e1ab2ce9c763196d320ec2b73bb7a9acad3f98cea94a37ccce30caa28bba70bb3931d521865c614e9012d88e6d7576a914e88e2124fffc9da0cfd28a92a92670443b4376b188ace0b46217000000001976a9143347a928ed9f8ad71955c09ecfa305efe4590cbe88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mgTdmr4kSe4jjBaQZwE3ar4Kb7XcZBqmZT\",\n \"amount\": \"4.947555\",\n \"confirmations\": 4,\n \"height\": 215,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485090,\n \"txid\": \"62a6d649879ce6a35a33265b8a9421faf24fd1e40457fdcdb4753d7eb7de6e0f\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"n2ibKtRbM8hdvp5EafkSAHBxbpBJ2CWWEV\",\n \"amount\": \"1.0\",\n \"claim_id\": \"74c583fc2e08061d6c32152cbdb86b09c483d3fc\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"a-new-stream\",\n \"normalized_name\": \"a-new-stream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://a-new-stream#74c583fc2e08061d6c32152cbdb86b09c483d3fc\",\n \"timestamp\": null,\n \"txid\": \"075ecb8118f2fe73a34683b574bb1be7a13d915ab14f3917a72c1d7e57abca1a\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpj0rdjqc7\",\n \"sd_hash\": \"3f3b7f11e1ab2ce9c763196d320ec2b73bb7a9acad3f98cea94a37ccce30caa28bba70bb3931d521865c614e9012d88e\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mkC6bv4hVXEKkjYzbHrZAJ6iZxHU7kyspa\",\n \"amount\": \"3.923448\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"075ecb8118f2fe73a34683b574bb1be7a13d915ab14f3917a72c1d7e57abca1a\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.024107\",\n \"total_input\": \"4.947555\",\n \"total_output\": \"4.923448\",\n \"txid\": \"075ecb8118f2fe73a34683b574bb1be7a13d915ab14f3917a72c1d7e57abca1a\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmp_djode3_\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet publish a-new-stream --bid=1.0 --file_path=/tmp/tmp_djode3_",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"publish\", \"params\": {\"name\": \"a-new-stream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmp_djode3_\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001301509336d7105f77744b0d8658d111b6d5c7f4b91dd60a99a1abd58e47bd855010000006b483045022100da5af53f91b0d6f81c54fe45cd7294edad374db1538b8a842b52909fc0f81d7a022018f5c6e86caa14d8b7b9cd00fc58dc62a3dc85116f1502725417846ac425119801210303b03af351f59825ab5a3f81e2cd3ccd9bc81b08dd3894e37af617d989303048ffffffff0200e1f50500000000bfb50c612d6e65772d73747265616d4c94000a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d705f646a6f6465335f180b22186170706c69636174696f6e2f6f637465742d73747265616d3230cd64057a0fc233a5414c2f0d55ab806faafddc220c4544e9dd1b6acf750553ce29d615b463cd9fed21b4444d209db4036d7576a914104e9db82ec98a53408ba517caa2bf2828ba028788ace0b46217000000001976a914310e5cdb39f601206132e8adcaa167f5b594b23f88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mk7Hr34G619JQ1wzFNRun1zWp9c8PLq7ze\",\n \"amount\": \"4.947555\",\n \"confirmations\": 4,\n \"height\": 215,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524492,\n \"txid\": \"55d87be458bd1a9aa960dd914b7f5c6d1b118d65d8b04477f705716d33091530\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mh1BHTvud83u2YRfdb3PwYS29aVS36cZL7\",\n \"amount\": \"1.0\",\n \"claim_id\": \"69d710bbe991b5c96b4efd5339a16d85a2d89bc4\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"a-new-stream\",\n \"normalized_name\": \"a-new-stream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://a-new-stream#69d710bbe991b5c96b4efd5339a16d85a2d89bc4\",\n \"timestamp\": null,\n \"txid\": \"406b4ea7584d40ab2f48ca553bd574ad04101df9beedc126ee519b0489425953\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmp_djode3_\",\n \"sd_hash\": \"cd64057a0fc233a5414c2f0d55ab806faafddc220c4544e9dd1b6acf750553ce29d615b463cd9fed21b4444d209db403\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mjzLcPkJvG8GQgDFSW9X2iCFSkwAyF2NmP\",\n \"amount\": \"3.923448\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"406b4ea7584d40ab2f48ca553bd574ad04101df9beedc126ee519b0489425953\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.024107\",\n \"total_input\": \"4.947555\",\n \"total_output\": \"4.923448\",\n \"txid\": \"406b4ea7584d40ab2f48ca553bd574ad04101df9beedc126ee519b0489425953\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -235,10 +241,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Resolve a claim",
|
||||
"curl": "curl -d'{\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#5d64500fb723eded83a41b0d5055f1783f019191\"]}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet resolve astream#5d64500fb723eded83a41b0d5055f1783f019191",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#5d64500fb723eded83a41b0d5055f1783f019191\"]}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"astream#5d64500fb723eded83a41b0d5055f1783f019191\": {\n \"address\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#7/astream#5\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_op\": \"update\",\n \"confirmations\": 3,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"meta\": {\n \"activation_height\": 213,\n \"creation_height\": 213,\n \"creation_timestamp\": 1561485090,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263187,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 213,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"short_url\": \"lbry://astream#5\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#7\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 7,\n \"height\": 210,\n \"meta\": {\n \"activation_height\": 209,\n \"claims_in_channel\": 1,\n \"creation_height\": 209,\n \"creation_timestamp\": 1561485089,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263183,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 209,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"short_url\": \"lbry://@channel#7\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"]}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet resolve astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"resolve\", \"params\": {\"urls\": [\"astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"]}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\": {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#1/astream#b\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_op\": \"update\",\n \"confirmations\": 3,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"meta\": {\n \"activation_height\": 213,\n \"creation_height\": 213,\n \"creation_timestamp\": 1567524492,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263187,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 213,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"short_url\": \"lbry://astream#b\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#1\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 7,\n \"height\": 210,\n \"meta\": {\n \"activation_height\": 209,\n \"claims_in_channel\": 1,\n \"creation_height\": 209,\n \"creation_timestamp\": 1567524491,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263183,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 209,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"short_url\": \"lbry://@channel#1\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -253,14 +259,14 @@
|
||||
"name": "status",
|
||||
"description": "Get daemon status",
|
||||
"arguments": [],
|
||||
"returns": "(dict) lbrynet-daemon status\n {\n 'installation_id': (str) installation id - base58,\n 'is_running': (bool),\n 'skipped_components': (list) [names of skipped components (str)],\n 'startup_status': { Does not include components which have been skipped\n 'blob_manager': (bool),\n 'blockchain_headers': (bool),\n 'database': (bool),\n 'dht': (bool),\n 'exchange_rate_manager': (bool),\n 'hash_announcer': (bool),\n 'peer_protocol_server': (bool),\n 'stream_manager': (bool),\n 'upnp': (bool),\n 'wallet': (bool),\n },\n 'connection_status': {\n 'code': (str) connection status code,\n 'message': (str) connection status message\n },\n 'blockchain_headers': {\n 'downloading_headers': (bool),\n 'download_progress': (float) 0-100.0\n },\n 'wallet': {\n 'blocks': (int) local blockchain height,\n 'blocks_behind': (int) remote_height - local_height,\n 'best_blockhash': (str) block hash of most recent block,\n 'is_encrypted': (bool),\n 'is_locked': (bool),\n },\n 'dht': {\n 'node_id': (str) lbry dht node id - hex encoded,\n 'peers_in_routing_table': (int) the number of peers in the routing table,\n },\n 'blob_manager': {\n 'finished_blobs': (int) number of finished blobs in the blob manager,\n 'connections': {\n 'incoming_bps': {\n <source ip and tcp port>: (int) bytes per second received,\n },\n 'outgoing_bps': {\n <destination ip and tcp port>: (int) bytes per second sent,\n },\n 'total_outgoing_mps': (float) megabytes per second sent,\n 'total_incoming_mps': (float) megabytes per second received,\n 'time': (float) timestamp\n }\n },\n 'hash_announcer': {\n 'announce_queue_size': (int) number of blobs currently queued to be announced\n },\n 'stream_manager': {\n 'managed_files': (int) count of files in the stream manager,\n },\n 'upnp': {\n 'aioupnp_version': (str),\n 'redirects': {\n <TCP | UDP>: (int) external_port,\n },\n 'gateway': (str) manufacturer and model,\n 'dht_redirect_set': (bool),\n 'peer_redirect_set': (bool),\n 'external_ip': (str) external ip address,\n }\n }",
|
||||
"returns": "(dict) lbrynet-daemon status\n {\n 'installation_id': (str) installation id - base58,\n 'is_running': (bool),\n 'skipped_components': (list) [names of skipped components (str)],\n 'startup_status': { Does not include components which have been skipped\n 'blob_manager': (bool),\n 'blockchain_headers': (bool),\n 'database': (bool),\n 'dht': (bool),\n 'exchange_rate_manager': (bool),\n 'hash_announcer': (bool),\n 'peer_protocol_server': (bool),\n 'stream_manager': (bool),\n 'upnp': (bool),\n 'wallet': (bool),\n },\n 'connection_status': {\n 'code': (str) connection status code,\n 'message': (str) connection status message\n },\n 'blockchain_headers': {\n 'downloading_headers': (bool),\n 'download_progress': (float) 0-100.0\n },\n 'wallet': {\n 'blocks': (int) local blockchain height,\n 'blocks_behind': (int) remote_height - local_height,\n 'best_blockhash': (str) block hash of most recent block,\n 'is_encrypted': (bool),\n 'is_locked': (bool),\n 'connected_servers': (list) [\n {\n 'host': (str) server hostname,\n 'port': (int) server port,\n 'latency': (int) milliseconds\n }\n ],\n },\n 'dht': {\n 'node_id': (str) lbry dht node id - hex encoded,\n 'peers_in_routing_table': (int) the number of peers in the routing table,\n },\n 'blob_manager': {\n 'finished_blobs': (int) number of finished blobs in the blob manager,\n 'connections': {\n 'incoming_bps': {\n <source ip and tcp port>: (int) bytes per second received,\n },\n 'outgoing_bps': {\n <destination ip and tcp port>: (int) bytes per second sent,\n },\n 'total_outgoing_mps': (float) megabytes per second sent,\n 'total_incoming_mps': (float) megabytes per second received,\n 'time': (float) timestamp\n }\n },\n 'hash_announcer': {\n 'announce_queue_size': (int) number of blobs currently queued to be announced\n },\n 'stream_manager': {\n 'managed_files': (int) count of files in the stream manager,\n },\n 'upnp': {\n 'aioupnp_version': (str),\n 'redirects': {\n <TCP | UDP>: (int) external_port,\n },\n 'gateway': (str) manufacturer and model,\n 'dht_redirect_set': (bool),\n 'peer_redirect_set': (bool),\n 'external_ip': (str) external ip address,\n }\n }",
|
||||
"examples": [
|
||||
{
|
||||
"title": "Get status",
|
||||
"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 \"connections\": {\n \"incoming_bps\": {},\n \"outgoing_bps\": {},\n \"time\": 174753.638136067,\n \"total_incoming_mbs\": 0.0,\n \"total_outgoing_mbs\": 0.0\n },\n \"finished_blobs\": 0\n },\n \"connection_status\": {\n \"code\": \"connected\",\n \"message\": \"No connection problems detected\"\n },\n \"installation_id\": \"8pS8Qp6ZV2azEgMT9MqurqFyEhGFgtR8L8UEbYbdGnCyvSrWEDU3ND4UZKG2iSzQ1f\",\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\": \"c432cf5e38130f7a6611b18078d8a4160c20481122e34b53c6e26e4831bc06c2\",\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 \"connections\": {\n \"incoming_bps\": {},\n \"outgoing_bps\": {},\n \"time\": 55995.711101459,\n \"total_incoming_mbs\": 0.0,\n \"total_outgoing_mbs\": 0.0,\n \"total_received\": 0,\n \"total_sent\": 0\n },\n \"finished_blobs\": 0\n },\n \"connection_status\": {\n \"code\": \"connected\",\n \"message\": \"No connection problems detected\"\n },\n \"installation_id\": \"7rrw8gej961zecjNyCJ6vFC1vMCZZ1tUsz5cYwrKNHn9VRVHECikd2eC47NZYEP7Bn\",\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\": \"4f4b0a8fd77284e1a83a05b9dfca0e5fdc337477caa94bd82239759512e5a27a\",\n \"blocks\": 206,\n \"blocks_behind\": 0,\n \"connected_servers\": [\n {\n \"host\": \"localhost\",\n \"latency\": 0.02,\n \"port\": 50002\n }\n ],\n \"is_encrypted\": false,\n \"is_locked\": false\n }\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -282,7 +288,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.38.0rc10\",\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.3\",\n \"torba_version\": \"0.5.7\"\n }\n}"
|
||||
"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.39.3\",\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.4\",\n \"torba_version\": \"0.5.7\"\n }\n}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -330,10 +336,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Add an account from seed",
|
||||
"curl": "curl -d'{\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"admit whisper prosper true example brown sea sketch clarify pudding hen faith\", \"single_key\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account add \"new account\" --seed=\"admit whisper prosper true example brown sea sketch clarify pudding hen faith\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"admit whisper prosper true example brown sea sketch clarify pudding hen faith\", \"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\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1561485056.9625015,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPfK8PpjVn9CX9dQbHu5cRhD6AB8kLNqJf7gckQYNRvtC4xawA34xQ7yQnUHkd6jwHCkZHVuY3s897sKyBHGGGWg8tokKkASU\",\n \"public_key\": \"tpubD6NzVbkrYhZ4YnABiPANYcBGCS7E4QoLGWgwTendo773xAsX2wC27Now8iQZ2kKbSq6GUaSDTV714e3Qxfdwsqh1dnYwbzUboTCqBSZ53gg\",\n \"seed\": \"admit whisper prosper true example brown sea sketch clarify pudding hen faith\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"stadium call taxi myth power method puppy same subject second guess scrub\", \"single_key\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account add \"new account\" --seed=\"stadium call taxi myth power method puppy same subject second guess scrub\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_add\", \"params\": {\"account_name\": \"new account\", \"seed\": \"stadium call taxi myth power method puppy same subject second guess scrub\", \"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\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1567524459.2594378,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPecCYqVR6CJDGkdewMmh6YTxdi8Q6P4QUFUYVrc3uBVMnWTe9f2ZAMxMyDQiJ5DZd9bPw1SL6DyPmLRaPJ8KC6LVgVVyWG77\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Y5ELj95gbhsPKfAsX6t17mZQzeSPoLCs5xoGUzsVMyyegZTamKHdJBPEPiK63GSKho6dV4DsfaE7n9LJuifHZZ5BZDUqWiJ\",\n \"seed\": \"stadium call taxi myth power method puppy same subject second guess scrub\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -352,23 +358,29 @@
|
||||
"type": "int",
|
||||
"description": "Only include transactions with this many confirmed blocks.",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "reserved_subtotals",
|
||||
"type": "bool",
|
||||
"description": "Include detailed reserved balances on claims, tips and supports.",
|
||||
"is_required": false
|
||||
}
|
||||
],
|
||||
"returns": "(decimal) amount of lbry credits in wallet",
|
||||
"examples": [
|
||||
{
|
||||
"title": "Get default account balance",
|
||||
"curl": "curl -d'{\"method\": \"account_balance\", \"params\": {}}' http://localhost:5279/",
|
||||
"curl": "curl -d'{\"method\": \"account_balance\", \"params\": {\"reserved_subtotals\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account balance",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_balance\", \"params\": {}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"7.999876\"\n}"
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_balance\", \"params\": {\"reserved_subtotals\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"available\": \"7.999876\",\n \"reserved\": \"0.0\",\n \"reserved_subtotals\": null,\n \"total\": \"7.999876\"\n }\n}"
|
||||
},
|
||||
{
|
||||
"title": "Get balance for specific account by id",
|
||||
"curl": "curl -d'{\"method\": \"account_balance\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account balance \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_balance\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"2.0\"\n}"
|
||||
"curl": "curl -d'{\"method\": \"account_balance\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"reserved_subtotals\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account balance \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_balance\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"reserved_subtotals\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"available\": \"2.0\",\n \"reserved\": \"0.0\",\n \"reserved_subtotals\": null,\n \"total\": \"2.0\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -396,7 +408,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\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1561485056.7929218,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPfK8PpjVn9CX9dQbHu5cRhD6AB8kLNqJf7gckQYNRvtC4xawA34xQ7yQnUHkd6jwHCkZHVuY3s897sKyBHGGGWg8tokKkASU\",\n \"public_key\": \"tpubD6NzVbkrYhZ4YnABiPANYcBGCS7E4QoLGWgwTendo773xAsX2wC27Now8iQZ2kKbSq6GUaSDTV714e3Qxfdwsqh1dnYwbzUboTCqBSZ53gg\",\n \"seed\": \"admit whisper prosper true example brown sea sketch clarify pudding hen faith\"\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\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1567524459.0664673,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPecCYqVR6CJDGkdewMmh6YTxdi8Q6P4QUFUYVrc3uBVMnWTe9f2ZAMxMyDQiJ5DZd9bPw1SL6DyPmLRaPJ8KC6LVgVVyWG77\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Y5ELj95gbhsPKfAsX6t17mZQzeSPoLCs5xoGUzsVMyyegZTamKHdJBPEPiK63GSKho6dV4DsfaE7n9LJuifHZZ5BZDUqWiJ\",\n \"seed\": \"stadium call taxi myth power method puppy same subject second guess scrub\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -479,24 +491,24 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Transfer 2 LBC from default account to specific account",
|
||||
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account fund --to_account=\"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\" --amount=2.0 --broadcast",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001c0fc2691a44442cb2c1b48a27518be2ec79230a771ef1a7d1c9ce9b4f293a08f010000006a47304402203f2685e9fa15bd431e61d659e3abbc2d900f2ef04c15c1864456b449c068f55902205505b654acada67b154179f6329516212f9cf3df7fb39636a286121e540f87a80121031370fc0bbc4f99acf402e5d687e846666cc0e5d7467c83104874e238c6ee6d2dffffffff0200c2eb0b000000001976a91469dd5873a711b516c47a0227efda9132a805bb0288ac90d7ae2f000000001976a914ea36761adfb298e01c377eeeb93e3a03874f6de588ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mjnGbmHPAUrnF2VmUqeDAZsSMHWbdmpfJ5\",\n \"amount\": \"10.0\",\n \"confirmations\": 6,\n \"height\": 201,\n \"is_change\": false,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485088,\n \"txid\": \"8fa093f2b4e99c1c7d1aef71a73092c72ebe1875a2481b2ccb4244a49126fcc0\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mqAiQYyqiqVWXaEYapnu5P49cnLvQdh11s\",\n \"amount\": \"2.0\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"0e071fe12cfda37fb80dd634afb1a44bcb861e2de16009ad5628cc7f74776634\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"n2sMeyyRYF5btHqQTa8Y5eitMZ6pGEKRoE\",\n \"amount\": \"7.999876\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"0e071fe12cfda37fb80dd634afb1a44bcb861e2de16009ad5628cc7f74776634\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000124\",\n \"total_input\": \"10.0\",\n \"total_output\": \"9.999876\",\n \"txid\": \"0e071fe12cfda37fb80dd634afb1a44bcb861e2de16009ad5628cc7f74776634\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account fund --to_account=\"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\" --amount=2.0 --broadcast",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"amount\": \"2.0\", \"everything\": false, \"broadcast\": true}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000012d1508ed14fd8d62d75cdb57eabe66364d3a769b89517299cc2f0eb8e42ab479010000006b483045022100f3a6ef432adc9b3e04a21da7adb15dd035cb8598355801923430a4e0f163693e0220087f7a751a3d368bb9ef92069f686bac41e972ed18632e448693e8418533fef9012102ec6d1f6c1bc6b026357f87f3d6afdeb71fd1e15bc8f2f0752ed1656281aaf4d3ffffffff0200c2eb0b000000001976a9148167e7add764797c9cdc98552e401133a96a932588ac90d7ae2f000000001976a9149b95cc2634f683041cca56112526caeeed97183188ac00000000\",\n \"inputs\": [\n {\n \"address\": \"n4Xag4N3ZDjuhwCLRqifkiSEEQP6PpV36S\",\n \"amount\": \"10.0\",\n \"confirmations\": 6,\n \"height\": 201,\n \"is_change\": false,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524490,\n \"txid\": \"79b42ae4b80e2fcc997251899b763a4d3666beea57db5cd7628dfd14ed08152d\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"msKBwFDKRQGiCfXo8QmdDtfen9FcFYfgaQ\",\n \"amount\": \"2.0\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"3e770eda0c2cc8b74e0107e6395fc686a08e022814f55a8153f83fb0f5f923ab\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"muhcUu1j1b5TrfvnsrMJ68CAUA9hahXHZH\",\n \"amount\": \"7.999876\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"3e770eda0c2cc8b74e0107e6395fc686a08e022814f55a8153f83fb0f5f923ab\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000124\",\n \"total_input\": \"10.0\",\n \"total_output\": \"9.999876\",\n \"txid\": \"3e770eda0c2cc8b74e0107e6395fc686a08e022814f55a8153f83fb0f5f923ab\"\n }\n}"
|
||||
},
|
||||
{
|
||||
"title": "Spread LBC between multiple addresses",
|
||||
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"from_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account fund --to_account=\"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\" --from_account=\"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\" --amount=1.5 --outputs=2 --broadcast",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"from_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001346677747fcc2856ad0960e12d1e86cb4ba4b1af34d60db87fa3fd2ce11f070e000000006b483045022100f03612c9d7c7e011b8f1cb72726cf1f4fb7b9841c0a353df3af355ce299b5ce2022049a9bd4e5c2708c8f13218610b30ad1948e742e6afb892c92ce6577aba44af6001210342bb0577c9c1f33257bcd8bfb791b3cf8f4dae24d37e0a2e17b8a8cc6d446a76ffffffff03c0687804000000001976a9148f7781bf51d1a0f5f75f498ebeb742c0b556cca388acc0687804000000001976a9148f7781bf51d1a0f5f75f498ebeb742c0b556cca388ac6cb9fa02000000001976a91426551ba83e54370b9bfe7e00f950d9b0e63bc40788ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mqAiQYyqiqVWXaEYapnu5P49cnLvQdh11s\",\n \"amount\": \"2.0\",\n \"confirmations\": 1,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1561485089,\n \"txid\": \"0e071fe12cfda37fb80dd634afb1a44bcb861e2de16009ad5628cc7f74776634\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mtbY5xxTz94srMVzLYHZQZvfDGCub8xfTR\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"f3ecdfab319d402d18e3b83ecff474c80b787ac10b79d8542c81ed10040e6202\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mtbY5xxTz94srMVzLYHZQZvfDGCub8xfTR\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"f3ecdfab319d402d18e3b83ecff474c80b787ac10b79d8542c81ed10040e6202\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mj1dvkfJo289BLRNevo2j7kiFsJcYSdQtv\",\n \"amount\": \"0.499859\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 2,\n \"timestamp\": null,\n \"txid\": \"f3ecdfab319d402d18e3b83ecff474c80b787ac10b79d8542c81ed10040e6202\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000141\",\n \"total_input\": \"2.0\",\n \"total_output\": \"1.999859\",\n \"txid\": \"f3ecdfab319d402d18e3b83ecff474c80b787ac10b79d8542c81ed10040e6202\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"from_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account fund --to_account=\"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\" --from_account=\"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\" --amount=1.5 --outputs=2 --broadcast",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"to_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"from_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"amount\": \"1.5\", \"everything\": false, \"outputs\": 2, \"broadcast\": true}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001ab23f9f5b03ff853815af51428028ea086c65f39e607014eb7c82c0cda0e773e000000006a47304402200350e8549f476fe19c82ae814b96f3a3ab245f282010921bf6c8808b8cccba3302204000cf0fdc08420886919665206785fd910fdbd4d72be6325914469912bb0c4301210219ba33f16de9b9f8b551dcd3dc932a174229075302103213a0f83a3c63df7646ffffffff03c0687804000000001976a9140d9b85fa9ecda29ba36b96cddf78b033c469a0fa88acc0687804000000001976a9140d9b85fa9ecda29ba36b96cddf78b033c469a0fa88ac6cb9fa02000000001976a9147e318c3fb101eb541c5e62fe98998ad294cb27f088ac00000000\",\n \"inputs\": [\n {\n \"address\": \"msKBwFDKRQGiCfXo8QmdDtfen9FcFYfgaQ\",\n \"amount\": \"2.0\",\n \"confirmations\": 1,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1567524491,\n \"txid\": \"3e770eda0c2cc8b74e0107e6395fc686a08e022814f55a8153f83fb0f5f923ab\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mgkuPVxE2UwWfLr26kLT1QAEiYScvMohPs\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"a47c8cb42a3920e7fedbf143b6cb3409d16ac85660abf7fc7892804783858f72\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mgkuPVxE2UwWfLr26kLT1QAEiYScvMohPs\",\n \"amount\": \"0.75\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"a47c8cb42a3920e7fedbf143b6cb3409d16ac85660abf7fc7892804783858f72\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"ms2CnsNwPX42NZjkYt3kTF4JfpuSxhmjHj\",\n \"amount\": \"0.499859\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 2,\n \"timestamp\": null,\n \"txid\": \"a47c8cb42a3920e7fedbf143b6cb3409d16ac85660abf7fc7892804783858f72\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000141\",\n \"total_input\": \"2.0\",\n \"total_output\": \"1.999859\",\n \"txid\": \"a47c8cb42a3920e7fedbf143b6cb3409d16ac85660abf7fc7892804783858f72\"\n }\n}"
|
||||
},
|
||||
{
|
||||
"title": "Transfer all LBC to a specified account",
|
||||
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"from_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"everything\": true, \"broadcast\": true}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account fund --from_account=\"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\" --everything --broadcast",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"from_account\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"everything\": true, \"broadcast\": true}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"010000000302620e0410ed812c54d8790bc17a780bc874f4cf3eb8e3182d409d31abdfecf3000000006a4730440220294fb6a9c2e72a48559546018a47b9809b6203d6557087fcb67836b8912c85dd0220186097a96551a014bfd997884dfaa15b6988adae64b723e5add723727ff1298801210337b6117f3a5fc40820b936e4b228d2576ce2f9a70a91228f71e6a967592572fcffffffff02620e0410ed812c54d8790bc17a780bc874f4cf3eb8e3182d409d31abdfecf3010000006a47304402203e6012c10ce76236b3685202ef4fe9ae6ce24ffd2b7f5648af5ba88d9f3ac56b022009ced72bc1ae82bf89acc2abe0b8e850467dd2814d680fd8a81dffce02a54f0901210337b6117f3a5fc40820b936e4b228d2576ce2f9a70a91228f71e6a967592572fcffffffff02620e0410ed812c54d8790bc17a780bc874f4cf3eb8e3182d409d31abdfecf3020000006b483045022100c75caa1826ede730b253d751ebd2164d40c74fb4724bc7d4d9a200325fefe7e70220262c74bcfacb214aa781d80775e39d35a396c1dda4453ddb470fc6cc0c3fb3c101210296295f9ab2bff497ac1e64d012d45d4d48a8f3bc8e926febacfe1d5e1a9cd01effffffff015027eb0b000000001976a914d15a521046fc425e25444798485573df4d2401ba88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mtbY5xxTz94srMVzLYHZQZvfDGCub8xfTR\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1561485089,\n \"txid\": \"f3ecdfab319d402d18e3b83ecff474c80b787ac10b79d8542c81ed10040e6202\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mtbY5xxTz94srMVzLYHZQZvfDGCub8xfTR\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485089,\n \"txid\": \"f3ecdfab319d402d18e3b83ecff474c80b787ac10b79d8542c81ed10040e6202\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mj1dvkfJo289BLRNevo2j7kiFsJcYSdQtv\",\n \"amount\": \"0.499859\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 2,\n \"timestamp\": 1561485089,\n \"txid\": \"f3ecdfab319d402d18e3b83ecff474c80b787ac10b79d8542c81ed10040e6202\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mzbuijFAnVGiEKWb9n24hcrUgdxauR3i83\",\n \"amount\": \"1.999604\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"c5e686d1617e9bc0ee1d4d14e1b7f211985db09c839e307a7876b1df1acfd15d\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000255\",\n \"total_input\": \"1.999859\",\n \"total_output\": \"1.999604\",\n \"txid\": \"c5e686d1617e9bc0ee1d4d14e1b7f211985db09c839e307a7876b1df1acfd15d\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"account_fund\", \"params\": {\"from_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"everything\": true, \"broadcast\": true}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account fund --from_account=\"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\" --everything --broadcast",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_fund\", \"params\": {\"from_account\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"everything\": true, \"broadcast\": true}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000003728f858347809278fcf7ab6056c86ad10934cbb643f1dbfee720392ab48c7ca4000000006a473044022067b37bffa018c7b54e862ce8ea6d3703718adb44a842f7acf3d8f8f38e45bdac02206c528df2c07d2301710935307530b31f6bd0864c135edeaa64246c6a8455645c012102ca78e33e37a6662255c12842d8ac4d89b2a6432f36fe37ab9de5a81f170aa339ffffffff728f858347809278fcf7ab6056c86ad10934cbb643f1dbfee720392ab48c7ca4010000006b483045022100a61a3687a73245222c16bd975518bef97bd6d975dfe5ad3eea0c935198bf1dad02207880a83ff7d52e14ad78f7ce99fa8b11d4940f33ffc6f27907940cc417b4e36b012102ca78e33e37a6662255c12842d8ac4d89b2a6432f36fe37ab9de5a81f170aa339ffffffff728f858347809278fcf7ab6056c86ad10934cbb643f1dbfee720392ab48c7ca4020000006b483045022100f46d51067598e68e9905da461175e1a5b73df742d8e073021226114fe44b772e022005c2f8e881571cbbe112f054ff6856d603b6bf621403ef0f82ea0dda836082940121028724b5be2ae3ba6b54c90e3ad283fcd211763bf81dbf15c97c166130628e3a0fffffffff015027eb0b000000001976a9146f15a545a6b6c030fb255447274e2e996be89f4688ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mgkuPVxE2UwWfLr26kLT1QAEiYScvMohPs\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1567524491,\n \"txid\": \"a47c8cb42a3920e7fedbf143b6cb3409d16ac85660abf7fc7892804783858f72\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"mgkuPVxE2UwWfLr26kLT1QAEiYScvMohPs\",\n \"amount\": \"0.75\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524491,\n \"txid\": \"a47c8cb42a3920e7fedbf143b6cb3409d16ac85660abf7fc7892804783858f72\",\n \"type\": \"payment\"\n },\n {\n \"address\": \"ms2CnsNwPX42NZjkYt3kTF4JfpuSxhmjHj\",\n \"amount\": \"0.499859\",\n \"confirmations\": 1,\n \"height\": 208,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 2,\n \"timestamp\": 1567524491,\n \"txid\": \"a47c8cb42a3920e7fedbf143b6cb3409d16ac85660abf7fc7892804783858f72\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mqeKEJuCipt8ArNwvnd9Ed2mpdVSKFjFPf\",\n \"amount\": \"1.999604\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"44f8291dfc8ca34a42469e945f4aa86fbab08ec9780dce8f340e6cfb3362442c\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000255\",\n \"total_input\": \"1.999859\",\n \"total_output\": \"1.999604\",\n \"txid\": \"44f8291dfc8ca34a42469e945f4aa86fbab08ec9780dce8f340e6cfb3362442c\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -536,7 +548,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\": \"mvuCTbTWTnF7u2vh3raaxSuR8Rd4hPGqs9\",\n \"is_default\": true,\n \"name\": \"Account #mvuCTbTWTnF7u2vh3raaxSuR8Rd4hPGqs9\",\n \"public_key\": \"tpubD6NzVbkrYhZ4XQhwsZYqxyH3vVf4MHQoiF2xXS2xcmGC2Ejbvq5X7S3onhZhMH7c4pgbJiFPX8C36HWwFgHUaZygQeXKJWsyaAWWzYqWSJm\",\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\": \"mrsZujEBWo4WRGRu1hx6uogoqDiAdbef3b\",\n \"is_default\": true,\n \"name\": \"Account #mrsZujEBWo4WRGRu1hx6uogoqDiAdbef3b\",\n \"preferences\": {\n \"theme\": \"dark\"\n },\n \"public_key\": \"tpubD6NzVbkrYhZ4Wjno2VHeqwKLRQZRWBYQ18z41xq9oPBfRWL76diN4VUBTbUGVEgpXG1pUoD9nDgZszYJLM2uVZAK1tFtke3VXiEmk6BnsD2\",\n \"satoshis\": 1000000000\n }\n ]\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -583,10 +595,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Remove an account",
|
||||
"curl": "curl -d'{\"method\": \"account_remove\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account remove mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_remove\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"}}).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\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1561485056.7929218,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPfK8PpjVn9CX9dQbHu5cRhD6AB8kLNqJf7gckQYNRvtC4xawA34xQ7yQnUHkd6jwHCkZHVuY3s897sKyBHGGGWg8tokKkASU\",\n \"public_key\": \"tpubD6NzVbkrYhZ4YnABiPANYcBGCS7E4QoLGWgwTendo773xAsX2wC27Now8iQZ2kKbSq6GUaSDTV714e3Qxfdwsqh1dnYwbzUboTCqBSZ53gg\",\n \"seed\": \"admit whisper prosper true example brown sea sketch clarify pudding hen faith\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"account_remove\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account remove mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_remove\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\"}}).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\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1567524459.0664673,\n \"name\": \"generated account\",\n \"private_key\": \"tprv8ZgxMBicQKsPecCYqVR6CJDGkdewMmh6YTxdi8Q6P4QUFUYVrc3uBVMnWTe9f2ZAMxMyDQiJ5DZd9bPw1SL6DyPmLRaPJ8KC6LVgVVyWG77\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Y5ELj95gbhsPKfAsX6t17mZQzeSPoLCs5xoGUzsVMyyegZTamKHdJBPEPiK63GSKho6dV4DsfaE7n9LJuifHZZ5BZDUqWiJ\",\n \"seed\": \"stadium call taxi myth power method puppy same subject second guess scrub\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -661,10 +673,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Modify maximum number of times a change address can be reused",
|
||||
"curl": "curl -d'{\"method\": \"account_set\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"default\": false, \"change_max_uses\": 10}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account set mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk --change_max_uses=10",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_set\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\", \"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\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1561485057.0708687,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPfK8PpjVn9CX9dQbHu5cRhD6AB8kLNqJf7gckQYNRvtC4xawA34xQ7yQnUHkd6jwHCkZHVuY3s897sKyBHGGGWg8tokKkASU\",\n \"public_key\": \"tpubD6NzVbkrYhZ4YnABiPANYcBGCS7E4QoLGWgwTendo773xAsX2wC27Now8iQZ2kKbSq6GUaSDTV714e3Qxfdwsqh1dnYwbzUboTCqBSZ53gg\",\n \"seed\": \"admit whisper prosper true example brown sea sketch clarify pudding hen faith\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"account_set\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"default\": false, \"change_max_uses\": 10}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet account set mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa --change_max_uses=10",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"account_set\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\", \"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\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\",\n \"is_default\": false,\n \"ledger\": \"lbc_regtest\",\n \"modified_on\": 1567524459.3661392,\n \"name\": \"new account\",\n \"private_key\": \"tprv8ZgxMBicQKsPecCYqVR6CJDGkdewMmh6YTxdi8Q6P4QUFUYVrc3uBVMnWTe9f2ZAMxMyDQiJ5DZd9bPw1SL6DyPmLRaPJ8KC6LVgVVyWG77\",\n \"public_key\": \"tpubD6NzVbkrYhZ4Y5ELj95gbhsPKfAsX6t17mZQzeSPoLCs5xoGUzsVMyyegZTamKHdJBPEPiK63GSKho6dV4DsfaE7n9LJuifHZZ5BZDUqWiJ\",\n \"seed\": \"stadium call taxi myth power method puppy same subject second guess scrub\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -714,9 +726,9 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Check if address is mine",
|
||||
"curl": "curl -d'{\"method\": \"address_is_mine\", \"params\": {\"address\": \"mzPzDUvLyZUKv2LmQdMZAmd4ZNm1Xxgf1z\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet address is_mine mzPzDUvLyZUKv2LmQdMZAmd4ZNm1Xxgf1z",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_is_mine\", \"params\": {\"address\": \"mzPzDUvLyZUKv2LmQdMZAmd4ZNm1Xxgf1z\"}}).json()",
|
||||
"curl": "curl -d'{\"method\": \"address_is_mine\", \"params\": {\"address\": \"mh1BHTvud83u2YRfdb3PwYS29aVS36cZL7\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet address is_mine mh1BHTvud83u2YRfdb3PwYS29aVS36cZL7",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_is_mine\", \"params\": {\"address\": \"mh1BHTvud83u2YRfdb3PwYS29aVS36cZL7\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": true\n}"
|
||||
}
|
||||
]
|
||||
@@ -751,14 +763,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 \"mjnGbmHPAUrnF2VmUqeDAZsSMHWbdmpfJ5\",\n \"mfsQtTpZgv9D1KzkgS6sgevuRD3TDpx4b8\",\n \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"msaGdm9gRuVwbRPW47pL41hjuiT7xo2vRd\",\n \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"n2aKiEgh36nK3xLr4C5vZzvj7hEuMhJWdb\",\n \"mfq8BbdBew1SdWUsK49XT863YobqKVheDy\",\n \"mzPzDUvLyZUKv2LmQdMZAmd4ZNm1Xxgf1z\",\n \"miLhR5kJLGVqi5Ss2VKT2Nxt4fToriqtX2\",\n \"mvrHAPqKaFJUVYXSqQS9MLWN7EHdAWArGJ\",\n \"mzZTN3wcKyqfLHL1bFAgGTqryHrJJshHPV\",\n \"mjgAKEpQjZVjvYsdHoRiucG6HfgTZxbfnD\",\n \"mkMSb7uWUMdGAQ3pnXjDgofyiVibmy2zw2\",\n \"n2ibKtRbM8hdvp5EafkSAHBxbpBJ2CWWEV\",\n \"mkaiNK23LKyWQqUxCYvk8KT1Bf7F5kccBV\",\n \"mr8ttV21zxBiiYeyHtWNfVo3dkgqJ9XtgP\",\n \"mvxcVQv1fJQGkJgCHxpRr15BzqKmTn9Jp2\",\n \"mmDrz35MC54Gqs12sxC48LcSsZiD6GRjvJ\",\n \"mq8DfGaa1vkw89tVaEaEgsQoHnkQdfwXBr\",\n \"mi9uQeFBjKe4EFze4gHvLVm9REepjj2qEm\",\n \"moXzxEEXj4nhGhnozbGGFqGXdEzysbDMHJ\",\n \"mgTdmr4kSe4jjBaQZwE3ar4Kb7XcZBqmZT\",\n \"moLhFf1vkeMKeMG3DAP1RTvbHDqSXha11K\",\n \"n2sMeyyRYF5btHqQTa8Y5eitMZ6pGEKRoE\",\n \"n2FNDLjvbu4dnW6pCtGKJN87PttvCeBWsR\",\n \"mwhWukDANoke2ikBrkj8u3kFdRh5YM2Xv7\",\n \"mzEZcphSw5ZUrEN3MpYmqRCEPBRS8iN34w\"\n ]\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"n4Xag4N3ZDjuhwCLRqifkiSEEQP6PpV36S\",\n \"mpXqw4ekUeJnVt4HUVaUosdMRHckFLpJCV\",\n \"mmKg1fn6nmGHvnTWGz68nxRPUZwCYRkAsD\",\n \"mh1BHTvud83u2YRfdb3PwYS29aVS36cZL7\",\n \"mgMzHjZQAVJBJhYMu4VxKM6kR5SLY4gdDD\",\n \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"mg7RyLK5N2dbdPjeWD2fVr4dTcyavw2Ct2\",\n \"myCuq56SrV2pce92Dm3Nzbe6tm9r46tpEE\",\n \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"n1T7bqxpN2a4Jhy2v4D8S5Z9mU3U4vxLCX\",\n \"mqK5dgq7NbPAAuxC9r86xDrtW2fqz52q4X\",\n \"mrTCKDBAm6E2j3hY1paCRtguSvR9YMjavH\",\n \"mjV34bsrCzmSJdrN93jaAWurkc9TaPBEis\",\n \"n4GBt198ctM4KF1AJGJG8ppxAeFyXFfut9\",\n \"mmpdMa9REnAKFcB53jWjbTbLbXwXcXkNd2\",\n \"myLteN944rTScB8AM9NpmA5qbDvnWNXbNY\",\n \"mg5JJDDtptTPX44PiUibpByPeyMr3tmTL8\",\n \"miCcFsZ8btLRMVDh5eS6einqWKvW5Fd6Nw\",\n \"mw9NWnxosCDEqtGZbdw7u9rnVXcXFQLpJk\",\n \"mpwknBXErVReLTFbGUaDYuJeEpdY8hmw5x\",\n \"mqeKEJuCipt8ArNwvnd9Ed2mpdVSKFjFPf\",\n \"mk7Hr34G619JQ1wzFNRun1zWp9c8PLq7ze\",\n \"mvHTTahf6ZHHUJyEMpAXCDRQrvtSq2jAxZ\",\n \"mxHmETLREWiKKZGbekHYJZLYbCVPvZ3kjX\",\n \"mzQFLzaXkTU6oki1wqikNixwngsBuMjQZG\",\n \"muhcUu1j1b5TrfvnsrMJ68CAUA9hahXHZH\",\n \"mfpDwgCS4TpWdAaMJUpgxFkv2Jw78X8MpL\"\n ]\n}"
|
||||
},
|
||||
{
|
||||
"title": "List addresses in specified account",
|
||||
"curl": "curl -d'{\"method\": \"address_list\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet address list --account_id=\"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_list\", \"params\": {\"account_id\": \"mjy1nohNLnCRF9mcGM13RHwm4fPwp6hZDk\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"mkZ7dj4b1JzgEk1AbdaEKXRZMc3t1Qzz5s\",\n \"miLfQZNWVqDEDYz5fz2iKU9WryD883bsu3\",\n \"mkTBCWDfCkmBWY3GCxfPzLzv1nPrj42g9i\",\n \"mhxiYAHjBy565rG4utN5N7sqyfNedA8gMj\",\n \"mqAiQYyqiqVWXaEYapnu5P49cnLvQdh11s\",\n \"mfXqWw7JwDTjYS2RFPHQRRidRKh8kBQuDA\",\n \"mveVkYXt4i79j8LyVNmSQJRPbiC3D7qfUn\",\n \"n2FP55ZGxWni8yXXRkayaGtKjjCPgjosUg\",\n \"mjUP3SWW5xSQePxyvBJEojThw53p3stPGz\",\n \"mw9wNMarhPNHJZ3WpVYmQBwwSt6RHkKBaE\",\n \"mh7e4ooAELtxhKjtDLkw2GZMdefM8DSgWT\",\n \"mvQ8JJQ892fZugZNpKcQaTRry75GceWo41\",\n \"mySo8Q8qF66jan5ma2jsvkjjf7BNWyPUo8\",\n \"mppmfdJ3EwHNXRdf4qcEN48TQ2ydE9jjSH\",\n \"mwrS4yFmX5Na1cPRoQUWVBNhEpLh63Bn5j\",\n \"mqY3oET1RoUVT7VQPYjBX2atwbUZ43XSoT\",\n \"moCXqVgoM5EGyoxC9nZL6dkabSjE1TcTNu\",\n \"mvPxFaNfj6Ynp5bmVMtZzPiN27q8AvmmVS\",\n \"mr43PzgGuS1FxCbSjfKNdXsqxZV6hjawt3\",\n \"myuyATCL66mckzXzpiFzcFGQbzdYiQjLdt\",\n \"mrzft5H9sA6crxC7kzEUNBJiWzzAS3wKKH\",\n \"mnUVBfAM4BwEQq8fwJ7xuZgARrqkJwJhLc\",\n \"myvpjybXe9sV9bdAZX5uun7mk9tt8HDFrJ\",\n \"mvWm7QzWcD33rn5VZaQNzvWh89VZGYVpbd\",\n \"mzer6QqsQnsUZKYoCrrqVbQumXajXxbpzJ\",\n \"mhCtYeSBpXoQuEUitEeZjUpjRjje6LZmSL\"\n ]\n}"
|
||||
"curl": "curl -d'{\"method\": \"address_list\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet address list --account_id=\"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"address_list\", \"params\": {\"account_id\": \"mjnSjhq9hseBqH4SdLShwfWsPWmEvnFmBa\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"muzvTMwu85wycsEBTiR74My8AjeanjaarL\",\n \"mpipGa36pkDXB1u1XyHCTBFt3PjG8i9cc4\",\n \"ms2CnsNwPX42NZjkYt3kTF4JfpuSxhmjHj\",\n \"msKBwFDKRQGiCfXo8QmdDtfen9FcFYfgaQ\",\n \"mnCnaxRCfSnr8psqX8WeUHXTSrz9VGAcEo\",\n \"mi37PHLrkAoicex47AwsED7qcx15JwVdo7\",\n \"moBknJhYKrmBcGKeTEuL9UQunQfTkAiJ7m\",\n \"n4aN7LF4s3fbCLfncEpLD3BD1Wwqif5uiD\",\n \"mwPoyC91JPq2QmPpiXYjpUDtZDvHP4sbQn\",\n \"mrddwEaQnkvGDggNMskbYUa6menFeKUNoH\",\n \"mygJGMGKC6pydYNG7sLn5bT4PPPXMb8S54\",\n \"miyQCof94kG5bNSK3BSTr4tAkzjVRxhHTM\",\n \"msZvPxSu6kdPwzCdfcbjkDiK4TJuU8Bx4E\",\n \"mmUpT3VvpofQht94ZQJxU8RzgtWAKWVR3z\",\n \"mhqkehtFa9fCsP9u9XF19asaxuj6HCoCFE\",\n \"mi5YkQEetvta42JnM2qS8XtA5Hd5UuxptL\",\n \"mhxK9RYeGNYFFAbrdFzFSR5LLDzS2BsuTn\",\n \"mrBF61TpHevBNkXbUwWcizu37oahG65x2M\",\n \"mqJtXGmoKmrQPKht1qDTXpGRzsisiFzTBD\",\n \"mvjuDoeqvNGyVXUZ5y59tgCz8iCTjsMKkR\",\n \"mvXjURiW7rHjwiBjYBDfEjVHgsRs3U4eua\",\n \"mxq7FS1tMaf8FGV7rH1VssYTQPvjzEYdBu\",\n \"mt5mn8J9eQxnBeDkUEbMpkxLPo1FiRyphT\",\n \"mqhaqAvFqnFdi9JGmfhpyfH43kyJy1q7yp\",\n \"n29guvsCrb6qT4A94kmdogVmcRtn27L9Lh\",\n \"mxiv1v7tdpVE65QHdmVF6KHLtcm1jHx3N9\"\n ]\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -780,7 +792,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\": \"mzPzDUvLyZUKv2LmQdMZAmd4ZNm1Xxgf1z\"\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"mh1BHTvud83u2YRfdb3PwYS29aVS36cZL7\"\n}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -830,10 +842,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Delete a blob",
|
||||
"curl": "curl -d'{\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet blob delete d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"Deleted d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c\"\n}"
|
||||
"curl": "curl -d'{\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet blob delete 019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"blob_delete\", \"params\": {\"blob_hash\": \"019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": \"Deleted 019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33\"\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -911,7 +923,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 \"d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c\",\n \"609e824398f24b7420f1febfc04e1a237364e4ed00fe46a1e936c3ee4926717e4c86ba66708cb78cb1c0c9d68f488396\",\n \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"29d60d4ba62d33a280f448584fd825539f794943625101bd633b63b8f83c2e378a62765ca2e1a05dd720e762881519c2\"\n ]\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n \"019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33\",\n \"a0993d23d26f15bd494699edd3a6a37155d9621fe797579a6c12d56147ec17011d869bfbfede8441ee792eadf342a16f\",\n \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"e15a45f0d4bf7a6e6c1a39202c974d091e4f44530177b27c6cbec7e949db7afa3ec8d713c87621df4fa7dcc896e0e3ab\"\n ]\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -986,10 +998,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Abandon a channel claim",
|
||||
"curl": "curl -d'{\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet channel abandon 7ed794458d57978c49572424e1d32c7fa4d5325e",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001faa6baadb0eb6080167de2226bab20cffb1426ea2e47f2d696280b9d3256720f000000006a47304402205287bb4f85eeb0f38defe91a27b871ff1b7ac94cda6e9885109f9d5ed6e03939022055dcf9daad53f145f464b8e5f6def71d564f3ebc99f882e1a7b0cd5d022b3e4d0121020cd9a5a73e65c43d276d79901f21b22d09f3872e97a9311ea27908142217f6f7ffffffff0134b7f505000000001976a914d4c63445bfef987db896a7835c90728ab7eb598888ac00000000\",\n \"inputs\": [\n {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 8,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mzuzzC1LcwKoRaWEZcR2vcDaSxcakKTMR3\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"1384a1d6010d90d6d463cb63f1fe9b7cc8de70f62f62bf453c5a53cc05d85c22\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"1384a1d6010d90d6d463cb63f1fe9b7cc8de70f62f62bf453c5a53cc05d85c22\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet channel abandon 1812d3275894f62a055d59189a75698a071108af",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_abandon\", \"params\": {\"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001e76b671b4e9cda4db0eb9558919ebb76aedd164240b34700fe20535a14bf6d98000000006a47304402206086e67b5b3ef2da252bccf728bb3902613130dfee2e69b9cd42e1d51c23462b0220156d8ece8cf7c5b4469584cf6985acbb1fb285b26d4f1f2e69302d7d9a00ca550121026b08677484e71843c5db3ce862355276261d123eaaa5437857daeafeea526930ffffffff0134b7f505000000001976a91489741016527d8e511474fe346d3a54603a173d6588ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 8,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mt3juXFNHFPnCydLvtBwmTyAiXzs5joEcn\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"f0fbc91e74a19e2826aba44d919fd571ded9e8a8918a75e516795e1eb7ab0e88\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"f0fbc91e74a19e2826aba44d919fd571ded9e8a8918a75e516795e1eb7ab0e88\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1078,7 +1090,13 @@
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "id of the account to store channel",
|
||||
"description": "account to use for holding the transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "funding_account_ids",
|
||||
"type": "list",
|
||||
"description": "ids of accounts to fund this transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
@@ -1104,17 +1122,17 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Create a channel claim without metadata",
|
||||
"curl": "curl -d'{\"method\": \"channel_create\", \"params\": {\"name\": \"@channel\", \"bid\": \"1.0\", \"featured\": [], \"tags\": [], \"languages\": [], \"locations\": [], \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"curl": "curl -d'{\"method\": \"channel_create\", \"params\": {\"name\": \"@channel\", \"bid\": \"1.0\", \"featured\": [], \"tags\": [], \"languages\": [], \"locations\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": 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, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001346677747fcc2856ad0960e12d1e86cb4ba4b1af34d60db87fa3fd2ce11f070e010000006a4730440220183a3e4c2025f45b083bc970e3437fb3deb14891c2f877697c008d0f5ea8f482022049ac41eefb4c6700e39e78175c9c50f8133a2316663ec127cf4fb9d4aa8a30eb012102ca7e8b7efe7723f0a68d28f38c5b220af9e53f1bc2d344fb458ca527da67cf8affffffff0200e1f5050000000084b508406368616e6e656c4c5d00125a0a583056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae26d7576a914f4f607e8d47646250a79cfc9e57059e6ca8bb56688acc462a029000000001976a91457f3a42422174d5eb185b5bf049869a01db287c988ac00000000\",\n \"inputs\": [\n {\n \"address\": \"n2sMeyyRYF5btHqQTa8Y5eitMZ6pGEKRoE\",\n \"amount\": \"7.999876\",\n \"confirmations\": 2,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485089,\n \"txid\": \"0e071fe12cfda37fb80dd634afb1a44bcb861e2de16009ad5628cc7f74776634\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": null,\n \"txid\": \"50e9f458f59f7ddb51c13e956b178ac9457e00e36bddfe02f6f48079d3e3f896\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"moXzxEEXj4nhGhnozbGGFqGXdEzysbDMHJ\",\n \"amount\": \"6.983769\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"50e9f458f59f7ddb51c13e956b178ac9457e00e36bddfe02f6f48079d3e3f896\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.016107\",\n \"total_input\": \"7.999876\",\n \"total_output\": \"7.983769\",\n \"txid\": \"50e9f458f59f7ddb51c13e956b178ac9457e00e36bddfe02f6f48079d3e3f896\"\n }\n}"
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_create\", \"params\": {\"name\": \"@channel\", \"bid\": \"1.0\", \"featured\": [], \"tags\": [], \"languages\": [], \"locations\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001ab23f9f5b03ff853815af51428028ea086c65f39e607014eb7c82c0cda0e773e010000006b483045022100fa5029892bd48ce525d38063aa87919c060111d3e8387c8b58df9d8bd15c22de02200a97855e781be63f761008887b2a4a3ff60876bf57fea6590690740fa33458ad01210245c35d292e1b029f82f9cab1749e20a4929e955995bafc33afeae20e4fe78887ffffffff0200e1f5050000000084b508406368616e6e656c4c5d00125a0a583056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e6d7576a914aadf6c07f1c7cd225b42ff6abda631b0b102db2888acc462a029000000001976a9149fc8120908ab1812bd462144598da9bc3ffa9d7e88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"muhcUu1j1b5TrfvnsrMJ68CAUA9hahXHZH\",\n \"amount\": \"7.999876\",\n \"confirmations\": 2,\n \"height\": 207,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524491,\n \"txid\": \"3e770eda0c2cc8b74e0107e6395fc686a08e022814f55a8153f83fb0f5f923ab\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": null,\n \"txid\": \"71075987fae1171cb3e6b0db1dc1ef7635c9ebd6e26e1d510fdce1e4ebb576fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mv5oQhBhKEBinD1Bs3MKmzznidZSGBN1FG\",\n \"amount\": \"6.983769\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"71075987fae1171cb3e6b0db1dc1ef7635c9ebd6e26e1d510fdce1e4ebb576fa\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.016107\",\n \"total_input\": \"7.999876\",\n \"total_output\": \"7.983769\",\n \"txid\": \"71075987fae1171cb3e6b0db1dc1ef7635c9ebd6e26e1d510fdce1e4ebb576fa\"\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\", \"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, \"blocking\": 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\", \"funding_account_ids\": [], \"preview\": false, \"blocking\": 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\", \"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, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001faa6baadb0eb6080167de2226bab20cffb1426ea2e47f2d696280b9d3256720f010000006a473044022061957aa9e53c7588f10eaf460686fd02ac447f91a5f5fc69b010a509ba7d99d802207be2706dd40cf990811ea5e1484502e29510c8c0d0b2368a79b2c6186f3002c90121039e6825507996b2a26d8f13aa036b7beaf1688dfa8d1323224ce52154183d3164ffffffff0200e1f50500000000fd5001b50b406269676368616e6e656c4d25010012ab010a583056301006072a8648ce3d020106052b8104000a034200042b3464f5e174daad84a899552847c9af4a4577bfc9e867402aa30da9a966ab493f7c82c30642aaa5dcfbdeebe9f3ab021f09964ad93bfecb9b9e3cac7a35c9fe121663726561746f7240736d616c6c6d656469612e636f6d1a15687474703a2f2f736d616c6c6d656469612e636f6d22202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a7067420b426967204368616e6e656c4a1e41206368616e6e656c2077697468206c6f7473206f6620766964656f732e52202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a70675a056d757369635a0361727462050883011820620308ab016a0208206a0908e9011a044b6979766d7576a914cf1914f5cdcaf0d0ca01b53b7688dabea5cd9eb388ace221d305000000001976a9147d8fe8303a8d1506e3823e471e55ea128bfe637d88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"n2FNDLjvbu4dnW6pCtGKJN87PttvCeBWsR\",\n \"amount\": \"1.9993355\",\n \"confirmations\": 1,\n \"height\": 210,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mzPzDUvLyZUKv2LmQdMZAmd4ZNm1Xxgf1z\",\n \"amount\": \"1.0\",\n \"claim_id\": \"9d667ca2325a93dfbab993f4e22f63ce529eae92\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"@bigchannel\",\n \"normalized_name\": \"@bigchannel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@bigchannel#9d667ca2325a93dfbab993f4e22f63ce529eae92\",\n \"timestamp\": null,\n \"txid\": \"aa003b09c9a280b34d3d790f7bca3a12a7b8f0473f476cc7bc81b3853acb8ab4\",\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\": \"3056301006072a8648ce3d020106052b8104000a034200042b3464f5e174daad84a899552847c9af4a4577bfc9e867402aa30da9a966ab493f7c82c30642aaa5dcfbdeebe9f3ab021f09964ad93bfecb9b9e3cac7a35c9fe\",\n \"public_key_id\": \"mxN41g7KAmKtMbA1b25XgVWASvYVvKEcVW\",\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\": \"mrxs9s9nJgdvS6qW2ca4yr5UY6RkWS5zk9\",\n \"amount\": \"0.9772285\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"aa003b09c9a280b34d3d790f7bca3a12a7b8f0473f476cc7bc81b3853acb8ab4\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.022107\",\n \"total_input\": \"1.9993355\",\n \"total_output\": \"1.9772285\",\n \"txid\": \"aa003b09c9a280b34d3d790f7bca3a12a7b8f0473f476cc7bc81b3853acb8ab4\"\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\", \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001e76b671b4e9cda4db0eb9558919ebb76aedd164240b34700fe20535a14bf6d98010000006b483045022100f682c30b7e11d75a7c8003a0cf960225084bc0848dd1b87b9bcb5943df7cc89a02206eeb81a9d82041bc002938de734054e5bfbc0449ea595d047d830022815fcceb012102f468240028c0200dd91d0471061d20b84380888f5bc5e025512c710867053b4dffffffff0200e1f50500000000fd5001b50b406269676368616e6e656c4d25010012ab010a583056301006072a8648ce3d020106052b8104000a03420004af3f67b2c8c268546ddc740380fcea6dd60eadec5cb2fd081ec1d59bad5c8f94556d94f5b96f116459fe476de5597fbc9641f37751743d17fe33b213513bc658121663726561746f7240736d616c6c6d656469612e636f6d1a15687474703a2f2f736d616c6c6d656469612e636f6d22202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a7067420b426967204368616e6e656c4a1e41206368616e6e656c2077697468206c6f7473206f6620766964656f732e52202a1e687474703a2f2f736d616c6c6d656469612e636f6d2f6c6f676f2e6a70675a056d757369635a0361727462050883011820620308ab016a0208206a0908e9011a044b6979766d7576a91462e43cc42aaf50122b0b822c72e92df47752382488ace221d305000000001976a914c2d853ebfe9374f515d77fcc99fa3a4720dcd9d288ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mvHTTahf6ZHHUJyEMpAXCDRQrvtSq2jAxZ\",\n \"amount\": \"1.9993355\",\n \"confirmations\": 1,\n \"height\": 210,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mpXqw4ekUeJnVt4HUVaUosdMRHckFLpJCV\",\n \"amount\": \"1.0\",\n \"claim_id\": \"70be52d169e5debb0021317540fc7bc941af02dc\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"@bigchannel\",\n \"normalized_name\": \"@bigchannel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@bigchannel#70be52d169e5debb0021317540fc7bc941af02dc\",\n \"timestamp\": null,\n \"txid\": \"9b92799eb906956b01458dd97ace5e02f3c201a1c67089dc694b11caa77fedbd\",\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\": \"3056301006072a8648ce3d020106052b8104000a03420004af3f67b2c8c268546ddc740380fcea6dd60eadec5cb2fd081ec1d59bad5c8f94556d94f5b96f116459fe476de5597fbc9641f37751743d17fe33b213513bc658\",\n \"public_key_id\": \"n34uW64WnxJnnr9n6PWsHrzpQf2Qg8jV1h\",\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\": \"myHCXzM5bmTxED6Tyc9WcLhGsP1u8M9Wfo\",\n \"amount\": \"0.9772285\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"9b92799eb906956b01458dd97ace5e02f3c201a1c67089dc694b11caa77fedbd\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.022107\",\n \"total_input\": \"1.9993355\",\n \"total_output\": \"1.9772285\",\n \"txid\": \"9b92799eb906956b01458dd97ace5e02f3c201a1c67089dc694b11caa77fedbd\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1188,14 +1206,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\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"50e9f458f59f7ddb51c13e956b178ac9457e00e36bddfe02f6f48079d3e3f896\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\"\n },\n \"value_type\": \"channel\"\n }\n ]\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"71075987fae1171cb3e6b0db1dc1ef7635c9ebd6e26e1d510fdce1e4ebb576fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\"\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\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"50e9f458f59f7ddb51c13e956b178ac9457e00e36bddfe02f6f48079d3e3f896\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"71075987fae1171cb3e6b0db1dc1ef7635c9ebd6e26e1d510fdce1e4ebb576fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1302,7 +1320,13 @@
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "id of the account to store channel",
|
||||
"description": "account to use for holding the transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "funding_account_ids",
|
||||
"type": "list",
|
||||
"description": "ids of accounts to fund this transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
@@ -1340,10 +1364,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Update a channel claim",
|
||||
"curl": "curl -d'{\"method\": \"channel_update\", \"params\": {\"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"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, \"blocking\": false, \"replace\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet channel update 7ed794458d57978c49572424e1d32c7fa4d5325e --title=\"New Channel\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_update\", \"params\": {\"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"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, \"blocking\": false, \"replace\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"010000000296f8e3d37980f4f602fedd6be3007e45c98a176b953ec151db7d9ff558f4e950000000006a473044022061d6150bc3b011aaea76878575017c4e5eb21fac6b8a4cbbee9c085bd33587d50220488279fbf29cc4cbbedf4203082a16ae48b966181fea88d5d30e3627f28811730121020cd9a5a73e65c43d276d79901f21b22d09f3872e97a9311ea27908142217f6f7ffffffff5dd1cf1adfb176787a309e839cb05d9811f2b7e1144d1deec09b7e61d186e6c5000000006a47304402205b253336e35c39d7bee5e39508281043e4b463cf1ad1f76dc244ee869ef185b502205891abd1fa4c637b43ae19dde8857e9fb09627a173e84ba6bd96dfc1d154a087012103398d533373ab8881bb7a9e1060284ce9afd4e25fcca09d30fcf41da9b809ff11ffffffff0200e1f50500000000a6b708406368616e6e656c145e32d5a47f2cd3e1242457498c97578d4594d77e4c6a00125a0a583056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2420b4e6577204368616e6e656c6d6d76a914f4f607e8d47646250a79cfc9e57059e6ca8bb56688ac6ebeea0b000000001976a914e367f3d29e8b54f79c92ec2cf83a79ca5e04c60688ac00000000\",\n \"inputs\": [\n {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"50e9f458f59f7ddb51c13e956b178ac9457e00e36bddfe02f6f48079d3e3f896\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mzbuijFAnVGiEKWb9n24hcrUgdxauR3i83\",\n \"amount\": \"1.999604\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1561485089,\n \"txid\": \"c5e686d1617e9bc0ee1d4d14e1b7f211985db09c839e307a7876b1df1acfd15d\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": null,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"n2FNDLjvbu4dnW6pCtGKJN87PttvCeBWsR\",\n \"amount\": \"1.9993355\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.0002685\",\n \"total_input\": \"2.999604\",\n \"total_output\": \"2.9993355\",\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"channel_update\", \"params\": {\"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"title\": \"New Channel\", \"featured\": [], \"clear_featured\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"new_signing_key\": false, \"funding_account_ids\": [], \"preview\": false, \"blocking\": false, \"replace\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet channel update 1812d3275894f62a055d59189a75698a071108af --title=\"New Channel\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"channel_update\", \"params\": {\"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"title\": \"New Channel\", \"featured\": [], \"clear_featured\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"new_signing_key\": false, \"funding_account_ids\": [], \"preview\": false, \"blocking\": false, \"replace\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000002fa76b5ebe4e1dc0f511d6ee2d6ebc93576efc11ddbb0e6b31c17e1fa87590771000000006b483045022100c66ff055a275b9217ef363ae87ffda7ef44986bef685cec8d2ccafbbc367160e02206c191c13d228d516854537915a2101dee9065ed364c17437fc6a9aa8fb1421e70121026b08677484e71843c5db3ce862355276261d123eaaa5437857daeafeea526930ffffffff2c446233fb6c0e348fce0d78c98eb0ba6fa84a5f949e46424aa38cfc1d29f844000000006a47304402206956d6778c51de7306fb9e924ff8f58e2401517290ed64cb2e6c46b8a7bb69f902205c1375c4c0a8411db6a415a4950ec433410c01985c1ca7cbfb0de7145368aa50012102dface3eea48cf6ad620818099a453434adbf56c152268e680f23666d55ce2ac3ffffffff0200e1f50500000000a6b708406368616e6e656c14af0811078a69759a18595d052af6945827d312184c6a00125a0a583056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e420b4e6577204368616e6e656c6d6d76a914aadf6c07f1c7cd225b42ff6abda631b0b102db2888ac6ebeea0b000000001976a914a1fc688cf5f6899e6342e463d72eca70f73b973388ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"71075987fae1171cb3e6b0db1dc1ef7635c9ebd6e26e1d510fdce1e4ebb576fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mqeKEJuCipt8ArNwvnd9Ed2mpdVSKFjFPf\",\n \"amount\": \"1.999604\",\n \"confirmations\": 1,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 0,\n \"timestamp\": 1567524491,\n \"txid\": \"44f8291dfc8ca34a42469e945f4aa86fbab08ec9780dce8f340e6cfb3362442c\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": null,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n {\n \"address\": \"mvHTTahf6ZHHUJyEMpAXCDRQrvtSq2jAxZ\",\n \"amount\": \"1.9993355\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.0002685\",\n \"total_input\": \"2.999604\",\n \"total_output\": \"2.9993355\",\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\"\n }\n}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1382,14 +1406,14 @@
|
||||
"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\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ]\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\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\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_items\": 2,\n \"total_pages\": 1\n }\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_items\": 2,\n \"total_pages\": 1\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1429,13 +1453,13 @@
|
||||
},
|
||||
{
|
||||
"name": "channel_ids",
|
||||
"type": "str",
|
||||
"type": "list",
|
||||
"description": "claims signed by any of these channels (arguments must be claim ids of the channels), includes claims with invalid signatures, implies --has_channel_signature, use in conjunction with --valid_channel_signature",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "not_channel_ids",
|
||||
"type": "str",
|
||||
"type": "list",
|
||||
"description": "exclude claims signed by any of these channels (arguments must be claim ids of the channels)",
|
||||
"is_required": false
|
||||
},
|
||||
@@ -1651,9 +1675,15 @@
|
||||
},
|
||||
{
|
||||
"name": "order_by",
|
||||
"type": "str",
|
||||
"type": "list",
|
||||
"description": "field to order by, default is descending order, to do an ascending order prepend ^ to the field name, eg. '^amount' available fields: 'name', 'height', 'release_time', 'publish_time', 'amount', 'effective_amount', 'support_amount', 'trending_group', 'trending_mixed', 'trending_local', 'trending_global', 'activation_height'",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "no_totals",
|
||||
"type": "bool",
|
||||
"description": "do not calculate the total number of pages and items in result set (significant performance boost)",
|
||||
"is_required": false
|
||||
}
|
||||
],
|
||||
"returns": " {\n \"page\": \"Page number of the current items.\",\n \"page_size\": \"Number of items to show on a page.\",\n \"total_pages\": \"Total number of pages.\",\n \"total_items\": \"Total number of items.\",\n \"items\": [\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 }",
|
||||
@@ -1663,22 +1693,36 @@
|
||||
"curl": "curl -d'{\"method\": \"claim_search\", \"params\": {\"channel\": \"@channel\", \"channel_ids\": [], \"not_channel_ids\": [], \"has_channel_signature\": false, \"valid_channel_signature\": false, \"invalid_channel_signature\": false, \"is_controlling\": false, \"stream_types\": [], \"media_types\": [], \"any_tags\": [], \"all_tags\": [], \"not_tags\": [], \"any_languages\": [], \"all_languages\": [], \"not_languages\": [], \"any_locations\": [], \"all_locations\": [], \"not_locations\": [], \"order_by\": []}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet claim search --channel=@channel",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"claim_search\", \"params\": {\"channel\": \"@channel\", \"channel_ids\": [], \"not_channel_ids\": [], \"has_channel_signature\": false, \"valid_channel_signature\": false, \"invalid_channel_signature\": false, \"is_controlling\": false, \"stream_types\": [], \"media_types\": [], \"any_tags\": [], \"all_tags\": [], \"not_tags\": [], \"any_languages\": [], \"all_languages\": [], \"not_languages\": [], \"any_locations\": [], \"all_locations\": [], \"not_locations\": [], \"order_by\": []}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#7/astream#5\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"meta\": {\n \"activation_height\": 213,\n \"creation_height\": 213,\n \"creation_timestamp\": 1561485090,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263187,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 213,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"short_url\": \"lbry://astream#5\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#7\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"meta\": {\n \"activation_height\": 209,\n \"claims_in_channel\": 1,\n \"creation_height\": 209,\n \"creation_timestamp\": 1561485089,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263183,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 209,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"short_url\": \"lbry://@channel#7\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 10,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#1/astream#b\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"meta\": {\n \"activation_height\": 213,\n \"creation_height\": 213,\n \"creation_timestamp\": 1567524492,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263187,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 213,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"short_url\": \"lbry://astream#b\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#1\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"meta\": {\n \"activation_height\": 209,\n \"claims_in_channel\": 1,\n \"creation_height\": 209,\n \"creation_timestamp\": 1567524491,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263183,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 209,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"short_url\": \"lbry://@channel#1\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 10,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
},
|
||||
{
|
||||
"title": "Search for claims matching a name",
|
||||
"curl": "curl -d'{\"method\": \"claim_search\", \"params\": {\"name\": \"astream\", \"channel_ids\": [], \"not_channel_ids\": [], \"has_channel_signature\": false, \"valid_channel_signature\": false, \"invalid_channel_signature\": false, \"is_controlling\": false, \"stream_types\": [], \"media_types\": [], \"any_tags\": [], \"all_tags\": [], \"not_tags\": [], \"any_languages\": [], \"all_languages\": [], \"not_languages\": [], \"any_locations\": [], \"all_locations\": [], \"not_locations\": [], \"order_by\": []}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet claim search --name=\"astream\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"claim_search\", \"params\": {\"name\": \"astream\", \"channel_ids\": [], \"not_channel_ids\": [], \"has_channel_signature\": false, \"valid_channel_signature\": false, \"invalid_channel_signature\": false, \"is_controlling\": false, \"stream_types\": [], \"media_types\": [], \"any_tags\": [], \"all_tags\": [], \"not_tags\": [], \"any_languages\": [], \"all_languages\": [], \"not_languages\": [], \"any_locations\": [], \"all_locations\": [], \"not_locations\": [], \"order_by\": []}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#7/astream#5\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"meta\": {\n \"activation_height\": 213,\n \"creation_height\": 213,\n \"creation_timestamp\": 1561485090,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263187,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 213,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"short_url\": \"lbry://astream#5\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#7\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"meta\": {\n \"activation_height\": 209,\n \"claims_in_channel\": 1,\n \"creation_height\": 209,\n \"creation_timestamp\": 1561485089,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263183,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 209,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"short_url\": \"lbry://@channel#7\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 10,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#1/astream#b\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_op\": \"update\",\n \"confirmations\": 1,\n \"height\": 214,\n \"is_channel_signature_valid\": true,\n \"meta\": {\n \"activation_height\": 213,\n \"creation_height\": 213,\n \"creation_timestamp\": 1567524492,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263187,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 213,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"short_url\": \"lbry://astream#b\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"canonical_url\": \"lbry://@channel#1\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"meta\": {\n \"activation_height\": 209,\n \"claims_in_channel\": 1,\n \"creation_height\": 209,\n \"creation_timestamp\": 1567524491,\n \"effective_amount\": \"1.0\",\n \"expiration_height\": 263183,\n \"is_controlling\": true,\n \"support_amount\": \"0.0\",\n \"take_over_height\": 209,\n \"trending_global\": 0.0,\n \"trending_group\": 0,\n \"trending_local\": 0.0,\n \"trending_mixed\": 0.0\n },\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"short_url\": \"lbry://@channel#1\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 10,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"comment": {
|
||||
"doc": "Create and list comments.",
|
||||
"doc": "View, create and abandon comments.",
|
||||
"commands": [
|
||||
{
|
||||
"name": "comment_abandon",
|
||||
"description": "Abandon a comment published under your channel identity.",
|
||||
"arguments": [
|
||||
{
|
||||
"name": "comment_id",
|
||||
"type": "str",
|
||||
"description": "The ID of the comment to be abandoned.",
|
||||
"is_required": true
|
||||
}
|
||||
],
|
||||
"returns": "(dict) Object with the `comment_id` passed in as the key, and a flag indicating if it was abandoned\n {\n <comment_id> (str): {\n \"abandoned\": (bool)\n }\n }",
|
||||
"examples": []
|
||||
},
|
||||
{
|
||||
"name": "comment_create",
|
||||
"description": "Create and associate a comment with a claim using your channel identity.",
|
||||
@@ -1723,6 +1767,20 @@
|
||||
"returns": "(dict) Comment object if successfully made, (None) otherwise\n {\n \"comment\": (str) The actual string as inputted by the user,\n \"comment_id\": (str) The Comment's unique identifier,\n \"channel_name\": (str) Name of the channel this was posted under, prepended with a '@',\n \"channel_id\": (str) The Channel Claim ID that this comment was posted under,\n \"signature\": (str) The signature of the comment,\n \"channel_url\": (str) Channel's URI in the ClaimTrie,\n \"parent_id\": (str) Comment this is replying to, (None) if this is the root,\n \"timestamp\": (int) The time at which comment was entered into the server at, in nanoseconds.\n }",
|
||||
"examples": []
|
||||
},
|
||||
{
|
||||
"name": "comment_hide",
|
||||
"description": "Hide a comment published to a claim you control.",
|
||||
"arguments": [
|
||||
{
|
||||
"name": "comment_ids",
|
||||
"type": "str, list",
|
||||
"description": "one or more comment_id to hide.",
|
||||
"is_required": false
|
||||
}
|
||||
],
|
||||
"returns": "(dict) keyed by comment_id, containing success info\n '<comment_id>': {\n \"hidden\": (bool) flag indicating if comment_id was hidden\n }",
|
||||
"examples": []
|
||||
},
|
||||
{
|
||||
"name": "comment_list",
|
||||
"description": "List comments associated with a claim.",
|
||||
@@ -1762,6 +1820,18 @@
|
||||
"type": "bool",
|
||||
"description": "Only include comments with valid signatures. [Warning: Paginated total size will not change, even if list reduces]",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "visible",
|
||||
"type": "bool",
|
||||
"description": "Select only Visisble Comments",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "hidden",
|
||||
"type": "bool",
|
||||
"description": "Select only Hidden Comments",
|
||||
"is_required": false
|
||||
}
|
||||
],
|
||||
"returns": "(dict) Containing the list, and information about the paginated content:\n {\n \"page\": \"Page number of the current items.\",\n \"page_size\": \"Number of items to show on a page.\",\n \"total_pages\": \"Total number of pages.\",\n \"total_items\": \"Total number of items.\",\n \"items\": \"A List of dict objects representing comments.\"\n [\n {\n \"comment\": (str) The actual string as inputted by the user,\n \"comment_id\": (str) The Comment's unique identifier,\n \"channel_name\": (str) Name of the channel this was posted under, prepended with a '@',\n \"channel_id\": (str) The Channel Claim ID that this comment was posted under,\n \"signature\": (str) The signature of the comment,\n \"channel_url\": (str) Channel's URI in the ClaimTrie,\n \"parent_id\": (str) Comment this is replying to, (None) if this is the root,\n \"timestamp\": (int) The time at which comment was entered into the server at, in nanoseconds.\n },\n ...\n ]\n }",
|
||||
@@ -1853,9 +1923,9 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Delete a file",
|
||||
"curl": "curl -d'{\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet file delete --claim_id=\"5d64500fb723eded83a41b0d5055f1783f019191\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\"}}).json()",
|
||||
"curl": "curl -d'{\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet file delete --claim_id=\"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_delete\", \"params\": {\"delete_from_download_dir\": false, \"delete_all\": false, \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": true\n}"
|
||||
}
|
||||
]
|
||||
@@ -1962,14 +2032,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\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_name\": \"astream\",\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\": \"e8b365259d5b8644a6a1eb5d2f77459f\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"015e32d5a47f2cd3e1242457498c97578d4594d77ee519fc56b21384e97c75d5c1b6450f2138e209f7bbd2adb588609ba36d1982a2187070c391a89793a0b569f09fef656fe041eab1809e3964f6346ae0fb3d20f30a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d707a6a31716278666a180b22186170706c69636174696f6e2f6f637465742d73747265616d3230d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"8b7dee36b0985027ad1476590ee5759359b57e4cb6507d5288ffe1508c32177f5a39ef20772cf90da72987f6f55ce1ba\",\n \"stream_name\": \"tmpzj1qbxfj\",\n \"streaming_url\": \"http://localhost:5280/stream/d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"suggested_file_name\": \"tmpzj1qbxfj\",\n \"timestamp\": null,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"written_bytes\": null\n },\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"8cef1fdff80ef393ddb24a73ba60196610bedbc9\",\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\": \"e7256de8c71f32d15b11d820dded4ae8\",\n \"metadata\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"miLhR5kJLGVqi5Ss2VKT2Nxt4fToriqtX2\",\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\": \"1561485066\",\n \"source\": {\n \"hash\": \"6c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545\",\n \"media_type\": \"image/png\",\n \"name\": \"tmp_zkvgv47.png\",\n \"sd_hash\": \"d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c\",\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\": \"62a6d649879ce6a35a33265b8a9421faf24fd1e40457fdcdb4753d7eb7de6e0f:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"015e32d5a47f2cd3e1242457498c97578d4594d77ef0d8c8998fb8a90c600f66f6bce1b38b4f8ccca60f1896a1d0b85e3735c50d5b4841a37bb45dfdbef1ca2712189280efd4382ac843e11e6272e0389c1b99b6630ae6010a82010a306c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50eLine 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\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_name\": \"astream\",\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\": \"44c98cff66e9387514d212369d4af15e\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01af0811078a69759a18595d052af6945827d31218a49f0b990dfb596d464fa5c166a752b4835b01f02dcabd712d4345b09c18ce4096395d25caf4fb962732f54d58df839f9dd7cc2ef1d4303c89e4dd553865ed060a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d706d6a65676f306666180b22186170706c69636174696f6e2f6f637465742d73747265616d32302ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"d2fdfe280a77e5dd71f82cd531782ec5f71db1b2f9b6bf4da71240b5ad6fb21367d4b53e6f84fa83cc190aff004dd7bd\",\n \"stream_name\": \"tmpmjego0ff\",\n \"streaming_url\": \"http://localhost:5280/stream/2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"suggested_file_name\": \"tmpmjego0ff\",\n \"timestamp\": null,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"written_bytes\": 0\n },\n {\n \"blobs_completed\": 1,\n \"blobs_in_stream\": 1,\n \"blobs_remaining\": 0,\n \"channel_claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"0e08f286e3e5cf0b17d3fa64da93fbf96b0e9c90\",\n \"claim_name\": \"blank-image\",\n \"completed\": false,\n \"confirmations\": -1,\n \"content_fee\": null,\n \"download_directory\": null,\n \"download_path\": null,\n \"file_name\": null,\n \"height\": -1,\n \"key\": \"9625cf71e26cdbc140dcec6d6cbfc46e\",\n \"metadata\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"n4GBt198ctM4KF1AJGJG8ppxAeFyXFfut9\",\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\": \"1567524468\",\n \"source\": {\n \"hash\": \"6c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545\",\n \"media_type\": \"image/png\",\n \"name\": \"tmpg_6t0r6a.png\",\n \"sd_hash\": \"019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33\",\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\": \"55d87be458bd1a9aa960dd914b7f5c6d1b118d65d8b04477f705716d33091530:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01af0811078a69759a18595d052af6945827d312183830ab666b25817d8432e95af7bb26baed712eeca26420f81c8f8255ca008c86dbb6c771a21cbc97d0f460f7b4d4243e40a26d66f77c615f0f9cb4f99a228a830ae6010a82010a306c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85Line truncated
|
||||
},
|
||||
{
|
||||
"title": "List files matching a parameter",
|
||||
"curl": "curl -d'{\"method\": \"file_list\", \"params\": {\"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\", \"reverse\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet file list --claim_id=\"5d64500fb723eded83a41b0d5055f1783f019191\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_list\", \"params\": {\"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\", \"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\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\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\": \"e8b365259d5b8644a6a1eb5d2f77459f\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"015e32d5a47f2cd3e1242457498c97578d4594d77ee519fc56b21384e97c75d5c1b6450f2138e209f7bbd2adb588609ba36d1982a2187070c391a89793a0b569f09fef656fe041eab1809e3964f6346ae0fb3d20f30a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d707a6a31716278666a180b22186170706c69636174696f6e2f6f637465742d73747265616d3230d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"8b7dee36b0985027ad1476590ee5759359b57e4cb6507d5288ffe1508c32177f5a39ef20772cf90da72987f6f55ce1ba\",\n \"stream_name\": \"tmpzj1qbxfj\",\n \"streaming_url\": \"http://localhost:5280/stream/d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"suggested_file_name\": \"tmpzj1qbxfj\",\n \"timestamp\": 1561485090,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"written_bytes\": null\n }\n ]\n}"
|
||||
"curl": "curl -d'{\"method\": \"file_list\", \"params\": {\"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\", \"reverse\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet file list --claim_id=\"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_list\", \"params\": {\"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\", \"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\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\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\": \"44c98cff66e9387514d212369d4af15e\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01af0811078a69759a18595d052af6945827d31218a49f0b990dfb596d464fa5c166a752b4835b01f02dcabd712d4345b09c18ce4096395d25caf4fb962732f54d58df839f9dd7cc2ef1d4303c89e4dd553865ed060a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d706d6a65676f306666180b22186170706c69636174696f6e2f6f637465742d73747265616d32302ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"status\": \"finished\",\n \"stopped\": true,\n \"stream_hash\": \"d2fdfe280a77e5dd71f82cd531782ec5f71db1b2f9b6bf4da71240b5ad6fb21367d4b53e6f84fa83cc190aff004dd7bd\",\n \"stream_name\": \"tmpmjego0ff\",\n \"streaming_url\": \"http://localhost:5280/stream/2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"suggested_file_name\": \"tmpmjego0ff\",\n \"timestamp\": 1567524492,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"written_bytes\": 0\n }\n ]\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2086,10 +2156,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Save a file to the downloads directory",
|
||||
"curl": "curl -d'{\"method\": \"file_save\", \"params\": {\"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet file save --sd_hash=\"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_save\", \"params\": {\"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\"}}).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\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\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\": \"e8b365259d5b8644a6a1eb5d2f77459f\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"015e32d5a47f2cd3e1242457498c97578d4594d77ee519fc56b21384e97c75d5c1b6450f2138e209f7bbd2adb588609ba36d1982a2187070c391a89793a0b569f09fef656fe041eab1809e3964f6346ae0fb3d20f30a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d707a6a31716278666a180b22186170706c69636174696f6e2f6f637465742d73747265616d3230d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"status\": \"running\",\n \"stopped\": false,\n \"stream_hash\": \"8b7dee36b0985027ad1476590ee5759359b57e4cb6507d5288ffe1508c32177f5a39ef20772cf90da72987f6f55ce1ba\",\n \"stream_name\": \"tmpzj1qbxfj\",\n \"streaming_url\": \"http://localhost:5280/stream/d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"suggested_file_name\": \"tmpzj1qbxfj\",\n \"timestamp\": 1561485090,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"written_bytes\": null\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"file_save\", \"params\": {\"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet file save --sd_hash=\"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"file_save\", \"params\": {\"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\"}}).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\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"channel_name\": \"@channel\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\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\": \"44c98cff66e9387514d212369d4af15e\",\n \"metadata\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"mime_type\": \"application/octet-stream\",\n \"nout\": 0,\n \"outpoint\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231:0\",\n \"points_paid\": 0.0,\n \"protobuf\": \"01af0811078a69759a18595d052af6945827d31218a49f0b990dfb596d464fa5c166a752b4835b01f02dcabd712d4345b09c18ce4096395d25caf4fb962732f54d58df839f9dd7cc2ef1d4303c89e4dd553865ed060a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d706d6a65676f306666180b22186170706c69636174696f6e2f6f637465742d73747265616d32302ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"status\": \"running\",\n \"stopped\": false,\n \"stream_hash\": \"d2fdfe280a77e5dd71f82cd531782ec5f71db1b2f9b6bf4da71240b5ad6fb21367d4b53e6f84fa83cc190aff004dd7bd\",\n \"stream_name\": \"tmpmjego0ff\",\n \"streaming_url\": \"http://localhost:5280/stream/2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"suggested_file_name\": \"tmpmjego0ff\",\n \"timestamp\": 1567524492,\n \"total_bytes\": 16,\n \"total_bytes_lower_bound\": 0,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"written_bytes\": 0\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2165,6 +2235,73 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"preference": {
|
||||
"doc": "Preferences management.",
|
||||
"commands": [
|
||||
{
|
||||
"name": "preference_get",
|
||||
"description": "Get preference value for key or all values if not key is passed in.",
|
||||
"arguments": [
|
||||
{
|
||||
"name": "key",
|
||||
"type": "str",
|
||||
"description": "key associated with value",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "id of the account containing value",
|
||||
"is_required": false
|
||||
}
|
||||
],
|
||||
"returns": "(dict) Dictionary of preference(s)",
|
||||
"examples": [
|
||||
{
|
||||
"title": "Get preferences",
|
||||
"curl": "curl -d'{\"method\": \"preference_get\", \"params\": {}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet preference get",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"preference_get\", \"params\": {}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"theme\": \"dark\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "preference_set",
|
||||
"description": "Set preferences",
|
||||
"arguments": [
|
||||
{
|
||||
"name": "key",
|
||||
"type": "str",
|
||||
"description": "key associated with value",
|
||||
"is_required": true
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "str",
|
||||
"description": "key associated with value",
|
||||
"is_required": true
|
||||
},
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "id of the account containing value",
|
||||
"is_required": false
|
||||
}
|
||||
],
|
||||
"returns": "(dict) Dictionary with key/value of new preference",
|
||||
"examples": [
|
||||
{
|
||||
"title": "Set preference",
|
||||
"curl": "curl -d'{\"method\": \"preference_set\", \"params\": {\"key\": \"theme\", \"value\": \"dark\"}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet preference set \"theme\" \"dark\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"preference_set\", \"params\": {\"key\": \"theme\", \"value\": \"dark\"}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"theme\": \"dark\"\n }\n}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"doc": "Settings management.",
|
||||
"commands": [
|
||||
@@ -2179,7 +2316,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 \"blob_lru_cache_size\": 0,\n \"blockchain_name\": \"lbrycrd_regtest\",\n \"cache_time\": 150,\n \"coin_selection_strategy\": \"standard\",\n \"comment_server\": \"https://comments.lbry.com/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/tmpfjnst0c0\",\n \"download_dir\": \"/tmp/tmpfjnst0c0\",\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\": 4,\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\": 3.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 \"streaming_get\": true,\n \"streaming_server\": \"localhost:5280\",\n \"tcp_port\": 3333,\n \"udp_port\": 4444,\n \"use_upnp\": false,\n \"wallet_dir\": \"/tmp/tmpfjnst0c0\"\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 \"blob_lru_cache_size\": 0,\n \"blockchain_name\": \"lbrycrd_regtest\",\n \"cache_time\": 150,\n \"coin_selection_strategy\": \"standard\",\n \"comment_server\": \"https://comments.lbry.com/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/tmptn5ym8in\",\n \"download_dir\": \"/tmp/tmptn5ym8in\",\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\": 4,\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\": 3.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 \"streaming_get\": true,\n \"streaming_server\": \"localhost:5280\",\n \"tcp_port\": 3333,\n \"track_bandwidth\": true,\n \"udp_port\": 4444,\n \"use_upnp\": false,\n \"wallet_dir\": \"/tmp/tmptn5ym8in\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2188,7 +2325,15 @@
|
||||
"description": "Set daemon settings",
|
||||
"arguments": [],
|
||||
"returns": "(dict) Updated dictionary of daemon settings",
|
||||
"examples": []
|
||||
"examples": [
|
||||
{
|
||||
"title": "Set settings",
|
||||
"curl": "curl -d'{\"method\": \"settings_set\", \"params\": {\"key\": \"tcp_port\", \"value\": 99}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet settings set \"tcp_port\" 99",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"settings_set\", \"params\": {\"key\": \"tcp_port\", \"value\": 99}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"tcp_port\": 99\n }\n}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2240,10 +2385,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Abandon a stream claim",
|
||||
"curl": "curl -d'{\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream abandon 5d64500fb723eded83a41b0d5055f1783f019191",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\", \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000017e19c275684db4fd0f44b44777ba62ebe6e45eb3737637cbd8eb5dafadf1c2da000000006b483045022100c624c1ad3ba9ef23da28e8a21bda59d223bca0cc7011e952d14ab9fc065058aa022046708292d323bf9053ded6de63ae948058fa5650c8a2a3286ca700bb797be32e0121039efda2d8dd29b422fb044b6ccf6791ec3b0489713619b3f9dd9e8c89a4e54779ffffffff0134b7f505000000001976a9145b91c67ced35c7e2197da2da28fde8c113ef8a4588ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_op\": \"update\",\n \"confirmations\": 3,\n \"height\": 214,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mos8RABG1AF9QQ4HPVABG9p9ERCQ4DGG2Z\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"43b91f8ca1e4b543ddaa540e1b9026084f137cea5e9a9d7381321508086f3ce5\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"43b91f8ca1e4b543ddaa540e1b9026084f137cea5e9a9d7381321508086f3ce5\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\", \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream abandon bfb7d50e084d6d246ca9ff909c401aab30a6f9a6",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_abandon\", \"params\": {\"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\", \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"010000000131f2c34ed0090e10d3072ff86c9286a79d3eea3aa7ffb7350ecfb4c2428733f3000000006b4830450221008cf6f4d298c8275a90eab2e01822fedb9d12346873dfe0b44816a15121f150560220638d9b125eedbf87ed043a05df039e06b834159d1ecfb46c9da763b0390034180121023b0815369b8ef78200d00b1fef7fdd6bf0dac1a84cb34756aa390e54e07e85ecffffffff0134b7f505000000001976a9144f20673b0be85c20dfaf5e27efc880c0b31c8b0988ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_op\": \"update\",\n \"confirmations\": 3,\n \"height\": 214,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mnjLVdEZcL1cPXoWntjbvkaPDPpYLTVdSJ\",\n \"amount\": \"0.999893\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 0,\n \"timestamp\": null,\n \"txid\": \"b2cba880bb6bb4fbf9c3acca5f9df6c3eee2ebf83df37688bf9a69e1876ffef0\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.000107\",\n \"total_input\": \"1.0\",\n \"total_output\": \"0.999893\",\n \"txid\": \"b2cba880bb6bb4fbf9c3acca5f9df6c3eee2ebf83df37688bf9a69e1876ffef0\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2406,7 +2551,13 @@
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "account to use for funding the transaction",
|
||||
"description": "account to use for holding the transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "funding_account_ids",
|
||||
"type": "list",
|
||||
"description": "ids of accounts to fund this transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
@@ -2432,17 +2583,17 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Create a stream claim without metadata",
|
||||
"curl": "curl -d'{\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpzj1qbxfj\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream create astream 1.0 /tmp/tmpzj1qbxfj",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpzj1qbxfj\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"010000000196f8e3d37980f4f602fedd6be3007e45c98a176b953ec151db7d9ff558f4e950010000006b483045022100c86c0b5aa41515436e96d86767e75566cb5addd6c41fc03b182fd41cb50e6750022044937d16a79ed035ee77af8c4e05282b66417349a5d9bc4f340d7d5a3569f048012103fe478df2bbf4c46284220d4d439f5ced6d923cc18915e25b0fa1f14a039a758effffffff0200e1f50500000000bab5076173747265616d4c94000a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d707a6a31716278666a180b22186170706c69636174696f6e2f6f637465742d73747265616d3230d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d36d7576a9145f714bd8d8f78a7a6836eba4625ab0d05cbf9bf188ac38fb9423000000001976a914b18165ea11e7fc078a724665b8d5f4ed879418af88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"moXzxEEXj4nhGhnozbGGFqGXdEzysbDMHJ\",\n \"amount\": \"6.983769\",\n \"confirmations\": 4,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485089,\n \"txid\": \"50e9f458f59f7ddb51c13e956b178ac9457e00e36bddfe02f6f48079d3e3f896\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"timestamp\": null,\n \"txid\": \"c983a65d949c9badee6fdd78ec68dc214c44816576e90998a86c062790e8fffe\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mwhWukDANoke2ikBrkj8u3kFdRh5YM2Xv7\",\n \"amount\": \"5.969662\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"c983a65d949c9badee6fdd78ec68dc214c44816576e90998a86c062790e8fffe\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.014107\",\n \"total_input\": \"6.983769\",\n \"total_output\": \"6.969662\",\n \"txid\": \"c983a65d949c9badee6fdd78ec68dc214c44816576e90998a86c062790e8fffe\"\n }\n}"
|
||||
"curl": "curl -d'{\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpmjego0ff\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream create astream 1.0 /tmp/tmpmjego0ff",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"astream\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpmjego0ff\", \"tags\": [], \"languages\": [], \"locations\": [], \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001fa76b5ebe4e1dc0f511d6ee2d6ebc93576efc11ddbb0e6b31c17e1fa87590771010000006a47304402201470c22dd0eda9464317b03e19df649fdf3e714bd7ab7216786065cbcf7f506602204c1e906566d6470a6ec400b364970a07bc56f3c338929089966a6573a3b032a2012102cd305212f95664613654fae6a0b947c64fb741ab641b8ca731446f5301f8d2daffffffff0200e1f50500000000bab5076173747265616d4c94000a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d706d6a65676f306666180b22186170706c69636174696f6e2f6f637465742d73747265616d32302ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb376d7576a914726468487bd5cd1825dbe133ff4c1fee98694a1988ac38fb9423000000001976a9145f53c37fbba1d75a500cc3a95bd28d4ccf34894e88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mv5oQhBhKEBinD1Bs3MKmzznidZSGBN1FG\",\n \"amount\": \"6.983769\",\n \"confirmations\": 4,\n \"height\": 209,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524491,\n \"txid\": \"71075987fae1171cb3e6b0db1dc1ef7635c9ebd6e26e1d510fdce1e4ebb576fa\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"timestamp\": null,\n \"txid\": \"16d37a20dd97fec3f8f86456ed6eee78547e7145c802afdf5c91418a6d99204a\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mpCzqHAmHsyhp3J1NFWGPof1PoYhVugGdg\",\n \"amount\": \"5.969662\",\n \"confirmations\": -2,\n \"height\": -2,\n \"nout\": 1,\n \"timestamp\": null,\n \"txid\": \"16d37a20dd97fec3f8f86456ed6eee78547e7145c802afdf5c91418a6d99204a\",\n \"type\": \"payment\"\n }\n ],\n \"total_fee\": \"0.014107\",\n \"total_input\": \"6.983769\",\n \"total_output\": \"6.969662\",\n \"txid\": \"16d37a20dd97fec3f8f86456ed6eee78547e7145c802afdf5c91418a6d99204a\"\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/tmp_zkvgv47.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\": 1561485066, \"channel_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"channel_account_id\": [], \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream create blank-image 1.0 /tmp/tmp_zkvgv47.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=1561485066 --channel_id=\"7ed794458d57978c49572424e1d32c7fa4d5325e\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"blank-image\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmp_zkvgv47.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\": 1561485066, \"channel_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"channel_account_id\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000001feffe89027066ca89809e9766581444c21dc68ec78dd6feead9b9c945da683c9010000006b483045022100b3f2904121f6c6b5a41f31aae658e82db8b9b03385c5a68b4837603476905e3102206361878bb10bdf9ec3aa09e57777d67e97d93ecd6759784b937dc27441d4cb130121033c5a8006c1b3c7e3fce456220accfdf3a7b1f7f9c7a312789637d857dc8d68cbffffffff0200e1f50500000000fddc01b50b626c616e6b2d696d6167654db101015e32d5a47f2cd3e1242457498c97578d4594d77ef0d8c8998fb8a90c600f66f6bce1b38b4f8ccca60f1896a1d0b85e3735c50d5b4841a37bb45dfdbef1ca2712189280efd4382ac843e11e6272e0389c1b99b6630ae6010a82010a306c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545120f746d705f7a6b76677634372e706e6718632209696d6167652f706e673230d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c120650696361736f1a0d5075626c696320446f6d61696e2218687474703a2f2f7075626c69632d646f6d61696e2e6f7267288abec9e8053222080112196f1ef7cc2a7373816b32207342ec23f8c38dccf01292bec029188087a70e520408051007420b426c616e6b20496d6167654a184120626c616e6b20504e472074686174206973203578372e52252a23687474703a2f2f736d616c6c6d656469612e636f6d2f7468756d626e61696c2e6a70675a05626c616e6b5a03617274620208016a1308ec0112024e481a0a4d616e636865737465726d7576a9141ef7cc2a7373816b32207342ec23f8c38dccf01288acac5e7d1d000000001976a9140a576ae154110bade7e05856edb02f02c4192c2c88ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mwhWukDANoke2ikBrkj8u3kFdRh5YM2Xv7\",\n \"amount\": \"5.969662\",\n \"confirmations\": 2,\n \"height\": 213,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485090,\n \"txid\": \"c983a65d949c9badee6fdd78ec68dc214c44816576e90998a86c062790e8fffe\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"miLhR5kJLGVqi5Ss2VKT2Nxt4fToriqtX2\",\n \"amount\": \"1.0\",\n \"claim_id\": \"8cef1fdff80ef393ddb24a73ba60196610bedbc9\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"meta\": {},\n \"name\": \"blank-image\",\n \"normalized_name\": \"blank-image\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://blank-image#8cef1fdff80ef393ddb24a73ba60196610bedbc9\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": null,\n \"txid\": \"62a6d649879ce6a35a33265b8a9421faf24fd1e40457fdcdb4753d7eb7de6e0f\",\n \"type\": \"claim\",\n \"value\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"miLhR5kJLGVqi5Ss2VKT2Nxt4fToriqtX2\",\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\": \"1561485066\",\n \"source\": {\n \"hash\": \"6c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545\",\n \"media_type\": \"image/png\",\n \"name\": \"tmp_zkvgv47.png\",\n \"sd_hash\": \"d4595a73a829c2a567a25ee1fa7ced42ae4d2d5fccc19126f01b8518537a386b6d20d611b35278afe6a5e193a762cd8c\",\n \"size\": \"99\"\n },\n \"stream_type\": \"image\",\n \"taLine truncated
|
||||
"curl": "curl -d'{\"method\": \"stream_create\", \"params\": {\"name\": \"blank-image\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpg_6t0r6a.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\": 1567524468, \"channel_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream create blank-image 1.0 /tmp/tmpg_6t0r6a.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=1567524468 --channel_id=\"1812d3275894f62a055d59189a75698a071108af\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_create\", \"params\": {\"name\": \"blank-image\", \"bid\": \"1.0\", \"file_path\": \"/tmp/tmpg_6t0r6a.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\": 1567524468, \"channel_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000014a20996d8a41915cdfaf02c845717e5478ee6eed5664f8f8c3fe97dd207ad316010000006b483045022100f808f427a2644e1b0bfdaaabb9dab4774b741a1033030b53ca8d19e2376e0af402205ff5c862bbbeda9cede5e42e1e13f48059325cea04f700817d725c11df91db8f012102ddf444347dfb68dc2f69ca9462ecfe0d30f1db4c10080bdcf696cb22de42ed25ffffffff0200e1f50500000000fddc01b50b626c616e6b2d696d6167654db10101af0811078a69759a18595d052af6945827d312183830ab666b25817d8432e95af7bb26baed712eeca26420f81c8f8255ca008c86dbb6c771a21cbc97d0f460f7b4d4243e40a26d66f77c615f0f9cb4f99a228a830ae6010a82010a306c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545120f746d70675f3674307236612e706e6718632209696d6167652f706e673230019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33120650696361736f1a0d5075626c696320446f6d61696e2218687474703a2f2f7075626c69632d646f6d61696e2e6f726728f48cbaeb053222080112196ff97ffe7af1a8d072313edc64a91a58bebcc96496d7b1fc76188087a70e520408051007420b426c616e6b20496d6167654a184120626c616e6b20504e472074686174206973203578372e52252a23687474703a2f2f736d616c6c6d656469612e636f6d2f7468756d626e61696c2e6a70675a05626c616e6b5a03617274620208016a1308ec0112024e481a0a4d616e636865737465726d7576a914f97ffe7af1a8d072313edc64a91a58bebcc9649688acac5e7d1d000000001976a914325ef76f0613598d31a4952b241c4ad04e5452d688ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mpCzqHAmHsyhp3J1NFWGPof1PoYhVugGdg\",\n \"amount\": \"5.969662\",\n \"confirmations\": 2,\n \"height\": 213,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524492,\n \"txid\": \"16d37a20dd97fec3f8f86456ed6eee78547e7145c802afdf5c91418a6d99204a\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"n4GBt198ctM4KF1AJGJG8ppxAeFyXFfut9\",\n \"amount\": \"1.0\",\n \"claim_id\": \"0e08f286e3e5cf0b17d3fa64da93fbf96b0e9c90\",\n \"claim_op\": \"create\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"meta\": {},\n \"name\": \"blank-image\",\n \"normalized_name\": \"blank-image\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://blank-image#0e08f286e3e5cf0b17d3fa64da93fbf96b0e9c90\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": null,\n \"txid\": \"55d87be458bd1a9aa960dd914b7f5c6d1b118d65d8b04477f705716d33091530\",\n \"type\": \"claim\",\n \"value\": {\n \"author\": \"Picaso\",\n \"description\": \"A blank PNG that is 5x7.\",\n \"fee\": {\n \"address\": \"n4GBt198ctM4KF1AJGJG8ppxAeFyXFfut9\",\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\": \"1567524468\",\n \"source\": {\n \"hash\": \"6c7df435d412c603390f593ef658c199817c7830ba3f16b7eadd8f99fa50e85dbd0d2b3dc61eadc33fe096e3872d1545\",\n \"media_type\": \"image/png\",\n \"name\": \"tmpg_6t0r6a.png\",\n \"sd_hash\": \"019de60de1c0e860ae907dfbf13cd4a618a1acb9fb107e09bcaee3a6a7b2165a2a91e740a0fc9d4a4e613a6ed496bc33\",\n \"size\": \"99\"\n },\n \"stream_type\": \"image\",\n \"taLine truncated
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2476,14 +2627,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\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ]\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\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\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1561485090,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"items\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\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 \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 5,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": 1567524492,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n }\n ],\n \"page\": 1,\n \"page_size\": 20,\n \"total_items\": 1,\n \"total_pages\": 1\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2674,7 +2825,13 @@
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "account to use for funding the transaction",
|
||||
"description": "account to use for holding the transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "funding_account_ids",
|
||||
"type": "list",
|
||||
"description": "ids of accounts to fund this transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
@@ -2706,10 +2863,10 @@
|
||||
"examples": [
|
||||
{
|
||||
"title": "Update a stream claim to add channel",
|
||||
"curl": "curl -d'{\"method\": \"stream_update\", \"params\": {\"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\", \"clear_fee\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"clear_channel\": false, \"channel_account_id\": [], \"preview\": false, \"blocking\": false, \"replace\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream update 5d64500fb723eded83a41b0d5055f1783f019191 --channel_id=\"7ed794458d57978c49572424e1d32c7fa4d5325e\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_update\", \"params\": {\"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\", \"clear_fee\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\", \"clear_channel\": false, \"channel_account_id\": [], \"preview\": false, \"blocking\": false, \"replace\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"0100000002feffe89027066ca89809e9766581444c21dc68ec78dd6feead9b9c945da683c9000000006b483045022100d50e402d04306f995730a8cce777723723fff2846104882c27008649b9aae9bf022050a7b0432dd4a4bfd050e53cb072769cbd812f80e497c5c4c4c3e41bdae2e2800121039efda2d8dd29b422fb044b6ccf6791ec3b0489713619b3f9dd9e8c89a4e54779ffffffffb48acb3a85b381bcc76c473f47f0b8a7123aca7b0f793d4db380a2c9093b00aa010000006b483045022100a6948b248bedc73306df727c5068a0c34be18d9dde725e20c841719c0efcaea902203a842193eb567f4abee70e7560732cad4e216863d4c4d1c892359cff4678c18e012103931d91a3c5ade5cdc8a50814a522fcd34a309a6704ff608db69a878d214f6db0ffffffff0200e1f50500000000fd2301b7076173747265616d149191013f78f155500d1ba483eded23b70f50645d4ce8015e32d5a47f2cd3e1242457498c97578d4594d77ee519fc56b21384e97c75d5c1b6450f2138e209f7bbd2adb588609ba36d1982a2187070c391a89793a0b569f09fef656fe041eab1809e3964f6346ae0fb3d20f30a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d707a6a31716278666a180b22186170706c69636174696f6e2f6f637465742d73747265616d3230d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d36d6d76a9145f714bd8d8f78a7a6836eba4625ab0d05cbf9bf188ac32a0d205000000001976a9143b92d98084d9425628023c45e47f808c4abeacc588ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 213,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"timestamp\": 1561485090,\n \"txid\": \"c983a65d949c9badee6fdd78ec68dc214c44816576e90998a86c062790e8fffe\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpzj1qbxfj\",\n \"sd_hash\": \"d85e47456630442a413f6cbedbdc4b0a5177770155d8a4523bbf2f301ebae95e0785cb475ca8d1a9d3cab54a05de64d3\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"mrxs9s9nJgdvS6qW2ca4yr5UY6RkWS5zk9\",\n \"amount\": \"0.9772285\",\n \"confirmations\": 3,\n \"height\": 211,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1561485089,\n \"txid\": \"aa003b09c9a280b34d3d790f7bca3a12a7b8f0473f476cc7bc81b3853acb8ab4\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mpDcDEwvfvETWqTDhddKLTzZZS2GBQWBqC\",\n \"amount\": \"1.0\",\n \"claim_id\": \"5d64500fb723eded83a41b0d5055f1783f019191\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#5d64500fb723eded83a41b0d5055f1783f019191\",\n \"signing_channel\": {\n \"address\": \"n3rBuPQB9qzAha4xU1uHyP5nmvR3WGq3r6\",\n \"amount\": \"1.0\",\n \"claim_id\": \"7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"claim_op\": \"update\",\n \"confirmations\": 4,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#7ed794458d57978c49572424e1d32c7fa4d5325e\",\n \"timestamp\": 1561485089,\n \"txid\": \"0f7256329d0b2896d6f2472eea2614fbcf20ab6b22e27d168060ebb0adbaa6fa\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a0342000465bebc31803d2a7f0f037f696665d4d610abea2e518f906410163dec7513fc2b9a82ae0c4a15602f467d4c03823d72cf95c36fc6a87e963356e44db502027ae2\",\n \"public_key_id\": \"mrqYtVaoPEPqgyRPExUPi7PrYJ9nDc59yW\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": null,\n \"txid\": \"dac2f1adaf5debd8cb377673b35ee4e6eb62ba7747b4440ffdb44d6875c2197e\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4Line truncated
|
||||
"curl": "curl -d'{\"method\": \"stream_update\", \"params\": {\"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\", \"clear_fee\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"clear_channel\": false, \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false, \"replace\": false}}' http://localhost:5279/",
|
||||
"lbrynet": "lbrynet stream update bfb7d50e084d6d246ca9ff909c401aab30a6f9a6 --channel_id=\"1812d3275894f62a055d59189a75698a071108af\"",
|
||||
"python": "requests.post(\"http://localhost:5279\", json={\"method\": \"stream_update\", \"params\": {\"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\", \"clear_fee\": false, \"tags\": [], \"clear_tags\": false, \"languages\": [], \"clear_languages\": false, \"locations\": [], \"clear_locations\": false, \"channel_id\": \"1812d3275894f62a055d59189a75698a071108af\", \"clear_channel\": false, \"channel_account_id\": [], \"funding_account_ids\": [], \"preview\": false, \"blocking\": false, \"replace\": false}}).json()",
|
||||
"output": "{\n \"jsonrpc\": \"2.0\",\n \"result\": {\n \"height\": -2,\n \"hex\": \"01000000024a20996d8a41915cdfaf02c845717e5478ee6eed5664f8f8c3fe97dd207ad316000000006b4830450221009c4970496e636abc34224449e1f1d622371f01b147049da7f6f6f3bcb67baa2802200b3287b5a1c69d5ef2c2e3e7b7e9b380e9b8f4ab98432bb2af3f9ac4669d96690121023b0815369b8ef78200d00b1fef7fdd6bf0dac1a84cb34756aa390e54e07e85ecffffffffbded7fa7ca114b69dc8970c6a101c2f3025ece7ad98d45016b9506b99e79929b010000006a473044022013977e030d5d69106109c028565c3797bd4e38c6d3da87350ef2764a6dfa73be022050375628a5458937d7ad2d76acd4e405a75bf3fa5d99a8858417512e5c450697012102886cb9914841d8ba268858f82323ecab77a977d3cf5cf605a3bf0df8b70503e9ffffffff0200e1f50500000000fd2301b7076173747265616d14a6f9a630ab1a409c90ffa96c246d4d080ed5b7bf4ce801af0811078a69759a18595d052af6945827d31218a49f0b990dfb596d464fa5c166a752b4835b01f02dcabd712d4345b09c18ce4096395d25caf4fb962732f54d58df839f9dd7cc2ef1d4303c89e4dd553865ed060a90010a8d010a30fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd120b746d706d6a65676f306666180b22186170706c69636174696f6e2f6f637465742d73747265616d32302ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb376d6d76a914726468487bd5cd1825dbe133ff4c1fee98694a1988ac32a0d205000000001976a914b7fb7f269d470a1f77e83285c02e2d07f5a83c0588ac00000000\",\n \"inputs\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_op\": \"create\",\n \"confirmations\": 1,\n \"height\": 213,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"timestamp\": 1567524492,\n \"txid\": \"16d37a20dd97fec3f8f86456ed6eee78547e7145c802afdf5c91418a6d99204a\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcbb83578b3e417cb71ce646efd0819dd8c088de1bd\",\n \"media_type\": \"application/octet-stream\",\n \"name\": \"tmpmjego0ff\",\n \"sd_hash\": \"2ab7bbd96cb5db43df9ff909c0555dd8a132866355768c41d24f2b4be7c0478ae5f82d2c853e95c9b1179c6743e4bb37\",\n \"size\": \"11\"\n },\n \"stream_type\": \"binary\"\n },\n \"value_type\": \"stream\"\n },\n {\n \"address\": \"myHCXzM5bmTxED6Tyc9WcLhGsP1u8M9Wfo\",\n \"amount\": \"0.9772285\",\n \"confirmations\": 3,\n \"height\": 211,\n \"is_change\": true,\n \"is_mine\": true,\n \"nout\": 1,\n \"timestamp\": 1567524491,\n \"txid\": \"9b92799eb906956b01458dd97ace5e02f3c201a1c67089dc694b11caa77fedbd\",\n \"type\": \"payment\"\n }\n ],\n \"outputs\": [\n {\n \"address\": \"mqwocM9E8dcY9aHCaCGG6HXB8Pd3hA9KjF\",\n \"amount\": \"1.0\",\n \"claim_id\": \"bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"claim_op\": \"update\",\n \"confirmations\": -2,\n \"height\": -2,\n \"is_channel_signature_valid\": true,\n \"meta\": {},\n \"name\": \"astream\",\n \"normalized_name\": \"astream\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://astream#bfb7d50e084d6d246ca9ff909c401aab30a6f9a6\",\n \"signing_channel\": {\n \"address\": \"mw6SpJDWJeYTWsr2iEFNEbRuqmNhDjpsZS\",\n \"amount\": \"1.0\",\n \"claim_id\": \"1812d3275894f62a055d59189a75698a071108af\",\n \"claim_op\": \"update\",\n \"confirmations\": 4,\n \"height\": 210,\n \"is_change\": false,\n \"is_mine\": true,\n \"meta\": {},\n \"name\": \"@channel\",\n \"normalized_name\": \"@channel\",\n \"nout\": 0,\n \"permanent_url\": \"lbry://@channel#1812d3275894f62a055d59189a75698a071108af\",\n \"timestamp\": 1567524491,\n \"txid\": \"986dbf145a5320fe0047b3404216ddae76bb9e915895ebb04dda9c4e1b676be7\",\n \"type\": \"claim\",\n \"value\": {\n \"public_key\": \"3056301006072a8648ce3d020106052b8104000a034200044974cd9d7098183f8bc9005f3957a4dbfc1ede19044311337fe9f645f256a7a4013c6a142497590bd8461fc50ce6b489453686422079c334bd5f8316b335365e\",\n \"public_key_id\": \"mrne5J4YN1SYYE3qNAAwzEVHAxnZX4AKHp\",\n \"title\": \"New Channel\"\n },\n \"value_type\": \"channel\"\n },\n \"timestamp\": null,\n \"txid\": \"f3338742c2b4cf0e35b7ffa73aea3e9da786926cf82f07d3100e09d04ec3f231\",\n \"type\": \"claim\",\n \"value\": {\n \"source\": {\n \"hash\": \"fdbd8e75a67f29f701a4e0Line truncated
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -2725,7 +2882,7 @@
|
||||
{
|
||||
"name": "claim_id",
|
||||
"type": "str",
|
||||
"description": "claim_id of the claim to abandon",
|
||||
"description": "claim_id of the support to abandon",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
@@ -2793,7 +2950,13 @@
|
||||
{
|
||||
"name": "account_id",
|
||||
"type": "str",
|
||||
"description": "id of the account to use",
|
||||
"description": "account to use for holding the transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
"name": "funding_account_ids",
|
||||
"type": "list",
|
||||
"description": "ids of accounts to fund this transaction",
|
||||
"is_required": false
|
||||
},
|
||||
{
|
||||
@@ -2911,7 +3074,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-06-25 13:51\",\n \"fee\": \"-0.000124\",\n \"support_info\": [],\n \"timestamp\": 1561485089,\n \"txid\": \"0e071fe12cfda37fb80dd634afb1a44bcb861e2de16009ad5628cc7f74776634\",\n \"update_info\": [],\n \"value\": \"-2.0\"\n },\n {\n \"abandon_info\": [],\n \"claim_info\": [],\n \"confirmations\": 7,\n \"date\": \"2019-06-25 13:51\",\n \"fee\": \"0.0\",\n \"support_info\": [],\n \"timestamp\": 1561485088,\n \"txid\": \"8fa093f2b4e99c1c7d1aef71a73092c72ebe1875a2481b2ccb4244a49126fcc0\",\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-09-03 11:28\",\n \"fee\": \"-0.000124\",\n \"support_info\": [],\n \"timestamp\": 1567524491,\n \"txid\": \"3e770eda0c2cc8b74e0107e6395fc686a08e022814f55a8153f83fb0f5f923ab\",\n \"update_info\": [],\n \"value\": \"0.0\"\n },\n {\n \"abandon_info\": [],\n \"claim_info\": [],\n \"confirmations\": 7,\n \"date\": \"2019-09-03 11:28\",\n \"fee\": \"0.0\",\n \"support_info\": [],\n \"timestamp\": 1567524490,\n \"txid\": \"79b42ae4b80e2fcc997251899b763a4d3666beea57db5cd7628dfd14ed08152d\",\n \"update_info\": [],\n \"value\": \"10.0\"\n }\n ]\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
__name__ = "lbry"
|
||||
__version__ = "0.38.0"
|
||||
__version__ = "0.41.0"
|
||||
version = tuple(__version__.split('.'))
|
||||
|
||||
@@ -71,7 +71,7 @@ class AbstractBlob:
|
||||
'readers'
|
||||
]
|
||||
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, blob_hash: str, length: typing.Optional[int] = None,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, 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
|
||||
@@ -175,7 +175,7 @@ class AbstractBlob:
|
||||
|
||||
@classmethod
|
||||
async def create_from_unencrypted(
|
||||
cls, loop: asyncio.BaseEventLoop, blob_dir: typing.Optional[str], key: bytes, iv: bytes,
|
||||
cls, loop: asyncio.AbstractEventLoop, 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:
|
||||
"""
|
||||
@@ -237,7 +237,7 @@ class BlobBuffer(AbstractBlob):
|
||||
"""
|
||||
An in-memory only blob
|
||||
"""
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, blob_hash: str, length: typing.Optional[int] = None,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, 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
|
||||
@@ -276,7 +276,7 @@ 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,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, 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)
|
||||
@@ -324,7 +324,7 @@ class BlobFile(AbstractBlob):
|
||||
|
||||
@classmethod
|
||||
async def create_from_unencrypted(
|
||||
cls, loop: asyncio.BaseEventLoop, blob_dir: typing.Optional[str], key: bytes, iv: bytes,
|
||||
cls, loop: asyncio.AbstractEventLoop, 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:
|
||||
|
||||
@@ -16,7 +16,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BlobManager:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, blob_dir: str, storage: 'SQLiteStorage', config: 'Config',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, blob_dir: str, storage: 'SQLiteStorage', config: 'Config',
|
||||
node_data_store: typing.Optional['DictDataStore'] = None):
|
||||
"""
|
||||
This class stores blobs on the hard disk
|
||||
@@ -69,10 +69,10 @@ class BlobManager:
|
||||
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
|
||||
if blob_hash in self.blobs:
|
||||
return self.blobs[blob_hash].get_is_verified()
|
||||
return self._get_blob(blob_hash, length).get_is_verified()
|
||||
|
||||
async def setup(self) -> bool:
|
||||
@@ -86,7 +86,8 @@ class BlobManager:
|
||||
to_add = await self.storage.sync_missing_blobs(in_blobfiles_dir)
|
||||
if to_add:
|
||||
self.completed_blob_hashes.update(to_add)
|
||||
self.connection_manager.start()
|
||||
if self.config.track_bandwidth:
|
||||
self.connection_manager.start()
|
||||
return True
|
||||
|
||||
def stop(self):
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import asyncio
|
||||
import time
|
||||
import logging
|
||||
import typing
|
||||
import binascii
|
||||
from typing import Optional
|
||||
from lbry.error import InvalidBlobHashError, InvalidDataError
|
||||
from lbry.blob_exchange.serialization import BlobResponse, BlobRequest
|
||||
from lbry.utils import cache_concurrent
|
||||
@@ -14,7 +16,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BlobExchangeClientProtocol(asyncio.Protocol):
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_timeout: typing.Optional[float] = 10,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_timeout: typing.Optional[float] = 10,
|
||||
connection_manager: typing.Optional['ConnectionManager'] = None):
|
||||
self.loop = loop
|
||||
self.peer_port: typing.Optional[int] = None
|
||||
@@ -39,8 +41,6 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
|
||||
self.peer_address, self.peer_port = addr_info
|
||||
# assert self.peer_address is not None
|
||||
self.connection_manager.received_data(f"{self.peer_address}:{self.peer_port}", len(data))
|
||||
#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)
|
||||
if not self.transport or self.transport.is_closing():
|
||||
log.warning("transport closing, but got more bytes from %s:%i\n%s", self.peer_address, self.peer_port,
|
||||
binascii.hexlify(data))
|
||||
@@ -67,7 +67,8 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
|
||||
self.blob.set_length(blob_response.length)
|
||||
elif blob_response and not blob_response.error and self.blob.blob_hash != blob_response.blob_hash:
|
||||
# the server started sending a blob we didn't request
|
||||
log.warning("mismatch with self.blob %s", self.blob.blob_hash)
|
||||
log.warning("%s started sending blob we didnt request %s instead of %s", self.peer_address,
|
||||
blob_response.blob_hash, self.blob.blob_hash)
|
||||
return
|
||||
if response.responses:
|
||||
log.debug("got response from %s:%i <- %s", self.peer_address, self.peer_port, response.to_dict())
|
||||
@@ -91,15 +92,16 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
|
||||
log.error("error downloading blob from %s:%i: %s", self.peer_address, self.peer_port, err)
|
||||
if self._response_fut and not self._response_fut.done():
|
||||
self._response_fut.set_exception(err)
|
||||
except (asyncio.TimeoutError) as err: # TODO: is this needed?
|
||||
except asyncio.TimeoutError as err:
|
||||
log.error("%s downloading blob from %s:%i", str(err), self.peer_address, self.peer_port)
|
||||
if self._response_fut and not self._response_fut.done():
|
||||
self._response_fut.set_exception(err)
|
||||
|
||||
async def _download_blob(self) -> typing.Tuple[int, typing.Optional[asyncio.Transport]]:
|
||||
async def _download_blob(self) -> typing.Tuple[int, Optional['BlobExchangeClientProtocol']]:
|
||||
"""
|
||||
:return: download success (bool), keep connection (bool)
|
||||
:return: download success (bool), connected protocol (BlobExchangeClientProtocol)
|
||||
"""
|
||||
start_time = time.perf_counter()
|
||||
request = BlobRequest.make_request_for_blob_hash(self.blob.blob_hash)
|
||||
blob_hash = self.blob.blob_hash
|
||||
if not self.peer_address:
|
||||
@@ -152,9 +154,11 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
|
||||
log.debug(msg)
|
||||
msg = f"downloaded {self.blob.blob_hash[:8]} from {self.peer_address}:{self.peer_port}"
|
||||
await asyncio.wait_for(self.writer.finished, self.peer_timeout, loop=self.loop)
|
||||
log.info(msg)
|
||||
log.info("%s at %fMB/s", msg,
|
||||
round((float(self._blob_bytes_received) /
|
||||
float(time.perf_counter() - start_time)) / 1000000.0, 2))
|
||||
# await self.blob.finished_writing.wait() not necessary, but a dangerous change. TODO: is it needed?
|
||||
return self._blob_bytes_received, self.transport
|
||||
return self._blob_bytes_received, self
|
||||
except asyncio.TimeoutError:
|
||||
return self._blob_bytes_received, self.close()
|
||||
except (InvalidBlobHashError, InvalidDataError):
|
||||
@@ -175,19 +179,19 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
|
||||
self.transport = None
|
||||
self.buf = b''
|
||||
|
||||
async def download_blob(self, blob: 'AbstractBlob') -> typing.Tuple[int, typing.Optional[asyncio.Transport]]:
|
||||
async def download_blob(self, blob: 'AbstractBlob') -> typing.Tuple[int, Optional['BlobExchangeClientProtocol']]:
|
||||
self.closed.clear()
|
||||
blob_hash = blob.blob_hash
|
||||
if blob.get_is_verified() or not blob.is_writeable():
|
||||
return 0, self.transport
|
||||
return 0, self
|
||||
try:
|
||||
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:
|
||||
except OSError:
|
||||
# i'm not sure how to fix this race condition - jack
|
||||
log.warning("race happened downloading %s from %s:%i", blob_hash, self.peer_address, self.peer_port)
|
||||
log.warning("race happened downloading %s from %s:%s", blob_hash, self.peer_address, self.peer_port)
|
||||
# return self._blob_bytes_received, self.transport
|
||||
raise
|
||||
except asyncio.TimeoutError:
|
||||
@@ -220,31 +224,32 @@ class BlobExchangeClientProtocol(asyncio.Protocol):
|
||||
|
||||
|
||||
@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, connection_id: int = 0,
|
||||
connection_manager: typing.Optional['ConnectionManager'] = None)\
|
||||
-> typing.Tuple[int, typing.Optional[asyncio.Transport]]:
|
||||
async def request_blob(loop: asyncio.AbstractEventLoop, blob: Optional['AbstractBlob'], address: str,
|
||||
tcp_port: int, peer_connect_timeout: float, blob_download_timeout: float,
|
||||
connected_protocol: Optional['BlobExchangeClientProtocol'] = None,
|
||||
connection_id: int = 0, connection_manager: Optional['ConnectionManager'] = None)\
|
||||
-> typing.Tuple[int, Optional['BlobExchangeClientProtocol']]:
|
||||
"""
|
||||
Returns [<downloaded blob>, <keep connection>]
|
||||
Returns [<amount of bytes received>, <client protocol if connected>]
|
||||
"""
|
||||
|
||||
protocol = BlobExchangeClientProtocol(
|
||||
loop, blob_download_timeout, connection_manager
|
||||
)
|
||||
if connected_transport and not connected_transport.is_closing():
|
||||
connected_transport.set_protocol(protocol)
|
||||
protocol.transport = connected_transport
|
||||
log.debug("reusing connection for %s:%d", address, tcp_port)
|
||||
protocol = connected_protocol
|
||||
if not connected_protocol or not connected_protocol.transport or connected_protocol.transport.is_closing():
|
||||
connected_protocol = None
|
||||
protocol = BlobExchangeClientProtocol(
|
||||
loop, blob_download_timeout, connection_manager
|
||||
)
|
||||
else:
|
||||
connected_transport = None
|
||||
log.debug("reusing connection for %s:%d", address, tcp_port)
|
||||
try:
|
||||
if not connected_transport:
|
||||
if not connected_protocol:
|
||||
await asyncio.wait_for(loop.create_connection(lambda: protocol, address, tcp_port),
|
||||
peer_connect_timeout, loop=loop)
|
||||
if blob.get_is_verified() or not blob.is_writeable():
|
||||
connected_protocol = protocol
|
||||
if blob is None or blob.get_is_verified() or not blob.is_writeable():
|
||||
# blob is None happens when we are just opening a connection
|
||||
# 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)
|
||||
return 0, connected_protocol
|
||||
return await connected_protocol.download_blob(blob)
|
||||
except (asyncio.TimeoutError, ConnectionRefusedError, ConnectionAbortedError, OSError):
|
||||
return 0, None
|
||||
@@ -9,6 +9,7 @@ if typing.TYPE_CHECKING:
|
||||
from lbry.dht.peer import KademliaPeer
|
||||
from lbry.blob.blob_manager import BlobManager
|
||||
from lbry.blob.blob_file import AbstractBlob
|
||||
from lbry.blob_exchange.client import BlobExchangeClientProtocol
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,7 +17,7 @@ log = logging.getLogger(__name__)
|
||||
class BlobDownloader:
|
||||
BAN_FACTOR = 2.0 # fixme: when connection manager gets implemented, move it out from here
|
||||
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, config: 'Config', blob_manager: 'BlobManager',
|
||||
peer_queue: asyncio.Queue):
|
||||
self.loop = loop
|
||||
self.config = config
|
||||
@@ -26,35 +27,38 @@ class BlobDownloader:
|
||||
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.connection_failures: typing.List['KademliaPeer'] = []
|
||||
self.connections: typing.Dict['KademliaPeer', 'BlobExchangeClientProtocol'] = {}
|
||||
self.is_running = asyncio.Event(loop=self.loop)
|
||||
|
||||
def should_race_continue(self, blob: 'AbstractBlob'):
|
||||
if len(self.active_connections) >= self.config.max_connections_per_download:
|
||||
max_probes = self.config.max_connections_per_download * (1 if self.connections else 10)
|
||||
if len(self.active_connections) >= max_probes:
|
||||
return False
|
||||
return not (blob.get_is_verified() or not blob.is_writeable())
|
||||
|
||||
async def request_blob_from_peer(self, blob: 'AbstractBlob', peer: 'KademliaPeer', connection_id: int = 0):
|
||||
async def request_blob_from_peer(self, blob: 'AbstractBlob', peer: 'KademliaPeer', connection_id: int = 0,
|
||||
just_probe: bool = False):
|
||||
if blob.get_is_verified():
|
||||
return
|
||||
transport = self.connections.get(peer)
|
||||
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, connection_id=connection_id,
|
||||
connection_manager=self.blob_manager.connection_manager
|
||||
|
||||
bytes_received, protocol = await request_blob(
|
||||
self.loop, blob if not just_probe else None, peer.address, peer.tcp_port, self.config.peer_connect_timeout,
|
||||
self.config.blob_download_timeout, connected_protocol=self.connections.get(peer),
|
||||
connection_id=connection_id, connection_manager=self.blob_manager.connection_manager
|
||||
)
|
||||
if not transport and peer not in self.ignored:
|
||||
if not bytes_received and not protocol and peer not in self.connection_failures:
|
||||
self.connection_failures.append(peer)
|
||||
if not protocol 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:
|
||||
elif protocol:
|
||||
log.debug("keep peer %s:%i", peer.address, peer.tcp_port)
|
||||
self.failures[peer] = 0
|
||||
self.connections[peer] = transport
|
||||
self.connections[peer] = protocol
|
||||
elapsed = self.loop.time() - start
|
||||
self.scores[peer] = bytes_received / elapsed if bytes_received and elapsed else 1
|
||||
|
||||
@@ -91,16 +95,18 @@ class BlobDownloader:
|
||||
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)
|
||||
"running, %d peers, %d ignored, %d active, %s connections",
|
||||
len(batch), len(self.ignored), len(self.active_connections), len(self.connections)
|
||||
)
|
||||
for peer in sorted(batch, key=lambda peer: self.scores.get(peer, 0), reverse=True):
|
||||
if peer in self.ignored or peer in self.active_connections:
|
||||
continue
|
||||
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, connection_id))
|
||||
self.active_connections[peer] = t
|
||||
log.debug("request %s from %s:%i", blob_hash[:8], peer.address, peer.tcp_port)
|
||||
just_probe = len(self.connections) == 0
|
||||
t = self.loop.create_task(self.request_blob_from_peer(blob, peer, connection_id, just_probe))
|
||||
self.active_connections[peer] = t
|
||||
await self.new_peer_or_finished()
|
||||
self.cleanup_active()
|
||||
log.debug("downloaded %s", blob_hash[:8])
|
||||
@@ -109,11 +115,12 @@ class BlobDownloader:
|
||||
blob.close()
|
||||
|
||||
def close(self):
|
||||
self.connection_failures.clear()
|
||||
self.scores.clear()
|
||||
self.ignored.clear()
|
||||
self.is_running.clear()
|
||||
for transport in self.connections.values():
|
||||
transport.close()
|
||||
for protocol in self.connections.values():
|
||||
protocol.close()
|
||||
|
||||
|
||||
async def download_blob(loop, config: 'Config', blob_manager: 'BlobManager', node: 'Node',
|
||||
|
||||
@@ -12,25 +12,56 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# a standard request will be 295 bytes
|
||||
MAX_REQUEST_SIZE = 1200
|
||||
|
||||
|
||||
class BlobServerProtocol(asyncio.Protocol):
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str):
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str,
|
||||
idle_timeout: float = 30.0, transfer_timeout: float = 60.0):
|
||||
self.loop = loop
|
||||
self.blob_manager = blob_manager
|
||||
self.server_task: asyncio.Task = None
|
||||
self.idle_timeout = idle_timeout
|
||||
self.transfer_timeout = transfer_timeout
|
||||
self.server_task: typing.Optional[asyncio.Task] = None
|
||||
self.started_listening = asyncio.Event(loop=self.loop)
|
||||
self.buf = b''
|
||||
self.transport = None
|
||||
self.transport: typing.Optional[asyncio.Transport] = None
|
||||
self.lbrycrd_address = lbrycrd_address
|
||||
self.peer_address_and_port: typing.Optional[str] = None
|
||||
self.started_transfer = asyncio.Event(loop=self.loop)
|
||||
self.transfer_finished = asyncio.Event(loop=self.loop)
|
||||
self.close_on_idle_task: typing.Optional[asyncio.Task] = None
|
||||
|
||||
async def close_on_idle(self):
|
||||
while self.transport:
|
||||
try:
|
||||
await asyncio.wait_for(self.started_transfer.wait(), self.idle_timeout, loop=self.loop)
|
||||
except asyncio.TimeoutError:
|
||||
log.debug("closing idle connection from %s", self.peer_address_and_port)
|
||||
return self.close()
|
||||
self.started_transfer.clear()
|
||||
await self.transfer_finished.wait()
|
||||
self.transfer_finished.clear()
|
||||
|
||||
def close(self):
|
||||
if self.transport:
|
||||
self.transport.close()
|
||||
|
||||
def connection_made(self, transport):
|
||||
self.transport = transport
|
||||
self.close_on_idle_task = self.loop.create_task(self.close_on_idle())
|
||||
self.peer_address_and_port = "%s:%i" % self.transport.get_extra_info('peername')
|
||||
self.blob_manager.connection_manager.connection_received(self.peer_address_and_port)
|
||||
log.debug("received connection from %s", self.peer_address_and_port)
|
||||
|
||||
def connection_lost(self, exc: typing.Optional[Exception]) -> None:
|
||||
log.debug("lost connection from %s", self.peer_address_and_port)
|
||||
self.blob_manager.connection_manager.incoming_connection_lost(self.peer_address_and_port)
|
||||
self.transport = None
|
||||
if self.close_on_idle_task and not self.close_on_idle_task.done():
|
||||
self.close_on_idle_task.cancel()
|
||||
self.close_on_idle_task = None
|
||||
|
||||
def send_response(self, responses: typing.List[blob_response_types]):
|
||||
to_send = []
|
||||
@@ -65,20 +96,30 @@ class BlobServerProtocol(asyncio.Protocol):
|
||||
incoming_blob = {'blob_hash': blob.blob_hash, 'length': blob.length}
|
||||
responses.append(BlobDownloadResponse(incoming_blob=incoming_blob))
|
||||
self.send_response(responses)
|
||||
log.debug("send %s to %s:%i", blob.blob_hash[:8], peer_address, peer_port)
|
||||
bh = blob.blob_hash[:8]
|
||||
log.debug("send %s to %s:%i", bh, peer_address, peer_port)
|
||||
self.started_transfer.set()
|
||||
try:
|
||||
sent = await blob.sendfile(self)
|
||||
except (ConnectionResetError, BrokenPipeError, RuntimeError, OSError):
|
||||
if self.transport:
|
||||
self.transport.close()
|
||||
return
|
||||
log.info("sent %s (%i bytes) to %s:%i", blob.blob_hash[:8], sent, peer_address, peer_port)
|
||||
sent = await asyncio.wait_for(blob.sendfile(self), self.transfer_timeout, loop=self.loop)
|
||||
self.blob_manager.connection_manager.sent_data(self.peer_address_and_port, sent)
|
||||
log.info("sent %s (%i bytes) to %s:%i", bh, sent, peer_address, peer_port)
|
||||
except (ConnectionResetError, BrokenPipeError, RuntimeError, OSError, asyncio.TimeoutError) as err:
|
||||
if isinstance(err, asyncio.TimeoutError):
|
||||
log.debug("timed out sending blob %s to %s", bh, peer_address)
|
||||
else:
|
||||
log.debug("stopped sending %s to %s:%i", bh, peer_address, peer_port)
|
||||
self.close()
|
||||
finally:
|
||||
self.transfer_finished.set()
|
||||
if responses:
|
||||
self.send_response(responses)
|
||||
# self.transport.close()
|
||||
|
||||
def data_received(self, data):
|
||||
request = None
|
||||
if len(self.buf) + len(data or b'') >= MAX_REQUEST_SIZE:
|
||||
log.warning("request from %s is too large", self.peer_address_and_port)
|
||||
self.close()
|
||||
return
|
||||
if data:
|
||||
self.blob_manager.connection_manager.received_data(self.peer_address_and_port, len(data))
|
||||
message, separator, remainder = data.rpartition(b'}')
|
||||
@@ -89,26 +130,28 @@ class BlobServerProtocol(asyncio.Protocol):
|
||||
request = BlobRequest.deserialize(self.buf + data)
|
||||
self.buf = remainder
|
||||
except JSONDecodeError:
|
||||
addr = self.transport.get_extra_info('peername')
|
||||
peer_address, peer_port = addr
|
||||
log.error("failed to decode blob request from %s:%i (%i bytes): %s", peer_address, peer_port,
|
||||
len(data), '' if not data else binascii.hexlify(data).decode())
|
||||
if not request:
|
||||
addr = self.transport.get_extra_info('peername')
|
||||
peer_address, peer_port = addr
|
||||
log.warning("failed to decode blob request from %s:%i", peer_address, peer_port)
|
||||
self.transport.close()
|
||||
log.error("request from %s is not valid json (%i bytes): %s", self.peer_address_and_port,
|
||||
len(self.buf + data), '' if not data else binascii.hexlify(self.buf + data).decode())
|
||||
self.close()
|
||||
return
|
||||
if not request.requests:
|
||||
log.error("failed to decode request from %s (%i bytes): %s", self.peer_address_and_port,
|
||||
len(self.buf + data), '' if not data else binascii.hexlify(self.buf + data).decode())
|
||||
self.close()
|
||||
return
|
||||
self.loop.create_task(self.handle_request(request))
|
||||
|
||||
|
||||
class BlobServer:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str):
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, blob_manager: 'BlobManager', lbrycrd_address: str,
|
||||
idle_timeout: float = 30.0, transfer_timeout: float = 60.0):
|
||||
self.loop = loop
|
||||
self.blob_manager = blob_manager
|
||||
self.server_task: typing.Optional[asyncio.Task] = None
|
||||
self.started_listening = asyncio.Event(loop=self.loop)
|
||||
self.lbrycrd_address = lbrycrd_address
|
||||
self.idle_timeout = idle_timeout
|
||||
self.transfer_timeout = transfer_timeout
|
||||
self.server_protocol_class = BlobServerProtocol
|
||||
|
||||
def start_server(self, port: int, interface: typing.Optional[str] = '0.0.0.0'):
|
||||
@@ -117,7 +160,8 @@ class BlobServer:
|
||||
|
||||
async def _start_server():
|
||||
server = await self.loop.create_server(
|
||||
lambda: self.server_protocol_class(self.loop, self.blob_manager, self.lbrycrd_address),
|
||||
lambda: self.server_protocol_class(self.loop, self.blob_manager, self.lbrycrd_address,
|
||||
self.idle_timeout, self.transfer_timeout),
|
||||
interface, port
|
||||
)
|
||||
self.started_listening.set()
|
||||
|
||||
+10
-8
@@ -22,9 +22,6 @@ CURRENCIES = {
|
||||
'LBC': {'type': 'crypto'},
|
||||
'USD': {'type': 'fiat'},
|
||||
}
|
||||
HEADERS_FILE_SHA256_CHECKSUM = (
|
||||
366295, 'b0c8197153a33ccbc52fb81a279588b6015b68b7726f73f6a2b81f7e25bfe4b9'
|
||||
)
|
||||
|
||||
|
||||
class Setting(typing.Generic[T]):
|
||||
@@ -362,6 +359,9 @@ class ConfigFileAccess:
|
||||
del self.data[key]
|
||||
|
||||
|
||||
TBC = typing.TypeVar('TBC', bound='BaseConfig')
|
||||
|
||||
|
||||
class BaseConfig:
|
||||
|
||||
config = Path("Path to configuration file.", metavar='FILE')
|
||||
@@ -377,12 +377,11 @@ class BaseConfig:
|
||||
|
||||
@contextmanager
|
||||
def update_config(self):
|
||||
if not isinstance(self.persisted, ConfigFileAccess):
|
||||
raise TypeError("Config file cannot be updated.")
|
||||
self._updating_config = True
|
||||
yield self
|
||||
self._updating_config = False
|
||||
self.persisted.save()
|
||||
if isinstance(self.persisted, ConfigFileAccess):
|
||||
self.persisted.save()
|
||||
|
||||
@property
|
||||
def modify_order(self):
|
||||
@@ -418,7 +417,7 @@ class BaseConfig:
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create_from_arguments(cls, args):
|
||||
def create_from_arguments(cls, args) -> TBC:
|
||||
conf = cls()
|
||||
conf.set_arguments(args)
|
||||
conf.set_environment()
|
||||
@@ -551,6 +550,9 @@ class Config(CLIConfig):
|
||||
('spv4.lbry.com', 50001),
|
||||
('spv5.lbry.com', 50001),
|
||||
('spv6.lbry.com', 50001),
|
||||
('spv7.lbry.com', 50001),
|
||||
('spv8.lbry.com', 50001),
|
||||
('spv9.lbry.com', 50001),
|
||||
])
|
||||
known_dht_nodes = Servers("Known nodes for bootstrapping connection to the DHT", [
|
||||
('lbrynet1.lbry.com', 4444), # US EAST
|
||||
@@ -573,9 +575,9 @@ class Config(CLIConfig):
|
||||
"Whether to share usage stats and diagnostic info with LBRY.", True,
|
||||
previous_names=['upload_log', 'upload_log', 'share_debug_info']
|
||||
)
|
||||
track_bandwidth = Toggle("Track bandwidth usage", True)
|
||||
|
||||
# media server
|
||||
|
||||
streaming_server = String('Host name and port to serve streaming media over range requests',
|
||||
'localhost:5280', metavar='HOST:PORT')
|
||||
streaming_get = Toggle("Enable the /get endpoint for the streaming media server. "
|
||||
|
||||
@@ -19,7 +19,9 @@ class ConnectionManager:
|
||||
self.outgoing_connected: typing.Set[str] = set()
|
||||
self.outgoing: typing.DefaultDict[str, int] = collections.defaultdict(int)
|
||||
self._status = {}
|
||||
|
||||
self._total_sent = 0
|
||||
self._total_received = 0
|
||||
self._running = False
|
||||
self._task: typing.Optional[asyncio.Task] = None
|
||||
|
||||
@property
|
||||
@@ -27,33 +29,37 @@ class ConnectionManager:
|
||||
return self._status
|
||||
|
||||
def sent_data(self, host_and_port: str, size: int):
|
||||
self.outgoing[host_and_port] += size
|
||||
if self._running:
|
||||
self.outgoing[host_and_port] += size
|
||||
|
||||
def received_data(self, host_and_port: str, size: int):
|
||||
self.incoming[host_and_port] += size
|
||||
if self._running:
|
||||
self.incoming[host_and_port] += size
|
||||
|
||||
def connection_made(self, host_and_port: str):
|
||||
self.outgoing_connected.add(host_and_port)
|
||||
if self._running:
|
||||
self.outgoing_connected.add(host_and_port)
|
||||
|
||||
def connection_received(self, host_and_port: str):
|
||||
# self.incoming_connected.add(host_and_port)
|
||||
pass
|
||||
|
||||
def outgoing_connection_lost(self, host_and_port: str):
|
||||
if host_and_port in self.outgoing_connected:
|
||||
if self._running and host_and_port in self.outgoing_connected:
|
||||
self.outgoing_connected.remove(host_and_port)
|
||||
|
||||
def incoming_connection_lost(self, host_and_port: str):
|
||||
if host_and_port in self.incoming_connected:
|
||||
if self._running and host_and_port in self.incoming_connected:
|
||||
self.incoming_connected.remove(host_and_port)
|
||||
|
||||
async def _update(self):
|
||||
|
||||
self._status = {
|
||||
'incoming_bps': {},
|
||||
'outgoing_bps': {},
|
||||
'total_incoming_mbs': 0.0,
|
||||
'total_outgoing_mbs': 0.0,
|
||||
'total_sent': self._total_sent,
|
||||
'total_received': self._total_received,
|
||||
'time': self.loop.time()
|
||||
}
|
||||
|
||||
@@ -73,6 +79,9 @@ class ConnectionManager:
|
||||
) / (now - last)) / 1000000.0
|
||||
self._status['total_incoming_mbs'] = int(sum(list(self._status['incoming_bps'].values())
|
||||
) / (now - last)) / 1000000.0
|
||||
self._total_sent += sum(list(self._status['outgoing_bps'].values()))
|
||||
self._total_received += sum(list(self._status['incoming_bps'].values()))
|
||||
|
||||
self._status['time'] = now
|
||||
|
||||
def stop(self):
|
||||
@@ -84,7 +93,9 @@ class ConnectionManager:
|
||||
self.incoming.clear()
|
||||
self.incoming_connected.clear()
|
||||
self._status.clear()
|
||||
self._running = False
|
||||
|
||||
def start(self):
|
||||
self.stop()
|
||||
self._running = True
|
||||
self._task = self.loop.create_task(self._update())
|
||||
@@ -9,7 +9,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BlobAnnouncer:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, node: 'Node', storage: 'SQLiteStorage'):
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, node: 'Node', storage: 'SQLiteStorage'):
|
||||
self.loop = loop
|
||||
self.node = node
|
||||
self.storage = storage
|
||||
@@ -22,13 +22,12 @@ class BlobAnnouncer:
|
||||
if peers > 4:
|
||||
return blob_hash
|
||||
else:
|
||||
log.warning("failed to announce %s, could only find %d peers, retrying soon.", blob_hash[:8], peers)
|
||||
log.debug("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))
|
||||
|
||||
|
||||
async def _announce(self, batch_size: typing.Optional[int] = 10):
|
||||
while batch_size:
|
||||
if not self.node.joined.is_set():
|
||||
|
||||
+32
-4
@@ -16,7 +16,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Node:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager', node_id: bytes, udp_port: int,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager', node_id: bytes, udp_port: int,
|
||||
internal_udp_port: int, peer_port: int, external_ip: str, rpc_timeout: float = constants.rpc_timeout,
|
||||
split_buckets_under_index: int = constants.split_buckets_under_index):
|
||||
self.loop = loop
|
||||
@@ -88,10 +88,10 @@ class Node:
|
||||
)
|
||||
stored_to = [node_id for node_id, contacted in stored_to_tup if contacted]
|
||||
if stored_to:
|
||||
log.info("Stored %s to %i of %i attempted peers", binascii.hexlify(hash_value).decode()[:8],
|
||||
log.debug("Stored %s to %i of %i attempted peers", binascii.hexlify(hash_value).decode()[:8],
|
||||
len(stored_to), len(peers))
|
||||
else:
|
||||
log.warning("Failed announcing %s, stored to 0 peers", blob_hash[:8])
|
||||
log.debug("Failed announcing %s, stored to 0 peers", blob_hash[:8])
|
||||
return stored_to
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -208,8 +208,36 @@ class Node:
|
||||
task.cancel()
|
||||
|
||||
async def _value_producer(self, blob_hash: str, result_queue: asyncio.Queue):
|
||||
async def ping(_peer):
|
||||
try:
|
||||
await self.protocol.get_rpc_peer(_peer).ping()
|
||||
result_queue.put_nowait([_peer])
|
||||
except asyncio.TimeoutError:
|
||||
pass
|
||||
|
||||
async for results in self.get_iterative_value_finder(binascii.unhexlify(blob_hash.encode())):
|
||||
result_queue.put_nowait(results)
|
||||
to_put = []
|
||||
for peer in results:
|
||||
if peer.address == self.protocol.external_ip and self.protocol.peer_port == peer.tcp_port:
|
||||
continue
|
||||
is_good = self.protocol.peer_manager.peer_is_good(peer)
|
||||
if is_good:
|
||||
to_put.append(peer)
|
||||
elif is_good is None:
|
||||
udp_port_to_try = 4444
|
||||
if 3400 > peer.tcp_port > 3332:
|
||||
if not peer.udp_port:
|
||||
udp_port_to_try = (peer.tcp_port - 3333) + 4444
|
||||
elif 4500 > peer.tcp_port > 4443:
|
||||
if not peer.udp_port:
|
||||
udp_port_to_try = peer.tcp_port
|
||||
if not peer.udp_port:
|
||||
peer.update_udp_port(udp_port_to_try)
|
||||
self.loop.create_task(ping(peer))
|
||||
else:
|
||||
log.debug("skip bad peer %s:%i for %s", peer.address, peer.tcp_port, blob_hash)
|
||||
if to_put:
|
||||
result_queue.put_nowait(to_put)
|
||||
|
||||
def accumulate_peers(self, search_queue: asyncio.Queue,
|
||||
peer_queue: typing.Optional[asyncio.Queue] = None) -> typing.Tuple[
|
||||
|
||||
@@ -20,7 +20,7 @@ def is_valid_ipv4(address):
|
||||
|
||||
|
||||
class PeerManager:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop):
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop):
|
||||
self._loop = loop
|
||||
self._rpc_failures: typing.Dict[
|
||||
typing.Tuple[str, int], typing.Tuple[typing.Optional[float], typing.Optional[float]]
|
||||
@@ -61,7 +61,7 @@ class PeerManager:
|
||||
self._node_tokens[node_id] = (now, token)
|
||||
|
||||
def get_node_token(self, node_id: bytes) -> typing.Optional[bytes]:
|
||||
ts, token = self._node_tokens.get(node_id, (None, None))
|
||||
ts, token = self._node_tokens.get(node_id, (0, None))
|
||||
if ts and ts > self._loop.time() - constants.token_secret_refresh_interval:
|
||||
return token
|
||||
|
||||
@@ -148,7 +148,7 @@ class KademliaPeer:
|
||||
'protocol_version',
|
||||
]
|
||||
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, address: str, node_id: typing.Optional[bytes] = None,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, 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:
|
||||
if not len(node_id) == constants.hash_length:
|
||||
|
||||
@@ -7,7 +7,7 @@ if typing.TYPE_CHECKING:
|
||||
|
||||
|
||||
class DictDataStore:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager'):
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager'):
|
||||
# Dictionary format:
|
||||
# { <key>: [(<contact>, <age>), ...] }
|
||||
self._data_store: typing.Dict[bytes, typing.List[typing.Tuple['KademliaPeer', float]]] = {}
|
||||
|
||||
@@ -70,7 +70,7 @@ def get_shortlist(routing_table: 'TreeRoutingTable', key: bytes,
|
||||
|
||||
|
||||
class IterativeFinder:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager',
|
||||
routing_table: 'TreeRoutingTable', protocol: 'KademliaProtocol', key: bytes,
|
||||
bottom_out_limit: typing.Optional[int] = 2, max_results: typing.Optional[int] = constants.k,
|
||||
exclude: typing.Optional[typing.List[typing.Tuple[str, int]]] = None,
|
||||
@@ -254,7 +254,7 @@ class IterativeFinder:
|
||||
|
||||
|
||||
class IterativeNodeFinder(IterativeFinder):
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager',
|
||||
routing_table: 'TreeRoutingTable', protocol: 'KademliaProtocol', key: bytes,
|
||||
bottom_out_limit: typing.Optional[int] = 2, max_results: typing.Optional[int] = constants.k,
|
||||
exclude: typing.Optional[typing.List[typing.Tuple[str, int]]] = None,
|
||||
@@ -305,7 +305,7 @@ class IterativeNodeFinder(IterativeFinder):
|
||||
|
||||
|
||||
class IterativeValueFinder(IterativeFinder):
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager',
|
||||
routing_table: 'TreeRoutingTable', protocol: 'KademliaProtocol', key: bytes,
|
||||
bottom_out_limit: typing.Optional[int] = 2, max_results: typing.Optional[int] = constants.k,
|
||||
exclude: typing.Optional[typing.List[typing.Tuple[str, int]]] = None,
|
||||
|
||||
@@ -29,7 +29,7 @@ old_protocol_errors = {
|
||||
|
||||
|
||||
class KademliaRPC:
|
||||
def __init__(self, protocol: 'KademliaProtocol', loop: asyncio.BaseEventLoop, peer_port: int = 3333):
|
||||
def __init__(self, protocol: 'KademliaProtocol', loop: asyncio.AbstractEventLoop, peer_port: int = 3333):
|
||||
self.protocol = protocol
|
||||
self.loop = loop
|
||||
self.peer_port = peer_port
|
||||
@@ -132,7 +132,7 @@ class RemoteKademliaRPC:
|
||||
Encapsulates RPC calls to remote Peers
|
||||
"""
|
||||
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_tracker: 'PeerManager', protocol: 'KademliaProtocol',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_tracker: 'PeerManager', protocol: 'KademliaProtocol',
|
||||
peer: 'KademliaPeer'):
|
||||
self.loop = loop
|
||||
self.peer_tracker = peer_tracker
|
||||
@@ -195,7 +195,7 @@ class RemoteKademliaRPC:
|
||||
|
||||
|
||||
class PingQueue:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, protocol: 'KademliaProtocol'):
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, protocol: 'KademliaProtocol'):
|
||||
self._loop = loop
|
||||
self._protocol = protocol
|
||||
self._pending_contacts: typing.Dict['KademliaPeer', float] = {}
|
||||
@@ -258,7 +258,7 @@ class PingQueue:
|
||||
|
||||
|
||||
class KademliaProtocol(DatagramProtocol):
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager', node_id: bytes, external_ip: str,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager', node_id: bytes, external_ip: str,
|
||||
udp_port: int, peer_port: int, rpc_timeout: float = constants.rpc_timeout,
|
||||
split_buckets_under_index: int = constants.split_buckets_under_index):
|
||||
self.peer_manager = peer_manager
|
||||
|
||||
@@ -163,7 +163,7 @@ class TreeRoutingTable:
|
||||
that paper.
|
||||
"""
|
||||
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, peer_manager: 'PeerManager', parent_node_id: bytes,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, peer_manager: 'PeerManager', parent_node_id: bytes,
|
||||
split_buckets_under_index: int = constants.split_buckets_under_index):
|
||||
self._loop = loop
|
||||
self._peer_manager = peer_manager
|
||||
|
||||
+57
-64
@@ -221,6 +221,61 @@ def ensure_directory_exists(path: str):
|
||||
pathlib.Path(path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def run_daemon(args: list, conf: Config):
|
||||
default_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
|
||||
file_handler = logging.handlers.RotatingFileHandler(
|
||||
conf.log_file_path, maxBytes=2097152, backupCount=5
|
||||
)
|
||||
file_handler.setFormatter(default_formatter)
|
||||
log.addHandler(file_handler)
|
||||
logging.getLogger('torba').addHandler(file_handler)
|
||||
|
||||
if not args.quiet:
|
||||
handler = logging.StreamHandler()
|
||||
handler.setFormatter(default_formatter)
|
||||
log.addHandler(handler)
|
||||
logging.getLogger('torba').addHandler(handler)
|
||||
logging.getLogger('torba').setLevel(logging.INFO)
|
||||
|
||||
logging.getLogger('aioupnp').setLevel(logging.WARNING)
|
||||
logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
if args.verbose:
|
||||
log.setLevel(logging.DEBUG)
|
||||
loop.set_debug(True)
|
||||
else:
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
if conf.share_usage_data:
|
||||
loggly_handler = get_loggly_handler()
|
||||
loggly_handler.setLevel(logging.ERROR)
|
||||
log.addHandler(loggly_handler)
|
||||
|
||||
daemon = Daemon(conf)
|
||||
|
||||
def __exit():
|
||||
raise GracefulExit()
|
||||
|
||||
try:
|
||||
loop.add_signal_handler(signal.SIGINT, __exit)
|
||||
loop.add_signal_handler(signal.SIGTERM, __exit)
|
||||
except NotImplementedError:
|
||||
pass # Not implemented on Windows
|
||||
|
||||
try:
|
||||
loop.run_until_complete(daemon.start())
|
||||
loop.run_forever()
|
||||
except (GracefulExit, KeyboardInterrupt, asyncio.CancelledError):
|
||||
pass
|
||||
finally:
|
||||
loop.run_until_complete(daemon.stop())
|
||||
|
||||
if hasattr(loop, 'shutdown_asyncgens'):
|
||||
loop.run_until_complete(loop.shutdown_asyncgens())
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
argv = argv or sys.argv[1:]
|
||||
parser = get_argument_parser()
|
||||
@@ -232,88 +287,26 @@ def main(argv=None):
|
||||
|
||||
if args.cli_version:
|
||||
print(f"lbrynet {lbrynet_version}")
|
||||
return 0
|
||||
|
||||
elif args.command == 'start':
|
||||
|
||||
if args.help:
|
||||
args.start_parser.print_help()
|
||||
return 0
|
||||
|
||||
default_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
|
||||
file_handler = logging.handlers.RotatingFileHandler(
|
||||
conf.log_file_path, maxBytes=2097152, backupCount=5
|
||||
)
|
||||
file_handler.setFormatter(default_formatter)
|
||||
log.addHandler(file_handler)
|
||||
logging.getLogger('torba').addHandler(file_handler)
|
||||
|
||||
if not args.quiet:
|
||||
handler = logging.StreamHandler()
|
||||
handler.setFormatter(default_formatter)
|
||||
log.addHandler(handler)
|
||||
logging.getLogger('torba').addHandler(handler)
|
||||
logging.getLogger('torba').setLevel(logging.INFO)
|
||||
|
||||
logging.getLogger('aioupnp').setLevel(logging.WARNING)
|
||||
logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
if args.verbose:
|
||||
log.setLevel(logging.DEBUG)
|
||||
loop.set_debug(True)
|
||||
else:
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
if conf.share_usage_data:
|
||||
loggly_handler = get_loggly_handler()
|
||||
loggly_handler.setLevel(logging.ERROR)
|
||||
log.addHandler(loggly_handler)
|
||||
|
||||
daemon = Daemon(conf)
|
||||
started = False
|
||||
def __exit():
|
||||
if started:
|
||||
daemon.stop_event.set()
|
||||
else:
|
||||
raise GracefulExit()
|
||||
try:
|
||||
loop.add_signal_handler(signal.SIGINT, __exit)
|
||||
loop.add_signal_handler(signal.SIGTERM, __exit)
|
||||
except NotImplementedError:
|
||||
pass # Not implemented on Windows
|
||||
try:
|
||||
loop.run_until_complete(daemon.start())
|
||||
started = True
|
||||
loop.run_until_complete(daemon.stop_event.wait())
|
||||
except (GracefulExit, KeyboardInterrupt):
|
||||
pass
|
||||
finally:
|
||||
loop.run_until_complete(daemon.stop())
|
||||
if hasattr(loop, 'shutdown_asyncgens'):
|
||||
loop.run_until_complete(loop.shutdown_asyncgens())
|
||||
|
||||
run_daemon(args, conf)
|
||||
elif args.command is not None:
|
||||
|
||||
doc = args.doc
|
||||
api_method_name = args.api_method_name
|
||||
if args.replaced_by:
|
||||
print(f"{args.api_method_name} is deprecated, using {args.replaced_by['api_method_name']}.")
|
||||
doc = args.replaced_by['doc']
|
||||
api_method_name = args.replaced_by['api_method_name']
|
||||
|
||||
if args.help:
|
||||
print(doc)
|
||||
else:
|
||||
parsed = docopt(doc, command_args)
|
||||
params = set_kwargs(parsed)
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(execute_command(conf, api_method_name, params))
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(execute_command(conf, api_method_name, params))
|
||||
elif args.group is not None:
|
||||
args.group_parser.print_help()
|
||||
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ class Component(metaclass=ComponentType):
|
||||
self._running = True
|
||||
return result
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
log.info("Cancelled setup of %s component", self.__class__.__name__)
|
||||
raise
|
||||
except Exception as err:
|
||||
log.exception("Error setting up %s", self.component_name or self.__class__.__name__)
|
||||
raise err
|
||||
@@ -67,7 +68,8 @@ class Component(metaclass=ComponentType):
|
||||
self._running = False
|
||||
return result
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
log.info("Cancelled stop of %s component", self.__class__.__name__)
|
||||
raise
|
||||
except Exception as err:
|
||||
log.exception("Error stopping %s", self.__class__.__name__)
|
||||
raise err
|
||||
@@ -163,3 +163,6 @@ class ComponentManager:
|
||||
if component.component_name == component_name:
|
||||
return component.component
|
||||
raise NameError(component_name)
|
||||
|
||||
def has_component(self, component_name):
|
||||
return any(component for component in self.components if component_name == component.component_name)
|
||||
@@ -1,11 +1,10 @@
|
||||
import hashlib
|
||||
import os
|
||||
import asyncio
|
||||
import logging
|
||||
import math
|
||||
import binascii
|
||||
import typing
|
||||
from hashlib import sha256
|
||||
from types import SimpleNamespace
|
||||
import base58
|
||||
|
||||
from aioupnp import __version__ as aioupnp_version
|
||||
@@ -13,7 +12,6 @@ from aioupnp.upnp import UPnP
|
||||
from aioupnp.fault import UPnPError
|
||||
|
||||
from lbry import utils
|
||||
from lbry.conf import HEADERS_FILE_SHA256_CHECKSUM
|
||||
from lbry.dht.node import Node
|
||||
from lbry.dht.blob_announcer import BlobAnnouncer
|
||||
from lbry.blob.blob_manager import BlobManager
|
||||
@@ -23,8 +21,7 @@ from lbry.extras.daemon.Component import Component
|
||||
from lbry.extras.daemon.exchange_rate_manager import ExchangeRateManager
|
||||
from lbry.extras.daemon.storage import SQLiteStorage
|
||||
from lbry.wallet import LbryWalletManager
|
||||
from lbry.wallet import Network
|
||||
|
||||
from lbry.wallet.header import Headers
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -100,115 +97,103 @@ class DatabaseComponent(Component):
|
||||
self.storage = None
|
||||
|
||||
|
||||
HEADERS_URL = "https://headers.lbry.io/blockchain_headers_latest"
|
||||
HEADER_SIZE = 112
|
||||
|
||||
|
||||
class HeadersComponent(Component):
|
||||
component_name = HEADERS_COMPONENT
|
||||
HEADERS_URL = "https://headers.lbry.io/blockchain_headers_latest"
|
||||
CHECKPOINT = ('100b33ca3d0b86a48f0d6d6f30458a130ecb89d5affefe4afccb134d5a40f4c2', 600_000)
|
||||
|
||||
def __init__(self, component_manager):
|
||||
super().__init__(component_manager)
|
||||
self.headers_dir = os.path.join(self.conf.wallet_dir, 'lbc_mainnet')
|
||||
self.headers_file = os.path.join(self.headers_dir, 'headers')
|
||||
self.old_file = os.path.join(self.conf.wallet_dir, 'blockchain_headers')
|
||||
self._downloading_headers = None
|
||||
self.headers = Headers(self.headers_file)
|
||||
self.is_downloading_headers = False
|
||||
self._headers_progress_percent = 0
|
||||
|
||||
@property
|
||||
def component(self):
|
||||
return self
|
||||
|
||||
async def get_status(self):
|
||||
return {} if not self._downloading_headers else {
|
||||
'downloading_headers': self._downloading_headers,
|
||||
'download_progress': self._headers_progress_percent
|
||||
}
|
||||
def _round_progress(self, local_height, remote_height):
|
||||
return min(max(math.ceil(float(local_height) / float(remote_height) * 100), 0), 100)
|
||||
|
||||
async def get_status(self) -> dict:
|
||||
progress = None
|
||||
if self.is_downloading_headers:
|
||||
progress = self._headers_progress_percent
|
||||
elif self.component_manager.has_component(WALLET_COMPONENT):
|
||||
wallet_manager = self.component_manager.get_component(WALLET_COMPONENT)
|
||||
if wallet_manager and wallet_manager.ledger.network.remote_height > 0:
|
||||
local_height = wallet_manager.ledger.headers.height
|
||||
remote_height = wallet_manager.ledger.network.remote_height
|
||||
progress = self._round_progress(local_height, remote_height)
|
||||
return {
|
||||
'downloading_headers': True,
|
||||
'download_progress': progress
|
||||
} if progress is not None and progress < 100 else {}
|
||||
|
||||
async def fetch_headers_from_s3(self):
|
||||
local_header_size = self.local_header_file_size()
|
||||
resume_header = {"Range": f"bytes={local_header_size}-"}
|
||||
async with utils.aiohttp_request('get', HEADERS_URL, headers=resume_header) as response:
|
||||
if response.status == 406 or response.content_length < HEADER_SIZE: # our file is bigger
|
||||
async with utils.aiohttp_request('get', self.HEADERS_URL, headers=resume_header) as response:
|
||||
if response.status == 406 or response.content_length < self.headers.header_size: # our file is bigger
|
||||
log.warning("s3 is more out of date than we are")
|
||||
return
|
||||
if response.content_length % HEADER_SIZE != 0:
|
||||
final_size_after_download = response.content_length + local_header_size
|
||||
if final_size_after_download % self.headers.header_size != 0:
|
||||
log.warning("s3 appears to have corrupted header")
|
||||
return
|
||||
final_size_after_download = response.content_length + local_header_size
|
||||
write_mode = "wb"
|
||||
if local_header_size > 0:
|
||||
log.info("Resuming download of %i bytes from s3", response.content_length)
|
||||
write_mode = "a+b"
|
||||
with open(self.headers_file, write_mode) as fd:
|
||||
while True:
|
||||
chunk = await response.content.read(512)
|
||||
if not chunk:
|
||||
break
|
||||
fd.write(chunk)
|
||||
self._headers_progress_percent = math.ceil(
|
||||
float(fd.tell()) / float(final_size_after_download) * 100
|
||||
while not response.content.at_eof():
|
||||
local_header_size += fd.write(await response.content.readany())
|
||||
self._headers_progress_percent = self._round_progress(
|
||||
local_header_size, final_size_after_download
|
||||
)
|
||||
log.info("fetched headers from s3, now verifying integrity after download.")
|
||||
self._check_header_file_integrity()
|
||||
|
||||
def local_header_file_height(self):
|
||||
return max((self.local_header_file_size() / HEADER_SIZE) - 1, 0)
|
||||
|
||||
def local_header_file_size(self):
|
||||
def local_header_file_size(self) -> int:
|
||||
if os.path.isfile(self.headers_file):
|
||||
return os.stat(self.headers_file).st_size
|
||||
return 0
|
||||
|
||||
async def get_remote_height(self):
|
||||
ledger = SimpleNamespace()
|
||||
ledger.config = {
|
||||
'default_servers': self.conf.lbryum_servers,
|
||||
'data_path': self.conf.wallet_dir
|
||||
}
|
||||
net = Network(ledger)
|
||||
first_connection = net.on_connected.first
|
||||
asyncio.ensure_future(net.start())
|
||||
await first_connection
|
||||
remote_height = await net.get_server_height()
|
||||
await net.stop()
|
||||
return remote_height
|
||||
async def get_downloadable_header_height(self) -> typing.Optional[int]:
|
||||
async with utils.aiohttp_request('HEAD', self.HEADERS_URL) as response:
|
||||
if response.status != 200:
|
||||
log.warning("Header download error, unexpected response code: %s", response.status)
|
||||
return -1
|
||||
return response.content_length // self.headers.header_size
|
||||
|
||||
async def should_download_headers_from_s3(self):
|
||||
async def should_download_headers_from_s3(self) -> bool:
|
||||
if self.conf.blockchain_name != "lbrycrd_main":
|
||||
return False
|
||||
self._check_header_file_integrity()
|
||||
s3_headers_depth = self.conf.s3_headers_depth
|
||||
if not s3_headers_depth:
|
||||
return False
|
||||
local_height = self.local_header_file_height()
|
||||
remote_height = await self.get_remote_height()
|
||||
log.info("remote height: %i, local height: %i", remote_height, local_height)
|
||||
if remote_height > (local_height + s3_headers_depth):
|
||||
return True
|
||||
|
||||
local_height = self.local_header_file_size() // self.headers.header_size
|
||||
remote_height = await self.get_downloadable_header_height()
|
||||
if remote_height is not None:
|
||||
log.info("remote height: %i, local height: %i", remote_height, local_height)
|
||||
if remote_height > (local_height + s3_headers_depth):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _check_header_file_integrity(self):
|
||||
# TODO: temporary workaround for usability. move to txlbryum and check headers instead of file integrity
|
||||
if self.conf.blockchain_name != "lbrycrd_main":
|
||||
return
|
||||
hashsum = sha256()
|
||||
checksum_height, checksum = HEADERS_FILE_SHA256_CHECKSUM
|
||||
checksum_length_in_bytes = checksum_height * HEADER_SIZE
|
||||
if self.local_header_file_size() < checksum_length_in_bytes:
|
||||
return
|
||||
with open(self.headers_file, "rb") as headers_file:
|
||||
hashsum.update(headers_file.read(checksum_length_in_bytes))
|
||||
current_checksum = hashsum.hexdigest()
|
||||
if current_checksum != checksum:
|
||||
msg = f"Expected checksum {checksum}, got {current_checksum}"
|
||||
log.warning("Wallet file corrupted, checksum mismatch. " + msg)
|
||||
log.warning("Deleting header file so it can be downloaded again.")
|
||||
os.unlink(self.headers_file)
|
||||
elif (self.local_header_file_size() % HEADER_SIZE) != 0:
|
||||
log.warning("Header file is good up to checkpoint height, but incomplete. Truncating to checkpoint.")
|
||||
with open(self.headers_file, "rb+") as headers_file:
|
||||
headers_file.truncate(checksum_length_in_bytes)
|
||||
def verify_checkpoint(self):
|
||||
expected_hash, at_height = self.CHECKPOINT
|
||||
if self.local_header_file_size() // self.headers.header_size < at_height:
|
||||
return False
|
||||
hash = hashlib.sha256()
|
||||
chunk_size = self.headers.header_size * 1000
|
||||
with open(self.headers_file, 'rb') as header_file:
|
||||
data = header_file.read(chunk_size)
|
||||
while data and header_file.tell() <= at_height * self.headers.header_size:
|
||||
hash.update(data)
|
||||
data = header_file.read(chunk_size)
|
||||
return hash.hexdigest() == expected_hash
|
||||
|
||||
async def start(self):
|
||||
if not os.path.exists(self.headers_dir):
|
||||
@@ -216,14 +201,23 @@ class HeadersComponent(Component):
|
||||
if os.path.exists(self.old_file):
|
||||
log.warning("Moving old headers from %s to %s.", self.old_file, self.headers_file)
|
||||
os.rename(self.old_file, self.headers_file)
|
||||
self._downloading_headers = await self.should_download_headers_from_s3()
|
||||
if self._downloading_headers:
|
||||
try:
|
||||
|
||||
try:
|
||||
if await self.should_download_headers_from_s3():
|
||||
self.is_downloading_headers = True
|
||||
await self.fetch_headers_from_s3()
|
||||
except Exception as err:
|
||||
log.error("failed to fetch headers from s3: %s", err)
|
||||
finally:
|
||||
self._downloading_headers = False
|
||||
except Exception as err:
|
||||
log.error("failed to fetch headers from s3: %s", err)
|
||||
finally:
|
||||
self.is_downloading_headers = False
|
||||
# fixme: workaround, this should happen before download but happens after because headers.connect fail
|
||||
if not self.verify_checkpoint():
|
||||
log.info("Checkpoint failed, verifying headers using slower method.")
|
||||
await self.headers.open()
|
||||
await self.headers.repair()
|
||||
await self.headers.close()
|
||||
else:
|
||||
log.info("Header checkpoint verified.")
|
||||
|
||||
async def stop(self):
|
||||
pass
|
||||
@@ -242,11 +236,19 @@ class WalletComponent(Component):
|
||||
return self.wallet_manager
|
||||
|
||||
async def get_status(self):
|
||||
if self.wallet_manager and self.running:
|
||||
if self.wallet_manager and self.wallet_manager.ledger.network.remote_height:
|
||||
local_height = self.wallet_manager.ledger.headers.height
|
||||
remote_height = await self.wallet_manager.ledger.network.get_server_height()
|
||||
remote_height = self.wallet_manager.ledger.network.remote_height
|
||||
best_hash = self.wallet_manager.get_best_blockhash()
|
||||
return {
|
||||
'connected_servers': [
|
||||
{
|
||||
'host': session.server[0],
|
||||
'port': session.server[1],
|
||||
'latency': round(session.connection_latency, 2),
|
||||
} for session in self.wallet_manager.ledger.network.session_pool.sessions
|
||||
if session and session.available
|
||||
],
|
||||
'blocks': max(local_height, 0),
|
||||
'blocks_behind': max(remote_height - local_height, 0),
|
||||
'best_blockhash': best_hash,
|
||||
@@ -416,10 +418,8 @@ class StreamManagerComponent(Component):
|
||||
blob_manager = self.component_manager.get_component(BLOB_COMPONENT)
|
||||
storage = self.component_manager.get_component(DATABASE_COMPONENT)
|
||||
wallet = self.component_manager.get_component(WALLET_COMPONENT)
|
||||
try:
|
||||
node = self.component_manager.get_component(DHT_COMPONENT)
|
||||
except NameError:
|
||||
node = None
|
||||
node = self.component_manager.get_component(DHT_COMPONENT)\
|
||||
if self.component_manager.has_component(DHT_COMPONENT) else None
|
||||
log.info('Starting the file manager')
|
||||
loop = asyncio.get_event_loop()
|
||||
self.stream_manager = StreamManager(
|
||||
|
||||
+380
-152
File diff suppressed because it is too large.
Load diff
@@ -44,19 +44,22 @@ def _event_properties(installation_id: str, session_id: str,
|
||||
|
||||
def _download_properties(conf: Config, external_ip: str, resolve_duration: float,
|
||||
total_duration: typing.Optional[float], download_id: str, name: str,
|
||||
outpoint: str, active_peer_count: int, tried_peers_count: int,
|
||||
outpoint: str, active_peer_count: typing.Optional[int],
|
||||
tried_peers_count: typing.Optional[int], connection_failures_count: typing.Optional[int],
|
||||
added_fixed_peers: bool, fixed_peer_delay: float, sd_hash: str,
|
||||
sd_download_duration: typing.Optional[float] = None,
|
||||
head_blob_hash: typing.Optional[str] = None,
|
||||
head_blob_length: typing.Optional[int] = None,
|
||||
head_blob_download_duration: typing.Optional[float] = None,
|
||||
error: typing.Optional[str] = None) -> typing.Dict:
|
||||
error: typing.Optional[str] = None, error_msg: typing.Optional[str] = None,
|
||||
wallet_server: typing.Optional[str] = None) -> typing.Dict:
|
||||
return {
|
||||
"external_ip": external_ip,
|
||||
"download_id": download_id,
|
||||
"total_duration": round(total_duration, 4),
|
||||
"resolve_duration": None if not resolve_duration else round(resolve_duration, 4),
|
||||
"error": error,
|
||||
"error_message": error_msg,
|
||||
'name': name,
|
||||
"outpoint": outpoint,
|
||||
|
||||
@@ -74,7 +77,10 @@ def _download_properties(conf: Config, external_ip: str, resolve_duration: float
|
||||
|
||||
"head_blob_hash": head_blob_hash,
|
||||
"head_blob_length": head_blob_length,
|
||||
"head_blob_duration": None if not head_blob_download_duration else round(head_blob_download_duration, 4)
|
||||
"head_blob_duration": None if not head_blob_download_duration else round(head_blob_download_duration, 4),
|
||||
|
||||
"connection_failures_count": connection_failures_count,
|
||||
"wallet_server": wallet_server
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +105,6 @@ def _make_context(platform):
|
||||
|
||||
|
||||
class AnalyticsManager:
|
||||
|
||||
def __init__(self, conf: Config, installation_id: str, session_id: str):
|
||||
self.conf = conf
|
||||
self.cookies = {}
|
||||
@@ -110,7 +115,7 @@ class AnalyticsManager:
|
||||
self.context = _make_context(system_info.get_platform())
|
||||
self.installation_id = installation_id
|
||||
self.session_id = session_id
|
||||
self.task: asyncio.Task = None
|
||||
self.task: typing.Optional[asyncio.Task] = None
|
||||
self.external_ip: typing.Optional[str] = None
|
||||
|
||||
@property
|
||||
@@ -172,18 +177,24 @@ class AnalyticsManager:
|
||||
|
||||
async def send_time_to_first_bytes(self, resolve_duration: typing.Optional[float],
|
||||
total_duration: typing.Optional[float], download_id: str,
|
||||
name: str, outpoint: str, found_peers_count: int,
|
||||
tried_peers_count: int, added_fixed_peers: bool,
|
||||
name: str, outpoint: typing.Optional[str],
|
||||
found_peers_count: typing.Optional[int],
|
||||
tried_peers_count: typing.Optional[int],
|
||||
connection_failures_count: typing.Optional[int],
|
||||
added_fixed_peers: bool,
|
||||
fixed_peers_delay: float, sd_hash: str,
|
||||
sd_download_duration: typing.Optional[float] = None,
|
||||
head_blob_hash: typing.Optional[str] = None,
|
||||
head_blob_length: typing.Optional[int] = None,
|
||||
head_blob_duration: typing.Optional[int] = None,
|
||||
error: typing.Optional[str] = None):
|
||||
error: typing.Optional[str] = None,
|
||||
error_msg: typing.Optional[str] = None,
|
||||
wallet_server: typing.Optional[str] = None):
|
||||
await self.track(self._event(TIME_TO_FIRST_BYTES, _download_properties(
|
||||
self.conf, self.external_ip, resolve_duration, total_duration, download_id, name, outpoint,
|
||||
found_peers_count, tried_peers_count, added_fixed_peers, fixed_peers_delay, sd_hash,
|
||||
sd_download_duration, head_blob_hash, head_blob_length, head_blob_duration, error
|
||||
found_peers_count, tried_peers_count, connection_failures_count, added_fixed_peers, fixed_peers_delay,
|
||||
sd_hash, sd_download_duration, head_blob_hash, head_blob_length, head_blob_duration, error, error_msg,
|
||||
wallet_server
|
||||
)))
|
||||
|
||||
async def send_download_finished(self, download_id, name, sd_hash):
|
||||
|
||||
@@ -3,7 +3,7 @@ import time
|
||||
import hashlib
|
||||
import binascii
|
||||
|
||||
import aiohttp
|
||||
from lbry import utils
|
||||
import ecdsa
|
||||
from torba.client.hash import sha256
|
||||
from lbry.wallet.transaction import Output
|
||||
@@ -18,39 +18,49 @@ def get_encoded_signature(signature):
|
||||
return ecdsa.util.sigencode_der(r, s, len(signature) * 4)
|
||||
|
||||
|
||||
def is_comment_signed_by_channel(comment: dict, channel: Output):
|
||||
try:
|
||||
pieces = [
|
||||
comment['signing_ts'].encode(),
|
||||
channel.claim_hash,
|
||||
comment['comment'].encode()
|
||||
]
|
||||
return Output.is_signature_valid(
|
||||
get_encoded_signature(comment['signature']),
|
||||
sha256(b''.join(pieces)),
|
||||
channel.claim.channel.public_key_bytes
|
||||
)
|
||||
except KeyError:
|
||||
pass
|
||||
def cid2hash(claim_id: str) -> bytes:
|
||||
return binascii.unhexlify(claim_id.encode())[::-1]
|
||||
|
||||
|
||||
def is_comment_signed_by_channel(comment: dict, channel: Output, abandon=False):
|
||||
if type(channel) is Output:
|
||||
try:
|
||||
signing_field = comment['comment_id'] if abandon else comment['comment']
|
||||
pieces = [
|
||||
comment['signing_ts'].encode(),
|
||||
cid2hash(comment['channel_id']),
|
||||
signing_field.encode()
|
||||
]
|
||||
return Output.is_signature_valid(
|
||||
get_encoded_signature(comment['signature']),
|
||||
sha256(b''.join(pieces)),
|
||||
channel.claim.channel.public_key_bytes
|
||||
)
|
||||
except KeyError:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def sign_comment(comment: dict, channel: Output):
|
||||
timestamp = str(int(time.time())).encode()
|
||||
pieces = [timestamp, channel.claim_hash, comment['comment'].encode()]
|
||||
def sign_comment(comment: dict, channel: Output, abandon=False):
|
||||
timestamp = str(int(time.time()))
|
||||
signing_field = comment['comment_id'] if abandon else comment['comment']
|
||||
pieces = [timestamp.encode(), channel.claim_hash, signing_field.encode()]
|
||||
digest = sha256(b''.join(pieces))
|
||||
signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256)
|
||||
comment['signature'] = binascii.hexlify(signature).decode()
|
||||
comment['signing_ts'] = timestamp.decode()
|
||||
comment.update({
|
||||
'signature': binascii.hexlify(signature).decode(),
|
||||
'signing_ts': timestamp
|
||||
})
|
||||
|
||||
|
||||
async def jsonrpc_post(url: str, method: str, **params) -> any:
|
||||
async def jsonrpc_post(url: str, method: str, params: dict = None, **kwargs) -> any:
|
||||
params = params or {}
|
||||
params.update(kwargs)
|
||||
json_body = {'jsonrpc': '2.0', 'id': None, 'method': method, 'params': params}
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
async with aiohttp.request('POST', url, json=json_body, headers=headers) as response:
|
||||
async with utils.aiohttp_request('POST', url, json=json_body) as response:
|
||||
try:
|
||||
result = await response.json()
|
||||
return result['result'] if 'result' in result else result
|
||||
except aiohttp.client.ContentTypeError as cte:
|
||||
log.exception('Unable to decode respose from server: %s', cte)
|
||||
except Exception as cte:
|
||||
log.exception('Unable to decode response from server: %s', cte)
|
||||
return await response.text()
|
||||
@@ -3,7 +3,8 @@ import time
|
||||
import logging
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
from typing import Optional
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
from lbry.error import InvalidExchangeRateResponse, CurrencyConversionError
|
||||
from lbry.utils import aiohttp_request
|
||||
|
||||
@@ -44,7 +45,7 @@ class MarketFeed:
|
||||
self.params = params
|
||||
self.fee = fee
|
||||
self.rate = None
|
||||
self._task: asyncio.Task = None
|
||||
self._task: Optional[asyncio.Task] = None
|
||||
self._online = True
|
||||
|
||||
def rate_is_initialized(self):
|
||||
@@ -80,7 +81,7 @@ class MarketFeed:
|
||||
try:
|
||||
response = await asyncio.wait_for(self._make_request(), self.REQUESTS_TIMEOUT)
|
||||
self._save_price(self._subtract_fee(self._handle_response(response)))
|
||||
except (asyncio.TimeoutError, InvalidExchangeRateResponse) as err:
|
||||
except (asyncio.TimeoutError, InvalidExchangeRateResponse, ClientError) as err:
|
||||
self._on_error(err)
|
||||
await asyncio.sleep(self.EXCHANGE_RATE_UPDATE_RATE_SEC)
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ class JSONResponseEncoder(JSONEncoder):
|
||||
'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,
|
||||
'timestamp': self.ledger.headers[tx_height]['timestamp'] if tx_height > 0 else None
|
||||
'timestamp': self.ledger.headers[tx_height]['timestamp'] if 0 < tx_height <= best_height else None
|
||||
}
|
||||
if txo.is_change is not None:
|
||||
output['is_change'] = txo.is_change
|
||||
@@ -172,7 +172,7 @@ class JSONResponseEncoder(JSONEncoder):
|
||||
'normalized_name': txo.normalized_name,
|
||||
'claim_id': txo.claim_id,
|
||||
'permanent_url': txo.permanent_url,
|
||||
'meta': self.encode_claim_meta(txo.meta)
|
||||
'meta': self.encode_claim_meta(txo.meta.copy())
|
||||
})
|
||||
if 'short_url' in output['meta']:
|
||||
output['short_url'] = output['meta'].pop('short_url')
|
||||
@@ -184,6 +184,8 @@ class JSONResponseEncoder(JSONEncoder):
|
||||
output['value_type'] = txo.claim.claim_type
|
||||
if self.include_protobuf:
|
||||
output['protobuf'] = hexlify(txo.claim.to_bytes())
|
||||
if txo.claim.is_channel:
|
||||
output['has_signing_key'] = txo.has_private_key
|
||||
if check_signature and txo.claim.is_signed:
|
||||
if txo.channel is not None:
|
||||
output['signing_channel'] = self.encode_output(txo.channel)
|
||||
@@ -200,7 +202,7 @@ class JSONResponseEncoder(JSONEncoder):
|
||||
if key.endswith('_amount'):
|
||||
if isinstance(value, int):
|
||||
meta[key] = dewies_to_lbc(value)
|
||||
if meta.get('creation_height', 0) > 0:
|
||||
if 0 < meta.get('creation_height', 0) <= self.ledger.headers.height:
|
||||
meta['creation_timestamp'] = self.ledger.headers[meta['creation_height']]['timestamp']
|
||||
return meta
|
||||
|
||||
@@ -218,15 +220,44 @@ class JSONResponseEncoder(JSONEncoder):
|
||||
return result
|
||||
|
||||
def encode_file(self, managed_stream):
|
||||
file = managed_stream.as_dict()
|
||||
output_exists = managed_stream.output_file_exists
|
||||
tx_height = managed_stream.stream_claim_info.height
|
||||
best_height = self.ledger.headers.height
|
||||
file.update({
|
||||
return {
|
||||
'streaming_url': managed_stream.stream_url,
|
||||
'completed': managed_stream.completed,
|
||||
'file_name': managed_stream.file_name if output_exists else None,
|
||||
'download_directory': managed_stream.download_directory if output_exists else None,
|
||||
'download_path': managed_stream.full_path if output_exists else None,
|
||||
'points_paid': 0.0,
|
||||
'stopped': not managed_stream.running,
|
||||
'stream_hash': managed_stream.stream_hash,
|
||||
'stream_name': managed_stream.descriptor.stream_name,
|
||||
'suggested_file_name': managed_stream.descriptor.suggested_file_name,
|
||||
'sd_hash': managed_stream.descriptor.sd_hash,
|
||||
'mime_type': managed_stream.mime_type,
|
||||
'key': managed_stream.descriptor.key,
|
||||
'total_bytes_lower_bound': managed_stream.descriptor.lower_bound_decrypted_length(),
|
||||
'total_bytes': managed_stream.descriptor.upper_bound_decrypted_length(),
|
||||
'written_bytes': managed_stream.written_bytes,
|
||||
'blobs_completed': managed_stream.blobs_completed,
|
||||
'blobs_in_stream': managed_stream.blobs_in_stream,
|
||||
'blobs_remaining': managed_stream.blobs_remaining,
|
||||
'status': managed_stream.status,
|
||||
'claim_id': managed_stream.claim_id,
|
||||
'txid': managed_stream.txid,
|
||||
'nout': managed_stream.nout,
|
||||
'outpoint': managed_stream.outpoint,
|
||||
'metadata': managed_stream.metadata,
|
||||
'protobuf': managed_stream.metadata_protobuf,
|
||||
'channel_claim_id': managed_stream.channel_claim_id,
|
||||
'channel_name': managed_stream.channel_name,
|
||||
'claim_name': managed_stream.claim_name,
|
||||
'content_fee': managed_stream.content_fee,
|
||||
'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
|
||||
'confirmations': (best_height + 1) - tx_height if tx_height > 0 else tx_height,
|
||||
'timestamp': self.ledger.headers[tx_height]['timestamp'] if 0 < tx_height <= best_height else None
|
||||
}
|
||||
|
||||
def encode_claim(self, claim):
|
||||
encoded = getattr(claim, claim.claim_type).to_dict()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
import json
|
||||
import logging.handlers
|
||||
import traceback
|
||||
@@ -49,9 +50,12 @@ class HTTPSLogglyHandler(logging.Handler):
|
||||
return record.getMessage()
|
||||
|
||||
async def _emit(self, record):
|
||||
payload = self.format(record)
|
||||
async with utils.aiohttp_request('post', self.url, data=payload.encode(), cookies=self.cookies) as response:
|
||||
self.cookies.update(response.cookies)
|
||||
try:
|
||||
async with utils.aiohttp_request('post', self.url, data=self.format(record).encode(),
|
||||
cookies=self.cookies) as response:
|
||||
self.cookies.update(response.cookies)
|
||||
except ClientError:
|
||||
pass
|
||||
|
||||
def emit(self, record):
|
||||
asyncio.ensure_future(self._emit(record))
|
||||
|
||||
@@ -90,20 +90,6 @@ def get_claims_from_stream_hashes(transaction: sqlite3.Connection,
|
||||
}
|
||||
|
||||
|
||||
def get_content_claim_from_outpoint(transaction: sqlite3.Connection,
|
||||
outpoint: str) -> typing.Optional[StoredStreamClaim]:
|
||||
query = (
|
||||
"select content_claim.stream_hash, c.*, case when c.channel_claim_id is not null then "
|
||||
" (select claim_name from claim where claim_id==c.channel_claim_id) "
|
||||
" else null end as channel_name "
|
||||
" from content_claim "
|
||||
" inner join claim c on c.claim_outpoint=content_claim.claim_outpoint and content_claim.claim_outpoint=?"
|
||||
)
|
||||
claim_fields = transaction.execute(query, (outpoint, )).fetchone()
|
||||
if claim_fields:
|
||||
return StoredStreamClaim(*claim_fields)
|
||||
|
||||
|
||||
def _batched_select(transaction, query, parameters, batch_size=900):
|
||||
for start_index in range(0, len(parameters), batch_size):
|
||||
current_batch = parameters[start_index:start_index+batch_size]
|
||||
@@ -325,31 +311,6 @@ class SQLiteStorage(SQLiteMixin):
|
||||
"select status from blob where blob_hash=?", blob_hash
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
def count_should_announce_blobs(self):
|
||||
return self.run_and_return_one_or_none(
|
||||
"select count(*) from blob where should_announce=1 and status='finished'"
|
||||
)
|
||||
|
||||
def get_all_should_announce_blobs(self):
|
||||
return self.run_and_return_list(
|
||||
"select blob_hash from blob where should_announce=1 and status='finished'"
|
||||
)
|
||||
|
||||
def get_all_finished_blobs(self):
|
||||
return self.run_and_return_list(
|
||||
"select blob_hash from blob where status='finished'"
|
||||
)
|
||||
|
||||
def count_finished_blobs(self):
|
||||
return self.run_and_return_one_or_none(
|
||||
"select count(*) from blob where status='finished'"
|
||||
)
|
||||
|
||||
def update_last_announced_blobs(self, blob_hashes: typing.List[str]):
|
||||
def _update_last_announced_blobs(transaction: sqlite3.Connection):
|
||||
last_announced = self.time_getter()
|
||||
@@ -427,26 +388,6 @@ 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:
|
||||
@@ -459,11 +400,6 @@ class SQLiteStorage(SQLiteMixin):
|
||||
"s.stream_hash=f.stream_hash and s.sd_hash=?", sd_hash)
|
||||
return streams is not None
|
||||
|
||||
def rowid_for_stream(self, stream_hash: str) -> typing.Awaitable[typing.Optional[int]]:
|
||||
return self.run_and_return_one_or_none(
|
||||
"select rowid from file where stream_hash=?", stream_hash
|
||||
)
|
||||
|
||||
def store_stream(self, sd_blob: 'BlobFile', descriptor: 'StreamDescriptor'):
|
||||
return self.db.run(store_stream, sd_blob, descriptor)
|
||||
|
||||
@@ -509,12 +445,6 @@ 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)
|
||||
|
||||
@@ -788,55 +718,6 @@ class SQLiteStorage(SQLiteMixin):
|
||||
claim['effective_amount'] = calculate_effective_amount(claim['amount'], supports)
|
||||
return claim
|
||||
|
||||
async def get_claims_from_stream_hashes(self, stream_hashes: typing.List[str],
|
||||
include_supports: typing.Optional[bool] = True):
|
||||
claims = await self.db.run(get_claims_from_stream_hashes, stream_hashes)
|
||||
return {stream_hash: claim_info.as_dict() for stream_hash, claim_info in claims.items()}
|
||||
|
||||
async def get_claim(self, claim_outpoint, include_supports=True):
|
||||
claim_info = await self.db.run(get_content_claim_from_outpoint, claim_outpoint)
|
||||
if not claim_info:
|
||||
return
|
||||
result = claim_info.as_dict()
|
||||
if include_supports:
|
||||
supports = await self.get_supports(result['claim_id'])
|
||||
result['supports'] = supports
|
||||
result['effective_amount'] = calculate_effective_amount(result['amount'], supports)
|
||||
return result
|
||||
|
||||
def get_unknown_certificate_ids(self):
|
||||
def _get_unknown_certificate_claim_ids(transaction):
|
||||
return [
|
||||
claim_id for (claim_id,) in transaction.execute(
|
||||
"select distinct c1.channel_claim_id from claim as c1 "
|
||||
"where c1.channel_claim_id!='' "
|
||||
"and c1.channel_claim_id not in "
|
||||
"(select c2.claim_id from claim as c2)"
|
||||
).fetchall()
|
||||
]
|
||||
return self.db.run(_get_unknown_certificate_claim_ids)
|
||||
|
||||
async def get_pending_claim_outpoints(self):
|
||||
claim_outpoints = await self.run_and_return_list("select claim_outpoint from claim where height=-1")
|
||||
results = {} # {txid: [nout, ...]}
|
||||
for outpoint_str in claim_outpoints:
|
||||
txid, nout = outpoint_str.split(":")
|
||||
outputs = results.get(txid, [])
|
||||
outputs.append(int(nout))
|
||||
results[txid] = outputs
|
||||
if results:
|
||||
log.debug("missing transaction heights for %i claims", len(results))
|
||||
return results
|
||||
|
||||
def save_claim_tx_heights(self, claim_tx_heights):
|
||||
def _save_claim_heights(transaction):
|
||||
for outpoint, height in claim_tx_heights.items():
|
||||
transaction.execute(
|
||||
"update claim set height=? where claim_outpoint=? and height=-1",
|
||||
(height, outpoint)
|
||||
)
|
||||
return self.db.run(_save_claim_heights)
|
||||
|
||||
# # # # # # # # # reflector functions # # # # # # # # #
|
||||
|
||||
def update_reflected_stream(self, sd_hash, reflector_address, success=True):
|
||||
|
||||
@@ -379,7 +379,9 @@ class Language(Metadata):
|
||||
self.language = parts.pop(0)
|
||||
if parts and len(parts[0]) == 4:
|
||||
self.script = parts.pop(0)
|
||||
if parts and len(parts[0]) == 2:
|
||||
if parts and len(parts[0]) == 2 and parts[0].isalpha():
|
||||
self.region = parts.pop(0)
|
||||
if parts and len(parts[0]) == 3 and parts[0].isdigit():
|
||||
self.region = parts.pop(0)
|
||||
assert not parts, f"Failed to parse language tag: {langtag}"
|
||||
|
||||
@@ -404,10 +406,13 @@ class Language(Metadata):
|
||||
@property
|
||||
def region(self) -> str:
|
||||
if self.message.region:
|
||||
return LocationMessage.Country.Name(self.message.region)
|
||||
r = LocationMessage.Country.Name(self.message.region)
|
||||
return r[1:] if r.startswith('R') else r
|
||||
|
||||
@region.setter
|
||||
def region(self, region: str):
|
||||
if len(region) == 3:
|
||||
region = 'R'+region
|
||||
self.message.region = LocationMessage.Country.Value(region)
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ def from_old_json_schema(claim, payload: bytes):
|
||||
pass
|
||||
if value.get('nsfw', False):
|
||||
stream.tags.append('mature')
|
||||
if "fee" in value:
|
||||
if "fee" in value and isinstance(value['fee'], dict):
|
||||
fee = value["fee"]
|
||||
currency = list(fee.keys())[0]
|
||||
if currency == 'LBC':
|
||||
|
||||
@@ -77,7 +77,8 @@ class Outputs:
|
||||
def to_bytes(cls, txo_rows, extra_txo_rows, offset=0, total=None) -> bytes:
|
||||
page = OutputsMessage()
|
||||
page.offset = offset
|
||||
page.total = total or len(txo_rows)
|
||||
if total is not None:
|
||||
page.total = total
|
||||
for row in txo_rows:
|
||||
cls.row_to_message(row, page.txos.add())
|
||||
for row in extra_txo_rows:
|
||||
|
||||
@@ -6,8 +6,8 @@ WEIRD_CHARS_RE = re.compile(r"[#!~]")
|
||||
|
||||
|
||||
def normalize_tag(tag: str):
|
||||
return MULTI_SPACE_RE.sub(' ', WEIRD_CHARS_RE.sub(' ', tag.lower())).strip()
|
||||
return MULTI_SPACE_RE.sub(' ', WEIRD_CHARS_RE.sub(' ', tag.lower().replace("'", ""))).strip()
|
||||
|
||||
|
||||
def clean_tags(tags: List[str]):
|
||||
return [tag for tag in (normalize_tag(tag) for tag in tags) if tag]
|
||||
return [tag for tag in set(normalize_tag(tag) for tag in tags) if tag]
|
||||
File diff suppressed because it is too large.
Load diff
@@ -58,7 +58,7 @@ class StreamDescriptor:
|
||||
'sd_hash'
|
||||
]
|
||||
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, blob_dir: str, stream_name: str, key: str,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, 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):
|
||||
self.loop = loop
|
||||
@@ -139,7 +139,7 @@ class StreamDescriptor:
|
||||
return sd_blob
|
||||
|
||||
@classmethod
|
||||
def _from_stream_descriptor_blob(cls, loop: asyncio.BaseEventLoop, blob_dir: str,
|
||||
def _from_stream_descriptor_blob(cls, loop: asyncio.AbstractEventLoop, blob_dir: str,
|
||||
blob: AbstractBlob) -> 'StreamDescriptor':
|
||||
with blob.reader_context() as blob_reader:
|
||||
json_bytes = blob_reader.read()
|
||||
@@ -171,7 +171,7 @@ class StreamDescriptor:
|
||||
return descriptor
|
||||
|
||||
@classmethod
|
||||
async def from_stream_descriptor_blob(cls, loop: asyncio.BaseEventLoop, blob_dir: str,
|
||||
async def from_stream_descriptor_blob(cls, loop: asyncio.AbstractEventLoop, blob_dir: str,
|
||||
blob: AbstractBlob) -> 'StreamDescriptor':
|
||||
if not blob.is_readable():
|
||||
raise InvalidStreamDescriptorError(f"unreadable/missing blob: {blob.blob_hash}")
|
||||
@@ -209,7 +209,7 @@ class StreamDescriptor:
|
||||
|
||||
@classmethod
|
||||
async def create_stream(
|
||||
cls, loop: asyncio.BaseEventLoop, blob_dir: str, file_path: str, key: typing.Optional[bytes] = None,
|
||||
cls, loop: asyncio.AbstractEventLoop, 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'],
|
||||
|
||||
@@ -18,7 +18,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StreamDownloader:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager', sd_hash: str,
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, config: 'Config', blob_manager: 'BlobManager', sd_hash: str,
|
||||
descriptor: typing.Optional[StreamDescriptor] = None):
|
||||
self.loop = loop
|
||||
self.config = config
|
||||
@@ -114,7 +114,7 @@ class StreamDownloader:
|
||||
)
|
||||
|
||||
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]):
|
||||
if not filter(lambda b: b.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 asyncio.wait_for(
|
||||
self.blob_downloader.download_blob(blob_info.blob_hash, blob_info.length, connection_id),
|
||||
|
||||
@@ -33,7 +33,7 @@ def _get_next_available_file_name(download_directory: str, file_name: str) -> st
|
||||
return file_name
|
||||
|
||||
|
||||
async def get_next_available_file_name(loop: asyncio.BaseEventLoop, download_directory: str, file_name: str) -> str:
|
||||
async def get_next_available_file_name(loop: asyncio.AbstractEventLoop, download_directory: str, file_name: str) -> str:
|
||||
return await loop.run_in_executor(None, _get_next_available_file_name, download_directory, file_name)
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ class ManagedStream:
|
||||
'stream_claim_info',
|
||||
'download_id',
|
||||
'rowid',
|
||||
'written_bytes',
|
||||
'content_fee',
|
||||
'downloader',
|
||||
'analytics_manager',
|
||||
@@ -72,7 +71,7 @@ class ManagedStream:
|
||||
'finished_write_attempt'
|
||||
]
|
||||
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, 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, rowid: typing.Optional[int] = None,
|
||||
@@ -89,7 +88,6 @@ class ManagedStream:
|
||||
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
|
||||
@@ -121,6 +119,18 @@ class ManagedStream:
|
||||
def status(self) -> str:
|
||||
return self._status
|
||||
|
||||
@property
|
||||
def written_bytes(self) -> int:
|
||||
return 0 if not self.output_file_exists else os.stat(self.full_path).st_size
|
||||
|
||||
@property
|
||||
def completed(self):
|
||||
return self.written_bytes >= self.descriptor.lower_bound_decrypted_length()
|
||||
|
||||
@property
|
||||
def stream_url(self):
|
||||
return f"http://{self.config.streaming_host}:{self.config.streaming_port}/stream/{self.sd_hash}"
|
||||
|
||||
async def update_status(self, status: str):
|
||||
assert status in [self.STATUS_RUNNING, self.STATUS_STOPPED, self.STATUS_FINISHED]
|
||||
self._status = status
|
||||
@@ -177,7 +187,7 @@ class ManagedStream:
|
||||
|
||||
@property
|
||||
def blobs_completed(self) -> int:
|
||||
return sum([1 if self.blob_manager.is_blob_verified(b.blob_hash) else 0
|
||||
return sum([1 if b.blob_hash in self.blob_manager.completed_blob_hashes else 0
|
||||
for b in self.descriptor.blobs[:-1]])
|
||||
|
||||
@property
|
||||
@@ -201,57 +211,8 @@ class ManagedStream:
|
||||
def mime_type(self):
|
||||
return guess_media_type(os.path.basename(self.descriptor.suggested_file_name))[0]
|
||||
|
||||
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 {
|
||||
'streaming_url': f"http://{self.config.streaming_host}:{self.config.streaming_port}/stream/{self.sd_hash}",
|
||||
'completed': (self.output_file_exists and (self.status in ('stopped', 'finished'))
|
||||
or not self.saving.is_set()) 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,
|
||||
'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': 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(),
|
||||
'written_bytes': written_bytes,
|
||||
'blobs_completed': self.blobs_completed,
|
||||
'blobs_in_stream': self.blobs_in_stream,
|
||||
'blobs_remaining': self.blobs_remaining,
|
||||
'status': self.status,
|
||||
'claim_id': self.claim_id,
|
||||
'txid': self.txid,
|
||||
'nout': self.nout,
|
||||
'outpoint': self.outpoint,
|
||||
'metadata': self.metadata,
|
||||
'protobuf': self.metadata_protobuf,
|
||||
'channel_claim_id': self.channel_claim_id,
|
||||
'channel_name': self.channel_name,
|
||||
'claim_name': self.claim_name,
|
||||
'content_fee': self.content_fee
|
||||
}
|
||||
|
||||
@classmethod
|
||||
async def create(cls, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
|
||||
async def create(cls, loop: asyncio.AbstractEventLoop, 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(
|
||||
@@ -371,7 +332,6 @@ class ManagedStream:
|
||||
async for blob_info, decrypted in self._aiter_read_stream(connection_id=self.SAVING_ID):
|
||||
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)
|
||||
@@ -387,7 +347,6 @@ class ManagedStream:
|
||||
if os.path.isfile(output_path):
|
||||
log.warning("removing incomplete download %s for %s", output_path, self.sd_hash)
|
||||
os.remove(output_path)
|
||||
self.written_bytes = 0
|
||||
if isinstance(err, asyncio.TimeoutError):
|
||||
self.downloader.stop()
|
||||
await self.blob_manager.storage.change_file_download_dir_and_file_name(
|
||||
@@ -425,7 +384,6 @@ class ManagedStream:
|
||||
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()
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ def path_or_none(p) -> typing.Optional[str]:
|
||||
|
||||
|
||||
class StreamManager:
|
||||
def __init__(self, loop: asyncio.BaseEventLoop, config: 'Config', blob_manager: 'BlobManager',
|
||||
def __init__(self, loop: asyncio.AbstractEventLoop, config: 'Config', blob_manager: 'BlobManager',
|
||||
wallet: 'LbryWalletManager', storage: 'SQLiteStorage', node: typing.Optional['Node'],
|
||||
analytics_manager: typing.Optional['AnalyticsManager'] = None):
|
||||
self.loop = loop
|
||||
@@ -360,6 +360,10 @@ class StreamManager:
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
raise ResolveTimeout(uri)
|
||||
except Exception as err:
|
||||
if isinstance(err, asyncio.CancelledError):
|
||||
raise
|
||||
raise ResolveError(f"Unexpected error resolving stream: {str(err)}")
|
||||
await self.storage.save_claims_for_resolve([
|
||||
value for value in resolved_result.values() if 'error' not in value
|
||||
])
|
||||
@@ -391,7 +395,7 @@ class StreamManager:
|
||||
fee_amount, fee_address = None, None
|
||||
|
||||
# check that the fee is payable
|
||||
if not to_replace and claim.stream.has_fee:
|
||||
if not to_replace and claim.stream.has_fee and claim.stream.fee.amount:
|
||||
fee_amount = round(exchange_rate_manager.convert_currency(
|
||||
claim.stream.fee.currency, "LBC", claim.stream.fee.amount
|
||||
), 5)
|
||||
@@ -444,12 +448,14 @@ class StreamManager:
|
||||
finally:
|
||||
if self.analytics_manager and (error or (stream and (stream.downloader.time_to_descriptor or
|
||||
stream.downloader.time_to_first_bytes))):
|
||||
server = self.wallet.ledger.network.client.server
|
||||
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),
|
||||
None if not stream else len(stream.downloader.blob_downloader.connection_failures),
|
||||
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,
|
||||
@@ -457,7 +463,9 @@ class StreamManager:
|
||||
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__
|
||||
None if not error else error.__class__.__name__,
|
||||
None if not error else str(error),
|
||||
None if not server else f"{server[0]}:{server[1]}"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ class CommandTestCase(IntegrationTestCase):
|
||||
await self.on_transaction_id(txid)
|
||||
await self.generate(1)
|
||||
await self.on_transaction_id(txid)
|
||||
return txid
|
||||
|
||||
async def on_transaction_dict(self, tx):
|
||||
await self.ledger.wait(
|
||||
|
||||
+5
-11
@@ -81,28 +81,22 @@ def check_connection(server="lbry.com", port=80, timeout=5) -> bool:
|
||||
try:
|
||||
server = socket.gethostbyname(server)
|
||||
socket.create_connection((server, port), timeout).close()
|
||||
log.debug('Connection successful')
|
||||
return True
|
||||
except (socket.gaierror, socket.herror) as ex:
|
||||
log.warning("Failed to connect to %s:%s. Unable to resolve domain. Trying to bypass DNS",
|
||||
server, port)
|
||||
log.debug("Failed to connect to %s:%s. Unable to resolve domain. Trying to bypass DNS",
|
||||
server, port)
|
||||
try:
|
||||
server = "8.8.8.8"
|
||||
port = 53
|
||||
socket.create_connection((server, port), timeout).close()
|
||||
log.debug('Connection successful')
|
||||
return True
|
||||
except Exception:
|
||||
log.error("Failed to connect to %s:%s. Maybe the internet connection is not working",
|
||||
server, port)
|
||||
except OSError:
|
||||
return False
|
||||
except Exception:
|
||||
log.error("Failed to connect to %s:%s. Maybe the internet connection is not working",
|
||||
server, port)
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
async def async_check_connection(server="lbry.com", port=80, timeout=5) -> bool:
|
||||
async def async_check_connection(server="lbry.com", port=80, timeout=1) -> bool:
|
||||
return await asyncio.get_event_loop().run_in_executor(None, check_connection, server, port, timeout)
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ __node_daemon__ = 'lbrycrdd'
|
||||
__node_cli__ = 'lbrycrd-cli'
|
||||
__node_bin__ = ''
|
||||
__node_url__ = (
|
||||
'https://github.com/lbryio/lbrycrd/releases/download/v0.12.4.0/lbrycrd-linux.zip'
|
||||
'https://github.com/lbryio/lbrycrd/releases/download/v0.17.2.1/lbrycrd-linux.zip'
|
||||
)
|
||||
__spvserver__ = 'lbry.wallet.server.coin.LBCRegTest'
|
||||
|
||||
|
||||
+57
-20
@@ -1,9 +1,12 @@
|
||||
import json
|
||||
import logging
|
||||
from functools import partial
|
||||
from hashlib import sha256
|
||||
from string import hexdigits
|
||||
|
||||
import ecdsa
|
||||
from lbry.wallet.dewies import dewies_to_lbc
|
||||
from lbry.wallet.constants import TXO_TYPES
|
||||
|
||||
from torba.client.baseaccount import BaseAccount, HierarchicalDeterministic
|
||||
|
||||
@@ -25,6 +28,7 @@ class Account(BaseAccount):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.channel_keys = {}
|
||||
self.preferences = {}
|
||||
|
||||
@property
|
||||
def hash(self) -> bytes:
|
||||
@@ -36,6 +40,7 @@ class Account(BaseAccount):
|
||||
def apply(self, d: dict):
|
||||
super().apply(d)
|
||||
self.channel_keys.update(d.get('certificates', {}))
|
||||
self.preferences.update(d.get('preferences', {}))
|
||||
|
||||
def add_channel_private_key(self, private_key):
|
||||
public_key_bytes = private_key.get_verifying_key().to_der()
|
||||
@@ -72,9 +77,39 @@ class Account(BaseAccount):
|
||||
|
||||
def get_balance(self, confirmations=0, include_claims=False, **constraints):
|
||||
if not include_claims:
|
||||
constraints.update({'is_claim': 0, 'is_update': 0, 'is_support': 0})
|
||||
constraints.update({'txo_type': 0})
|
||||
return super().get_balance(confirmations, **constraints)
|
||||
|
||||
async def get_granular_balances(self, confirmations=0, reserved_subtotals=False):
|
||||
tips_balance, supports_balance, claims_balance = 0, 0, 0
|
||||
get_total_balance = partial(self.get_balance, confirmations=confirmations, include_claims=True)
|
||||
total = await get_total_balance()
|
||||
if reserved_subtotals:
|
||||
claims_balance = await get_total_balance(txo_type__in=[TXO_TYPES['stream'], TXO_TYPES['channel']])
|
||||
for amount, spent, from_me, to_me, height in await self.get_support_summary():
|
||||
if confirmations > 0 and not 0 < height <= self.ledger.headers.height - (confirmations - 1):
|
||||
continue
|
||||
if not spent and to_me:
|
||||
if from_me:
|
||||
supports_balance += amount
|
||||
else:
|
||||
tips_balance += amount
|
||||
reserved = claims_balance + supports_balance + tips_balance
|
||||
else:
|
||||
reserved = await self.get_balance(
|
||||
confirmations=confirmations, include_claims=True, txo_type__gt=0
|
||||
)
|
||||
return {
|
||||
'total': dewies_to_lbc(total),
|
||||
'available': dewies_to_lbc(total - reserved),
|
||||
'reserved': dewies_to_lbc(reserved),
|
||||
'reserved_subtotals': {
|
||||
'claims': dewies_to_lbc(claims_balance),
|
||||
'supports': dewies_to_lbc(supports_balance),
|
||||
'tips': dewies_to_lbc(tips_balance)
|
||||
} if reserved_subtotals else None
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_private_key_from_seed(cls, ledger, seed: str, password: str):
|
||||
return super().get_private_key_from_seed(
|
||||
@@ -85,54 +120,56 @@ class Account(BaseAccount):
|
||||
def from_dict(cls, ledger, wallet, d: dict) -> 'Account':
|
||||
account = super().from_dict(ledger, wallet, d)
|
||||
account.channel_keys = d.get('certificates', {})
|
||||
account.preferences = d.get('preferences', {})
|
||||
return account
|
||||
|
||||
def to_dict(self, include_channel_keys=True):
|
||||
def to_dict(self, include_channel_keys=True, include_preferences=True):
|
||||
d = super().to_dict()
|
||||
if include_channel_keys:
|
||||
d['certificates'] = self.channel_keys
|
||||
if include_preferences and self.preferences:
|
||||
d['preferences'] = self.preferences
|
||||
return d
|
||||
|
||||
async def get_details(self, **kwargs):
|
||||
details = await super().get_details(**kwargs)
|
||||
details['certificates'] = len(self.channel_keys)
|
||||
if self.preferences:
|
||||
details['preferences'] = self.preferences
|
||||
return details
|
||||
|
||||
@staticmethod
|
||||
def constraint_spending_utxos(constraints):
|
||||
constraints.update({'is_claim': 0, 'is_update': 0, 'is_support': 0})
|
||||
def get_transaction_history(self, **constraints):
|
||||
return self.ledger.get_transaction_history(account=self, **constraints)
|
||||
|
||||
def get_utxos(self, **constraints):
|
||||
self.constraint_spending_utxos(constraints)
|
||||
return super().get_utxos(**constraints)
|
||||
|
||||
def get_utxo_count(self, **constraints):
|
||||
self.constraint_spending_utxos(constraints)
|
||||
return super().get_utxo_count(**constraints)
|
||||
def get_transaction_history_count(self, **constraints):
|
||||
return self.ledger.get_transaction_history_count(account=self, **constraints)
|
||||
|
||||
def get_claims(self, **constraints):
|
||||
return self.ledger.db.get_claims(account=self, **constraints)
|
||||
return self.ledger.get_claims(account=self, **constraints)
|
||||
|
||||
def get_claim_count(self, **constraints):
|
||||
return self.ledger.db.get_claim_count(account=self, **constraints)
|
||||
return self.ledger.get_claim_count(account=self, **constraints)
|
||||
|
||||
def get_streams(self, **constraints):
|
||||
return self.ledger.db.get_streams(account=self, **constraints)
|
||||
return self.ledger.get_streams(account=self, **constraints)
|
||||
|
||||
def get_stream_count(self, **constraints):
|
||||
return self.ledger.db.get_stream_count(account=self, **constraints)
|
||||
return self.ledger.get_stream_count(account=self, **constraints)
|
||||
|
||||
def get_channels(self, **constraints):
|
||||
return self.ledger.db.get_channels(account=self, **constraints)
|
||||
return self.ledger.get_channels(account=self, **constraints)
|
||||
|
||||
def get_channel_count(self, **constraints):
|
||||
return self.ledger.db.get_channel_count(account=self, **constraints)
|
||||
return self.ledger.get_channel_count(account=self, **constraints)
|
||||
|
||||
def get_supports(self, **constraints):
|
||||
return self.ledger.db.get_supports(account=self, **constraints)
|
||||
return self.ledger.get_supports(account=self, **constraints)
|
||||
|
||||
def get_support_count(self, **constraints):
|
||||
return self.ledger.db.get_support_count(account=self, **constraints)
|
||||
return self.ledger.get_support_count(account=self, **constraints)
|
||||
|
||||
def get_support_summary(self):
|
||||
return self.ledger.db.get_supports_summary(account_id=self.id)
|
||||
|
||||
async def release_all_outputs(self):
|
||||
await self.ledger.db.release_all_outputs(self)
|
||||
@@ -0,0 +1,5 @@
|
||||
TXO_TYPES = {
|
||||
"stream": 1,
|
||||
"channel": 2,
|
||||
"support": 3
|
||||
}
|
||||
@@ -3,6 +3,7 @@ from typing import List
|
||||
from torba.client.basedatabase import BaseDatabase
|
||||
|
||||
from lbry.wallet.transaction import Output
|
||||
from lbry.wallet.constants import TXO_TYPES
|
||||
|
||||
|
||||
class WalletDatabase(BaseDatabase):
|
||||
@@ -17,15 +18,12 @@ class WalletDatabase(BaseDatabase):
|
||||
script blob not null,
|
||||
is_reserved boolean not null default 0,
|
||||
|
||||
txo_type integer not null default 0,
|
||||
claim_id text,
|
||||
claim_name text,
|
||||
is_claim boolean not null default 0,
|
||||
is_update boolean not null default 0,
|
||||
is_support boolean not null default 0,
|
||||
is_buy boolean not null default 0,
|
||||
is_sell boolean not null default 0
|
||||
claim_name text
|
||||
);
|
||||
create index if not exists txo_claim_id_idx on txo (claim_id);
|
||||
create index if not exists txo_txo_type_idx on txo (txo_type);
|
||||
"""
|
||||
|
||||
CREATE_TABLES_QUERY = (
|
||||
@@ -40,20 +38,20 @@ class WalletDatabase(BaseDatabase):
|
||||
|
||||
def txo_to_row(self, tx, address, txo):
|
||||
row = super().txo_to_row(tx, address, txo)
|
||||
row.update({
|
||||
'is_claim': txo.script.is_claim_name,
|
||||
'is_update': txo.script.is_update_claim,
|
||||
'is_support': txo.script.is_support_claim,
|
||||
'is_buy': txo.script.is_buy_claim,
|
||||
'is_sell': txo.script.is_sell_claim,
|
||||
})
|
||||
if txo.is_claim:
|
||||
if txo.can_decode_claim:
|
||||
row['txo_type'] = TXO_TYPES.get(txo.claim.claim_type, TXO_TYPES['stream'])
|
||||
else:
|
||||
row['txo_type'] = TXO_TYPES['stream']
|
||||
elif txo.is_support:
|
||||
row['txo_type'] = TXO_TYPES['support']
|
||||
if txo.script.is_claim_involved:
|
||||
row['claim_id'] = txo.claim_id
|
||||
row['claim_name'] = txo.claim_name
|
||||
return row
|
||||
|
||||
async def get_txos(self, **constraints) -> List[Output]:
|
||||
my_account = constraints.get('my_account', constraints.get('account', None))
|
||||
my_accounts = constraints.get('my_accounts', constraints.get('accounts', []))
|
||||
|
||||
txos = await super().get_txos(**constraints)
|
||||
|
||||
@@ -62,28 +60,34 @@ class WalletDatabase(BaseDatabase):
|
||||
if txo.is_claim and txo.can_decode_claim:
|
||||
if txo.claim.is_signed:
|
||||
channel_ids.add(txo.claim.signing_channel_id)
|
||||
if txo.claim.is_channel and my_account is not None:
|
||||
txo.private_key = my_account.get_channel_private_key(
|
||||
txo.claim.channel.public_key_bytes
|
||||
)
|
||||
if txo.claim.is_channel and my_accounts:
|
||||
for account in my_accounts:
|
||||
private_key = account.get_channel_private_key(
|
||||
txo.claim.channel.public_key_bytes
|
||||
)
|
||||
if private_key:
|
||||
txo.private_key = private_key
|
||||
break
|
||||
|
||||
if channel_ids:
|
||||
channels = {
|
||||
txo.claim_id: txo for txo in
|
||||
(await self.get_claims(
|
||||
my_account=my_account,
|
||||
my_accounts=my_accounts,
|
||||
claim_id__in=channel_ids
|
||||
))
|
||||
}
|
||||
for txo in txos:
|
||||
if txo.script.is_claim_name or txo.script.is_update_claim:
|
||||
if txo.is_claim and txo.can_decode_claim:
|
||||
txo.channel = channels.get(txo.claim.signing_channel_id, None)
|
||||
|
||||
return txos
|
||||
|
||||
@staticmethod
|
||||
def constrain_claims(constraints):
|
||||
constraints['claim_type__any'] = {'is_claim': 1, 'is_update': 1}
|
||||
constraints['txo_type__in'] = [
|
||||
TXO_TYPES['stream'], TXO_TYPES['channel']
|
||||
]
|
||||
|
||||
async def get_claims(self, **constraints) -> List[Output]:
|
||||
self.constrain_claims(constraints)
|
||||
@@ -95,8 +99,7 @@ class WalletDatabase(BaseDatabase):
|
||||
|
||||
@staticmethod
|
||||
def constrain_streams(constraints):
|
||||
if 'claim_name' not in constraints or 'claim_id' not in constraints:
|
||||
constraints['claim_name__not_like'] = '@%'
|
||||
constraints['txo_type'] = TXO_TYPES['stream']
|
||||
|
||||
def get_streams(self, **constraints):
|
||||
self.constrain_streams(constraints)
|
||||
@@ -108,8 +111,7 @@ class WalletDatabase(BaseDatabase):
|
||||
|
||||
@staticmethod
|
||||
def constrain_channels(constraints):
|
||||
if 'claim_name' not in constraints or 'claim_id' not in constraints:
|
||||
constraints['claim_name__like'] = '@%'
|
||||
constraints['txo_type'] = TXO_TYPES['channel']
|
||||
|
||||
def get_channels(self, **constraints):
|
||||
self.constrain_channels(constraints)
|
||||
@@ -121,7 +123,7 @@ class WalletDatabase(BaseDatabase):
|
||||
|
||||
@staticmethod
|
||||
def constrain_supports(constraints):
|
||||
constraints['is_support'] = 1
|
||||
constraints['txo_type'] = TXO_TYPES['support']
|
||||
|
||||
def get_supports(self, **constraints):
|
||||
self.constrain_supports(constraints)
|
||||
@@ -138,3 +140,14 @@ class WalletDatabase(BaseDatabase):
|
||||
" SELECT address from pubkey_address WHERE account = ?"
|
||||
" )", [account.public_key.address]
|
||||
)
|
||||
|
||||
def get_supports_summary(self, account_id):
|
||||
return self.db.execute_fetchall(f"""
|
||||
select txo.amount, exists(select * from txi where txi.txoid=txo.txoid) as spent,
|
||||
(txo.txid in
|
||||
(select txi.txid from txi join pubkey_address a on txi.address = a.address
|
||||
where a.account = ?)) as from_me,
|
||||
(txo.address in (select address from pubkey_address where account=?)) as to_me,
|
||||
tx.height
|
||||
from txo join tx using (txid) where txo_type={TXO_TYPES['support']}
|
||||
""", (account_id, account_id))
|
||||
+148
-5
@@ -1,14 +1,14 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from binascii import unhexlify
|
||||
from typing import Tuple, List, Dict
|
||||
from typing import Tuple, List
|
||||
from datetime import datetime
|
||||
|
||||
from torba.client.baseledger import BaseLedger
|
||||
from torba.client.baseaccount import SingleKey
|
||||
from lbry.schema.result import Outputs
|
||||
from lbry.schema.url import URL
|
||||
from lbry.wallet.dewies import dewies_to_lbc
|
||||
from lbry.wallet.resolve import Resolver
|
||||
from lbry.wallet.account import Account
|
||||
from lbry.wallet.network import Network
|
||||
from lbry.wallet.database import WalletDatabase
|
||||
@@ -51,7 +51,6 @@ class MainNetLedger(BaseLedger):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fee_per_name_char = self.config.get('fee_per_name_char', self.default_fee_per_name_char)
|
||||
self.resolver = Resolver(self)
|
||||
|
||||
async def _inflate_outputs(self, query):
|
||||
outputs = Outputs.from_base64(await query)
|
||||
@@ -74,10 +73,10 @@ class MainNetLedger(BaseLedger):
|
||||
result[url] = {'error': f'{url} did not resolve to a claim'}
|
||||
return result
|
||||
|
||||
async def claim_search(self, **kwargs) -> Tuple[List, int, int]:
|
||||
async def claim_search(self, **kwargs) -> Tuple[List[Output], int, int]:
|
||||
return await self._inflate_outputs(self.network.claim_search(**kwargs))
|
||||
|
||||
async def get_claim_by_claim_id(self, claim_id) -> Dict[str, Output]:
|
||||
async def get_claim_by_claim_id(self, claim_id) -> Output:
|
||||
for claim in (await self.claim_search(claim_id=claim_id))[0]:
|
||||
return claim
|
||||
|
||||
@@ -109,6 +108,150 @@ class MainNetLedger(BaseLedger):
|
||||
'Failed to display wallet state, please file issue '
|
||||
'for this bug along with the traceback you see below:')
|
||||
|
||||
@staticmethod
|
||||
def constraint_spending_utxos(constraints):
|
||||
constraints['txo_type'] = 0
|
||||
|
||||
def get_utxos(self, **constraints):
|
||||
self.constraint_spending_utxos(constraints)
|
||||
return super().get_utxos(**constraints)
|
||||
|
||||
def get_utxo_count(self, **constraints):
|
||||
self.constraint_spending_utxos(constraints)
|
||||
return super().get_utxo_count(**constraints)
|
||||
|
||||
def get_claims(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_claims(**constraints)
|
||||
|
||||
def get_claim_count(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_claim_count(**constraints)
|
||||
|
||||
def get_streams(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_streams(**constraints)
|
||||
|
||||
def get_stream_count(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_stream_count(**constraints)
|
||||
|
||||
def get_channels(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_channels(**constraints)
|
||||
|
||||
def get_channel_count(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_channel_count(**constraints)
|
||||
|
||||
def get_supports(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_supports(**constraints)
|
||||
|
||||
def get_support_count(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_support_count(**constraints)
|
||||
|
||||
async def get_transaction_history(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
txs = await self.db.get_transactions(**constraints)
|
||||
headers = self.headers
|
||||
history = []
|
||||
for tx in txs:
|
||||
ts = headers[tx.height]['timestamp'] if tx.height > 0 else None
|
||||
item = {
|
||||
'txid': tx.id,
|
||||
'timestamp': ts,
|
||||
'date': datetime.fromtimestamp(ts).isoformat(' ')[:-3] if tx.height > 0 else None,
|
||||
'confirmations': (headers.height+1) - tx.height if tx.height > 0 else 0,
|
||||
'claim_info': [],
|
||||
'update_info': [],
|
||||
'support_info': [],
|
||||
'abandon_info': []
|
||||
}
|
||||
is_my_inputs = all([txi.is_my_account for txi in tx.inputs])
|
||||
if is_my_inputs:
|
||||
# fees only matter if we are the ones paying them
|
||||
item['value'] = dewies_to_lbc(tx.net_account_balance+tx.fee)
|
||||
item['fee'] = dewies_to_lbc(-tx.fee)
|
||||
else:
|
||||
# someone else paid the fees
|
||||
item['value'] = dewies_to_lbc(tx.net_account_balance)
|
||||
item['fee'] = '0.0'
|
||||
for txo in tx.my_claim_outputs:
|
||||
item['claim_info'].append({
|
||||
'address': txo.get_address(self),
|
||||
'balance_delta': dewies_to_lbc(-txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
for txo in tx.my_update_outputs:
|
||||
if is_my_inputs: # updating my own claim
|
||||
previous = None
|
||||
for txi in tx.inputs:
|
||||
if txi.txo_ref.txo is not None:
|
||||
other_txo = txi.txo_ref.txo
|
||||
if (other_txo.is_claim or other_txo.script.is_support_claim) \
|
||||
and other_txo.claim_id == txo.claim_id:
|
||||
previous = other_txo
|
||||
break
|
||||
if previous is not None:
|
||||
item['update_info'].append({
|
||||
'address': txo.get_address(self),
|
||||
'balance_delta': dewies_to_lbc(previous.amount-txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
else: # someone sent us their claim
|
||||
item['update_info'].append({
|
||||
'address': txo.get_address(self),
|
||||
'balance_delta': dewies_to_lbc(0),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
for txo in tx.my_support_outputs:
|
||||
item['support_info'].append({
|
||||
'address': txo.get_address(self),
|
||||
'balance_delta': dewies_to_lbc(txo.amount if not is_my_inputs else -txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'is_tip': not is_my_inputs,
|
||||
'nout': txo.position
|
||||
})
|
||||
if is_my_inputs:
|
||||
for txo in tx.other_support_outputs:
|
||||
item['support_info'].append({
|
||||
'address': txo.get_address(self),
|
||||
'balance_delta': dewies_to_lbc(-txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'is_tip': is_my_inputs,
|
||||
'nout': txo.position
|
||||
})
|
||||
for txo in tx.my_abandon_outputs:
|
||||
item['abandon_info'].append({
|
||||
'address': txo.get_address(self),
|
||||
'balance_delta': dewies_to_lbc(txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
history.append(item)
|
||||
return history
|
||||
|
||||
def get_transaction_history_count(self, **constraints):
|
||||
self.constraint_account_or_all(constraints)
|
||||
return self.db.get_transaction_count(**constraints)
|
||||
|
||||
|
||||
class TestNetLedger(MainNetLedger):
|
||||
network_name = 'testnet'
|
||||
|
||||
@@ -3,16 +3,13 @@ import json
|
||||
import logging
|
||||
from binascii import unhexlify
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from torba.client.basemanager import BaseWalletManager
|
||||
from torba.rpc.jsonrpc import CodeMessageError
|
||||
|
||||
from lbry.wallet.ledger import MainNetLedger
|
||||
from lbry.wallet.account import BaseAccount
|
||||
from lbry.wallet.transaction import Transaction
|
||||
from lbry.wallet.database import WalletDatabase
|
||||
from lbry.wallet.dewies import dewies_to_lbc
|
||||
from lbry.conf import Config
|
||||
|
||||
|
||||
@@ -184,6 +181,8 @@ class LbryWalletManager(BaseWalletManager):
|
||||
len(set(receiving_addresses).difference(set(migrated_receiving))))
|
||||
|
||||
def get_best_blockhash(self):
|
||||
if len(self.ledger.headers) <= 0:
|
||||
return self.ledger.genesis_hash
|
||||
return self.ledger.headers.hash(self.ledger.headers.height).decode()
|
||||
|
||||
def get_unused_address(self):
|
||||
@@ -200,6 +199,8 @@ class LbryWalletManager(BaseWalletManager):
|
||||
if not tx:
|
||||
try:
|
||||
raw = await self.ledger.network.get_transaction(txid)
|
||||
if not raw:
|
||||
return {'success': False, 'code': 404, 'message': 'transaction not found'}
|
||||
height = await self.ledger.network.get_transaction_height(txid)
|
||||
except CodeMessageError as e:
|
||||
return {'success': False, 'code': e.code, 'message': e.message}
|
||||
@@ -207,102 +208,6 @@ class LbryWalletManager(BaseWalletManager):
|
||||
await self.ledger.maybe_verify_transaction(tx, height)
|
||||
return tx
|
||||
|
||||
@staticmethod
|
||||
async def get_history(account: BaseAccount, **constraints):
|
||||
headers = account.ledger.headers
|
||||
txs = await account.get_transactions(**constraints)
|
||||
history = []
|
||||
for tx in txs:
|
||||
ts = headers[tx.height]['timestamp'] if tx.height > 0 else None
|
||||
item = {
|
||||
'txid': tx.id,
|
||||
'timestamp': ts,
|
||||
'date': datetime.fromtimestamp(ts).isoformat(' ')[:-3] if tx.height > 0 else None,
|
||||
'confirmations': (headers.height+1) - tx.height if tx.height > 0 else 0,
|
||||
'claim_info': [],
|
||||
'update_info': [],
|
||||
'support_info': [],
|
||||
'abandon_info': []
|
||||
}
|
||||
is_my_inputs = all([txi.is_my_account for txi in tx.inputs])
|
||||
if is_my_inputs:
|
||||
# fees only matter if we are the ones paying them
|
||||
item['value'] = dewies_to_lbc(tx.net_account_balance+tx.fee)
|
||||
item['fee'] = dewies_to_lbc(-tx.fee)
|
||||
else:
|
||||
# someone else paid the fees
|
||||
item['value'] = dewies_to_lbc(tx.net_account_balance)
|
||||
item['fee'] = '0.0'
|
||||
for txo in tx.my_claim_outputs:
|
||||
item['claim_info'].append({
|
||||
'address': txo.get_address(account.ledger),
|
||||
'balance_delta': dewies_to_lbc(-txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
for txo in tx.my_update_outputs:
|
||||
if is_my_inputs: # updating my own claim
|
||||
previous = None
|
||||
for txi in tx.inputs:
|
||||
if txi.txo_ref.txo is not None:
|
||||
other_txo = txi.txo_ref.txo
|
||||
if (other_txo.is_claim or other_txo.script.is_support_claim) \
|
||||
and other_txo.claim_id == txo.claim_id:
|
||||
previous = other_txo
|
||||
break
|
||||
if previous is not None:
|
||||
item['update_info'].append({
|
||||
'address': txo.get_address(account.ledger),
|
||||
'balance_delta': dewies_to_lbc(previous.amount-txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
else: # someone sent us their claim
|
||||
item['update_info'].append({
|
||||
'address': txo.get_address(account.ledger),
|
||||
'balance_delta': dewies_to_lbc(0),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
for txo in tx.my_support_outputs:
|
||||
item['support_info'].append({
|
||||
'address': txo.get_address(account.ledger),
|
||||
'balance_delta': dewies_to_lbc(txo.amount if not is_my_inputs else -txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'is_tip': not is_my_inputs,
|
||||
'nout': txo.position
|
||||
})
|
||||
if is_my_inputs:
|
||||
for txo in tx.other_support_outputs:
|
||||
item['support_info'].append({
|
||||
'address': txo.get_address(account.ledger),
|
||||
'balance_delta': dewies_to_lbc(-txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'is_tip': is_my_inputs,
|
||||
'nout': txo.position
|
||||
})
|
||||
for txo in tx.my_abandon_outputs:
|
||||
item['abandon_info'].append({
|
||||
'address': txo.get_address(account.ledger),
|
||||
'balance_delta': dewies_to_lbc(txo.amount),
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'claim_id': txo.claim_id,
|
||||
'claim_name': txo.claim_name,
|
||||
'nout': txo.position
|
||||
})
|
||||
history.append(item)
|
||||
return history
|
||||
|
||||
def save(self):
|
||||
for wallet in self.wallets:
|
||||
wallet.save()
|
||||
@@ -3,9 +3,6 @@ from torba.client.basenetwork import BaseNetwork
|
||||
|
||||
class Network(BaseNetwork):
|
||||
|
||||
def get_server_height(self):
|
||||
return self.rpc('blockchain.block.get_server_height', [])
|
||||
|
||||
def get_claims_by_ids(self, claim_ids):
|
||||
return self.rpc('blockchain.claimtrie.getclaimsbyids', claim_ids)
|
||||
|
||||
|
||||
@@ -1,404 +0,0 @@
|
||||
import logging
|
||||
|
||||
import asyncio
|
||||
|
||||
from binascii import unhexlify, hexlify
|
||||
from lbry.utils import lru_cache_concurrent
|
||||
from lbry.wallet.account import validate_claim_id
|
||||
from lbry.wallet.dewies import dewies_to_lbc
|
||||
from lbry.error import UnknownNameError, UnknownClaimID, UnknownURI, UnknownOutpoint
|
||||
from lbry.schema.claim import Claim
|
||||
from google.protobuf.message import DecodeError
|
||||
from lbry.schema.url import URL
|
||||
from lbry.wallet.claim_proofs import verify_proof, InvalidProofError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Resolver:
|
||||
|
||||
def __init__(self, ledger):
|
||||
self.transaction_class = ledger.transaction_class
|
||||
self.network = ledger.network
|
||||
self.ledger = ledger
|
||||
|
||||
async def resolve(self, page, page_size, *uris):
|
||||
uris = set(uris)
|
||||
try:
|
||||
for uri in uris:
|
||||
for part in URL.parse(uri).parts:
|
||||
if part.claim_id:
|
||||
validate_claim_id(part.claim_id)
|
||||
claim_trie_root = self.ledger.headers.claim_trie_root
|
||||
resolutions = await self.network.get_values_for_uris(self.ledger.headers.hash().decode(), *uris)
|
||||
if len(uris) > 1:
|
||||
return await self._batch_handle(resolutions, uris, page, page_size, claim_trie_root)
|
||||
return await self._handle_resolutions(resolutions, uris, page, page_size, claim_trie_root)
|
||||
except ValueError as err:
|
||||
return {'error': err.args[0]}
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
return {'error': str(e)}
|
||||
|
||||
async def _batch_handle(self, resolutions, uris, page, page_size, claim_trie_root):
|
||||
futs = []
|
||||
for uri in uris:
|
||||
futs.append(
|
||||
asyncio.ensure_future(self._handle_resolutions(resolutions, [uri], page, page_size, claim_trie_root))
|
||||
)
|
||||
results = await asyncio.gather(*futs)
|
||||
return dict(list(map(lambda result: list(result.items())[0], results)))
|
||||
|
||||
@lru_cache_concurrent(256)
|
||||
async def _fetch_tx(self, txid):
|
||||
return self.transaction_class(unhexlify(await self.network.get_transaction(txid)))
|
||||
|
||||
async def _handle_resolutions(self, resolutions, requested_uris, page, page_size, claim_trie_root):
|
||||
results = {}
|
||||
for uri in requested_uris:
|
||||
resolution = (resolutions or {}).get(uri, {})
|
||||
if resolution:
|
||||
try:
|
||||
results[uri] = _handle_claim_result(
|
||||
await self._handle_resolve_uri_response(uri, resolution, claim_trie_root, page, page_size),
|
||||
uri
|
||||
)
|
||||
except (UnknownNameError, UnknownClaimID, UnknownURI) as err:
|
||||
log.exception(err)
|
||||
results[uri] = {'error': str(err)}
|
||||
else:
|
||||
results[uri] = {'error': "URI lbry://{} cannot be resolved".format(uri.replace("lbry://", ""))}
|
||||
return results
|
||||
|
||||
async def _handle_resolve_uri_response(self, uri, resolution, claim_trie_root, page=0, page_size=10):
|
||||
result = {}
|
||||
parsed_uri = URL.parse(uri)
|
||||
certificate_response = None
|
||||
# parse an included certificate
|
||||
if 'certificate' in resolution:
|
||||
certificate_response = resolution['certificate']['result']
|
||||
certificate_resolution_type = resolution['certificate']['resolution_type']
|
||||
if certificate_resolution_type == "winning" and certificate_response:
|
||||
if 'height' in certificate_response:
|
||||
certificate_response = _verify_proof(parsed_uri.stream.name,
|
||||
claim_trie_root,
|
||||
certificate_response,
|
||||
ledger=self.ledger)
|
||||
elif certificate_resolution_type not in ['winning', 'claim_id', 'sequence']:
|
||||
raise Exception(f"unknown response type: {certificate_resolution_type}")
|
||||
result['certificate'] = await self.parse_and_validate_claim_result(certificate_response)
|
||||
result['claims_in_channel'] = len(resolution.get('unverified_claims_in_channel', []))
|
||||
|
||||
# if this was a resolution for a name, parse the result
|
||||
if 'claim' in resolution:
|
||||
claim_response = resolution['claim']['result']
|
||||
claim_resolution_type = resolution['claim']['resolution_type']
|
||||
if claim_resolution_type == "winning" and claim_response:
|
||||
if 'height' in claim_response:
|
||||
claim_response = _verify_proof(parsed_uri.stream.name,
|
||||
claim_trie_root,
|
||||
claim_response,
|
||||
ledger=self.ledger)
|
||||
elif claim_resolution_type not in ["sequence", "winning", "claim_id"]:
|
||||
raise Exception(f"unknown response type: {claim_resolution_type}")
|
||||
result['claim'] = await self.parse_and_validate_claim_result(claim_response,
|
||||
certificate_response)
|
||||
|
||||
# if this was a resolution for a name in a channel make sure there is only one valid
|
||||
# match
|
||||
elif 'unverified_claims_for_name' in resolution and 'certificate' in result:
|
||||
unverified_claims_for_name = resolution['unverified_claims_for_name']
|
||||
|
||||
channel_info = await self.get_channel_claims_page(unverified_claims_for_name,
|
||||
result['certificate'], page=1)
|
||||
claims_in_channel, upper_bound = channel_info
|
||||
|
||||
if not claims_in_channel:
|
||||
log.error("No valid claims for this name for this channel")
|
||||
elif len(claims_in_channel) > 1:
|
||||
log.warning("Multiple signed claims for the same name.")
|
||||
winner = pick_winner_from_channel_path_collision(claims_in_channel)
|
||||
if winner:
|
||||
result['claim'] = winner
|
||||
else:
|
||||
log.error("No valid claims for this name for this channel")
|
||||
else:
|
||||
result['claim'] = claims_in_channel[0]
|
||||
|
||||
# parse and validate claims in a channel iteratively into pages of results
|
||||
elif 'unverified_claims_in_channel' in resolution and 'certificate' in result:
|
||||
ids_to_check = resolution['unverified_claims_in_channel']
|
||||
channel_info = await self.get_channel_claims_page(ids_to_check, result['certificate'],
|
||||
page=page, page_size=page_size)
|
||||
claims_in_channel, upper_bound = channel_info
|
||||
|
||||
if claims_in_channel:
|
||||
result['total_claims'] = upper_bound
|
||||
result['claims_in_channel'] = claims_in_channel
|
||||
elif 'error' not in result:
|
||||
return {'error': 'claim not found', 'success': False, 'uri': str(parsed_uri)}
|
||||
|
||||
# invalid signatures can only return outside a channel
|
||||
if result.get('claim', {}).get('has_signature', False):
|
||||
if parsed_uri.has_stream and not result['claim']['signature_is_valid']:
|
||||
return {'error': 'claim not found', 'success': False, 'uri': str(parsed_uri)}
|
||||
return result
|
||||
|
||||
async def parse_and_validate_claim_result(self, claim_result, certificate=None):
|
||||
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
|
||||
if claim_result['value'].is_signed:
|
||||
claim_result['has_signature'] = True
|
||||
claim_tx = await self._fetch_tx(claim_result['txid'])
|
||||
if certificate is None:
|
||||
log.info("fetching certificate to check claim signature")
|
||||
channel_id = claim_result['value'].signing_channel_id
|
||||
certificate = (await self.network.get_claims_by_ids([channel_id])).get(channel_id)
|
||||
if not certificate:
|
||||
log.warning('Certificate %s not found', channel_id)
|
||||
claim_result['channel_name'] = certificate['name'] if certificate else None
|
||||
cert_tx = await self._fetch_tx(certificate['txid']) if certificate else None
|
||||
claim_result['signature_is_valid'] = validate_claim_signature_and_get_channel_name(
|
||||
claim_result, certificate, self.ledger, claim_tx=claim_tx, cert_tx=cert_tx
|
||||
)
|
||||
# fixme: workaround while json encoder isnt used here
|
||||
if cert_tx:
|
||||
channel_txo = cert_tx.outputs[certificate['nout']]
|
||||
claim_result['signing_channel'] = {
|
||||
'name': channel_txo.claim_name,
|
||||
'claim_id': channel_txo.claim_id,
|
||||
'value': channel_txo.claim
|
||||
}
|
||||
claim_result['is_channel_signature_valid'] = claim_result['signature_is_valid']
|
||||
|
||||
if 'amount' in claim_result:
|
||||
claim_result['amount'] = dewies_to_lbc(claim_result['amount'])
|
||||
claim_result['effective_amount'] = dewies_to_lbc(claim_result['effective_amount'])
|
||||
claim_result['supports'] = [
|
||||
{'txid': txid, 'nout': nout, 'amount': dewies_to_lbc(amount)}
|
||||
for (txid, nout, amount) in claim_result['supports']
|
||||
]
|
||||
|
||||
claim_result['height'] = claim_result.get('height', -1) or -1
|
||||
claim_result['permanent_url'] = f"lbry://{claim_result['name']}#{claim_result['claim_id']}"
|
||||
|
||||
return claim_result
|
||||
|
||||
@staticmethod
|
||||
def prepare_claim_queries(start_position, query_size, channel_claim_infos):
|
||||
queries = [tuple()]
|
||||
names = {}
|
||||
# a table of index counts for the sorted claim ids, including ignored claims
|
||||
absolute_position_index = {}
|
||||
|
||||
block_sorted_infos = sorted(channel_claim_infos.items(), key=lambda x: int(x[1][1]))
|
||||
per_block_infos = {}
|
||||
for claim_id, (name, height) in block_sorted_infos:
|
||||
claims = per_block_infos.get(height, [])
|
||||
claims.append((claim_id, name))
|
||||
per_block_infos[height] = sorted(claims, key=lambda x: int(x[0], 16))
|
||||
|
||||
abs_position = 0
|
||||
|
||||
for height in sorted(per_block_infos.keys(), reverse=True):
|
||||
for claim_id, name in per_block_infos[height]:
|
||||
names[claim_id] = name
|
||||
absolute_position_index[claim_id] = abs_position
|
||||
if abs_position >= start_position:
|
||||
if len(queries[-1]) >= query_size:
|
||||
queries.append(tuple())
|
||||
queries[-1] += (claim_id,)
|
||||
abs_position += 1
|
||||
return queries, names, absolute_position_index
|
||||
|
||||
async def iter_channel_claims_pages(self, queries, claim_positions, claim_names, certificate,
|
||||
page_size=10):
|
||||
# lbryum server returns a dict of {claim_id: (name, claim_height)}
|
||||
# first, sort the claims by block height (and by claim id int value within a block).
|
||||
|
||||
# map the sorted claims into getclaimsbyids queries of query_size claim ids each
|
||||
|
||||
# send the batched queries to lbryum server and iteratively validate and parse
|
||||
# the results, yield a page of results at a time.
|
||||
|
||||
# these results can include those where `signature_is_valid` is False. if they are skipped,
|
||||
# page indexing becomes tricky, as the number of results isn't known until after having
|
||||
# processed them.
|
||||
# TODO: fix ^ in lbry.schema
|
||||
|
||||
async def iter_validate_channel_claims():
|
||||
formatted_claims = []
|
||||
for claim_ids in queries:
|
||||
batch_result = await self.network.get_claims_by_ids(claim_ids)
|
||||
for claim_id in claim_ids:
|
||||
claim = batch_result[claim_id]
|
||||
if claim['name'] == claim_names[claim_id]:
|
||||
formatted_claim = await self.parse_and_validate_claim_result(claim, certificate)
|
||||
formatted_claim['absolute_channel_position'] = claim_positions[
|
||||
claim['claim_id']]
|
||||
formatted_claims.append(formatted_claim)
|
||||
else:
|
||||
log.warning("ignoring claim with name mismatch %s %s", claim['name'],
|
||||
claim['claim_id'])
|
||||
return formatted_claims
|
||||
|
||||
results = []
|
||||
|
||||
for claim in await iter_validate_channel_claims():
|
||||
results.append(claim)
|
||||
|
||||
# if there is a full page of results, yield it
|
||||
if len(results) and len(results) % page_size == 0:
|
||||
return results[-page_size:]
|
||||
|
||||
return results
|
||||
|
||||
async def get_channel_claims_page(self, channel_claim_infos, certificate, page, page_size=10):
|
||||
page = page or 0
|
||||
page_size = max(page_size, 1)
|
||||
if page_size > 500:
|
||||
raise Exception("page size above maximum allowed")
|
||||
start_position = (page - 1) * page_size
|
||||
queries, names, claim_positions = self.prepare_claim_queries(start_position, page_size,
|
||||
channel_claim_infos)
|
||||
upper_bound = len(claim_positions)
|
||||
if not page:
|
||||
return None, upper_bound
|
||||
if start_position > upper_bound:
|
||||
raise IndexError("claim %i greater than max %i" % (start_position, upper_bound))
|
||||
page_generator = await self.iter_channel_claims_pages(queries, claim_positions, names,
|
||||
certificate, page_size=page_size)
|
||||
return page_generator, upper_bound
|
||||
|
||||
|
||||
def _verify_proof(name, claim_trie_root, result, ledger):
|
||||
"""
|
||||
Verify proof for name claim
|
||||
"""
|
||||
support_amount = sum([amt for (stxid, snout, amt) in result['supports']])
|
||||
|
||||
def _build_response(name, tx, nOut):
|
||||
output = tx.outputs[nOut]
|
||||
r = {
|
||||
'name': name,
|
||||
'value': hexlify(output.script.values['claim']),
|
||||
'claim_id': output.claim_id,
|
||||
'txid': tx.id,
|
||||
'nout': nOut,
|
||||
'amount': output.amount,
|
||||
'effective_amount': output.amount + support_amount,
|
||||
'height': result['height'],
|
||||
'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
|
||||
|
||||
def _parse_proof_result(name, result):
|
||||
if 'txhash' in result['proof'] and 'nOut' in result['proof']:
|
||||
if 'transaction' in result:
|
||||
tx = ledger.transaction_class(raw=unhexlify(result['transaction']))
|
||||
nOut = result['proof']['nOut']
|
||||
if result['proof']['txhash'] == tx.id:
|
||||
if 0 <= nOut < len(tx.outputs):
|
||||
if tx.outputs[nOut].claim_name == name:
|
||||
return _build_response(name, tx, nOut)
|
||||
return {'error': 'name in proof did not match requested name'}
|
||||
outputs = len(tx['outputs'])
|
||||
return {'error': 'invalid nOut: %d (let(outputs): %d' % (nOut, outputs)}
|
||||
return {'error': "computed txid did not match given transaction: %s vs %s" %
|
||||
(tx.id, result['proof']['txhash'])
|
||||
}
|
||||
return {'error': "didn't receive a transaction with the proof"}
|
||||
return {'error': 'name is not claimed'}
|
||||
|
||||
if 'proof' in result:
|
||||
name = result.get('name', name)
|
||||
proof_name = result.get('normalized_name', name)
|
||||
try:
|
||||
verify_proof(result['proof'], claim_trie_root, proof_name)
|
||||
except InvalidProofError:
|
||||
return {'error': "Proof was invalid"}
|
||||
return _parse_proof_result(name, result)
|
||||
else:
|
||||
return {'error': "proof not in result"}
|
||||
|
||||
|
||||
def validate_claim_signature_and_get_channel_name(claim_result, certificate_claim, ledger,
|
||||
claim_tx=None, cert_tx=None):
|
||||
valid_signature = False
|
||||
if cert_tx and certificate_claim and claim_tx and claim_result:
|
||||
valid_signature = claim_tx.outputs[claim_result['nout']].is_signed_by(
|
||||
cert_tx.outputs[certificate_claim['nout']], ledger
|
||||
)
|
||||
if not valid_signature:
|
||||
log.warning("lbry://%s#%s has an invalid signature",
|
||||
claim_result['name'], claim_result['claim_id'])
|
||||
return valid_signature
|
||||
|
||||
|
||||
# TODO: The following came from code handling lbryum results. Now that it's all in one place a refactor should unify it.
|
||||
def _decode_claim_result(claim):
|
||||
if 'decoded_claim' in claim:
|
||||
return claim
|
||||
if 'value' not in claim:
|
||||
log.warning('Got an invalid claim while parsing, please report: %s', claim)
|
||||
claim['protobuf'] = None
|
||||
claim['value'] = None
|
||||
backend_message = ' SDK message: ' + claim.get('error', '')
|
||||
claim['error'] = "Failed to parse: missing value." + backend_message
|
||||
return claim
|
||||
try:
|
||||
if not isinstance(claim['value'], Claim):
|
||||
claim['value'] = Claim.from_bytes(unhexlify(claim['value']))
|
||||
claim['protobuf'] = hexlify(claim['value'].to_bytes())
|
||||
claim['decoded_claim'] = True
|
||||
except DecodeError:
|
||||
claim['decoded_claim'] = False
|
||||
claim['protobuf'] = claim['value']
|
||||
claim['value'] = None
|
||||
return claim
|
||||
|
||||
|
||||
def _handle_claim_result(results, uri):
|
||||
if not results:
|
||||
raise UnknownURI(uri)
|
||||
|
||||
if 'error' in results:
|
||||
if results['error'] in ['name is not claimed', 'claim not found']:
|
||||
if 'claim_id' in results:
|
||||
raise UnknownClaimID(results['claim_id'])
|
||||
if 'name' in results:
|
||||
raise UnknownNameError(results['name'])
|
||||
if 'uri' in results:
|
||||
raise UnknownURI(results['uri'])
|
||||
if 'outpoint' in results:
|
||||
raise UnknownOutpoint(results['outpoint'])
|
||||
raise Exception(results['error'])
|
||||
if not {'value', 'claim', 'certificate'}.intersection(results.keys()):
|
||||
raise Exception(f'result in unexpected format:{results}')
|
||||
return results
|
||||
|
||||
|
||||
def pick_winner_from_channel_path_collision(claims_in_channel):
|
||||
# we should be doing this by effective amount so we pick the controlling claim, however changing the resolved
|
||||
# claim triggers another issue where 2 claims cant be saved for the same file. This code picks the oldest, so it
|
||||
# stays the same. Using effective amount would change the resolved claims for a channel path on takeovers,
|
||||
# potentially triggering that.
|
||||
winner = {}
|
||||
for claim in claims_in_channel:
|
||||
if not winner or claim['height'] < winner['height'] or \
|
||||
(claim['height'] == winner['height'] and claim['nout'] < winner['nout']):
|
||||
winner = claim if claim['signature_is_valid'] else winner
|
||||
return winner or None
|
||||
@@ -3,7 +3,7 @@ import time
|
||||
from torba.server.block_processor import BlockProcessor
|
||||
|
||||
from lbry.schema.claim import Claim
|
||||
from lbry.wallet.server.db import SQLDB
|
||||
from lbry.wallet.server.db.writer import SQLDB
|
||||
|
||||
|
||||
class Timer:
|
||||
@@ -68,6 +68,7 @@ class LBRYBlockProcessor(BlockProcessor):
|
||||
self.logger.info(f"LbryumX Block Processor - Validating signatures: {self.should_validate_signatures}")
|
||||
self.sql: SQLDB = self.db.sql
|
||||
self.timer = Timer('BlockProcessor')
|
||||
self.search_cache = {}
|
||||
|
||||
def advance_blocks(self, blocks):
|
||||
self.sql.begin()
|
||||
@@ -78,6 +79,12 @@ class LBRYBlockProcessor(BlockProcessor):
|
||||
raise
|
||||
finally:
|
||||
self.sql.commit()
|
||||
if self.db.first_sync and self.height == self.daemon.cached_height():
|
||||
self.timer.run(self.sql.db.executescript, self.sql.SEARCH_INDEXES, timer_name='executing SEARCH_INDEXES')
|
||||
if self.env.individual_tag_indexes:
|
||||
self.timer.run(self.sql.db.executescript, self.sql.TAG_INDEXES, timer_name='executing TAG_INDEXES')
|
||||
for cache in self.search_cache.values():
|
||||
cache.clear()
|
||||
|
||||
def advance_txs(self, height, txs, header):
|
||||
timer = self.timer.sub_timers['advance_blocks']
|
||||
|
||||
@@ -9,13 +9,14 @@ from torba.server.coins import Coin, CoinError
|
||||
|
||||
|
||||
class LBC(Coin):
|
||||
from .session import LBRYElectrumX
|
||||
from .session import LBRYElectrumX, LBRYSessionManager
|
||||
from .block_processor import LBRYBlockProcessor
|
||||
from .daemon import LBCDaemon
|
||||
from .db import LBRYDB
|
||||
from .db.writer import LBRYDB
|
||||
DAEMON = LBCDaemon
|
||||
SESSIONCLS = LBRYElectrumX
|
||||
BLOCK_PROCESSOR = LBRYBlockProcessor
|
||||
SESSION_MANAGER = LBRYSessionManager
|
||||
DB = LBRYDB
|
||||
NAME = "LBRY"
|
||||
SHORTNAME = "LBC"
|
||||
@@ -101,7 +102,7 @@ class LBC(Coin):
|
||||
'''
|
||||
Overrides electrumx hashX from script by extracting addresses from claim scripts.
|
||||
'''
|
||||
if script and script[0] == OpCodes.OP_RETURN:
|
||||
if script and script[0] == OpCodes.OP_RETURN or not script:
|
||||
return None
|
||||
if script[0] in [
|
||||
OutputScript.OP_CLAIM_NAME,
|
||||
|
||||
Whitespace-only changes.
File renamed without changes.
@@ -0,0 +1,220 @@
|
||||
CLAIM_TYPES = {
|
||||
'stream': 1,
|
||||
'channel': 2,
|
||||
}
|
||||
|
||||
STREAM_TYPES = {
|
||||
'video': 1,
|
||||
'audio': 2,
|
||||
'image': 3,
|
||||
'document': 4,
|
||||
'binary': 5,
|
||||
'model': 6
|
||||
}
|
||||
|
||||
MATURE_TAGS = [
|
||||
'nsfw', 'porn', 'xxx', 'mature', 'adult', 'sex'
|
||||
]
|
||||
|
||||
COMMON_TAGS = {
|
||||
"gaming": "gaming",
|
||||
"people & blogs": "people_and_blogs",
|
||||
"pop culture": "pop_culture",
|
||||
"entertainment": "entertainment",
|
||||
"technology": "technology",
|
||||
"music": "music",
|
||||
"funny": "funny",
|
||||
"education": "education",
|
||||
"learning": "learning",
|
||||
"news": "news",
|
||||
"gameplay": "gameplay",
|
||||
"science & technology": "science_and_technology",
|
||||
"playstation 4": "playstation_4",
|
||||
"beliefs": "beliefs",
|
||||
"nature": "nature",
|
||||
"news & politics": "news_and_politics",
|
||||
"comedy": "comedy",
|
||||
"games": "games",
|
||||
"sony interactive entertainment": "sony_interactive_entertainment",
|
||||
"film & animation": "film_and_animation",
|
||||
"game": "game",
|
||||
"howto & style": "howto_and_style",
|
||||
"weapons": "weapons",
|
||||
"blockchain": "blockchain",
|
||||
"video game": "video_game",
|
||||
"sports": "sports",
|
||||
"walkthrough": "walkthrough",
|
||||
"ps4live": "ps4live",
|
||||
"art": "art",
|
||||
"pc": "pc",
|
||||
"economics": "economics",
|
||||
"automotive": "automotive",
|
||||
"minecraft": "minecraft",
|
||||
"playthrough": "playthrough",
|
||||
"ps4share": "ps4share",
|
||||
"tutorial": "tutorial",
|
||||
"play": "play",
|
||||
"twitch": "twitch",
|
||||
"how to": "how_to",
|
||||
"ps4": "ps4",
|
||||
"bitcoin": "bitcoin",
|
||||
"fortnite": "fortnite",
|
||||
"commentary": "commentary",
|
||||
"lets play": "lets_play",
|
||||
"fun": "fun",
|
||||
"politics": "politics",
|
||||
"xbox": "xbox",
|
||||
"autos & vehicles": "autos_and_vehicles",
|
||||
"travel & events": "travel_and_events",
|
||||
"food": "food",
|
||||
"science": "science",
|
||||
"mature": "mature",
|
||||
"xbox one": "xbox_one",
|
||||
"liberal": "liberal",
|
||||
"democrat": "democrat",
|
||||
"progressive": "progressive",
|
||||
"survival": "survival",
|
||||
"nonprofits & activism": "nonprofits_and_activism",
|
||||
"cryptocurrency": "cryptocurrency",
|
||||
"playstation": "playstation",
|
||||
"nintendo": "nintendo",
|
||||
"government": "government",
|
||||
"steam": "steam",
|
||||
"podcast": "podcast",
|
||||
"horror": "horror",
|
||||
"conservative": "conservative",
|
||||
"reaction": "reaction",
|
||||
"trailer": "trailer",
|
||||
"love": "love",
|
||||
"cnn": "cnn",
|
||||
"republican": "republican",
|
||||
"gamer": "gamer",
|
||||
"political": "political",
|
||||
"hangoutsonair": "hangoutsonair",
|
||||
"hoa": "hoa",
|
||||
"msnbc": "msnbc",
|
||||
"cbs": "cbs",
|
||||
"donald trump": "donald_trump",
|
||||
"fiction": "fiction",
|
||||
"fox news": "fox_news",
|
||||
"anime": "anime",
|
||||
"crypto": "crypto",
|
||||
"ethereum": "ethereum",
|
||||
"call of duty": "call_of_duty",
|
||||
"multiplayer": "multiplayer",
|
||||
"android": "android",
|
||||
"epic": "epic",
|
||||
"rpg": "rpg",
|
||||
"adventure": "adventure",
|
||||
"secular talk": "secular_talk",
|
||||
"btc": "btc",
|
||||
"atheist": "atheist",
|
||||
"atheism": "atheism",
|
||||
"ps3": "ps3",
|
||||
"video games": "video_games",
|
||||
"cod": "cod",
|
||||
"agnostic": "agnostic",
|
||||
"movie": "movie",
|
||||
"online": "online",
|
||||
"fps": "fps",
|
||||
"mod": "mod",
|
||||
"reviews": "reviews",
|
||||
"sharefactory": "sharefactory",
|
||||
"world": "world",
|
||||
"space": "space",
|
||||
"hilarious": "hilarious",
|
||||
"stream": "stream",
|
||||
"lol": "lol",
|
||||
"sony": "sony",
|
||||
"god": "god",
|
||||
"lets": "lets",
|
||||
"dance": "dance",
|
||||
"pvp": "pvp",
|
||||
"tech": "tech",
|
||||
"zombies": "zombies",
|
||||
"pokemon": "pokemon",
|
||||
"fail": "fail",
|
||||
"xbox 360": "xbox_360",
|
||||
"film": "film",
|
||||
"unboxing": "unboxing",
|
||||
"animation": "animation",
|
||||
"travel": "travel",
|
||||
"money": "money",
|
||||
"wwe": "wwe",
|
||||
"how": "how",
|
||||
"mods": "mods",
|
||||
"pubg": "pubg",
|
||||
"indie": "indie",
|
||||
"strategy": "strategy",
|
||||
"history": "history",
|
||||
"rap": "rap",
|
||||
"ios": "ios",
|
||||
"sony computer entertainment": "sony_computer_entertainment",
|
||||
"mobile": "mobile",
|
||||
"trump": "trump",
|
||||
"flat earth": "flat_earth",
|
||||
"hack": "hack",
|
||||
"trap": "trap",
|
||||
"fox": "fox",
|
||||
"vlogging": "vlogging",
|
||||
"news radio": "news_radio",
|
||||
"humor": "humor",
|
||||
"facebook": "facebook",
|
||||
"edm": "edm",
|
||||
"fitness": "fitness",
|
||||
"vaping": "vaping",
|
||||
"hip hop": "hip_hop",
|
||||
"secular": "secular",
|
||||
"jesus": "jesus",
|
||||
"vape": "vape",
|
||||
"song": "song",
|
||||
"remix": "remix",
|
||||
"guitar": "guitar",
|
||||
"daily": "daily",
|
||||
"mining": "mining",
|
||||
"diy": "diy",
|
||||
"videogame": "videogame",
|
||||
"pets & animals": "pets_and_animals",
|
||||
"funny moments": "funny_moments",
|
||||
"religion": "religion",
|
||||
"death": "death",
|
||||
"media": "media",
|
||||
"nbc": "nbc",
|
||||
"war": "war",
|
||||
"freedom": "freedom",
|
||||
"viral": "viral",
|
||||
"meme": "meme",
|
||||
"family": "family",
|
||||
"gold": "gold",
|
||||
"photography": "photography",
|
||||
"chill": "chill",
|
||||
"zombie": "zombie",
|
||||
"computer": "computer",
|
||||
"sniper": "sniper",
|
||||
"bible": "bible",
|
||||
"linux": "linux",
|
||||
"overwatch": "overwatch",
|
||||
"pro": "pro",
|
||||
"dragon": "dragon",
|
||||
"litecoin": "litecoin",
|
||||
"gta": "gta",
|
||||
"iphone": "iphone",
|
||||
"house": "house",
|
||||
"bass": "bass",
|
||||
"bitcoin news": "bitcoin_news",
|
||||
"wii": "wii",
|
||||
"crash": "crash",
|
||||
"league of legends": "league_of_legends",
|
||||
"grand theft auto v": "grand_theft_auto_v",
|
||||
"mario": "mario",
|
||||
"mmorpg": "mmorpg",
|
||||
"satire": "satire",
|
||||
"fire": "fire",
|
||||
"racing": "racing",
|
||||
"apple": "apple",
|
||||
"health": "health",
|
||||
"instrumental": "instrumental",
|
||||
"destiny": "destiny",
|
||||
"truth": "truth",
|
||||
"race": "race"
|
||||
}
|
||||
@@ -0,0 +1,530 @@
|
||||
import time
|
||||
import struct
|
||||
import sqlite3
|
||||
import logging
|
||||
from typing import Tuple, List, Dict, Union, Type, Optional
|
||||
from binascii import unhexlify
|
||||
from decimal import Decimal
|
||||
from contextvars import ContextVar
|
||||
from functools import wraps
|
||||
from dataclasses import dataclass
|
||||
|
||||
from torba.client.basedatabase import query, interpolate
|
||||
|
||||
from lbry.schema.url import URL, normalize_name
|
||||
from lbry.schema.tags import clean_tags
|
||||
from lbry.schema.result import Outputs
|
||||
from lbry.wallet.ledger import BaseLedger, MainNetLedger, RegTestLedger
|
||||
|
||||
from .common import CLAIM_TYPES, STREAM_TYPES, COMMON_TAGS
|
||||
|
||||
|
||||
class SQLiteOperationalError(sqlite3.OperationalError):
|
||||
def __init__(self, metrics):
|
||||
super().__init__('sqlite query errored')
|
||||
self.metrics = metrics
|
||||
|
||||
|
||||
class SQLiteInterruptedError(sqlite3.OperationalError):
|
||||
def __init__(self, metrics):
|
||||
super().__init__('sqlite query interrupted')
|
||||
self.metrics = metrics
|
||||
|
||||
|
||||
ATTRIBUTE_ARRAY_MAX_LENGTH = 100
|
||||
|
||||
|
||||
INTEGER_PARAMS = {
|
||||
'height', 'creation_height', 'activation_height', 'expiration_height',
|
||||
'timestamp', 'creation_timestamp', 'release_time', 'fee_amount',
|
||||
'tx_position', 'channel_join',
|
||||
'amount', 'effective_amount', 'support_amount',
|
||||
'trending_group', 'trending_mixed',
|
||||
'trending_local', 'trending_global',
|
||||
}
|
||||
|
||||
SEARCH_PARAMS = {
|
||||
'name', 'claim_id', 'txid', 'nout', 'channel', 'channel_ids', 'not_channel_ids',
|
||||
'public_key_id', 'claim_type', 'stream_types', 'media_types', 'fee_currency',
|
||||
'has_channel_signature', 'signature_valid',
|
||||
'any_tags', 'all_tags', 'not_tags',
|
||||
'any_locations', 'all_locations', 'not_locations',
|
||||
'any_languages', 'all_languages', 'not_languages',
|
||||
'is_controlling', 'limit', 'offset', 'order_by',
|
||||
'no_totals',
|
||||
} | INTEGER_PARAMS
|
||||
|
||||
|
||||
ORDER_FIELDS = {
|
||||
'name', 'claim_hash'
|
||||
} | INTEGER_PARAMS
|
||||
|
||||
|
||||
PRAGMAS = """
|
||||
pragma journal_mode=WAL;
|
||||
"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReaderState:
|
||||
db: sqlite3.Connection
|
||||
stack: List[List]
|
||||
metrics: Dict
|
||||
is_tracking_metrics: bool
|
||||
ledger: Type[BaseLedger]
|
||||
query_timeout: float
|
||||
log: logging.Logger
|
||||
|
||||
def close(self):
|
||||
self.db.close()
|
||||
|
||||
def reset_metrics(self):
|
||||
self.stack = []
|
||||
self.metrics = {}
|
||||
|
||||
def set_query_timeout(self):
|
||||
stop_at = time.perf_counter() + self.query_timeout
|
||||
|
||||
def interruptor():
|
||||
if time.perf_counter() >= stop_at:
|
||||
self.db.interrupt()
|
||||
return
|
||||
|
||||
self.db.set_progress_handler(interruptor, 100)
|
||||
|
||||
|
||||
ctx: ContextVar[Optional[ReaderState]] = ContextVar('ctx')
|
||||
|
||||
|
||||
def initializer(log, _path, _ledger_name, query_timeout, _measure=False):
|
||||
db = sqlite3.connect(_path, isolation_level=None, uri=True)
|
||||
db.row_factory = sqlite3.Row
|
||||
ctx.set(
|
||||
ReaderState(
|
||||
db=db, stack=[], metrics={}, is_tracking_metrics=_measure,
|
||||
ledger=MainNetLedger if _ledger_name == 'mainnet' else RegTestLedger,
|
||||
query_timeout=query_timeout, log=log
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def cleanup():
|
||||
ctx.get().close()
|
||||
ctx.set(None)
|
||||
|
||||
|
||||
def measure(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
state = ctx.get()
|
||||
if not state.is_tracking_metrics:
|
||||
return func(*args, **kwargs)
|
||||
metric = {}
|
||||
state.metrics.setdefault(func.__name__, []).append(metric)
|
||||
state.stack.append([])
|
||||
start = time.perf_counter()
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
finally:
|
||||
elapsed = int((time.perf_counter()-start)*1000)
|
||||
metric['total'] = elapsed
|
||||
metric['isolated'] = (elapsed-sum(state.stack.pop()))
|
||||
if state.stack:
|
||||
state.stack[-1].append(elapsed)
|
||||
return wrapper
|
||||
|
||||
|
||||
def reports_metrics(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
state = ctx.get()
|
||||
if not state.is_tracking_metrics:
|
||||
return func(*args, **kwargs)
|
||||
state.reset_metrics()
|
||||
r = func(*args, **kwargs)
|
||||
return r, state.metrics
|
||||
return wrapper
|
||||
|
||||
|
||||
@reports_metrics
|
||||
def search_to_bytes(constraints) -> Union[bytes, Tuple[bytes, Dict]]:
|
||||
return encode_result(search(constraints))
|
||||
|
||||
|
||||
@reports_metrics
|
||||
def resolve_to_bytes(urls) -> Union[bytes, Tuple[bytes, Dict]]:
|
||||
return encode_result(resolve(urls))
|
||||
|
||||
|
||||
def encode_result(result):
|
||||
return Outputs.to_bytes(*result)
|
||||
|
||||
|
||||
@measure
|
||||
def execute_query(sql, values) -> List:
|
||||
context = ctx.get()
|
||||
context.set_query_timeout()
|
||||
try:
|
||||
return context.db.execute(sql, values).fetchall()
|
||||
except sqlite3.OperationalError as err:
|
||||
plain_sql = interpolate(sql, values)
|
||||
if context.is_tracking_metrics:
|
||||
context.metrics['execute_query'][-1]['sql'] = plain_sql
|
||||
if str(err) == "interrupted":
|
||||
context.log.warning("interrupted slow sqlite query:\n%s", plain_sql)
|
||||
raise SQLiteInterruptedError(context.metrics)
|
||||
context.log.exception('failed running query', exc_info=err)
|
||||
raise SQLiteOperationalError(context.metrics)
|
||||
|
||||
|
||||
def _get_claims(cols, for_count=False, **constraints) -> Tuple[str, Dict]:
|
||||
if 'order_by' in constraints:
|
||||
sql_order_by = []
|
||||
for order_by in constraints['order_by']:
|
||||
is_asc = order_by.startswith('^')
|
||||
column = order_by[1:] if is_asc else order_by
|
||||
if column not in ORDER_FIELDS:
|
||||
raise NameError(f'{column} is not a valid order_by field')
|
||||
if column == 'name':
|
||||
column = 'normalized'
|
||||
sql_order_by.append(
|
||||
f"claim.{column} ASC" if is_asc else f"claim.{column} DESC"
|
||||
)
|
||||
constraints['order_by'] = sql_order_by
|
||||
|
||||
ops = {'<=': '__lte', '>=': '__gte', '<': '__lt', '>': '__gt'}
|
||||
for constraint in INTEGER_PARAMS:
|
||||
if constraint in constraints:
|
||||
value = constraints.pop(constraint)
|
||||
postfix = ''
|
||||
if isinstance(value, str):
|
||||
if len(value) >= 2 and value[:2] in ops:
|
||||
postfix, value = ops[value[:2]], value[2:]
|
||||
elif len(value) >= 1 and value[0] in ops:
|
||||
postfix, value = ops[value[0]], value[1:]
|
||||
if constraint == 'fee_amount':
|
||||
value = Decimal(value)*1000
|
||||
constraints[f'claim.{constraint}{postfix}'] = int(value)
|
||||
|
||||
if constraints.pop('is_controlling', False):
|
||||
if {'sequence', 'amount_order'}.isdisjoint(constraints):
|
||||
for_count = False
|
||||
constraints['claimtrie.claim_hash__is_not_null'] = ''
|
||||
if 'sequence' in constraints:
|
||||
constraints['order_by'] = 'claim.activation_height ASC'
|
||||
constraints['offset'] = int(constraints.pop('sequence')) - 1
|
||||
constraints['limit'] = 1
|
||||
if 'amount_order' in constraints:
|
||||
constraints['order_by'] = 'claim.effective_amount DESC'
|
||||
constraints['offset'] = int(constraints.pop('amount_order')) - 1
|
||||
constraints['limit'] = 1
|
||||
|
||||
if 'claim_id' in constraints:
|
||||
claim_id = constraints.pop('claim_id')
|
||||
if len(claim_id) == 40:
|
||||
constraints['claim.claim_id'] = claim_id
|
||||
else:
|
||||
constraints['claim.claim_id__like'] = f'{claim_id[:40]}%'
|
||||
|
||||
if 'name' in constraints:
|
||||
constraints['claim.normalized'] = normalize_name(constraints.pop('name'))
|
||||
|
||||
if 'public_key_id' in constraints:
|
||||
constraints['claim.public_key_hash'] = sqlite3.Binary(
|
||||
ctx.get().ledger.address_to_hash160(constraints.pop('public_key_id')))
|
||||
if 'channel_hash' in constraints:
|
||||
constraints['claim.channel_hash'] = sqlite3.Binary(constraints.pop('channel_hash'))
|
||||
if 'channel_ids' in constraints:
|
||||
channel_ids = constraints.pop('channel_ids')
|
||||
if channel_ids:
|
||||
constraints['claim.channel_hash__in'] = [
|
||||
sqlite3.Binary(unhexlify(cid)[::-1]) for cid in channel_ids
|
||||
]
|
||||
if 'not_channel_ids' in constraints:
|
||||
not_channel_ids = constraints.pop('not_channel_ids')
|
||||
if not_channel_ids:
|
||||
not_channel_ids_binary = [
|
||||
sqlite3.Binary(unhexlify(ncid)[::-1]) for ncid in not_channel_ids
|
||||
]
|
||||
if constraints.get('has_channel_signature', False):
|
||||
constraints['claim.channel_hash__not_in'] = not_channel_ids_binary
|
||||
else:
|
||||
constraints['null_or_not_channel__or'] = {
|
||||
'claim.signature_valid__is_null': True,
|
||||
'claim.channel_hash__not_in': not_channel_ids_binary
|
||||
}
|
||||
if 'signature_valid' in constraints:
|
||||
has_channel_signature = constraints.pop('has_channel_signature', False)
|
||||
if has_channel_signature:
|
||||
constraints['claim.signature_valid'] = constraints.pop('signature_valid')
|
||||
else:
|
||||
constraints['null_or_signature__or'] = {
|
||||
'claim.signature_valid__is_null': True,
|
||||
'claim.signature_valid': constraints.pop('signature_valid')
|
||||
}
|
||||
elif constraints.pop('has_channel_signature', False):
|
||||
constraints['claim.signature_valid__is_not_null'] = True
|
||||
|
||||
if 'txid' in constraints:
|
||||
tx_hash = unhexlify(constraints.pop('txid'))[::-1]
|
||||
nout = constraints.pop('nout', 0)
|
||||
constraints['claim.txo_hash'] = sqlite3.Binary(
|
||||
tx_hash + struct.pack('<I', nout)
|
||||
)
|
||||
|
||||
if 'claim_type' in constraints:
|
||||
constraints['claim.claim_type'] = CLAIM_TYPES[constraints.pop('claim_type')]
|
||||
if 'stream_types' in constraints:
|
||||
stream_types = constraints.pop('stream_types')
|
||||
if stream_types:
|
||||
constraints['claim.stream_type__in'] = [
|
||||
STREAM_TYPES[stream_type] for stream_type in stream_types
|
||||
]
|
||||
if 'media_types' in constraints:
|
||||
media_types = constraints.pop('media_types')
|
||||
if media_types:
|
||||
constraints['claim.media_type__in'] = media_types
|
||||
|
||||
if 'fee_currency' in constraints:
|
||||
constraints['claim.fee_currency'] = constraints.pop('fee_currency').lower()
|
||||
|
||||
_apply_constraints_for_array_attributes(constraints, 'tag', clean_tags, for_count)
|
||||
_apply_constraints_for_array_attributes(constraints, 'language', lambda _: _, for_count)
|
||||
_apply_constraints_for_array_attributes(constraints, 'location', lambda _: _, for_count)
|
||||
|
||||
select = f"SELECT {cols} FROM claim"
|
||||
|
||||
sql, values = query(
|
||||
select if for_count else select+"""
|
||||
LEFT JOIN claimtrie USING (claim_hash)
|
||||
LEFT JOIN claim as channel ON (claim.channel_hash=channel.claim_hash)
|
||||
""", **constraints
|
||||
)
|
||||
return sql, values
|
||||
|
||||
|
||||
def get_claims(cols, for_count=False, **constraints) -> List:
|
||||
if 'channel' in constraints:
|
||||
channel_url = constraints.pop('channel')
|
||||
match = resolve_url(channel_url)
|
||||
if isinstance(match, sqlite3.Row):
|
||||
constraints['channel_hash'] = match['claim_hash']
|
||||
else:
|
||||
return [[0]] if cols == 'count(*)' else []
|
||||
sql, values = _get_claims(cols, for_count, **constraints)
|
||||
return execute_query(sql, values)
|
||||
|
||||
|
||||
@measure
|
||||
def get_claims_count(**constraints) -> int:
|
||||
constraints.pop('offset', None)
|
||||
constraints.pop('limit', None)
|
||||
constraints.pop('order_by', None)
|
||||
count = get_claims('count(*)', for_count=True, **constraints)
|
||||
return count[0][0]
|
||||
|
||||
|
||||
@measure
|
||||
def search(constraints) -> Tuple[List, List, int, int]:
|
||||
assert set(constraints).issubset(SEARCH_PARAMS), \
|
||||
f"Search query contains invalid arguments: {set(constraints).difference(SEARCH_PARAMS)}"
|
||||
total = None
|
||||
if not constraints.pop('no_totals', False):
|
||||
total = get_claims_count(**constraints)
|
||||
constraints['offset'] = abs(constraints.get('offset', 0))
|
||||
constraints['limit'] = min(abs(constraints.get('limit', 10)), 50)
|
||||
if 'order_by' not in constraints:
|
||||
constraints['order_by'] = ["claim_hash"]
|
||||
txo_rows = _search(**constraints)
|
||||
channel_hashes = set(txo['channel_hash'] for txo in txo_rows if txo['channel_hash'])
|
||||
extra_txo_rows = []
|
||||
if channel_hashes:
|
||||
extra_txo_rows = _search(
|
||||
**{'claim.claim_hash__in': [sqlite3.Binary(h) for h in channel_hashes]}
|
||||
)
|
||||
return txo_rows, extra_txo_rows, constraints['offset'], total
|
||||
|
||||
|
||||
def _search(**constraints):
|
||||
return get_claims(
|
||||
"""
|
||||
claimtrie.claim_hash as is_controlling,
|
||||
claimtrie.last_take_over_height,
|
||||
claim.claim_hash, claim.txo_hash,
|
||||
claim.claims_in_channel,
|
||||
claim.height, claim.creation_height,
|
||||
claim.activation_height, claim.expiration_height,
|
||||
claim.effective_amount, claim.support_amount,
|
||||
claim.trending_group, claim.trending_mixed,
|
||||
claim.trending_local, claim.trending_global,
|
||||
claim.short_url, claim.canonical_url,
|
||||
claim.channel_hash, channel.txo_hash AS channel_txo_hash,
|
||||
channel.height AS channel_height, claim.signature_valid
|
||||
""", **constraints
|
||||
)
|
||||
|
||||
|
||||
@measure
|
||||
def resolve(urls) -> Tuple[List, List]:
|
||||
result = []
|
||||
channel_hashes = set()
|
||||
for raw_url in urls:
|
||||
match = resolve_url(raw_url)
|
||||
result.append(match)
|
||||
if isinstance(match, sqlite3.Row) and match['channel_hash']:
|
||||
channel_hashes.add(match['channel_hash'])
|
||||
extra_txo_rows = []
|
||||
if channel_hashes:
|
||||
extra_txo_rows = _search(
|
||||
**{'claim.claim_hash__in': [sqlite3.Binary(h) for h in channel_hashes]}
|
||||
)
|
||||
return result, extra_txo_rows
|
||||
|
||||
|
||||
@measure
|
||||
def resolve_url(raw_url):
|
||||
|
||||
try:
|
||||
url = URL.parse(raw_url)
|
||||
except ValueError as e:
|
||||
return e
|
||||
|
||||
channel = None
|
||||
|
||||
if url.has_channel:
|
||||
query = url.channel.to_dict()
|
||||
if set(query) == {'name'}:
|
||||
query['is_controlling'] = True
|
||||
else:
|
||||
query['order_by'] = ['^height']
|
||||
matches = _search(**query, limit=1)
|
||||
if matches:
|
||||
channel = matches[0]
|
||||
else:
|
||||
return LookupError(f'Could not find channel in "{raw_url}".')
|
||||
|
||||
if url.has_stream:
|
||||
query = url.stream.to_dict()
|
||||
if channel is not None:
|
||||
if set(query) == {'name'}:
|
||||
# temporarily emulate is_controlling for claims in channel
|
||||
query['order_by'] = ['effective_amount', '^height']
|
||||
else:
|
||||
query['order_by'] = ['^channel_join']
|
||||
query['channel_hash'] = channel['claim_hash']
|
||||
query['signature_valid'] = 1
|
||||
elif set(query) == {'name'}:
|
||||
query['is_controlling'] = 1
|
||||
matches = _search(**query, limit=1)
|
||||
if matches:
|
||||
return matches[0]
|
||||
else:
|
||||
return LookupError(f'Could not find stream in "{raw_url}".')
|
||||
|
||||
return channel
|
||||
|
||||
|
||||
def _apply_constraints_for_array_attributes(constraints, attr, cleaner, for_count=False):
|
||||
any_items = set(cleaner(constraints.pop(f'any_{attr}s', []))[:ATTRIBUTE_ARRAY_MAX_LENGTH])
|
||||
all_items = set(cleaner(constraints.pop(f'all_{attr}s', []))[:ATTRIBUTE_ARRAY_MAX_LENGTH])
|
||||
not_items = set(cleaner(constraints.pop(f'not_{attr}s', []))[:ATTRIBUTE_ARRAY_MAX_LENGTH])
|
||||
|
||||
all_items = {item for item in all_items if item not in not_items}
|
||||
any_items = {item for item in any_items if item not in not_items}
|
||||
|
||||
any_queries = {}
|
||||
|
||||
if attr == 'tag':
|
||||
common_tags = any_items & COMMON_TAGS.keys()
|
||||
if common_tags:
|
||||
any_items -= common_tags
|
||||
if len(common_tags) < 5:
|
||||
for item in common_tags:
|
||||
index_name = COMMON_TAGS[item]
|
||||
any_queries[f'#_common_tag_{index_name}'] = f"""
|
||||
EXISTS(
|
||||
SELECT 1 FROM tag INDEXED BY tag_{index_name}_idx WHERE claim.claim_hash=tag.claim_hash
|
||||
AND tag = '{item}'
|
||||
)
|
||||
"""
|
||||
elif len(common_tags) >= 5:
|
||||
constraints.update({
|
||||
f'$any_common_tag{i}': item for i, item in enumerate(common_tags)
|
||||
})
|
||||
values = ', '.join(
|
||||
f':$any_common_tag{i}' for i in range(len(common_tags))
|
||||
)
|
||||
any_queries[f'#_any_common_tags'] = f"""
|
||||
EXISTS(
|
||||
SELECT 1 FROM tag WHERE claim.claim_hash=tag.claim_hash
|
||||
AND tag IN ({values})
|
||||
)
|
||||
"""
|
||||
|
||||
if any_items:
|
||||
|
||||
constraints.update({
|
||||
f'$any_{attr}{i}': item for i, item in enumerate(any_items)
|
||||
})
|
||||
values = ', '.join(
|
||||
f':$any_{attr}{i}' for i in range(len(any_items))
|
||||
)
|
||||
if for_count or attr == 'tag':
|
||||
any_queries[f'claim.claim_hash__in#_any_{attr}'] = f"""
|
||||
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||
"""
|
||||
else:
|
||||
any_queries[f'#_any_{attr}'] = f"""
|
||||
EXISTS(
|
||||
SELECT 1 FROM {attr} WHERE
|
||||
claim.claim_hash={attr}.claim_hash
|
||||
AND {attr} IN ({values})
|
||||
)
|
||||
"""
|
||||
|
||||
if len(any_queries) == 1:
|
||||
constraints.update(any_queries)
|
||||
elif len(any_queries) > 1:
|
||||
constraints[f'ORed_{attr}_queries__any'] = any_queries
|
||||
|
||||
if all_items:
|
||||
constraints[f'$all_{attr}_count'] = len(all_items)
|
||||
constraints.update({
|
||||
f'$all_{attr}{i}': item for i, item in enumerate(all_items)
|
||||
})
|
||||
values = ', '.join(
|
||||
f':$all_{attr}{i}' for i in range(len(all_items))
|
||||
)
|
||||
if for_count:
|
||||
constraints[f'claim.claim_hash__in#_all_{attr}'] = f"""
|
||||
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||
GROUP BY claim_hash HAVING COUNT({attr}) = :$all_{attr}_count
|
||||
"""
|
||||
else:
|
||||
constraints[f'#_all_{attr}'] = f"""
|
||||
{len(all_items)}=(
|
||||
SELECT count(*) FROM {attr} WHERE
|
||||
claim.claim_hash={attr}.claim_hash
|
||||
AND {attr} IN ({values})
|
||||
)
|
||||
"""
|
||||
|
||||
if not_items:
|
||||
constraints.update({
|
||||
f'$not_{attr}{i}': item for i, item in enumerate(not_items)
|
||||
})
|
||||
values = ', '.join(
|
||||
f':$not_{attr}{i}' for i in range(len(not_items))
|
||||
)
|
||||
if for_count:
|
||||
constraints[f'claim.claim_hash__not_in#_not_{attr}'] = f"""
|
||||
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||
"""
|
||||
else:
|
||||
constraints[f'#_not_{attr}'] = f"""
|
||||
NOT EXISTS(
|
||||
SELECT 1 FROM {attr} WHERE
|
||||
claim.claim_hash={attr}.claim_hash
|
||||
AND {attr} IN ({values})
|
||||
)
|
||||
"""
|
||||
@@ -61,7 +61,7 @@ def calculate_trending(db, height, is_first_sync, final_height):
|
||||
|
||||
start = (height-TRENDING_WINDOW)+1
|
||||
db.execute(f"""
|
||||
INSERT INTO trend (claim_hash, height, amount)
|
||||
INSERT OR IGNORE INTO trend (claim_hash, height, amount)
|
||||
SELECT claim_hash, {start}, COALESCE(
|
||||
(SELECT SUM(amount) FROM support WHERE claim_hash=claim.claim_hash
|
||||
AND height >= {start}), 0
|
||||
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
import sqlite3
|
||||
import struct
|
||||
from typing import Union, Tuple, Set, List
|
||||
from binascii import unhexlify
|
||||
from itertools import chain
|
||||
from decimal import Decimal
|
||||
|
||||
@@ -9,70 +8,19 @@ from torba.server.db import DB
|
||||
from torba.server.util import class_logger
|
||||
from torba.client.basedatabase import query, constraints_to_sql
|
||||
|
||||
from lbry.schema.url import URL, normalize_name
|
||||
from lbry.schema.tags import clean_tags
|
||||
from lbry.schema.mime_types import guess_stream_type
|
||||
from lbry.wallet.ledger import MainNetLedger, RegTestLedger
|
||||
from lbry.wallet.transaction import Transaction, Output
|
||||
from lbry.wallet.server.canonical import register_canonical_functions
|
||||
from lbry.wallet.server.trending import (
|
||||
from lbry.wallet.server.db.canonical import register_canonical_functions
|
||||
from lbry.wallet.server.db.trending import (
|
||||
CREATE_TREND_TABLE, calculate_trending, register_trending_functions
|
||||
)
|
||||
|
||||
from .common import CLAIM_TYPES, STREAM_TYPES, COMMON_TAGS
|
||||
|
||||
|
||||
ATTRIBUTE_ARRAY_MAX_LENGTH = 100
|
||||
CLAIM_TYPES = {
|
||||
'stream': 1,
|
||||
'channel': 2,
|
||||
}
|
||||
STREAM_TYPES = {
|
||||
'video': 1,
|
||||
'audio': 2,
|
||||
'image': 3,
|
||||
'document': 4,
|
||||
'binary': 5,
|
||||
'model': 6
|
||||
}
|
||||
|
||||
|
||||
def _apply_constraints_for_array_attributes(constraints, attr, cleaner):
|
||||
any_items = cleaner(constraints.pop(f'any_{attr}s', []))[:ATTRIBUTE_ARRAY_MAX_LENGTH]
|
||||
if any_items:
|
||||
constraints.update({
|
||||
f'$any_{attr}{i}': item for i, item in enumerate(any_items)
|
||||
})
|
||||
values = ', '.join(
|
||||
f':$any_{attr}{i}' for i in range(len(any_items))
|
||||
)
|
||||
constraints[f'claim.claim_hash__in#_any_{attr}'] = f"""
|
||||
SELECT DISTINCT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||
"""
|
||||
|
||||
all_items = cleaner(constraints.pop(f'all_{attr}s', []))[:ATTRIBUTE_ARRAY_MAX_LENGTH]
|
||||
if all_items:
|
||||
constraints[f'$all_{attr}_count'] = len(all_items)
|
||||
constraints.update({
|
||||
f'$all_{attr}{i}': item for i, item in enumerate(all_items)
|
||||
})
|
||||
values = ', '.join(
|
||||
f':$all_{attr}{i}' for i in range(len(all_items))
|
||||
)
|
||||
constraints[f'claim.claim_hash__in#_all_{attr}'] = f"""
|
||||
SELECT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||
GROUP BY claim_hash HAVING COUNT({attr}) = :$all_{attr}_count
|
||||
"""
|
||||
|
||||
not_items = cleaner(constraints.pop(f'not_{attr}s', []))[:ATTRIBUTE_ARRAY_MAX_LENGTH]
|
||||
if not_items:
|
||||
constraints.update({
|
||||
f'$not_{attr}{i}': item for i, item in enumerate(not_items)
|
||||
})
|
||||
values = ', '.join(
|
||||
f':$not_{attr}{i}' for i in range(len(not_items))
|
||||
)
|
||||
constraints[f'claim.claim_hash__not_in#_not_{attr}'] = f"""
|
||||
SELECT DISTINCT claim_hash FROM {attr} WHERE {attr} IN ({values})
|
||||
"""
|
||||
|
||||
|
||||
class SQLDB:
|
||||
@@ -129,33 +77,12 @@ class SQLDB:
|
||||
trending_global integer not null default 0
|
||||
);
|
||||
|
||||
create index if not exists claim_resolve_idx on claim (normalized, claim_id);
|
||||
create index if not exists claim_normalized_idx on claim (normalized, activation_height);
|
||||
create index if not exists claim_channel_hash_idx on claim (channel_hash, signature, claim_hash);
|
||||
create index if not exists claim_claims_in_channel_idx on claim (signature_valid, channel_hash, normalized);
|
||||
|
||||
create index if not exists claim_id_idx on claim (claim_id);
|
||||
create index if not exists claim_normalized_idx on claim (normalized);
|
||||
create index if not exists claim_txo_hash_idx on claim (txo_hash);
|
||||
create index if not exists claim_channel_hash_idx on claim (channel_hash);
|
||||
create index if not exists claim_release_time_idx on claim (release_time);
|
||||
create index if not exists claim_timestamp_idx on claim (timestamp);
|
||||
create index if not exists claim_height_idx on claim (height);
|
||||
create index if not exists claim_activation_height_idx on claim (activation_height);
|
||||
create index if not exists claim_activation_height_idx on claim (activation_height, claim_hash);
|
||||
create index if not exists claim_expiration_height_idx on claim (expiration_height);
|
||||
create index if not exists claim_public_key_hash_idx on claim (public_key_hash);
|
||||
|
||||
create index if not exists claim_claim_type_idx on claim (claim_type);
|
||||
create index if not exists claim_stream_type_idx on claim (stream_type);
|
||||
create index if not exists claim_media_type_idx on claim (media_type);
|
||||
create index if not exists claim_fee_amount_idx on claim (fee_amount);
|
||||
create index if not exists claim_fee_currency_idx on claim (fee_currency);
|
||||
|
||||
create index if not exists claim_signature_valid_idx on claim (signature_valid);
|
||||
|
||||
create index if not exists claim_effective_amount_idx on claim (effective_amount);
|
||||
create index if not exists claim_trending_group_idx on claim (trending_group);
|
||||
create index if not exists claim_trending_mixed_idx on claim (trending_mixed);
|
||||
create index if not exists claim_trending_local_idx on claim (trending_local);
|
||||
create index if not exists claim_trending_global_idx on claim (trending_global);
|
||||
"""
|
||||
|
||||
CREATE_SUPPORT_TABLE = """
|
||||
@@ -166,7 +93,6 @@ class SQLDB:
|
||||
claim_hash bytes not null,
|
||||
amount integer not null
|
||||
);
|
||||
create index if not exists support_txo_hash_idx on support (txo_hash);
|
||||
create index if not exists support_claim_hash_idx on support (claim_hash, height);
|
||||
"""
|
||||
|
||||
@@ -176,9 +102,7 @@ class SQLDB:
|
||||
claim_hash bytes not null,
|
||||
height integer not null
|
||||
);
|
||||
create index if not exists tag_tag_idx on tag (tag);
|
||||
create index if not exists tag_claim_hash_idx on tag (claim_hash);
|
||||
create index if not exists tag_height_idx on tag (height);
|
||||
create unique index if not exists tag_claim_hash_tag_idx on tag (claim_hash, tag);
|
||||
"""
|
||||
|
||||
CREATE_CLAIMTRIE_TABLE = """
|
||||
@@ -190,6 +114,38 @@ class SQLDB:
|
||||
create index if not exists claimtrie_claim_hash_idx on claimtrie (claim_hash);
|
||||
"""
|
||||
|
||||
SEARCH_INDEXES = """
|
||||
-- used by any tag clouds
|
||||
create index if not exists tag_tag_idx on tag (tag, claim_hash);
|
||||
|
||||
-- common ORDER BY
|
||||
create unique index if not exists claim_effective_amount_idx on claim (effective_amount, claim_hash, release_time);
|
||||
create unique index if not exists claim_release_time_idx on claim (release_time, claim_hash);
|
||||
create unique index if not exists claim_trending_global_mixed_idx on claim (trending_global, trending_mixed, claim_hash);
|
||||
create unique index if not exists filter_fee_amount_order_release_time_idx on claim (fee_amount, release_time, claim_hash);
|
||||
|
||||
create unique index if not exists claim_type_trending_idx on claim (claim_type, trending_global, trending_mixed, claim_hash);
|
||||
|
||||
-- TODO: verify that all indexes below are used
|
||||
create index if not exists claim_height_normalized_idx on claim (height, normalized asc);
|
||||
|
||||
create index if not exists claim_resolve_idx on claim (normalized, claim_id);
|
||||
|
||||
create index if not exists claim_id_idx on claim (claim_id, claim_hash);
|
||||
create index if not exists claim_timestamp_idx on claim (timestamp);
|
||||
create index if not exists claim_public_key_hash_idx on claim (public_key_hash);
|
||||
|
||||
create index if not exists claim_stream_type_idx on claim (stream_type);
|
||||
create index if not exists claim_media_type_idx on claim (media_type);
|
||||
|
||||
create index if not exists claim_signature_valid_idx on claim (signature_valid);
|
||||
"""
|
||||
|
||||
TAG_INDEXES = '\n'.join(
|
||||
f"create unique index if not exists tag_{tag_key}_idx on tag (tag, claim_hash) WHERE tag='{tag_value}';"
|
||||
for tag_value, tag_key in COMMON_TAGS.items()
|
||||
)
|
||||
|
||||
CREATE_TABLES_QUERY = (
|
||||
PRAGMAS +
|
||||
CREATE_CLAIM_TABLE +
|
||||
@@ -207,7 +163,7 @@ class SQLDB:
|
||||
self.ledger = MainNetLedger if self.main.coin.NET == 'mainnet' else RegTestLedger
|
||||
|
||||
def open(self):
|
||||
self.db = sqlite3.connect(self._db_path, isolation_level=None, check_same_thread=False)
|
||||
self.db = sqlite3.connect(self._db_path, isolation_level=None, check_same_thread=False, uri=True)
|
||||
self.db.row_factory = sqlite3.Row
|
||||
self.db.executescript(self.CREATE_TABLES_QUERY)
|
||||
register_canonical_functions(self.db)
|
||||
@@ -253,7 +209,7 @@ class SQLDB:
|
||||
self.execute('commit;')
|
||||
|
||||
def _upsertable_claims(self, txos: List[Output], header, clear_first=False):
|
||||
claim_hashes, claims, tags = [], [], []
|
||||
claim_hashes, claims, tags = [], [], {}
|
||||
for txo in txos:
|
||||
tx = txo.tx_ref.tx
|
||||
|
||||
@@ -298,20 +254,23 @@ class SQLDB:
|
||||
if claim.stream.release_time:
|
||||
claim_record['release_time'] = claim.stream.release_time
|
||||
if claim.stream.has_fee:
|
||||
claim_record['fee_currency'] = claim.stream.fee.currency.lower()
|
||||
claim_record['fee_amount'] = int(claim.stream.fee.amount*1000)
|
||||
fee = claim.stream.fee
|
||||
if isinstance(fee.currency, str):
|
||||
claim_record['fee_currency'] = fee.currency.lower()
|
||||
if isinstance(fee.amount, Decimal):
|
||||
claim_record['fee_amount'] = int(fee.amount*1000)
|
||||
elif claim.is_channel:
|
||||
claim_record['claim_type'] = CLAIM_TYPES['channel']
|
||||
|
||||
for tag in clean_tags(claim.message.tags):
|
||||
tags.append((tag, claim_hash, tx.height))
|
||||
tags[(tag, claim_hash)] = (tag, claim_hash, tx.height)
|
||||
|
||||
if clear_first:
|
||||
self._clear_claim_metadata(claim_hashes)
|
||||
|
||||
if tags:
|
||||
self.db.executemany(
|
||||
"INSERT INTO tag (tag, claim_hash, height) VALUES (?, ?, ?)", tags
|
||||
"INSERT OR IGNORE INTO tag (tag, claim_hash, height) VALUES (?, ?, ?)", tags.values()
|
||||
)
|
||||
|
||||
return claims
|
||||
@@ -742,265 +701,13 @@ class SQLDB:
|
||||
r(self.update_claimtrie, height, recalculate_claim_hashes, deleted_claim_names, forward_timer=True)
|
||||
r(calculate_trending, self.db, height, self.main.first_sync, daemon_height)
|
||||
|
||||
def get_claims(self, cols, join=True, **constraints):
|
||||
if 'order_by' in constraints:
|
||||
sql_order_by = []
|
||||
for order_by in constraints['order_by']:
|
||||
is_asc = order_by.startswith('^')
|
||||
column = order_by[1:] if is_asc else order_by
|
||||
if column not in self.ORDER_FIELDS:
|
||||
raise NameError(f'{column} is not a valid order_by field')
|
||||
if column == 'name':
|
||||
column = 'normalized'
|
||||
sql_order_by.append(
|
||||
f"claim.{column} ASC" if is_asc else f"claim.{column} DESC"
|
||||
)
|
||||
constraints['order_by'] = sql_order_by
|
||||
|
||||
ops = {'<=': '__lte', '>=': '__gte', '<': '__lt', '>': '__gt'}
|
||||
for constraint in self.INTEGER_PARAMS:
|
||||
if constraint in constraints:
|
||||
value = constraints.pop(constraint)
|
||||
postfix = ''
|
||||
if isinstance(value, str):
|
||||
if len(value) >= 2 and value[:2] in ops:
|
||||
postfix, value = ops[value[:2]], value[2:]
|
||||
elif len(value) >= 1 and value[0] in ops:
|
||||
postfix, value = ops[value[0]], value[1:]
|
||||
if constraint == 'fee_amount':
|
||||
value = Decimal(value)*1000
|
||||
constraints[f'claim.{constraint}{postfix}'] = int(value)
|
||||
|
||||
if constraints.pop('is_controlling', False):
|
||||
if {'sequence', 'amount_order'}.isdisjoint(constraints):
|
||||
join = True
|
||||
constraints['claimtrie.claim_hash__is_not_null'] = ''
|
||||
if 'sequence' in constraints:
|
||||
constraints['order_by'] = 'claim.activation_height ASC'
|
||||
constraints['offset'] = int(constraints.pop('sequence')) - 1
|
||||
constraints['limit'] = 1
|
||||
if 'amount_order' in constraints:
|
||||
constraints['order_by'] = 'claim.effective_amount DESC'
|
||||
constraints['offset'] = int(constraints.pop('amount_order')) - 1
|
||||
constraints['limit'] = 1
|
||||
|
||||
if 'claim_id' in constraints:
|
||||
claim_id = constraints.pop('claim_id')
|
||||
if len(claim_id) == 40:
|
||||
constraints['claim.claim_id'] = claim_id
|
||||
else:
|
||||
constraints['claim.claim_id__like'] = f'{claim_id[:40]}%'
|
||||
|
||||
if 'name' in constraints:
|
||||
constraints['claim.normalized'] = normalize_name(constraints.pop('name'))
|
||||
|
||||
if 'public_key_id' in constraints:
|
||||
constraints['claim.public_key_hash'] = sqlite3.Binary(
|
||||
self.ledger.address_to_hash160(constraints.pop('public_key_id')))
|
||||
|
||||
if 'channel' in constraints:
|
||||
channel_url = constraints.pop('channel')
|
||||
match = self._resolve_one(channel_url)
|
||||
if isinstance(match, sqlite3.Row):
|
||||
constraints['channel_hash'] = match['claim_hash']
|
||||
else:
|
||||
return [[0]] if cols == 'count(*)' else []
|
||||
if 'channel_hash' in constraints:
|
||||
constraints['claim.channel_hash'] = sqlite3.Binary(constraints.pop('channel_hash'))
|
||||
if 'channel_ids' in constraints:
|
||||
channel_ids = constraints.pop('channel_ids')
|
||||
if channel_ids:
|
||||
constraints['claim.channel_hash__in'] = [
|
||||
sqlite3.Binary(unhexlify(cid)[::-1]) for cid in channel_ids
|
||||
]
|
||||
if 'not_channel_ids' in constraints:
|
||||
not_channel_ids = constraints.pop('not_channel_ids')
|
||||
if not_channel_ids:
|
||||
not_channel_ids_binary = [
|
||||
sqlite3.Binary(unhexlify(ncid)[::-1]) for ncid in not_channel_ids
|
||||
]
|
||||
if constraints.get('has_channel_signature', False):
|
||||
constraints['claim.channel_hash__not_in'] = not_channel_ids_binary
|
||||
else:
|
||||
constraints['null_or_not_channel__or'] = {
|
||||
'claim.signature_valid__is_null': True,
|
||||
'claim.channel_hash__not_in': not_channel_ids_binary
|
||||
}
|
||||
if 'signature_valid' in constraints:
|
||||
has_channel_signature = constraints.pop('has_channel_signature', False)
|
||||
if has_channel_signature:
|
||||
constraints['claim.signature_valid'] = constraints.pop('signature_valid')
|
||||
else:
|
||||
constraints['null_or_signature__or'] = {
|
||||
'claim.signature_valid__is_null': True,
|
||||
'claim.signature_valid': constraints.pop('signature_valid')
|
||||
}
|
||||
elif 'has_channel_signature' in constraints:
|
||||
constraints['claim.signature_valid__is_not_null'] = constraints.pop('has_channel_signature')
|
||||
|
||||
if 'txid' in constraints:
|
||||
tx_hash = unhexlify(constraints.pop('txid'))[::-1]
|
||||
nout = constraints.pop('nout', 0)
|
||||
constraints['claim.txo_hash'] = sqlite3.Binary(
|
||||
tx_hash + struct.pack('<I', nout)
|
||||
)
|
||||
|
||||
if 'claim_type' in constraints:
|
||||
constraints['claim.claim_type'] = CLAIM_TYPES[constraints.pop('claim_type')]
|
||||
if 'stream_types' in constraints:
|
||||
stream_types = constraints.pop('stream_types')
|
||||
if stream_types:
|
||||
constraints['claim.stream_type__in'] = [
|
||||
STREAM_TYPES[stream_type] for stream_type in stream_types
|
||||
]
|
||||
if 'media_types' in constraints:
|
||||
media_types = constraints.pop('media_types')
|
||||
if media_types:
|
||||
constraints['claim.media_type__in'] = media_types
|
||||
|
||||
if 'fee_currency' in constraints:
|
||||
constraints['claim.fee_currency'] = constraints.pop('fee_currency').lower()
|
||||
|
||||
_apply_constraints_for_array_attributes(constraints, 'tag', clean_tags)
|
||||
_apply_constraints_for_array_attributes(constraints, 'language', lambda _: _)
|
||||
_apply_constraints_for_array_attributes(constraints, 'location', lambda _: _)
|
||||
|
||||
select = f"SELECT {cols} FROM claim"
|
||||
|
||||
sql, values = query(
|
||||
select if not join else select+"""
|
||||
LEFT JOIN claimtrie USING (claim_hash)
|
||||
LEFT JOIN claim as channel ON (claim.channel_hash=channel.claim_hash)
|
||||
""", **constraints
|
||||
)
|
||||
try:
|
||||
return self.db.execute(sql, values).fetchall()
|
||||
except:
|
||||
self.logger.exception(f'Failed to execute claim search query: {sql}')
|
||||
raise
|
||||
|
||||
def get_claims_count(self, **constraints):
|
||||
constraints.pop('offset', None)
|
||||
constraints.pop('limit', None)
|
||||
constraints.pop('order_by', None)
|
||||
count = self.get_claims('count(*)', join=False, **constraints)
|
||||
return count[0][0]
|
||||
|
||||
def _search(self, **constraints):
|
||||
return self.get_claims(
|
||||
"""
|
||||
claimtrie.claim_hash as is_controlling,
|
||||
claimtrie.last_take_over_height,
|
||||
claim.claim_hash, claim.txo_hash,
|
||||
claim.claims_in_channel,
|
||||
claim.height, claim.creation_height,
|
||||
claim.activation_height, claim.expiration_height,
|
||||
claim.effective_amount, claim.support_amount,
|
||||
claim.trending_group, claim.trending_mixed,
|
||||
claim.trending_local, claim.trending_global,
|
||||
claim.short_url, claim.canonical_url,
|
||||
claim.channel_hash, channel.txo_hash AS channel_txo_hash,
|
||||
channel.height AS channel_height, claim.signature_valid
|
||||
""", **constraints
|
||||
)
|
||||
|
||||
INTEGER_PARAMS = {
|
||||
'height', 'creation_height', 'activation_height', 'expiration_height',
|
||||
'timestamp', 'creation_timestamp', 'release_time', 'fee_amount',
|
||||
'tx_position', 'channel_join',
|
||||
'amount', 'effective_amount', 'support_amount',
|
||||
'trending_group', 'trending_mixed',
|
||||
'trending_local', 'trending_global',
|
||||
}
|
||||
|
||||
SEARCH_PARAMS = {
|
||||
'name', 'claim_id', 'txid', 'nout', 'channel', 'channel_ids', 'not_channel_ids',
|
||||
'public_key_id', 'claim_type', 'stream_types', 'media_types', 'fee_currency',
|
||||
'has_channel_signature', 'signature_valid',
|
||||
'any_tags', 'all_tags', 'not_tags',
|
||||
'any_locations', 'all_locations', 'not_locations',
|
||||
'any_languages', 'all_languages', 'not_languages',
|
||||
'is_controlling', 'limit', 'offset', 'order_by'
|
||||
} | INTEGER_PARAMS
|
||||
|
||||
ORDER_FIELDS = {
|
||||
'name',
|
||||
} | INTEGER_PARAMS
|
||||
|
||||
def search(self, constraints) -> Tuple[List, List, int, int]:
|
||||
assert set(constraints).issubset(self.SEARCH_PARAMS), \
|
||||
f"Search query contains invalid arguments: {set(constraints).difference(self.SEARCH_PARAMS)}"
|
||||
total = self.get_claims_count(**constraints)
|
||||
constraints['offset'] = abs(constraints.get('offset', 0))
|
||||
constraints['limit'] = min(abs(constraints.get('limit', 10)), 50)
|
||||
if 'order_by' not in constraints:
|
||||
constraints['order_by'] = ["height", "^name"]
|
||||
txo_rows = self._search(**constraints)
|
||||
channel_hashes = set(txo['channel_hash'] for txo in txo_rows if txo['channel_hash'])
|
||||
extra_txo_rows = []
|
||||
if channel_hashes:
|
||||
extra_txo_rows = self._search(**{'claim.claim_hash__in': [sqlite3.Binary(h) for h in channel_hashes]})
|
||||
return txo_rows, extra_txo_rows, constraints['offset'], total
|
||||
|
||||
def _resolve_one(self, raw_url):
|
||||
try:
|
||||
url = URL.parse(raw_url)
|
||||
except ValueError as e:
|
||||
return e
|
||||
|
||||
channel = None
|
||||
|
||||
if url.has_channel:
|
||||
query = url.channel.to_dict()
|
||||
if set(query) == {'name'}:
|
||||
query['is_controlling'] = True
|
||||
else:
|
||||
query['order_by'] = ['^height']
|
||||
matches = self._search(**query, limit=1)
|
||||
if matches:
|
||||
channel = matches[0]
|
||||
else:
|
||||
return LookupError(f'Could not find channel in "{raw_url}".')
|
||||
|
||||
if url.has_stream:
|
||||
query = url.stream.to_dict()
|
||||
if channel is not None:
|
||||
if set(query) == {'name'}:
|
||||
# temporarily emulate is_controlling for claims in channel
|
||||
query['order_by'] = ['effective_amount']
|
||||
else:
|
||||
query['order_by'] = ['^channel_join']
|
||||
query['channel_hash'] = channel['claim_hash']
|
||||
query['signature_valid'] = 1
|
||||
elif set(query) == {'name'}:
|
||||
query['is_controlling'] = 1
|
||||
matches = self._search(**query, limit=1)
|
||||
if matches:
|
||||
return matches[0]
|
||||
else:
|
||||
return LookupError(f'Could not find stream in "{raw_url}".')
|
||||
|
||||
return channel
|
||||
|
||||
def resolve(self, urls) -> Tuple[List, List]:
|
||||
result = []
|
||||
channel_hashes = set()
|
||||
for raw_url in urls:
|
||||
match = self._resolve_one(raw_url)
|
||||
result.append(match)
|
||||
if isinstance(match, sqlite3.Row) and match['channel_hash']:
|
||||
channel_hashes.add(match['channel_hash'])
|
||||
extra_txo_rows = []
|
||||
if channel_hashes:
|
||||
extra_txo_rows = self._search(**{'claim.claim_hash__in': [sqlite3.Binary(h) for h in channel_hashes]})
|
||||
return result, extra_txo_rows
|
||||
|
||||
|
||||
class LBRYDB(DB):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.sql = SQLDB(self, 'claims.db')
|
||||
path = os.path.join(self.env.db_dir, 'claims.db')
|
||||
self.sql = SQLDB(self, path)
|
||||
|
||||
def close(self):
|
||||
super().close()
|
||||
@@ -0,0 +1,135 @@
|
||||
import time
|
||||
import math
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
def calculate_elapsed(start) -> int:
|
||||
return int((time.perf_counter() - start) * 1000)
|
||||
|
||||
|
||||
def calculate_avg_percentiles(data) -> Tuple[int, int, int, int, int, int, int, int]:
|
||||
if not data:
|
||||
return 0, 0, 0, 0, 0, 0, 0, 0
|
||||
data.sort()
|
||||
size = len(data)
|
||||
return (
|
||||
int(sum(data) / size),
|
||||
data[0],
|
||||
data[math.ceil(size * .05) - 1],
|
||||
data[math.ceil(size * .25) - 1],
|
||||
data[math.ceil(size * .50) - 1],
|
||||
data[math.ceil(size * .75) - 1],
|
||||
data[math.ceil(size * .95) - 1],
|
||||
data[-1]
|
||||
)
|
||||
|
||||
|
||||
def remove_select_list(sql) -> str:
|
||||
return sql[sql.index('FROM'):]
|
||||
|
||||
|
||||
class APICallMetrics:
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
# total requests received
|
||||
self.receive_count = 0
|
||||
self.cache_response_count = 0
|
||||
|
||||
# millisecond timings for query based responses
|
||||
self.query_response_times = []
|
||||
self.query_intrp_times = []
|
||||
self.query_error_times = []
|
||||
|
||||
self.query_python_times = []
|
||||
self.query_wait_times = []
|
||||
self.query_sql_times = [] # aggregate total of multiple SQL calls made per request
|
||||
|
||||
self.individual_sql_times = [] # every SQL query run on server
|
||||
|
||||
# actual queries
|
||||
self.errored_queries = set()
|
||||
self.interrupted_queries = set()
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
# total requests received
|
||||
"receive_count": self.receive_count,
|
||||
# sum of these is total responses made
|
||||
"cache_response_count": self.cache_response_count,
|
||||
"query_response_count": len(self.query_response_times),
|
||||
"intrp_response_count": len(self.query_intrp_times),
|
||||
"error_response_count": len(self.query_error_times),
|
||||
# millisecond timings for non-cache responses
|
||||
"response": calculate_avg_percentiles(self.query_response_times),
|
||||
"interrupt": calculate_avg_percentiles(self.query_intrp_times),
|
||||
"error": calculate_avg_percentiles(self.query_error_times),
|
||||
# response, interrupt and error each also report the python, wait and sql stats:
|
||||
"python": calculate_avg_percentiles(self.query_python_times),
|
||||
"wait": calculate_avg_percentiles(self.query_wait_times),
|
||||
"sql": calculate_avg_percentiles(self.query_sql_times),
|
||||
# extended timings for individual sql executions
|
||||
"individual_sql": calculate_avg_percentiles(self.individual_sql_times),
|
||||
"individual_sql_count": len(self.individual_sql_times),
|
||||
# actual queries
|
||||
"errored_queries": list(self.errored_queries),
|
||||
"interrupted_queries": list(self.interrupted_queries),
|
||||
}
|
||||
|
||||
def start(self):
|
||||
self.receive_count += 1
|
||||
|
||||
def cache_response(self):
|
||||
self.cache_response_count += 1
|
||||
|
||||
def _add_query_timings(self, request_total_time, metrics):
|
||||
if metrics and 'execute_query' in metrics:
|
||||
sub_process_total = metrics[self.name][0]['total']
|
||||
individual_query_times = [f['total'] for f in metrics['execute_query']]
|
||||
aggregated_query_time = sum(individual_query_times)
|
||||
self.individual_sql_times.extend(individual_query_times)
|
||||
self.query_sql_times.append(aggregated_query_time)
|
||||
self.query_python_times.append(sub_process_total - aggregated_query_time)
|
||||
self.query_wait_times.append(request_total_time - sub_process_total)
|
||||
|
||||
@staticmethod
|
||||
def _add_queries(query_set, metrics):
|
||||
if metrics and 'execute_query' in metrics:
|
||||
for execute_query in metrics['execute_query']:
|
||||
if 'sql' in execute_query:
|
||||
query_set.add(remove_select_list(execute_query['sql']))
|
||||
|
||||
def query_response(self, start, metrics):
|
||||
self.query_response_times.append(calculate_elapsed(start))
|
||||
self._add_query_timings(self.query_response_times[-1], metrics)
|
||||
|
||||
def query_interrupt(self, start, metrics):
|
||||
self.query_intrp_times.append(calculate_elapsed(start))
|
||||
self._add_queries(self.interrupted_queries, metrics)
|
||||
self._add_query_timings(self.query_intrp_times[-1], metrics)
|
||||
|
||||
def query_error(self, start, metrics):
|
||||
self.query_error_times.append(calculate_elapsed(start))
|
||||
self._add_queries(self.errored_queries, metrics)
|
||||
self._add_query_timings(self.query_error_times[-1], metrics)
|
||||
|
||||
|
||||
class ServerLoadData:
|
||||
|
||||
def __init__(self):
|
||||
self._apis = {}
|
||||
|
||||
def for_api(self, name) -> APICallMetrics:
|
||||
if name not in self._apis:
|
||||
self._apis[name] = APICallMetrics(name)
|
||||
return self._apis[name]
|
||||
|
||||
def to_json_and_reset(self, status):
|
||||
try:
|
||||
return {
|
||||
'api': {name: api.to_json() for name, api in self._apis.items()},
|
||||
'status': status
|
||||
}
|
||||
finally:
|
||||
self._apis = {}
|
||||
+150
-225
@@ -1,21 +1,99 @@
|
||||
import os
|
||||
import math
|
||||
import unicodedata as uda
|
||||
from binascii import unhexlify, hexlify
|
||||
import time
|
||||
import base64
|
||||
import asyncio
|
||||
from binascii import hexlify
|
||||
from pylru import lrucache
|
||||
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
||||
|
||||
from torba.rpc.jsonrpc import RPCError
|
||||
from torba.server.hash import hash_to_hex_str
|
||||
from torba.server.session import ElectrumX
|
||||
from torba.rpc.jsonrpc import RPCError, JSONRPC
|
||||
from torba.server.session import ElectrumX, SessionManager
|
||||
from torba.server import util
|
||||
|
||||
from lbry.schema.result import Outputs
|
||||
from lbry.schema.url import URL
|
||||
from lbry.wallet.server.block_processor import LBRYBlockProcessor
|
||||
from lbry.wallet.server.db import LBRYDB
|
||||
from lbry.wallet.server.db.writer import LBRYDB
|
||||
from lbry.wallet.server.db import reader
|
||||
from lbry.wallet.server.websocket import AdminWebSocket
|
||||
from lbry.wallet.server.metrics import ServerLoadData, APICallMetrics
|
||||
|
||||
|
||||
class ResultCacheItem:
|
||||
__slots__ = '_result', 'lock', 'has_result'
|
||||
|
||||
def __init__(self):
|
||||
self.has_result = asyncio.Event()
|
||||
self.lock = asyncio.Lock()
|
||||
self._result = None
|
||||
|
||||
@property
|
||||
def result(self) -> str:
|
||||
return self._result
|
||||
|
||||
@result.setter
|
||||
def result(self, result: str):
|
||||
self._result = result
|
||||
if result is not None:
|
||||
self.has_result.set()
|
||||
|
||||
|
||||
class LBRYSessionManager(SessionManager):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.query_executor = None
|
||||
self.websocket = None
|
||||
self.metrics = ServerLoadData()
|
||||
self.metrics_loop = None
|
||||
self.running = False
|
||||
if self.env.websocket_host is not None and self.env.websocket_port is not None:
|
||||
self.websocket = AdminWebSocket(self)
|
||||
self.search_cache = self.bp.search_cache
|
||||
self.search_cache['search'] = lrucache(10000)
|
||||
self.search_cache['resolve'] = lrucache(10000)
|
||||
|
||||
async def process_metrics(self):
|
||||
while self.running:
|
||||
data = self.metrics.to_json_and_reset({
|
||||
'sessions': self.session_count(),
|
||||
'height': self.db.db_height,
|
||||
})
|
||||
if self.websocket is not None:
|
||||
self.websocket.send_message(data)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
async def start_other(self):
|
||||
self.running = True
|
||||
path = os.path.join(self.env.db_dir, 'claims.db')
|
||||
args = dict(
|
||||
initializer=reader.initializer,
|
||||
initargs=(self.logger, path, self.env.coin.NET, self.env.database_query_timeout,
|
||||
self.env.track_metrics)
|
||||
)
|
||||
if self.env.max_query_workers is not None and self.env.max_query_workers == 0:
|
||||
self.query_executor = ThreadPoolExecutor(max_workers=1, **args)
|
||||
else:
|
||||
self.query_executor = ProcessPoolExecutor(
|
||||
max_workers=self.env.max_query_workers or max(os.cpu_count(), 4), **args
|
||||
)
|
||||
if self.websocket is not None:
|
||||
await self.websocket.start()
|
||||
if self.env.track_metrics:
|
||||
self.metrics_loop = asyncio.create_task(self.process_metrics())
|
||||
|
||||
async def stop_other(self):
|
||||
self.running = False
|
||||
if self.env.track_metrics:
|
||||
self.metrics_loop.cancel()
|
||||
if self.websocket is not None:
|
||||
await self.websocket.stop()
|
||||
self.query_executor.shutdown()
|
||||
|
||||
|
||||
class LBRYElectrumX(ElectrumX):
|
||||
PROTOCOL_MIN = (0, 0) # temporary, for supporting 0.10 protocol
|
||||
max_errors = math.inf # don't disconnect people for errors! let them happen...
|
||||
session_mgr: LBRYSessionManager
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -30,28 +108,75 @@ class LBRYElectrumX(ElectrumX):
|
||||
'blockchain.transaction.get_height': self.transaction_get_height,
|
||||
'blockchain.claimtrie.search': self.claimtrie_search,
|
||||
'blockchain.claimtrie.resolve': self.claimtrie_resolve,
|
||||
'blockchain.claimtrie.getclaimbyid': self.claimtrie_getclaimbyid,
|
||||
'blockchain.claimtrie.getclaimsforname': self.claimtrie_getclaimsforname,
|
||||
'blockchain.claimtrie.getclaimsbyids': self.claimtrie_getclaimsbyids,
|
||||
'blockchain.claimtrie.getvalue': self.claimtrie_getvalue,
|
||||
'blockchain.claimtrie.getnthclaimforname': self.claimtrie_getnthclaimforname,
|
||||
'blockchain.claimtrie.getclaimsintx': self.claimtrie_getclaimsintx,
|
||||
'blockchain.claimtrie.getclaimssignedby': self.claimtrie_getclaimssignedby,
|
||||
'blockchain.claimtrie.getclaimssignedbynthtoname': self.claimtrie_getclaimssignedbynthtoname,
|
||||
'blockchain.claimtrie.getvalueforuri': self.claimtrie_getvalueforuri,
|
||||
'blockchain.claimtrie.getvaluesforuris': self.claimtrie_getvalueforuris,
|
||||
'blockchain.claimtrie.getclaimssignedbyid': self.claimtrie_getclaimssignedbyid,
|
||||
'blockchain.block.get_server_height': self.get_server_height,
|
||||
}
|
||||
self.request_handlers.update(handlers)
|
||||
|
||||
def get_metrics_or_placeholder_for_api(self, query_name):
|
||||
""" Do not hold on to a reference to the metrics
|
||||
returned by this method past an `await` or
|
||||
you may be working with a stale metrics object.
|
||||
"""
|
||||
if self.env.track_metrics:
|
||||
return self.session_mgr.metrics.for_api(query_name)
|
||||
else:
|
||||
return APICallMetrics(query_name)
|
||||
|
||||
async def run_in_executor(self, query_name, func, kwargs):
|
||||
start = time.perf_counter()
|
||||
try:
|
||||
result = await asyncio.get_running_loop().run_in_executor(
|
||||
self.session_mgr.query_executor, func, kwargs
|
||||
)
|
||||
except reader.SQLiteInterruptedError as error:
|
||||
metrics = self.get_metrics_or_placeholder_for_api(query_name)
|
||||
metrics.query_interrupt(start, error.metrics)
|
||||
raise RPCError(JSONRPC.QUERY_TIMEOUT, 'sqlite query timed out')
|
||||
except reader.SQLiteOperationalError as error:
|
||||
metrics = self.get_metrics_or_placeholder_for_api(query_name)
|
||||
metrics.query_error(start, error.metrics)
|
||||
raise RPCError(JSONRPC.INTERNAL_ERROR, 'query failed to execute')
|
||||
except:
|
||||
metrics = self.get_metrics_or_placeholder_for_api(query_name)
|
||||
metrics.query_error(start, {})
|
||||
raise RPCError(JSONRPC.INTERNAL_ERROR, 'unknown server error')
|
||||
|
||||
if self.env.track_metrics:
|
||||
metrics = self.get_metrics_or_placeholder_for_api(query_name)
|
||||
(result, metrics_data) = result
|
||||
metrics.query_response(start, metrics_data)
|
||||
|
||||
return base64.b64encode(result).decode()
|
||||
|
||||
async def run_and_cache_query(self, query_name, function, kwargs):
|
||||
metrics = self.get_metrics_or_placeholder_for_api(query_name)
|
||||
metrics.start()
|
||||
cache = self.session_mgr.search_cache[query_name]
|
||||
cache_key = str(kwargs)
|
||||
cache_item = cache.get(cache_key)
|
||||
if cache_item is None:
|
||||
cache_item = cache[cache_key] = ResultCacheItem()
|
||||
elif cache_item.result is not None:
|
||||
metrics.cache_response()
|
||||
return cache_item.result
|
||||
async with cache_item.lock:
|
||||
if cache_item.result is None:
|
||||
cache_item.result = await self.run_in_executor(
|
||||
query_name, function, kwargs
|
||||
)
|
||||
else:
|
||||
metrics = self.get_metrics_or_placeholder_for_api(query_name)
|
||||
metrics.cache_response()
|
||||
return cache_item.result
|
||||
|
||||
async def claimtrie_search(self, **kwargs):
|
||||
if 'claim_id' in kwargs:
|
||||
self.assert_claim_id(kwargs['claim_id'])
|
||||
return Outputs.to_base64(*self.db.sql.search(kwargs))
|
||||
if kwargs:
|
||||
return await self.run_and_cache_query('search', reader.search_to_bytes, kwargs)
|
||||
|
||||
async def claimtrie_resolve(self, *urls):
|
||||
return Outputs.to_base64(*self.db.sql.resolve(urls))
|
||||
if urls:
|
||||
return await self.run_and_cache_query('resolve', reader.resolve_to_bytes, urls)
|
||||
|
||||
async def get_server_height(self):
|
||||
return self.bp.height
|
||||
@@ -66,84 +191,9 @@ class LBRYElectrumX(ElectrumX):
|
||||
return -1
|
||||
return None
|
||||
|
||||
async def claimtrie_getclaimssignedby(self, name):
|
||||
winning_claim = await self.daemon.getvalueforname(name)
|
||||
if winning_claim:
|
||||
return await self.claimtrie_getclaimssignedbyid(winning_claim['claimId'])
|
||||
|
||||
async def claimtrie_getclaimssignedbyid(self, certificate_id):
|
||||
claim_ids = self.get_claim_ids_signed_by(certificate_id)
|
||||
return await self.batched_formatted_claims_from_daemon(claim_ids)
|
||||
|
||||
def claimtrie_getclaimssignedbyidminimal(self, certificate_id):
|
||||
claim_ids = self.get_claim_ids_signed_by(certificate_id)
|
||||
ret = []
|
||||
for claim_id in claim_ids:
|
||||
raw_claim_id = unhexlify(claim_id)[::-1]
|
||||
info = self.db.get_claim_info(raw_claim_id)
|
||||
if info:
|
||||
ret.append({
|
||||
'claim_id': claim_id,
|
||||
'height': info.height,
|
||||
'name': info.name.decode()
|
||||
})
|
||||
return ret
|
||||
|
||||
def get_claim_ids_signed_by(self, certificate_id):
|
||||
raw_certificate_id = unhexlify(certificate_id)[::-1]
|
||||
raw_claim_ids = self.db.get_signed_claim_ids_by_cert_id(raw_certificate_id)
|
||||
return list(map(hash_to_hex_str, raw_claim_ids))
|
||||
|
||||
async def claimtrie_getclaimssignedbynthtoname(self, name, n):
|
||||
claim = self.claimtrie_getnthclaimforname(name, n)
|
||||
if claim and 'claim_id' in claim:
|
||||
return await self.claimtrie_getclaimssignedbyid(hash_to_hex_str(claim['claim_id']))
|
||||
|
||||
async def claimtrie_getclaimsintx(self, txid):
|
||||
# TODO: this needs further discussion.
|
||||
# Code on lbryum-server is wrong and we need to gather what we clearly expect from this command
|
||||
claim_ids = [claim['claimId'] for claim in (await self.daemon.getclaimsfortx(txid)) if 'claimId' in claim]
|
||||
return await self.batched_formatted_claims_from_daemon(claim_ids)
|
||||
|
||||
async def claimtrie_getvalue(self, name, block_hash=None):
|
||||
proof = await self.daemon.getnameproof(name, block_hash)
|
||||
result = {'proof': proof, 'supports': []}
|
||||
|
||||
if proof_has_winning_claim(proof):
|
||||
tx_hash, nout = proof['txhash'], int(proof['nOut'])
|
||||
transaction_info = await self.daemon.getrawtransaction(tx_hash, True)
|
||||
result['transaction'] = transaction_info['hex'] # should have never included this (or the call to get it)
|
||||
raw_claim_id = self.db.get_claim_id_from_outpoint(unhexlify(tx_hash)[::-1], nout)
|
||||
claim_id = hexlify(raw_claim_id[::-1]).decode()
|
||||
claim = await self.claimtrie_getclaimbyid(claim_id)
|
||||
result.update(claim)
|
||||
|
||||
return result
|
||||
|
||||
async def claimtrie_getnthclaimforname(self, name, n):
|
||||
n = int(n)
|
||||
result = await self.claimtrie_getclaimsforname(name)
|
||||
if 'claims' in result and len(result['claims']) > n >= 0:
|
||||
# TODO: revist this after lbrycrd_#209 to see if we can sort by claim_sequence at this point
|
||||
result['claims'].sort(key=lambda c: (int(c['height']), int(c['nout'])))
|
||||
result['claims'][n]['claim_sequence'] = n
|
||||
return result['claims'][n]
|
||||
|
||||
async def claimtrie_getpartialmatch(self, name, part):
|
||||
result = await self.claimtrie_getclaimsforname(name)
|
||||
if 'claims' in result:
|
||||
return next(filter(lambda x: x['claim_id'].starts_with(part), result['claims']), None)
|
||||
|
||||
async def claimtrie_getclaimsforname(self, name):
|
||||
claims = await self.daemon.getclaimsforname(name)
|
||||
if claims:
|
||||
claims['claims'] = [self.format_claim_from_daemon(claim, name) for claim in claims['claims']]
|
||||
claims['supports_without_claims'] = [] # fixme temporary
|
||||
del claims['supports without claims']
|
||||
claims['last_takeover_height'] = claims['nLastTakeoverHeight']
|
||||
del claims['nLastTakeoverHeight']
|
||||
return claims
|
||||
return {}
|
||||
async def claimtrie_getclaimsbyids(self, *claim_ids):
|
||||
claims = await self.batched_formatted_claims_from_daemon(claim_ids)
|
||||
return dict(zip(claim_ids, claims))
|
||||
|
||||
async def batched_formatted_claims_from_daemon(self, claim_ids):
|
||||
claims = await self.daemon.getclaimsbyids(claim_ids)
|
||||
@@ -202,19 +252,6 @@ class LBRYElectrumX(ElectrumX):
|
||||
result['normalized_name'] = claim['normalized_name'].encode('ISO-8859-1').decode()
|
||||
return result
|
||||
|
||||
def format_supports_from_daemon(self, supports):
|
||||
return [[support['txid'], support['n'], get_from_possible_keys(support, 'amount', 'nAmount')] for
|
||||
support in supports]
|
||||
|
||||
async def claimtrie_getclaimbyid(self, claim_id):
|
||||
self.assert_claim_id(claim_id)
|
||||
claim = await self.daemon.getclaimbyid(claim_id)
|
||||
return self.format_claim_from_daemon(claim)
|
||||
|
||||
async def claimtrie_getclaimsbyids(self, *claim_ids):
|
||||
claims = await self.batched_formatted_claims_from_daemon(claim_ids)
|
||||
return dict(zip(claim_ids, claims))
|
||||
|
||||
def assert_tx_hash(self, value):
|
||||
'''Raise an RPCError if the value is not a valid transaction
|
||||
hash.'''
|
||||
@@ -235,118 +272,6 @@ class LBRYElectrumX(ElectrumX):
|
||||
pass
|
||||
raise RPCError(1, f'{value} should be a claim id hash')
|
||||
|
||||
def normalize_name(self, name):
|
||||
# this is designed to match lbrycrd; change it here if it changes there
|
||||
return uda.normalize('NFD', name).casefold()
|
||||
|
||||
def claim_matches_name(self, claim, name):
|
||||
if not name:
|
||||
return False
|
||||
if 'normalized_name' in claim:
|
||||
return self.normalize_name(name) == claim['normalized_name']
|
||||
return name == claim['name']
|
||||
|
||||
async def claimtrie_getvalueforuri(self, block_hash, uri, known_certificates=None):
|
||||
# TODO: this thing is huge, refactor
|
||||
CLAIM_ID = "claim_id"
|
||||
WINNING = "winning"
|
||||
SEQUENCE = "sequence"
|
||||
uri = uri
|
||||
block_hash = block_hash
|
||||
try:
|
||||
parsed_uri = URL.parse(uri)
|
||||
except ValueError as err:
|
||||
return {'error': err.args[0]}
|
||||
result = {}
|
||||
|
||||
if parsed_uri.has_channel:
|
||||
certificate = None
|
||||
|
||||
# TODO: this is also done on the else, refactor
|
||||
if parsed_uri.channel.claim_id:
|
||||
if len(parsed_uri.channel.claim_id) < 40:
|
||||
certificate_info = self.claimtrie_getpartialmatch(
|
||||
parsed_uri.channel.name, parsed_uri.channel.claim_id)
|
||||
else:
|
||||
certificate_info = await self.claimtrie_getclaimbyid(parsed_uri.channel.claim_id)
|
||||
if certificate_info and self.claim_matches_name(certificate_info, parsed_uri.channel.name):
|
||||
certificate = {'resolution_type': CLAIM_ID, 'result': certificate_info}
|
||||
elif parsed_uri.claim_sequence:
|
||||
certificate_info = await self.claimtrie_getnthclaimforname(parsed_uri.name, parsed_uri.claim_sequence)
|
||||
if certificate_info:
|
||||
certificate = {'resolution_type': SEQUENCE, 'result': certificate_info}
|
||||
else:
|
||||
certificate_info = await self.claimtrie_getvalue(parsed_uri.name, block_hash)
|
||||
if certificate_info:
|
||||
certificate = {'resolution_type': WINNING, 'result': certificate_info}
|
||||
|
||||
if certificate and 'claim_id' not in certificate['result']:
|
||||
return result
|
||||
|
||||
if certificate:
|
||||
result['certificate'] = certificate
|
||||
channel_id = certificate['result']['claim_id']
|
||||
claims_in_channel = self.claimtrie_getclaimssignedbyidminimal(channel_id)
|
||||
if not parsed_uri.path:
|
||||
result['unverified_claims_in_channel'] = {claim['claim_id']: (claim['name'], claim['height'])
|
||||
for claim in claims_in_channel}
|
||||
else:
|
||||
# making an assumption that there aren't case conflicts on an existing channel
|
||||
norm_path = self.normalize_name(parsed_uri.path)
|
||||
result['unverified_claims_for_name'] = {claim['claim_id']: (claim['name'], claim['height'])
|
||||
for claim in claims_in_channel
|
||||
if self.normalize_name(claim['name']) == norm_path}
|
||||
|
||||
else:
|
||||
claim = None
|
||||
if parsed_uri.claim_id:
|
||||
if len(parsed_uri.claim_id) < 40:
|
||||
claim_info = self.claimtrie_getpartialmatch(parsed_uri.name, parsed_uri.claim_id)
|
||||
else:
|
||||
claim_info = await self.claimtrie_getclaimbyid(parsed_uri.claim_id)
|
||||
if claim_info and self.claim_matches_name(claim_info, parsed_uri.name):
|
||||
claim = {'resolution_type': CLAIM_ID, 'result': claim_info}
|
||||
elif parsed_uri.claim_sequence:
|
||||
claim_info = await self.claimtrie_getnthclaimforname(parsed_uri.name, parsed_uri.claim_sequence)
|
||||
if claim_info:
|
||||
claim = {'resolution_type': SEQUENCE, 'result': claim_info}
|
||||
else:
|
||||
claim_info = await self.claimtrie_getvalue(parsed_uri.name, block_hash)
|
||||
if claim_info:
|
||||
claim = {'resolution_type': WINNING, 'result': claim_info}
|
||||
if (claim and
|
||||
# is not an unclaimed winning name
|
||||
(claim['resolution_type'] != WINNING or proof_has_winning_claim(claim['result']['proof']))):
|
||||
raw_claim_id = unhexlify(claim['result']['claim_id'])[::-1]
|
||||
raw_certificate_id = self.db.get_claim_info(raw_claim_id).cert_id
|
||||
if raw_certificate_id:
|
||||
certificate_id = hash_to_hex_str(raw_certificate_id)
|
||||
certificate = await self.claimtrie_getclaimbyid(certificate_id)
|
||||
if certificate:
|
||||
certificate = {'resolution_type': CLAIM_ID,
|
||||
'result': certificate}
|
||||
result['certificate'] = certificate
|
||||
result['claim'] = claim
|
||||
|
||||
return result
|
||||
|
||||
async def claimtrie_getvalueforuris(self, block_hash, *uris):
|
||||
MAX_BATCH_URIS = 500
|
||||
if len(uris) > MAX_BATCH_URIS:
|
||||
raise Exception("Exceeds max batch uris of {}".format(MAX_BATCH_URIS))
|
||||
|
||||
return {uri: await self.claimtrie_getvalueforuri(block_hash, uri) for uri in uris}
|
||||
|
||||
# TODO: get it all concurrently when lbrycrd pending changes goes into a stable release
|
||||
#async def getvalue(uri):
|
||||
# value = await self.claimtrie_getvalueforuri(block_hash, uri)
|
||||
# return uri, value,
|
||||
#return dict([await asyncio.gather(*tuple(getvalue(uri) for uri in uris))][0])
|
||||
|
||||
|
||||
def proof_has_winning_claim(proof):
|
||||
return {'txhash', 'nOut'}.issubset(proof.keys())
|
||||
|
||||
|
||||
def get_from_possible_keys(dictionary, *keys):
|
||||
for key in keys:
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import asyncio
|
||||
from weakref import WeakSet
|
||||
|
||||
from aiohttp.web import Application, AppRunner, WebSocketResponse, TCPSite
|
||||
from aiohttp.http_websocket import WSMsgType, WSCloseCode
|
||||
|
||||
|
||||
class AdminWebSocket:
|
||||
|
||||
def __init__(self, manager):
|
||||
self.manager = manager
|
||||
self.app = Application()
|
||||
self.app['websockets'] = WeakSet()
|
||||
self.app.router.add_get('/', self.on_connect)
|
||||
self.app.on_shutdown.append(self.on_shutdown)
|
||||
self.runner = AppRunner(self.app)
|
||||
|
||||
async def on_status(self, _):
|
||||
if not self.app['websockets']:
|
||||
return
|
||||
self.send_message({
|
||||
'type': 'status',
|
||||
'height': self.manager.daemon.cached_height(),
|
||||
})
|
||||
|
||||
def send_message(self, msg):
|
||||
for web_socket in self.app['websockets']:
|
||||
asyncio.create_task(web_socket.send_json(msg))
|
||||
|
||||
async def start(self):
|
||||
await self.runner.setup()
|
||||
await TCPSite(self.runner, self.manager.env.websocket_host, self.manager.env.websocket_port).start()
|
||||
|
||||
async def stop(self):
|
||||
await self.runner.cleanup()
|
||||
|
||||
async def on_connect(self, request):
|
||||
web_socket = WebSocketResponse()
|
||||
await web_socket.prepare(request)
|
||||
self.app['websockets'].add(web_socket)
|
||||
try:
|
||||
async for msg in web_socket:
|
||||
if msg.type == WSMsgType.TEXT:
|
||||
await self.on_status(None)
|
||||
elif msg.type == WSMsgType.ERROR:
|
||||
print('web socket connection closed with exception %s' %
|
||||
web_socket.exception())
|
||||
finally:
|
||||
self.app['websockets'].discard(web_socket)
|
||||
return web_socket
|
||||
|
||||
@staticmethod
|
||||
async def on_shutdown(app):
|
||||
for web_socket in set(app['websockets']):
|
||||
await web_socket.close(code=WSCloseCode.GOING_AWAY, message='Server shutdown')
|
||||
@@ -8,7 +8,7 @@ RUN mkdir -p /home/$user/
|
||||
RUN chown -R $user:$user /home/$user/
|
||||
|
||||
# install python, pip, git and clean up
|
||||
RUN apt-get update && apt-get -y --no-install-recommends install build-essential git python3.7 python3.7-dev python3-pip && rm -rf /var/lib/apt/lists/*
|
||||
RUN apt-get update && apt-get -y --no-install-recommends install build-essential git tar wget python3.7 python3.7-dev python3-pip && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# create and chown database dir
|
||||
ARG db_dir=/database
|
||||
@@ -53,4 +53,5 @@ ENV BANDWIDTH_LIMIT=1000000000000000000000000000000000000000000
|
||||
ENV MAX_SESSIONS=1000000000
|
||||
ENV MAX_SEND=1000000000000000000
|
||||
ENV EVENT_LOOP_POLICY=uvloop
|
||||
ENTRYPOINT ["/home/lbry/.local/bin/torba-server"]
|
||||
COPY ./lbry/scripts/wallet_server_entrypoint.sh /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,32 @@
|
||||
import argparse
|
||||
import sqlite3
|
||||
from binascii import hexlify
|
||||
from lbry.wallet.transaction import Output
|
||||
|
||||
|
||||
def check(db_path, claim_id):
|
||||
db = sqlite3.connect(db_path)
|
||||
db.row_factory = sqlite3.Row
|
||||
claim = db.execute('select * from claim where claim_id=?', (claim_id,)).fetchone()
|
||||
if not claim:
|
||||
print('Could not find claim.')
|
||||
return
|
||||
channel = db.execute('select * from claim where claim_hash=?', (claim['channel_hash'],)).fetchone()
|
||||
if not channel:
|
||||
print('Could not find channel for this claim.')
|
||||
print(f"Claim: {claim['claim_name']}")
|
||||
print(f"Channel: {channel['claim_name']}")
|
||||
print(f"Signature: {hexlify(claim['signature']).decode()}")
|
||||
print(f"Digest: {hexlify(claim['signature_digest']).decode()}")
|
||||
print(f"Pubkey: {hexlify(channel['public_key_bytes']).decode()}")
|
||||
print("Valid: {}".format(Output.is_signature_valid(
|
||||
claim['signature'], claim['signature_digest'], channel['public_key_bytes']
|
||||
)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('db_path')
|
||||
parser.add_argument('claim_id')
|
||||
args = parser.parse_args()
|
||||
check(args.db_path, args.claim_id)
|
||||
@@ -0,0 +1,177 @@
|
||||
import os
|
||||
import time
|
||||
import textwrap
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
from concurrent.futures.process import ProcessPoolExecutor
|
||||
from lbry.wallet.server.db.reader import search_to_bytes, initializer, _get_claims, interpolate
|
||||
from lbry.wallet.ledger import MainNetLedger
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
log.addHandler(logging.StreamHandler())
|
||||
log.setLevel(logging.CRITICAL)
|
||||
|
||||
DEFAULT_ANY_TAGS = [
|
||||
'blockchain',
|
||||
'news',
|
||||
'learning',
|
||||
'technology',
|
||||
'automotive',
|
||||
'economics',
|
||||
'food',
|
||||
'science',
|
||||
'art',
|
||||
'nature'
|
||||
]
|
||||
|
||||
COMMON_AND_RARE = [
|
||||
'gaming',
|
||||
'ufos'
|
||||
]
|
||||
|
||||
COMMON_AND_RARE2 = [
|
||||
'city fix',
|
||||
'gaming'
|
||||
]
|
||||
|
||||
RARE_ANY_TAGS = [
|
||||
'city fix',
|
||||
'ufos',
|
||||
]
|
||||
|
||||
CITY_FIX = [
|
||||
'city fix'
|
||||
]
|
||||
|
||||
MATURE_TAGS = [
|
||||
'porn',
|
||||
'nsfw',
|
||||
'mature',
|
||||
'xxx'
|
||||
]
|
||||
|
||||
ORDER_BY = [
|
||||
[
|
||||
"trending_global",
|
||||
"trending_mixed",
|
||||
],
|
||||
[
|
||||
"release_time"
|
||||
],
|
||||
[
|
||||
"effective_amount"
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
def get_args(limit=20):
|
||||
args = []
|
||||
any_tags_combinations = [DEFAULT_ANY_TAGS, COMMON_AND_RARE, RARE_ANY_TAGS, COMMON_AND_RARE2, CITY_FIX, []]
|
||||
not_tags_combinations = [MATURE_TAGS, []]
|
||||
for no_fee in [False, True]:
|
||||
for claim_type in [None, 'stream', 'channel']:
|
||||
for no_totals in [True]:
|
||||
for offset in [0, 100]:
|
||||
for any_tags in any_tags_combinations:
|
||||
for not_tags in not_tags_combinations:
|
||||
for order_by in ORDER_BY:
|
||||
kw = {
|
||||
'order_by': order_by,
|
||||
'offset': offset,
|
||||
'limit': limit,
|
||||
'no_totals': no_totals
|
||||
}
|
||||
if not_tags:
|
||||
kw['not_tags'] = not_tags
|
||||
if any_tags:
|
||||
kw['any_tags'] = any_tags
|
||||
if claim_type:
|
||||
kw['claim_type'] = claim_type
|
||||
if no_fee:
|
||||
kw['fee_amount'] = 0
|
||||
args.append(kw)
|
||||
print(f"-- Trying {len(args)} argument combinations")
|
||||
return args
|
||||
|
||||
|
||||
def _search(kwargs):
|
||||
start = time.perf_counter()
|
||||
error = None
|
||||
try:
|
||||
search_to_bytes(kwargs)
|
||||
except Exception as err:
|
||||
error = str(err)
|
||||
return time.perf_counter() - start, kwargs, error
|
||||
|
||||
|
||||
async def search(executor, kwargs):
|
||||
return await asyncio.get_running_loop().run_in_executor(
|
||||
executor, _search, kwargs
|
||||
)
|
||||
|
||||
|
||||
async def main(db_path, max_query_time):
|
||||
args = dict(initializer=initializer, initargs=(log, db_path, MainNetLedger, 0.25))
|
||||
workers = max(os.cpu_count(), 4)
|
||||
log.info(f"using {workers} reader processes")
|
||||
query_executor = ProcessPoolExecutor(workers, **args)
|
||||
tasks = [search(query_executor, constraints) for constraints in get_args()]
|
||||
try:
|
||||
results = await asyncio.gather(*tasks)
|
||||
query_times = [
|
||||
{
|
||||
'sql': interpolate(*_get_claims("""
|
||||
claimtrie.claim_hash as is_controlling,
|
||||
claimtrie.last_take_over_height,
|
||||
claim.claim_hash, claim.txo_hash,
|
||||
claim.claims_in_channel,
|
||||
claim.height, claim.creation_height,
|
||||
claim.activation_height, claim.expiration_height,
|
||||
claim.effective_amount, claim.support_amount,
|
||||
claim.trending_group, claim.trending_mixed,
|
||||
claim.trending_local, claim.trending_global,
|
||||
claim.short_url, claim.canonical_url,
|
||||
claim.channel_hash, channel.txo_hash AS channel_txo_hash,
|
||||
channel.height AS channel_height, claim.signature_valid
|
||||
""", **constraints)),
|
||||
'duration': ts,
|
||||
'error': error
|
||||
}
|
||||
for ts, constraints, error in results
|
||||
]
|
||||
errored = [query_info for query_info in query_times if query_info['error']]
|
||||
errors = {str(query_info['error']): [] for query_info in errored}
|
||||
for error in errored:
|
||||
errors[str(error['error'])].append(error['sql'])
|
||||
slow = [
|
||||
query_info for query_info in query_times
|
||||
if not query_info['error'] and query_info['duration'] > (max_query_time / 2.0)
|
||||
]
|
||||
fast = [
|
||||
query_info for query_info in query_times
|
||||
if not query_info['error'] and query_info['duration'] <= (max_query_time / 2.0)
|
||||
]
|
||||
print(f"-- {len(fast)} queries were fast")
|
||||
slow.sort(key=lambda query_info: query_info['duration'], reverse=True)
|
||||
print(f"-- Failing queries:")
|
||||
for error in errors:
|
||||
print(f"-- Failure: \"{error}\"")
|
||||
for failing_query in errors[error]:
|
||||
print(f"{textwrap.dedent(failing_query)};\n")
|
||||
print()
|
||||
print(f"-- Slow queries:")
|
||||
for slow_query in slow:
|
||||
print(f"-- Query took {slow_query['duration']}\n{textwrap.dedent(slow_query['sql'])};\n")
|
||||
finally:
|
||||
query_executor.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--db_path', dest='db_path', default=os.path.expanduser('~/claims.db'), type=str)
|
||||
parser.add_argument('--max_time', dest='max_time', default=0.25, type=float)
|
||||
args = parser.parse_args()
|
||||
db_path = args.db_path
|
||||
max_query_time = args.max_time
|
||||
asyncio.run(main(db_path, max_query_time))
|
||||
@@ -0,0 +1,107 @@
|
||||
import time
|
||||
import asyncio
|
||||
import random
|
||||
from argparse import ArgumentParser
|
||||
from torba.client.basenetwork import ClientSession
|
||||
|
||||
|
||||
class AgentSmith(ClientSession):
|
||||
|
||||
async def do_nefarious_things(self):
|
||||
await self.send_request('blockchain.claimtrie.search', {
|
||||
'no_totals': True,
|
||||
'offset': random.choice(range(0, 300, 20)),
|
||||
'limit': 20,
|
||||
'any_tags': (
|
||||
random.choice([[
|
||||
random.choice(['gaming', 'games', 'game']) +
|
||||
random.choice(['entertainment', 'playthrough', 'funny']) +
|
||||
random.choice(['xbox', 'xbox one', 'xbox news'])
|
||||
], [
|
||||
random.choice(['aliens', 'alien', 'ufo', 'ufos']) +
|
||||
random.choice(['news', 'sighting', 'sightings'])
|
||||
], [
|
||||
random.choice(['art', 'automotive']),
|
||||
random.choice(['blockchain', 'economics', 'food']),
|
||||
random.choice(['funny', 'learnings', 'nature']),
|
||||
random.choice(['news', 'science', 'technology'])
|
||||
]
|
||||
])
|
||||
),
|
||||
'not_tags': random.choice([[], [
|
||||
'porn', 'mature', 'xxx', 'nsfw'
|
||||
]]),
|
||||
'order_by': random.choice([
|
||||
['release_time'],
|
||||
['trending_global', 'trending_mixed'],
|
||||
['effective_amount']
|
||||
])
|
||||
})
|
||||
|
||||
|
||||
class AgentSmithProgram:
|
||||
|
||||
def __init__(self, host, port):
|
||||
self.host, self.port = host, port
|
||||
self.agent_smiths = []
|
||||
|
||||
async def make_one_more_of_them(self):
|
||||
smith = AgentSmith(network=None, server=(self.host, self.port))
|
||||
await smith.create_connection()
|
||||
self.agent_smiths.append(smith)
|
||||
|
||||
async def coordinate_nefarious_activity(self):
|
||||
start = time.perf_counter()
|
||||
await asyncio.gather(
|
||||
*(s.do_nefarious_things() for s in self.agent_smiths),
|
||||
return_exceptions=True
|
||||
)
|
||||
return time.perf_counter() - start
|
||||
|
||||
def __len__(self):
|
||||
return len(self.agent_smiths)
|
||||
|
||||
async def delete_one_smith(self):
|
||||
if self.agent_smiths:
|
||||
await self.agent_smiths.pop().close()
|
||||
|
||||
async def delete_program(self):
|
||||
await asyncio.gather(*(
|
||||
s.close() for s in self.agent_smiths
|
||||
))
|
||||
|
||||
|
||||
async def main(host, port):
|
||||
smiths = AgentSmithProgram(host, port)
|
||||
await smiths.make_one_more_of_them()
|
||||
activity = asyncio.create_task(smiths.coordinate_nefarious_activity())
|
||||
ease_off = 0
|
||||
for i in range(1000):
|
||||
await asyncio.sleep(1)
|
||||
if activity.done() and activity.result() < .9:
|
||||
print('more, more, more...')
|
||||
await asyncio.gather(*(
|
||||
asyncio.create_task(smiths.make_one_more_of_them()) for _ in range(20)
|
||||
))
|
||||
else:
|
||||
print('!!!!!!!!!!!!!!')
|
||||
print('IS NEO LOSING?')
|
||||
print('!!!!!!!!!!!!!!')
|
||||
await asyncio.gather(*(
|
||||
asyncio.create_task(smiths.delete_one_smith()) for _ in range(21)
|
||||
))
|
||||
print(f'coordinate all {len(smiths)} smiths to action')
|
||||
activity = asyncio.create_task(smiths.coordinate_nefarious_activity())
|
||||
print('finishing up any remaining actions')
|
||||
await activity
|
||||
print('neo has won, deleting agents...')
|
||||
await smiths.delete_program()
|
||||
print('done.')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('--host', dest='host', default='localhost', type=str)
|
||||
parser.add_argument('--port', dest='port', default=50001, type=int)
|
||||
args = parser.parse_args()
|
||||
asyncio.run(main(args.host, args.port))
|
||||
@@ -78,11 +78,31 @@ class Examples(CommandTestCase):
|
||||
'Get version',
|
||||
'version'
|
||||
)
|
||||
|
||||
# settings
|
||||
|
||||
await r(
|
||||
'Get settings',
|
||||
'settings', 'get'
|
||||
)
|
||||
|
||||
await r(
|
||||
'Set settings',
|
||||
'settings', 'set', '"tcp_port"', '99'
|
||||
)
|
||||
|
||||
# preferences
|
||||
|
||||
await r(
|
||||
'Set preference',
|
||||
'preference', 'set', '"theme"', '"dark"'
|
||||
)
|
||||
|
||||
await r(
|
||||
'Get preferences',
|
||||
'preference', 'get'
|
||||
)
|
||||
|
||||
# accounts
|
||||
|
||||
await r(
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import os, asyncio, aiohttp, json, slack, sqlparse
|
||||
|
||||
|
||||
async def listen(slack_client, url):
|
||||
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(3)) as session:
|
||||
print(f"connecting to {url}")
|
||||
try:
|
||||
ws = await session.ws_connect(url)
|
||||
except (aiohttp.ClientConnectorError, asyncio.TimeoutError):
|
||||
print(f"failed to connect to {url}")
|
||||
return
|
||||
print(f"connected to {url}")
|
||||
|
||||
async for msg in ws:
|
||||
r = json.loads(msg.data)
|
||||
try:
|
||||
queries = r["api"]["search"]["interrupted_queries"]
|
||||
except KeyError:
|
||||
continue
|
||||
|
||||
for q in queries:
|
||||
# clean = re.sub(r"\s+", " ", q)
|
||||
clean = sqlparse.format(q, reindent=True, keyword_case='upper')
|
||||
print(f'{url}: {clean}')
|
||||
response = await slack_client.chat_postMessage(
|
||||
username=url,
|
||||
icon_emoji=":hourglass_flowing_sand:",
|
||||
channel='#clubhouse-de-obscure',
|
||||
text="*Query timed out:* " + clean
|
||||
)
|
||||
if not response["ok"]:
|
||||
print("SLACK ERROR:\n", response)
|
||||
print()
|
||||
|
||||
|
||||
async def main():
|
||||
try:
|
||||
slack_client = slack.WebClient(token=os.environ['SLACK_TOKEN'], run_async=True)
|
||||
except KeyError:
|
||||
print("Error: SLACK_TOKEN env var required")
|
||||
return
|
||||
|
||||
num_servers = 5
|
||||
tasks = []
|
||||
for i in range(1, num_servers+1):
|
||||
tasks.append(asyncio.create_task(listen(slack_client, f'http://spv{i}.lbry.com:50005')))
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
asyncio.run(main())
|
||||
+32
-61
@@ -74,28 +74,19 @@ def get_release_text(desc: str):
|
||||
yield line[len(RELEASE_TEXT):]
|
||||
|
||||
|
||||
def get_previous_final(repo, current_release):
|
||||
assert current_release.rc is not None, "Need an rc to find the previous final release."
|
||||
previous = None
|
||||
for tag in repo.tags(current_release.rc+1):
|
||||
previous = tag
|
||||
return previous
|
||||
|
||||
|
||||
class Version:
|
||||
|
||||
def __init__(self, major=0, minor=0, micro=0, rc=None):
|
||||
def __init__(self, major=0, minor=0, micro=0):
|
||||
self.major = int(major)
|
||||
self.minor = int(minor)
|
||||
self.micro = int(micro)
|
||||
self.rc = rc if rc is None else int(rc)
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, version_string):
|
||||
(major, minor, micro), rc = version_string.split('.'), None
|
||||
if 'rc' in micro:
|
||||
micro, rc = micro.split('rc')
|
||||
return cls(major, minor, micro, rc)
|
||||
return cls(major, minor, micro)
|
||||
|
||||
@classmethod
|
||||
def from_content(cls, content):
|
||||
@@ -106,20 +97,12 @@ class Version:
|
||||
def increment(self, action):
|
||||
cls = self.__class__
|
||||
|
||||
if action == '*-rc':
|
||||
assert self.rc is not None, f"Can't drop rc designation because {self} is already not an rc."
|
||||
return cls(self.major, self.minor, self.micro)
|
||||
elif action == '*+rc':
|
||||
assert self.rc is not None, "Must already be an rc to increment."
|
||||
return cls(self.major, self.minor, self.micro, self.rc+1)
|
||||
|
||||
assert self.rc is None, f"Can't start a new rc because {self} is already an rc."
|
||||
if action == 'major+rc':
|
||||
return cls(self.major+1, rc=1)
|
||||
elif action == 'minor+rc':
|
||||
return cls(self.major, self.minor+1, rc=1)
|
||||
elif action == 'micro+rc':
|
||||
return cls(self.major, self.minor, self.micro+1, 1)
|
||||
if action == 'major':
|
||||
return cls(self.major+1)
|
||||
elif action == 'minor':
|
||||
return cls(self.major, self.minor+1)
|
||||
elif action == 'micro':
|
||||
return cls(self.major, self.minor, self.micro+1)
|
||||
|
||||
raise ValueError(f'unknown action: {action}')
|
||||
|
||||
@@ -128,10 +111,7 @@ class Version:
|
||||
return f'v{self}'
|
||||
|
||||
def __str__(self):
|
||||
version = '.'.join(str(p) for p in [self.major, self.minor, self.micro])
|
||||
if self.rc is not None:
|
||||
version += f'rc{self.rc}'
|
||||
return version
|
||||
return '.'.join(str(p) for p in [self.major, self.minor, self.micro])
|
||||
|
||||
|
||||
def release(args):
|
||||
@@ -139,15 +119,15 @@ def release(args):
|
||||
repo = gh.repository('lbryio', 'lbry-sdk')
|
||||
version_file = repo.file_contents('lbry/lbry/__init__.py')
|
||||
|
||||
if not args.confirm:
|
||||
print("\nDRY RUN ONLY. RUN WITH --confirm TO DO A REAL RELEASE.\n")
|
||||
|
||||
current_version = Version.from_content(version_file)
|
||||
print(f'Current Version: {current_version}')
|
||||
new_version = current_version.increment(args.action)
|
||||
print(f' New Version: {new_version}')
|
||||
|
||||
if args.action == '*-rc':
|
||||
previous_release = repo.release_from_tag(args.start_tag or get_previous_final(repo, current_version))
|
||||
else:
|
||||
previous_release = repo.release_from_tag(current_version.tag)
|
||||
previous_release = repo.release_from_tag(current_version.tag)
|
||||
|
||||
print(f' Changelog From: {previous_release.tag_name} ({previous_release.created_at})')
|
||||
print()
|
||||
@@ -165,7 +145,7 @@ def release(args):
|
||||
incompats.append(f' * [{area_name}] {incompat.strip()} ({pr.html_url})')
|
||||
for release_text in get_release_text(pr.body):
|
||||
release_texts.append(f'{release_text.strip()} ({pr.html_url})')
|
||||
if not (args.action == '*-rc' and type_label == 'fixup'):
|
||||
if type_label != 'fixup':
|
||||
area = areas.setdefault(area_name, [])
|
||||
area.append(f' * [{type_label}] {pr.title} ({pr.html_url}) by {pr.user["login"]}')
|
||||
else:
|
||||
@@ -203,7 +183,7 @@ def release(args):
|
||||
for skipped in unlabeled:
|
||||
print(skipped)
|
||||
|
||||
if not args.dry_run:
|
||||
if args.confirm:
|
||||
|
||||
commit = version_file.update(
|
||||
new_version.tag,
|
||||
@@ -223,9 +203,10 @@ def release(args):
|
||||
name=new_version.tag,
|
||||
body=body.getvalue(),
|
||||
draft=True,
|
||||
prerelease=new_version.rc is not None
|
||||
)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
class TestReleaseTool(unittest.TestCase):
|
||||
|
||||
@@ -235,44 +216,34 @@ class TestReleaseTool(unittest.TestCase):
|
||||
|
||||
def test_version_increment(self):
|
||||
v = Version.from_string('1.2.3')
|
||||
self.assertTrue(str(v.increment('major+rc')), '2.0.0rc1')
|
||||
self.assertTrue(str(v.increment('minor+rc')), '1.3.0rc1')
|
||||
self.assertTrue(str(v.increment('micro+rc')), '1.2.4rc1')
|
||||
with self.assertRaisesRegex(AssertionError, "Must already be an rc to increment."):
|
||||
v.increment('*+rc')
|
||||
with self.assertRaisesRegex(AssertionError, "Can't drop rc designation"):
|
||||
v.increment('*-rc')
|
||||
|
||||
v = Version.from_string('1.2.3rc3')
|
||||
self.assertTrue(str(v.increment('*+rc')), '1.2.3rc4')
|
||||
self.assertTrue(str(v.increment('*-rc')), '1.2.3')
|
||||
with self.assertRaisesRegex(AssertionError, "already an rc"):
|
||||
v.increment('major+rc')
|
||||
with self.assertRaisesRegex(AssertionError, "already an rc"):
|
||||
v.increment('minor+rc')
|
||||
with self.assertRaisesRegex(AssertionError, "already an rc"):
|
||||
v.increment('micro+rc')
|
||||
self.assertTrue(str(v.increment('major')), '2.0.0')
|
||||
self.assertTrue(str(v.increment('minor')), '1.3.0')
|
||||
self.assertTrue(str(v.increment('micro')), '1.2.4')
|
||||
|
||||
|
||||
def test():
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
loader = unittest.TestLoader()
|
||||
suite = loader.loadTestsFromTestCase(TestReleaseTool)
|
||||
runner.run(suite)
|
||||
return 0 if runner.run(suite).wasSuccessful() else 1
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--test", default=False, action="store_true", help="run unit tests")
|
||||
parser.add_argument("--dry-run", default=False, action="store_true", help="show what will be done")
|
||||
parser.add_argument("--confirm", default=False, action="store_true",
|
||||
help="without this flag, it will only print what it will do but will not actually do it")
|
||||
parser.add_argument("--start-tag", help="custom starting tag for changelog generation")
|
||||
parser.add_argument("action", nargs="?", choices=['major+rc', 'minor+rc', 'micro+rc', '*+rc', '*-rc'])
|
||||
parser.add_argument("action", choices=['test', 'major', 'minor', 'micro'])
|
||||
args = parser.parse_args()
|
||||
if args.test:
|
||||
test()
|
||||
|
||||
if args.action == "test":
|
||||
code = test()
|
||||
else:
|
||||
release(args)
|
||||
code = release(args)
|
||||
|
||||
print()
|
||||
return code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,62 @@
|
||||
import uvloop, asyncio, time, sys, logging
|
||||
from concurrent.futures import ProcessPoolExecutor
|
||||
from lbry.wallet.server.db import reader
|
||||
from lbry.wallet.server.metrics import calculate_avg_percentiles
|
||||
|
||||
|
||||
db_path = '../../../lbryconf/wallet-server/claims.db'
|
||||
default_query_timout = 0.25
|
||||
log = logging.getLogger(__name__)
|
||||
log.addHandler(logging.StreamHandler())
|
||||
|
||||
|
||||
async def run_times(executor, iterations, show=True):
|
||||
start = time.perf_counter()
|
||||
timings = await asyncio.gather(*(asyncio.get_running_loop().run_in_executor(
|
||||
executor, reader.search_to_bytes, {
|
||||
'no_totals': True,
|
||||
'offset': 0,
|
||||
'limit': 20,
|
||||
'any_tags': [
|
||||
'ufos', 'city fix'
|
||||
],
|
||||
'not_tags': [
|
||||
'porn', 'mature', 'xxx', 'nsfw'
|
||||
],
|
||||
'order_by': [
|
||||
'release_time'
|
||||
]
|
||||
}
|
||||
) for _ in range(iterations)))
|
||||
timings = [r[1]['execute_query'][0]['total'] for r in timings]
|
||||
total = int((time.perf_counter() - start) * 100)
|
||||
if show:
|
||||
avg = sum(timings)/len(timings)
|
||||
print(f"{iterations:4}: {total}ms total concurrent, {len(timings)*avg*1000:.3f}s total sequential (avg*runs)")
|
||||
print(f" {total/len(timings):.1f}ms/query concurrent (total/runs)")
|
||||
print(f" {avg:.1f}ms/query actual average (sum(queries)/runs)")
|
||||
stats = calculate_avg_percentiles(timings)
|
||||
print(f" min: {stats[1]}, 5%: {stats[2]}, 25%: {stats[3]}, 50%: {stats[4]}, 75%: {stats[5]}, 95%: {stats[6]}, max: {stats[7]}")
|
||||
sys.stdout.write(' sample:')
|
||||
for i, t in zip(range(10), timings[::-1]):
|
||||
sys.stdout.write(f' {t}ms')
|
||||
print(' ...\n' if len(timings) > 10 else '\n')
|
||||
|
||||
|
||||
async def main():
|
||||
executor = ProcessPoolExecutor(
|
||||
4, initializer=reader.initializer, initargs=(log, db_path, 'mainnet', 1.0, True)
|
||||
)
|
||||
#await run_times(executor, 4, show=False)
|
||||
#await run_times(executor, 1)
|
||||
await run_times(executor, 2**3)
|
||||
await run_times(executor, 2**5)
|
||||
await run_times(executor, 2**7)
|
||||
#await run_times(executor, 2**9)
|
||||
#await run_times(executor, 2**11)
|
||||
#await run_times(executor, 2**13)
|
||||
executor.shutdown(True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
uvloop.install()
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,47 @@
|
||||
import asyncio
|
||||
from torba.client.basenetwork import ClientSession
|
||||
from torba.rpc.jsonrpc import RPCError
|
||||
import logging
|
||||
import json
|
||||
import sys
|
||||
|
||||
logging.getLogger('torba').setLevel(logging.CRITICAL)
|
||||
|
||||
|
||||
async def main():
|
||||
try:
|
||||
hostname = sys.argv[1]
|
||||
except IndexError:
|
||||
hostname = 'spv1.lbry.com'
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
client = ClientSession(network=None, server=(hostname, 50001))
|
||||
error = None
|
||||
args = {
|
||||
'any_tags': ['art'],
|
||||
'not_tags': ['xxx', 'porn', 'mature', 'nsfw', 'titan'],
|
||||
'order_by': ["name"],
|
||||
'offset': 3000,
|
||||
'limit': 200,
|
||||
'no_totals': False,
|
||||
}
|
||||
|
||||
start = loop.time()
|
||||
try:
|
||||
await client.create_connection()
|
||||
try:
|
||||
await client.send_request('blockchain.claimtrie.search', args)
|
||||
except RPCError as err:
|
||||
error = err
|
||||
finally:
|
||||
await client.close()
|
||||
finally:
|
||||
print(json.dumps({
|
||||
"time": loop.time() - start,
|
||||
"error": error.__str__() if error else None,
|
||||
"args": args,
|
||||
}, indent=4))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -1,43 +1,19 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import argparse
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import time
|
||||
|
||||
import aiohttp
|
||||
from aiohttp import ClientConnectorError
|
||||
from lbry import __version__
|
||||
from lbry.blob.blob_file import MAX_BLOB_SIZE
|
||||
from lbry.conf import Config
|
||||
from lbry.schema.uri import parse_lbry_uri
|
||||
from lbry.extras.daemon.client import daemon_rpc
|
||||
from lbry.extras import system_info
|
||||
|
||||
|
||||
def extract_uris(response):
|
||||
uris = list()
|
||||
for key in response:
|
||||
for value in response[key]:
|
||||
uris.append(value)
|
||||
|
||||
return uris
|
||||
|
||||
|
||||
async def get_frontpage_uris():
|
||||
session = aiohttp.ClientSession()
|
||||
try:
|
||||
response = await session.get("https://api.lbry.com/file/list_homepage", timeout=10.0)
|
||||
if response.status != 200:
|
||||
print("API returned non 200 code!!")
|
||||
return
|
||||
body = await response.json()
|
||||
await session.close()
|
||||
uris = extract_uris(body['data']['Uris'])
|
||||
return uris
|
||||
finally:
|
||||
await session.close()
|
||||
|
||||
|
||||
async def report_to_slack(output, webhook):
|
||||
payload = {
|
||||
"text": f"lbrynet {__version__} ({system_info.get_platform()['platform']}) time to first byte:\n{output}"
|
||||
@@ -58,120 +34,127 @@ 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, timeout):
|
||||
name = uri.split("#")[0]
|
||||
last_complete = 0
|
||||
hang_count = 0
|
||||
async def wait_for_done(conf, claim_name, timeout):
|
||||
blobs_completed, last_completed = 0, time.perf_counter()
|
||||
while True:
|
||||
files = await daemon_rpc(conf, "file_list", claim_name=name)
|
||||
file = files[0]
|
||||
file = (await daemon_rpc(conf, "file_list", claim_name=claim_name))[0]
|
||||
if file['status'] in ['finished', 'stopped']:
|
||||
return True, file['blobs_completed'], file['blobs_in_stream']
|
||||
if last_complete < int(file['blobs_completed']):
|
||||
hang_count = 0
|
||||
last_complete = int(file['blobs_completed'])
|
||||
else:
|
||||
hang_count += 1
|
||||
await asyncio.sleep(1.0)
|
||||
if hang_count > timeout:
|
||||
elif blobs_completed < int(file['blobs_completed']):
|
||||
blobs_completed, last_completed = int(file['blobs_completed']), time.perf_counter()
|
||||
elif (time.perf_counter() - last_completed) > timeout:
|
||||
return False, file['blobs_completed'], file['blobs_in_stream']
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
|
||||
async def main(uris=None, cmd_args=None):
|
||||
if not uris:
|
||||
uris = await get_frontpage_uris()
|
||||
async def main(cmd_args=None):
|
||||
print('Time to first byte started using parameters:')
|
||||
for key, value in vars(cmd_args).items():
|
||||
print(f"{key}: {value}")
|
||||
conf = Config()
|
||||
url_to_claim = {}
|
||||
try:
|
||||
await daemon_rpc(conf, 'status')
|
||||
for page in range(1, cmd_args.download_pages + 1):
|
||||
start = time.perf_counter()
|
||||
kwargs = {
|
||||
'page': page,
|
||||
# 'claim_type': 'stream',
|
||||
'order_by': ['trending_global', 'trending_mixed'],
|
||||
'no_totals': True
|
||||
}
|
||||
|
||||
# if not cmd_args.allow_fees:
|
||||
# kwargs['fee_amount'] = 0
|
||||
|
||||
response = await daemon_rpc(
|
||||
conf, 'claim_search', **kwargs
|
||||
)
|
||||
if 'error' in response or not response.get('items'):
|
||||
print(f'Error getting claim list page {page}:')
|
||||
print(response)
|
||||
return 1
|
||||
else:
|
||||
url_to_claim.update({
|
||||
claim['permanent_url']: claim for claim in response['items'] if claim['value_type'] == 'stream'
|
||||
})
|
||||
print(f'Claim search page {page} took: {time.perf_counter() - start}')
|
||||
except (ClientConnectorError, ConnectionError):
|
||||
print("Could not connect to daemon")
|
||||
return 1
|
||||
print(f"Checking {len(uris)} uris from the front page")
|
||||
print("**********************************************")
|
||||
|
||||
resolvable = []
|
||||
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']) 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")
|
||||
print(f"Attempting to download {len(url_to_claim)} claim_search streams")
|
||||
|
||||
first_byte_times = []
|
||||
download_speeds = []
|
||||
download_successes = []
|
||||
failed_to_start = []
|
||||
download_failures = []
|
||||
failed_to = {}
|
||||
|
||||
for uri in resolvable:
|
||||
await daemon_rpc(conf, 'file_delete', delete_from_download_dir=True, claim_name=parse_lbry_uri(uri).name)
|
||||
await asyncio.gather(*(
|
||||
daemon_rpc(conf, 'file_delete', delete_from_download_dir=True, claim_name=claim['name'])
|
||||
for claim in url_to_claim.values() if not cmd_args.keep_files
|
||||
))
|
||||
|
||||
for i, uri in enumerate(resolvable):
|
||||
start = time.time()
|
||||
try:
|
||||
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}")
|
||||
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)
|
||||
for i, (url, claim) in enumerate(url_to_claim.items()):
|
||||
start = time.perf_counter()
|
||||
response = await daemon_rpc(conf, 'get', uri=url, save_file=not cmd_args.head_blob_only)
|
||||
if 'error' in response:
|
||||
print(f"{i + 1}/{len(url_to_claim)} - failed to start {url}: {response['error']}")
|
||||
failed_to[url] = 'start'
|
||||
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)
|
||||
continue
|
||||
first_byte = time.perf_counter()
|
||||
first_byte_times.append(first_byte - start)
|
||||
print(f"{i + 1}/{len(url_to_claim)} - {first_byte - start} {url}")
|
||||
if not cmd_args.head_blob_only:
|
||||
downloaded, amount_downloaded, blobs_in_stream = await wait_for_done(
|
||||
conf, claim['name'], cmd_args.stall_download_timeout
|
||||
)
|
||||
if downloaded:
|
||||
download_successes.append(url)
|
||||
else:
|
||||
failed_to[url] = 'finish'
|
||||
mbs = round((blobs_in_stream * (MAX_BLOB_SIZE - 1)) / (time.perf_counter() - start) / 1000000, 2)
|
||||
download_speeds.append(mbs)
|
||||
print(f"downloaded {amount_downloaded}/{blobs_in_stream} blobs for {url} at "
|
||||
f"{mbs}mb/s")
|
||||
if not cmd_args.keep_files:
|
||||
await daemon_rpc(conf, 'file_delete', delete_from_download_dir=True, claim_name=claim['name'])
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
print("**********************************************")
|
||||
result = f"Started {len(first_byte_times)} of {len(resolvable)} attempted front page streams\n" \
|
||||
f"Worst first byte time: {round(max(first_byte_times), 2)}\n" \
|
||||
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"
|
||||
if not cmd_args.head_blob_only:
|
||||
result += f"Downloaded {len(download_successes)}/{len(resolvable)}\n" \
|
||||
result = f"Started {len(first_byte_times)} of {len(url_to_claim)} attempted front page streams\n"
|
||||
if first_byte_times:
|
||||
result += f"Worst first byte time: {round(max(first_byte_times), 2)}\n" \
|
||||
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"
|
||||
if download_successes:
|
||||
result += f"Downloaded {len(download_successes)}/{len(url_to_claim)}\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])
|
||||
if download_failures:
|
||||
result += "\nFailed to finish:" + "\n".join([f for f in download_failures])
|
||||
for reason in ('start', 'finish'):
|
||||
failures = [url for url, why in failed_to.items() if reason == why]
|
||||
if failures:
|
||||
result += f"\nFailed to {reason}:\n" + "\n•".join(failures)
|
||||
print(result)
|
||||
|
||||
webhook = os.environ.get('TTFB_SLACK_TOKEN', None)
|
||||
if webhook:
|
||||
await report_to_slack(result, webhook)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
#parser.add_argument("--data_dir")
|
||||
#parser.add_argument("--wallet_dir")
|
||||
#parser.add_argument("--download_directory")
|
||||
parser.add_argument("--allow_fees", action='store_true')
|
||||
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("--stall_download_timeout", default=0, type=int)
|
||||
parser.add_argument("--keep_files", action='store_true')
|
||||
parser.add_argument("--head_blob_only", action='store_true')
|
||||
asyncio.run(main(cmd_args=parser.parse_args()))
|
||||
parser.add_argument("--download_pages", type=int, default=10)
|
||||
sys.exit(asyncio.run(main(cmd_args=parser.parse_args())) or 0)
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# entrypoint for wallet server Docker image
|
||||
|
||||
SNAPSHOT_URL="${SNAPSHOT_URL:-}" #off by default. latest snapshot at https://lbry.com/snapshot/wallet
|
||||
|
||||
if [[ -n "$SNAPSHOT_URL" ]] && [[ ! -f /database/claims.db ]]; then
|
||||
echo "Downloading wallet snapshot from $SNAPSHOT_URL"
|
||||
wget -O wallet_snapshot.tar.bz2 "$SNAPSHOT_URL"
|
||||
echo "Extracting snapshot..."
|
||||
tar xvjf wallet_snapshot.tar.bz2 --directory /database
|
||||
rm wallet_snapshot.tar.bz2
|
||||
fi
|
||||
|
||||
/home/lbry/.local/bin/torba-server "$@"
|
||||
@@ -0,0 +1,331 @@
|
||||
import sys
|
||||
import json
|
||||
import random
|
||||
import asyncio
|
||||
import argparse
|
||||
import traceback
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
|
||||
try:
|
||||
import aiohttp
|
||||
import psycopg2
|
||||
import slack
|
||||
except ImportError:
|
||||
print(f"To run {sys.argv[0]} you need to install aiohttp, psycopg2 and slackclient:")
|
||||
print(f"")
|
||||
print(f" $ pip install aiohttp psycopg2 slackclient")
|
||||
print("")
|
||||
sys.exit(1)
|
||||
|
||||
if not sys.version_info >= (3, 7):
|
||||
print("Please use Python 3.7 or higher, this script expects that dictionary keys preserve order.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
async def handle_slow_query(cursor, server, command, queries):
|
||||
for query in queries:
|
||||
cursor.execute("""
|
||||
INSERT INTO wallet_server_slow_queries (server, command, query, event_time) VALUES (%s,%s,%s,%s);
|
||||
""", (server, command, query, datetime.now()))
|
||||
|
||||
|
||||
async def handle_analytics_event(cursor, event, server):
|
||||
cursor.execute("""
|
||||
INSERT INTO wallet_server_stats (server, sessions, event_time) VALUES (%s,%s,%s);
|
||||
""", (server, event['status']['sessions'], datetime.now()))
|
||||
|
||||
for command, stats in event["api"].items():
|
||||
data = {
|
||||
'server': server,
|
||||
'command': command,
|
||||
'event_time': datetime.now()
|
||||
}
|
||||
for key, value in stats.items():
|
||||
if key.endswith("_queries"):
|
||||
if key == "interrupted_queries":
|
||||
await handle_slow_query(cursor, server, command, value)
|
||||
continue
|
||||
if isinstance(value, list):
|
||||
data.update({
|
||||
key + '_avg': value[0],
|
||||
key + '_min': value[1],
|
||||
key + '_five': value[2],
|
||||
key + '_twenty_five': value[3],
|
||||
key + '_fifty': value[4],
|
||||
key + '_seventy_five': value[5],
|
||||
key + '_ninety_five': value[6],
|
||||
key + '_max': value[7],
|
||||
})
|
||||
else:
|
||||
data[key] = value
|
||||
|
||||
cursor.execute(f"""
|
||||
INSERT INTO wallet_server_command_stats ({','.join(data)})
|
||||
VALUES ({','.join('%s' for _ in data)});
|
||||
""", list(data.values()))
|
||||
|
||||
|
||||
SLACKCLIENT = None
|
||||
|
||||
|
||||
async def boris_says(what_boris_says):
|
||||
if SLACKCLIENT:
|
||||
await SLACKCLIENT.chat_postMessage(
|
||||
username="boris the wallet monitor",
|
||||
icon_emoji=":boris:",
|
||||
channel='#tech-sdk',
|
||||
text=what_boris_says
|
||||
)
|
||||
else:
|
||||
print(what_boris_says)
|
||||
|
||||
|
||||
async def monitor(db, server):
|
||||
c = db.cursor()
|
||||
delay = 30
|
||||
height_changed = None, time()
|
||||
height_change_reported = False
|
||||
first_attempt = True
|
||||
while True:
|
||||
try:
|
||||
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(10)) as session:
|
||||
try:
|
||||
ws = await session.ws_connect(server)
|
||||
except (aiohttp.ClientConnectorError, asyncio.TimeoutError):
|
||||
if first_attempt:
|
||||
print(f"failed connecting to {server}")
|
||||
await boris_says(random.choice([
|
||||
f"{server} is not responding, probably dead, will not connect again.",
|
||||
]))
|
||||
return
|
||||
raise
|
||||
|
||||
if first_attempt:
|
||||
await boris_says(f"{server} is online")
|
||||
else:
|
||||
await boris_says(f"{server} is back online")
|
||||
|
||||
delay = 30
|
||||
first_attempt = False
|
||||
print(f"connected to {server}")
|
||||
|
||||
async for msg in ws:
|
||||
event = json.loads(msg.data)
|
||||
height = event['status']['height']
|
||||
height_change_time = int(time()-height_changed[1])
|
||||
if height_changed[0] != height:
|
||||
height_changed = (height, time())
|
||||
if height_change_reported:
|
||||
await boris_says(
|
||||
f"Server {server} received new block after {height_change_time / 60:.1f} minutes.",
|
||||
)
|
||||
height_change_reported = False
|
||||
elif height_change_time > 10*60:
|
||||
if not height_change_reported or height_change_time % (2*60) == 0:
|
||||
await boris_says(
|
||||
f"It's been {height_change_time/60:.1f} minutes since {server} received a new block.",
|
||||
)
|
||||
height_change_reported = True
|
||||
await handle_analytics_event(c, event, server)
|
||||
db.commit()
|
||||
|
||||
except (aiohttp.ClientConnectorError, asyncio.TimeoutError):
|
||||
await boris_says(random.choice([
|
||||
f"<!channel> Guys, we have a problem! Nobody home at {server}. Will check on it again in {delay} seconds.",
|
||||
f"<!channel> Something wrong with {server}. I think dead. Will poke it again in {delay} seconds.",
|
||||
f"<!channel> Don't hear anything from {server}, maybe dead. Will try it again in {delay} seconds.",
|
||||
]))
|
||||
await asyncio.sleep(delay)
|
||||
delay += 30
|
||||
|
||||
|
||||
async def main(dsn, servers):
|
||||
db = ensure_database(dsn)
|
||||
await boris_says(random.choice([
|
||||
"No fear, Boris is here! I will monitor the servers now and will try not to fall asleep again.",
|
||||
"Comrad the Cat and Boris are here now, monitoring wallet servers.",
|
||||
]))
|
||||
await asyncio.gather(*(
|
||||
asyncio.create_task(monitor(db, server))
|
||||
for server in servers
|
||||
))
|
||||
|
||||
|
||||
def ensure_database(dsn):
|
||||
db = psycopg2.connect(**dsn)
|
||||
c = db.cursor()
|
||||
|
||||
c.execute("SELECT to_regclass('wallet_server_stats');")
|
||||
if c.fetchone()[0] is None:
|
||||
print("creating table 'wallet_server_stats'...")
|
||||
c.execute("""
|
||||
CREATE TABLE wallet_server_stats (
|
||||
server text,
|
||||
sessions integer,
|
||||
event_time timestamp
|
||||
);
|
||||
""")
|
||||
|
||||
c.execute("SELECT to_regclass('wallet_server_slow_queries');")
|
||||
if c.fetchone()[0] is None:
|
||||
print("creating table 'wallet_server_slow_queries'...")
|
||||
c.execute("""
|
||||
CREATE TABLE wallet_server_slow_queries (
|
||||
server text,
|
||||
command text,
|
||||
query text,
|
||||
event_time timestamp
|
||||
);
|
||||
""")
|
||||
|
||||
c.execute("SELECT to_regclass('wallet_server_command_stats');")
|
||||
if c.fetchone()[0] is None:
|
||||
print("creating table 'wallet_server_command_stats'...")
|
||||
c.execute("""
|
||||
CREATE TABLE wallet_server_command_stats (
|
||||
server text,
|
||||
command text,
|
||||
event_time timestamp,
|
||||
|
||||
-- total requests received during event window
|
||||
receive_count integer,
|
||||
|
||||
-- sum of these is total responses made
|
||||
cache_response_count integer,
|
||||
query_response_count integer,
|
||||
intrp_response_count integer,
|
||||
error_response_count integer,
|
||||
|
||||
-- millisecond timings for non-cache responses (response_*, interrupt_*, error_*)
|
||||
|
||||
response_avg float,
|
||||
response_min float,
|
||||
response_five float,
|
||||
response_twenty_five float,
|
||||
response_fifty float,
|
||||
response_seventy_five float,
|
||||
response_ninety_five float,
|
||||
response_max float,
|
||||
|
||||
interrupt_avg float,
|
||||
interrupt_min float,
|
||||
interrupt_five float,
|
||||
interrupt_twenty_five float,
|
||||
interrupt_fifty float,
|
||||
interrupt_seventy_five float,
|
||||
interrupt_ninety_five float,
|
||||
interrupt_max float,
|
||||
|
||||
error_avg float,
|
||||
error_min float,
|
||||
error_five float,
|
||||
error_twenty_five float,
|
||||
error_fifty float,
|
||||
error_seventy_five float,
|
||||
error_ninety_five float,
|
||||
error_max float,
|
||||
|
||||
-- response, interrupt and error each also report the python, wait and sql stats
|
||||
|
||||
python_avg float,
|
||||
python_min float,
|
||||
python_five float,
|
||||
python_twenty_five float,
|
||||
python_fifty float,
|
||||
python_seventy_five float,
|
||||
python_ninety_five float,
|
||||
python_max float,
|
||||
|
||||
wait_avg float,
|
||||
wait_min float,
|
||||
wait_five float,
|
||||
wait_twenty_five float,
|
||||
wait_fifty float,
|
||||
wait_seventy_five float,
|
||||
wait_ninety_five float,
|
||||
wait_max float,
|
||||
|
||||
sql_avg float,
|
||||
sql_min float,
|
||||
sql_five float,
|
||||
sql_twenty_five float,
|
||||
sql_fifty float,
|
||||
sql_seventy_five float,
|
||||
sql_ninety_five float,
|
||||
sql_max float,
|
||||
|
||||
-- extended timings for individual sql executions
|
||||
individual_sql_avg float,
|
||||
individual_sql_min float,
|
||||
individual_sql_five float,
|
||||
individual_sql_twenty_five float,
|
||||
individual_sql_fifty float,
|
||||
individual_sql_seventy_five float,
|
||||
individual_sql_ninety_five float,
|
||||
individual_sql_max float,
|
||||
|
||||
individual_sql_count integer
|
||||
);
|
||||
""")
|
||||
db.commit()
|
||||
return db
|
||||
|
||||
|
||||
def get_dsn(args):
|
||||
dsn = {}
|
||||
for attr in ('dbname', 'user', 'password', 'host', 'port'):
|
||||
value = getattr(args, f'pg_{attr}')
|
||||
if value:
|
||||
dsn[attr] = value
|
||||
return dsn
|
||||
|
||||
|
||||
def get_servers(args):
|
||||
if '..' in args.server_range:
|
||||
start, end = args.server_range.split('..')
|
||||
else:
|
||||
start = end = args.server_range
|
||||
return [
|
||||
args.server_url.format(i)
|
||||
for i in range(int(start), int(end)+1)
|
||||
]
|
||||
|
||||
|
||||
def get_slack_client(args):
|
||||
if args.slack_token:
|
||||
return slack.WebClient(token=args.slack_token, run_async=True)
|
||||
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("--pg-dbname", default="analytics", help="PostgreSQL database name")
|
||||
parser.add_argument("--pg-user", help="PostgreSQL username")
|
||||
parser.add_argument("--pg-password", help="PostgreSQL password")
|
||||
parser.add_argument("--pg-host", default="localhost", help="PostgreSQL host")
|
||||
parser.add_argument("--pg-port", default="5432", help="PostgreSQL port")
|
||||
parser.add_argument("--server-url", default="http://spv{}.lbry.com:50005", help="URL with '{}' placeholder")
|
||||
parser.add_argument("--server-range", default="1..5", help="Range of numbers or single number to use in URL placeholder")
|
||||
parser.add_argument("--slack-token")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
args = get_args()
|
||||
SLACKCLIENT = get_slack_client(args)
|
||||
try:
|
||||
loop.run_until_complete(main(get_dsn(args), get_servers(args)))
|
||||
except KeyboardInterrupt as e:
|
||||
pass
|
||||
except Exception as e:
|
||||
loop.run_until_complete(boris_says("<!channel> I crashed with the following exception:"))
|
||||
loop.run_until_complete(boris_says(traceback.format_exc()))
|
||||
finally:
|
||||
loop.run_until_complete(
|
||||
boris_says(random.choice([
|
||||
"Wallet servers will have to watch themselves, I'm leaving now.",
|
||||
"I'm going to go take a nap, hopefully nothing blows up while I'm gone.",
|
||||
"Babushka is calling, I'll be back later, someone else watch the servers while I'm gone.",
|
||||
]))
|
||||
)
|
||||
+1
-1
@@ -25,7 +25,7 @@ setup(
|
||||
install_requires=[
|
||||
'torba',
|
||||
'aiohttp==3.5.4',
|
||||
'aioupnp==0.0.13',
|
||||
'aioupnp==0.0.14',
|
||||
'appdirs==1.4.3',
|
||||
'certifi>=2018.11.29',
|
||||
'colorama==0.3.7',
|
||||
|
||||
@@ -8,7 +8,7 @@ if typing.TYPE_CHECKING:
|
||||
from lbry.dht.protocol.protocol import KademliaProtocol
|
||||
|
||||
|
||||
def get_time_accelerator(loop: asyncio.BaseEventLoop,
|
||||
def get_time_accelerator(loop: asyncio.AbstractEventLoop,
|
||||
now: typing.Optional[float] = None) -> typing.Callable[[float], typing.Awaitable[None]]:
|
||||
"""
|
||||
Returns an async advance() function
|
||||
@@ -48,7 +48,7 @@ def get_time_accelerator(loop: asyncio.BaseEventLoop,
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def mock_network_loop(loop: asyncio.BaseEventLoop):
|
||||
def mock_network_loop(loop: asyncio.AbstractEventLoop):
|
||||
dht_network: typing.Dict[typing.Tuple[str, int], 'KademliaProtocol'] = {}
|
||||
|
||||
async def create_datagram_endpoint(proto_lam: typing.Callable[[], 'KademliaProtocol'],
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
import asyncio
|
||||
import sqlite3
|
||||
from lbry.testcase import CommandTestCase
|
||||
from torba.client.basedatabase import SQLiteMixin
|
||||
from lbry.wallet.dewies import dewies_to_lbc
|
||||
from lbry.wallet.account import Account
|
||||
|
||||
|
||||
def extract(d, keys):
|
||||
return dict((k, d[k]) for k in keys)
|
||||
|
||||
|
||||
class AccountManagement(CommandTestCase):
|
||||
async def test_sqlite_binding_error(self):
|
||||
tasks = [
|
||||
self.loop.create_task(self.daemon.jsonrpc_account_create('second account' + str(x))) for x in range(100)
|
||||
]
|
||||
await asyncio.wait(tasks)
|
||||
for result in tasks:
|
||||
self.assertFalse(isinstance(result.result(), Exception))
|
||||
|
||||
async def test_account_list_set_create_remove_add(self):
|
||||
# check initial account
|
||||
@@ -65,3 +81,101 @@ class AccountManagement(CommandTestCase):
|
||||
self.account.channel_keys[keys[1]] = "some invalid junk"
|
||||
await self.account.maybe_migrate_certificates()
|
||||
self.assertEqual(list(self.account.channel_keys.keys()), [keys[2]])
|
||||
|
||||
async def assertFindsClaims(self, claim_names, awaitable):
|
||||
self.assertEqual(claim_names, [txo.claim_name for txo in await awaitable])
|
||||
|
||||
async def assertOutputAmount(self, amounts, awaitable):
|
||||
self.assertEqual(amounts, [dewies_to_lbc(txo.amount) for txo in await awaitable])
|
||||
|
||||
async def test_commands_across_accounts(self):
|
||||
channel_list = self.daemon.jsonrpc_channel_list
|
||||
stream_list = self.daemon.jsonrpc_stream_list
|
||||
support_list = self.daemon.jsonrpc_support_list
|
||||
utxo_list = self.daemon.jsonrpc_utxo_list
|
||||
default_account = self.daemon.default_account
|
||||
second_account = await self.daemon.jsonrpc_account_create('second account')
|
||||
|
||||
tx = await self.daemon.jsonrpc_account_send(
|
||||
'0.05', await self.daemon.jsonrpc_address_unused(account_id=second_account.id)
|
||||
)
|
||||
await self.confirm_tx(tx.id)
|
||||
await self.assertOutputAmount(['0.05', '9.949876'], utxo_list())
|
||||
await self.assertOutputAmount(['0.05'], utxo_list(account_id=second_account.id))
|
||||
await self.assertOutputAmount(['9.949876'], utxo_list(account_id=default_account.id))
|
||||
|
||||
channel1 = await self.channel_create('@channel-in-account1', '0.01')
|
||||
channel2 = await self.channel_create(
|
||||
'@channel-in-account2', '0.01', account_id=second_account.id, funding_account_ids=[default_account.id]
|
||||
)
|
||||
|
||||
await self.assertFindsClaims(['@channel-in-account2', '@channel-in-account1'], channel_list())
|
||||
await self.assertFindsClaims(['@channel-in-account1'], channel_list(account_id=default_account.id))
|
||||
await self.assertFindsClaims(['@channel-in-account2'], channel_list(account_id=second_account.id))
|
||||
|
||||
stream1 = await self.stream_create('stream-in-account1', '0.01', channel_id=self.get_claim_id(channel1))
|
||||
stream2 = await self.stream_create(
|
||||
'stream-in-account2', '0.01', channel_id=self.get_claim_id(channel2),
|
||||
account_id=second_account.id, funding_account_ids=[default_account.id]
|
||||
)
|
||||
await self.assertFindsClaims(['stream-in-account2', 'stream-in-account1'], stream_list())
|
||||
await self.assertFindsClaims(['stream-in-account1'], stream_list(account_id=default_account.id))
|
||||
await self.assertFindsClaims(['stream-in-account2'], stream_list(account_id=second_account.id))
|
||||
|
||||
await self.assertFindsClaims(
|
||||
['stream-in-account2', 'stream-in-account1', '@channel-in-account2', '@channel-in-account1'],
|
||||
self.daemon.jsonrpc_claim_list()
|
||||
)
|
||||
await self.assertFindsClaims(
|
||||
['stream-in-account1', '@channel-in-account1'],
|
||||
self.daemon.jsonrpc_claim_list(account_id=default_account.id)
|
||||
)
|
||||
await self.assertFindsClaims(
|
||||
['stream-in-account2', '@channel-in-account2'],
|
||||
self.daemon.jsonrpc_claim_list(account_id=second_account.id)
|
||||
)
|
||||
|
||||
support1 = await self.support_create(self.get_claim_id(stream1), '0.01')
|
||||
support2 = await self.support_create(
|
||||
self.get_claim_id(stream2), '0.01', account_id=second_account.id, funding_account_ids=[default_account.id]
|
||||
)
|
||||
self.assertEqual([support2['txid'], support1['txid']], [txo.tx_ref.id for txo in await support_list()])
|
||||
self.assertEqual([support1['txid']], [txo.tx_ref.id for txo in await support_list(account_id=default_account.id)])
|
||||
self.assertEqual([support2['txid']], [txo.tx_ref.id for txo in await support_list(account_id=second_account.id)])
|
||||
|
||||
history = await self.daemon.jsonrpc_transaction_list()
|
||||
self.assertEqual(len(history), 8)
|
||||
self.assertEqual(extract(history[0]['support_info'][0], ['claim_name', 'is_tip', 'amount', 'balance_delta']), {
|
||||
'claim_name': 'stream-in-account2',
|
||||
'is_tip': False,
|
||||
'amount': '0.01',
|
||||
'balance_delta': '-0.01'
|
||||
})
|
||||
self.assertEqual(extract(history[1]['support_info'][0], ['claim_name', 'is_tip', 'amount', 'balance_delta']), {
|
||||
'claim_name': 'stream-in-account1',
|
||||
'is_tip': False,
|
||||
'amount': '0.01',
|
||||
'balance_delta': '-0.01'
|
||||
})
|
||||
self.assertEqual(extract(history[2]['claim_info'][0], ['claim_name', 'amount', 'balance_delta']), {
|
||||
'claim_name': 'stream-in-account2',
|
||||
'amount': '0.01',
|
||||
'balance_delta': '-0.01'
|
||||
})
|
||||
self.assertEqual(extract(history[3]['claim_info'][0], ['claim_name', 'amount', 'balance_delta']), {
|
||||
'claim_name': 'stream-in-account1',
|
||||
'amount': '0.01',
|
||||
'balance_delta': '-0.01'
|
||||
})
|
||||
self.assertEqual(extract(history[4]['claim_info'][0], ['claim_name', 'amount', 'balance_delta']), {
|
||||
'claim_name': '@channel-in-account2',
|
||||
'amount': '0.01',
|
||||
'balance_delta': '-0.01'
|
||||
})
|
||||
self.assertEqual(extract(history[5]['claim_info'][0], ['claim_name', 'amount', 'balance_delta']), {
|
||||
'claim_name': '@channel-in-account1',
|
||||
'amount': '0.01',
|
||||
'balance_delta': '-0.01'
|
||||
})
|
||||
self.assertEqual(history[6]['value'], '0.0')
|
||||
self.assertEqual(history[7]['value'], '10.0')
|
||||
@@ -10,7 +10,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
||||
|
||||
# Chris45 starts everyday by checking his balance.
|
||||
result = await self.daemon.jsonrpc_account_balance()
|
||||
self.assertEqual(result, '10.0')
|
||||
self.assertEqual(result['available'], '10.0')
|
||||
# "10 LBC, yippy! I can do a lot with that.", he thinks to himself,
|
||||
# enthusiastically. But he is hungry so he goes into the kitchen
|
||||
# to make himself a spamdwich.
|
||||
@@ -31,12 +31,12 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
||||
# Chris doesn't sit idly by: he checks his balance!
|
||||
|
||||
result = await self.daemon.jsonrpc_account_balance()
|
||||
self.assertEqual(result, '8.989893')
|
||||
self.assertEqual(result['available'], '8.989893')
|
||||
|
||||
# He waits for 6 more blocks (confirmations) to make sure the balance has been settled.
|
||||
await self.generate(6)
|
||||
result = await self.daemon.jsonrpc_account_balance(confirmations=6)
|
||||
self.assertEqual(result, '8.989893')
|
||||
self.assertEqual(result['available'], '8.989893')
|
||||
|
||||
# And is the channel resolvable and empty?
|
||||
response = await self.resolve('lbry://@spam')
|
||||
@@ -59,7 +59,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
||||
# He quickly checks the unconfirmed balance to make sure everything looks
|
||||
# correct.
|
||||
result = await self.daemon.jsonrpc_account_balance()
|
||||
self.assertEqual(result, '7.969786')
|
||||
self.assertEqual(result['available'], '7.969786')
|
||||
|
||||
# Also checks that his new story can be found on the blockchain before
|
||||
# giving the link to all his friends.
|
||||
@@ -70,7 +70,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
||||
await self.generate(5)
|
||||
# When he comes back he verifies the confirmed balance.
|
||||
result = await self.daemon.jsonrpc_account_balance()
|
||||
self.assertEqual(result, '7.969786')
|
||||
self.assertEqual(result['available'], '7.969786')
|
||||
|
||||
# As people start reading his story they discover some typos and notify
|
||||
# Chris who explains in despair "Oh! Noooooos!" but then remembers
|
||||
@@ -93,7 +93,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.9693455')
|
||||
self.assertEqual(result['available'], '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
|
||||
@@ -109,11 +109,11 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
||||
await self.generate(5)
|
||||
result = await self.daemon.jsonrpc_account_balance()
|
||||
# Chris' balance was correct
|
||||
self.assertEqual(result, '7.9692215')
|
||||
self.assertEqual(result['available'], '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)
|
||||
self.assertEqual(result, '1.0')
|
||||
self.assertEqual(result['available'], '1.0')
|
||||
|
||||
# After Chris is done with all the "helping other people" stuff he decides that it's time to
|
||||
# write a new story and publish it to lbry. All he needed was a fresh start and he came up with:
|
||||
|
||||
@@ -89,6 +89,7 @@ class ClaimSearchCommand(ClaimTestCase):
|
||||
await self.assertFindsClaims([claim], **kwargs)
|
||||
|
||||
async def assertFindsClaims(self, claims, **kwargs):
|
||||
kwargs.setdefault('order_by', ['height', '^name'])
|
||||
results = await self.claim_search(**kwargs)
|
||||
self.assertEqual(len(claims), len(results))
|
||||
for claim, result in zip(claims, results):
|
||||
@@ -165,21 +166,29 @@ class ClaimSearchCommand(ClaimTestCase):
|
||||
await self.create_channel()
|
||||
await self.create_lots_of_streams()
|
||||
|
||||
page = await self.claim_search(page_size=20, channel='@abc')
|
||||
page = await self.claim_search(page_size=20, channel='@abc', order_by=['height', '^name'])
|
||||
page_claim_ids = [item['name'] for item in page]
|
||||
self.assertEqual(page_claim_ids, self.streams)
|
||||
|
||||
page = await self.claim_search(page_size=6, channel='@abc')
|
||||
page = await self.claim_search(page_size=6, channel='@abc', order_by=['height', '^name'])
|
||||
page_claim_ids = [item['name'] for item in page]
|
||||
self.assertEqual(page_claim_ids, self.streams[:6])
|
||||
|
||||
page = await self.claim_search(page=2, page_size=6, channel='@abc')
|
||||
page = await self.claim_search(page=2, page_size=6, channel='@abc', order_by=['height', '^name'])
|
||||
page_claim_ids = [item['name'] for item in page]
|
||||
self.assertEqual(page_claim_ids, self.streams[6:])
|
||||
|
||||
out_of_bounds = await self.claim_search(page=2, page_size=20, channel='@abc')
|
||||
self.assertEqual(out_of_bounds, [])
|
||||
|
||||
results = await self.daemon.jsonrpc_claim_search()
|
||||
self.assertEqual(results['total_pages'], 2)
|
||||
self.assertEqual(results['total_items'], 13)
|
||||
|
||||
results = await self.daemon.jsonrpc_claim_search(no_totals=True)
|
||||
self.assertNotIn('total_pages', results)
|
||||
self.assertNotIn('total_items', results)
|
||||
|
||||
async def test_tag_search(self):
|
||||
claim1 = await self.stream_create('claim1', tags=['aBc'])
|
||||
claim2 = await self.stream_create('claim2', tags=['#abc', 'def'])
|
||||
@@ -217,7 +226,7 @@ class ClaimSearchCommand(ClaimTestCase):
|
||||
await self.assertFindsClaims([claim4, claim3, claim2], all_tags=['abc'], any_tags=['def', 'ghi'])
|
||||
|
||||
async def test_order_by(self):
|
||||
height = await self.ledger.network.get_server_height()
|
||||
height = self.ledger.network.remote_height
|
||||
claims = [await self.stream_create(f'claim{i}') for i in range(5)]
|
||||
|
||||
await self.assertFindsClaims(claims, order_by=["^height"])
|
||||
@@ -469,7 +478,8 @@ class ChannelCommands(CommandTestCase):
|
||||
tx = await self.out(self.channel_update(claim_id, claim_address=other_address))
|
||||
|
||||
# after sending
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_channel_list()), 2)
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_channel_list()), 3)
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_channel_list(account_id=self.account.id)), 2)
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_channel_list(account_id=account2_id)), 1)
|
||||
|
||||
# shoud not have private key
|
||||
@@ -489,44 +499,9 @@ class ChannelCommands(CommandTestCase):
|
||||
claim_id = self.get_claim_id(tx)
|
||||
channel_private_key = (await self.account.get_channels())[0].private_key
|
||||
exported_data = await self.out(self.daemon.jsonrpc_channel_export(claim_id))
|
||||
|
||||
daemon2 = await self.add_daemon()
|
||||
|
||||
# before importing channel
|
||||
self.assertEqual(1, len(daemon2.default_wallet.accounts))
|
||||
|
||||
# importing channel which will create a new single key account
|
||||
await daemon2.jsonrpc_channel_import(exported_data)
|
||||
|
||||
# after import
|
||||
self.assertEqual(2, len(daemon2.default_wallet.accounts))
|
||||
new_account = daemon2.default_wallet.accounts[1]
|
||||
await daemon2.ledger._update_tasks.done.wait()
|
||||
channels = await new_account.get_channels()
|
||||
self.assertEqual(1, len(channels))
|
||||
self.assertEqual(channel_private_key.to_string(), channels[0].private_key.to_string())
|
||||
|
||||
async def test_channel_export_import_into_existing_account(self):
|
||||
tx = await self.channel_create('@foo', '1.0')
|
||||
claim_id = self.get_claim_id(tx)
|
||||
channel_private_key = (await self.account.get_channels())[0].private_key
|
||||
exported_data = await self.out(self.daemon.jsonrpc_channel_export(claim_id))
|
||||
|
||||
daemon2 = await self.add_daemon(seed=self.account.seed)
|
||||
await daemon2.ledger._update_tasks.done.wait() # will sync channel previously created
|
||||
|
||||
# before importing channel key, has channel without key
|
||||
self.assertEqual(1, len(daemon2.default_wallet.accounts))
|
||||
channels = await daemon2.default_account.get_channels()
|
||||
self.assertEqual(1, len(channels))
|
||||
self.assertIsNone(channels[0].private_key)
|
||||
|
||||
# importing channel will add it to existing account
|
||||
await daemon2.jsonrpc_channel_import(exported_data)
|
||||
|
||||
# after import, still just one account but with private key now
|
||||
self.assertEqual(1, len(daemon2.default_wallet.accounts))
|
||||
channels = await daemon2.default_account.get_channels()
|
||||
channels = await daemon2.jsonrpc_channel_list()
|
||||
self.assertEqual(1, len(channels))
|
||||
self.assertEqual(channel_private_key.to_string(), channels[0].private_key.to_string())
|
||||
|
||||
@@ -593,15 +568,15 @@ class StreamCommands(ClaimTestCase):
|
||||
account2_id, account2 = new_account['id'], self.daemon.get_account_or_error(new_account['id'])
|
||||
|
||||
await self.out(self.channel_create('@spam', '1.0'))
|
||||
self.assertEqual('8.989893', await self.daemon.jsonrpc_account_balance())
|
||||
self.assertEqual('8.989893', (await self.daemon.jsonrpc_account_balance())['available'])
|
||||
|
||||
result = await self.out(self.daemon.jsonrpc_account_send(
|
||||
'5.0', await self.daemon.jsonrpc_address_unused(account2_id)
|
||||
))
|
||||
await self.confirm_tx(result['txid'])
|
||||
|
||||
self.assertEqual('3.989769', await self.daemon.jsonrpc_account_balance())
|
||||
self.assertEqual('5.0', await self.daemon.jsonrpc_account_balance(account2_id))
|
||||
self.assertEqual('3.989769', (await self.daemon.jsonrpc_account_balance())['available'])
|
||||
self.assertEqual('5.0', (await self.daemon.jsonrpc_account_balance(account2_id))['available'])
|
||||
|
||||
baz_tx = await self.out(self.channel_create('@baz', '1.0', account_id=account2_id))
|
||||
baz_id = self.get_claim_id(baz_tx)
|
||||
@@ -609,12 +584,17 @@ class StreamCommands(ClaimTestCase):
|
||||
channels = await self.out(self.daemon.jsonrpc_channel_list(account1_id))
|
||||
self.assertEqual(len(channels), 1)
|
||||
self.assertEqual(channels[0]['name'], '@spam')
|
||||
self.assertEqual(channels, await self.out(self.daemon.jsonrpc_channel_list()))
|
||||
self.assertEqual(channels, await self.out(self.daemon.jsonrpc_channel_list(account1_id)))
|
||||
|
||||
channels = await self.out(self.daemon.jsonrpc_channel_list(account2_id))
|
||||
self.assertEqual(len(channels), 1)
|
||||
self.assertEqual(channels[0]['name'], '@baz')
|
||||
|
||||
channels = await self.out(self.daemon.jsonrpc_channel_list())
|
||||
self.assertEqual(len(channels), 2)
|
||||
self.assertEqual(channels[0]['name'], '@baz')
|
||||
self.assertEqual(channels[1]['name'], '@spam')
|
||||
|
||||
# defaults to using all accounts to lookup channel
|
||||
await self.stream_create('hovercraft1', '0.1', channel_id=baz_id)
|
||||
self.assertEqual((await self.claim_search(name='hovercraft1'))[0]['signing_channel']['name'], '@baz')
|
||||
@@ -638,6 +618,15 @@ class StreamCommands(ClaimTestCase):
|
||||
'hovercraft5', '0.1', channel_name='@baz', channel_account_id=[account1_id]
|
||||
)
|
||||
|
||||
# signing with channel works even if channel and certificate are in different accounts
|
||||
await self.channel_update(
|
||||
baz_id, account_id=account2_id,
|
||||
claim_address=await self.daemon.jsonrpc_address_unused(account1_id)
|
||||
)
|
||||
await self.stream_create(
|
||||
'hovercraft5', '0.1', channel_id=baz_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))
|
||||
@@ -797,13 +786,15 @@ class StreamCommands(ClaimTestCase):
|
||||
|
||||
# before sending
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_claim_list()), 4)
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_claim_list(account_id=self.account.id)), 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()), 3)
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_claim_list()), 4)
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_claim_list(account_id=self.account.id)), 3)
|
||||
self.assertEqual(len(await self.daemon.jsonrpc_claim_list(account_id=account2_id)), 1)
|
||||
|
||||
async def test_setting_fee_fields(self):
|
||||
@@ -1103,8 +1094,7 @@ class SupportCommands(CommandTestCase):
|
||||
await self.assertBalance(account2, '5.0')
|
||||
|
||||
# create the claim we'll be tipping and supporting
|
||||
tx = await self.stream_create()
|
||||
claim_id = self.get_claim_id(tx)
|
||||
claim_id = self.get_claim_id(await self.stream_create())
|
||||
|
||||
# account1 and account2 balances:
|
||||
await self.assertBalance(self.account, '3.979769')
|
||||
@@ -1112,18 +1102,17 @@ class SupportCommands(CommandTestCase):
|
||||
|
||||
# send a tip to the claim using account2
|
||||
tip = await self.out(
|
||||
self.daemon.jsonrpc_support_create(claim_id, '1.0', True, account2_id)
|
||||
self.daemon.jsonrpc_support_create(
|
||||
claim_id, '1.0', True, account2_id, funding_account_ids=[account2_id])
|
||||
)
|
||||
await self.on_transaction_dict(tip)
|
||||
await self.generate(1)
|
||||
await self.on_transaction_dict(tip)
|
||||
await self.confirm_tx(tip['txid'])
|
||||
|
||||
# tips don't affect balance so account1 balance is same but account2 balance went down
|
||||
await self.assertBalance(self.account, '3.979769')
|
||||
await self.assertBalance(account2, '3.9998585')
|
||||
|
||||
# verify that the incoming tip is marked correctly as is_tip=True in account1
|
||||
txs = await self.out(self.daemon.jsonrpc_transaction_list())
|
||||
txs = await self.out(self.daemon.jsonrpc_transaction_list(self.account.id))
|
||||
self.assertEqual(len(txs[0]['support_info']), 1)
|
||||
self.assertEqual(txs[0]['support_info'][0]['balance_delta'], '1.0')
|
||||
self.assertEqual(txs[0]['support_info'][0]['claim_id'], claim_id)
|
||||
@@ -1144,11 +1133,10 @@ class SupportCommands(CommandTestCase):
|
||||
|
||||
# send a support to the claim using account2
|
||||
support = await self.out(
|
||||
self.daemon.jsonrpc_support_create(claim_id, '2.0', False, account2_id)
|
||||
self.daemon.jsonrpc_support_create(
|
||||
claim_id, '2.0', False, account2_id, funding_account_ids=[account2_id])
|
||||
)
|
||||
await self.on_transaction_dict(support)
|
||||
await self.generate(1)
|
||||
await self.on_transaction_dict(support)
|
||||
await self.confirm_tx(support['txid'])
|
||||
|
||||
# account2 balance went down ~2
|
||||
await self.assertBalance(self.account, '3.979769')
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import time
|
||||
from math import ceil
|
||||
|
||||
from aiohttp import web
|
||||
@@ -14,6 +15,20 @@ class MockedCommentServer:
|
||||
'INVALID_METHOD': {'code': -32604, 'message': 'The Requested method does not exist'}
|
||||
}
|
||||
|
||||
COMMENT_SCHEMA = {
|
||||
'comment': None,
|
||||
'comment_id': None,
|
||||
'claim_id': None,
|
||||
'parent_id': None,
|
||||
'channel_name': None,
|
||||
'channel_id': None,
|
||||
'signature': None,
|
||||
'signing_ts': None,
|
||||
'timestamp': None,
|
||||
'channel_url': None,
|
||||
'is_hidden': False,
|
||||
}
|
||||
|
||||
def __init__(self, port=2903):
|
||||
self.port = port
|
||||
self.app = web.Application(debug=True)
|
||||
@@ -23,36 +38,119 @@ class MockedCommentServer:
|
||||
self.comments = []
|
||||
self.comment_id = 0
|
||||
|
||||
def create_comment(self, **comment):
|
||||
self.comment_id += 1
|
||||
comment['comment_id'] = self.comment_id
|
||||
if 'channel_id' in comment:
|
||||
comment['channel_url'] = 'lbry://' + comment['channel_name'] + '#' + comment['channel_id']
|
||||
self.comments.append(comment)
|
||||
return comment
|
||||
@classmethod
|
||||
def _create_comment(cls, **kwargs):
|
||||
schema = cls.COMMENT_SCHEMA.copy()
|
||||
schema.update(**kwargs)
|
||||
return schema
|
||||
|
||||
def get_claim_comments(self, page=1, page_size=50, **kwargs):
|
||||
@staticmethod
|
||||
def clean(d: dict):
|
||||
return {k: v for k, v in d.items() if v or isinstance(v, bool)}
|
||||
|
||||
def create_comment(self, channel_name=None, channel_id=None, **kwargs):
|
||||
comment_id = self.comment_id
|
||||
channel_url = 'lbry://' + channel_name + '#' + channel_id if channel_id else None
|
||||
comment = self._create_comment(
|
||||
comment_id=str(comment_id),
|
||||
channel_name=channel_name,
|
||||
channel_id=channel_id,
|
||||
channel_url=channel_url,
|
||||
timestamp=str(int(time.time())),
|
||||
**kwargs
|
||||
)
|
||||
self.comments.append(comment)
|
||||
self.comment_id += 1
|
||||
return self.clean(comment)
|
||||
|
||||
def abandon_comment(self, comment_id: int, channel_id: str, **kwargs):
|
||||
deleted = False
|
||||
try:
|
||||
if 0 <= comment_id < len(self.comments) and self.comments[comment_id]['channel_id'] == channel_id:
|
||||
self.comments.pop(comment_id)
|
||||
deleted = True
|
||||
finally:
|
||||
return {
|
||||
str(comment_id): {
|
||||
'abandoned': deleted
|
||||
}
|
||||
}
|
||||
|
||||
def hide_comment(self, comment_id, signing_ts, signature):
|
||||
comment_id = int(comment_id) if not isinstance(comment_id, int) else comment_id
|
||||
if 0 <= comment_id < len(self.comments) and len(signature) == 128 and signing_ts.isalnum():
|
||||
self.comments[comment_id]['is_hidden'] = True
|
||||
return True
|
||||
return False
|
||||
|
||||
def hide_comments(self, pieces: list):
|
||||
comments_hidden = []
|
||||
for p in pieces:
|
||||
if self.hide_comment(**p):
|
||||
comments_hidden.append(p['comment_id'])
|
||||
return {'hidden': comments_hidden}
|
||||
|
||||
def get_claim_comments(self, claim_id, page=1, page_size=50,**kwargs):
|
||||
comments = list(filter(lambda c: c['claim_id'] == claim_id, self.comments))
|
||||
return {
|
||||
'page': page,
|
||||
'page_size': page_size,
|
||||
'total_pages': ceil(len(self.comments)/page_size),
|
||||
'total_items': len(self.comments),
|
||||
'items': (self.comments[::-1])[(page - 1) * page_size: page * page_size]
|
||||
'total_pages': ceil(len(comments)/page_size),
|
||||
'total_items': len(comments),
|
||||
'items': [self.clean(c) for c in (comments[::-1])[(page - 1) * page_size: page * page_size]],
|
||||
'has_hidden_comments': bool(list(filter(lambda x: x['is_hidden'], comments)))
|
||||
}
|
||||
|
||||
def get_claim_hidden_comments(self, claim_id, hidden=True, page=1, page_size=50):
|
||||
comments = list(filter(lambda c: c['claim_id'] == claim_id, self.comments))
|
||||
select_comments = list(filter(lambda c: c['is_hidden'] == hidden, comments))
|
||||
return {
|
||||
'page': page,
|
||||
'page_size': page_size,
|
||||
'total_pages': ceil(len(select_comments) / page_size),
|
||||
'total_items': len(select_comments),
|
||||
'items': [self.clean(c) for c in (select_comments[::-1])[(page - 1) * page_size: page * page_size]],
|
||||
'has_hidden_comments': bool(list(filter(lambda c: c['is_hidden'], comments)))
|
||||
}
|
||||
|
||||
def get_comment_channel_by_id(self, comment_id: int, **kwargs):
|
||||
comment = self.comments[comment_id]
|
||||
return {
|
||||
'channel_id': comment.get('channel_id'),
|
||||
'channel_name': comment.get('channel_name')
|
||||
}
|
||||
|
||||
def get_comments_by_id(self, comment_ids: list):
|
||||
comment_ids = [int(c) if not isinstance(c, int) else c for c in comment_ids]
|
||||
comments = [self.comments[cmnt_id] for cmnt_id in comment_ids if 0 <= cmnt_id < len(self.comments)]
|
||||
return comments
|
||||
|
||||
methods = {
|
||||
'get_claim_comments': get_claim_comments,
|
||||
'get_comments_by_id': get_comments_by_id,
|
||||
'create_comment': create_comment,
|
||||
'abandon_comment': abandon_comment,
|
||||
'get_channel_from_comment_id': get_comment_channel_by_id,
|
||||
'get_claim_hidden_comments': get_claim_hidden_comments,
|
||||
'hide_comments': hide_comments,
|
||||
}
|
||||
|
||||
def process_json(self, body) -> dict:
|
||||
response = {'jsonrpc': '2.0', 'id': body['id']}
|
||||
if body['method'] in self.methods:
|
||||
params = body.get('params', {})
|
||||
result = self.methods[body['method']](self, **params)
|
||||
response['result'] = result
|
||||
else:
|
||||
response['error'] = self.ERRORS['INVALID_METHOD']
|
||||
try:
|
||||
if body['method'] in self.methods:
|
||||
params: dict = body.get('params', {})
|
||||
comment_id = params.get('comment_id')
|
||||
if comment_id and not isinstance(comment_id, int):
|
||||
params['comment_id'] = int(comment_id)
|
||||
|
||||
result = self.methods[body['method']](self, **params)
|
||||
response['result'] = result
|
||||
else:
|
||||
response['error'] = self.ERRORS['INVALID_METHOD']
|
||||
except Exception as err:
|
||||
response['error'] = self.ERRORS['UNKNOWN']
|
||||
response['error'].update({'exception': f'{type(err).__name__}: {err}'})
|
||||
return response
|
||||
|
||||
async def start(self):
|
||||
@@ -123,20 +221,19 @@ class CommentCommands(CommandTestCase):
|
||||
async def test02_unsigned_comment_list(self):
|
||||
stream = (await self.stream_create())['outputs'][0]
|
||||
comments = []
|
||||
for i in range(28):
|
||||
num_items = 28
|
||||
for i in range(num_items):
|
||||
comment = await self.daemon.jsonrpc_comment_create(
|
||||
comment=f'{i}',
|
||||
claim_id=stream['claim_id'],
|
||||
)
|
||||
self.assertIn('comment_id', comment)
|
||||
comments.append(comment)
|
||||
|
||||
comment_list = await self.daemon.jsonrpc_comment_list(
|
||||
claim_id=stream['claim_id']
|
||||
)
|
||||
self.assertIs(comment_list['page_size'], 50)
|
||||
self.assertIs(comment_list['page'], 1)
|
||||
self.assertIs(comment_list['total_items'], 28)
|
||||
list_fields = ['items', 'page', 'page_size', 'has_hidden_comments', 'total_items', 'total_pages']
|
||||
comment_list = await self.daemon.jsonrpc_comment_list(stream['claim_id'])
|
||||
for field in list_fields:
|
||||
self.assertIn(field, comment_list)
|
||||
self.assertEqual(comment_list['total_items'], num_items)
|
||||
for comment in comment_list['items']:
|
||||
self.assertEqual(comment['comment'], comments.pop()['comment'])
|
||||
|
||||
@@ -158,10 +255,12 @@ class CommentCommands(CommandTestCase):
|
||||
)
|
||||
self.assertIn('comment_id', comment)
|
||||
comments.append(comment)
|
||||
|
||||
list_fields = ['items', 'page', 'page_size', 'has_hidden_comments', 'total_items', 'total_pages']
|
||||
comment_list = await self.daemon.jsonrpc_comment_list(
|
||||
claim_id=stream['claim_id']
|
||||
)
|
||||
for field in list_fields:
|
||||
self.assertIn(field, comment_list)
|
||||
self.assertIs(comment_list['page_size'], 50)
|
||||
self.assertIs(comment_list['page'], 1)
|
||||
self.assertIs(comment_list['total_items'], 28)
|
||||
@@ -173,3 +272,130 @@ class CommentCommands(CommandTestCase):
|
||||
is_channel_signature_valid=True
|
||||
)
|
||||
self.assertIs(len(signed_comment_list['items']), 28)
|
||||
|
||||
async def test04_comment_abandons(self):
|
||||
rswanson = (await self.channel_create('@RonSwanson'))['outputs'][0]
|
||||
stream = (await self.stream_create('Pawnee Town Hall of Fame by Leslie Knope'))['outputs'][0]
|
||||
comment = await self.daemon.jsonrpc_comment_create(
|
||||
comment='KNOPE! WHAT DID I TELL YOU ABOUT PUTTING MY INFORMATION UP LIKE THAT',
|
||||
claim_id=stream['claim_id'],
|
||||
channel_id=rswanson['claim_id']
|
||||
)
|
||||
self.assertIn('signature', comment)
|
||||
abandoned = await self.daemon.jsonrpc_comment_abandon(comment['comment_id'])
|
||||
self.assertIn(comment['comment_id'], abandoned)
|
||||
self.assertTrue(abandoned[comment['comment_id']]['abandoned'])
|
||||
|
||||
abandoned = await self.daemon.jsonrpc_comment_abandon(comment['comment_id'])
|
||||
self.assertFalse(abandoned[comment['comment_id']]['abandoned'])
|
||||
|
||||
async def test05_comment_hide(self):
|
||||
moth = (await self.channel_create('@InconspicuousMoth'))['outputs'][0]
|
||||
bee = (await self.channel_create('@LazyBumblebee'))['outputs'][0]
|
||||
moth_id = moth['claim_id']
|
||||
stream = await self.stream_create('Cool Lamps to Sit On', channel_id=moth_id)
|
||||
claim_id = stream['outputs'][0]['claim_id']
|
||||
|
||||
comment1 = await self.daemon.jsonrpc_comment_create(
|
||||
comment='Who on earth would want to sit around on a lamp all day',
|
||||
claim_id=claim_id,
|
||||
channel_id=bee['claim_id']
|
||||
)
|
||||
self.assertFalse(comment1['is_hidden'])
|
||||
|
||||
comment2 = await self.daemon.jsonrpc_comment_create(
|
||||
comment='silence mortal',
|
||||
claim_id=claim_id,
|
||||
channel_id=moth_id,
|
||||
)
|
||||
self.assertFalse(comment2['is_hidden'])
|
||||
|
||||
comments = await self.daemon.jsonrpc_comment_list(claim_id)
|
||||
self.assertIn('has_hidden_comments', comments)
|
||||
self.assertFalse(comments['has_hidden_comments'])
|
||||
|
||||
hidden = await self.daemon.jsonrpc_comment_hide([comment1['comment_id']])
|
||||
self.assertIn('hidden', hidden)
|
||||
hidden = hidden['hidden']
|
||||
self.assertIn(comment1['comment_id'], hidden)
|
||||
|
||||
comments = await self.daemon.jsonrpc_comment_list(claim_id)
|
||||
self.assertIn('has_hidden_comments', comments)
|
||||
self.assertTrue(comments['has_hidden_comments'])
|
||||
hidden_cmts1 = list(filter(lambda c: c['is_hidden'], comments['items']))
|
||||
self.assertTrue(len(hidden_cmts1) == 1)
|
||||
hidden_comment = hidden_cmts1[0]
|
||||
self.assertEqual(hidden_comment['comment_id'], hidden[0])
|
||||
|
||||
hidden_comments = await self.daemon.jsonrpc_comment_list(claim_id, hidden=True)
|
||||
self.assertIn('has_hidden_comments', hidden_comments)
|
||||
self.assertTrue(hidden_comments['has_hidden_comments'])
|
||||
self.assertLess(hidden_comments['total_items'], comments['total_items'])
|
||||
self.assertListEqual(hidden_comments['items'], hidden_cmts1)
|
||||
|
||||
visible_comments = await self.daemon.jsonrpc_comment_list(claim_id, visible=True)
|
||||
self.assertIn('has_hidden_comments', visible_comments)
|
||||
self.assertTrue(visible_comments['has_hidden_comments'])
|
||||
self.assertLess(visible_comments['total_items'], comments['total_items'])
|
||||
total_hidden = hidden_comments['total_items']
|
||||
total_visible = visible_comments['total_items']
|
||||
self.assertEqual(total_hidden + total_visible, comments['total_items'])
|
||||
|
||||
items_hidden = hidden_comments['items']
|
||||
items_visible = visible_comments['items']
|
||||
for item in items_visible + items_hidden:
|
||||
self.assertIn(item, comments['items'])
|
||||
|
||||
async def test06_comment_list_test(self):
|
||||
moth = (await self.channel_create('@InconspicuousMoth'))['outputs'][0]
|
||||
bee = (await self.channel_create('@LazyBumblebee'))['outputs'][0]
|
||||
moth_id = moth['claim_id']
|
||||
stream = await self.stream_create('Cool Lamps to Sit On', channel_id=moth_id)
|
||||
claim_id = stream['outputs'][0]['claim_id']
|
||||
hidden_comment = await self.daemon.jsonrpc_comment_create(
|
||||
comment='Who on earth would want to sit around on a lamp all day',
|
||||
claim_id=claim_id,
|
||||
channel_id=bee['claim_id']
|
||||
)
|
||||
await self.daemon.jsonrpc_comment_hide([hidden_comment['comment_id']])
|
||||
owner_comment = await self.daemon.jsonrpc_comment_create(
|
||||
comment='Go away you yellow freak',
|
||||
claim_id=claim_id,
|
||||
channel_id=moth_id,
|
||||
)
|
||||
other_comment = await self.daemon.jsonrpc_comment_create(
|
||||
comment='I got my swim trunks and my flippy-floppies',
|
||||
claim_id=claim_id,
|
||||
channel_id=bee['claim_id']
|
||||
)
|
||||
anon_comment = await self.daemon.jsonrpc_comment_create(
|
||||
claim_id=claim_id,
|
||||
comment='Anonymous comment'
|
||||
)
|
||||
all_comments = [anon_comment, other_comment, owner_comment, hidden_comment]
|
||||
list_fields = ['items', 'page', 'page_size', 'has_hidden_comments', 'total_items', 'total_pages']
|
||||
normal_list = await self.daemon.jsonrpc_comment_list(claim_id)
|
||||
for field in list_fields:
|
||||
self.assertIn(field, normal_list)
|
||||
self.assertEqual(normal_list['total_items'], 4)
|
||||
self.assertTrue(normal_list['has_hidden_comments'])
|
||||
for i, cmnt in enumerate(all_comments):
|
||||
self.assertEqual(cmnt['comment_id'], normal_list['items'][i]['comment_id'])
|
||||
|
||||
hidden = await self.daemon.jsonrpc_comment_list(claim_id, hidden=True)
|
||||
self.assertTrue(hidden['has_hidden_comments'])
|
||||
for field in list_fields:
|
||||
self.assertIn(field, hidden)
|
||||
self.assertEqual(hidden['total_items'], 1)
|
||||
|
||||
visible = await self.daemon.jsonrpc_comment_list(claim_id, visible=True)
|
||||
for field in list_fields:
|
||||
self.assertIn(field, visible)
|
||||
self.assertTrue(visible['has_hidden_comments'])
|
||||
self.assertEqual(visible['total_items'], normal_list['total_items'] - hidden['total_items'])
|
||||
|
||||
valid_list = await self.daemon.jsonrpc_comment_list(claim_id, is_channel_signature_valid=True)
|
||||
for field in list_fields:
|
||||
self.assertIn(field, valid_list)
|
||||
self.assertTrue(visible['has_hidden_comments'])
|
||||
self.assertEqual(len(valid_list['items']), len(normal_list['items']) - 1)
|
||||
@@ -34,7 +34,7 @@ class DHTIntegrationTest(AsyncioTestCase):
|
||||
|
||||
async def test_replace_bad_nodes(self):
|
||||
await self.setup_network(20)
|
||||
self.assertEquals(len(self.nodes), 20)
|
||||
self.assertEqual(len(self.nodes), 20)
|
||||
node = self.nodes[0]
|
||||
bad_peers = []
|
||||
for candidate in self.nodes[1:10]:
|
||||
|
||||
@@ -277,6 +277,24 @@ class FileCommands(CommandTestCase):
|
||||
self.assertEqual(response['content_fee']['outputs'][0]['amount'], '2.0')
|
||||
self.assertEqual(response['content_fee']['outputs'][0]['address'], target_address)
|
||||
|
||||
async def test_null_fee(self):
|
||||
target_address = await self.blockchain.get_raw_change_address()
|
||||
tx = await self.stream_create(
|
||||
'nullfee', '0.01', data=b'no pay me, no',
|
||||
fee_currency='LBC', fee_address=target_address, fee_amount='1.0'
|
||||
)
|
||||
await self.__raw_value_update_no_fee_amount(tx, target_address)
|
||||
await self.daemon.jsonrpc_file_delete(claim_name='nullfee')
|
||||
response = await self.daemon.jsonrpc_get('lbry://nullfee')
|
||||
self.assertEqual(len(self.daemon.jsonrpc_file_list()), 1)
|
||||
self.assertIsNone(response.content_fee)
|
||||
self.assertTrue(response.stream_claim_info.claim.stream.has_fee)
|
||||
self.assertDictEqual(
|
||||
response.stream_claim_info.claim.stream.to_dict()['fee'],
|
||||
{'currency': 'LBC', 'address': target_address}
|
||||
)
|
||||
await self.daemon.jsonrpc_file_delete(claim_name='nullfee')
|
||||
|
||||
async def __raw_value_update_no_fee_address(self, tx, claim_address, **kwargs):
|
||||
tx = await self.daemon.jsonrpc_stream_update(
|
||||
self.get_claim_id(tx), preview=True, claim_address=claim_address, **kwargs
|
||||
@@ -286,3 +304,14 @@ class FileCommands(CommandTestCase):
|
||||
await tx.sign([self.account])
|
||||
await self.broadcast(tx)
|
||||
await self.confirm_tx(tx.id)
|
||||
|
||||
async def __raw_value_update_no_fee_amount(self, tx, claim_address):
|
||||
tx = await self.daemon.jsonrpc_stream_update(
|
||||
self.get_claim_id(tx), preview=True, fee_currency='LBC', fee_amount='1.0', fee_address=claim_address,
|
||||
claim_address=claim_address
|
||||
)
|
||||
tx.outputs[0].claim.stream.fee.message.ClearField('amount')
|
||||
tx.outputs[0].script.generate()
|
||||
await tx.sign([self.account])
|
||||
await self.broadcast(tx)
|
||||
await self.confirm_tx(tx.id)
|
||||
@@ -84,3 +84,31 @@ class AccountSynchronization(AsyncioTestCase):
|
||||
self.daemon.jsonrpc_sync_apply('password', data=add_cert)
|
||||
self.assertEqual(self.daemon.jsonrpc_sync_hash(), hash_w_cert)
|
||||
self.assertEqual(self.account.channel_keys, {'abcdefg1234:0': '---PRIVATE KEY---'})
|
||||
|
||||
@mock.patch('time.time', mock.Mock(return_value=12345))
|
||||
def test_account_preferences_syncing(self):
|
||||
starting_hash = '69afcd60a300f47933917d77ef011beeeb4decfafebbda91c144c84282c6814f'
|
||||
self.account.modified_on = 123.456
|
||||
self.assertEqual(self.daemon.jsonrpc_sync_hash(), starting_hash)
|
||||
self.assertEqual(self.daemon.jsonrpc_sync_apply('password')['hash'], starting_hash)
|
||||
self.assertFalse(self.daemon.jsonrpc_preference_get())
|
||||
|
||||
hash_w_pref = '2fe43f0b2f8bbf1fbb55537f862d8bcb0823791019a7151c848bd5f5bd32d336'
|
||||
add_pref = (
|
||||
'czo4MTkyOjE2OjE6Jgn3nAGrfYP2usMA4KQ/73+YHAwMyiGdSWuxCmgZKlpwSpnfQv8R7R0tum/n2oTSBQxjdL'
|
||||
'OlTW+tv/G5L2GfQ5op3xaT89gN+F/JJnvf3cdWvYH7Nc+uTUMb7cKhJP7hQvFW5bb1Y3jX3EBBY00Jkqyj9RCR'
|
||||
'XPtbLVu71KbVRvCAR/oAnMEsgD+ITsC3WkXMwE3BS2LjJDQmeqbH4YXNdcjJN/JzQ6fxOmr3Uk1GqnpuhFsta8'
|
||||
'H14ViRilq1pLKOSZIN80rrm5cKq45nFO5kFeoqBCEaal4u2/OkX9nOnpQlO3E95wD8hkCmZ3i20aSte6nqwqXx'
|
||||
'ZKVRZqR2a0TjwVWB8kPXPA2ewKvPILaj190bXPl8EVu+TAnTCQwMgytinYjtcKNZmMz3ENJyI2mCANwpWlX7xl'
|
||||
'y/J+qLi5b9N+agghTxggs5rVJ/hkaue7GS542dXDrwMrw9nwGqNw3dS/lcU+1wRUQ0fnHwb/85XbbwyO2aDj2i'
|
||||
'DFNkdyLyUIiIUvB1JfWAnWqX3vQcL1REK1ePgUei7dCHJ3WyWdsRx3cVXzlK8yOPkf0N6d3AKrZQWVebwDC7Nd'
|
||||
'eL4sDW8AkaXuBIrbuZw6XUHd6WI0NvU/q10j2qMm0YoXSu+dExou1/1THwx5g86MxcX5nwodKUEVCOTzKMyrLz'
|
||||
'CRsitH/+dAXhZNRp/FbnDCGBMyD3MOYCjZvAFbCZUasoRwqponxILw=='
|
||||
)
|
||||
self.daemon.jsonrpc_sync_apply('password', data=add_pref)
|
||||
self.assertEqual(self.daemon.jsonrpc_sync_hash(), hash_w_pref)
|
||||
self.assertEqual(self.daemon.jsonrpc_preference_get(), {"fruit": ["apple", "orange"]})
|
||||
|
||||
self.daemon.jsonrpc_preference_set("fruit", ["peach", "apricot"])
|
||||
self.assertEqual(self.daemon.jsonrpc_preference_get(), {"fruit": ["peach", "apricot"]})
|
||||
self.assertNotEqual(self.daemon.jsonrpc_sync_hash(), hash_w_pref)
|
||||
@@ -36,3 +36,79 @@ class TransactionCommandsTestCase(CommandTestCase):
|
||||
await self.assertBalance(self.account, '0.0')
|
||||
await self.daemon.jsonrpc_utxo_release()
|
||||
await self.assertBalance(self.account, '11.0')
|
||||
|
||||
async def test_granular_balances(self):
|
||||
account_balance = self.daemon.jsonrpc_account_balance
|
||||
|
||||
self.assertEqual(await account_balance(reserved_subtotals=False), {
|
||||
'total': '10.0',
|
||||
'available': '10.0',
|
||||
'reserved': '0.0',
|
||||
'reserved_subtotals': None
|
||||
})
|
||||
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '10.0',
|
||||
'available': '10.0',
|
||||
'reserved': '0.0',
|
||||
'reserved_subtotals': {'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
# claim with update + supporting our own claim
|
||||
stream1 = await self.stream_create('granularity', '3.0')
|
||||
await self.stream_update(self.get_claim_id(stream1), data=b'news', bid='1.0')
|
||||
await self.support_create(self.get_claim_id(stream1), '2.0')
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '9.977534',
|
||||
'available': '6.977534',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
account2 = await self.daemon.jsonrpc_account_create("Tip-er")
|
||||
address2 = await self.daemon.jsonrpc_address_unused(account2.id)
|
||||
|
||||
# send lbc to someone else
|
||||
tx = await self.daemon.jsonrpc_account_send('1.0', address2)
|
||||
await self.confirm_tx(tx.id)
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '8.97741',
|
||||
'available': '5.97741',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
# tip received
|
||||
support1 = await self.support_create(
|
||||
self.get_claim_id(stream1), '0.3', tip=True, funding_account_ids=[account2.id]
|
||||
)
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '9.27741',
|
||||
'available': '5.97741',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||
})
|
||||
|
||||
# tip claimed
|
||||
tx = await self.daemon.jsonrpc_support_abandon(txid=support1['txid'], nout=0)
|
||||
await self.confirm_tx(tx.id)
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '9.277303',
|
||||
'available': '6.277303',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
stream2 = await self.stream_create(
|
||||
'granularity-is-cool', '0.1', account_id=account2.id, funding_account_ids=[account2.id]
|
||||
)
|
||||
|
||||
# tip another claim
|
||||
await self.support_create(
|
||||
self.get_claim_id(stream2), '0.2', tip=True, funding_account_ids=[self.account.id])
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '9.077157',
|
||||
'available': '6.077157',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
@@ -0,0 +1,61 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
import lbry.wallet
|
||||
from lbry.testcase import CommandTestCase
|
||||
from lbry.extras.daemon.Components import HeadersComponent
|
||||
from torba.client.basenetwork import ClientSession
|
||||
from torba.testcase import IntegrationTestCase
|
||||
|
||||
|
||||
class TestSessionBloat(IntegrationTestCase):
|
||||
"""
|
||||
Tests that server cleans up stale connections after session timeout and client times out too.
|
||||
"""
|
||||
|
||||
LEDGER = lbry.wallet
|
||||
|
||||
async def test_session_bloat_from_socket_timeout(self):
|
||||
await self.conductor.stop_spv()
|
||||
await self.ledger.stop()
|
||||
self.conductor.spv_node.session_timeout = 1
|
||||
await self.conductor.start_spv()
|
||||
session = ClientSession(
|
||||
network=None, server=(self.conductor.spv_node.hostname, self.conductor.spv_node.port), timeout=0.2
|
||||
)
|
||||
await session.create_connection()
|
||||
await session.send_request('server.banner', ())
|
||||
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 1)
|
||||
self.assertFalse(session.is_closing())
|
||||
await asyncio.sleep(1.1)
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
await session.send_request('server.banner', ())
|
||||
self.assertTrue(session.is_closing())
|
||||
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0)
|
||||
|
||||
|
||||
class TestSegwitServer(IntegrationTestCase):
|
||||
LEDGER = lbry.wallet
|
||||
ENABLE_SEGWIT = True
|
||||
|
||||
async def test_at_least_it_starts(self):
|
||||
await asyncio.wait_for(self.ledger.network.get_headers(0, 1), 1.0)
|
||||
|
||||
|
||||
class TestHeadersComponent(CommandTestCase):
|
||||
|
||||
LEDGER = lbry.wallet
|
||||
|
||||
async def asyncSetUp(self):
|
||||
await super().asyncSetUp()
|
||||
self.component_manager = self.daemon.component_manager
|
||||
self.component_manager.conf.blockchain_name = 'lbrycrd_main'
|
||||
self.headers_component = HeadersComponent(self.component_manager)
|
||||
|
||||
async def test_cant_reach_host(self):
|
||||
HeadersComponent.HEADERS_URL = 'notthere/'
|
||||
os.unlink(self.headers_component.headers.path)
|
||||
# test is that this doesnt raise
|
||||
await self.headers_component.start()
|
||||
self.assertTrue(self.component_manager.get_components_status()['blockchain_headers'])
|
||||
self.assertEqual(await self.headers_component.get_status(), {})
|
||||
@@ -17,6 +17,18 @@ class TestBlobManager(AsyncioTestCase):
|
||||
self.blob_manager = BlobManager(self.loop, tmp_dir, self.storage, self.config)
|
||||
await self.storage.open()
|
||||
|
||||
async def test_memory_blobs_arent_verifie_but_real_ones_are(self):
|
||||
for save_blobs in (False, True):
|
||||
await self.setup_blob_manager(save_blobs=save_blobs)
|
||||
# add a blob file
|
||||
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
|
||||
blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
|
||||
blob = self.blob_manager.get_blob(blob_hash, len(blob_bytes))
|
||||
blob.save_verified_blob(blob_bytes)
|
||||
self.assertTrue(blob.get_is_verified())
|
||||
self.blob_manager.blob_completed(blob)
|
||||
self.assertEqual(self.blob_manager.is_blob_verified(blob_hash), save_blobs)
|
||||
|
||||
async def test_sync_blob_file_manager_on_startup(self):
|
||||
await self.setup_blob_manager(save_blobs=True)
|
||||
|
||||
|
||||
@@ -225,3 +225,84 @@ class TestBlobExchange(BlobExchangeTestBase):
|
||||
server_protocol.data_received(bytes([byte]))
|
||||
await asyncio.sleep(0.1) # yield execution
|
||||
self.assertTrue(len(received_data.getvalue()) > 0)
|
||||
|
||||
async def test_idle_timeout(self):
|
||||
self.server.idle_timeout = 1
|
||||
|
||||
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
|
||||
mock_blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
|
||||
await self._add_blob_to_server(blob_hash, mock_blob_bytes)
|
||||
client_blob = self.client_blob_manager.get_blob(blob_hash)
|
||||
|
||||
# download the blob
|
||||
downloaded, protocol = await request_blob(self.loop, client_blob, self.server_from_client.address,
|
||||
self.server_from_client.tcp_port, 2, 3)
|
||||
self.assertIsNotNone(protocol)
|
||||
self.assertFalse(protocol.transport.is_closing())
|
||||
await client_blob.verified.wait()
|
||||
self.assertTrue(client_blob.get_is_verified())
|
||||
self.assertTrue(downloaded)
|
||||
client_blob.delete()
|
||||
|
||||
# wait for less than the idle timeout
|
||||
await asyncio.sleep(0.5, loop=self.loop)
|
||||
|
||||
# download the blob again
|
||||
downloaded, protocol2 = await request_blob(self.loop, client_blob, self.server_from_client.address,
|
||||
self.server_from_client.tcp_port, 2, 3,
|
||||
connected_protocol=protocol)
|
||||
self.assertTrue(protocol is protocol2)
|
||||
self.assertFalse(protocol.transport.is_closing())
|
||||
await client_blob.verified.wait()
|
||||
self.assertTrue(client_blob.get_is_verified())
|
||||
self.assertTrue(downloaded)
|
||||
client_blob.delete()
|
||||
|
||||
# check that the connection times out from the server side
|
||||
await asyncio.sleep(0.9, loop=self.loop)
|
||||
self.assertFalse(protocol.transport.is_closing())
|
||||
self.assertIsNotNone(protocol.transport._sock)
|
||||
await asyncio.sleep(0.1, loop=self.loop)
|
||||
self.assertIsNone(protocol.transport)
|
||||
|
||||
def test_max_request_size(self):
|
||||
protocol = BlobServerProtocol(self.loop, self.server_blob_manager, 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
|
||||
called = asyncio.Event()
|
||||
protocol.close = called.set
|
||||
protocol.data_received(b'0' * 1199)
|
||||
self.assertFalse(called.is_set())
|
||||
protocol.data_received(b'0')
|
||||
self.assertTrue(called.is_set())
|
||||
|
||||
def test_bad_json(self):
|
||||
protocol = BlobServerProtocol(self.loop, self.server_blob_manager, 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
|
||||
called = asyncio.Event()
|
||||
protocol.close = called.set
|
||||
protocol.data_received(b'{{0}')
|
||||
self.assertTrue(called.is_set())
|
||||
|
||||
def test_no_request(self):
|
||||
protocol = BlobServerProtocol(self.loop, self.server_blob_manager, 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
|
||||
called = asyncio.Event()
|
||||
protocol.close = called.set
|
||||
protocol.data_received(b'{}')
|
||||
self.assertTrue(called.is_set())
|
||||
|
||||
async def test_transfer_timeout(self):
|
||||
self.server.transfer_timeout = 1
|
||||
|
||||
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
|
||||
mock_blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
|
||||
await self._add_blob_to_server(blob_hash, mock_blob_bytes)
|
||||
client_blob = self.client_blob_manager.get_blob(blob_hash)
|
||||
server_blob = self.server_blob_manager.get_blob(blob_hash)
|
||||
|
||||
async def sendfile(writer):
|
||||
await asyncio.sleep(2, loop=self.loop)
|
||||
return 0
|
||||
|
||||
server_blob.sendfile = sendfile
|
||||
|
||||
with self.assertRaises(asyncio.CancelledError):
|
||||
await request_blob(self.loop, client_blob, self.server_from_client.address,
|
||||
self.server_from_client.tcp_port, 2, 3)
|
||||
@@ -1,5 +1,5 @@
|
||||
from torba.testcase import AsyncioTestCase
|
||||
|
||||
import hashlib
|
||||
from lbry.extras.daemon.comment_client import sign_comment
|
||||
from lbry.extras.daemon.comment_client import is_comment_signed_by_channel
|
||||
|
||||
@@ -14,7 +14,8 @@ class TestSigningComments(AsyncioTestCase):
|
||||
'claim_id': claim.claim_id,
|
||||
'channel_name': channel.claim_name,
|
||||
'channel_id': channel.claim_id,
|
||||
'comment': comment
|
||||
'comment': comment,
|
||||
'comment_id': hashlib.sha256(comment.encode()).hexdigest()
|
||||
}
|
||||
|
||||
def test01_successful_create_sign_and_validate_comment(self):
|
||||
@@ -31,3 +32,28 @@ class TestSigningComments(AsyncioTestCase):
|
||||
comment = self.create_claim_comment_body('Woahh This is Sick!! Shout out 2 my boy Tommy H', stream, pdiddy)
|
||||
sign_comment(comment, channel2)
|
||||
self.assertFalse(is_comment_signed_by_channel(comment, pdiddy))
|
||||
|
||||
def test03_successful_sign_abandon_comment(self):
|
||||
rswanson = get_channel('@RonSwanson')
|
||||
dsilver = get_stream('Welcome to the Pawnee, and give a big round for Ron Swanson, AKA Duke Silver')
|
||||
comment_body = self.create_claim_comment_body('COMPUTER, DELETE ALL VIDEOS OF RON.', dsilver, rswanson)
|
||||
sign_comment(comment_body, rswanson, abandon=True)
|
||||
self.assertTrue(is_comment_signed_by_channel(comment_body, rswanson, abandon=True))
|
||||
|
||||
def test04_invalid_signature(self):
|
||||
rswanson = get_channel('@RonSwanson')
|
||||
jeanralphio = get_channel('@JeanRalphio')
|
||||
chair = get_stream('This is a nice chair. I made it with Mahogany wood and this electric saw')
|
||||
chair_comment = self.create_claim_comment_body(
|
||||
'Hah. You use an electric saw? Us swansons have been making chairs with handsaws just three after birth.',
|
||||
chair,
|
||||
rswanson
|
||||
)
|
||||
sign_comment(chair_comment, rswanson)
|
||||
self.assertTrue(is_comment_signed_by_channel(chair_comment, rswanson))
|
||||
self.assertFalse(is_comment_signed_by_channel(chair_comment, jeanralphio))
|
||||
fake_abandon_signal = chair_comment.copy()
|
||||
sign_comment(fake_abandon_signal, jeanralphio, abandon=True)
|
||||
self.assertFalse(is_comment_signed_by_channel(fake_abandon_signal, rswanson, abandon=True))
|
||||
self.assertFalse(is_comment_signed_by_channel(fake_abandon_signal, jeanralphio, abandon=True))
|
||||
|
||||
@@ -72,6 +72,13 @@ class TestLanguages(TestCase):
|
||||
self.assertEqual(stream.languages[2].region, 'US')
|
||||
self.assertEqual(stream.langtags, ['en', 'en-US', 'en-Latn-US'])
|
||||
|
||||
stream.languages.append('es-419')
|
||||
self.assertEqual(stream.languages[3].langtag, 'es-419')
|
||||
self.assertEqual(stream.languages[3].language, 'es')
|
||||
self.assertEqual(stream.languages[3].script, None)
|
||||
self.assertEqual(stream.languages[3].region, '419')
|
||||
self.assertEqual(stream.langtags, ['en', 'en-US', 'en-Latn-US', 'es-419'])
|
||||
|
||||
stream = Stream()
|
||||
stream.languages.extend(['en-Latn-US', 'es-ES', 'de-DE'])
|
||||
self.assertEqual(stream.languages[0].language, 'en')
|
||||
|
||||
@@ -11,9 +11,13 @@ class TestTagNormalization(unittest.TestCase):
|
||||
def test_normalize_tag(self):
|
||||
tag = self.assertNormalizedTag
|
||||
tag('', ' \t #!~')
|
||||
tag('tag', 'Tag')
|
||||
tag('tag', 'T\'ag')
|
||||
tag('t ag', '\tT \nAG ')
|
||||
tag('tag hash', '#tag~#hash!')
|
||||
|
||||
def test_clean_tags(self):
|
||||
self.assertEqual(['tag'], clean_tags([' \t #!~', '!taG', '\t']))
|
||||
cleaned = clean_tags(['fOo', '!taG', 'FoO'])
|
||||
self.assertIn('tag', cleaned)
|
||||
self.assertIn('foo', cleaned)
|
||||
self.assertEqual(len(cleaned), 2)
|
||||
@@ -40,6 +40,15 @@ class TestManagedStream(BlobExchangeTestBase):
|
||||
self.loop, self.client_config, self.client_blob_manager, self.sd_hash, self.client_dir
|
||||
)
|
||||
|
||||
async def test_status_file_completed(self):
|
||||
await self._test_transfer_stream(10)
|
||||
self.assertTrue(self.stream.output_file_exists)
|
||||
self.assertTrue(self.stream.completed)
|
||||
with open(self.stream.full_path, 'w+b') as outfile:
|
||||
outfile.truncate(1)
|
||||
self.assertTrue(self.stream.output_file_exists)
|
||||
self.assertFalse(self.stream.completed)
|
||||
|
||||
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)
|
||||
@@ -52,7 +61,7 @@ class TestManagedStream(BlobExchangeTestBase):
|
||||
|
||||
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()
|
||||
await self.stream.finished_write_attempt.wait()
|
||||
self.assertTrue(os.path.isfile(self.stream.full_path))
|
||||
if stop_when_done:
|
||||
await self.stream.stop()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
import binascii
|
||||
from unittest import mock
|
||||
import asyncio
|
||||
@@ -77,6 +78,7 @@ def get_mock_wallet(sd_hash, storage, balance=10.0, fee=None):
|
||||
|
||||
mock_wallet = mock.Mock(spec=LbryWalletManager)
|
||||
mock_wallet.ledger.resolve = mock_resolve
|
||||
mock_wallet.ledger.network.client.server = ('fakespv.lbry.com', 50001)
|
||||
|
||||
async def get_balance(*_):
|
||||
return balance
|
||||
@@ -130,6 +132,7 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
head_blob_duration = event['properties']['head_blob_duration']
|
||||
sd_blob_duration = event['properties']['sd_blob_duration']
|
||||
self.assertFalse(event['properties']['added_fixed_peers'])
|
||||
self.assertEqual(event['properties']['wallet_server'], "fakespv.lbry.com:50001")
|
||||
self.assertTrue(total_duration >= resolve_duration + head_blob_duration + sd_blob_duration)
|
||||
|
||||
await self._test_time_to_first_bytes(check_post)
|
||||
@@ -152,6 +155,7 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
self.assertEqual(event['event'], 'Time To First Bytes')
|
||||
self.assertEqual(event['properties']['tried_peers_count'], 1)
|
||||
self.assertEqual(event['properties']['active_peer_count'], 1)
|
||||
self.assertEqual(event['properties']['connection_failures_count'], 0)
|
||||
self.assertEqual(event['properties']['use_fixed_peers'], True)
|
||||
self.assertEqual(event['properties']['added_fixed_peers'], True)
|
||||
self.assertEqual(event['properties']['fixed_peer_delay'], self.client_config.fixed_peer_delay)
|
||||
@@ -159,6 +163,24 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
|
||||
await self._test_time_to_first_bytes(check_post, after_setup=after_setup)
|
||||
|
||||
async def test_tcp_connection_failure_analytics(self):
|
||||
self.client_config.download_timeout = 3.0
|
||||
|
||||
def after_setup():
|
||||
self.server.stop_server()
|
||||
|
||||
def check_post(event):
|
||||
self.assertEqual(event['event'], 'Time To First Bytes')
|
||||
self.assertIsNone(event['properties']['head_blob_duration'])
|
||||
self.assertIsNone(event['properties']['sd_blob_duration'])
|
||||
self.assertFalse(event['properties']['added_fixed_peers'])
|
||||
self.assertEqual(event['properties']['connection_failures_count'], 1)
|
||||
self.assertEqual(
|
||||
event['properties']['error_message'], f'Failed to download sd blob {self.sd_hash} within timeout'
|
||||
)
|
||||
|
||||
await self._test_time_to_first_bytes(check_post, DownloadSDTimeout, after_setup=after_setup)
|
||||
|
||||
async def test_override_fixed_peer_delay_dht_disabled(self):
|
||||
self.client_config.reflector_servers = [(self.server_from_client.address, self.server_from_client.tcp_port - 1)]
|
||||
self.client_config.components_to_skip = ['dht', 'hash_announcer']
|
||||
@@ -197,6 +219,9 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
self.assertEqual(event['properties']['use_fixed_peers'], False)
|
||||
self.assertEqual(event['properties']['added_fixed_peers'], False)
|
||||
self.assertEqual(event['properties']['fixed_peer_delay'], None)
|
||||
self.assertEqual(
|
||||
event['properties']['error_message'], f'Failed to download sd blob {self.sd_hash} within timeout'
|
||||
)
|
||||
|
||||
start = self.loop.time()
|
||||
await self._test_time_to_first_bytes(check_post, DownloadSDTimeout)
|
||||
@@ -256,14 +281,21 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
self.assertListEqual(expected_events, received)
|
||||
|
||||
async def _test_download_error_on_start(self, expected_error, timeout=None):
|
||||
with self.assertRaises(expected_error):
|
||||
error = None
|
||||
try:
|
||||
await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager, timeout)
|
||||
except Exception as err:
|
||||
if isinstance(err, asyncio.CancelledError):
|
||||
raise
|
||||
error = err
|
||||
self.assertEqual(expected_error, type(error))
|
||||
|
||||
async def _test_download_error_analytics_on_start(self, expected_error, timeout=None):
|
||||
async def _test_download_error_analytics_on_start(self, expected_error, error_message, timeout=None):
|
||||
received = []
|
||||
|
||||
async def check_post(event):
|
||||
self.assertEqual("Time To First Bytes", event['event'])
|
||||
self.assertEqual(event['properties']['error_message'], error_message)
|
||||
received.append(event['properties']['error'])
|
||||
|
||||
self.stream_manager.analytics_manager._post = check_post
|
||||
@@ -279,7 +311,7 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
'version': '_0_0_1'
|
||||
}
|
||||
await self.setup_stream_manager(10.0, fee)
|
||||
await self._test_download_error_on_start(InsufficientFundsError)
|
||||
await self._test_download_error_on_start(InsufficientFundsError, "")
|
||||
|
||||
async def test_fee_above_max_allowed(self):
|
||||
fee = {
|
||||
@@ -289,7 +321,7 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
'version': '_0_0_1'
|
||||
}
|
||||
await self.setup_stream_manager(1000000.0, fee)
|
||||
await self._test_download_error_on_start(KeyFeeAboveMaxAllowed)
|
||||
await self._test_download_error_on_start(KeyFeeAboveMaxAllowed, "")
|
||||
|
||||
async def test_resolve_error(self):
|
||||
await self.setup_stream_manager()
|
||||
@@ -299,14 +331,27 @@ class TestStreamManager(BlobExchangeTestBase):
|
||||
async def test_download_sd_timeout(self):
|
||||
self.server.stop_server()
|
||||
await self.setup_stream_manager()
|
||||
await self._test_download_error_analytics_on_start(DownloadSDTimeout, timeout=1)
|
||||
await self._test_download_error_analytics_on_start(
|
||||
DownloadSDTimeout, f'Failed to download sd blob {self.sd_hash} within timeout', timeout=1
|
||||
)
|
||||
|
||||
async def test_download_data_timeout(self):
|
||||
await self.setup_stream_manager()
|
||||
with open(os.path.join(self.server_dir, self.sd_hash), 'r') as sdf:
|
||||
head_blob_hash = json.loads(sdf.read())['blobs'][0]['blob_hash']
|
||||
self.server_blob_manager.delete_blob(head_blob_hash)
|
||||
await self._test_download_error_analytics_on_start(DownloadDataTimeout, timeout=1)
|
||||
await self._test_download_error_analytics_on_start(
|
||||
DownloadDataTimeout, f'Failed to download data blobs for sd hash {self.sd_hash} within timeout', timeout=1
|
||||
)
|
||||
|
||||
async def test_unexpected_error(self):
|
||||
await self.setup_stream_manager()
|
||||
err_msg = f"invalid blob directory '{self.client_dir}'"
|
||||
shutil.rmtree(self.client_dir)
|
||||
await self._test_download_error_analytics_on_start(
|
||||
OSError, err_msg, timeout=1
|
||||
)
|
||||
os.mkdir(self.client_dir) # so the test cleanup doesn't error
|
||||
|
||||
async def test_non_head_data_timeout(self):
|
||||
await self.setup_stream_manager()
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import time
|
||||
import unittest
|
||||
from lbry.wallet.server.metrics import ServerLoadData, calculate_avg_percentiles
|
||||
|
||||
|
||||
class TestPercentileCalculation(unittest.TestCase):
|
||||
|
||||
def test_calculate_percentiles(self):
|
||||
self.assertEqual(calculate_avg_percentiles([]), (0, 0, 0, 0, 0, 0, 0, 0))
|
||||
self.assertEqual(calculate_avg_percentiles([1]), (1, 1, 1, 1, 1, 1, 1, 1))
|
||||
self.assertEqual(calculate_avg_percentiles([1, 2]), (1, 1, 1, 1, 1, 2, 2, 2))
|
||||
self.assertEqual(calculate_avg_percentiles([1, 2, 3]), (2, 1, 1, 1, 2, 3, 3, 3))
|
||||
self.assertEqual(calculate_avg_percentiles([4, 1, 2, 3]), (2, 1, 1, 1, 2, 3, 4, 4))
|
||||
self.assertEqual(calculate_avg_percentiles([1, 2, 3, 4, 5, 6]), (3, 1, 1, 2, 3, 5, 6, 6))
|
||||
self.assertEqual(calculate_avg_percentiles(
|
||||
list(range(1, 101))), (50, 1, 5, 25, 50, 75, 95, 100))
|
||||
|
||||
|
||||
class TestCollectingMetrics(unittest.TestCase):
|
||||
|
||||
def test_happy_path(self):
|
||||
self.maxDiff = None
|
||||
load = ServerLoadData()
|
||||
search = load.for_api('search')
|
||||
self.assertEqual(search.name, 'search')
|
||||
search.start()
|
||||
search.cache_response()
|
||||
search.cache_response()
|
||||
metrics = {
|
||||
'search': [{'total': 40}],
|
||||
'execute_query': [
|
||||
{'total': 20},
|
||||
{'total': 10}
|
||||
]
|
||||
}
|
||||
for x in range(5):
|
||||
search.query_response(time.perf_counter() - 0.055 + 0.001*x, metrics)
|
||||
metrics['execute_query'][0]['total'] = 10
|
||||
metrics['execute_query'][0]['sql'] = "select lots, of, stuff FROM claim where something=1"
|
||||
search.query_interrupt(time.perf_counter() - 0.050, metrics)
|
||||
search.query_error(time.perf_counter() - 0.050, metrics)
|
||||
search.query_error(time.perf_counter() - 0.052, {})
|
||||
self.assertEqual(load.to_json_and_reset({}), {'status': {}, 'api': {'search': {
|
||||
"receive_count": 1,
|
||||
"cache_response_count": 2,
|
||||
"query_response_count": 5,
|
||||
"intrp_response_count": 1,
|
||||
"error_response_count": 2,
|
||||
"response": (53, 51, 51, 52, 53, 54, 55, 55),
|
||||
"interrupt": (50, 50, 50, 50, 50, 50, 50, 50),
|
||||
"error": (51, 50, 50, 50, 50, 52, 52, 52),
|
||||
"python": (12, 10, 10, 10, 10, 20, 20, 20),
|
||||
"wait": (12, 10, 10, 10, 12, 14, 15, 15),
|
||||
"sql": (27, 20, 20, 20, 30, 30, 30, 30),
|
||||
"individual_sql": (13, 10, 10, 10, 10, 20, 20, 20),
|
||||
"individual_sql_count": 14,
|
||||
"errored_queries": ['FROM claim where something=1'],
|
||||
"interrupted_queries": ['FROM claim where something=1'],
|
||||
}}})
|
||||
self.assertEqual(load.to_json_and_reset({}), {'status': {}, 'api': {}})
|
||||
@@ -1,14 +1,15 @@
|
||||
import unittest
|
||||
import ecdsa
|
||||
import hashlib
|
||||
import logging
|
||||
from binascii import hexlify
|
||||
from torba.client.constants import COIN, NULL_HASH32
|
||||
|
||||
from lbry.schema.claim import Claim
|
||||
from lbry.wallet.server.db import SQLDB
|
||||
from lbry.wallet.server.db import reader, writer
|
||||
from lbry.wallet.server.coin import LBCRegTest
|
||||
from lbry.wallet.server.trending import TRENDING_WINDOW
|
||||
from lbry.wallet.server.canonical import FindShortestID
|
||||
from lbry.wallet.server.db.trending import TRENDING_WINDOW
|
||||
from lbry.wallet.server.db.canonical import FindShortestID
|
||||
from lbry.wallet.server.block_processor import Timer
|
||||
from lbry.wallet.transaction import Transaction, Input, Output
|
||||
|
||||
@@ -36,12 +37,17 @@ class OldWalletServerTransaction:
|
||||
|
||||
|
||||
class TestSQLDB(unittest.TestCase):
|
||||
query_timeout = 0.25
|
||||
|
||||
def setUp(self):
|
||||
self.first_sync = False
|
||||
self.daemon_height = 1
|
||||
self.coin = LBCRegTest()
|
||||
self.sql = SQLDB(self, ':memory:')
|
||||
db_url = 'file:test_sqldb?mode=memory&cache=shared'
|
||||
self.sql = writer.SQLDB(self, db_url)
|
||||
self.addCleanup(self.sql.close)
|
||||
reader.initializer(logging.getLogger(__name__), db_url, 'regtest', self.query_timeout)
|
||||
self.addCleanup(reader.cleanup)
|
||||
self.timer = Timer('BlockProcessor')
|
||||
self.sql.open()
|
||||
self._current_height = 0
|
||||
@@ -339,7 +345,7 @@ class TestClaimtrie(TestSQLDB):
|
||||
txo_chan_a = tx_chan_a[0].tx.outputs[0]
|
||||
advance(1, [tx_chan_a])
|
||||
advance(2, [tx_chan_ab])
|
||||
r_ab, r_a = self.sql._search(order_by=['creation_height'], limit=2)
|
||||
r_ab, r_a = reader._search(order_by=['creation_height'], limit=2)
|
||||
self.assertEqual("@foo#a", r_a['short_url'])
|
||||
self.assertEqual("@foo#ab", r_ab['short_url'])
|
||||
self.assertIsNone(r_a['canonical_url'])
|
||||
@@ -352,7 +358,7 @@ class TestClaimtrie(TestSQLDB):
|
||||
tx_abc = self.get_stream_with_claim_id_prefix('abc', 65)
|
||||
advance(3, [tx_a])
|
||||
advance(4, [tx_ab, tx_abc])
|
||||
r_abc, r_ab, r_a = self.sql._search(order_by=['creation_height', 'tx_position'], limit=3)
|
||||
r_abc, r_ab, r_a = reader._search(order_by=['creation_height', 'tx_position'], limit=3)
|
||||
self.assertEqual("foo#a", r_a['short_url'])
|
||||
self.assertEqual("foo#ab", r_ab['short_url'])
|
||||
self.assertEqual("foo#abc", r_abc['short_url'])
|
||||
@@ -366,39 +372,39 @@ class TestClaimtrie(TestSQLDB):
|
||||
ab2_claim_id = tx_ab2[0].tx.outputs[0].claim_id
|
||||
advance(6, [tx_a2])
|
||||
advance(7, [tx_ab2])
|
||||
r_ab2, r_a2 = self.sql._search(order_by=['creation_height'], limit=2)
|
||||
r_ab2, r_a2 = reader._search(order_by=['creation_height'], limit=2)
|
||||
self.assertEqual(f"foo#{a2_claim_id[:2]}", r_a2['short_url'])
|
||||
self.assertEqual(f"foo#{ab2_claim_id[:4]}", r_ab2['short_url'])
|
||||
self.assertEqual("@foo#a/foo#a", r_a2['canonical_url'])
|
||||
self.assertEqual("@foo#a/foo#ab", r_ab2['canonical_url'])
|
||||
self.assertEqual(2, self.sql._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
self.assertEqual(2, reader._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
|
||||
# change channel public key, invaliding stream claim signatures
|
||||
advance(8, [self.get_channel_update(txo_chan_a, COIN, key=b'a')])
|
||||
r_ab2, r_a2 = self.sql._search(order_by=['creation_height'], limit=2)
|
||||
r_ab2, r_a2 = reader._search(order_by=['creation_height'], limit=2)
|
||||
self.assertEqual(f"foo#{a2_claim_id[:2]}", r_a2['short_url'])
|
||||
self.assertEqual(f"foo#{ab2_claim_id[:4]}", r_ab2['short_url'])
|
||||
self.assertIsNone(r_a2['canonical_url'])
|
||||
self.assertIsNone(r_ab2['canonical_url'])
|
||||
self.assertEqual(0, self.sql._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
self.assertEqual(0, reader._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
|
||||
# reinstate previous channel public key (previous stream claim signatures become valid again)
|
||||
channel_update = self.get_channel_update(txo_chan_a, COIN, key=b'c')
|
||||
advance(9, [channel_update])
|
||||
r_ab2, r_a2 = self.sql._search(order_by=['creation_height'], limit=2)
|
||||
r_ab2, r_a2 = reader._search(order_by=['creation_height'], limit=2)
|
||||
self.assertEqual(f"foo#{a2_claim_id[:2]}", r_a2['short_url'])
|
||||
self.assertEqual(f"foo#{ab2_claim_id[:4]}", r_ab2['short_url'])
|
||||
self.assertEqual("@foo#a/foo#a", r_a2['canonical_url'])
|
||||
self.assertEqual("@foo#a/foo#ab", r_ab2['canonical_url'])
|
||||
self.assertEqual(2, self.sql._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
self.assertEqual(2, reader._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
|
||||
# claim abandon updates claims_in_channel
|
||||
advance(10, [self.get_abandon(tx_ab2)])
|
||||
self.assertEqual(1, self.sql._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
self.assertEqual(1, reader._search(claim_id=txo_chan_a.claim_id, limit=1)[0]['claims_in_channel'])
|
||||
|
||||
# delete channel, invaliding stream claim signatures
|
||||
advance(11, [self.get_abandon(channel_update)])
|
||||
r_a2, = self.sql._search(order_by=['creation_height'], limit=1)
|
||||
r_a2, = reader._search(order_by=['creation_height'], limit=1)
|
||||
self.assertEqual(f"foo#{a2_claim_id[:2]}", r_a2['short_url'])
|
||||
self.assertIsNone(r_a2['canonical_url'])
|
||||
|
||||
@@ -436,7 +442,7 @@ class TestTrending(TestSQLDB):
|
||||
self.get_support(up_medium, (20+(window*(2 if window == 7 else 1)))*COIN),
|
||||
self.get_support(up_biggly, (20+(window*(3 if window == 7 else 1)))*COIN),
|
||||
])
|
||||
results = self.sql._search(order_by=['trending_local'])
|
||||
results = reader._search(order_by=['trending_local'])
|
||||
self.assertEqual([c.claim_id for c in claims], [hexlify(c['claim_hash'][::-1]).decode() for c in results])
|
||||
self.assertEqual([10, 6, 2, 0, -2], [int(c['trending_local']) for c in results])
|
||||
self.assertEqual([53, 38, -32, 0, -6], [int(c['trending_global']) for c in results])
|
||||
|
||||
@@ -7,7 +7,6 @@ dist/
|
||||
|
||||
# testing
|
||||
.tox/
|
||||
tests/client_tests/unit/bitcoin_headers
|
||||
torba/bin
|
||||
|
||||
# cache and logs
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import logging
|
||||
import asyncio
|
||||
from unittest.mock import Mock
|
||||
|
||||
from torba.client.basenetwork import BaseNetwork
|
||||
from torba.orchstr8.node import SPVNode
|
||||
from torba.rpc import RPCSession
|
||||
from torba.testcase import IntegrationTestCase, AsyncioTestCase
|
||||
|
||||
|
||||
class NetworkTests(IntegrationTestCase):
|
||||
|
||||
async def test_remote_height_updated_automagically(self):
|
||||
initial_height = self.ledger.network.remote_height
|
||||
await self.blockchain.generate(1)
|
||||
await self.ledger.network.on_header.first
|
||||
self.assertEqual(self.ledger.network.remote_height, initial_height + 1)
|
||||
|
||||
|
||||
class ReconnectTests(IntegrationTestCase):
|
||||
|
||||
VERBOSITY = logging.WARN
|
||||
|
||||
async def test_multiple_servers(self):
|
||||
# we have a secondary node that connects later, so
|
||||
node2 = SPVNode(self.conductor.spv_module, node_number=2)
|
||||
self.ledger.network.config['default_servers'].append((node2.hostname, node2.port))
|
||||
await asyncio.wait_for(self.ledger.stop(), timeout=1)
|
||||
await asyncio.wait_for(self.ledger.start(), timeout=1)
|
||||
self.ledger.network.session_pool.new_connection_event.clear()
|
||||
await node2.start(self.blockchain)
|
||||
# this is only to speed up the test as retrying would take 4+ seconds
|
||||
for session in self.ledger.network.session_pool.sessions:
|
||||
session.trigger_urgent_reconnect.set()
|
||||
await asyncio.wait_for(self.ledger.network.session_pool.new_connection_event.wait(), timeout=1)
|
||||
self.assertEqual(2, len(list(self.ledger.network.session_pool.available_sessions)))
|
||||
self.assertTrue(self.ledger.network.is_connected)
|
||||
switch_event = self.ledger.network.on_connected.first
|
||||
await node2.stop(True)
|
||||
# secondary down, but primary is ok, do not switch! (switches trigger new on_connected events)
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
await asyncio.wait_for(switch_event, timeout=1)
|
||||
|
||||
async def test_connection_drop_still_receives_events_after_reconnected(self):
|
||||
address1 = await self.account.receiving.get_or_create_usable_address()
|
||||
# disconnect and send a new tx, should reconnect and get it
|
||||
self.ledger.network.client.connection_lost(Exception())
|
||||
self.assertFalse(self.ledger.network.is_connected)
|
||||
sendtxid = await self.blockchain.send_to_address(address1, 1.1337)
|
||||
await asyncio.wait_for(self.on_transaction_id(sendtxid), 1.0) # mempool
|
||||
await self.blockchain.generate(1)
|
||||
await self.on_transaction_id(sendtxid) # confirmed
|
||||
self.assertLess(self.ledger.network.client.response_time, 1) # response time properly set lower, we are fine
|
||||
|
||||
await self.assertBalance(self.account, '1.1337')
|
||||
# is it real? are we rich!? let me see this tx...
|
||||
d = self.ledger.network.get_transaction(sendtxid)
|
||||
# what's that smoke on my ethernet cable? oh no!
|
||||
master_client = self.ledger.network.client
|
||||
self.ledger.network.client.connection_lost(Exception())
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
await d
|
||||
self.assertIsNone(master_client.response_time) # response time unknown as it failed
|
||||
# rich but offline? no way, no water, let's retry
|
||||
with self.assertRaisesRegex(ConnectionError, 'connection is not available'):
|
||||
await self.ledger.network.get_transaction(sendtxid)
|
||||
# * goes to pick some water outside... * time passes by and another donation comes in
|
||||
sendtxid = await self.blockchain.send_to_address(address1, 42)
|
||||
await self.blockchain.generate(1)
|
||||
# (this is just so the test doesnt hang forever if it doesnt reconnect)
|
||||
if not self.ledger.network.is_connected:
|
||||
await asyncio.wait_for(self.ledger.network.on_connected.first, timeout=1.0)
|
||||
# omg, the burned cable still works! torba is fire proof!
|
||||
await self.ledger.network.get_transaction(sendtxid)
|
||||
|
||||
async def test_timeout_then_reconnect(self):
|
||||
# tests that it connects back after some failed attempts
|
||||
await self.conductor.spv_node.stop()
|
||||
self.assertFalse(self.ledger.network.is_connected)
|
||||
await asyncio.sleep(0.2) # let it retry and fail once
|
||||
await self.conductor.spv_node.start(self.conductor.blockchain_node)
|
||||
await self.ledger.network.on_connected.first
|
||||
self.assertTrue(self.ledger.network.is_connected)
|
||||
|
||||
|
||||
class ServerPickingTestCase(AsyncioTestCase):
|
||||
|
||||
async def _make_fake_server(self, latency=1.0, port=1):
|
||||
# local fake server with artificial latency
|
||||
class FakeSession(RPCSession):
|
||||
async def handle_request(self, request):
|
||||
await asyncio.sleep(latency)
|
||||
return {"height": 1}
|
||||
server = await self.loop.create_server(lambda: FakeSession(), host='127.0.0.1', port=port)
|
||||
self.addCleanup(server.close)
|
||||
return '127.0.0.1', port
|
||||
|
||||
async def _make_bad_server(self, port=42420):
|
||||
async def echo(reader, writer):
|
||||
while True:
|
||||
writer.write(await reader.read())
|
||||
server = await asyncio.start_server(echo, host='127.0.0.1', port=port)
|
||||
self.addCleanup(server.close)
|
||||
return '127.0.0.1', port
|
||||
|
||||
async def test_pick_fastest(self):
|
||||
ledger = Mock(config={
|
||||
'default_servers': [
|
||||
# fast but unhealthy, should be discarded
|
||||
await self._make_bad_server(),
|
||||
('localhost', 1),
|
||||
('example.that.doesnt.resolve', 9000),
|
||||
await self._make_fake_server(latency=1.0, port=1340),
|
||||
await self._make_fake_server(latency=0.1, port=1337),
|
||||
await self._make_fake_server(latency=0.4, port=1339),
|
||||
],
|
||||
'connect_timeout': 3
|
||||
})
|
||||
|
||||
network = BaseNetwork(ledger)
|
||||
self.addCleanup(network.stop)
|
||||
asyncio.ensure_future(network.start())
|
||||
await asyncio.wait_for(network.on_connected.first, timeout=1)
|
||||
self.assertTrue(network.is_connected)
|
||||
self.assertEqual(network.client.server, ('127.0.0.1', 1337))
|
||||
self.assertTrue(all([not session.is_closing() for session in network.session_pool.available_sessions]))
|
||||
# ensure we are connected to all of them after a while
|
||||
await asyncio.sleep(1)
|
||||
self.assertEqual(len(list(network.session_pool.available_sessions)), 3)
|
||||
@@ -1,74 +0,0 @@
|
||||
import logging
|
||||
import asyncio
|
||||
from unittest.mock import Mock
|
||||
|
||||
from torba.client.basenetwork import BaseNetwork
|
||||
from torba.rpc import RPCSession
|
||||
from torba.testcase import IntegrationTestCase, AsyncioTestCase
|
||||
|
||||
|
||||
class ReconnectTests(IntegrationTestCase):
|
||||
|
||||
VERBOSITY = logging.WARN
|
||||
|
||||
async def test_connection_drop_still_receives_events_after_reconnected(self):
|
||||
address1 = await self.account.receiving.get_or_create_usable_address()
|
||||
self.ledger.network.client.connection_lost(Exception())
|
||||
sendtxid = await self.blockchain.send_to_address(address1, 1.1337)
|
||||
await self.on_transaction_id(sendtxid) # mempool
|
||||
await self.blockchain.generate(1)
|
||||
await self.on_transaction_id(sendtxid) # confirmed
|
||||
|
||||
await self.assertBalance(self.account, '1.1337')
|
||||
# is it real? are we rich!? let me see this tx...
|
||||
d = self.ledger.network.get_transaction(sendtxid)
|
||||
# what's that smoke on my ethernet cable? oh no!
|
||||
self.ledger.network.client.connection_lost(Exception())
|
||||
with self.assertRaises(asyncio.CancelledError):
|
||||
await d
|
||||
# rich but offline? no way, no water, let's retry
|
||||
with self.assertRaisesRegex(ConnectionError, 'connection is not available'):
|
||||
await self.ledger.network.get_transaction(sendtxid)
|
||||
# * goes to pick some water outside... * time passes by and another donation comes in
|
||||
sendtxid = await self.blockchain.send_to_address(address1, 42)
|
||||
await self.blockchain.generate(1)
|
||||
# omg, the burned cable still works! torba is fire proof!
|
||||
await self.ledger.network.get_transaction(sendtxid)
|
||||
|
||||
async def test_timeout_then_reconnect(self):
|
||||
await self.conductor.spv_node.stop()
|
||||
self.assertFalse(self.ledger.network.is_connected)
|
||||
await self.conductor.spv_node.start(self.conductor.blockchain_node)
|
||||
await self.ledger.network.on_connected.first
|
||||
self.assertTrue(self.ledger.network.is_connected)
|
||||
|
||||
|
||||
class ServerPickingTestCase(AsyncioTestCase):
|
||||
async def _make_fake_server(self, latency=1.0, port=1337):
|
||||
# local fake server with artificial latency
|
||||
proto = RPCSession()
|
||||
proto.handle_request = lambda _: asyncio.sleep(latency)
|
||||
server = await self.loop.create_server(lambda: proto, host='127.0.0.1', port=port)
|
||||
self.addCleanup(server.close)
|
||||
return ('127.0.0.1', port)
|
||||
|
||||
async def test_pick_fastest(self):
|
||||
ledger = Mock(config={
|
||||
'default_servers': [
|
||||
await self._make_fake_server(latency=1.5, port=1340),
|
||||
await self._make_fake_server(latency=0.1, port=1337),
|
||||
await self._make_fake_server(latency=1.0, port=1339),
|
||||
await self._make_fake_server(latency=0.5, port=1338),
|
||||
],
|
||||
'connect_timeout': 30
|
||||
})
|
||||
|
||||
network = BaseNetwork(ledger)
|
||||
self.addCleanup(network.stop)
|
||||
asyncio.ensure_future(network.start())
|
||||
await asyncio.wait_for(network.on_connected.first, timeout=1)
|
||||
self.assertTrue(network.is_connected)
|
||||
self.assertEqual(network.client.server, ('127.0.0.1', 1337))
|
||||
# ensure we are connected to all of them
|
||||
self.assertEqual(len(network.session_pool.sessions), 4)
|
||||
self.assertTrue(all([not session.is_closing() for session in network.session_pool.sessions]))
|
||||
@@ -1,6 +1,9 @@
|
||||
import logging
|
||||
import asyncio
|
||||
import random
|
||||
from itertools import chain
|
||||
from random import shuffle
|
||||
|
||||
from torba.testcase import IntegrationTestCase
|
||||
from torba.client.util import satoshis_to_coins, coins_to_satoshis
|
||||
|
||||
@@ -129,3 +132,48 @@ class BasicTransactionTests(IntegrationTestCase):
|
||||
self.assertEqual(tx.outputs[0].get_address(self.ledger), address2)
|
||||
self.assertEqual(tx.outputs[0].is_change, False)
|
||||
self.assertEqual(tx.outputs[1].is_change, True)
|
||||
|
||||
async def test_history_edge_cases(self):
|
||||
await self.assertBalance(self.account, '0.0')
|
||||
address = await self.account.receiving.get_or_create_usable_address()
|
||||
# evil trick: mempool is unsorted on real life, but same order between python instances. reproduce it
|
||||
original_summary = self.conductor.spv_node.server.mempool.transaction_summaries
|
||||
|
||||
async def random_summary(*args, **kwargs):
|
||||
summary = await original_summary(*args, **kwargs)
|
||||
if summary and len(summary) > 2:
|
||||
ordered = summary.copy()
|
||||
while summary == ordered:
|
||||
random.shuffle(summary)
|
||||
return summary
|
||||
self.conductor.spv_node.server.mempool.transaction_summaries = random_summary
|
||||
# 10 unconfirmed txs, all from blockchain wallet
|
||||
sends = list(self.blockchain.send_to_address(address, 10) for _ in range(10))
|
||||
# use batching to reduce issues with send_to_address on cli
|
||||
for batch in range(0, len(sends), 10):
|
||||
txids = await asyncio.gather(*sends[batch:batch + 10])
|
||||
await asyncio.wait([self.on_transaction_id(txid) for txid in txids])
|
||||
remote_status = await self.ledger.network.subscribe_address(address)
|
||||
self.assertTrue(await self.ledger.update_history(address, remote_status))
|
||||
# 20 unconfirmed txs, 10 from blockchain, 10 from local to local
|
||||
utxos = await self.account.get_utxos()
|
||||
txs = []
|
||||
for utxo in utxos:
|
||||
tx = await self.ledger.transaction_class.create(
|
||||
[self.ledger.transaction_class.input_class.spend(utxo)],
|
||||
[],
|
||||
[self.account], self.account
|
||||
)
|
||||
await self.broadcast(tx)
|
||||
txs.append(tx)
|
||||
await asyncio.wait([self.on_transaction_address(tx, address) for tx in txs], timeout=1)
|
||||
remote_status = await self.ledger.network.subscribe_address(address)
|
||||
self.assertTrue(await self.ledger.update_history(address, remote_status))
|
||||
# server history grows unordered
|
||||
txid = await self.blockchain.send_to_address(address, 1)
|
||||
await self.on_transaction_id(txid)
|
||||
self.assertTrue(await self.ledger.update_history(address, remote_status))
|
||||
self.assertEqual(21, len((await self.ledger.get_local_status_and_history(address))[1]))
|
||||
self.assertEqual(0, len(self.ledger._known_addresses_out_of_sync))
|
||||
# should be another test, but it would be too much to setup just for that and it affects sync
|
||||
self.assertIsNone(await self.ledger.network.retriable_call(self.ledger.network.get_transaction, '1'*64))
|
||||
Binary file not shown.
@@ -1,10 +1,12 @@
|
||||
import unittest
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
from torba.client.wallet import Wallet
|
||||
from torba.client.constants import COIN
|
||||
from torba.coin.bitcoinsegwit import MainNetLedger as ledger_class
|
||||
from torba.client.basedatabase import query, constraints_to_sql, AIOSQLite
|
||||
from torba.client.basedatabase import query, interpolate, constraints_to_sql, AIOSQLite
|
||||
from torba.client.hash import sha256
|
||||
|
||||
from torba.testcase import AsyncioTestCase
|
||||
@@ -166,6 +168,26 @@ class TestQueryBuilder(unittest.TestCase):
|
||||
("select * from foo LIMIT 20 OFFSET 10", {})
|
||||
)
|
||||
|
||||
def test_query_interpolation(self):
|
||||
self.maxDiff = None
|
||||
# tests that interpolation replaces longer keys first
|
||||
self.assertEqual(
|
||||
interpolate(*query(
|
||||
"select * from foo",
|
||||
a__not='b', b__in='select * from blah where c=:$c',
|
||||
d__any={'one__like': 'o', 'two': 2},
|
||||
a0=3, a00=1, a00a=2, a00aa=4, # <-- breaks without correct interpolation key order
|
||||
ahash=memoryview(sha256(b'hello world')),
|
||||
limit=10, order_by='b', **{'$c': 3})
|
||||
),
|
||||
"select * from foo WHERE a != 'b' AND "
|
||||
"b IN (select * from blah where c=3) AND "
|
||||
"(one LIKE 'o' OR two = 2) AND "
|
||||
"a0 = 3 AND a00 = 1 AND a00a = 2 AND a00aa = 4 "
|
||||
"AND ahash = X'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' "
|
||||
"ORDER BY b LIMIT 10",
|
||||
)
|
||||
|
||||
|
||||
class TestQueries(AsyncioTestCase):
|
||||
|
||||
@@ -224,6 +246,30 @@ class TestQueries(AsyncioTestCase):
|
||||
def txi(self, txo):
|
||||
return ledger_class.transaction_class.input_class.spend(txo)
|
||||
|
||||
async def test_large_tx_doesnt_hit_variable_limits(self):
|
||||
# SQLite is usually compiled with 999 variables limit: https://www.sqlite.org/limits.html
|
||||
# This can be removed when there is a better way. See: https://github.com/lbryio/lbry-sdk/issues/2281
|
||||
fetchall = self.ledger.db.db.execute_fetchall
|
||||
def check_parameters_length(sql, parameters):
|
||||
self.assertLess(len(parameters or []), 999)
|
||||
return fetchall(sql, parameters)
|
||||
|
||||
self.ledger.db.db.execute_fetchall = check_parameters_length
|
||||
account = await self.create_account()
|
||||
tx = await self.create_tx_from_nothing(account, 0)
|
||||
for height in range(1, 1200):
|
||||
tx = await self.create_tx_from_txo(tx.outputs[0], account, height=height)
|
||||
variable_limit = self.ledger.db.MAX_QUERY_VARIABLES
|
||||
for limit in range(variable_limit-2, variable_limit+2):
|
||||
txs = await self.ledger.get_transactions(limit=limit, order_by='height asc')
|
||||
self.assertEqual(len(txs), limit)
|
||||
inputs, outputs, last_tx = set(), set(), txs[0]
|
||||
for tx in txs[1:]:
|
||||
self.assertEqual(len(tx.inputs), 1)
|
||||
self.assertEqual(tx.inputs[0].txo_ref.tx_ref.id, last_tx.id)
|
||||
self.assertEqual(len(tx.outputs), 1)
|
||||
last_tx = tx
|
||||
|
||||
async def test_queries(self):
|
||||
self.assertEqual(0, await self.ledger.db.get_address_count())
|
||||
account1 = await self.create_account()
|
||||
@@ -231,73 +277,73 @@ class TestQueries(AsyncioTestCase):
|
||||
account2 = await self.create_account()
|
||||
self.assertEqual(52, await self.ledger.db.get_address_count())
|
||||
|
||||
self.assertEqual(0, await self.ledger.db.get_transaction_count())
|
||||
self.assertEqual(0, await self.ledger.db.get_transaction_count(accounts=[account1, account2]))
|
||||
self.assertEqual(0, await self.ledger.db.get_utxo_count())
|
||||
self.assertEqual([], await self.ledger.db.get_utxos())
|
||||
self.assertEqual(0, await self.ledger.db.get_txo_count())
|
||||
self.assertEqual(0, await self.ledger.db.get_balance())
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(account=account1))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(account=account2))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(accounts=[account1]))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(accounts=[account2]))
|
||||
|
||||
tx1 = await self.create_tx_from_nothing(account1, 1)
|
||||
self.assertEqual(1, await self.ledger.db.get_transaction_count(account=account1))
|
||||
self.assertEqual(0, await self.ledger.db.get_transaction_count(account=account2))
|
||||
self.assertEqual(1, await self.ledger.db.get_utxo_count(account=account1))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(account=account1))
|
||||
self.assertEqual(0, await self.ledger.db.get_txo_count(account=account2))
|
||||
self.assertEqual(1, await self.ledger.db.get_transaction_count(accounts=[account1]))
|
||||
self.assertEqual(0, await self.ledger.db.get_transaction_count(accounts=[account2]))
|
||||
self.assertEqual(1, await self.ledger.db.get_utxo_count(accounts=[account1]))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(accounts=[account1]))
|
||||
self.assertEqual(0, await self.ledger.db.get_txo_count(accounts=[account2]))
|
||||
self.assertEqual(10**8, await self.ledger.db.get_balance())
|
||||
self.assertEqual(10**8, await self.ledger.db.get_balance(account=account1))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(account=account2))
|
||||
self.assertEqual(10**8, await self.ledger.db.get_balance(accounts=[account1]))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(accounts=[account2]))
|
||||
|
||||
tx2 = await self.create_tx_from_txo(tx1.outputs[0], account2, 2)
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(account=account1))
|
||||
self.assertEqual(1, await self.ledger.db.get_transaction_count(account=account2))
|
||||
self.assertEqual(0, await self.ledger.db.get_utxo_count(account=account1))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(account=account1))
|
||||
self.assertEqual(1, await self.ledger.db.get_utxo_count(account=account2))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(account=account2))
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(accounts=[account1]))
|
||||
self.assertEqual(1, await self.ledger.db.get_transaction_count(accounts=[account2]))
|
||||
self.assertEqual(0, await self.ledger.db.get_utxo_count(accounts=[account1]))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(accounts=[account1]))
|
||||
self.assertEqual(1, await self.ledger.db.get_utxo_count(accounts=[account2]))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(accounts=[account2]))
|
||||
self.assertEqual(10**8, await self.ledger.db.get_balance())
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(account=account1))
|
||||
self.assertEqual(10**8, await self.ledger.db.get_balance(account=account2))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(accounts=[account1]))
|
||||
self.assertEqual(10**8, await self.ledger.db.get_balance(accounts=[account2]))
|
||||
|
||||
tx3 = await self.create_tx_to_nowhere(tx2.outputs[0], 3)
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(account=account1))
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(account=account2))
|
||||
self.assertEqual(0, await self.ledger.db.get_utxo_count(account=account1))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(account=account1))
|
||||
self.assertEqual(0, await self.ledger.db.get_utxo_count(account=account2))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(account=account2))
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(accounts=[account1]))
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(accounts=[account2]))
|
||||
self.assertEqual(0, await self.ledger.db.get_utxo_count(accounts=[account1]))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(accounts=[account1]))
|
||||
self.assertEqual(0, await self.ledger.db.get_utxo_count(accounts=[account2]))
|
||||
self.assertEqual(1, await self.ledger.db.get_txo_count(accounts=[account2]))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance())
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(account=account1))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(account=account2))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(accounts=[account1]))
|
||||
self.assertEqual(0, await self.ledger.db.get_balance(accounts=[account2]))
|
||||
|
||||
txs = await self.ledger.db.get_transactions()
|
||||
txs = await self.ledger.db.get_transactions(accounts=[account1, account2])
|
||||
self.assertEqual([tx3.id, tx2.id, tx1.id], [tx.id for tx in txs])
|
||||
self.assertEqual([3, 2, 1], [tx.height for tx in txs])
|
||||
|
||||
txs = await self.ledger.db.get_transactions(account=account1)
|
||||
txs = await self.ledger.db.get_transactions(accounts=[account1])
|
||||
self.assertEqual([tx2.id, tx1.id], [tx.id for tx in txs])
|
||||
self.assertEqual(txs[0].inputs[0].is_my_account, True)
|
||||
self.assertEqual(txs[0].outputs[0].is_my_account, False)
|
||||
self.assertEqual(txs[1].inputs[0].is_my_account, False)
|
||||
self.assertEqual(txs[1].outputs[0].is_my_account, True)
|
||||
|
||||
txs = await self.ledger.db.get_transactions(account=account2)
|
||||
txs = await self.ledger.db.get_transactions(accounts=[account2])
|
||||
self.assertEqual([tx3.id, tx2.id], [tx.id for tx in txs])
|
||||
self.assertEqual(txs[0].inputs[0].is_my_account, True)
|
||||
self.assertEqual(txs[0].outputs[0].is_my_account, False)
|
||||
self.assertEqual(txs[1].inputs[0].is_my_account, False)
|
||||
self.assertEqual(txs[1].outputs[0].is_my_account, True)
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(account=account2))
|
||||
self.assertEqual(2, await self.ledger.db.get_transaction_count(accounts=[account2]))
|
||||
|
||||
tx = await self.ledger.db.get_transaction(txid=tx2.id)
|
||||
self.assertEqual(tx.id, tx2.id)
|
||||
self.assertEqual(tx.inputs[0].is_my_account, False)
|
||||
self.assertEqual(tx.outputs[0].is_my_account, False)
|
||||
tx = await self.ledger.db.get_transaction(txid=tx2.id, account=account1)
|
||||
tx = await self.ledger.db.get_transaction(txid=tx2.id, accounts=[account1])
|
||||
self.assertEqual(tx.inputs[0].is_my_account, True)
|
||||
self.assertEqual(tx.outputs[0].is_my_account, False)
|
||||
tx = await self.ledger.db.get_transaction(txid=tx2.id, account=account2)
|
||||
tx = await self.ledger.db.get_transaction(txid=tx2.id, accounts=[account2])
|
||||
self.assertEqual(tx.inputs[0].is_my_account, False)
|
||||
self.assertEqual(tx.outputs[0].is_my_account, True)
|
||||
|
||||
@@ -306,6 +352,82 @@ class TestQueries(AsyncioTestCase):
|
||||
txos = await self.ledger.db.get_txos()
|
||||
self.assertEqual([0, 2, 1], [txo.tx_ref.height for txo in txos])
|
||||
self.assertEqual([tx4.id, tx2.id, tx1.id], [txo.tx_ref.id for txo in txos])
|
||||
txs = await self.ledger.db.get_transactions()
|
||||
txs = await self.ledger.db.get_transactions(accounts=[account1, account2])
|
||||
self.assertEqual([0, 3, 2, 1], [tx.height for tx in txs])
|
||||
self.assertEqual([tx4.id, tx3.id, tx2.id, tx1.id], [tx.id for tx in txs])
|
||||
|
||||
|
||||
class TestUpgrade(AsyncioTestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.path = tempfile.mktemp()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
os.remove(self.path)
|
||||
|
||||
def get_version(self):
|
||||
with sqlite3.connect(self.path) as conn:
|
||||
versions = conn.execute('select version from version').fetchall()
|
||||
assert len(versions) == 1
|
||||
return versions[0][0]
|
||||
|
||||
def get_tables(self):
|
||||
with sqlite3.connect(self.path) as conn:
|
||||
sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"
|
||||
return [col[0] for col in conn.execute(sql).fetchall()]
|
||||
|
||||
def add_address(self, address):
|
||||
with sqlite3.connect(self.path) as conn:
|
||||
conn.execute("""
|
||||
INSERT INTO pubkey_address (address, account, chain, position, pubkey)
|
||||
VALUES (?, 'account1', 0, 0, 'pubkey blob')
|
||||
""", (address,))
|
||||
|
||||
def get_addresses(self):
|
||||
with sqlite3.connect(self.path) as conn:
|
||||
sql = "SELECT address FROM pubkey_address ORDER BY address;"
|
||||
return [col[0] for col in conn.execute(sql).fetchall()]
|
||||
|
||||
async def test_reset_on_version_change(self):
|
||||
self.ledger = ledger_class({
|
||||
'db': ledger_class.database_class(self.path),
|
||||
'headers': ledger_class.headers_class(':memory:'),
|
||||
})
|
||||
|
||||
# initial open, pre-version enabled db
|
||||
self.ledger.db.SCHEMA_VERSION = None
|
||||
self.assertEqual(self.get_tables(), [])
|
||||
await self.ledger.db.open()
|
||||
self.assertEqual(self.get_tables(), ['pubkey_address', 'tx', 'txi', 'txo'])
|
||||
self.assertEqual(self.get_addresses(), [])
|
||||
self.add_address('address1')
|
||||
await self.ledger.db.close()
|
||||
|
||||
# initial open after version enabled
|
||||
self.ledger.db.SCHEMA_VERSION = '1.0'
|
||||
await self.ledger.db.open()
|
||||
self.assertEqual(self.get_version(), '1.0')
|
||||
self.assertEqual(self.get_tables(), ['pubkey_address', 'tx', 'txi', 'txo', 'version'])
|
||||
self.assertEqual(self.get_addresses(), []) # address1 deleted during version upgrade
|
||||
self.add_address('address2')
|
||||
await self.ledger.db.close()
|
||||
|
||||
# nothing changes
|
||||
self.assertEqual(self.get_version(), '1.0')
|
||||
self.assertEqual(self.get_tables(), ['pubkey_address', 'tx', 'txi', 'txo', 'version'])
|
||||
await self.ledger.db.open()
|
||||
self.assertEqual(self.get_version(), '1.0')
|
||||
self.assertEqual(self.get_tables(), ['pubkey_address', 'tx', 'txi', 'txo', 'version'])
|
||||
self.assertEqual(self.get_addresses(), ['address2'])
|
||||
await self.ledger.db.close()
|
||||
|
||||
# upgrade version, database reset
|
||||
self.ledger.db.SCHEMA_VERSION = '1.1'
|
||||
self.ledger.db.CREATE_TABLES_QUERY += """
|
||||
create table if not exists foo (bar text);
|
||||
"""
|
||||
await self.ledger.db.open()
|
||||
self.assertEqual(self.get_version(), '1.1')
|
||||
self.assertEqual(self.get_tables(), ['foo', 'pubkey_address', 'tx', 'txi', 'txo', 'version'])
|
||||
self.assertEqual(self.get_addresses(), []) # all tables got reset
|
||||
await self.ledger.db.close()
|
||||
@@ -1,4 +1,6 @@
|
||||
import asyncio
|
||||
import os
|
||||
import tempfile
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
from torba.testcase import AsyncioTestCase
|
||||
@@ -11,27 +13,12 @@ def block_bytes(blocks):
|
||||
|
||||
|
||||
class BitcoinHeadersTestCase(AsyncioTestCase):
|
||||
|
||||
# Download headers instead of storing them in git.
|
||||
HEADER_URL = 'http://headers.electrum.org/blockchain_headers'
|
||||
HEADER_FILE = 'bitcoin_headers'
|
||||
HEADER_BYTES = block_bytes(32260) # 2.6MB
|
||||
RETARGET_BLOCK = 32256 # difficulty: 1 -> 1.18
|
||||
|
||||
def setUp(self):
|
||||
self.maxDiff = None
|
||||
self.header_file_name = os.path.join(os.path.dirname(__file__), self.HEADER_FILE)
|
||||
if not os.path.exists(self.header_file_name):
|
||||
req = Request(self.HEADER_URL)
|
||||
req.add_header('Range', 'bytes=0-{}'.format(self.HEADER_BYTES-1))
|
||||
with urlopen(req) as response, open(self.header_file_name, 'wb') as header_file:
|
||||
header_file.write(response.read())
|
||||
if os.path.getsize(self.header_file_name) != self.HEADER_BYTES:
|
||||
os.remove(self.header_file_name)
|
||||
raise Exception(
|
||||
"Downloaded headers for testing are not the correct number of bytes. "
|
||||
"They were deleted. Try running the tests again."
|
||||
)
|
||||
|
||||
def get_bytes(self, upto: int = -1, after: int = 0) -> bytes:
|
||||
with open(self.header_file_name, 'rb') as headers:
|
||||
@@ -106,3 +93,52 @@ class BasicHeadersTests(BitcoinHeadersTestCase):
|
||||
self.assertEqual(headers.height, 32250)
|
||||
await headers.connect(len(headers), remainder)
|
||||
self.assertEqual(headers.height, 32259)
|
||||
|
||||
async def test_bounds(self):
|
||||
headers = MainHeaders(':memory:')
|
||||
await headers.connect(0, self.get_bytes(block_bytes(3001)))
|
||||
self.assertEqual(headers.height, 3000)
|
||||
with self.assertRaises(IndexError):
|
||||
_ = headers[3001]
|
||||
with self.assertRaises(IndexError):
|
||||
_ = headers[-1]
|
||||
self.assertIsNotNone(headers[3000])
|
||||
self.assertIsNotNone(headers[0])
|
||||
|
||||
async def test_repair(self):
|
||||
headers = MainHeaders(':memory:')
|
||||
await headers.connect(0, self.get_bytes(block_bytes(3001)))
|
||||
self.assertEqual(headers.height, 3000)
|
||||
await headers.repair()
|
||||
self.assertEqual(headers.height, 3000)
|
||||
# corrupt the middle of it
|
||||
headers.io.seek(block_bytes(1500))
|
||||
headers.io.write(b"wtf")
|
||||
await headers.repair()
|
||||
self.assertEqual(headers.height, 1499)
|
||||
self.assertEqual(len(headers), 1500)
|
||||
# corrupt by appending
|
||||
headers.io.seek(block_bytes(len(headers)))
|
||||
headers.io.write(b"appending")
|
||||
await headers.repair()
|
||||
self.assertEqual(headers.height, 1499)
|
||||
await headers.connect(len(headers), self.get_bytes(block_bytes(3001 - 1500), after=block_bytes(1500)))
|
||||
self.assertEqual(headers.height, 3000)
|
||||
|
||||
async def test_concurrency(self):
|
||||
BLOCKS = 30
|
||||
headers_temporary_file = tempfile.mktemp()
|
||||
headers = MainHeaders(headers_temporary_file)
|
||||
await headers.open()
|
||||
self.addCleanup(os.remove, headers_temporary_file)
|
||||
async def writer():
|
||||
for block_index in range(BLOCKS):
|
||||
await headers.connect(block_index, self.get_bytes(block_bytes(block_index + 1), block_bytes(block_index)))
|
||||
async def reader():
|
||||
for block_index in range(BLOCKS):
|
||||
while len(headers) < block_index:
|
||||
await asyncio.sleep(0.000001)
|
||||
assert headers[block_index]['block_height'] == block_index
|
||||
reader_task = asyncio.create_task(reader())
|
||||
await writer()
|
||||
await reader_task
|
||||
@@ -18,6 +18,9 @@ class MockNetwork:
|
||||
self.get_transaction_called = []
|
||||
self.is_connected = False
|
||||
|
||||
def retriable_call(self, function, *args, **kwargs):
|
||||
return function(*args, **kwargs)
|
||||
|
||||
async def get_history(self, address):
|
||||
self.get_history_called.append(address)
|
||||
self.address = address
|
||||
@@ -26,7 +29,7 @@ class MockNetwork:
|
||||
async def get_merkle(self, txid, height):
|
||||
return {'merkle': ['abcd01'], 'pos': 1}
|
||||
|
||||
async def get_transaction(self, tx_hash):
|
||||
async def get_transaction(self, tx_hash, _=None):
|
||||
self.get_transaction_called.append(tx_hash)
|
||||
return self.transaction[tx_hash]
|
||||
|
||||
@@ -121,8 +124,9 @@ class TestSynchronization(LedgerTestCase):
|
||||
)
|
||||
|
||||
|
||||
class MocHeaderNetwork:
|
||||
class MocHeaderNetwork(MockNetwork):
|
||||
def __init__(self, responses):
|
||||
super().__init__(None, None)
|
||||
self.responses = responses
|
||||
|
||||
async def get_headers(self, height, blocks):
|
||||
|
||||
Loaded 100 of 123 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user