From a1353b5f289e1711d0ecc268a1766fca32501eb9 Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Sun, 22 Jan 2023 16:31:27 +0100 Subject: [PATCH 1/8] new: manage the paste to be deleted --- backend/Pipfile | 4 +- backend/Pipfile.lock | 268 ++++++++++++++++++++++++++++++++++++++++--- backend/cron.py | 82 +++++++++++++ backend/db.py | 34 +++++- backend/main.py | 5 + backend/pasteNym.py | 25 +++- backend/serve.py | 26 +++-- backend/utils.py | 4 + 8 files changed, 420 insertions(+), 28 deletions(-) create mode 100644 backend/cron.py diff --git a/backend/Pipfile b/backend/Pipfile index 4517b5f..68d83e4 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -10,7 +10,9 @@ websocket-client = "1.4.1" rel = "*" requests = "*" py-cid = "*" - +python-bitcoinrpc = "*" +arrow = "*" +dateparser = "*" [dev-packages] diff --git a/backend/Pipfile.lock b/backend/Pipfile.lock index 97761cd..0638ee3 100644 --- a/backend/Pipfile.lock +++ b/backend/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "70d7752478e9bf57cbdd6cc1fdf81d28c12cd24faffcf38c3cf1c122c49e5265" + "sha256": "03f48445c74f4a706a05b61a5ba4f3be76ad5b17db2bdb97696103c2c5177630" }, "pipfile-spec": 6, "requires": { @@ -16,6 +16,14 @@ ] }, "default": { + "arrow": { + "hashes": [ + "sha256:3934b30ca1b9f292376d9db15b19446088d12ec58629bc3f0da28fd55fb633a1", + "sha256:5a49ab92e3b7b71d96cd6bfcc4df14efefc9dfa96ea19045815914a6ab6b1fe2" + ], + "index": "pypi", + "version": "==1.2.3" + }, "base58": { "hashes": [ "sha256:1e42993c0628ed4f898c03b522b26af78fb05115732549b21a028bc4633d19ab", @@ -34,11 +42,105 @@ }, "charset-normalizer": { "hashes": [ - "sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845", - "sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f" + "sha256:00d3ffdaafe92a5dc603cb9bd5111aaa36dfa187c8285c543be562e61b755f6b", + "sha256:024e606be3ed92216e2b6952ed859d86b4cfa52cd5bc5f050e7dc28f9b43ec42", + "sha256:0298eafff88c99982a4cf66ba2efa1128e4ddaca0b05eec4c456bbc7db691d8d", + "sha256:02a51034802cbf38db3f89c66fb5d2ec57e6fe7ef2f4a44d070a593c3688667b", + "sha256:083c8d17153ecb403e5e1eb76a7ef4babfc2c48d58899c98fcaa04833e7a2f9a", + "sha256:0a11e971ed097d24c534c037d298ad32c6ce81a45736d31e0ff0ad37ab437d59", + "sha256:0bf2dae5291758b6f84cf923bfaa285632816007db0330002fa1de38bfcb7154", + "sha256:0c0a590235ccd933d9892c627dec5bc7511ce6ad6c1011fdf5b11363022746c1", + "sha256:0f438ae3532723fb6ead77e7c604be7c8374094ef4ee2c5e03a3a17f1fca256c", + "sha256:109487860ef6a328f3eec66f2bf78b0b72400280d8f8ea05f69c51644ba6521a", + "sha256:11b53acf2411c3b09e6af37e4b9005cba376c872503c8f28218c7243582df45d", + "sha256:12db3b2c533c23ab812c2b25934f60383361f8a376ae272665f8e48b88e8e1c6", + "sha256:14e76c0f23218b8f46c4d87018ca2e441535aed3632ca134b10239dfb6dadd6b", + "sha256:16a8663d6e281208d78806dbe14ee9903715361cf81f6d4309944e4d1e59ac5b", + "sha256:292d5e8ba896bbfd6334b096e34bffb56161c81408d6d036a7dfa6929cff8783", + "sha256:2c03cc56021a4bd59be889c2b9257dae13bf55041a3372d3295416f86b295fb5", + "sha256:2e396d70bc4ef5325b72b593a72c8979999aa52fb8bcf03f701c1b03e1166918", + "sha256:2edb64ee7bf1ed524a1da60cdcd2e1f6e2b4f66ef7c077680739f1641f62f555", + "sha256:31a9ddf4718d10ae04d9b18801bd776693487cbb57d74cc3458a7673f6f34639", + "sha256:356541bf4381fa35856dafa6a965916e54bed415ad8a24ee6de6e37deccf2786", + "sha256:358a7c4cb8ba9b46c453b1dd8d9e431452d5249072e4f56cfda3149f6ab1405e", + "sha256:37f8febc8ec50c14f3ec9637505f28e58d4f66752207ea177c1d67df25da5aed", + "sha256:39049da0ffb96c8cbb65cbf5c5f3ca3168990adf3551bd1dee10c48fce8ae820", + "sha256:39cf9ed17fe3b1bc81f33c9ceb6ce67683ee7526e65fde1447c772afc54a1bb8", + "sha256:3ae1de54a77dc0d6d5fcf623290af4266412a7c4be0b1ff7444394f03f5c54e3", + "sha256:3b590df687e3c5ee0deef9fc8c547d81986d9a1b56073d82de008744452d6541", + "sha256:3e45867f1f2ab0711d60c6c71746ac53537f1684baa699f4f668d4c6f6ce8e14", + "sha256:3fc1c4a2ffd64890aebdb3f97e1278b0cc72579a08ca4de8cd2c04799a3a22be", + "sha256:4457ea6774b5611f4bed5eaa5df55f70abde42364d498c5134b7ef4c6958e20e", + "sha256:44ba614de5361b3e5278e1241fda3dc1838deed864b50a10d7ce92983797fa76", + "sha256:4a8fcf28c05c1f6d7e177a9a46a1c52798bfe2ad80681d275b10dcf317deaf0b", + "sha256:4b0d02d7102dd0f997580b51edc4cebcf2ab6397a7edf89f1c73b586c614272c", + "sha256:502218f52498a36d6bf5ea77081844017bf7982cdbe521ad85e64cabee1b608b", + "sha256:503e65837c71b875ecdd733877d852adbc465bd82c768a067badd953bf1bc5a3", + "sha256:5995f0164fa7df59db4746112fec3f49c461dd6b31b841873443bdb077c13cfc", + "sha256:59e5686dd847347e55dffcc191a96622f016bc0ad89105e24c14e0d6305acbc6", + "sha256:601f36512f9e28f029d9481bdaf8e89e5148ac5d89cffd3b05cd533eeb423b59", + "sha256:608862a7bf6957f2333fc54ab4399e405baad0163dc9f8d99cb236816db169d4", + "sha256:62595ab75873d50d57323a91dd03e6966eb79c41fa834b7a1661ed043b2d404d", + "sha256:70990b9c51340e4044cfc394a81f614f3f90d41397104d226f21e66de668730d", + "sha256:71140351489970dfe5e60fc621ada3e0f41104a5eddaca47a7acb3c1b851d6d3", + "sha256:72966d1b297c741541ca8cf1223ff262a6febe52481af742036a0b296e35fa5a", + "sha256:74292fc76c905c0ef095fe11e188a32ebd03bc38f3f3e9bcb85e4e6db177b7ea", + "sha256:761e8904c07ad053d285670f36dd94e1b6ab7f16ce62b9805c475b7aa1cffde6", + "sha256:772b87914ff1152b92a197ef4ea40efe27a378606c39446ded52c8f80f79702e", + "sha256:79909e27e8e4fcc9db4addea88aa63f6423ebb171db091fb4373e3312cb6d603", + "sha256:7e189e2e1d3ed2f4aebabd2d5b0f931e883676e51c7624826e0a4e5fe8a0bf24", + "sha256:7eb33a30d75562222b64f569c642ff3dc6689e09adda43a082208397f016c39a", + "sha256:81d6741ab457d14fdedc215516665050f3822d3e56508921cc7239f8c8e66a58", + "sha256:8499ca8f4502af841f68135133d8258f7b32a53a1d594aa98cc52013fff55678", + "sha256:84c3990934bae40ea69a82034912ffe5a62c60bbf6ec5bc9691419641d7d5c9a", + "sha256:87701167f2a5c930b403e9756fab1d31d4d4da52856143b609e30a1ce7160f3c", + "sha256:88600c72ef7587fe1708fd242b385b6ed4b8904976d5da0893e31df8b3480cb6", + "sha256:8ac7b6a045b814cf0c47f3623d21ebd88b3e8cf216a14790b455ea7ff0135d18", + "sha256:8b8af03d2e37866d023ad0ddea594edefc31e827fee64f8de5611a1dbc373174", + "sha256:8c7fe7afa480e3e82eed58e0ca89f751cd14d767638e2550c77a92a9e749c317", + "sha256:8eade758719add78ec36dc13201483f8e9b5d940329285edcd5f70c0a9edbd7f", + "sha256:911d8a40b2bef5b8bbae2e36a0b103f142ac53557ab421dc16ac4aafee6f53dc", + "sha256:93ad6d87ac18e2a90b0fe89df7c65263b9a99a0eb98f0a3d2e079f12a0735837", + "sha256:95dea361dd73757c6f1c0a1480ac499952c16ac83f7f5f4f84f0658a01b8ef41", + "sha256:9ab77acb98eba3fd2a85cd160851816bfce6871d944d885febf012713f06659c", + "sha256:9cb3032517f1627cc012dbc80a8ec976ae76d93ea2b5feaa9d2a5b8882597579", + "sha256:9cf4e8ad252f7c38dd1f676b46514f92dc0ebeb0db5552f5f403509705e24753", + "sha256:9d9153257a3f70d5f69edf2325357251ed20f772b12e593f3b3377b5f78e7ef8", + "sha256:a152f5f33d64a6be73f1d30c9cc82dfc73cec6477ec268e7c6e4c7d23c2d2291", + "sha256:a16418ecf1329f71df119e8a65f3aa68004a3f9383821edcb20f0702934d8087", + "sha256:a60332922359f920193b1d4826953c507a877b523b2395ad7bc716ddd386d866", + "sha256:a8d0fc946c784ff7f7c3742310cc8a57c5c6dc31631269876a88b809dbeff3d3", + "sha256:ab5de034a886f616a5668aa5d098af2b5385ed70142090e2a31bcbd0af0fdb3d", + "sha256:c22d3fe05ce11d3671297dc8973267daa0f938b93ec716e12e0f6dee81591dc1", + "sha256:c2ac1b08635a8cd4e0cbeaf6f5e922085908d48eb05d44c5ae9eabab148512ca", + "sha256:c512accbd6ff0270939b9ac214b84fb5ada5f0409c44298361b2f5e13f9aed9e", + "sha256:c75ffc45f25324e68ab238cb4b5c0a38cd1c3d7f1fb1f72b5541de469e2247db", + "sha256:c95a03c79bbe30eec3ec2b7f076074f4281526724c8685a42872974ef4d36b72", + "sha256:cadaeaba78750d58d3cc6ac4d1fd867da6fc73c88156b7a3212a3cd4819d679d", + "sha256:cd6056167405314a4dc3c173943f11249fa0f1b204f8b51ed4bde1a9cd1834dc", + "sha256:db72b07027db150f468fbada4d85b3b2729a3db39178abf5c543b784c1254539", + "sha256:df2c707231459e8a4028eabcd3cfc827befd635b3ef72eada84ab13b52e1574d", + "sha256:e62164b50f84e20601c1ff8eb55620d2ad25fb81b59e3cd776a1902527a788af", + "sha256:e696f0dd336161fca9adbb846875d40752e6eba585843c768935ba5c9960722b", + "sha256:eaa379fcd227ca235d04152ca6704c7cb55564116f8bc52545ff357628e10602", + "sha256:ebea339af930f8ca5d7a699b921106c6e29c617fe9606fa7baa043c1cdae326f", + "sha256:f4c39b0e3eac288fedc2b43055cfc2ca7a60362d0e5e87a637beac5d801ef478", + "sha256:f5057856d21e7586765171eac8b9fc3f7d44ef39425f85dbcccb13b3ebea806c", + "sha256:f6f45710b4459401609ebebdbcfb34515da4fc2aa886f95107f556ac69a9147e", + "sha256:f97e83fa6c25693c7a35de154681fcc257c1c41b38beb0304b9c4d2d9e164479", + "sha256:f9d0c5c045a3ca9bedfc35dca8526798eb91a07aa7a2c0fee134c6c6f321cbd7", + "sha256:ff6f3db31555657f3163b15a6b7c6938d08df7adbfc9dd13d9d19edad678f1e8" ], "markers": "python_full_version >= '3.6.0'", - "version": "==2.1.1" + "version": "==3.0.1" + }, + "dateparser": { + "hashes": [ + "sha256:c47b6e4b8c4b2b2a21690111b6571b6991295ba327ec6503753abeebf5e80696", + "sha256:e703db1815270c020552f4b3e3a981937b48b2cbcfcef5347071b74788dd9214" + ], + "index": "pypi", + "version": "==1.1.6" }, "idna": { "hashes": [ @@ -96,13 +198,137 @@ ], "version": "==1.2.2" }, + "python-bitcoinrpc": { + "hashes": [ + "sha256:a6a6f35672635163bc491c25fe29520bdd063dedbeda3b37bf5be97aa038c6e7" + ], + "index": "pypi", + "version": "==1.0" + }, + "python-dateutil": { + "hashes": [ + "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86", + "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.8.2" + }, "python-dotenv": { "hashes": [ - "sha256:1684eb44636dd462b66c3ee016599815514527ad99965de77f43e0944634a7e5", - "sha256:b77d08274639e3d34145dfa6c7008e66df0f04b7be7a75fd0d5292c191d79045" + "sha256:1c93de8f636cde3ce377292818d0e440b6e45a82f215c3744979151fa8151c49", + "sha256:41e12e0318bebc859fcc4d97d4db8d20ad21721a6aa5047dd59f090391cb549a" ], "index": "pypi", - "version": "==0.21.0" + "version": "==0.21.1" + }, + "pytz": { + "hashes": [ + "sha256:01a0681c4b9684a28304615eba55d1ab31ae00bf68ec157ec3708a8182dbbcd0", + "sha256:78f4f37d8198e0627c5f1143240bb0206b8691d8d7ac6d78fee88b78733f8c4a" + ], + "version": "==2022.7.1" + }, + "pytz-deprecation-shim": { + "hashes": [ + "sha256:8314c9692a636c8eb3bda879b9f119e350e93223ae83e70e80c31675a0fdc1a6", + "sha256:af097bae1b616dde5c5744441e2ddc69e74dfdcb0c263129610d85b87445a59d" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", + "version": "==0.1.0.post0" + }, + "regex": { + "hashes": [ + "sha256:052b670fafbe30966bbe5d025e90b2a491f85dfe5b2583a163b5e60a85a321ad", + "sha256:0653d012b3bf45f194e5e6a41df9258811ac8fc395579fa82958a8b76286bea4", + "sha256:0a069c8483466806ab94ea9068c34b200b8bfc66b6762f45a831c4baaa9e8cdd", + "sha256:0cf0da36a212978be2c2e2e2d04bdff46f850108fccc1851332bcae51c8907cc", + "sha256:131d4be09bea7ce2577f9623e415cab287a3c8e0624f778c1d955ec7c281bd4d", + "sha256:144486e029793a733e43b2e37df16a16df4ceb62102636ff3db6033994711066", + "sha256:1ddf14031a3882f684b8642cb74eea3af93a2be68893901b2b387c5fd92a03ec", + "sha256:1eba476b1b242620c266edf6325b443a2e22b633217a9835a52d8da2b5c051f9", + "sha256:20f61c9944f0be2dc2b75689ba409938c14876c19d02f7585af4460b6a21403e", + "sha256:22960019a842777a9fa5134c2364efaed5fbf9610ddc5c904bd3a400973b0eb8", + "sha256:22e7ebc231d28393dfdc19b185d97e14a0f178bedd78e85aad660e93b646604e", + "sha256:23cbb932cc53a86ebde0fb72e7e645f9a5eec1a5af7aa9ce333e46286caef783", + "sha256:29c04741b9ae13d1e94cf93fca257730b97ce6ea64cfe1eba11cf9ac4e85afb6", + "sha256:2bde29cc44fa81c0a0c8686992c3080b37c488df167a371500b2a43ce9f026d1", + "sha256:2cdc55ca07b4e70dda898d2ab7150ecf17c990076d3acd7a5f3b25cb23a69f1c", + "sha256:370f6e97d02bf2dd20d7468ce4f38e173a124e769762d00beadec3bc2f4b3bc4", + "sha256:395161bbdbd04a8333b9ff9763a05e9ceb4fe210e3c7690f5e68cedd3d65d8e1", + "sha256:44136355e2f5e06bf6b23d337a75386371ba742ffa771440b85bed367c1318d1", + "sha256:44a6c2f6374e0033873e9ed577a54a3602b4f609867794c1a3ebba65e4c93ee7", + "sha256:4919899577ba37f505aaebdf6e7dc812d55e8f097331312db7f1aab18767cce8", + "sha256:4b4b1fe58cd102d75ef0552cf17242705ce0759f9695334a56644ad2d83903fe", + "sha256:4bdd56ee719a8f751cf5a593476a441c4e56c9b64dc1f0f30902858c4ef8771d", + "sha256:4bf41b8b0a80708f7e0384519795e80dcb44d7199a35d52c15cc674d10b3081b", + "sha256:4cac3405d8dda8bc6ed499557625585544dd5cbf32072dcc72b5a176cb1271c8", + "sha256:4fe7fda2fe7c8890d454f2cbc91d6c01baf206fbc96d89a80241a02985118c0c", + "sha256:50921c140561d3db2ab9f5b11c5184846cde686bb5a9dc64cae442926e86f3af", + "sha256:5217c25229b6a85049416a5c1e6451e9060a1edcf988641e309dbe3ab26d3e49", + "sha256:5352bea8a8f84b89d45ccc503f390a6be77917932b1c98c4cdc3565137acc714", + "sha256:542e3e306d1669b25936b64917285cdffcd4f5c6f0247636fec037187bd93542", + "sha256:543883e3496c8b6d58bd036c99486c3c8387c2fc01f7a342b760c1ea3158a318", + "sha256:586b36ebda81e6c1a9c5a5d0bfdc236399ba6595e1397842fd4a45648c30f35e", + "sha256:597f899f4ed42a38df7b0e46714880fb4e19a25c2f66e5c908805466721760f5", + "sha256:5a260758454580f11dd8743fa98319bb046037dfab4f7828008909d0aa5292bc", + "sha256:5aefb84a301327ad115e9d346c8e2760009131d9d4b4c6b213648d02e2abe144", + "sha256:5e6a5567078b3eaed93558842346c9d678e116ab0135e22eb72db8325e90b453", + "sha256:5ff525698de226c0ca743bfa71fc6b378cda2ddcf0d22d7c37b1cc925c9650a5", + "sha256:61edbca89aa3f5ef7ecac8c23d975fe7261c12665f1d90a6b1af527bba86ce61", + "sha256:659175b2144d199560d99a8d13b2228b85e6019b6e09e556209dfb8c37b78a11", + "sha256:6a9a19bea8495bb419dc5d38c4519567781cd8d571c72efc6aa959473d10221a", + "sha256:6b30bddd61d2a3261f025ad0f9ee2586988c6a00c780a2fb0a92cea2aa702c54", + "sha256:6ffd55b5aedc6f25fd8d9f905c9376ca44fcf768673ffb9d160dd6f409bfda73", + "sha256:702d8fc6f25bbf412ee706bd73019da5e44a8400861dfff7ff31eb5b4a1276dc", + "sha256:74bcab50a13960f2a610cdcd066e25f1fd59e23b69637c92ad470784a51b1347", + "sha256:75f591b2055523fc02a4bbe598aa867df9e953255f0b7f7715d2a36a9c30065c", + "sha256:763b64853b0a8f4f9cfb41a76a4a85a9bcda7fdda5cb057016e7706fde928e66", + "sha256:76c598ca73ec73a2f568e2a72ba46c3b6c8690ad9a07092b18e48ceb936e9f0c", + "sha256:78d680ef3e4d405f36f0d6d1ea54e740366f061645930072d39bca16a10d8c93", + "sha256:7b280948d00bd3973c1998f92e22aa3ecb76682e3a4255f33e1020bd32adf443", + "sha256:7db345956ecce0c99b97b042b4ca7326feeec6b75facd8390af73b18e2650ffc", + "sha256:7dbdce0c534bbf52274b94768b3498abdf675a691fec5f751b6057b3030f34c1", + "sha256:7ef6b5942e6bfc5706301a18a62300c60db9af7f6368042227ccb7eeb22d0892", + "sha256:7f5a3ffc731494f1a57bd91c47dc483a1e10048131ffb52d901bfe2beb6102e8", + "sha256:8a45b6514861916c429e6059a55cf7db74670eaed2052a648e3e4d04f070e001", + "sha256:8ad241da7fac963d7573cc67a064c57c58766b62a9a20c452ca1f21050868dfa", + "sha256:8b0886885f7323beea6f552c28bff62cbe0983b9fbb94126531693ea6c5ebb90", + "sha256:8ca88da1bd78990b536c4a7765f719803eb4f8f9971cc22d6ca965c10a7f2c4c", + "sha256:8e0caeff18b96ea90fc0eb6e3bdb2b10ab5b01a95128dfeccb64a7238decf5f0", + "sha256:957403a978e10fb3ca42572a23e6f7badff39aa1ce2f4ade68ee452dc6807692", + "sha256:9af69f6746120998cd9c355e9c3c6aec7dff70d47247188feb4f829502be8ab4", + "sha256:9c94f7cc91ab16b36ba5ce476f1904c91d6c92441f01cd61a8e2729442d6fcf5", + "sha256:a37d51fa9a00d265cf73f3de3930fa9c41548177ba4f0faf76e61d512c774690", + "sha256:a3a98921da9a1bf8457aeee6a551948a83601689e5ecdd736894ea9bbec77e83", + "sha256:a3c1ebd4ed8e76e886507c9eddb1a891673686c813adf889b864a17fafcf6d66", + "sha256:a5f9505efd574d1e5b4a76ac9dd92a12acb2b309551e9aa874c13c11caefbe4f", + "sha256:a8ff454ef0bb061e37df03557afda9d785c905dab15584860f982e88be73015f", + "sha256:a9d0b68ac1743964755ae2d89772c7e6fb0118acd4d0b7464eaf3921c6b49dd4", + "sha256:aa62a07ac93b7cb6b7d0389d8ef57ffc321d78f60c037b19dfa78d6b17c928ee", + "sha256:ac741bf78b9bb432e2d314439275235f41656e189856b11fb4e774d9f7246d81", + "sha256:ae1e96785696b543394a4e3f15f3f225d44f3c55dafe3f206493031419fedf95", + "sha256:b683e5fd7f74fb66e89a1ed16076dbab3f8e9f34c18b1979ded614fe10cdc4d9", + "sha256:b7a8b43ee64ca8f4befa2bea4083f7c52c92864d8518244bfa6e88c751fa8fff", + "sha256:b8e38472739028e5f2c3a4aded0ab7eadc447f0d84f310c7a8bb697ec417229e", + "sha256:bfff48c7bd23c6e2aec6454aaf6edc44444b229e94743b34bdcdda2e35126cf5", + "sha256:c14b63c9d7bab795d17392c7c1f9aaabbffd4cf4387725a0ac69109fb3b550c6", + "sha256:c27cc1e4b197092e50ddbf0118c788d9977f3f8f35bfbbd3e76c1846a3443df7", + "sha256:c28d3309ebd6d6b2cf82969b5179bed5fefe6142c70f354ece94324fa11bf6a1", + "sha256:c670f4773f2f6f1957ff8a3962c7dd12e4be54d05839b216cb7fd70b5a1df394", + "sha256:ce6910b56b700bea7be82c54ddf2e0ed792a577dfaa4a76b9af07d550af435c6", + "sha256:d0213671691e341f6849bf33cd9fad21f7b1cb88b89e024f33370733fec58742", + "sha256:d03fe67b2325cb3f09be029fd5da8df9e6974f0cde2c2ac6a79d2634e791dd57", + "sha256:d0e5af9a9effb88535a472e19169e09ce750c3d442fb222254a276d77808620b", + "sha256:d243b36fbf3d73c25e48014961e83c19c9cc92530516ce3c43050ea6276a2ab7", + "sha256:d26166acf62f731f50bdd885b04b38828436d74e8e362bfcb8df221d868b5d9b", + "sha256:d403d781b0e06d2922435ce3b8d2376579f0c217ae491e273bab8d092727d244", + "sha256:d8716f82502997b3d0895d1c64c3b834181b1eaca28f3f6336a71777e437c2af", + "sha256:e4f781ffedd17b0b834c8731b75cce2639d5a8afe961c1e58ee7f1f20b3af185", + "sha256:e613a98ead2005c4ce037c7b061f2409a1a4e45099edb0ef3200ee26ed2a69a8", + "sha256:ef4163770525257876f10e8ece1cf25b71468316f61451ded1a6f44273eedeb5" + ], + "markers": "python_version >= '3.6'", + "version": "==2022.10.31" }, "rel": { "hashes": [ @@ -115,11 +341,11 @@ }, "requests": { "hashes": [ - "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983", - "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349" + "sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa", + "sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf" ], "index": "pypi", - "version": "==2.28.1" + "version": "==2.28.2" }, "six": { "hashes": [ @@ -129,13 +355,29 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.16.0" }, + "tzdata": { + "hashes": [ + "sha256:2b88858b0e3120792a3c0635c23daf36a7d7eeeca657c323da299d2094402a0d", + "sha256:fe5f866eddd8b96e9fcba978f8e503c909b19ea7efda11e52e39494bad3a7bfa" + ], + "markers": "python_version >= '3.6'", + "version": "==2022.7" + }, + "tzlocal": { + "hashes": [ + "sha256:89885494684c929d9191c57aa27502afc87a579be5cdd3225c77c463ea043745", + "sha256:ee5842fa3a795f023514ac2d801c4a81d1743bbe642e3940143326b3a00addd7" + ], + "markers": "python_version >= '3.6'", + "version": "==4.2" + }, "urllib3": { "hashes": [ - "sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc", - "sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8" + "sha256:076907bf8fd355cde77728471316625a4d2f7e713c125f51953bb5b3eecf4f72", + "sha256:75edcdc2f7d85b137124a6c3c9fc3933cdeaa12ecb9a6a959f22797a0feca7e1" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.26.13" + "version": "==1.26.14" }, "varint": { "hashes": [ diff --git a/backend/cron.py b/backend/cron.py new file mode 100644 index 0000000..144ddc4 --- /dev/null +++ b/backend/cron.py @@ -0,0 +1,82 @@ +import json +import time +import traceback +from bitcoinrpc.authproxy import AuthServiceProxy +import db +import utils + +TIME_EXECUTION_TIME_MINUTES = 1 + + +class Cron: + + def __init__(self): + self.db = db.BaseModel() + self.firstRun = True + + timestampNow = time.time() + self.lastExecutionTime = timestampNow + + if Cron.bitcoinExpirationEnabled(): + try: + self.rpc_connection = AuthServiceProxy( + f"http://{utils.BITCOIN_USER}:{utils.BITCOIN_PASSWORD}@{utils.BITCOIN_RPC_URL}:{utils.BITCOIN_RPC_URL_PORT}") + self.lastExecutionHeight = Cron.getCurrentHeight() + except Exception: + print("Error connection to bitcoin core rpc") + traceback.print_exc() + + def executeCron(self): + + if self.firstRun: + print("First run delete job") + print(f"Number paste time deleted: {self.deleteExpiredTimePaste()}") + if Cron.bitcoinExpirationEnabled(): + print(f"Number paste height deleted: {self.deleteExpiredHeightPaste(self.lastExecutionHeight)}") + + self.firstRun = False + return + + timestampNow = time.time() + + # only execute delete paste every 1 minute + if self.lastExecutionTime <= timestampNow - TIME_EXECUTION_TIME_MINUTES * 60: + print(f"Number paste time deleted: {self.deleteExpiredTimePaste()}") + self.lastExecutionTime = timestampNow + + if Cron.bitcoinExpirationEnabled(): + heightNow = Cron.getCurrentHeight() + if self.lastExecutionHeight <= heightNow: + print(f"Number paste height deleted: {self.deleteExpiredHeightPaste(heightNow)}") + self.lastExecutionHeight = heightNow + + def deleteExpiredTimePaste(self): + return self.db.deletePasteExpirationTime(Cron.getCurrentTime()) + + def deleteExpiredHeightPaste(self, heightNow): + if heightNow > 0: + return self.db.deletePasteExpirationHeight(heightNow) + else: + print("error with current height, cannot remove the paste") + + @staticmethod + def getCurrentHeight(): + + try: + rpc_connection = AuthServiceProxy( + f"http://{utils.BITCOIN_USER}:{utils.BITCOIN_PASSWORD}@{utils.BITCOIN_RPC_URL}:{utils.BITCOIN_RPC_URL_PORT}") + if rpc_connection.getblockchaininfo()['initialblockdownload']: + print("Be careful fullnode is not synced") + numBlocks = rpc_connection.getblockcount() + return numBlocks + except Exception: + traceback.print_exc() + return 0 + + @staticmethod + def getCurrentTime(): + return time.time() + + @staticmethod + def bitcoinExpirationEnabled(): + return True if utils.BITCOIN_RPC_URL is not None else False diff --git a/backend/db.py b/backend/db.py index 455125c..7726eb3 100644 --- a/backend/db.py +++ b/backend/db.py @@ -1,4 +1,5 @@ import logging +import time import traceback from datetime import datetime @@ -36,7 +37,7 @@ def idExists(self, id): finally: self.close() - def insertText(self, text, url_id, enc_params_b64, burn_view=0,private=True, burn=False, ipfs=False): + def insertText(self, text, url_id, enc_params_b64, burn_view=0,private=True, burn=False, ipfs=False,expiration_time=None, expiration_height=None): self.connect() try: @@ -48,7 +49,9 @@ def insertText(self, text, url_id, enc_params_b64, burn_view=0,private=True, bur url_id=url_id, is_private=private, is_burn=burn, - burn_view=burn_view + burn_view=burn_view, + expiration_time=expiration_time, + expiration_height=expiration_height ).execute() return list(Text.select().where(Text.id == idInsert).dicts()) @@ -103,6 +106,31 @@ def getTextByUrlId(self, url_id): finally: self.close() + def deletePasteExpirationTime(self,currentTimestamp): + try: + with database.atomic(): + + return Text.delete().where(Text.expiration_time <= currentTimestamp).execute() + + except (IntegrityError, DoesNotExist) as e: + logHandler.exception(e) + return False + finally: + self.close() + + def deletePasteExpirationHeight(self, currentHeight): + try: + with database.atomic(): + + return Text.delete().where(Text.expiration_height <= currentHeight).execute() + + except (IntegrityError, DoesNotExist) as e: + logHandler.exception(e) + return False + finally: + self.close() + + class Text(BaseModel): class Meta: @@ -114,6 +142,8 @@ class Meta: # Setting url_id as index allows faster operations url_id = TextField(index=True) expiration_time = TimestampField(null=True) + expiration_height = TimestampField(null=True) + author = TextField(null=True) # If not null, means that 'text' field is encrypted with password encryption_params_b64 = TextField(null=True) diff --git a/backend/main.py b/backend/main.py index 13a15be..0c18082 100644 --- a/backend/main.py +++ b/backend/main.py @@ -3,6 +3,7 @@ import db from os.path import exists import ipfsHandler +import cron if __name__ == '__main__': @@ -10,6 +11,10 @@ print("Create database done") db.create_tables() + + cron = cron.Cron() + cron.executeCron() + # init and start the backend server serveClient = Serve() diff --git a/backend/pasteNym.py b/backend/pasteNym.py index 8a9c5db..1e18b8a 100644 --- a/backend/pasteNym.py +++ b/backend/pasteNym.py @@ -1,13 +1,13 @@ from datetime import datetime +import cron import db -import sys import utils import html import json import base64 import ipfsHandler -from utils import isBase64 +import dateparser class PasteNym: @@ -45,6 +45,25 @@ def newText(self, data): else: burn_view = 1 + expiration_time = None + if data.get('expiration_time') and type(data.get('expiration_time')) == str: + rel_expiration_time = data.get('expiration_time') + try: + # transform relative time from string to timestamp add in keyword to specify in future + expiration_time = dateparser.parse("in "+rel_expiration_time).timestamp() + except Exception as e: + print(f"Parsing time error, set to 0, {e}") + expiration_time = 0 + + + expiration_height = None + if data.get('expiration_height') and type(data.get('expiration_height')) == int: + expiration_height = data.get('expiration_height') + if expiration_height > 0: + expiration_height += cron.Cron.getCurrentHeight() + else: + print(f"Parsing height error, height must be positive") + # by default the pastes are not uploaded to IPFS @@ -88,7 +107,7 @@ def newText(self, data): while self.db.idExists(urlId) is not None: urlId = utils.generateRandomString(self.idLength) - return self.db.insertText(html.escape(text), urlId, encParamsB64, burn_view, private, burn, ipfs) + return self.db.insertText(html.escape(text), urlId, encParamsB64, burn_view, private, burn, ipfs, expiration_time, expiration_height) except (KeyError, AttributeError) as e: diff --git a/backend/serve.py b/backend/serve.py index 79c72f3..57240e6 100644 --- a/backend/serve.py +++ b/backend/serve.py @@ -1,6 +1,8 @@ import base64 import json import websocket + +from cron import Cron from pasteNym import PasteNym import utils from datetime import datetime @@ -47,6 +49,7 @@ def __init__(self): url = f"ws://{utils.NYM_CLIENT_ADDR}:1977" self.firstRun = True self.pasteNym = PasteNym() + self.cron= Cron() websocket.enableTrace(False) self.ws = websocket.WebSocketApp(url, on_message=lambda ws, msg: self.on_message( @@ -55,22 +58,20 @@ def __init__(self): ws, msg), on_close=lambda ws: self.on_close( ws), - on_open=lambda ws: self.on_open(ws)) + on_open=lambda ws: self.on_open(ws), + on_pong=lambda ws,msg: self.on_pong(ws,msg) + ) # Set dispatcher to automatic reconnection - self.ws.run_forever(dispatcher=rel, ping_interval=30, - ping_timeout=10, ping_payload=self_address_request) + self.ws.run_forever(dispatcher=rel, ping_interval=30, ping_timeout=10) rel.signal(2, rel.abort) # Keyboard Interrupt rel.dispatch() self.ws.close() - - def on_ping(self, ws): - pass - - def on_pong(self, ws): - pass + def on_pong(self,ws,msg): + self.cron.executeCron() + ws.send(self_address_request) def on_open(self, ws): self.ws.send(self_address_request) @@ -98,6 +99,11 @@ def on_message(self, ws, message): return received_message = json.loads(message) + + # test if it's ping answer message + if received_message.get('address'): + return + recipient = None except UnicodeDecodeError as e: @@ -149,6 +155,8 @@ def on_message(self, ws, message): print(f"No recipient found in message {received_message}") return None + # excute cron.py + reply = "" if recipient is not None: diff --git a/backend/utils.py b/backend/utils.py index ce6720d..b6b5a0e 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -17,6 +17,10 @@ IPFS_HOST = os.getenv("IPFS_HOST", "localhost") IPFS_CLUSTER_HOST = os.getenv("IPFS_CLUSTER_HOST", None) +BITCOIN_RPC_URL=os.getenv("BITCOIN_RPC_URL",None) +BITCOIN_RPC_URL_PORT=os.getenv("BITCOIN_RPC_URL_PORT","8832") +BITCOIN_USER=os.getenv("BITCOIN_USER",None) +BITCOIN_PASSWORD=os.getenv("BITCOIN_PASSWORD",None) def generateRandomString(length): return token_urlsafe(nbytes=length) From c5d0c06d0cdfbc01576811506edeb95757398cea Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Sun, 22 Jan 2023 16:32:12 +0100 Subject: [PATCH 2/8] support expiration paste --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 31f2419..150f02c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ backend/ipfs/data backend/ipfs/ipfs_fuse backend/ipfs/ipns_fuse +backend/bitcoin-core .idea env.docker docker-compose.yml From 5f93d8481e567e7092410a87ee2da0a0b63d6f0e Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Sun, 22 Jan 2023 16:37:11 +0100 Subject: [PATCH 3/8] support expiration paste --- backend/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/utils.py b/backend/utils.py index b6b5a0e..23dca91 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -18,7 +18,7 @@ IPFS_CLUSTER_HOST = os.getenv("IPFS_CLUSTER_HOST", None) BITCOIN_RPC_URL=os.getenv("BITCOIN_RPC_URL",None) -BITCOIN_RPC_URL_PORT=os.getenv("BITCOIN_RPC_URL_PORT","8832") +BITCOIN_RPC_URL_PORT=os.getenv("BITCOIN_RPC_URL_PORT","8332") BITCOIN_USER=os.getenv("BITCOIN_USER",None) BITCOIN_PASSWORD=os.getenv("BITCOIN_PASSWORD",None) From 8c378920e31f0a8095f9a525902d501dface00eb Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Mon, 23 Jan 2023 21:50:45 +0100 Subject: [PATCH 4/8] cleaning --- backend/Pipfile | 1 - backend/Pipfile.lock | 10 +--------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/backend/Pipfile b/backend/Pipfile index 68d83e4..2f2aaca 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -11,7 +11,6 @@ rel = "*" requests = "*" py-cid = "*" python-bitcoinrpc = "*" -arrow = "*" dateparser = "*" [dev-packages] diff --git a/backend/Pipfile.lock b/backend/Pipfile.lock index 0638ee3..0ae724b 100644 --- a/backend/Pipfile.lock +++ b/backend/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "03f48445c74f4a706a05b61a5ba4f3be76ad5b17db2bdb97696103c2c5177630" + "sha256": "05d74d09900b13afba4da92eab447a2ebea9cefc770dae381ab944a4449f21cc" }, "pipfile-spec": 6, "requires": { @@ -16,14 +16,6 @@ ] }, "default": { - "arrow": { - "hashes": [ - "sha256:3934b30ca1b9f292376d9db15b19446088d12ec58629bc3f0da28fd55fb633a1", - "sha256:5a49ab92e3b7b71d96cd6bfcc4df14efefc9dfa96ea19045815914a6ab6b1fe2" - ], - "index": "pypi", - "version": "==1.2.3" - }, "base58": { "hashes": [ "sha256:1e42993c0628ed4f898c03b522b26af78fb05115732549b21a028bc4633d19ab", From 361d6d4b067d00e9c401fe4306d29e06a2a904c5 Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Mon, 23 Jan 2023 21:50:57 +0100 Subject: [PATCH 5/8] block height support --- backend/cron.py | 1 + backend/main.py | 4 ---- backend/pasteNym.py | 21 ++++++++++----------- backend/serve.py | 42 ++++++++++++++++++++++-------------------- backend/utils.py | 2 +- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/backend/cron.py b/backend/cron.py index 144ddc4..bc13d20 100644 --- a/backend/cron.py +++ b/backend/cron.py @@ -46,6 +46,7 @@ def executeCron(self): if Cron.bitcoinExpirationEnabled(): heightNow = Cron.getCurrentHeight() + print(heightNow) if self.lastExecutionHeight <= heightNow: print(f"Number paste height deleted: {self.deleteExpiredHeightPaste(heightNow)}") self.lastExecutionHeight = heightNow diff --git a/backend/main.py b/backend/main.py index 0c18082..2431316 100644 --- a/backend/main.py +++ b/backend/main.py @@ -11,10 +11,6 @@ print("Create database done") db.create_tables() - - cron = cron.Cron() - cron.executeCron() - # init and start the backend server serveClient = Serve() diff --git a/backend/pasteNym.py b/backend/pasteNym.py index 1e18b8a..5dcaf4d 100644 --- a/backend/pasteNym.py +++ b/backend/pasteNym.py @@ -40,7 +40,7 @@ def newText(self, data): if data.get('burn') and type(data.get('burn')) == bool: burn = data.get('burn') - if data.get('burn_view') and type(data.get('burn_view')) == int and 0 < data.get('burn_view') <= 10000 : + if data.get('burn_view') and type(data.get('burn_view')) == int and 0 < data.get('burn_view') <= 10000: burn_view = data.get('burn_view') else: burn_view = 1 @@ -50,21 +50,19 @@ def newText(self, data): rel_expiration_time = data.get('expiration_time') try: # transform relative time from string to timestamp add in keyword to specify in future - expiration_time = dateparser.parse("in "+rel_expiration_time).timestamp() + expiration_time = dateparser.parse("in " + rel_expiration_time).timestamp() except Exception as e: print(f"Parsing time error, set to 0, {e}") expiration_time = 0 - expiration_height = None - if data.get('expiration_height') and type(data.get('expiration_height')) == int: - expiration_height = data.get('expiration_height') - if expiration_height > 0: - expiration_height += cron.Cron.getCurrentHeight() + if data.get('expiration_height') and type( + data.get('expiration_height')) == int and data.get('expiration_height') > 0: + if utils.BITCOIN_RPC_URL: + expiration_height = data.get('expiration_height') + cron.Cron.getCurrentHeight() else: - print(f"Parsing height error, height must be positive") - - + print("error: Bitcoin block not working") + return None # by default the pastes are not uploaded to IPFS ipfs = False @@ -107,7 +105,8 @@ def newText(self, data): while self.db.idExists(urlId) is not None: urlId = utils.generateRandomString(self.idLength) - return self.db.insertText(html.escape(text), urlId, encParamsB64, burn_view, private, burn, ipfs, expiration_time, expiration_height) + return self.db.insertText(html.escape(text), urlId, encParamsB64, burn_view, private, burn, ipfs, + expiration_time, expiration_height) except (KeyError, AttributeError) as e: diff --git a/backend/serve.py b/backend/serve.py index 57240e6..7a06ab1 100644 --- a/backend/serve.py +++ b/backend/serve.py @@ -10,7 +10,6 @@ import ipfsHandler import rel - self_address_request = json.dumps({ "type": "selfAddress" }) @@ -22,8 +21,8 @@ NYM_KIND_TEXT = b'\x00' # uint8 NYM_KIND_BINARY = b'\x01' -NYM_HEADER_SIZE_TEXT = b'\x00'*8 # set to 0 if it's a text -NYM_HEADER_BINARY = b'\x00'*8 # not used now, to investigate later +NYM_HEADER_SIZE_TEXT = b'\x00' * 8 # set to 0 if it's a text +NYM_HEADER_BINARY = b'\x00' * 8 # not used now, to investigate later class Serve: @@ -31,15 +30,15 @@ class Serve: @staticmethod def createPayload(recipient, reply_message, is_text=True): if is_text: - metadata = (NYM_KIND_TEXT+NYM_HEADER_SIZE_TEXT).decode('utf-8') + metadata = (NYM_KIND_TEXT + NYM_HEADER_SIZE_TEXT).decode('utf-8') else: # not used now, to investigate later - metadata = (NYM_KIND_BINARY+NYM_HEADER_BINARY).decode('utf-8') + metadata = (NYM_KIND_BINARY + NYM_HEADER_BINARY).decode('utf-8') return json.dumps({ "type": "send", # append \x00 because of "kind" message is non binary and equal 0 + 1 bytes because no header are set - "message": metadata+reply_message, + "message": metadata + reply_message, "recipient": recipient, "withReplySurb": False # "replySurb": reply_surb @@ -49,17 +48,19 @@ def __init__(self): url = f"ws://{utils.NYM_CLIENT_ADDR}:1977" self.firstRun = True self.pasteNym = PasteNym() - self.cron= Cron() + self.cron = Cron() + self.cron.executeCron() + websocket.enableTrace(False) self.ws = websocket.WebSocketApp(url, on_message=lambda ws, msg: self.on_message( ws, msg), on_error=lambda ws, msg: self.on_error( ws, msg), - on_close=lambda ws: self.on_close( + on_close=lambda ws: self.on_close( ws), - on_open=lambda ws: self.on_open(ws), - on_pong=lambda ws,msg: self.on_pong(ws,msg) + on_open=lambda ws: self.on_open(ws), + on_pong=lambda ws, msg: self.on_pong(ws, msg) ) # Set dispatcher to automatic reconnection @@ -69,7 +70,8 @@ def __init__(self): rel.signal(2, rel.abort) # Keyboard Interrupt rel.dispatch() self.ws.close() - def on_pong(self,ws,msg): + + def on_pong(self, ws, msg): self.cron.executeCron() ws.send(self_address_request) @@ -155,8 +157,6 @@ def on_message(self, ws, message): print(f"No recipient found in message {received_message}") return None - # excute cron.py - reply = "" if recipient is not None: @@ -168,7 +168,7 @@ def on_message(self, ws, message): reply = self.getVersion(recipient) else: reply = f"Error event {event} not found" - + if utils.DEBUG: print(f"-> Rcv {event} - answers {reply} over the mix network.") else: @@ -193,7 +193,7 @@ def newText(self, recipient, message): reply_message['ipfs'] = urlId[0].get('is_ipfs') reply_message.update({"hash": urlId[0].get('url_id')}) - reply_message.update({ "url_id": urlId[0].get('url_id')}) + reply_message.update({"url_id": urlId[0].get('url_id')}) else: reply_message = "Error" except IndexError as e: @@ -220,11 +220,11 @@ def getText(self, recipient, message): if type(createdOn) == str: # remove the microseconds - text['created_on'] = datetime.strptime(createdOn.split(".")[0],"%Y-%m-%dT%H:%M:%S") + text['created_on'] = datetime.strptime(createdOn.split(".")[0], "%Y-%m-%dT%H:%M:%S") elif createdOn is not None: text['created_on'] = datetime.isoformat( - createdOn)+'Z' + createdOn) + 'Z' reply_message = json.dumps(text, default=str) else: @@ -235,7 +235,9 @@ def getText(self, recipient, message): return Serve.createPayload(recipient, reply_message) - def getVersion(self,recipient): - reply_message=json.dumps({"version": utils.VERSION,"alive":True}) - return Serve.createPayload(recipient,reply_message) + def getVersion(self, recipient): + capabilities = {'ipfsHosting': utils.IPFS_HOST is not None, + 'expirationBitcoinHeight': utils.BITCOIN_RPC_URL is not None} + reply_message = {"version": utils.VERSION, "alive": True, "capabilities": capabilities} + return Serve.createPayload(recipient, json.dumps(reply_message)) diff --git a/backend/utils.py b/backend/utils.py index 23dca91..55a6d49 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -14,7 +14,7 @@ PASTE_MAX_LENGTH = 10 ** 100 # very big limit because right now we accept file DEBUG = bool(os.getenv("DEBUG", 'False').lower() in ('true', '1', 't')) -IPFS_HOST = os.getenv("IPFS_HOST", "localhost") +IPFS_HOST = os.getenv("IPFS_HOST", None) IPFS_CLUSTER_HOST = os.getenv("IPFS_CLUSTER_HOST", None) BITCOIN_RPC_URL=os.getenv("BITCOIN_RPC_URL",None) From 6a021dfdbabfee44a259c370d184a090c2c4bccd Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Tue, 24 Jan 2023 18:32:50 +0100 Subject: [PATCH 6/8] expiration heigth --- backend/cron.py | 29 +++++++++++++++++++---------- backend/pasteNym.py | 7 ++++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/backend/cron.py b/backend/cron.py index bc13d20..dc81f37 100644 --- a/backend/cron.py +++ b/backend/cron.py @@ -5,7 +5,7 @@ import db import utils -TIME_EXECUTION_TIME_MINUTES = 1 +TIME_EXECUTION_TIME_MINUTES = 0 class Cron: @@ -17,21 +17,28 @@ def __init__(self): timestampNow = time.time() self.lastExecutionTime = timestampNow + # test if connection to Bitcoin Core is working + self.bitcoinCoreWorking = False + if Cron.bitcoinExpirationEnabled(): - try: - self.rpc_connection = AuthServiceProxy( + self.rpc_connection = AuthServiceProxy( f"http://{utils.BITCOIN_USER}:{utils.BITCOIN_PASSWORD}@{utils.BITCOIN_RPC_URL}:{utils.BITCOIN_RPC_URL_PORT}") - self.lastExecutionHeight = Cron.getCurrentHeight() - except Exception: - print("Error connection to bitcoin core rpc") - traceback.print_exc() + self.lastExecutionHeight = Cron.getCurrentHeight() + + if self.lastExecutionHeight > 0: + self.bitcoinCoreWorking = True + + if not(self.bitcoinCoreWorking): + print("Connection to Bitcoin Core is not working. Paste height expiration is disabled") + def executeCron(self): if self.firstRun: print("First run delete job") print(f"Number paste time deleted: {self.deleteExpiredTimePaste()}") - if Cron.bitcoinExpirationEnabled(): + + if Cron.bitcoinExpirationEnabled() and self.bitcoinCoreWorking: print(f"Number paste height deleted: {self.deleteExpiredHeightPaste(self.lastExecutionHeight)}") self.firstRun = False @@ -44,9 +51,10 @@ def executeCron(self): print(f"Number paste time deleted: {self.deleteExpiredTimePaste()}") self.lastExecutionTime = timestampNow - if Cron.bitcoinExpirationEnabled(): + if Cron.bitcoinExpirationEnabled() and self.bitcoinCoreWorking: + heightNow = Cron.getCurrentHeight() - print(heightNow) + if self.lastExecutionHeight <= heightNow: print(f"Number paste height deleted: {self.deleteExpiredHeightPaste(heightNow)}") self.lastExecutionHeight = heightNow @@ -59,6 +67,7 @@ def deleteExpiredHeightPaste(self, heightNow): return self.db.deletePasteExpirationHeight(heightNow) else: print("error with current height, cannot remove the paste") + return 0 @staticmethod def getCurrentHeight(): diff --git a/backend/pasteNym.py b/backend/pasteNym.py index 5dcaf4d..4d62bf4 100644 --- a/backend/pasteNym.py +++ b/backend/pasteNym.py @@ -59,7 +59,12 @@ def newText(self, data): if data.get('expiration_height') and type( data.get('expiration_height')) == int and data.get('expiration_height') > 0: if utils.BITCOIN_RPC_URL: - expiration_height = data.get('expiration_height') + cron.Cron.getCurrentHeight() + currentActual = cron.Cron.getCurrentHeight() + if currentActual > 0: + expiration_height = data.get('expiration_height') + currentActual + else: + print("error: with current height") + return None else: print("error: Bitcoin block not working") return None From 6389e6cfb9373b6dbf555d8309df50d2a8ec61f6 Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Tue, 24 Jan 2023 18:34:41 +0100 Subject: [PATCH 7/8] bump version --- backend/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/utils.py b/backend/utils.py index 55a6d49..9655e25 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -5,7 +5,7 @@ from cid import make_cid from dotenv import load_dotenv -VERSION="1.0.0" +VERSION="1.1.0" load_dotenv() From e1bcd2281cc1708bf622eb4f332f4da60d6fca71 Mon Sep 17 00:00:00 2001 From: cgi-bin Date: Tue, 24 Jan 2023 18:52:02 +0100 Subject: [PATCH 8/8] small changes --- README.md | 2 +- env.docker.example | 2 ++ example.docker-compose.yml | 49 +++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 9cf18ec..ead435d 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,6 @@ cp -r ~/.nym/clients/docker-client nym-data/clients * `backend/` manage the websockets connections and DB * [Frontend](https://github.com/notrustverify/pastenym-frontend) web application -* [CLI](https://github.com/notrustverify/pastenym-cli) CLI application to interact with pastenym without the frontend +* [CLI](https://github.com/notrustverify/pastenym-cli) application to interact with pastenym without the frontend * `nym-client/` store the configuration,keys for the nym-client * `resources/` store img or files for documentation diff --git a/env.docker.example b/env.docker.example index 2c88d20..4f07157 100644 --- a/env.docker.example +++ b/env.docker.example @@ -1,2 +1,4 @@ NYM_CLIENT_ADDR="nym-client" DEBUG=True + + diff --git a/example.docker-compose.yml b/example.docker-compose.yml index 11fccc6..fc91936 100644 --- a/example.docker-compose.yml +++ b/example.docker-compose.yml @@ -25,21 +25,36 @@ services: depends_on: - pastenym-backend - ipfs: - image: ipfs/kubo:latest - restart: unless-stopped - volumes: - - ./backend/ipfs/data:/data/ipfs - - ./backend/ipfs/ipfs_fuse:/ipfs - - ./backend/ipfs/ipns_fuse:/ipns - environment: - - IPFS_PATH=/data/ipfs - ports: - # Swarm listens on all interfaces, so is remotely reachable. - - 4001:4001/tcp - - 4001:4001/udp - # API port, which includes admin operations, so you probably don't want this remotely accessible. - - 127.0.0.1:5001:5001 - # HTTP Gateway - - 127.0.0.1:8080:8080 +# ipfs: +# image: ipfs/kubo:latest +# restart: unless-stopped +# volumes: +# - ./backend/ipfs/data:/data/ipfs +# - ./backend/ipfs/ipfs_fuse:/ipfs +# - ./backend/ipfs/ipns_fuse:/ipns +# environment: +# - IPFS_PATH=/data/ipfs +# ports: +# # Swarm listens on all interfaces, so is remotely reachable. +# - 4001:4001/tcp +# - 4001:4001/udp +# # API port, which includes admin operations, so you probably don't want this remotely accessible. +# - 127.0.0.1:5001:5001 +# # HTTP Gateway +# - 127.0.0.1:8080:8080 + +# bitcoin: +# image: ruimarinho/bitcoin-core +# command: +# -printtoconsole +# -server +# -prune=550 +# -rpcbind=0.0.0.0 +# -rpcallowip=0.0.0.0/0 +# -rpcuser=user +# -rpcpassword=user +# volumes: +# - ./bitcoin-core:/home/bitcoin/.bitcoin +# ports: +# - 127.0.0.1:8332:8332