Compare commits

...
534 Commits
Author SHA1 Message Date
Chris Troutner 00ff744726 Merge pull request #88 from Permissionless-Software-Foundation/helia
Bumping to v3.0. Helia & sync with ipfs-service-provider
2024-03-22 13:03:38 -07:00
Chris Troutner abd33c4ebd linting 2024-03-22 12:36:46 -07:00
Chris Troutner f091e088c4 Passing bchjs to ipfs adapter 2024-03-22 12:35:46 -07:00
Chris Troutner 4cf8129b9d Fixed tests 2024-03-22 12:30:45 -07:00
Chris Troutner d8f2dd5755 linting 2024-03-22 10:59:36 -07:00
Chris Troutner a2232f7147 Fixed merge conflicts 2024-03-22 10:59:22 -07:00
Chris Troutner a79d152993 Merge pull request #143 from Permissionless-Software-Foundation/ct-unstable
fix(helia-coord): Updating to v1.5.5
2024-03-12 08:32:05 -07:00
Chris Troutner ce7c3a0e2f fix(helia-coord): Updating to v1.5.5 2024-03-12 08:30:32 -07:00
Chris Troutner e6b0580209 Merge pull request #142 from Permissionless-Software-Foundation/ct-unstable
Back to 100% unit test coverage
2024-03-10 07:44:19 -07:00
Chris Troutner 1f3c639100 fix(tests): Back to 100% unit test coverage 2024-03-10 07:43:06 -07:00
Chris Troutner e6efc4f49b Prototyped /ipfs/download 2024-03-07 21:27:06 -08:00
Chris Troutner dbbd321029 fix(/ipfs/node): Added unit tests for API controller 2024-03-07 18:55:09 -08:00
Chris Troutner 439dbc54ae fix(ipfs): Increased adapter to 100% unit test coverage 2024-03-07 10:22:25 -08:00
Chris Troutner 547e59f52f fix(Docker): Adding .env file 2024-03-04 10:47:08 -08:00
Chris Troutner a0d385de73 Merge pull request #141 from Permissionless-Software-Foundation/ct-unstable
fix(helia-coord): Updating to v1.5.4, fixes minor bug
2024-03-03 06:46:38 -08:00
Chris Troutner bec136009f fix(helia-coord): Updating to v1.5.4, fixes minor bug 2024-03-03 06:44:24 -08:00
Chris Troutner 98b7fa7734 Merge pull request #140 from Permissionless-Software-Foundation/ct-unstable
Removing Circuit Relay for nodes configured for direct connection
2024-02-05 06:41:01 -08:00
Chris Troutner d7bb476858 fix(circuit-relay): Removing CR transport if node is configured for direct connection 2024-02-05 06:39:01 -08:00
Chris Troutner 18c71c383f fix(webrtc): Upgrading from v3.2.11 to v4.0.17 2024-02-05 06:26:01 -08:00
Chris Troutner de85a933c4 fix(webrtc): Adding @libp2p/webrtc 2024-02-04 20:43:34 -08:00
Chris Troutner 16247372f1 linting 2024-02-04 20:35:34 -08:00
Chris Troutner c6c8b6418c Prototyping download REST API 2024-02-04 20:35:22 -08:00
Chris Troutner 10c4e7380f fix(webrtc): Removing webrtc library 2024-01-31 09:38:18 -08:00
Chris Troutner 4933dce472 Merge pull request #139 from Permissionless-Software-Foundation/ct-unstable
fix(webRTC): Explicitly adding @libp2p/webrtc package
2024-01-31 08:50:43 -08:00
Chris Troutner 80c2822716 fix(webRTC): Explicitly adding @libp2p/webrtc package 2024-01-31 08:42:38 -08:00
Chris Troutner f48ff9a67e Merge pull request #138 from Permissionless-Software-Foundation/ct-unstable
fix(helia-coord): Updating to v1.5.3
2024-01-30 19:45:57 -08:00
Chris Troutner 4bd2385359 fix(helia-coord): Updating to v1.5.3 2024-01-30 19:44:29 -08:00
Chris Troutner be71492773 Merge pull request #137 from Permissionless-Software-Foundation/ct-unstable
fix(createNode()): Updating RSA to Ed25519 keys
2024-01-29 07:58:49 -08:00
Chris Troutner bcb70edf2b fix(createNode()): Updating RSA to Ed25519 keys 2024-01-29 07:57:32 -08:00
Chris Troutner 07071032bc Merge pull request #136 from Permissionless-Software-Foundation/ct-unstable
fix(Docker): Updated new node.js installation
2024-01-28 19:57:45 -08:00
Chris Troutner f476e119a2 fix(Docker): Updated new node.js installation 2024-01-28 19:54:21 -08:00
Chris Troutner 0fed232428 Merge pull request #135 from Permissionless-Software-Foundation/ct-unstable
fix(Docker): Switching to ct-unstable branch
2024-01-28 19:42:02 -08:00
Chris Troutner 0273510485 fix(Docker): Switching to ct-unstable branch 2024-01-28 19:38:42 -08:00
Chris Troutner a62dee37f4 Merge pull request #134 from Permissionless-Software-Foundation/v1.0.10
libp2p v1.2.1
2024-01-28 19:36:24 -08:00
Chris Troutner 8d6af3e1b7 fix(helia-coord): Updating to v1.4.3 2024-01-28 15:17:01 -08:00
Chris Troutner ee0f2da641 fix(docker): Building container rather than using image 2024-01-28 15:05:34 -08:00
Chris Troutner 44499d9652 Updating Dockerfile to use v1.0.10 branch 2024-01-28 15:00:30 -08:00
Chris Troutner 365a5dcd4b Updated to libp2p 1.2.1 2024-01-28 14:59:25 -08:00
Chris Troutner 7f5b456018 linting 2024-01-28 14:13:42 -08:00
Chris Troutner c7217486bd fix(getSeed()): Generates seed for IPFS private key 2024-01-28 12:49:18 -08:00
Chris Troutner 050141d31e Creating todo for seed 2024-01-28 08:22:55 -08:00
Chris Troutner b697f37199 fix(keys): Creating persistent keystore for libp2p v1.0.x 2024-01-28 08:19:38 -08:00
Chris Troutner ceb58caba1 linting 2024-01-28 08:04:02 -08:00
Chris Troutner 2724b500ee Got keychain working for first time 2024-01-28 08:03:41 -08:00
Chris Troutner 1b84e7beb8 Merge pull request #133 from Permissionless-Software-Foundation/v0.46.21
fix(pubsub): Removing chat handler causing screen spam
2024-01-27 17:48:29 -08:00
Chris Troutner 383900d8b5 fix(pubsub): Removing chat handler causing screen spam 2024-01-27 17:45:23 -08:00
Chris Troutner ba806d86b5 Merge pull request #132 from Permissionless-Software-Foundation/v0.46.21
Updated to helia-coord v1.4.1
2024-01-27 15:02:57 -08:00
Chris Troutner 4d7c7350a0 linting 2024-01-27 15:01:01 -08:00
Chris Troutner adc6500aed Adding config options for V2 Circuit Relay server 2024-01-27 13:17:34 -08:00
Chris Troutner eb9fce73eb Updated helia-coord to v1.4.1 2024-01-27 10:45:44 -08:00
Chris Troutner ec3ed165e4 feat(GET /ipfs/node): Retrieves thisNode object 2024-01-27 09:26:50 -08:00
Chris Troutner d41d20cc81 prototyping keychain example 2024-01-26 19:52:55 -08:00
Chris Troutner 5f965e7146 Switching back to libp2p v0.46.21 2024-01-11 12:26:16 -08:00
Chris Troutner f382bb4578 Merge pull request #131 from Permissionless-Software-Foundation/ct-unstable
Helia v1.2.24 - recommended peers from gist
2023-12-18 20:56:26 -08:00
Chris Troutner ba37f87f80 fix(helia-coord): updating to v1.2.24, adding recommended peers 2023-12-18 20:55:25 -08:00
Chris Troutner eaa9c23f55 Updating helia-coord ot v1.2.23 2023-12-16 06:42:12 -08:00
Chris Troutner ac3730dbd9 Merge pull request #130 from Permissionless-Software-Foundation/libp2p-v1
Libp2p v1
2023-12-13 19:46:43 -08:00
Chris Troutner 581b8eb626 fix(libp2p): Updating to v1.0.10 2023-12-13 19:44:58 -08:00
Chris Troutner cd4ec2711e Updated circuit-relay library 2023-12-06 10:32:59 -08:00
Chris Troutner e9e3dbad0d Updated to libp2p 1.0.9, added @libp2p/identify 2023-12-06 10:20:48 -08:00
Chris Troutner 295b361431 Merge pull request #129 from Permissionless-Software-Foundation/ct-unstable
Updating helia-coord to v1.2.21
2023-12-04 08:53:58 -08:00
Chris Troutner ad60df9d51 Updating helia-coord to v1.2.21 2023-12-04 08:52:16 -08:00
Chris Troutner 6ae635c21d Merge pull request #128 from Permissionless-Software-Foundation/ct-unstable
fix(bootstrap): Loading bootstrap nodes from gist only
2023-12-04 07:27:14 -08:00
Chris Troutner 61807a2f3d fix(bootstrap): Loading bootstrap nodes from gist only 2023-12-04 07:25:32 -08:00
Chris Troutner 16ba5a8980 Merge pull request #127 from Permissionless-Software-Foundation/ct-unstable
fix(deps): Updating helia-coord and helia
2023-12-03 16:43:34 -08:00
Chris Troutner 99b817549e fix(deps): Updating helia-coord and helia 2023-12-03 16:42:32 -08:00
Chris Troutner 60a8c335c8 Merge pull request #126 from Permissionless-Software-Foundation/ct-unstable
fix(helia-coord): Updated to v1.2.18
2023-12-03 09:42:52 -08:00
Chris Troutner 1783768c32 fix(helia-coord): Updated to v1.2.18 2023-12-03 09:41:42 -08:00
Chris Troutner b3630eaa06 Merge pull request #125 from Permissionless-Software-Foundation/ct-unstable
fix(helia): Upgrade to v0.46.21
2023-12-03 09:04:01 -08:00
Chris Troutner d691016911 fix(helia): Upgrade to v0.46.21 2023-12-03 09:01:03 -08:00
Chris Troutner 6506aead8c Merge pull request #124 from Permissionless-Software-Foundation/ct-unstable
fix(webrtc): Adding webrtc as a transport
2023-12-03 07:37:11 -08:00
Chris Troutner ddfc83d026 fix(webrtc): Adding webrtc as a transport 2023-12-03 07:35:47 -08:00
Chris Troutner fe42c1e0e3 Merge pull request #123 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs): Autodetecting ip addr and adding to multiaddr
2023-12-03 07:30:15 -08:00
Chris Troutner 928a211a63 fix(ipfs): Autodetecting ip addr and adding to multiaddr 2023-12-03 07:28:31 -08:00
Chris Troutner 8bff69a4ca Merge pull request #122 from Permissionless-Software-Foundation/ct-unstable
fix(helia-coord): Updating to v1.2.17
2023-12-02 17:12:47 -08:00
Chris Troutner 5fced7d501 fix(helia-coord): Updating to v1.2.17 2023-12-02 17:11:05 -08:00
Chris Troutner 7cdf622ad6 Merge pull request #121 from Permissionless-Software-Foundation/ct-unstable
fix(helia-coord): Updating helida-coord to v1.2.16
2023-12-02 14:13:43 -08:00
Chris Troutner afd8ceac7b fix(helia-coord): Updating helida-coord to v1.2.16 2023-12-02 14:12:32 -08:00
Chris Troutner 5d63db3662 Merge pull request #120 from Permissionless-Software-Foundation/ct-unstable
fix(helia-coord): Updating to v1.2.5
2023-11-04 08:47:34 -07:00
Chris Troutner 9f6cd7dbf1 fix(helia-coord): Updating to v1.2.5 2023-11-04 08:45:46 -07:00
Chris Troutner 0725aa3ada Merge pull request #119 from Permissionless-Software-Foundation/ct-unstable
fix(peers): Adding connectionAddr to /ipfs/peers
2023-11-03 14:42:28 -07:00
Chris Troutner 3eb88d4076 fix(peers): Adding connectionAddr to /ipfs/peers 2023-11-03 14:33:58 -07:00
Chris Troutner 1c61f150b1 fix(v1 relays): Discerning between v1 and v2 circuit relays 2023-11-03 12:07:43 -07:00
Chris Troutner 4c74b287d8 Merge pull request #118 from Permissionless-Software-Foundation/ct-unstable
feat(/ipfs/connect): Adding REST API endpoint to connect to an IPFS peer
2023-11-01 14:18:51 -07:00
Chris Troutner 264d762f74 feat(/ipfs/connect): Adding REST API endpoint to connect to an IPFS peer 2023-11-01 14:17:24 -07:00
Chris Troutner 3c02461c6b Merge pull request #117 from Permissionless-Software-Foundation/ct-unstable
fix(circuit relay): Adding ability to creating and consume circuit re…
2023-10-29 16:41:52 -07:00
Chris Troutner a30f2be51f fix(circuit relay): Adding ability to creating and consume circuit relays 2023-10-29 16:39:35 -07:00
Chris Troutner 0690a9fb65 Merge pull request #116 from Permissionless-Software-Foundation/ct-unstable
fix(README): Adding link to video demo
2023-10-28 13:57:55 -07:00
Chris Troutner 4fa103765e Merge branch 'master' into ct-unstable 2023-10-28 13:51:35 -07:00
Chris Troutner b0d6ce40a9 fix(README): Adding link to video demo 2023-10-28 13:50:46 -07:00
Chris Troutner c57a3d935b Merge pull request #115 from Permissionless-Software-Foundation/ct-unstable
Updating Docker container for production
2023-10-28 11:32:24 -07:00
Chris Troutner 82b5943601 Adding collaborative coinjoin project to README 2023-10-28 11:30:57 -07:00
Chris Troutner 41b76967f5 Adding production section back to README 2023-10-28 11:27:06 -07:00
Chris Troutner e4c2ee44c1 fix(production): Updating docker container 2023-10-28 11:24:40 -07:00
Chris Troutner c05f022995 Bumping to v5.0.0 2023-10-28 10:32:45 -07:00
Chris Troutner 7723c3a201 Merge pull request #114 from Permissionless-Software-Foundation/helia
Helia refactor. v4.0.0
2023-10-28 10:24:20 -07:00
Chris Troutner 8e338818ca Updating READMe 2023-10-28 10:19:59 -07:00
Chris Troutner ea51aa420c Updating README 2023-10-28 10:14:42 -07:00
Chris Troutner bc410678b4 Updating README and package.json 2023-10-28 10:11:04 -07:00
Chris Troutner a42c15c969 Updating package.json 2023-10-28 09:55:41 -07:00
Chris Troutner a3102a0278 Cleaned up comments 2023-10-28 09:50:12 -07:00
Chris Troutner f4f142dc48 fix(tests): Increased test coverage to 100% 2023-10-28 09:17:48 -07:00
Chris Troutner e03a70c9a3 fix(get-peers): finalizing REST endpoint behavior 2023-10-27 17:39:24 -07:00
Chris Troutner d47b8797d4 fix(libp2p): Updated to v0.46.16 2023-10-25 22:13:35 -07:00
Chris Troutner 56ba0aad02 Adding IPFS REST API endpoints 2023-10-23 20:28:17 -07:00
Chris Troutner 825bc6d2de fix(ipfs): Creating block & data store directories if they don't exit 2023-10-23 09:16:06 -07:00
Chris Troutner 18fe63a5ad fix(tests): Fixed broken tests 2023-10-22 17:35:10 -07:00
Chris Troutner d6e0e7b903 got helia working 2023-10-22 07:51:45 -07:00
Chris Troutner 8759e1af5e Merge pull request #113 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord-esm): Updating to v9.1.13
2023-08-29 16:38:56 -07:00
Chris Troutner b78f3fb08b fix(ipfs-coord-esm): Updating to v9.1.13 2023-08-29 16:34:41 -07:00
Chris Troutner 5fa0b2e1c8 Merge pull request #112 from Permissionless-Software-Foundation/ct-unstable
fix(license): Updating license file
2023-06-25 06:15:14 -07:00
Chris Troutner 6a88d0559a fix(license): Updating license file 2023-06-25 06:13:22 -07:00
Chris Troutner 314fdc2bb0 fix(minimal-slp-wallet): Updating to v5.11.1 2023-06-25 06:11:45 -07:00
Chris Troutner 077c60bd34 Merge pull request #111 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord-esm): Updating to v9.1.9
2023-05-13 07:06:26 -07:00
Chris Troutner 6485537207 Turning down debug logs 2023-05-13 07:03:49 -07:00
Chris Troutner 286f079679 fix(ipfs-coord-esm): Updating to v9.1.9 2023-05-13 06:59:25 -07:00
Chris Troutner 075818d551 Adding test coverage reporting for just unit tests 2023-05-12 15:25:58 -07:00
Chris Troutner 6f620a7323 Debugging 2023-05-12 07:25:23 -07:00
Chris Troutner d0a23608e0 Merge pull request #87 from Permissionless-Software-Foundation/ct-unstable
fix(deps): Updating npm dependencies:
2023-05-12 06:49:00 -07:00
Chris Troutner 6cc5196a78 fix(deps): Updating npm dependencies: 2023-05-12 06:47:41 -07:00
Chris Troutner 9de2caba94 Merge pull request #110 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord-esm): Updating to 9.1.7
2023-05-09 09:00:04 -07:00
Chris Troutner a45fb3ad08 fix(ipfs-coord-esm): Updating to 9.1.7 2023-05-09 08:56:26 -07:00
Chris Troutner 666f954529 Merge pull request #109 from Permissionless-Software-Foundation/ct-unstable
Minor Fixes
2023-05-09 08:07:55 -07:00
Chris Troutner 7d2e02fe64 fix(timer-controller): Adding unit tests for startTimers() 2023-05-09 08:06:57 -07:00
Chris Troutner 9912ed7af7 fix(json-files): Rejecting promise rather than throwing an error 2023-05-09 08:00:30 -07:00
Chris Troutner 441d898ae7 fix(timer controller): Preventing duplicate timer controllers 2023-05-08 08:01:02 -07:00
Chris Troutner 553a7ff86a Merge pull request #108 from Permissionless-Software-Foundation/ct-unstable
feat(ipfs): Allowing disabling IPFS features with config flag
2023-04-10 09:22:11 -07:00
Chris Troutner 349d070273 feat(ipfs): Allowing disabling IPFS features with config flag 2023-04-10 09:19:51 -07:00
Chris Troutner 7b1aba9da8 Merge pull request #86 from Permissionless-Software-Foundation/ct-unstable
updating dependencies
2023-04-06 06:12:31 -07:00
Chris Troutner 3539f0af50 fix(deps): Updating dependencies 2023-04-06 06:11:08 -07:00
Chris Troutner b6dcb9c177 Updating link to clean architecture 2023-03-22 17:10:51 -07:00
Chris Troutner 8aff3a6568 Merge pull request #107 from Permissionless-Software-Foundation/ct-unstable
feat(timer-controllers): Added template for timer-based controllers
2023-02-25 06:10:53 -08:00
Chris Troutner 9e885b8bc3 feat(timer-controllers): Added template for timer-based controllers 2023-02-25 06:09:56 -08:00
Chris Troutner d6b924a5f4 Merge pull request #106 from Permissionless-Software-Foundation/ct-unstable
Updating ipfs-coord-esm for bch-coinjoin pubsub
2023-02-24 13:50:17 -08:00
Chris Troutner 97691a0dd9 fix(minimal-slp-wallet): Updated to v5.8.5 2023-02-24 13:47:22 -08:00
Chris Troutner 3781af6305 fix(ipfs-coord-esm): Updating to v9.1.5 2023-02-24 13:45:48 -08:00
Chris Troutner cb5d5a603d fixing typo in user REST controller 2023-02-23 08:36:47 -08:00
Chris Troutner 34fa039ced Removing debugging 2023-02-08 15:08:00 -08:00
Chris Troutner f42ccafffa More debugging 2023-02-08 14:52:17 -08:00
Chris Troutner 842e6ead69 Debugging utxoBulk 2023-02-08 14:33:15 -08:00
Chris Troutner 62ef3e0a93 Merge pull request #85 from Permissionless-Software-Foundation/ct-unstable
Created JSON RPC endpoint for bulk UTXO lookup
2023-02-08 05:43:25 -08:00
Chris Troutner c9ab4b5ef8 fix(tests): Got unit tests to 100% 2023-02-08 05:37:12 -08:00
Chris Troutner f338f26593 fix(tests): Increased test coverage 2023-02-08 05:33:48 -08:00
Chris Troutner dc302066f0 linting 2023-02-08 05:20:58 -08:00
Chris Troutner fe5c95078b feat(utxoBulk): Created JSON RPC endpoint for bulk UTXO lookup 2023-02-08 05:20:38 -08:00
Chris Troutner c21554008c Merge pull request #84 from Permissionless-Software-Foundation/ct-unstable
fix(getTokenData2()): Adding updateCache argument
2023-01-26 18:03:17 -08:00
Chris Troutner e2a900d3a0 fix(getTokenData2()): Adding updateCache argument 2023-01-26 18:01:13 -08:00
Chris Troutner c870b54cae fix(getTokenData2()): Adding updateCache argument 2023-01-26 18:00:05 -08:00
Chris Troutner 81713bfebe Updating README 2023-01-16 05:37:52 -08:00
Chris Troutner 0f8a6b9299 Merge pull request #103 from Permissionless-Software-Foundation/ct-unstable
fix(minimal-slp-wallet): Updating to v5.5.5
2022-12-05 13:53:19 -08:00
Chris Troutner 4f2c87bbd4 fix(minimal-slp-wallet): Updating to v5.5.5 2022-12-05 13:51:41 -08:00
Chris Troutner dd7db3814a Merge pull request #102 from Permissionless-Software-Foundation/ct-unstable
fix(minimal-slp-wallet): Updating to v5.5.3
2022-11-30 15:06:29 -08:00
Chris Troutner fdb3b9c3ac fix(minimal-slp-wallet): Updating to v5.5.3 2022-11-30 14:59:54 -08:00
Chris Troutner f022951680 Merge pull request #83 from Permissionless-Software-Foundation/ct-unstable
fix(deps): Updating dependencies
2022-11-02 04:56:51 -07:00
Chris Troutner 942a8f20ec fix(deps): Updating dependencies 2022-11-02 04:54:46 -07:00
Chris Troutner 683c1e4b2b Merge pull request #82 from Permissionless-Software-Foundation/ct-unstable
fix(getTokenData2): Adding token icon lookup
2022-10-06 21:10:50 -07:00
Chris Troutner 953690baa5 fix(getTokenData2): Adding token icon lookup 2022-10-06 21:07:12 -07:00
Chris Troutner c13a5d1593 Merge pull request #101 from Permissionless-Software-Foundation/ct-unstable
Increased test coverage to 100%
2022-09-17 15:24:26 -07:00
Chris Troutner 6d7b3db370 Using latest version of ipfs-coord-esm 2022-09-17 15:19:37 -07:00
Chris Troutner 33d06e99e8 fix(tests): got ipfs-coord lib to 100% test coverage 2022-09-17 14:51:57 -07:00
Chris Troutner 3203e56a4d fix(tests): Added user e2e tests back in 2022-09-17 14:47:17 -07:00
Chris Troutner ff47f1b356 fix(test): Got use cases to 100% test coverage 2022-09-17 14:23:46 -07:00
Chris Troutner d9377ea78b fix(tests): Increased coverage of REST API validators 2022-09-17 14:18:16 -07:00
Chris Troutner d266bcc54b fix(deps): Updating dependencies 2022-09-17 10:10:39 -07:00
Chris Troutner a033fb1042 fix(tests): Replacing nyc with c8, for test coverage of ESM 2022-09-16 08:38:53 -07:00
Chris Troutner 569dcbd576 Merge pull request #100 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to new version to fix bugs
2022-09-08 09:32:01 -07:00
Chris Troutner b0a2d73540 fix(ipfs-coord): Updating to new version to fix bugs 2022-09-08 09:30:21 -07:00
Chris Troutner 0d4c8cd56e Merge pull request #99 from Permissionless-Software-Foundation/ct-unstable
Breaking change: Converted from CommonJS to ESM
2022-09-08 09:00:19 -07:00
Chris Troutner b37dae60d1 fix(ESM): Converted from CommonJS to ESM 2022-09-08 08:59:03 -07:00
Chris Troutner 448b028bb4 fixed linting issue 2022-09-08 08:58:39 -07:00
Chris Troutner da637df44a Merge pull request #98 from Permissionless-Software-Foundation/ct-unstable
Using bandwidth limited IPFS Docker container
2022-08-27 13:43:51 -07:00
Chris Troutner 9315e6f166 fix(production): Updating docker image 2022-08-27 13:39:06 -07:00
Chris Troutner 7e965e8415 Adding comments 2022-08-27 12:59:20 -07:00
Chris Troutner a5916c95f9 fix(production): Using bandwidth limited IPFS Docker container 2022-08-27 12:58:41 -07:00
Chris Troutner 708f97d107 More dependency updates 2022-08-27 12:55:24 -07:00
Chris Troutner 637738bfb9 Updated npm deps 2022-08-27 12:53:43 -07:00
Chris Troutner d8e82c5ad2 fix(ipfs-coord): Updating to v8.0.5 2022-08-27 12:52:16 -07:00
Chris Troutner 80a65c4e03 Merge pull request #81 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs): Swapping out IPFS docker container with bandwidth limited …
2022-08-22 16:56:28 -07:00
Chris Troutner 63ecd21734 fix(ipfs): Swapping out IPFS docker container with bandwidth limited version 2022-08-22 16:52:11 -07:00
Chris Troutner ae957a835a Merge pull request #80 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2022-08-03 18:34:50 -07:00
Chris Troutner c61feba1e6 Fixing merge conflicts with upstream 2022-08-03 17:47:00 -07:00
Chris Troutner 8a05f1f063 fix(deps): Updating dependencies 2022-08-03 17:43:28 -07:00
Chris Troutner b23acd3cdc Merge pull request #97 from Permissionless-Software-Foundation/ct-unstable
fix(production): Switching to Docker Image
2022-07-25 19:17:27 -07:00
Chris Troutner c71fda38ff fix(production): Switching to Docker Image 2022-07-25 19:14:44 -07:00
Chris Troutner f99f49d840 Merge pull request #96 from Permissionless-Software-Foundation/ct-unstable
Configuring ports with env vars
2022-07-25 17:58:40 -07:00
Chris Troutner 2edd924c57 fix(production): Adding 4003 websocket port 2022-07-25 17:56:02 -07:00
Chris Troutner 689c8fd8d9 fix(ipfs): Using config to set ports 2022-07-25 17:40:05 -07:00
Chris Troutner ffd6c452c9 Merge pull request #95 from Permissionless-Software-Foundation/ct-unstable
fix(mocks): Another update to IPFS test mocks
2022-07-24 08:15:55 -07:00
Chris Troutner fc8e160874 fix(mocks): Another update to IPFS test mocks 2022-07-24 08:14:27 -07:00
Chris Troutner d2f83307e6 Merge pull request #94 from Permissionless-Software-Foundation/ct-unstable
fix(mocks): Improvement to adapter mocks used in tests
2022-07-24 08:08:13 -07:00
Chris Troutner 1a09fcd26f fix(mocks): Improvement to adapter mocks used in tests 2022-07-24 08:06:32 -07:00
Chris Troutner d095d40b3f Merge pull request #79 from Permissionless-Software-Foundation/ct-unstable
fix(getTokenData): JSON controller accepts flag for showing tx history
2022-07-12 15:04:56 -07:00
Chris Troutner fac9f12072 fix(getTokenData): JSON controller accepts flag for showing tx history 2022-07-12 15:02:40 -07:00
Chris Troutner 6b00513db7 Merge pull request #78 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2022-07-08 09:03:54 -07:00
Chris Troutner 4387c9a758 fix(production): Updating docker file 2022-07-08 09:01:04 -07:00
Chris Troutner 469f1e05e8 fix(startup): Fixing bug from merge with upstream 2022-07-08 08:51:16 -07:00
Chris Troutner 3b836a7a35 Fixing merge conflicts with upstream 2022-07-08 08:46:05 -07:00
Chris Troutner fd1b13a917 Minor edit to documentation 2022-07-08 08:35:26 -07:00
Chris Troutner e2c5821dbe Merge pull request #93 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating bootstrap nodes
2022-07-07 15:56:42 -07:00
Chris Troutner 9967d5145b fix(ipfs-coord): Updating bootstrap nodes 2022-07-07 15:55:33 -07:00
Chris Troutner 9d16291855 Merge pull request #92 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v8
2022-07-07 15:17:09 -07:00
Chris Troutner 1518d1a12b fix(ipfs-coord): Updating to v8 2022-07-07 15:16:03 -07:00
Chris Troutner b68a143071 Merge pull request #91 from Permissionless-Software-Foundation/ct-unstable
Added hooks for async startup
2022-06-27 11:33:50 -07:00
Chris Troutner 5c25ebeeca Renaming mock log 2022-06-27 11:32:25 -07:00
Chris Troutner 3b17ba8e8b fix(logapi): Fixing issues with unit tests 2022-06-27 11:29:27 -07:00
Chris Troutner 434a4d7bd6 Refactoring failing unit tests 2022-06-27 10:25:19 -07:00
Chris Troutner dd36ebc7a0 Got test coverage back to 100% 2022-06-27 10:15:35 -07:00
Chris Troutner f117fe15df fix(startup): Added hooks for async startup 2022-06-27 10:09:08 -07:00
Chris Troutner 0333f77f5a Fixing broken link in README 2022-06-20 07:30:10 -07:00
Chris Troutner 3c908d1a4d Merge pull request #90 from Permissionless-Software-Foundation/ct-unstable
Increasing test coverage to 100%
2022-06-20 07:22:10 -07:00
Chris Troutner eb46a4c130 fix(tests): Got to 100% test coverage for entire repo 2022-06-20 07:19:36 -07:00
Chris Troutner d0efdcfa07 fix(ipfs-coord): Increased unit test coverage to 100% 2022-06-20 07:01:43 -07:00
Chris Troutner 62a7fcb16d fix(tests): Got bin/server.js unit test coverage to 100% 2022-06-19 20:21:40 -07:00
Chris Troutner d8addd5b27 Trying to build unit tests for bin/server 2022-06-19 20:00:25 -07:00
Chris Troutner bf6f1cf62d Merge pull request #89 from Permissionless-Software-Foundation/ct-unstable
Updating dependencies
2022-06-19 13:25:07 -07:00
Chris Troutner b7df7c47a5 Updated ipfs 2022-06-19 13:23:52 -07:00
Chris Troutner ae260db4af Updated some dependencies 2022-06-19 13:19:31 -07:00
Chris Troutner 778098ca12 fix(ipfs-coord): Updating to v7.1.19 2022-05-28 09:29:31 -07:00
Chris Troutner 0c4bb9c4a1 fix(ipfs-coord): Updating to v7.1.18 2022-05-28 09:09:44 -07:00
Chris Troutner 9cb975656d Merge pull request #88 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v7.1.17
2022-05-28 08:00:57 -07:00
Chris Troutner 4f6564423e fix(ipfs-coord): Updating to v7.1.17 2022-05-28 07:59:47 -07:00
Chris Troutner 54e7e74ae5 Merge pull request #87 from Permissionless-Software-Foundation/ct-unstable
Subscribing to chat channel at startup
2022-05-26 09:14:50 -07:00
Chris Troutner 324c372119 fix(startup): Subscribing to chat pubsub channel at startup 2022-05-26 09:12:15 -07:00
Chris Troutner da62f1bbe3 linting 2022-05-26 08:24:45 -07:00
Chris Troutner 129047fe88 fix(startup): Announcing config settings at startup 2022-05-26 08:24:30 -07:00
Chris Troutner fb182ced58 Merge pull request #86 from Permissionless-Software-Foundation/ct-unstable
Updating docker-compose file
2022-05-16 12:33:03 -07:00
Chris Troutner bec7c11e46 Updating README 2022-05-16 12:31:53 -07:00
Chris Troutner fb10e10226 fix(production): Updating docker images 2022-05-16 12:30:58 -07:00
Chris Troutner 5b37e47747 Merge pull request #85 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Updating to v6.4.1
2022-05-16 12:15:47 -07:00
Chris Troutner a3cea782ba fix(bch-js): Updating to v6.4.1 2022-05-16 12:14:20 -07:00
Chris Troutner 14ffdae194 Merge pull request #84 from Permissionless-Software-Foundation/dh-test-coverage
feat(coverage): Got ipfs-coord.js to 100% test coverage
2022-05-16 12:09:18 -07:00
Chris Troutner 79918f6376 Merge pull request #77 from Permissionless-Software-Foundation/ct-unstable
feat(getTokenData): Adding new endpoint for PS002 token data
2022-05-10 11:15:21 -07:00
Chris Troutner da5942b28f feat(getTokenData): Adding new endpoint for PS002 token data 2022-05-10 11:14:11 -07:00
Chris Troutner d54cd3889b Merge pull request #76 from Permissionless-Software-Foundation/ct-unstable
feat(utxoIsValid): Adding new bch endpoint
2022-05-10 10:16:15 -07:00
Chris Troutner 5df54feb5e feat(utxoIsValid): Adding new bch endpoint 2022-05-10 10:14:37 -07:00
Chris Troutner fb841df43e fix(bch-js): Updated to v6.3.4 2022-05-09 18:33:28 -07:00
Chris Troutner a763ec640f Merge pull request #75 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Updating to v6.2.14
2022-05-05 16:48:00 -07:00
Chris Troutner e74e063b0d fix(bch-js): Updating to v6.2.14 2022-05-05 16:46:50 -07:00
Daniel Gonzalez 7e3ce1564d feat(coverage): Got ipfs-coord.js to 100% test coverage 2022-03-25 22:12:11 -04:00
Chris Troutner 8154dd96f9 Merge pull request #83 from Permissionless-Software-Foundation/ct-unstable
fix(deps): Updating bch-js
2022-03-20 07:48:42 -07:00
Chris Troutner e37223cc88 fix(deps): Updating bch-js 2022-03-20 07:46:08 -07:00
Chris Troutner 5002ef2b90 Merge pull request #82 from Permissionless-Software-Foundation/dh-test-coverage-ipfsjs
feat(test): Got ipfs.js to 100% test coverage
2022-03-18 11:27:32 -07:00
Chris Troutner 5d95109ad4 more linting 2022-03-18 11:24:15 -07:00
Chris Troutner 13b3150f62 minor linting 2022-03-18 11:24:04 -07:00
Daniel Gonzalez b3a4a7c1ab feat(test): Got ipfs.js to 100% test coverage 2022-03-15 18:58:55 -04:00
Chris Troutner 142cdb17a6 fix(production): Updating IPFS docker container from v11 to v12 2022-03-15 14:12:11 -07:00
Chris Troutner a129988538 Merge pull request #74 from Permissionless-Software-Foundation/ct-unstable
Ct unstable
2022-03-10 09:55:32 -08:00
Chris Troutner 6bf85b4639 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2022-03-10 09:53:17 -08:00
Chris Troutner 733e8fd405 Merge pull request #81 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v7.1.6
2022-03-10 09:29:32 -08:00
Chris Troutner baee72c1c6 fix(ipfs-coord): Updating to v7.1.6 2022-03-10 09:27:13 -08:00
Chris Troutner 5d12749043 Merge pull request #73 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v7.1.5
2022-03-10 08:46:47 -08:00
Chris Troutner 2ebd8b998f Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2022-03-10 08:42:57 -08:00
Chris Troutner 11618a796f Merge pull request #80 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v7.1.5
2022-03-10 08:35:21 -08:00
Chris Troutner 025ae20704 fix(ipfs-coord): Updating to v7.1.5 2022-03-10 08:33:53 -08:00
Chris Troutner b9146bbff9 Merge pull request #72 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2022-03-08 10:15:33 -08:00
Chris Troutner 47f1b84dd8 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2022-03-08 10:13:37 -08:00
Chris Troutner fdf73610eb Merge pull request #79 from Permissionless-Software-Foundation/ct-unstable
fix(tests): Updating tests for node.js v16
2022-03-08 09:42:42 -08:00
Chris Troutner b09e77c079 fix(tests): Updating tests for node.js v16 2022-03-08 09:39:54 -08:00
Chris Troutner 5050816052 Merge pull request #71 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v7.1.4
2022-03-05 14:26:18 -08:00
Chris Troutner 7193b9d048 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2022-03-05 14:23:22 -08:00
Chris Troutner c2977c5264 fix(production): Updating to node v16 for IPFS 2022-03-05 14:23:14 -08:00
Chris Troutner 68ad2561b1 Merge pull request #78 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v7.1.4
2022-03-05 14:22:25 -08:00
Chris Troutner 791d11e597 Merge branch 'master' into ct-unstable 2022-03-05 14:20:19 -08:00
Chris Troutner 5489e76f55 fix(ipfs-coord): Updating to v7.1.4 2022-03-05 14:20:13 -08:00
Chris Troutner 2ad10180d0 Merge pull request #70 from Permissionless-Software-Foundation/ct-upstream
fix(ipfs-coord): Updating to v7.1.3
2022-03-05 08:35:10 -08:00
Chris Troutner dd42f5da16 fix(upstream): Syncing with upstream. Updating ipfs-coord 2022-03-05 08:32:38 -08:00
Chris Troutner 496a1dd07c Merge pull request #77 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v7.1.3
2022-03-05 08:26:32 -08:00
Chris Troutner a7b8ca9ad5 linting 2022-03-05 08:24:50 -08:00
Chris Troutner 6eb16eb11a fix(ipfs-coord): Updating to v7.1.3 2022-03-05 08:24:36 -08:00
Chris Troutner 553957a173 Merge pull request #69 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Updating to 5.3.1
2022-01-31 21:20:51 -08:00
Chris Troutner 99a737c7e7 fix(bch-js): Updating to 5.3.1 2022-01-31 21:17:40 -08:00
Chris Troutner ffb87d09c2 Merge pull request #68 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2022-01-31 10:39:37 -08:00
Chris Troutner 65ead3568a Merge branch 'master' into ct-unstable 2022-01-31 10:34:52 -08:00
Chris Troutner b4b2aefac6 synced with upstream ipfs-service-provider 2022-01-31 10:33:54 -08:00
Chris Troutner 1844f30dc5 Merge pull request #76 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Bumping to v6.8.12
2022-01-31 10:31:20 -08:00
Chris Troutner b6ab2f02f4 Updating package-lock 2022-01-31 10:29:45 -08:00
Chris Troutner b5c76aa5fe fix(ipfs-coord): Bumping to v6.8.12 2022-01-31 10:28:06 -08:00
Chris Troutner 7648c96a70 Removing console logs 2022-01-29 17:37:22 -08:00
Chris Troutner 79f5adaf6b fix(bch-js): Tweeking initialization at startup 2022-01-29 17:29:26 -08:00
Chris Troutner e2f84d661f Debugging bch-js 2022-01-29 17:13:46 -08:00
Chris Troutner 31091a50a8 fix(startup): Announcing APISERVER when default init of bch-js is overridden 2022-01-29 15:53:45 -08:00
Chris Troutner 512775c68f More debugging 2022-01-29 15:42:50 -08:00
Chris Troutner c53394e547 Merge pull request #67 from Permissionless-Software-Foundation/ct-unstable
Adding debugging to txData()
2022-01-29 15:34:56 -08:00
Chris Troutner 79083502fb Adding debugging to txData() 2022-01-29 14:52:19 -08:00
Chris Troutner 6049c6566f Merge pull request #66 from Permissionless-Software-Foundation/ct-unstable
fix(getTxData): Removing txData property from output
2022-01-29 09:21:25 -08:00
Chris Troutner 99a52ec605 fix(getTxData): Removing txData property from output 2022-01-29 09:19:43 -08:00
Chris Troutner 33e7bc2b52 Merge pull request #65 from Permissionless-Software-Foundation/ct-unstable
feat(txData): Renamed transaction JSON endpoint to txData
2022-01-29 07:39:47 -08:00
Chris Troutner a20f30ec1e feat(txData): Renamed transaction JSON endpoint to txData 2022-01-29 07:38:05 -08:00
Chris Troutner b0b12c590c Merge pull request #64 from Permissionless-Software-Foundation/ct-unstable
feat(txHistory): Renamed transactions JSON endpoint to txHistory
2022-01-29 07:11:58 -08:00
Chris Troutner 286092f2e3 feat(txHistory): Renamed transactions JSON endpoint to txHistory 2022-01-29 07:09:40 -08:00
Chris Troutner 5be93afc38 fix(production): adding .env file to docker folder to prevent orphan warning 2022-01-28 19:43:51 -08:00
Chris Troutner 63cb107a25 Merge pull request #63 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to 6.8.11
2022-01-28 19:32:43 -08:00
Chris Troutner c54fb73c7d fix(bch): Adding additional debugging statements for BCH endpoints 2022-01-28 19:31:04 -08:00
Chris Troutner 8063c0e922 fix(ipfs-coord): Updating to 6.8.11 2022-01-28 19:26:41 -08:00
Chris Troutner b729c7ed80 Merge pull request #62 from Permissionless-Software-Foundation/ct-unstable
feat(transaction): Refactoring to allow up to 20 TXIDs per call
2022-01-28 12:06:12 -08:00
Chris Troutner 5a3d91e3b0 feat(transaction): Refactoring to allow up to 20 TXIDs per call 2022-01-28 12:04:35 -08:00
Chris Troutner d9fa44328a Merge pull request #61 from Permissionless-Software-Foundation/ct-unstable
Heavily refactored transaction history JSON RPC endpoint
2022-01-28 08:15:36 -08:00
Chris Troutner efaffa8e0f fix(getTransactions()): Added unit tests 2022-01-28 08:03:35 -08:00
Chris Troutner 27a9e9f3f3 Working on unit tests 2022-01-28 06:55:50 -08:00
Chris Troutner 41a5071467 fix(JSON transactions): Updated to new algorithm 2022-01-28 06:37:18 -08:00
Chris Troutner c6c3bb5d9c More debugging of pagination 2022-01-27 19:01:57 -08:00
Chris Troutner e4977a4351 Debugging pagination 2022-01-27 18:58:28 -08:00
Chris Troutner fe3b45f6be fixing typo 2022-01-27 17:54:17 -08:00
Chris Troutner d25b240112 Debugging 2022-01-27 17:52:16 -08:00
Chris Troutner 7a89a06ddb fix(getTransactions()): Adding pagination to tx history 2022-01-27 17:47:03 -08:00
Chris Troutner 74fb65df72 more debugging 2022-01-27 15:10:46 -08:00
Chris Troutner 0b38247f5a more debugging 2022-01-27 15:05:08 -08:00
Chris Troutner 473aaae307 debugging 2022-01-27 15:00:54 -08:00
Chris Troutner 284f4e4478 Debugging and reporting errors 2022-01-27 14:58:00 -08:00
Chris Troutner 56f6dc273a Restoring bch-js 2022-01-27 09:06:39 -08:00
Chris Troutner 4bd3387bde feat(transactions): Refactored JSON RPC transactions endpoint 2022-01-27 08:47:06 -08:00
Chris Troutner 7e7e91460a fix(integration): Adding integration test script to package.json 2022-01-24 13:21:29 -08:00
Chris Troutner e5f6f24570 Created mock unit tests for BCH use cases 2022-01-24 13:13:55 -08:00
Chris Troutner 818c85e3d4 Merge branch 'master' into ct-unstable 2022-01-24 12:32:24 -08:00
Chris Troutner 4101615a4a Merge pull request #75 from Permissionless-Software-Foundation/ct-unstable
Maintenance
2022-01-20 08:05:50 -08:00
Chris Troutner 34a4072384 fix(restart): Removing code the auto-restarts app after 2 hours 2022-01-20 07:56:40 -08:00
Chris Troutner 5fc72be10c fix(fullstack-jwt.js): Got unit test coverage back to 100% 2022-01-20 07:53:12 -08:00
Chris Troutner 651c4a1346 Debugging transactions JSON RPC endpoint 2022-01-19 15:58:25 -08:00
Chris Troutner 4b90ad5009 fix(bch-js): Upgrading to v5.2.2 2022-01-19 15:31:25 -08:00
Chris Troutner 05ddf8521a fix(bch-js): Updating to v5.2.1 2022-01-19 11:34:58 -08:00
Chris Troutner 88d1805685 Merge pull request #60 from Permissionless-Software-Foundation/ct-unstable
No-op
2022-01-18 15:38:12 -08:00
Chris Troutner ea104b5586 Rolling back debug console.logs 2022-01-18 15:31:15 -08:00
Chris Troutner 4251e2a02d more debugging 2022-01-18 15:22:26 -08:00
Chris Troutner 5e0eb017ef Debugging 2022-01-18 15:16:45 -08:00
Chris Troutner 86946968fe Merge pull request #59 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Updating to bch-js v5
2022-01-18 12:40:22 -08:00
Chris Troutner 9597f1963f fix(bch-js): Updating to bch-js v5 2022-01-18 12:38:33 -08:00
Chris Troutner 67d80056ff Merge pull request #58 from Permissionless-Software-Foundation/ct-unstable
New version. Syncing with upstream ipfs-service-provider
2022-01-18 12:32:55 -08:00
Chris Troutner 199677e4c6 synced with upstream ipfs-service-provider 2022-01-18 12:14:51 -08:00
Chris Troutner 86ea5c6354 fix(version): Bumping to v2.0.0 2022-01-18 12:08:36 -08:00
Chris Troutner 7b112a13d4 fix(cors): Fixing bug leading to CORS error 2022-01-12 15:33:04 -08:00
Chris Troutner fe5c573291 Merge pull request #74 from Permissionless-Software-Foundation/ct-unstable
fix(tests): Skipping IPFS stuff in test environment
2022-01-09 11:54:41 -08:00
Chris Troutner 463d7df582 fix(tests): Skipping IPFS stuff in test environment 2022-01-09 11:51:15 -08:00
Chris Troutner 5a1ec640a4 Merge pull request #73 from Permissionless-Software-Foundation/ct-unstable
Adding swarm.key
2022-01-03 11:39:57 -08:00
Chris Troutner 8bb8dbcd23 Updating READMe 2022-01-03 11:35:26 -08:00
Chris Troutner ba212b0997 fix(ipfs): Adding swarm.key file for joining network 2022-01-03 11:22:15 -08:00
Chris Troutner 803496fbc3 Merge pull request #57 from Permissionless-Software-Foundation/ct-unstable
Syncing upstream ipfs-service-provider
2022-01-02 19:15:52 -08:00
Chris Troutner c49ab4f58b Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2022-01-02 19:14:28 -08:00
Chris Troutner 4670bd22af Merge pull request #72 from Permissionless-Software-Foundation/ct-unstable
fix(pubsub): Applying fix for pubsub in external node
2022-01-02 19:13:44 -08:00
Chris Troutner b3e7c63e61 fix(pubsub): Applying fix for pubsub in external node 2022-01-02 19:00:50 -08:00
Chris Troutner 421ca359f2 Merge pull request #56 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2022-01-01 21:06:35 -08:00
Chris Troutner 4e6559ac96 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2022-01-01 21:04:33 -08:00
Chris Troutner 1fcc92e10d Merge pull request #71 from Permissionless-Software-Foundation/ct-unstable
fix(ipsf-coord): Updating to v6.8.10
2022-01-01 21:01:14 -08:00
Chris Troutner f332aece98 fix(ipsf-coord): Updating to v6.8.10 2022-01-01 20:58:56 -08:00
Chris Troutner 4112b34205 Merge pull request #55 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2022-01-01 20:47:11 -08:00
Chris Troutner 30d0a62455 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2022-01-01 20:44:41 -08:00
Chris Troutner 89f24e9940 Merge pull request #70 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Switching to private network. Updating ipfs-coord
2022-01-01 20:40:23 -08:00
Chris Troutner 25a75dc369 fix(ipfs-coord): Switching to private network. Updating ipfs-coord to v6.8.9 2022-01-01 20:25:40 -08:00
Chris Troutner f36ce14087 fix(ipfs-coord): Updating v6.8.8 2022-01-01 18:58:47 -08:00
Chris Troutner df45792f47 fix(ipfs-coord): Updating to v6.8.7 2022-01-01 18:43:24 -08:00
Chris Troutner 9e71e33ccd Merge pull request #69 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.8.6
2022-01-01 18:20:30 -08:00
Chris Troutner c7b0b0c1d5 fix(ipfs-coord): Updating to v6.8.6 2022-01-01 18:19:07 -08:00
Chris Troutner e475e5f4c3 Downgrading ipfs-http-client 2022-01-01 16:41:56 -08:00
Chris Troutner 7fff41b702 fix(production): Fixing typo in docker-compose.yml 2022-01-01 06:51:54 -08:00
Chris Troutner a7f7fc4e14 Merge pull request #54 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2022-01-01 06:48:33 -08:00
Chris Troutner 83ad0d8bfa Merge branch 'master' into ct-unstable 2022-01-01 06:44:04 -08:00
Chris Troutner ac4aaca66e fix(production): Explictly using ipfs v0.11.0 docker container 2022-01-01 06:43:16 -08:00
Chris Troutner 0748106637 Merge pull request #68 from Permissionless-Software-Foundation/ct-unstable
fix(production): using explcit v0.11.0 ipfs docker container
2022-01-01 06:41:36 -08:00
Chris Troutner 27dcc219b9 fix(production): using explcit v0.11.0 ipfs docker container 2022-01-01 06:40:15 -08:00
Chris Troutner 1362e64c42 Merge pull request #53 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2021-12-31 18:44:59 -08:00
Chris Troutner 7aad5db594 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-12-31 18:42:36 -08:00
Chris Troutner b231686a64 Merge pull request #67 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.8.5
2021-12-31 18:40:55 -08:00
Chris Troutner 60668430f5 fix(ipfs-coord): Updating to v6.8.5 2021-12-31 18:38:17 -08:00
Chris Troutner cf0fb0f572 Merge pull request #52 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2021-12-31 16:04:19 -08:00
Chris Troutner 68b0117c3d Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-12-31 16:02:57 -08:00
Chris Troutner e73440f342 fix(production): Slight tweek to start-production.sh 2021-12-31 16:02:37 -08:00
Chris Troutner b9680508db Merge pull request #66 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.8.4
2021-12-31 16:01:32 -08:00
Chris Troutner acebfdef09 fix(ipfs-coord): Updating to v6.8.4 2021-12-31 15:59:06 -08:00
Chris Troutner c3ee71a54f Merge pull request #51 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2021-12-31 15:44:39 -08:00
Chris Troutner 0d9a32488e Merge branch 'master' into ct-unstable 2021-12-31 15:43:00 -08:00
Chris Troutner de7629c93d Syncing with upstream ipfs-service-provider 2021-12-31 15:42:16 -08:00
Chris Troutner 3979694109 Merge pull request #65 from Permissionless-Software-Foundation/ct-unstable
fix(production): Adding instructions for customizing IPFS docker cont…
2021-12-31 15:38:39 -08:00
Chris Troutner ae888d094b fix(production): Adding instructions for customizing IPFS docker container 2021-12-31 15:34:40 -08:00
Chris Troutner 9b8db2adaf Merge pull request #50 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2021-12-31 12:15:50 -08:00
Chris Troutner c8539372ae Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-12-31 12:14:24 -08:00
Chris Troutner e8a3234dcd Merge pull request #64 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): updating to v6.8.2
2021-12-31 12:13:13 -08:00
Chris Troutner fc717e0dcd fix(ipfs-coord): updating to v6.8.2 2021-12-31 12:11:47 -08:00
Chris Troutner 02512a8183 Automatically restarting wallet service 2021-12-30 07:52:22 -08:00
Chris Troutner 09a58a78ef Merge pull request #49 from Permissionless-Software-Foundation/ct-unstable
Synced with upstream ipfs-servicer-provider
2021-12-29 20:06:42 -08:00
Chris Troutner f4708d9a49 Synced with upstream ipfs-servicer-provider 2021-12-29 19:53:53 -08:00
Chris Troutner 18cec75f41 Merge pull request #63 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.8.1
2021-12-29 19:33:54 -08:00
Chris Troutner 7621842952 fix(ipfs-coord): Updating to v6.8.1 2021-12-29 19:32:39 -08:00
Chris Troutner 01da1b44da minor tweeks to docker files 2021-12-29 18:31:01 -08:00
Chris Troutner b8f262b01b feat(ipfs-service-provider): Syncing with upstream. Production uses go-ipfs 2021-12-29 18:17:35 -08:00
Chris Troutner 0e9a57a1da Merge pull request #62 from Permissionless-Software-Foundation/ct-unstable
Kicking off v2.0.0
2021-12-29 18:04:29 -08:00
Chris Troutner e374522725 fix(version): Bumping to v2.0.0 2021-12-29 18:03:09 -08:00
Chris Troutner e402f33132 Adding more properties to docker-compose 2021-12-29 18:00:17 -08:00
Chris Troutner e85655c0ec Adding data/ directory to gitignore 2021-12-29 17:46:52 -08:00
Chris Troutner 227ffbc4bc Removing data directory 2021-12-29 17:46:28 -08:00
Chris Troutner b41f819783 fix(startup): Exiting if server can't stop 2021-12-29 17:46:05 -08:00
Chris Troutner d6c3635c6a fix(ipfs): Got running with external IPFS node 2021-12-29 17:28:35 -08:00
Chris Troutner 37e98e4248 fix(ipfs): Switching from @chris.troutner/ipfs to ipfs v0.60.0 2021-12-29 16:59:32 -08:00
Chris Troutner d2f4369f8d Merge pull request #48 from Permissionless-Software-Foundation/ct-unstable
syncing upstream ipfs-service-provider
2021-12-24 17:16:17 -08:00
Chris Troutner bd33314c4f Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-12-24 17:14:26 -08:00
Chris Troutner e6941f7f7f Merge pull request #61 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-cood): Updating to v6.7.6
2021-12-24 17:10:49 -08:00
Chris Troutner 4fdf35a55f fix(ipfs-cood): Updating to v6.7.6 2021-12-24 17:07:54 -08:00
Chris Troutner e6441a9c8c Merge pull request #47 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2021-12-24 15:43:23 -08:00
Chris Troutner 8a3265bff2 Merge branch 'master' into ct-unstable 2021-12-24 15:34:30 -08:00
Chris Troutner d871d8b392 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-12-24 15:33:01 -08:00
Chris Troutner f1fbe34b58 Merge pull request #60 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.7.5
2021-12-24 15:26:04 -08:00
Chris Troutner d232b6404d fix(ipfs-coord): Updating to v6.7.5 2021-12-24 15:24:38 -08:00
Chris Troutner ea724f7ed8 Merge pull request #46 from Permissionless-Software-Foundation/samrock5000-patch-1
🚧 fix typo and add cd into scripts folder
2021-12-15 08:17:02 -08:00
Samuel Nevarez 2b04bae260 🚧 fix typo and add cd into scripts folder 2021-12-14 21:25:00 -07:00
Chris Troutner 84f1e25648 Adding example script for running locally 2021-12-10 15:30:42 -08:00
Chris Troutner ef8c6fbcec fix(errors): Giving more clues when errors happen 2021-12-10 15:20:03 -08:00
Chris Troutner 12d462b89d Merge pull request #45 from Permissionless-Software-Foundation/ct-unstable
Syncing with upstream ipfs-service-provider
2021-12-06 12:52:16 -08:00
Chris Troutner 53065d8365 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-12-06 12:50:38 -08:00
Chris Troutner 1bf8f756e5 Merge pull request #59 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs): Deleting /blocks dir if it prevents app from starting
2021-12-06 12:48:48 -08:00
Chris Troutner 1e513cc133 fix(ipfs): Deleting /blocks dir if it prevents app from starting 2021-12-06 12:46:22 -08:00
Chris Troutner 7ce53439b1 Updating gitignore 2021-12-02 14:11:27 -08:00
Chris Troutner e90d664761 Merge pull request #44 from Permissionless-Software-Foundation/ct-unstable
Minor updates
2021-12-02 13:52:13 -08:00
Chris Troutner fc11e701e4 fix(broadcast): Handling full node errors 2021-12-02 13:51:07 -08:00
Chris Troutner 3c7ebef8a7 fix(bch-js): Updating to v4.20.28 2021-12-01 14:54:56 -08:00
Chris Troutner 5d70c89f2d Merge pull request #43 from Permissionless-Software-Foundation/ct-unstable
fix(garbage collection): Updating IPFS config for more conservative GC
2021-11-27 15:28:06 -08:00
Chris Troutner 7149c0a824 fix(upstream): Syncing with upstream ipfs-service-provider 2021-11-27 15:25:39 -08:00
Chris Troutner 74c6bc5737 Merge pull request #58 from Permissionless-Software-Foundation/ct-unstable
fix(garbage collection): Updating IPFS config for more conservative GC
2021-11-27 15:14:30 -08:00
Chris Troutner bac6c8b1e9 Disabling debug code 2021-11-27 15:13:23 -08:00
Chris Troutner 9e7d955bc4 fix(garbage collection): Updating IPFS config for more conservative GC 2021-11-27 15:12:08 -08:00
Chris Troutner af7c4464bb Merge pull request #42 from Permissionless-Software-Foundation/dh-pubkey
feat(pubkey): Added pubkey route to ipfs-bch-wallet-service
2021-11-25 06:10:16 -08:00
Chris Troutner cfb128f3c8 Updating deps 2021-11-25 06:04:35 -08:00
Daniel Gonzalez 451a828a05 feat(pubkey): Added pubkey route to ipfs-bch-wallet-service 2021-11-23 19:25:01 -04:00
Chris Troutner 678bc7015c Merge pull request #56 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.7.4
2021-11-13 11:36:57 -08:00
Chris Troutner 013aa97143 fix(ipfs-coord): Updating to v6.7.4 2021-11-13 11:33:28 -08:00
Chris Troutner 45b7e480b7 Merge pull request #55 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js, ipfs-coord): Updating npm packages
2021-10-29 15:40:36 -07:00
Chris Troutner 09772bae29 fix(bch-js, ipfs-coord): Updating npm packages 2021-10-29 15:38:20 -07:00
Chris Troutner c01130fcc7 Updating ipfs-coord and bch-js 2021-10-27 14:33:17 -07:00
Chris Troutner 2d4159b4cf Merge pull request #41 from Permissionless-Software-Foundation/ct-unstable
fix(Docker): Increasing memory limit to 1GB
2021-10-12 13:39:37 -07:00
Chris Troutner 6dcd1ce5e7 fix(Docker): Increasing memory limit to 1GB 2021-10-12 13:37:31 -07:00
Chris Troutner 6c913b2c36 Merge pull request #40 from Permissionless-Software-Foundation/ct-unstable
fix(dependencies): Using exact versions
2021-10-12 13:34:51 -07:00
Chris Troutner c453705a80 fix(dependencies): Using exact versions 2021-10-12 13:22:16 -07:00
Chris Troutner bb9a2a2408 Merge pull request #54 from Permissionless-Software-Foundation/ct-unstable
fix(dependencies): Using exact versions
2021-10-12 12:46:51 -07:00
Chris Troutner 54709a8c70 fix(dependencies): Using exact versions 2021-10-12 09:56:52 -07:00
Chris Troutner 64135b55a7 fix(tests): Fixing broken unit test 2021-10-11 14:45:09 -07:00
Chris Troutner 1ff4ba440d fixing merge conflicts with upstream 2021-10-11 14:40:22 -07:00
Chris Troutner 72da6203a1 Merge pull request #53 from Permissionless-Software-Foundation/ct-unstable
fix(Dockerfile): Switching to more basic stuff
2021-10-11 14:34:03 -07:00
Chris Troutner e2bc560c7d fix(Dockerfile): Switching to more basic stuff 2021-10-11 13:48:20 -07:00
Chris Troutner e40241bac8 Fixing typo in docker-compose 2021-10-11 09:05:57 -07:00
Chris Troutner 01c8c5c194 Merge pull request #52 from Permissionless-Software-Foundation/ct-unstable
Additional test coverage
2021-10-01 14:11:44 -07:00
Chris Troutner 5eb5ef204e fix(json rpc): Increasing to 100% test coverage 2021-10-01 14:01:08 -07:00
Chris Troutner ee90bc0730 fix(ipfs): Got adapter back to 100% unit test coverage 2021-09-30 15:20:51 -07:00
Chris Troutner 5af068e0d6 fix(ipfs-coord): Got adapter back to 100% test coverage 2021-09-30 15:12:47 -07:00
Chris Troutner 7e228b729e fix(ipfs adapter): Adding unit tests for lock-file error handling 2021-09-30 14:47:17 -07:00
Chris Troutner ec4c61f38e Merge pull request #39 from Permissionless-Software-Foundation/ct-unstable
Syncing upstream: Improvements to Docker container
2021-09-29 07:20:47 -07:00
Chris Troutner 9ed610e3a4 fix(upstream): Synced with upstream ipfs-service-provider 2021-09-29 07:05:52 -07:00
Chris Troutner a9e7fc616e Merge pull request #51 from Permissionless-Software-Foundation/ct-unstable
fix(docker): disabling circuit relays by default
2021-09-28 20:30:45 -07:00
Chris Troutner 9d5ffbe26e fix(docker): disabling circuit relays by default 2021-09-28 20:11:25 -07:00
Chris Troutner 3829e90844 Merge pull request #50 from Permissionless-Software-Foundation/ct-unstable
fix(docker): Matching ports to dev env
2021-09-28 19:55:58 -07:00
Chris Troutner f181d8b095 fix(docker): Matching ports to dev env 2021-09-28 19:52:10 -07:00
Chris Troutner a2270e70af Merge pull request #49 from Permissionless-Software-Foundation/ct-unstable
fix(Docker): Dropping RAM to 500MB
2021-09-28 18:18:26 -07:00
Chris Troutner 34604d53b0 fix(Docker): Dropping RAM to 500MB 2021-09-28 18:16:56 -07:00
Chris Troutner 6257b96bc3 fix(Docker): Forcing memory limit of 1GB 2021-09-28 18:14:18 -07:00
Chris Troutner 1d8912f60d Slight update to docker container 2021-09-28 18:04:52 -07:00
Chris Troutner 3c9b63d009 Merge pull request #48 from Permissionless-Software-Foundation/ct-unstable
fix(circuit relay): Auto-discover IP4 addr when CR enabled
2021-09-28 17:53:29 -07:00
Chris Troutner e6f9f64b4a fix(circuit relay): Auto-discover IP4 addr when CR enabled 2021-09-28 17:51:19 -07:00
Chris Troutner a8ad4149e0 fix(shell-scripts): Added shell-script dir with example scripts 2021-09-28 16:58:57 -07:00
Chris Troutner 3924812985 Merge pull request #47 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs): HOP setting is controlled by config.isCircuitRelay
2021-09-28 15:48:44 -07:00
Chris Troutner fef0f3a987 fix(ipfs): HOP setting is controlled by config.isCircuitRelay 2021-09-28 15:44:06 -07:00
Chris Troutner 1c012322fd Merge pull request #46 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Bumping to v6.7.0
2021-09-28 06:56:26 -07:00
Chris Troutner 545e8aa670 fix(ipfs-coord): Bumping to v6.7.0 2021-09-28 06:54:12 -07:00
Chris Troutner 449bd500c2 Merge pull request #38 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating bootstrap peers. v6.6.8
2021-09-27 12:52:00 -07:00
Chris Troutner ea295f2f41 linting 2021-09-27 12:47:10 -07:00
Chris Troutner 9175b8abe8 Fixing merge conflicts 2021-09-27 12:44:59 -07:00
Chris Troutner 9d4a61ea99 Merge pull request #45 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating bootstrap peers. v6.6.8
2021-09-27 12:40:53 -07:00
Chris Troutner cb50fdc70d fix(ipfs-coord): Updating bootstrap peers. v6.6.8 2021-09-27 12:39:10 -07:00
Chris Troutner cf488e1440 Merge pull request #37 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.6.7
2021-09-20 10:41:57 -07:00
Chris Troutner 4fc6def1cd Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-09-20 10:34:59 -07:00
Chris Troutner e0b2fd2525 Merge pull request #44 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.6.7
2021-09-20 10:21:12 -07:00
Chris Troutner 8e08201b16 fix(ipfs-coord): Updating to v6.6.7 2021-09-20 10:19:33 -07:00
Chris Troutner c347a2d99a Merge pull request #36 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-service-provider): Syncing with upstream repo
2021-09-18 11:37:16 -07:00
Chris Troutner 5b7d8d4db4 fix(ipfs-service-provider): Syncing with upstream repo 2021-09-18 11:34:23 -07:00
Chris Troutner dd0692e91f Merge pull request #43 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Bumping to v6.6.6
2021-09-18 11:23:26 -07:00
Chris Troutner 576da66194 fix(ipfs-coord): Bumping to v6.6.6 2021-09-18 11:20:11 -07:00
Chris Troutner f4851d6771 Merge pull request #42 from Permissionless-Software-Foundation/ct-unstable
Minor tweeks
2021-09-17 17:43:33 -07:00
Chris Troutner 96abb0d56e fix(ipfs-coord): Updating to v6.6.5 2021-09-17 17:41:08 -07:00
Chris Troutner fdf3141c91 fix(reset): Restarting app after 4 hours, not 8 2021-09-17 16:23:47 -07:00
Chris Troutner 6692d234da Adding link to video in readme 2021-09-17 16:23:04 -07:00
Chris Troutner b8655e31ca Fixing typo in shell script 2021-09-17 12:22:05 -07:00
Chris Troutner e118fe4d6e Merge pull request #41 from Permissionless-Software-Foundation/ct-unstable
fix(startup script): Added startup script
2021-09-17 11:20:39 -07:00
Chris Troutner 86283195c5 slight tweek to README 2021-09-17 11:18:26 -07:00
Chris Troutner a037646aca fix(startup script): Added startup script 2021-09-17 11:17:10 -07:00
Chris Troutner ae6bdcdd5f Merge pull request #35 from Permissionless-Software-Foundation/ct-unstable
fix(bch-js): Selecting custom server when not using JWT token
2021-09-08 14:02:25 -07:00
Chris Troutner 9fe822024c fix(bch-js): Selecting custom server when not using JWT token 2021-09-08 14:00:00 -07:00
Chris Troutner fc94041d17 Merge pull request #34 from Permissionless-Software-Foundation/ct-unstable
fix(docker): Using Ubuntu base container
2021-09-08 13:05:58 -07:00
Chris Troutner a3f780b1f5 fix(docker): Using Ubuntu base container 2021-09-08 13:02:23 -07:00
Chris Troutner 9487f19233 Merge pull request #33 from Permissionless-Software-Foundation/ct-unstable
fix(JWT): Added env var to enable/disable JWT retrieval at startup
2021-09-08 12:38:05 -07:00
Chris Troutner 2988374769 linting 2021-09-08 12:35:26 -07:00
Chris Troutner 22ab7260f4 fix(startup): Fixing startup issues caused by code mixup with upstream 2021-09-08 12:35:00 -07:00
Chris Troutner 27f6f62f8c fix(gitignore): Adding run-dev.sh to gitignore 2021-09-08 12:03:46 -07:00
Chris Troutner 33ab787a95 Integrating JWT env var in production 2021-09-08 12:02:57 -07:00
Chris Troutner 4f2cde2599 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-09-08 12:00:41 -07:00
Chris Troutner d419084216 Merge pull request #40 from Permissionless-Software-Foundation/ct-unstable
fix(JWT): Added env var to enable/disable JWT retrieval at startup
2021-09-08 11:59:55 -07:00
Chris Troutner 553e0081fa fix(JWT): Added env var to enable/disable JWT retrieval at startup 2021-09-08 11:58:18 -07:00
Chris Troutner 0716922b7c Merge pull request #32 from Permissionless-Software-Foundation/ct-unstable
fix(memory-leak): Resetting app after 8 hours
2021-09-07 21:05:20 -07:00
Chris Troutner 7e227d994b Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-09-07 21:01:46 -07:00
Chris Troutner dd1b702966 Merge pull request #39 from Permissionless-Software-Foundation/ct-unstable
fix(memory-leak): Resetting app after 8 hours
2021-09-07 20:59:56 -07:00
Chris Troutner 0963f89049 fix(memory-leak): Resetting app after 8 hours 2021-09-07 20:58:23 -07:00
Chris Troutner cda3f1c0a7 Merge pull request #31 from Permissionless-Software-Foundation/ct-unstable
fix(JSON RPC): Adding filters and logging to JSON RPC router
2021-09-05 09:40:16 -07:00
Chris Troutner 1247bcb8c0 fix(upstream): Syncing with upstream ipfs-service-provider 2021-09-05 09:35:53 -07:00
Chris Troutner 36476b32ab Noting GitHub Issue 2021-09-05 09:23:38 -07:00
Chris Troutner 630135ac1c Merge pull request #37 from Permissionless-Software-Foundation/ct-unstable
fix(JSON RPC): Adding filters and logging to JSON RPC router
2021-09-05 08:45:51 -07:00
Chris Troutner 0a86c7dc92 fix(JSON RPC): Adding filters and logging to JSON RPC router 2021-09-05 08:31:06 -07:00
Chris Troutner a8a08f8978 Merge pull request #30 from Permissionless-Software-Foundation/ct-unstable
fix(JSON RPC): Prevening processing of duplicate entries
2021-09-04 18:18:23 -07:00
Chris Troutner 8b8d35573d fix(upstream): Syncing with upstream ipfs-service-provider 2021-09-04 18:07:28 -07:00
Chris Troutner 36ed80212d Merge pull request #36 from Permissionless-Software-Foundation/ct-unstable
fix(JSON RPC): Prevening processing of duplicate entries
2021-09-04 18:01:24 -07:00
Chris Troutner 131e6e1460 Updating ipfs-coord to v6.6.4 2021-09-04 17:59:53 -07:00
Chris Troutner 5c799a8197 fix(JSON RPC): Prevening processing of duplicate entries 2021-09-04 17:53:45 -07:00
Chris Troutner 488c5d3c22 fix(app): Exiting app if IPFS lock file is being held 2021-09-04 17:51:27 -07:00
Chris Troutner e93ffc4c77 Bumping version to 1.11.12 2021-09-04 15:25:52 -07:00
Chris Troutner e4c4e324b8 Merge pull request #29 from Permissionless-Software-Foundation/ct-unstable
fix(debug): Removing debug log spam
2021-09-04 09:20:09 -07:00
Chris Troutner e5e012a700 Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-09-04 09:12:25 -07:00
Chris Troutner 9bddcf1c8e Merge pull request #35 from Permissionless-Software-Foundation/ct-unstable
fix(debug): Removing debug log spam
2021-09-04 09:09:26 -07:00
Chris Troutner ba2fdbc836 fix(debug): Removing debug log spam 2021-09-04 09:05:30 -07:00
Chris Troutner 3f809d38fb Merge pull request #28 from Permissionless-Software-Foundation/ct-unstable
fix(upstream): Syncing with upstream ipfs-service-provider
2021-09-04 08:46:39 -07:00
Chris Troutner d66d80bb0c fix(upstream): Syncing with upstream ipfs-service-provider 2021-09-04 08:43:41 -07:00
Chris Troutner 4c707cf5b9 Merge pull request #34 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.6.3
2021-09-04 08:39:37 -07:00
Chris Troutner 8670bdb588 fix(ipfs-coord): Updating to v6.6.3 2021-09-04 08:37:12 -07:00
Chris Troutner 4c5bdd089e Debugging relay metrics 2021-09-03 21:01:53 -07:00
Chris Troutner c3eb1b1ad3 Merge pull request #27 from Permissionless-Software-Foundation/ct-unstable
fix(docker): Specifying max size for log files
2021-09-03 12:08:46 -07:00
Chris Troutner 1e1e1558b4 Adding data/ directory to gitignore 2021-09-03 12:07:00 -07:00
Chris Troutner d4abd693de fix(upstream): Syncing with upstream ipfs-service-provider 2021-09-03 12:01:45 -07:00
Chris Troutner d38718dcdf Merge pull request #33 from Permissionless-Software-Foundation/ct-unstable
fix(docker): Specifying max size for log files
2021-09-03 11:29:37 -07:00
Chris Troutner 3a3376c303 fix(docker): Specifying max size for log files 2021-09-03 11:27:27 -07:00
Chris Troutner 05043ac74d fix(ipfs-coord): Upgrading to v6.6.0 2021-09-03 11:05:52 -07:00
Chris Troutner 5f89bfcbd8 Merge pull request #26 from Permissionless-Software-Foundation/ct-unstable
fix(sync): Synced with upstream ipfs-service-provider
2021-09-02 17:15:13 -07:00
Chris Troutner d7d56d9ebf fix(sync): Synced with upstream ipfs-service-provider 2021-09-02 17:12:11 -07:00
Chris Troutner 1592eadd8c fix(sync): Syncing with upstream ipfs-service-provider 2021-09-02 17:09:32 -07:00
Chris Troutner be1a4c750a Merge pull request #32 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updated to v6.5.6
2021-09-02 16:54:32 -07:00
Chris Troutner 4572ce3d6b fix(ipfs-coord): Updated to v6.5.6 2021-09-02 16:52:39 -07:00
Chris Troutner fb7d4e6074 Merge pull request #31 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs): Updating IPFS nad ipfs-coord
2021-09-02 09:06:27 -07:00
Chris Troutner 5467c991de Merge branch 'master' into ct-unstable 2021-09-02 09:04:25 -07:00
Chris Troutner ba93c6cc46 fix(ipfs): Updating IPFS nad ipfs-coord 2021-09-02 09:03:16 -07:00
Chris Troutner 60b37e4f72 Merge pull request #25 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.5.2
2021-08-30 08:02:58 -07:00
Chris Troutner 02a543323c Merge branch 'master' of https://github.com/Permissionless-Software-Foundation/ipfs-service-provider into ct-unstable 2021-08-30 08:00:24 -07:00
Chris Troutner c28bc22084 Merge pull request #30 from Permissionless-Software-Foundation/ct-unstable
fix(ipfs-coord): Updating to v6.5.2
2021-08-30 07:56:29 -07:00
Chris Troutner f796dd6076 fix(ipfs-coord): Updating to v6.5.2 2021-08-30 07:51:44 -07:00
138 changed files with 22927 additions and 36998 deletions
+3
View File
@@ -7,6 +7,7 @@
#logs
logs/*.json
*.log
*.log.*
npm-debug.log*
# Runtime data
@@ -67,5 +68,7 @@ ipfsdata
.ipfsdata
ipfs-service-provider.sh
start-bch-wallet-service.sh
data/
run-dev.sh
!README.md
+8
View File
@@ -0,0 +1,8 @@
[
{
"srcDir": "",
"destDir": "",
"files": "**/*.js",
"command": "npm run lint"
}
]
+93
View File
@@ -0,0 +1,93 @@
# Permissionless Software Foundation Community Contributing Guide 1.0
This document describes a very simple process suitable for most projects under
the PSF umbrella. It is based on [this Medium article](https://medium.com/the-node-js-collection/healthy-open-source-967fa8be7951) and the [Node.js Community Contribution Guide](https://github.com/nodejs/TSC/blob/master/BasePolicies/CONTRIBUTING.md).
Projects are encouraged to adopt this whether they
are hosted under the PSF or not.
The goal of this document is to create a contribution process that:
* Encourages new contributions.
* Encourages contributors to remain involved.
* Avoids unnecessary processes and bureaucracy whenever possible.
* Creates a transparent decision making process which makes it clear how
contributors can be involved in decision making.
This document is based on much prior art in the Node.js community, io.js,
and the Node.js project.
Additional guidance can be found at the [Permissionless Software Foundation Telegram Channel](https://t.me/permissionless_software).
## Vocabulary
* A **Contributor** is any individual creating or commenting on an issue or pull request.
* A **Committer** is a subset of contributors who have been given write access to the repository.
* A **TC (Technical Committee)** is a group of committers representing the required technical
expertise to resolve rare disputes.
# Logging Issues
Log an issue for any question or problem you might have. When in doubt, log an issue,
any additional policies about what to include will be provided in the responses. The only
exception is security disclosures which should be sent privately.
Committers may direct you to another repository, ask for additional clarifications, and
add appropriate metadata before the issue is addressed.
Please be courteous, respectful, and every participant is expected to follow the
project's Code of Conduct.
# Contributions
Any change to resources in this repository must be through pull requests. This applies to all changes
to documentation, code, binary files, etc. Even long term committers and TC members must use
pull requests.
No pull request can be merged without being reviewed.
For non-trivial contributions, pull requests should sit for at least 36 hours to ensure that
contributors in other timezones have time to review. Consideration should also be given to
weekends and other holiday periods to ensure active committers all have reasonable time to
become involved in the discussion and review process if they wish.
The default for each contribution is that it is accepted once no committer has an objection.
During review committers may also request that a specific contributor who is most versed in a
particular area gives a "LGTM" before the PR can be merged. There is no additional "sign off"
process for contributions to land. Once all issues brought by committers are addressed it can
be landed by any committer.
In the case of an objection being raised in a pull request by another committer, all involved
committers should seek to arrive at a consensus by way of addressing concerns being expressed
by discussion, compromise on the proposed change, or withdrawal of the proposed change.
If a contribution is controversial and committers cannot agree about how to get it to land
or if it should land then it should be escalated to the TC. TC members should regularly
discuss pending contributions in order to find a resolution. It is expected that only a
small minority of issues be brought to the TC for resolution and that discussion and
compromise among committers be the default resolution mechanism.
# Becoming a Committer
All contributors who land a non-trivial contribution should be on-boarded in a timely manner,
and added as a committer, and be given write access to the repository.
Committers are expected to follow this policy and continue to send pull requests, go through
proper review, and have other committers merge their pull requests.
# TC Process
The TC uses a "consensus seeking" process for issues that are escalated to the TC.
The group tries to find a resolution that has no open objections among TC members.
If a consensus cannot be reached that has no objections then a majority wins vote
is called. It is also expected that the majority of decisions made by the TC are via
a consensus seeking process and that voting is only used as a last-resort.
Resolution may involve returning the issue to committers with suggestions on how to
move forward towards a consensus. It is not expected that a meeting of the TC
will resolve all issues on its agenda during that meeting and may prefer to continue
the discussion happening among the committers.
Members can be added to the TC at any time. Any committer can nominate another committer
to the TC and the TC uses its standard consensus seeking process to evaluate whether or
not to add this new member. Members who do not participate consistently at the level of
a majority of the other members are expected to resign.
+1 -1
View File
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2021 Permissionless Software Foundation
Copyright (c) 2021-2024 Permissionless Software Foundation
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+3
View File
@@ -0,0 +1,3 @@
# Pedigree
This repository was forked from [koa-api-boilerplate](https://github.com/christroutner/koa-api-boilerplate). Code changes from that upstream repository is frequently pulled in and merged to this repository.
+48 -9
View File
@@ -24,36 +24,73 @@ This repository is one step in a longer path. Here are the major milestones of t
## Requirements
- node **^14.17.0**
- npm **^7.13.0**
- node **^16.20.2**
- npm **^8.19.4**
- Docker **^20.10.8**
- Docker Compose **^1.27.4**
## Installation
### Development Environment
**Note:** This software now uses an external go-ipfs IPFS node. The instructions below have not been updated to reflect this.
A development environment will allow you modify the code on-the-fly and contribute to the code base of this repository. [PM2](https://www.npmjs.com/package/pm2) is recommended for running this code base as an IPFS Circuit Relay.
- [Video: Installing ipfs-service-provider](https://youtu.be/Z0NsboIVN44)
- [Step-by-step installation instructions](https://gist.github.com/christroutner/3304a71d4c12a3a3e1664a438f64d9d0)
```bash
git clone https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service
cd ipfs-bch-wallet-service
sudo npm install -g node-pre-gyp
./install-mongo.sh
npm install
cd shell-scripts
./ipfs-bch-wallet-service.sh
```
### Production Environment
The [docker](./production/docker) directory contains a Dockerfile for building a production deployment.
```
docker-compose pull
docker-compose up -d
```
- You can bring the containers down with `docker-compose down`
- You can bring the containers back up with `docker-compose up -d`.
### Development Environment
A development environment will allow you modify the code on-the-fly and contribute to the code base of this repository. Ubuntu v20 is the recommended OS for creating a dev environment. Other operating systems may cause issues.
```bash
git clone https://github.com/Permissionless-Software-Foundation/ipfs-service-provider
cd ipfs-service-provider
./install-mongo-sh
npm install
npm start
```
## Structure
## File Structure
The file layout of this repository differs from the koa-api-boilerplate. Instead, it follows the file layout of [Clean Architecture](troutsblog.com/blog/clean-architecture).
The file layout of this repository follows the file layout of [Clean Architecture](https://christroutner.github.io/trouts-blog/blog/clean-architecture). Understaning the principles laid out this article will help developers navigate the code base.
## Usage
- `npm start` Start server on live mode
- `npm run docs` Generate API documentation
- `npm test` Run mocha tests
- `docker-compose build` Build a 'production' Docker container
- `docker-compose up` Run the docker container
## Documentation
API documentation is written inline and generated by [apidoc](http://apidocjs.com/).
API documentation is written inline and generated by [apidoc](http://apidocjs.com/). Docs can be generated with this command:
- `npm run docs`
Visit `http://localhost:5000/docs/` to view docs
Visit `http://localhost:5020/` to view docs
There is additional developer documentation in the [dev-docs directory](./dev-docs).
## Dependencies
@@ -78,3 +115,5 @@ Snapshots pinned to IPFS will be listed here.
## License
[MIT](./LICENSE.md)
a
+70 -36
View File
@@ -8,47 +8,56 @@
*/
// npm libraries
const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const convert = require('koa-convert')
const logger = require('koa-logger')
const mongoose = require('mongoose')
const session = require('koa-generic-session')
const passport = require('koa-passport')
const mount = require('koa-mount')
const serve = require('koa-static')
const cors = require('kcors')
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import convert from 'koa-convert'
import logger from 'koa-logger'
import mongoose from 'mongoose'
import session from 'koa-generic-session'
import passport from 'koa-passport'
import mount from 'koa-mount'
import serve from 'koa-static'
import cors from 'kcors'
// Local libraries
const config = require('../config') // this first.
const AdminLib = require('../src/adapters/admin')
const errorMiddleware = require('../src/controllers/rest-api/middleware/error')
const { wlogger } = require('../src/adapters/wlogger')
import config from '../config/index.js' // this first.
import AdminLib from '../src/adapters/admin.js'
import errorMiddleware from '../src/controllers/rest-api/middleware/error.js'
import wlogger from '../src/adapters/wlogger.js'
import Controllers from '../src/controllers/index.js'
import { applyPassportMods } from '../config/passport.js'
class Server {
constructor () {
// Encapsulate dependencies
this.adminLib = new AdminLib()
this.controllers = new Controllers()
this.mongoose = mongoose
this.config = config
this.process = process
}
async startServer () {
try {
// Create a Koa instance.
const app = new Koa()
app.keys = [config.session]
app.keys = [this.config.session]
// Connect to the Mongo Database.
mongoose.Promise = global.Promise
mongoose.set('useCreateIndex', true) // Stop deprecation warning.
this.mongoose.Promise = global.Promise
this.mongoose.set('useCreateIndex', true) // Stop deprecation warning.
console.log(
`Connecting to MongoDB with this connection string: ${config.database}`
`Connecting to MongoDB with this connection string: ${this.config.database}`
)
await mongoose.connect(config.database, {
await this.mongoose.connect(this.config.database, {
useUnifiedTopology: true,
useNewUrlParser: true
})
console.log(`Starting environment: ${config.env}`)
console.log(`Debug level: ${config.debugLevel}`)
console.log(`Starting environment: ${this.config.env}`)
console.log(`Debug level: ${this.config.debugLevel}`)
// MIDDLEWARE START
@@ -64,28 +73,34 @@ class Server {
app.use(mount('/logs', serve(`${process.cwd()}/config/logs`)))
// User Authentication
require('../config/passport')
// require('../config/passport')
applyPassportMods(passport)
app.use(passport.initialize())
app.use(passport.session())
// Attach REST API and JSON RPC controllers to the app.
const Controllers = require('../src/controllers')
const controllers = new Controllers()
await controllers.attachRESTControllers(app)
app.controllers = controllers
// Enable CORS for testing
// THIS IS A SECURITY RISK. COMMENT OUT FOR PRODUCTION
// Dev Note: This line must come BEFORE controllers.attachRESTControllers()
app.use(cors({ origin: '*' }))
// Wait for any adapters to initialize.
await this.controllers.initAdapters()
// Wait for any use-libraries to initialize.
await this.controllers.initUseCases()
// Attach REST API and JSON RPC controllers to the app.
await this.controllers.attachRESTControllers(app)
app.controllers = this.controllers
// MIDDLEWARE END
console.log(`Running server in environment: ${config.env}`)
wlogger.info(`Running server in environment: ${config.env}`)
console.log(`Running server in environment: ${this.config.env}`)
wlogger.info(`Running server in environment: ${this.config.env}`)
await app.listen(config.port)
console.log(`Server started on ${config.port}`)
this.server = await app.listen(this.config.port)
console.log(`Server started on ${this.config.port}`)
// Create the system admin user.
try {
@@ -97,14 +112,33 @@ class Server {
)
}
// Attach the other IPFS controllers
await controllers.attachControllers(app)
// Attach the other IPFS controllers.
// Skip if this is a test environment.
if (this.config.env !== 'test') {
await this.controllers.attachControllers(app)
}
// Display configuration settings
console.log('\nConfiguration:')
console.log(`Circuit Relay: ${this.config.isCircuitRelay}`)
console.log(`IPFS TCP port: ${this.config.ipfsTcpPort}`)
console.log(`IPFS WS port: ${this.config.ipfsWsPort}\n`)
return app
} catch (err) {
console.error('Could not start server. Error: ', err)
console.log(
'Exiting after 5 seconds. Depending on process manager to restart.'
)
await this.sleep(5000)
this.process.exit(1)
}
}
sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
}
module.exports = Server
export default Server
+41 -6
View File
@@ -1,21 +1,35 @@
/*
This file is used to store unsecure, application-specific data common to all
environments.
Additional Environent Variables:
- CONNECT_PREF: should have a value of 'cr' (default), or 'direct'. This is
used by helia-coord to select a connection preference between peers. Servers
with an ip4 or ip6 address should use 'direct'.
*/
/* eslint no-unneeded-ternary:0 */
// Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
import * as url from 'url'
// Get the version from the package.json file.
const pkgInfo = require('../../package.json')
import { readFileSync } from 'fs'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const pkgInfo = JSON.parse(readFileSync(`${__dirname.toString()}/../../package.json`))
const version = pkgInfo.version
const ipfsCoordName = process.env.COORD_NAME
? process.env.COORD_NAME
: 'ipfs-bch-wallet-service'
module.exports = {
console.log('GET_JWT_AT_STARTUP: ', process.env.GET_JWT_AT_STARTUP)
export default {
// Configure TCP port.
port: process.env.PORT || 5001,
port: process.env.PORT || 5020,
// Password for HTML UI that displays logs.
logPass: 'test',
@@ -32,7 +46,7 @@ module.exports = {
: 'emailpassword',
// FullStack.cash account information, used for automatic JWT handling.
getJwtAtStartup: false,
getJwtAtStartup: process.env.GET_JWT_AT_STARTUP ? true : false,
authServer: process.env.AUTHSERVER
? process.env.AUTHSERVER
: 'https://auth.fullstack.cash',
@@ -47,12 +61,15 @@ module.exports = {
: 'demo',
// IPFS settings.
useIpfs: process.env.DISABLE_IPFS ? false : true, // Disable IPFS flag
isCircuitRelay: process.env.ENABLE_CIRCUIT_RELAY ? true : false,
// SSL domain used for websocket connection via browsers.
crDomain: process.env.CR_DOMAIN ? process.env.CR_DOMAIN : '',
// Information passed to other IPFS peers about this node.
apiInfo: 'https://ipfs-bch-wallet-service.fullstack.cash/',
ipfsCoordName: ipfsCoordName,
ipfsCoordName,
// JSON-LD and Schema.org schema with info about this app.
announceJsonLd: {
@@ -78,5 +95,23 @@ module.exports = {
// BCH Mnemonic for generating encryption keys and payment address
mnemonic: process.env.MNEMONIC ? process.env.MNEMONIC : '',
debugLevel: process.env.DEBUG_LEVEL ? parseInt(process.env.DEBUG_LEVEL) : 2
debugLevel: process.env.DEBUG_LEVEL ? parseInt(process.env.DEBUG_LEVEL) : 2,
// Settings for production, using external go-ipfs node.
isProduction: process.env.SVC_ENV === 'prod' ? true : false,
ipfsHost: process.env.IPFS_HOST ? process.env.IPFS_HOST : 'localhost',
ipfsApiPort: process.env.IPFS_API_PORT
? parseInt(process.env.IPFS_API_PORT)
: 5001,
chatPubSubChan: 'psf-ipfs-chat-001',
// This can add specific Circuit Relay v2 servers to connect to.
bootstrapRelays: [
// v2 Circuit Relay (Token Tiger)
// '/ip4/137.184.93.145/tcp/8001/p2p/12D3KooWGMEKkdJfyZbwdH9EafZbRTtMn7FnhWPrE4MhRty2763g',
// v2 Circuit Relay server (FullStack.cash)
// '/ip4/78.46.129.7/tcp/4001/p2p/12D3KooWFQ11GQ5NubsJGhYZ4X3wrAGimLevxfm6HPExCrMYhpSL'
]
}
+1 -1
View File
@@ -4,7 +4,7 @@
specified.
*/
module.exports = {
export default {
session: 'secret-boilerplate-token',
token: 'secret-jwt-token',
database: 'mongodb://localhost:27017/bch-service-dev',
+1 -1
View File
@@ -7,7 +7,7 @@
so as not to conflict with the default host port of 27017 for MongoDB.
*/
module.exports = {
export default {
session: 'secret-boilerplate-token',
token: 'secret-jwt-token',
database: process.env.DBURL
+1 -1
View File
@@ -4,7 +4,7 @@
This is the environment run by the test suite.
*/
module.exports = {
export default {
session: 'secret-boilerplate-token',
token: 'secret-jwt-token',
database: 'mongodb://localhost:27017/bch-service-test',
+14 -3
View File
@@ -1,6 +1,17 @@
const common = require('./env/common')
import common from './env/common.js'
import development from './env/development.js'
import production from './env/production.js'
import test from './env/test.js'
const env = process.env.SVC_ENV || 'development'
const config = require(`./env/${env}`)
console.log(`Loading config for this environment: ${env}`)
module.exports = Object.assign({}, common, config)
let config = development
if (env === 'test') {
config = test
} else if (env === 'prod') {
config = production
}
export default Object.assign({}, common, config)
+32 -29
View File
@@ -1,30 +1,6 @@
const passport = require('koa-passport')
const User = require('../src/adapters/localdb/models/users')
const Strategy = require('passport-local')
passport.serializeUser((user, done) => {
done(null, user.id)
})
passport.deserializeUser(async (id, done) => {
try {
const user = await User.findById(id, '-password')
done(null, user)
} catch (err) {
done(err)
}
})
passport.use(
'local',
new Strategy(
{
usernameField: 'email',
passwordField: 'password'
},
passportCallback
)
)
// import passport from 'koa-passport';
import User from '../src/adapters/localdb/models/users.js'
import Strategy from 'passport-local'
async function passportCallback (email, password, done) {
try {
@@ -49,5 +25,32 @@ async function passportCallback (email, password, done) {
}
}
// For testing
module.exports = { passport, passportCallback }
function applyPassportMods (passport) {
passport.serializeUser((user, done) => {
done(null, user.id)
})
passport.deserializeUser(async (id, done) => {
try {
const user = await User.findById(id, '-password')
done(null, user)
} catch (err) {
done(err)
}
})
passport.use(
'local',
new Strategy(
{
usernameField: 'email',
passwordField: 'password'
},
passportCallback
)
)
return true
}
export { applyPassportMods, passportCallback }
+10
View File
@@ -0,0 +1,10 @@
# Developer Documentation
This directory needs to be fleshed out with more information. The markdown files in this directory are intended to provide additional documentation for software developers that use this boilerplate to run their own forks.
## Startup
This software requires an IPFS node in order to operate the JSON RPC and ipfs-coord features. There are two ways to incorporate an IPFS node:
- js-ipfs is integrated into this repository. If you simply run `npm start`, then this app will default to the js-ipfs IPFS node. However, js-ipfs is not as full featured as go-ipfs. It has memory leaks and lags considerably behind go-ipfs in terms of features.
- go-ipfs is the preferred way to run a node. It can be run externally by following the guidence on the [IPFS homepage](https://ipfs.io). Once the IPFS node is running, this app can take control of it. Use the [local-external-ipfs-node.sh](../shell-scripts/local-external-ipfs-node.sh) shell script to start this app and attach it to the go-ipfs node.
+1 -1
View File
@@ -1,4 +1,4 @@
const Server = require('./bin/server.js')
import Server from './bin/server.js'
const server = new Server()
server.startServer()
+17156 -36029
View File
File diff suppressed because it is too large Load Diff
+61 -47
View File
@@ -1,19 +1,21 @@
{
"name": "ipfs-bch-wallet-service",
"version": "1.11.4",
"version": "3.0.0",
"description": "IPFS and REST service providing blockchain access needed by a wallet. ",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js",
"test": "npm run test:all",
"test:all": "export SVC_ENV=test && nyc --reporter=text mocha --exit --timeout 15000 --recursive test/unit test/e2e/automated/",
"test:all": "export SVC_ENV=test && c8 --reporter=text mocha --exit --timeout 15000 --recursive test/unit test/e2e/automated/",
"test:unit": "export SVC_ENV=test && mocha --exit --timeout 15000 --recursive test/unit/",
"test:e2e:auto": "export SVC_ENV=test && mocha --exit --timeout 30000 test/e2e/automated/",
"test:integration": "export SVC_ENV=test && mocha --timeout 30000 --recursive test/integration/",
"test:temp": "export SVC_ENV=test && mocha --exit --timeout 15000 -g '#rate-limit' test/unit/json-rpc/",
"lint": "standard --env mocha --fix",
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coverage:report": "export SVC_ENV=test && nyc --reporter=html mocha --exit --timeout 15000 --recursive test/unit/ test/e2e/automated/"
"coverage": "c8 report --reporter=text-lcov | coveralls",
"coverage:report": "export SVC_ENV=test && c8 --reporter=html mocha --exit --timeout 15000 --recursive test/unit/ test/e2e/automated/"
},
"author": "Chris Troutner <chris.troutner@gmail.com>",
"license": "MIT",
@@ -23,51 +25,63 @@
},
"repository": "Permissionless-Software-Foundation/ipfs-bch-wallet-service",
"dependencies": {
"@psf/bch-js": "^4.20.3",
"axios": "^0.21.1",
"bcryptjs": "^2.4.3",
"glob": "^7.1.6",
"ipfs": "0.55.4",
"ipfs-coord": "^6.5.1",
"jsonrpc-lite": "^2.2.0",
"jsonwebtoken": "^8.5.1",
"jwt-bch-lib": "^1.3.0",
"kcors": "^2.2.2",
"koa": "^2.13.1",
"koa-bodyparser": "^4.3.0",
"koa-convert": "^2.0.0",
"koa-generic-session": "^2.1.1",
"koa-logger": "^3.2.1",
"koa-mount": "^4.0.0",
"koa-passport": "^4.1.3",
"koa-router": "^10.0.0",
"koa-static": "^5.0.0",
"koa2-ratelimit": "^0.9.0",
"line-reader": "^0.4.0",
"mongoose": "^5.11.15",
"node-fetch": "npm:@achingbrain/node-fetch@^2.6.7",
"nodemailer": "^6.4.17",
"passport-local": "^1.0.0",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0"
"@chainsafe/libp2p-gossipsub": "11.0.1",
"@chainsafe/libp2p-noise": "14.1.0",
"@chainsafe/libp2p-yamux": "6.0.1",
"@helia/unixfs": "3.0.1",
"@libp2p/bootstrap": "10.0.7",
"@libp2p/circuit-relay-v2": "1.0.13",
"@libp2p/identify": "1.0.6",
"@libp2p/keychain": "4.0.7",
"@libp2p/logger": "4.0.5",
"@libp2p/mplex": "10.0.16",
"@libp2p/tcp": "9.0.7",
"@libp2p/webrtc": "4.0.17",
"@psf/bch-js": "6.7.3",
"axios": "0.27.2",
"bcryptjs": "2.4.3",
"blockstore-fs": "1.1.8",
"datastore-fs": "9.1.6",
"glob": "7.1.6",
"helia": "2.1.0",
"helia-coord": "1.5.5",
"jsonrpc-lite": "2.2.0",
"jsonwebtoken": "8.5.1",
"jwt-bch-lib": "1.3.0",
"kcors": "2.2.2",
"koa": "2.13.1",
"koa-bodyparser": "4.3.0",
"koa-convert": "2.0.0",
"koa-generic-session": "2.1.1",
"koa-logger": "3.2.1",
"koa-mount": "4.0.0",
"koa-passport": "4.1.3",
"koa-router": "10.0.0",
"koa-static": "5.0.0",
"koa2-ratelimit": "0.9.1",
"libp2p": "1.2.1",
"line-reader": "0.4.0",
"minimal-slp-wallet": "5.11.1",
"mongoose": "5.13.14",
"node-fetch": "npm:@achingbrain/node-fetch@2.6.7",
"nodemailer": "6.7.5",
"passport-local": "1.0.0",
"public-ip": "6.0.1",
"winston": "3.3.3",
"winston-daily-rotate-file": "4.5.0"
},
"devDependencies": {
"apidoc": "^0.26.0",
"chai": "^4.3.0",
"coveralls": "^3.1.0",
"eslint": "7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^4.3.8",
"mocha": "^8.2.1",
"nyc": "^15.1.0",
"semantic-release": "^17.4.4",
"sinon": "^9.2.4",
"standard": "^16.0.3",
"uuid": "^8.3.2"
"apidoc": "0.51.1",
"c8": "7.12.0",
"chai": "4.3.0",
"coveralls": "3.1.0",
"husky": "4.3.8",
"lodash.clonedeep": "4.5.0",
"mocha": "10.0.0",
"semantic-release": "19.0.3",
"sinon": "9.2.4",
"standard": "17.0.0",
"uuid": "8.3.2"
},
"release": {
"publish": [
+1
View File
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=bch-wallet-service
+36 -12
View File
@@ -2,32 +2,54 @@
#
#IMAGE BUILD COMMANDS
# ct-base-ubuntu = ubuntu 18.04 + nodejs v10 LTS
FROM christroutner/ct-base-ubuntu:latest
FROM ubuntu:20.04
MAINTAINER Chris Troutner <chris.troutner@gmail.com>
#Update the OS and install any OS packages needed.
RUN apt-get update
RUN apt-get install -y sudo git curl nano gnupg wget
#Install Node and NPM
RUN sudo apt-get install -y ca-certificates curl gnupg
RUN sudo mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
RUN sudo apt-get update
RUN sudo apt-get install -y nodejs build-essential
#Create the user 'safeuser' and add them to the sudo group.
#RUN useradd -ms /bin/bash safeuser
#RUN adduser safeuser sudo
RUN useradd -ms /bin/bash safeuser
RUN adduser safeuser sudo
#Set password to 'password' change value below if you want a different password
#RUN echo safeuser:password | chpasswd
RUN echo safeuser:password | chpasswd
#Set the working directory to be the home directory
WORKDIR /home/safeuser
#Setup NPM for non-root global install
#RUN mkdir /home/safeuser/.npm-global
#RUN chown -R safeuser .npm-global
#RUN echo "export PATH=~/.npm-global/bin:$PATH" >> /home/safeuser/.profile
#RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'"
RUN mkdir /home/safeuser/.npm-global
RUN chown -R safeuser .npm-global
RUN echo "export PATH=~/.npm-global/bin:$PATH" >> /home/safeuser/.profile
RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'"
# Update to the latest version of npm.
# Working with npm@7.21.1
RUN npm install -g npm
# Update to the latest version of npm.
#RUN npm install -g npm@7.23.0
#RUN npm install -g npm
# npm mirror to prevent direct dependency on npm.
RUN npm set registry http://94.130.170.209:4873/
# Switch to user account.
#USER safeuser
# Prep 'sudo' commands.
#RUN echo 'abcd8765' | sudo -S pwd
# Clone the rest.bitcoin.com repository
# Clone the repository
WORKDIR /home/safeuser
RUN git clone https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-service
@@ -39,7 +61,7 @@ WORKDIR /home/safeuser/ipfs-bch-wallet-service
RUN git checkout ct-unstable
# Install dependencies
RUN npm install -g @mapbox/node-pre-gyp
#RUN npm install -g @mapbox/node-pre-gyp
RUN npm install
# Generate the API docs
@@ -51,8 +73,10 @@ RUN mkdir /home/safeuser/.ipfsdata
#VOLUME /home/safeuser/ipfsdata
#VOLUME /home/safeuser/orbitdb
EXPOSE 5010
# Start the application.
COPY start-production.sh start-production.sh
#COPY start-production.sh start-production.sh
CMD ["./start-production.sh"]
#CMD ["npm", "start"]
+61
View File
@@ -0,0 +1,61 @@
# Docker Containers
The 'production' environment is assumed to be a set of Docker containers orchestrated with Docker Compose. The files in this directory will stand up three Docker containers:
1 An instance of go-ipfs.
2 An instance of MongoDB.
3 The JavaScript software in this repository.
The software in this repository depends on the first two containers, so if they aren't running correctly, the application won't run correctly either.
## IPFS
IPFS can be a little tricky to set up. By default, the container uses the following ports:
- 4001 for TCP connections, exposed publicly.
- 5001 for control by the application, exposed privately.
- 8080 for an IPFS gateway, consumed by the application, exposed privately.
If you already have an IPFS node running on a the computer, you will need to change the ports to avaid a conflict. To change the ports from the default, you'll need to perform a series of steps, and the order of the steps matter.
1. Edit the `docker-compose.yml` file and change the ports. Then save the file. Here is an example:
```
ports:
- 4101:4101
- 172.17.0.1:5101:5101
- 172.17.0.1:8180:8180
```
2. Bring the Docker containers up, and then back down. This will allow the IPFS container to create the config file that you'll need to edit.
- `docker-compose up -d`
- Wait a few seconds.
- `docker-compose down`
3. Update the generated config file at `../data/go-ipfs/data/config`, to update the ports in the config file, like this:
```
"Addresses": {
"API": "/ip4/0.0.0.0/tcp/5101",
"Announce": [],
"AppendAnnounce": [],
"Gateway": "/ip4/0.0.0.0/tcp/8180",
"NoAnnounce": [],
"Swarm": [
"/ip4/0.0.0.0/tcp/4101",
"/ip6/::/tcp/4101",
"/ip4/0.0.0.0/udp/4101/quic",
"/ip6/::/udp/4101/quic"
]
},
```
4. Update the port changes in the `start-production.sh` shell script. This tells the application which ports to use, in order to control the IPFS node, are are used when signaling other nodes.
5. Quickly rebuild the containers, to add the modified `start-production.sh` shell script to the application Docker container:
- `docker-compose build`
6. Now start the containers, and the port changes to IPFS should be complete.
+32 -24
View File
@@ -1,27 +1,35 @@
# Start the testnet server with the command 'docker-compose up -d'
# Start the service with the command 'docker-compose up -d'
bch-wallet-mongodb:
image: mongo
container_name: mongo-bch-service
ports:
- '5555:27017' # <host port>:<container port>
volumes:
- ../data/database:/data/db
command: mongod --logpath=/dev/null # -- quiet
restart: always
version: '3.9'
bch-wallet-service:
build: ./
dockerfile: Dockerfile
container_name: bch-wallet-service
links:
- bch-wallet-mongodb
ports:
# <host port>:<container port>
- '5001:5001' # REST API
- '5668:5668' # IPFS TCP Port
- '5669:5669' # IPFS WS Port
volumes:
- ../data/ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata
services:
mongo-bch-service:
image: mongo:4.2.0
container_name: mongo-bch-service
ports:
- '5555:27017' # <host port>:<container port>
volumes:
- ../data/mongodb:/data/db
command: mongod --logpath=/dev/null # -- quiet
restart: always
restart: always
ipfs-bch-wallet:
build: .
#image: christroutner/ipfs-service-provider:v5.0.1
container_name: ipfs-service
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '10'
mem_limit: 1000mb
links:
- mongo-bch-service
ports:
- '5010:5010' # <host port>:<container port>
- '4001:4001'
- '4003:4003'
volumes:
- ../data/ipfsdata:/home/safeuser/ipfs-bch-wallet-service/.ipfsdata
- ./start-production.sh:/home/safeuser/ipfs-bch-wallet-service/start-production.sh
restart: always
+28 -13
View File
@@ -4,16 +4,29 @@
# This mnemonic is used to set up persistent public key for e2ee
# Replace this with your own 12-word mnemonic.
# You can get one at https://wallet.fullstack.cash.
export MNEMONIC="olive two muscle bottom coral ancient wait legend bronze useful process session"
# The human readable name this IPFS node identifies as.
export COORD_NAME=ipfs-service-provider-generic
export COORD_NAME=bch-wallet-service-generic
# Allow this node to function as a circuit relay. It must not be behind a firewall.
#export ENABLE_CIRCUIT_RELAY=true
#export ENABLE_CIRCUIT_RELAY=1
# For browsers to use your circuit realy, you must set up a domain, SSL certificate,
# and you must forward that subdomain to the IPFS_WS_PORT.
#export CR_DOMAIN=subdomain.yourdomain.com
# Debug level. 0 = minimal info. 2 = max info.
export DEBUG_LEVEL=1
export DEBUG_LEVEL=2
# BCH Wallet Service Settings
# Change APISERVER to point to your own installation of bch-api
export APISERVER=https://api.fullstack.cash/v5/
# These settings are used to proxy a subscription to FullStack.cash.
#export GET_JWT_AT_STARTUP=1
export AUTHSERVER=https://auth.fullstack.cash
export FULLSTACKLOGIN=demo@demo.com
export FULLSTACKPASS=demo
# END: Optional configuration settings
@@ -21,16 +34,18 @@ export DEBUG_LEVEL=1
# Production database connection string.
export DBURL=mongodb://172.17.0.1:5555/ipfs-service-prod
# Customize these environment variables for your own installation.
export AUTHSERVER=https://auth.fullstack.cash
export APISERVER=https://api.fullstack.cash/v5/
export FULLSTACKLOGIN=demo@demo.com
export FULLSTACKPASS=demo
# Configure REST API port
export PORT=5010
# Ports
export PORT=5001 # REST API
export IPFS_TCP_PORT=5668 # IPSF TCP Port
export IPFS_WS_PORT=5669 # IPFS WS Port
# Production settings using external go-ipfs node.
export SVC_ENV=prod
export IPFS_HOST=172.17.0.1
export IPFS_API_PORT=5001
export IPFS_TCP_PORT=4001
export IPFS_WS_PORT=4003
# Set the debug level for helia-coord. 0-3.
# 0 = no debug logs. 3 = maximum debug logs.
export DEBUG_LEVEL=0
export SVC_ENV=production
npm start
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# This script is an example for running a generic ipfs-service-provider instance
# using a local installation of bch-api.
# Ports
export PORT=5002 # REST API port
export IPFS_TCP_PORT=5268
export IPFS_WS_PORT=5269
# The human-readible name that is used when displaying data about this node.
export COORD_NAME=ipfs-service-provider-generic
# This is used for end-to-end encryption (e2ee).
export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran"
# 0 = less verbose. 3 = most verbose
export DEBUG_LEVEL=1
# MongoDB connection string.
#export DBURL=mongodb://localhost:27017/bch-service-dev
# Customize these environment variables for your own installation.
export GET_JWT_AT_STARTUP=0
export APISERVER=http://localhost:3000/v5/
npm start
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
# This script is an example for running a generic ipfs-service-provider instance.
# Ports
export PORT=5002 # REST API port
export IPFS_TCP_PORT=5268
export IPFS_WS_PORT=5269
# The human-readible name that is used when displaying data about this node.
export COORD_NAME=ipfs-service-provider-generic
# This is used for end-to-end encryption (e2ee).
export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran"
# 0 = less verbose. 3 = most verbose
export DEBUG_LEVEL=1
# MongoDB connection string.
#export DBURL=mongodb://localhost:27017/bch-service-dev
npm start
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
# This script is an example for running a generic ipfs-service-provider instance.
# Ports
export PORT=5001 # REST API port
export IPFS_TCP_PORT=5268
export IPFS_WS_PORT=5269
# The human-readible name that is used when displaying data about this node.
export COORD_NAME=ipfs-service-provider-generic
# This is used for end-to-end encryption (e2ee).
export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran"
# 0 = less verbose. 3 = most verbose
export DEBUG_LEVEL=1
# MongoDB connection string.
#export DBURL=mongodb://localhost:27017/bch-service-dev
npm start
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
# This script is an example for running a ipfs-service-provider as a Circuit Relay.
# Circuit Relays are help other nodes on the network communicate. They are
# critical for reliable functioning of the network, and for circumventing
# censorship.
# Ports
export PORT=5001 # REST API port
export IPFS_TCP_PORT=5268
export IPFS_WS_PORT=5269
# The human-readible name that is used when displaying data about this node.
export COORD_NAME=ipfs-service-provider-generic
# This is used for end-to-end encryption (e2ee).
export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran"
# 0 = less verbose. 3 = most verbose
export DEBUG_LEVEL=1
# MongoDB connection string.
#export DBURL=mongodb://localhost:27017/bch-service-dev
# Comment to disable circuit relay functionality. Or set to 1 to enable.
export ENABLE_CIRCUIT_RELAY=1
# For browsers to use your circuit realy, you must set up a domain, SSL certificate,
# and you must forward that subdomain to the IPFS_WS_PORT.
#export CR_DOMAIN=subdomain.yourdomain.com
npm start
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
# This script is an example for running a production environment, which is
# defined by running an external go-ipfs node.
# Ports
export PORT=5010 # REST API port
# The human-readible name that is used when displaying data about this node.
export COORD_NAME=ipfs-bch-service-generic
# This is used for end-to-end encryption (e2ee).
export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran"
# 0 = less verbose. 3 = most verbose
export DEBUG_LEVEL=2
# Production settings that use external IPFS node.
# https://github.com/christroutner/docker-ipfs
export SVC_ENV=production
export IPFS_HOST=localhost
#export IPFS_HOST=172.17.0.1
export IPFS_API_PORT=5001
# Configure IPFS ports
export IPFS_TCP_PORT=4001
#export IPFS_WS_PORT=5269
# MongoDB connection string.
export DBURL=mongodb://localhost:27017/ipfs-service-dev
#export ENABLE_CIRCUIT_RELAY=true
npm start
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
# This script is an example for running a production environment, which is
# defined by running an external go-ipfs node.
# Ports
export PORT=5010 # REST API port
# The human-readible name that is used when displaying data about this node.
export COORD_NAME=ipfs-service-provider-generic
# This is used for end-to-end encryption (e2ee).
export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran"
# 0 = less verbose. 3 = most verbose
export DEBUG_LEVEL=0
# Production settings that use external IPFS node.
# https://github.com/christroutner/docker-ipfs
export SVC_ENV=production
export IPFS_HOST=localhost
# export IPFS_HOST=172.17.0.1
export IPFS_API_PORT=5001
# Configure IPFS ports
export IPFS_TCP_PORT=4001
#export IPFS_WS_PORT=5269
# MongoDB connection string.
export DBURL=mongodb://localhost:27017/ipfs-service-dev
npm start
+18 -8
View File
@@ -13,16 +13,24 @@
in the Adapter directory.
*/
'use strict'
const axios = require('axios').default
const mongoose = require('mongoose')
const User = require('../adapters/localdb/models/users')
const config = require('../../config')
const JsonFiles = require('../adapters/json-files')
// Global npm libraries
import axios from 'axios'
import mongoose from 'mongoose'
// Local libraries
import User from '../adapters/localdb/models/users.js'
import config from '../../config/index.js'
import JsonFiles from '../adapters/json-files.js'
// Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
import * as url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const jsonFiles = new JsonFiles()
const JSON_FILE = `system-user-${config.env}.json`
const JSON_PATH = `${__dirname.toString()}/../../config/${JSON_FILE}`
const JSON_PATH = `${__dirname.toString()}../../config/${JSON_FILE}`
const LOCALHOST = `http://localhost:${config.port}`
const context = {}
@@ -82,6 +90,8 @@ class Admin {
// applications like the Task Manager and the test scripts can access.
await jsonFiles.writeJSON(context, JSON_PATH)
// console.log('context: ', context)
// console.log('JSON_PATH: ', JSON_PATH)
return context
} catch (err) {
@@ -169,4 +179,4 @@ class Admin {
}
}
module.exports = Admin
export default Admin
+5 -6
View File
@@ -3,13 +3,12 @@
*/
/* eslint-disable no-useless-escape */
import config from '../../config/index.js'
import NodeMailer from '../adapters/nodemailer.js'
import wlogger from '../adapters/wlogger.js'
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const config = require('../../config')
const NodeMailer = require('../adapters/nodemailer')
const nodemailer = new NodeMailer()
const { wlogger } = require('../adapters/wlogger')
let _this
@@ -60,4 +59,4 @@ class ContactLib {
}
}
}
module.exports = ContactLib
export default ContactLib
+4 -9
View File
@@ -5,8 +5,9 @@
for this file.
*/
const JwtLib = require('jwt-bch-lib')
const BCHJS = require('@psf/bch-js')
import JwtLib from 'jwt-bch-lib'
import BCHJS from '@psf/bch-js'
class FullStackJWT {
constructor (localConfig = {}) {
@@ -52,12 +53,6 @@ class FullStackJWT {
// Get's a JWT token from FullStack.cash.
async getJWT () {
try {
// Skip connecting FullStack.cash auth server to the network if this is an E2E test.
if (process.env.TEST_TYPE === 'e2e') {
this.apiToken = 'faketoken'
return this.apiToken
}
// Log into the auth server.
await this.jwtLib.register()
@@ -104,4 +99,4 @@ class FullStackJWT {
}
}
module.exports = FullStackJWT
export default FullStackJWT
+33 -14
View File
@@ -5,31 +5,33 @@
*/
// Public NPM libraries
const BCHJS = require('@psf/bch-js')
import BCHJS from '@psf/bch-js'
// Load individual adapter libraries.
const IPFSAdapter = require('./ipfs')
const LocalDB = require('./localdb')
const LogsAPI = require('./logapi')
const Passport = require('./passport')
const Nodemailer = require('./nodemailer')
// const { wlogger } = require('./wlogger')
const JSONFiles = require('./json-files')
const FullStackJWT = require('./fullstack-jwt')
import IPFSAdapter from './ipfs/index.js'
const config = require('../../config')
import LocalDB from './localdb/index.js'
import LogsAPI from './logapi.js'
import Passport from './passport.js'
import Nodemailer from './nodemailer.js'
// const { wlogger } = require('./wlogger')
import JSONFiles from './json-files.js'
import FullStackJWT from './fullstack-jwt.js'
import config from '../../config/index.js'
class Adapters {
constructor (localConfig = {}) {
// Encapsulate dependencies
this.config = config
this.ipfs = new IPFSAdapter()
this.localdb = new LocalDB()
this.logapi = new LogsAPI()
this.passport = new Passport()
this.nodemailer = new Nodemailer()
this.jsonFiles = new JSONFiles()
this.bchjs = new BCHJS()
this.config = config
this.bchjs = new BCHJS({ restURL: this.config.apiServer })
// Get a valid JWT API key and instance bch-js.
this.fullStackJwt = new FullStackJWT(config)
@@ -43,10 +45,27 @@ class Adapters {
await this.fullStackJwt.getJWT()
// Instantiate bch-js with the JWT token, and overwrite the placeholder for bch-js.
this.bchjs = await this.fullStackJwt.instanceBchjs()
} else {
// console.log(
// `Initializing bchjs with this restURL: ${this.config.apiServer}`
// )
this.bchjs = new BCHJS({ restURL: this.config.apiServer })
}
// Start the IPFS node.
await this.ipfs.start({ bchjs: this.bchjs })
// Do not start these adapters if this is an e2e test.
if (this.config.env !== 'test') {
if (this.config.useIpfs) {
await this.ipfs.start({ bchjs: this.bchjs })
}
} else {
// These lines are here to ensure code coverage hits 100%.
console.log('Not starting IPFS node since this is an e2e test.')
}
console.log('Async Adapters have been started.')
return true
} catch (err) {
console.error('Error in adapters/index.js/start()')
throw err
@@ -54,4 +73,4 @@ class Adapters {
}
}
module.exports = Adapters
export default Adapters
+156 -4
View File
@@ -2,14 +2,19 @@
top-level IPFS library that combines the individual IPFS-based libraries.
*/
const IpfsAdapter = require('./ipfs')
const IpfsCoordAdapter = require('./ipfs-coord')
// Local libraries
import IpfsAdapter from './ipfs.js'
import IpfsCoordAdapter from './ipfs-coord.js'
import config from '../../../config/index.js'
class IPFS {
constructor (localConfig = {}) {
// Encapsulate dependencies
this.ipfsAdapter = new IpfsAdapter()
this.IpfsCoordAdapter = IpfsCoordAdapter
this.process = process
this.config = config
this.ipfsCoordAdapter = {} // placeholder
@@ -38,17 +43,164 @@ class IPFS {
// Start ipfs-coord
this.ipfsCoordAdapter = new this.IpfsCoordAdapter({
ipfs: this.ipfs,
bchjs
bchjs,
tcpPort: this.config.ipfsTcpPort,
wsPort: this.config.ipfsWsPort
})
await this.ipfsCoordAdapter.start()
console.log('ipfs-coord is ready.')
// Subscribe to the chat pubsub channel
await this.ipfsCoordAdapter.subscribeToChat()
return true
} catch (err) {
console.error('Error in adapters/ipfs/index.js/start()')
// If error is due to a lock file issue. Kill the process, so that
// Docker or pm2 has a chance to restart the service.
if (err.message.includes('Lock already being held')) {
console.log('lock being held. Exiting.')
this.process.exit(1)
}
throw err
}
}
// Get the status of this IPFS node.
// Create an object with different metrics about this IPFS node, then return
// the object.
getStatus () {
try {
const statusObj = {
ipfsId: this.ipfsCoordAdapter.ipfsCoord.thisNode.ipfsId,
multiAddrs: this.ipfsCoordAdapter.ipfsCoord.thisNode.ipfsMultiaddrs,
bchAddr: this.ipfsCoordAdapter.ipfsCoord.thisNode.bchAddr,
slpAddr: this.ipfsCoordAdapter.ipfsCoord.thisNode.slpAddr,
pubKey: this.ipfsCoordAdapter.ipfsCoord.thisNode.pubKey,
peers: this.ipfsCoordAdapter.ipfsCoord.thisNode.peerList.length,
relays: this.ipfsCoordAdapter.ipfsCoord.thisNode.relayData.length
}
return statusObj
} catch (err) {
console.error('Error in ipfs-coord.js/getStatus()')
throw err
}
}
// Get details on the other peers this node is connected to.
async getPeers (showAll) {
try {
const peerData = this.ipfsCoordAdapter.ipfsCoord.thisNode.peerData
// console.log(`peerData: ${JSON.stringify(peerData, null, 2)}`)
let ipfsPeers =
await this.ipfsCoordAdapter.ipfsCoord.adapters.ipfs.getPeers()
// console.log('ipfsPeers: ', ipfsPeers)
ipfsPeers = this._removeDuplicatePeers(ipfsPeers)
// console.log('filtered ipfsPeers: ', ipfsPeers)
const peerDataOut = []
// Loop through each IPFS peer and hydrate it with data from the peerData.
for (let i = 0; i < ipfsPeers.length; i++) {
const thisPeer = {
peer: ipfsPeers[i]
}
// if (!showAll) {
// // Delete properties that don't contain good info.
// delete thisPeer.muxer
// delete thisPeer.latency
// delete thisPeer.streams
// }
// Get the ipfs-coord peer data for this peer.
let thisPeerData = peerData.filter((x) =>
x.from.includes(thisPeer.peer)
)
thisPeerData = thisPeerData[0]
// console.log('thisPeerData: ', thisPeerData)
// Skip if peerData for this IPFS peer could not be found.
// if (!thisPeerData) continue
try {
// console.log('thisPeerData: ', thisPeerData)
// Add data to the IPFS peer data.
thisPeer.name = thisPeerData.data.jsonLd.name
thisPeer.protocol = thisPeerData.data.jsonLd.protocol
thisPeer.version = thisPeerData.data.jsonLd.version
thisPeer.connectionAddr = thisPeerData.data.connectionAddr
if (showAll) {
// Add all the peer data.
thisPeer.peerData = thisPeerData
}
} catch (err) {
console.warn(
`warning: ${thisPeer.peer}: ${err.message}`
)
}
peerDataOut.push(thisPeer)
}
return peerDataOut
} catch (err) {
console.error('Error in getPeers(): ', err)
throw err
}
}
// Expects an array of peers and returns an array of peers with duplicates
// removed.
// This function is used by getPeers()
_removeDuplicatePeers (arr) {
// https://stackoverflow.com/questions/2218999/how-to-remove-all-duplicates-from-an-array-of-objects
return arr.filter((v, i, a) => a.findIndex((t) => t === v) === i)
}
// Get data about the known Circuit Relays. Hydrate with data from peers list.
getRelays () {
try {
const relayData = this.ipfsCoordAdapter.ipfsCoord.thisNode.relayData
const peerData = this.ipfsCoordAdapter.ipfsCoord.thisNode.peerData
// console.log(`relayData: ${JSON.stringify(relayData, null, 2)}`)
// console.log(`peerData: ${JSON.stringify(peerData, null, 2)}`)
for (let i = 0; i < relayData.length; i++) {
const thisRelay = relayData[i]
// Find the peer that corresponds to this relay.
const thisPeer = peerData.filter((x) =>
x.from.includes(thisRelay.ipfsId)
)
// console.log('thisPeer: ', thisPeer)
// If the peer couldn't be found, skip.
if (!thisPeer.length) {
thisRelay.name = ''
thisRelay.description = ''
continue
}
thisRelay.name = thisPeer[0].data.jsonLd.name
thisRelay.description = thisPeer[0].data.jsonLd.description
}
const v1Relays = this.config.v1Relays
return { v2Relays: relayData, v1Relays }
} catch (err) {
console.error('Error in getRelays(): ', err)
throw err
}
}
}
module.exports = IPFS
export default IPFS
+63 -12
View File
@@ -5,11 +5,16 @@
*/
// Global npm libraries
const IpfsCoord = require('ipfs-coord')
// const BCHJS = require('@psf/bch-js')
// import IpfsCoord from 'ipfs-coord-esm'
import IpfsCoord from 'helia-coord'
// import BCHJS from '@psf/bch-js';
import SlpWallet from 'minimal-slp-wallet'
import { publicIpv4 } from 'public-ip'
// Local libraries
const config = require('../../../config')
import config from '../../../config/index.js'
// const JSONRPC = require('../../controllers/json-rpc/')
let _this
@@ -33,8 +38,10 @@ class IpfsCoordAdapter {
// Encapsulate dependencies
this.IpfsCoord = IpfsCoord
this.ipfsCoord = {}
// this.rpc = new JSONRPC()
// this.bchjs = new BCHJS()
this.wallet = new SlpWallet()
this.config = config
this.publicIp = publicIpv4
// Properties of this class instance.
this.isReady = false
@@ -43,20 +50,52 @@ class IpfsCoordAdapter {
}
async start (localConfig = {}) {
// console.log('this.config.announceJsonLd: ', this.config.announceJsonLd)
const circuitRelayInfo = {}
this.ipfsCoord = new this.IpfsCoord({
// Wait for the BCH wallet to create the wallet.
await this.wallet.walletInfoPromise
// If configured as a Circuit Relay, get the public IP addresses for this node.
if (this.config.isCircuitRelay) {
try {
const ip4 = await this.publicIp()
// const ip6 = await publicIp.v6()
circuitRelayInfo.ip4 = ip4
circuitRelayInfo.tcpPort = this.config.ipfsTcpPort
// Domain used by browser-based secure websocket connections.
circuitRelayInfo.crDomain = this.config.crDomain
} catch (err) {
/* exit quietly */
}
}
const nullLog = () => {}
const ipfsCoordOptions = {
ipfs: this.ipfs,
type: 'node.js',
// type: 'browser',
bchjs: this.bchjs,
privateLog: console.log, // Default to console.log
wallet: this.wallet,
// privateLog: console.log, // Default to console.log
privateLog: nullLog,
isCircuitRelay: this.config.isCircuitRelay,
circuitRelayInfo,
apiInfo: this.config.apiInfo,
announceJsonLd: this.config.announceJsonLd,
mnemonic: this.config.mnemonic,
debugLevel: this.config.debugLevel
})
debugLevel: this.config.debugLevel,
v1Relays: this.config.v1Relays,
tcpPort: this.config.ipfsTcpPort
}
// Production env uses external go-ipfs node.
// if (this.config.isProduction) {
// ipfsCoordOptions.nodeType = 'external'
// }
this.ipfsCoord = new this.IpfsCoord(ipfsCoordOptions)
// Wait for the ipfs-coord library to signal that it is ready.
await this.ipfsCoord.start({ type: 'node.js' })
@@ -72,12 +111,24 @@ class IpfsCoordAdapter {
attachRPCRouter (router) {
try {
_this.ipfsCoord.privateLog = router
_this.ipfsCoord.adapters.orbit.privateLog = router
_this.ipfsCoord.adapters.pubsub.privateLog = router
} catch (err) {
console.error('Error in attachRPCRouter()')
throw err
}
}
// Subscribe to the chat pubsub channel
async subscribeToChat () {
// TODO: Allow user to replace nullog with their own log handler at startup.
const nullLog = () => {}
await this.ipfsCoord.adapters.pubsub.subscribeToPubsubChannel(
this.config.chatPubSubChan,
nullLog,
this.ipfsCoord.thisNode
)
}
}
module.exports = IpfsCoordAdapter
export default IpfsCoordAdapter
+254 -35
View File
@@ -2,73 +2,292 @@
Clean Architecture Adapter for IPFS.
This library deals with IPFS so that the apps business logic doesn't need
to have any specific knowledge of the js-ipfs library.
TODO: Add the external IP address to the list of multiaddrs advertised by
this node. See this GitHub Issue for details:
https://github.com/Permissionless-Software-Foundation/ipfs-service-provider/issues/38
*/
// Global npm libraries
const IPFS = require('ipfs')
import { createHelia } from 'helia'
import fs from 'fs'
import { FsBlockstore } from 'blockstore-fs'
import { FsDatastore } from 'datastore-fs'
import { createLibp2p } from 'libp2p'
import { tcp } from '@libp2p/tcp'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
// import { bootstrap } from '@libp2p/bootstrap'
// import { identifyService } from 'libp2p/identify'
import { identify } from '@libp2p/identify'
// import { circuitRelayServer, circuitRelayTransport } from 'libp2p/circuit-relay'
import { circuitRelayServer, circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { webSockets } from '@libp2p/websockets'
import { publicIpv4 } from 'public-ip'
import { multiaddr } from '@multiformats/multiaddr'
import { webRTC } from '@libp2p/webrtc'
import { keychain } from '@libp2p/keychain'
import { defaultLogger } from '@libp2p/logger'
import { unixfs } from '@helia/unixfs'
// Local libraries
const config = require('../../../config')
import config from '../../../config/index.js'
import JsonFiles from '../json-files.js'
// Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
import * as url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
// console.log('__dirname: ', __dirname)
const ROOT_DIR = `${__dirname}../../../`
const IPFS_DIR = `${__dirname}../../../.ipfsdata/ipfs`
class IpfsAdapter {
constructor (localConfig) {
// Encapsulate dependencies
this.IPFS = IPFS
this.config = config
this.fs = fs
this.createLibp2p = createLibp2p
this.publicIp = publicIpv4
this.multiaddr = multiaddr
this.jsonFiles = new JsonFiles()
this.keychain = keychain
this.createHelia = createHelia
// Properties of this class instance.
this.isReady = false
this.config = config
// Bind 'this' object to all subfunctions
this.start = this.start.bind(this)
this.createNode = this.createNode.bind(this)
this.stop = this.stop.bind(this)
this.ensureBlocksDir = this.ensureBlocksDir.bind(this)
this.getSeed = this.getSeed.bind(this)
this.getKeychain = this.getKeychain.bind(this)
}
// Start an IPFS node.
async start () {
try {
// Ipfs Options
const ipfsOptions = {
repo: './.ipfsdata/ipfs',
start: true,
config: {
relay: {
enabled: true, // enable circuit relay dialer and listener
hop: {
enabled: true // enable circuit relay HOP (make this node a relay)
}
},
pubsub: true, // enable pubsub
Swarm: {
ConnMgr: {
HighWater: 30,
LowWater: 10
}
},
Addresses: {
Swarm: [
`/ip4/0.0.0.0/tcp/${this.config.ipfsTcpPort}`,
`/ip4/0.0.0.0/tcp/${this.config.ipfsWsPort}/ws`
]
}
}
}
// Ensure the directory structure exists that is needed by the IPFS node to store data.
this.ensureBlocksDir()
// Create a new IPFS node.
this.ipfs = await this.IPFS.create(ipfsOptions)
// Create an IPFS node
const ipfs = await this.createNode()
// console.log('ipfs: ', ipfs)
// Set the 'server' profile so the node does not scan private networks.
await this.ipfs.config.profiles.apply('server')
this.id = ipfs.libp2p.peerId.toString()
console.log('IPFS ID: ', this.id)
// Attempt to guess our ip4 IP address.
const ip4 = await this.publicIp()
let detectedMultiaddr = `/ip4/${ip4}/tcp/${this.config.ipfsTcpPort}/p2p/${this.id}`
detectedMultiaddr = this.multiaddr(detectedMultiaddr)
// Get the multiaddrs for the node.
const multiaddrs = ipfs.libp2p.getMultiaddrs()
multiaddrs.push(detectedMultiaddr)
console.log('Multiaddrs: ', multiaddrs)
this.multiaddrs = multiaddrs
// Signal that this adapter is ready.
this.isReady = true
this.ipfs = ipfs
return this.ipfs
} catch (err) {
console.error('Error in ipfs.js/start()')
// If IPFS crashes because the /blocks directory is full, wipe the directory.
// if (err.message.includes('No space left on device')) {
// this.rmBlocksDir()
// }
throw err
}
}
async getKeychain (datastore) {
const keychainInit = {
pass: await this.getSeed()
}
const chain = this.keychain(keychainInit)({
datastore,
logger: defaultLogger()
})
return chain
}
// This function creates an IPFS node using Helia.
// It returns the node as an object.
async createNode () {
try {
// Create block and data stores.
const blockstore = new FsBlockstore(`${IPFS_DIR}/blockstore`)
const datastore = new FsDatastore(`${IPFS_DIR}/datastore`)
// const keychainInit = {
// pass: await this.getSeed()
// }
// Create an identity
let peerId
// console.log('this.keychain: ', this.keychain)
// const chain = this.keychain(keychainInit)({
// datastore,
// logger: defaultLogger()
// })
const chain = await this.getKeychain(datastore)
try {
peerId = await chain.exportPeerId('myKey')
} catch (err) {
await chain.createKey('myKey', 'Ed25519', 4096)
peerId = await chain.exportPeerId('myKey')
}
// Configure services
const services = {
identify: identify(),
pubsub: gossipsub({ allowPublishToZeroPeers: true })
}
if (this.config.isCircuitRelay) {
console.log('Helia (IPFS) node IS configured as Circuit Relay')
services.relay = circuitRelayServer({ // makes the node function as a relay server
hopTimeout: 30 * 1000, // incoming relay requests must be resolved within this time limit
advertise: true,
reservations: {
maxReservations: 15, // how many peers are allowed to reserve relay slots on this server
reservationClearInterval: 300 * 1000, // how often to reclaim stale reservations
applyDefaultLimit: true, // whether to apply default data/duration limits to each relayed connection
defaultDurationLimit: 2 * 60 * 1000, // the default maximum amount of time a relayed connection can be open for
defaultDataLimit: BigInt(2 << 7), // the default maximum number of bytes that can be transferred over a relayed connection
maxInboundHopStreams: 32, // how many inbound HOP streams are allow simultaneously
maxOutboundHopStreams: 64 // how many outbound HOP streams are allow simultaneously
}
})
} else {
console.log('Helia (IPFS) node IS NOT configured as Circuit Relay')
}
// Configure transports
let transports
if (process.env.CONNECT_PREF === 'direct') {
transports = [
tcp(),
webSockets(),
webRTC()
]
} else {
transports = [
tcp(),
webSockets(),
circuitRelayTransport({
discoverRelays: 3,
reservationConcurrency: 3
}),
webRTC()
]
}
// libp2p is the networking layer that underpins Helia
const libp2p = await this.createLibp2p({
peerId,
datastore,
addresses: {
listen: [
'/ip4/127.0.0.1/tcp/0',
`/ip4/0.0.0.0/tcp/${this.config.ipfsTcpPort}`,
`/ip4/0.0.0.0/tcp/${this.config.ipfsWsPort}/ws`,
'/webrtc'
]
},
transports,
connectionEncryption: [
noise()
],
streamMuxers: [
yamux()
],
services
})
// create a Helia node
const helia = await this.createHelia({
blockstore,
datastore,
libp2p
})
// Attach IPFS file system.
const fs = unixfs(helia)
helia.fs = fs
return helia
} catch (err) {
console.error('Error creating Helia node: ', err)
throw err
}
}
async stop () {
await this.ipfs.stop()
return true
}
// Ensure that the directories exist to store blocks from the IPFS network.
// This function is called at startup, before the IPFS node is started.
ensureBlocksDir () {
try {
!this.fs.existsSync(`${ROOT_DIR}.ipfsdata`) && this.fs.mkdirSync(`${ROOT_DIR}.ipfsdata`)
!this.fs.existsSync(`${IPFS_DIR}`) && this.fs.mkdirSync(`${IPFS_DIR}`)
!this.fs.existsSync(`${IPFS_DIR}/blockstore`) && this.fs.mkdirSync(`${IPFS_DIR}/blockstore`)
!this.fs.existsSync(`${IPFS_DIR}/datastore`) && this.fs.mkdirSync(`${IPFS_DIR}/datastore`)
return true
} catch (err) {
console.error('Error in adapters/ipfs.js/ensureBlocksDir(): ', err)
throw err
}
}
// This function opens the seed used to generate the key for this IPFS peer.
// The seed is stored in a JSON file. If it doesn't exist, a new one is created.
async getSeed () {
try {
let seed
const filename = `${IPFS_DIR}/seed.json`
try {
// Try to read the JSON file containing the seed.
seed = await this.jsonFiles.readJSON(filename)
} catch (err) {
const seedNum = Math.floor(Math.random() * 1000000000000000000000)
seed = seedNum.toString()
// Save the newly generated seed
await this.jsonFiles.writeJSON(seed, filename)
}
// console.log('getSeed() seed: ', seed)
return seed
} catch (err) {
console.error('Error in adapters/ipfs/ipfs.js/getSeed()')
throw err
}
}
}
module.exports = IpfsAdapter
export default IpfsAdapter
+5 -4
View File
@@ -1,8 +1,8 @@
/*
A utility file for reading and writing JSON files.
*/
'use strict'
const fs = require('fs')
import fs from 'fs'
let _this
@@ -57,7 +57,8 @@ class JsonFiles {
console.log(`err: ${JSON.stringify(err, null, 2)}`)
}
throw err
// throw err
return reject(err)
}
const obj = JSON.parse(data)
@@ -72,4 +73,4 @@ class JsonFiles {
}
}
module.exports = JsonFiles
export default JsonFiles
+2 -2
View File
@@ -3,7 +3,7 @@
*/
// Load Mongoose models.
const Users = require('./models/users')
import Users from './models/users.js'
class LocalDB {
constructor () {
@@ -12,4 +12,4 @@ class LocalDB {
}
}
module.exports = LocalDB
export default LocalDB
+8 -5
View File
@@ -1,7 +1,10 @@
const mongoose = require('mongoose')
const bcrypt = require('bcryptjs')
const config = require('../../../../config')
const jwt = require('jsonwebtoken')
// Global npm libraries
import mongoose from 'mongoose'
import bcrypt from 'bcryptjs'
import jwt from 'jsonwebtoken'
// Local libraries
import config from '../../../../config/index.js'
const User = new mongoose.Schema({
type: { type: String, default: 'user' },
@@ -51,4 +54,4 @@ User.methods.generateToken = function generateToken () {
}
// export default mongoose.model('user', User)
module.exports = mongoose.model('user', User)
export default mongoose.model('user', User)
+12 -5
View File
@@ -1,9 +1,14 @@
const lineReader = require('line-reader')
const fs = require('fs')
import lineReader from 'line-reader'
import fs from 'fs'
const config = require('../../config')
import config from '../../config/index.js'
// Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
import * as url from 'url'
let _this
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
class LogsApi {
constructor () {
@@ -135,8 +140,10 @@ class LogsApi {
if (!filename || typeof filename !== 'string') {
throw new Error('filename must be a string')
}
// Throw an error if the file does not exist.
console.log('readLines() filename: ', filename)
// Throw an error if the file does not exist.
if (!_this.fs.existsSync(filename)) {
throw new Error('file does not exist')
}
@@ -167,4 +174,4 @@ class LogsApi {
}
}
module.exports = LogsApi
export default LogsApi
+4 -5
View File
@@ -3,11 +3,10 @@
*/
'use strict'
const nodemailer = require('nodemailer')
import nodemailer from 'nodemailer'
const config = require('../../config')
const { wlogger } = require('./wlogger')
import config from '../../config/index.js'
import wlogger from './wlogger.js'
let _this
@@ -150,4 +149,4 @@ class NodeMailer {
}
}
module.exports = NodeMailer
export default NodeMailer
+2 -2
View File
@@ -2,7 +2,7 @@
koa-passport is an authorization library used for different authentication schemes.
*/
const passport = require('koa-passport')
import passport from 'koa-passport'
let _this
class Passport {
@@ -32,4 +32,4 @@ class Passport {
}
}
module.exports = Passport
export default Passport
+16 -39
View File
@@ -6,10 +6,17 @@
'use strict'
const winston = require('winston')
require('winston-daily-rotate-file')
// Global npm libraries
import winston from 'winston'
import 'winston-daily-rotate-file'
const config = require('../../config')
// Local libraries
import config from '../../config/index.js'
// Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
import * as url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
class Wlogger {
constructor (localConfig = {}) {
@@ -62,42 +69,12 @@ class Wlogger {
}
}
// transport.on('rotate', notifyRotation)
// function notifyRotation (oldFilename, newFilename) {
// wlogger.info('Rotating log files')
// }
// This controls what goes into the log FILES
// const wlogger = winston.createLogger({
// level: 'verbose',
// format: winston.format.json(),
// transports: [
// //
// // - Write to all logs with level `info` and below to `combined.log`
// // - Write all logs error (and below) to `error.log`.
// //
// // new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
// // new winston.transports.File({ filename: 'logs/combined.log' })
// transport
// ]
// })
// function outputToConsole () {
// wlogger.add(
// new winston.transports.Console({
// format: winston.format.simple(),
// level: 'info'
// })
// )
// }
// This controls the logs to CONSOLE
// if (config.env !== 'test') {
// outputToConsole()
// }
const logger = new Wlogger()
// Allow the logger to write to the console.
logger.outputToConsole()
const wlogger = logger.wlogger
module.exports = { wlogger, Wlogger }
export { wlogger as default, Wlogger }
// export default wlogger
+31 -25
View File
@@ -6,39 +6,31 @@
// Public npm libraries.
// Load the Clean Architecture Adapters library
const Adapters = require('../adapters')
// Load the JSON RPC Controller.
const JSONRPC = require('./json-rpc')
// Load the Clean Architecture Use Case libraries.
const UseCases = require('../use-cases')
// const useCases = new UseCases({ adapters })
// Load the REST API Controllers.
const RESTControllers = require('./rest-api')
// Local libraries
import Adapters from '../adapters/index.js'
import JSONRPC from './json-rpc/index.js'
import UseCases from '../use-cases/index.js'
import RESTControllers from './rest-api/index.js'
import TimerControllers from './timer-controllers.js'
import config from '../../config/index.js'
class Controllers {
constructor (localConfig = {}) {
// Encapsulate dependencies
this.adapters = new Adapters()
this.useCases = new UseCases({ adapters: this.adapters })
this.timerControllers = new TimerControllers({ adapters: this.adapters, useCases: this.useCases })
this.config = config
}
async attachControllers (app) {
// Get a JWT token and instantiate bch-js with it. Then pass that instance
// to all the rest of the apps controllers and adapters.
await this.adapters.fullStackJwt.getJWT()
// Instantiate bch-js with the JWT token, and overwrite the placeholder for bch-js.
this.adapters.bchjs = await this.adapters.fullStackJwt.instanceBchjs()
// Wait for any startup processes to complete for the Adapters libraries.
// Spin up any adapter libraries that have async startup needs.
async initAdapters () {
await this.adapters.start()
}
// Attach the REST controllers to the Koa app.
// this.attachRESTControllers(app)
this.attachRPCControllers()
// Run any Use Cases to startup the app.
async initUseCases () {
await this.useCases.start()
}
// Top-level function for this library.
@@ -53,6 +45,20 @@ class Controllers {
restControllers.attachRESTControllers(app)
}
// Attach any other controllers other than REST API controllers.
async attachControllers (app) {
// Wait for any startup processes to complete for the Adapters libraries.
// await this.adapters.start()
if (this.config.useIpfs) {
// Attach JSON RPC controllers
this.attachRPCControllers()
}
// Attach and start the timer controllers
this.timerControllers.startTimers()
}
// Add the JSON RPC router to the ipfs-coord adapter.
attachRPCControllers () {
const jsonRpcController = new JSONRPC({
@@ -67,4 +73,4 @@ class Controllers {
}
}
module.exports = Controllers
export default Controllers
+8 -3
View File
@@ -1,12 +1,15 @@
/*
This is the JSON RPC router for the users API
CT 3/5/22: This library can probably be deleted. Handling of the /about endpoint
is now directly controlled by the ipfs-coord library.
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
import jsonrpc from 'jsonrpc-lite'
// Local libraries
const config = require('../../../../config')
import config from '../../../../config/index.js'
class AboutRPC {
constructor (localConfig) {
@@ -33,6 +36,8 @@ class AboutRPC {
// This is a bit different than other router libraries, because there is
// only one response, which is a string about this node.
async aboutRouter (rpcData) {
console.log('debugging: aboutRouter from ipfs-service-provider triggered')
return {
success: true,
status: 200,
@@ -43,4 +48,4 @@ class AboutRPC {
}
}
module.exports = AboutRPC
export default AboutRPC
+5 -4
View File
@@ -3,13 +3,14 @@
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
import jsonrpc from 'jsonrpc-lite'
// Local libraries
// const AuthLib = require('../../lib/auth')
// const UserLib = require('../../../use-cases/user')
const { wlogger } = require('../../../adapters/wlogger')
const RateLimit = require('../rate-limit')
import wlogger from '../../../adapters/wlogger.js'
import RateLimit from '../rate-limit.js'
class AuthRPC {
constructor (localConfig = {}) {
@@ -173,4 +174,4 @@ class AuthRPC {
}
}
module.exports = AuthRPC
export default AuthRPC
+527 -61
View File
@@ -3,13 +3,13 @@
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
import jsonrpc from 'jsonrpc-lite'
// const BCHJS = require('@psf/bch-js')
// Local libraries
// const UserLib = require('../../../use-cases/user')
const Validators = require('../validators')
const RateLimit = require('../rate-limit')
import Validators from '../validators.js'
import RateLimit from '../rate-limit.js'
class BCHRPC {
constructor (localConfig = {}) {
@@ -32,7 +32,6 @@ class BCHRPC {
this.jsonrpc = jsonrpc
this.validators = new Validators(localConfig)
this.rateLimit = new RateLimit()
// this.bchjs = new BCHJS()
this.bchjs = this.adapters.bchjs
}
@@ -49,9 +48,9 @@ class BCHRPC {
// Route the call based on the value of the method property.
switch (endpoint) {
case 'transactions':
case 'txHistory':
await this.rateLimit.limiter(rpcData.from)
return await this.transactions(rpcData)
return await this.txHistory(rpcData)
case 'balance':
await this.rateLimit.limiter(rpcData.from)
@@ -61,13 +60,33 @@ class BCHRPC {
await this.rateLimit.limiter(rpcData.from)
return await this.utxos(rpcData)
case 'utxosBulk':
await this.rateLimit.limiter(rpcData.from)
return await this.utxosBulk(rpcData)
case 'broadcast':
await this.rateLimit.limiter(rpcData.from)
return await this.broadcast(rpcData)
case 'transaction':
case 'txData':
await this.rateLimit.limiter(rpcData.from)
return await this.transaction(rpcData)
return await this.txData(rpcData)
case 'pubkey':
await this.rateLimit.limiter(rpcData.from)
return await this.pubKey(rpcData)
case 'utxoIsValid':
await this.rateLimit.limiter(rpcData.from)
return await this.utxoIsValid(rpcData)
case 'getTokenData':
await this.rateLimit.limiter(rpcData.from)
return await this.getTokenData(rpcData)
case 'getTokenData2':
await this.rateLimit.limiter(rpcData.from)
return await this.getTokenData2(rpcData)
}
} catch (err) {
console.error('Error in BCHRPC/rpcRouter()')
@@ -83,12 +102,20 @@ class BCHRPC {
}
/**
* @api {JSON} /bch Transactions
* @api {JSON} /bch TX History
* @apiPermission public
* @apiName Transactions
* @apiName txHistory
* @apiGroup JSON BCH
* @apiDescription This endpoint wraps the bchjs.Electrumx.transactions([]) function.
* Given the 'addresses' property this endpoint returns an object with the following properties
* It returns the transaction history for an address. This list of TXIDs is
* sorted and paginated.
*
* There are three possible inputs:
* - address: (required) the address to query for a transaction history
* - sortOrder: (optional) will sort results in 'DECENDING' (default) or 'ASCENDING' order.
* - page: (optional) will return a 'page' of 100 results. Default is 0
*
* Given the 'address' property this endpoint returns an object with the following properties
*
* - jsonrpc: "" - jsonrpc version
* - id: "" - jsonrpc id
@@ -97,15 +124,14 @@ class BCHRPC {
* - receiver: "" - Receiver address
* - value: {} - Final result value of the petition
* - success : - Petition status
* - transactions : [] - Transactions of the provided adresses
* - transactions: [] - Transaction details
* - height : - Reference to the blockchain size
* - tx_hash: "" - Hash of the transaction
* - address : "" - Address asociated to the transactions
* - txs : [] - Transactions of the provided address
* - height : - Reference to the blockchain size
* - tx_hash: "" - Hash of the transaction
* - address : "" - Address asociated to the transactions
* - status: - HTTP Status Code
*
* @apiExample Example usage:
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "transactions", "addresses": ["bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"]}}
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "txHistory", "addresses": ["bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"], "sortOrder": "DESCENDING", "page": 0}}
*
* @apiSuccessExample {json} Success-Response:
* {
@@ -115,36 +141,29 @@ class BCHRPC {
* "method":"bch",
* "reciever":"QmU86vLVbUY1UhziKB6rak7GPKRA2QHWvzNm2AjEvXNsT6",
* "value":{
* "address":"bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"
* "success":true,
* "transactions":[
* {
* "transactions":[
* {
* "height":631219,
* "tx_hash":"ae2daa01c8172545b5edd205ea438706bcb74e63d4084a26b9ff2a46d46dc97f"
* }
* ],
* "address":"bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"
* }
* "txs":[
* {
* "height":631219,
* "tx_hash":"ae2daa01c8172545b5edd205ea438706bcb74e63d4084a26b9ff2a46d46dc97f"
* }
* ],
* "status":200
* }
* }
* }
*/
async transactions (rpcData) {
async txHistory (rpcData) {
try {
// console.log('createUser rpcData: ', rpcData)
// console.log('transactions rpcData: ', rpcData)
const addrs = rpcData.payload.params.addresses
// const addr = rpcData.payload.params.address
// const sortOrder = rpcData.payload.params.sortOrder
const data = await this.bchjs.Electrumx.transactions(addrs)
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
const data = await this.useCases.bch.getTransactions(rpcData)
const retObj = data
retObj.status = 200
return retObj
return data
} catch (err) {
console.error('Error in JSON RPC BCH transactions()')
// throw err
@@ -154,7 +173,7 @@ class BCHRPC {
success: false,
status: 422,
message: err.message,
endpoint: 'transactions'
endpoint: 'txHistory'
}
}
}
@@ -223,7 +242,7 @@ class BCHRPC {
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH balance()')
console.error('Error in JSON RPC BCH balance(): ', err)
// throw err
// Return an error response
@@ -327,6 +346,7 @@ class BCHRPC {
// console.log('createUser rpcData: ', rpcData)
const addr = rpcData.payload.params.address
// console.log('addr: ', addr)
const data = await this.bchjs.Utxo.get(addr)
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
@@ -350,6 +370,145 @@ class BCHRPC {
}
}
/**
* @api {JSON} /bch UTXOs Bulk
* @apiPermission public
* @apiName UTXOs Bulk
* @apiGroup JSON BCH
* @apiDescription This endpoint provides the same data as as the utxos
* endpoint, but it allows retrieval of UTXOs for up to 20 addresses at
* a time. This reduces the number of JSON RPC calls, and is very handy
* for HD wallets that need to quickly scan a lot of addresses.
*
* Given an array of addresses, this endpoint will return an object
* with the following properties
*
* - jsonrpc: "" - jsonrpc version
* - id: "" - jsonrpc id
* - result: {} - Result of the request with the RPC information
* - method: "" - Method used in the request
* - receiver: "" - Receiver address
* - value: [] - Final result value of the request
* - address: "" - the address these UTXOs are associated with
* - bchUtxos: [] - UTXOs confirmed to be spendable as normal BCH
* - nullUtxo: [] - UTXOs that did not pass SLP validation. Should be ignored and
* not spent, to be safe.
* - slpUtxos: {} - UTXOs confirmed to be colored as valid SLP tokens
* - type1: {}
* - tokens: [] - SLP token Type 1 tokens.
* - mintBatons: [] - SLP token Type 1 mint batons.
* - nft: {}
* - tokens: [] - NFT tokens
* - groupTokens: [] - NFT Group tokens, used to create NFT tokens.
* - groupMintBatons: [] - Minting baton to create more NFT Group tokens.
*
* @apiExample Example usage:
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "utxos", "address": "bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj"}}
*
* @apiSuccessExample {json} Success-Response:
*
* {
* "jsonrpc":"2.0",
* "id":"555",
* "result":{
* "method":"bch",
* "reciever":"QmU86vLVbUY1UhziKB6rak7GPKRA2QHWvzNm2AjEvXNsT6",
* "value":[
* {
* "address":"bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj",
* "bchUtxos":[
* {
* "height":631219,
* "tx_hash":"ae2daa01c8172545b5edd205ea438706bcb74e63d4084a26b9ff2a46d46dc97f",
* "tx_pos":0,
* "value":1000,
* "txid":"ae2daa01c8172545b5edd205ea438706bcb74e63d4084a26b9ff2a46d46dc97f",
* "vout":0,
* "isValid":false
* }
* ],
* "nullUtxos":[
*
* ],
* "slpUtxos":{
* "type1":{
* "mintBatons":[
*
* ],
* "tokens":[
*
* ]
* },
* "nft":{
* "groupMintBatons":[
*
* ],
* "groupTokens":[
*
* ],
* "tokens":[
*
* ]
* }
* }
* }
* ]
* }
* }
*
*/
async utxosBulk (rpcData) {
try {
// console.log('createUser rpcData: ', rpcData)
const addrs = rpcData.payload.params.addresses
// console.log('addrs: ', addrs)
// Input validation
if (!Array.isArray(addrs)) {
throw new Error('addresses parameter must be an array')
}
if (addrs.length > 20) {
throw new Error('addresses parameter must not exceed 20 elements')
}
const result = []
for (let i = 0; i < addrs.length; i++) {
const thisAddr = addrs[i]
const data = await this.bchjs.Utxo.get(thisAddr)
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
result.push({
address: thisAddr,
utxos: data
})
}
// console.log('result: ', result)
const retObj = {}
retObj.status = 200
retObj.success = true
retObj.data = result
// console.log('retObj: ', retObj)
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH utxosBulk()')
console.error('Error in JSON RPC utxosBulk(): ', err)
// throw err
// Return an error response
return {
success: false,
status: 422,
message: err.message,
endpoint: 'utxosBulk'
}
}
}
/**
* @api {JSON} /bch Broadcast
* @apiPermission public
@@ -400,25 +559,38 @@ class BCHRPC {
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH broadcast()')
console.log('error: ', err)
// throw err
// bch-api will sometimes return an error message, not an error object.
let message = ''
if (!err.message && err.error) {
// Full node error
message = err.error
} else {
// Normal error
message = err.message
}
// Return an error response
return {
success: false,
status: 422,
message: err.message,
message,
endpoint: 'broadcast'
}
}
}
/**
* @api {JSON} /bch Transaction
* @api {JSON} /bch Transaction Data
* @apiPermission public
* @apiName Transaction
* @apiName txData
* @apiGroup JSON BCH
* @apiDescription Get data about a specific transaction.
* Given a transaction the endpoint will return an object with the
* @apiDescription Get expanded transaction data for an array of transaction
* IDs. Each call is limited to 20 TXIDs or less.
*
* Given a transaction ID, the endpoint will return an object with the
* following properties
*
* - jsonrpc: "" - jsonrpc version
@@ -443,13 +615,13 @@ class BCHRPC {
* - status: - HTTP Status Code
*
* @apiExample Example usage:
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "transaction", "txid": "01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b"}}
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "txData", "txids": ["01517ff1587fa5ffe6f5eb91c99cf3f2d22330cd7ee847e928ce90ca95bf781b"]}}
*
* @apiSuccessExample {json} Success-Response:
* {
* "jsonrpc":"2.0",
* "id":"555",
* "result":{
* "txData": [{
* "method":"bch",
* "reciever":"QmU86vLVbUY1UhziKB6rak7GPKRA2QHWvzNm2AjEvXNsT6",
* "value":{
@@ -504,34 +676,328 @@ class BCHRPC {
* "status":200
* }
* }
* }
* }]
*/
async transaction (rpcData) {
async txData (rpcData) {
try {
// console.log('transaction rpcData: ', rpcData)
const txid = rpcData.payload.params.txid
const data = await this.bchjs.Transaction.get(txid.toString())
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
const retObj = data
retObj.status = 200
const retObj = await this.useCases.bch.getTxData(rpcData)
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH transaction()')
// throw err
console.error('Error in JSON RPC BCH txData()): ', err)
// Return an error response
return {
success: false,
status: 422,
message: err.message,
endpoint: 'transaction'
endpoint: 'txData'
}
}
}
/**
* @api {JSON} /bch PubKey
* @apiPermission public
* @apiName PubKey
* @apiGroup JSON BCH
* @apiDescription Get the public key from an address.
* Given an address the endpoint will return an object with the
* following properties
*
* - jsonrpc: "" - jsonrpc version
* - id: "" - jsonrpc id
* - result: {} - Result of the petition with the RPC information
* - success: - Request status
* - publickey: - Address public key
*
* @apiExample Example usage:
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "pubkey", "address": "bitcoincash:qpnty9t0w93fez04h7yzevujpv8pun204qv6yfuahk"}}
*
* @apiSuccessExample {json} Success-Response:
* {
* "jsonrpc":"2.0",
* "id":"555",
* "result":{
* "method":"bch",
* "reciever":"QmU86vLVbUY1UhziKB6rak7GPKRA2QHWvzNm2AjEvXNsT6",
* "value":{
* "success": true,
* "status": 200,
* "endpoint": "pubkey",
* "pubkey": {
* "success": true,
* "publicKey": "033f267fec0f7eb2b27f8c2e3052b3d03b09d36b47de4082ffb638ffb334ef0eee"
* }
*
* }
*/
async pubKey (rpcData) {
try {
// console.log('createUser rpcData: ', rpcData)
const address = rpcData.payload.params.address
const data = await this.bchjs.encryption.getPubKey(address)
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
const retObj = {
success: true,
status: 200,
endpoint: 'pubkey',
pubkey: data
}
// retObj.status = 200
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH pubKey()')
// Handle different error formats.
let error = err
if (err.error && typeof err.error === 'string') {
error = new Error(err.error)
}
// Return an error response
return {
success: false,
status: 422,
message: error.message,
endpoint: 'pubkey'
}
}
}
/**
* @api {JSON} /bch UtxoIsValid
* @apiPermission public
* @apiName UtxoIsValid
* @apiGroup JSON BCH
* @apiDescription Verify if UTXO is valid
* Given a UTXO object (txid and vout), a full node is queried to verify that
* the UTXO still exists in the mempool (true), or if it has been spent (false).
*
* - jsonrpc: "" - jsonrpc version
* - id: "" - jsonrpc id
* - result: {} - Result of the petition with the RPC information
* - success: - Request status
* - isValid: - Boolean: true or false
*
* @apiExample Example usage:
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "utxoIsValid", "utxo": {"tx_hash": "17754221b29f189532d4fc2ae89fb467ad2dede30fdec4854eb2129b3ba90d7a", "tx_pos": 0}}}
*
* @apiSuccessExample {json} Success-Response:
* {
* "jsonrpc":"2.0",
* "id":"555",
* "result":{
* "method":"bch",
* "reciever":"QmU86vLVbUY1UhziKB6rak7GPKRA2QHWvzNm2AjEvXNsT6",
* "value":{
* "success": true,
* "status": 200,
* "endpoint": "utxoIsValid",
* "isValid": true
* }
* }
*
* }
*/
async utxoIsValid (rpcData) {
try {
// console.log('createUser rpcData: ', rpcData)
const utxo = rpcData.payload.params.utxo
// console.log('utxo: ', utxo)
const isValid = await this.bchjs.Utxo.isValid(utxo)
const retObj = {
success: true,
status: 200,
endpoint: 'utxoIsValid',
isValid
}
// retObj.status = 200
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH utxoIsValid()')
// Handle different error formats.
let error = err
if (err.error && typeof err.error === 'string') {
error = new Error(err.error)
}
// Return an error response
return {
success: false,
status: 422,
message: error.message,
endpoint: 'utxoIsValid'
}
}
}
/**
* @api {JSON} /bch getTokenData
* @apiPermission public
* @apiName getTokenData
* @apiGroup JSON BCH
* @apiDescription Get data associated with a token
* Given a token ID, this endpoint will retrieve the IPFS CIDs associated with
* the tokens mutable and immutable data. This is extension of the PS002
* specification for mutable data for tokens:
* https://github.com/Permissionless-Software-Foundation/specifications/blob/master/ps002-slp-mutable-data.md
*
* If optional parameter 'withTxHistory' is true, data will include the
* transaction history of the token.
*
* - jsonrpc: "" - jsonrpc version
* - id: "" - jsonrpc id
* - result: {} - Result of the petition with the RPC information
* - success: - Request status
* - tokenData: - Address public key
*
* @apiExample Example usage:
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "getTokenData", "tokenId": "c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d", "withTxHistory": true }}
*
* @apiSuccessExample {json} Success-Response:
* {
* "jsonrpc":"2.0",
* "id":"555",
* "result":{
* "method":"bch",
* "reciever":"QmU86vLVbUY1UhziKB6rak7GPKRA2QHWvzNm2AjEvXNsT6",
* "value":{
* "success": true,
* "status": 200,
* "endpoint": "getTokenData",
* "tokenData": {
* "genesisData": {
* "type": 1,
* "ticker": 'MT2',
* "name": 'Mutable Token',
* "tokenId": 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d',
* "documentUri": 'ipfs://bafybeie7oxpsr7evcnlptecxfdhaqlot4732phukd2ekgvuzoir2frost4',
* "documentHash": '56ed1a5768076a318d02b5db64e125544dca57ab6b2cc7ca61dfa4645d244463',
* "decimals": 0,
* "mintBatonIsActive": true,
* "tokensInCirculationBN": '1000',
* "tokensInCirculationStr": '1000',
* "blockCreated": 739412,
* "totalBurned": '0',
* "totalMinted": '1000'
* },
* "immutableData": 'ipfs://bafybeie7oxpsr7evcnlptecxfdhaqlot4732phukd2ekgvuzoir2frost4',
* "mutableData": 'ipfs://bafybeigotuony53ley3n63hqwyxiqruqn5uamskmci6f645putnc46jju4'
* }
* }
* }
* }
*/
async getTokenData (rpcData) {
try {
// console.log('createUser rpcData: ', rpcData)
const tokenId = rpcData.payload.params.tokenId
// console.log('tokenId: ', tokenId)
const withTxHistory = !!rpcData.payload.params.withTxHistory
const tokenData = await this.bchjs.PsfSlpIndexer.getTokenData(tokenId, withTxHistory)
const retObj = {
success: true,
status: 200,
endpoint: 'getTokenData',
tokenData
}
// retObj.status = 200
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH utxoIsValid()')
// Handle different error formats.
let error = err
if (err.error && typeof err.error === 'string') {
error = new Error(err.error)
}
// Return an error response
return {
success: false,
status: 422,
message: error.message,
endpoint: 'getTokenData'
}
}
}
/**
* @api {JSON} /bch getTokenData2
* @apiPermission public
* @apiName getTokenData2
* @apiGroup JSON BCH
* @apiDescription Get token icon and other media
*
* Get the icon for a token, given it's token ID.
* This function expects a string input of a token ID property.
* This function returns an object with a tokenIcon property that contains
* the URL to the icon.
*
* The output object always have these properties:
* - tokenIcon: A url to the token icon, if it exists.
* - tokenStats: Data about the token from psf-slp-indexer.
* - optimizedTokenIcon: An alternative, potentially more optimal, url to the token icon, if it exists.
* - iconRepoCompatible: true if the token icon is available via token.bch.sx
* - ps002Compatible: true if the token icon is compatible with PS007 specification.
*
* @apiExample Example usage:
* {"jsonrpc":"2.0","id":"555","method":"bch","params":{ "endpoint": "getTokenData2", "tokenId": "c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d", "withTxHistory": true }}
*
*/
async getTokenData2 (rpcData) {
try {
// console.log('createUser rpcData: ', rpcData)
const tokenId = rpcData.payload.params.tokenId
// console.log('tokenId: ', tokenId)
const updateCache = rpcData.payload.params.updateCache
const tokenData = await this.bchjs.PsfSlpIndexer.getTokenData2(tokenId, updateCache)
const retObj = {
success: true,
status: 200,
endpoint: 'getTokenData2',
tokenData
}
// retObj.status = 200
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH utxoIsValid()')
// Handle different error formats.
let error = err
if (err.error && typeof err.error === 'string') {
error = new Error(err.error)
}
// Return an error response
return {
success: false,
status: 422,
message: error.message,
endpoint: 'getTokenData2'
}
}
}
}
module.exports = BCHRPC
// module.exports = BCHRPC
export default BCHRPC
+81 -15
View File
@@ -3,14 +3,14 @@
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
import jsonrpc from 'jsonrpc-lite'
// Local support libraries
const { wlogger } = require('../../adapters/wlogger')
const UserController = require('./users')
const AuthController = require('./auth')
const AboutController = require('./about')
const BCHController = require('./bch')
import wlogger from '../../adapters/wlogger.js'
import UserController from './users/index.js'
import AuthController from './auth/index.js'
import AboutController from './about/index.js'
import BCHController from './bch/index.js'
let _this
@@ -38,6 +38,11 @@ class JSONRPC {
this.aboutController = new AboutController()
this.bchController = new BCHController(localConfig)
// Cache to store IDs of processed JSON RPC commands. Used to prevent
// duplicate processing.
this.msgCache = []
this.MSG_CACHE_SIZE = 30
_this = this
}
@@ -45,24 +50,55 @@ class JSONRPC {
// which controller to route the instruction to.
async router (str, from) {
try {
console.log('router str: ', str)
console.log('router from: ', from)
// console.log('router str: ', str)
console.log('JSON RPC router recieved data from: ', from)
// Exit quietly if 'from' is not specified.
if (!from || typeof from !== 'string') {
// console.warn(
// 'Warning: Can not send JSON RPC response. Can not determine which peer this message came from.'
// )
return
wlogger.info(
'Warning: Can not send JSON RPC response. Can not determine which peer this message came from.'
)
return false
}
// Attempt to parse the incoming data as a JSON RPC string.
const parsedData = _this.jsonrpc.parse(str)
// console.log('parsedData: ', parsedData)
// wlogger.debug(`parsedData: ${JSON.stringify(parsedData, null, 2)}`)
// Exit quietly if the incoming string is an invalid JSON RPC string.
if (parsedData.type === 'invalid') {
return
wlogger.info('Rejecting invalid JSON RPC command.')
return false
}
// Check for duplicate entries with same 'id' value.
const alreadyProcessed = _this._checkIfAlreadyProcessed(parsedData)
if (alreadyProcessed) {
return false
} else {
// console.log(`parsedData: ${JSON.stringify(parsedData, null, 2)}`)
// This node will regularly ping known circuit relays with an /about
// JSON RPC call. These will be handled by ipfs-coord, but will percolate
// up to this library. Ignore these messages.
if (
parsedData.type.includes('success') &&
parsedData.payload.method === undefined
) {
return false
}
// Log the incoming JSON RPC command.
wlogger.info(
`JSON RPC received from ${from}, ID: ${parsedData.payload.id}, type: ${parsedData.type}, method: ${parsedData.payload.method}`
)
// Additional debugging for BCH.
if (parsedData.payload.method === 'bch') {
wlogger.info(
`rpcData.payload: ${JSON.stringify(parsedData.payload, null, 2)}`
)
}
}
// Added the property "from" to the parsedData object;
@@ -124,6 +160,36 @@ class JSONRPC {
}
}
// Checks the ID of the JSON RPC call, to see if the message has already been
// processed. Returns true if the ID exists in the cache of processed messages.
// If the ID is new, the function adds it to the cache and return false.
_checkIfAlreadyProcessed (data) {
try {
// console.log('data: ', data)
const id = data.payload.id
// Check if the hash is in the array of already processed message.
const alreadyProcessed = this.msgCache.includes(id)
// Update the msgCache if this is a new message.
if (!alreadyProcessed) {
// Add the hash to the array.
this.msgCache.push(id)
// If the array is at its max size, then remove the oldest element.
if (this.msgCache.length > this.MSG_CACHE_SIZE) {
this.msgCache.shift()
}
}
return alreadyProcessed
} catch (err) {
console.error('Error in _checkIfAlreadyProcessed: ', err)
return true
}
}
// The default JSON RPC response if the incoming command could not be routed.
defaultResponse () {
const errorObj = {
@@ -136,4 +202,4 @@ class JSONRPC {
}
}
module.exports = JSONRPC
export default JSONRPC
+2 -2
View File
@@ -4,7 +4,7 @@
/* eslint no-useless-catch: 0 */
// Local libraries
const RateLimitLib = require('koa2-ratelimit').RateLimit
import { RateLimit as RateLimitLib } from 'koa2-ratelimit'
class RateLimit {
constructor (options) {
@@ -80,4 +80,4 @@ class RateLimit {
}
}
module.exports = RateLimit
export default RateLimit
+5 -4
View File
@@ -3,12 +3,13 @@
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
import jsonrpc from 'jsonrpc-lite'
// Local libraries
// const UserLib = require('../../../use-cases/user')
const Validators = require('../validators')
const RateLimit = require('../rate-limit')
import Validators from '../validators.js'
import RateLimit from '../rate-limit.js'
class UserRPC {
constructor (localConfig = {}) {
@@ -533,4 +534,4 @@ class UserRPC {
// TODO create deleteUser()
}
module.exports = UserRPC
export default UserRPC
+4 -3
View File
@@ -4,10 +4,11 @@
/* eslint no-useless-catch: 0 */
// Public npm libraries
const jwt = require('jsonwebtoken')
import jwt from 'jsonwebtoken'
// Local libraries
const config = require('../../../config')
import config from '../../../config/index.js'
// const UserModel = require('../../adapters/localdb/models/users')
class Validators {
@@ -93,4 +94,4 @@ class Validators {
}
}
module.exports = Validators
export default Validators
+2 -2
View File
@@ -1,4 +1,4 @@
const Passport = require('../../../adapters/passport')
import Passport from '../../../adapters/passport.js'
const passport = new Passport()
let _this
@@ -96,4 +96,4 @@ class AuthRESTController {
}
}
module.exports = AuthRESTController
export default AuthRESTController
+3 -3
View File
@@ -3,10 +3,10 @@
*/
// Public npm libraries.
const Router = require('koa-router')
import Router from 'koa-router'
// Local libraries.
const AuthRESTController = require('./controller')
import AuthRESTController from './controller.js'
class AuthRouter {
constructor (localConfig = {}) {
@@ -48,4 +48,4 @@ class AuthRouter {
}
}
module.exports = AuthRouter
export default AuthRouter
+55 -2
View File
@@ -94,7 +94,7 @@ class BCHRESTController {
* @api {post} /bch/balance Balance
* @apiName Balance
* @apiGroup REST BCH
* @apiDescription Devuelve el balance de un address o un array de adresses.
* @apiDescription Returns the balance of an address or an array of addresses.
*
* Given the 'addresses' property returns an array of objects
* with the following properties
@@ -378,6 +378,57 @@ class BCHRESTController {
}
}
/**
* @api {post} /bch/pubkey PubKey
* @apiName PubKey
* @apiGroup REST BCH
* @apiDescription Get the public key from an address
*
* Given the 'address' param returns an object
* with the following properties
*
* - success : - Request status
* - publicKey : '' - Public key of the provided address
*
*
* @apiExample Example usage:
* curl -H "Content-Type: application/json" -X GET localhost:5001/bch/pubkey/bitcoincash:qpnty9t0w93fez04h7yzevujpv8pun204qv6yfuahk
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "success":true,
* "publicKey": '033f267fec0f7eb2b27f8c2e3052b3d03b09d36b47de4082ffb638ffb334ef0eee'
* }
*
* @apiError UnprocessableEntity Missing required parameters
*
* @apiErrorExample {json} Error-Response:
* HTTP/1.1 422 Unprocessable Entity
* {
* "status": 422,
* "error": "Unprocessable Entity"
* }
*/
async pubKey (ctx) {
try {
const address = ctx.params.address
console.log(`pubKey address: ${address}`)
const pubkey = await _this.bchjs.encryption.getPubKey(address)
// console.log(`pubkey: ${JSON.stringify(pubkey, null, 2)}`)
ctx.body = pubkey
} catch (err) {
console.log(err)
let error = err
if (err.error && typeof err.error === 'string') {
error = new Error(err.error)
}
_this.handleError(ctx, error)
}
}
// DRY error handler
handleError (ctx, err) {
// If an HTTP status is specified by the buisiness logic, use that.
@@ -393,4 +444,6 @@ class BCHRESTController {
}
}
}
module.exports = BCHRESTController
// module.exports = BCHRESTController
export default BCHRESTController
+7 -3
View File
@@ -3,10 +3,12 @@
*/
// Public npm libraries.
const Router = require('koa-router')
// const Router = require('koa-router')
import Router from 'koa-router'
// Local libraries.
const BCHRESTController = require('./controller')
// const BCHRESTController = require('./controller')
import BCHRESTController from './controller.js'
class BCHRouter {
constructor (localConfig = {}) {
@@ -50,6 +52,7 @@ class BCHRouter {
this.router.post('/utxos', this.bchRESTController.utxos)
this.router.post('/broadcast', this.bchRESTController.broadcast)
this.router.post('/transaction', this.bchRESTController.transaction)
this.router.get('/pubkey/:address', this.bchRESTController.pubKey)
// Attach the Controller routes to the Koa app.
app.use(this.router.routes())
@@ -57,4 +60,5 @@ class BCHRouter {
}
}
module.exports = BCHRouter
// module.exports = BCHRouter
export default BCHRouter
@@ -3,9 +3,9 @@
*/
/* eslint-disable no-useless-escape */
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
import ContactLib from '../../../adapters/contact.js'
const ContactLib = require('../../../adapters/contact')
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const contactLib = new ContactLib()
let _this
@@ -74,4 +74,4 @@ class ContactController {
}
}
}
module.exports = ContactController
export default ContactController
+3 -3
View File
@@ -3,10 +3,10 @@
*/
// Public npm libraries.
const Router = require('koa-router')
import Router from 'koa-router'
// Local libraries.
const ContactRESTControllerLib = require('./controller')
import ContactRESTControllerLib from './controller.js'
class ContactRouter {
constructor (localConfig = {}) {
@@ -53,4 +53,4 @@ class ContactRouter {
}
}
module.exports = ContactRouter
export default ContactRouter
+12 -7
View File
@@ -6,12 +6,13 @@
// Public npm libraries.
// Load the REST API Controllers.
const AuthRESTController = require('./auth')
const UserRouter = require('./users')
const ContactRESTController = require('./contact')
const LogsRESTController = require('./logs')
const BCHRESTController = require('./bch')
// Local libraries
import AuthRESTController from './auth/index.js'
import UserRouter from './users/index.js'
import ContactRESTController from './contact/index.js'
import LogsRESTController from './logs/index.js'
import IpfsRESTController from './ipfs/index.js'
import BCHRESTController from './bch/index.js'
class RESTControllers {
constructor (localConfig = {}) {
@@ -54,10 +55,14 @@ class RESTControllers {
const logsRESTController = new LogsRESTController(dependencies)
logsRESTController.attach(app)
// Attach the REST API Controllers associated with the /ipfs route
const ipfsRESTController = new IpfsRESTController(dependencies)
ipfsRESTController.attach(app)
// Attach the REST API Controllers associated with the /fulcrum route
const bchRESTController = new BCHRESTController(dependencies)
bchRESTController.attach(app)
}
}
module.exports = RESTControllers
export default RESTControllers
+145
View File
@@ -0,0 +1,145 @@
/*
REST API Controller library for the /ipfs route
*/
// Global npm libraries
// Local libraries
import wlogger from '../../../adapters/wlogger.js'
class IpfsRESTControllerLib {
constructor (localConfig = {}) {
// Dependency Injection.
this.adapters = localConfig.adapters
if (!this.adapters) {
throw new Error(
'Instance of Adapters library required when instantiating /ipfs REST Controller.'
)
}
this.useCases = localConfig.useCases
if (!this.useCases) {
throw new Error(
'Instance of Use Cases library required when instantiating /ipfs REST Controller.'
)
}
// Encapsulate dependencies
// this.UserModel = this.adapters.localdb.Users
// this.userUseCases = this.useCases.user
// Bind 'this' object to all subfunctions
this.getStatus = this.getStatus.bind(this)
this.getPeers = this.getPeers.bind(this)
this.getRelays = this.getRelays.bind(this)
this.handleError = this.handleError.bind(this)
this.connect = this.connect.bind(this)
this.getThisNode = this.getThisNode.bind(this)
}
/**
* @api {get} /ipfs Get status on IPFS infrastructure
* @apiPermission public
* @apiName GetIpfsStatus
* @apiGroup REST BCH
*
* @apiExample Example usage:
* curl -H "Content-Type: application/json" -X GET localhost:5001/ipfs
*
*/
async getStatus (ctx) {
try {
const status = await this.adapters.ipfs.getStatus()
ctx.body = { status }
} catch (err) {
wlogger.error('Error in ipfs/controller.js/getStatus(): ')
// ctx.throw(422, err.message)
this.handleError(ctx, err)
}
}
// Return information on IPFS peers this node is connected to.
async getPeers (ctx) {
try {
const showAll = ctx.request.body.showAll
const peers = await this.adapters.ipfs.getPeers(showAll)
ctx.body = { peers }
} catch (err) {
wlogger.error('Error in ipfs/controller.js/getPeers(): ')
// ctx.throw(422, err.message)
this.handleError(ctx, err)
}
}
// Get data about the known Circuit Relays. Hydrate with data from peers list.
async getRelays (ctx) {
try {
const relays = await this.adapters.ipfs.getRelays()
ctx.body = { relays }
} catch (err) {
wlogger.error('Error in ipfs/controller.js/getRelays(): ')
// ctx.throw(422, err.message)
this.handleError(ctx, err)
}
}
async connect (ctx) {
try {
const multiaddr = ctx.request.body.multiaddr
const getDetails = ctx.request.body.getDetails
// console.log('this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs: ', this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs)
const result = await this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.adapters.ipfs.connectToPeer({ multiaddr, getDetails })
// console.log('result: ', result)
ctx.body = result
} catch (err) {
wlogger.error('Error in ipfs/controller.js/connect():', err)
// ctx.throw(422, err.message)
this.handleError(ctx, err)
}
}
/**
* @api {get} /ipfs/node Get a copy of the thisNode object from helia-coord
* @apiPermission public
* @apiName GetThisNode
* @apiGroup REST BCH
*
* @apiExample Example usage:
* curl -H "Content-Type: application/json" -X GET localhost:5001/ipfs/node
*
*/
async getThisNode (ctx) {
try {
const thisNode = this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode
ctx.body = { thisNode }
} catch (err) {
wlogger.error('Error in ipfs/controller.js/getThisNode(): ')
// ctx.throw(422, err.message)
this.handleError(ctx, err)
}
}
// DRY error handler
handleError (ctx, err) {
// If an HTTP status is specified by the buisiness logic, use that.
if (err.status) {
if (err.message) {
ctx.throw(err.status, err.message)
} else {
ctx.throw(err.status)
}
} else {
// By default use a 422 error if the HTTP status is not specified.
ctx.throw(422, err.message)
}
}
}
// module.exports = IpfsRESTControllerLib
export default IpfsRESTControllerLib
+67
View File
@@ -0,0 +1,67 @@
/*
REST API library for the /ipfs route.
*/
// Public npm libraries.
import Router from 'koa-router'
// Local libraries.
import IPFSRESTControllerLib from './controller.js'
import Validators from '../middleware/validators.js'
// let _this
class IpfsRouter {
constructor (localConfig = {}) {
// Dependency Injection.
this.adapters = localConfig.adapters
if (!this.adapters) {
throw new Error(
'Instance of Adapters library required when instantiating IPFS REST Controller.'
)
}
this.useCases = localConfig.useCases
if (!this.useCases) {
throw new Error(
'Instance of Use Cases library required when instantiating IPFS REST Controller.'
)
}
const dependencies = {
adapters: this.adapters,
useCases: this.useCases
}
// Encapsulate dependencies.
this.ipfsRESTController = new IPFSRESTControllerLib(dependencies)
this.validators = new Validators()
// Instantiate the router and set the base route.
const baseUrl = '/ipfs'
this.router = new Router({ prefix: baseUrl })
// _this = this
}
attach (app) {
if (!app) {
throw new Error(
'Must pass app object when attaching REST API controllers.'
)
}
// Define the routes and attach the controller.
this.router.get('/', this.ipfsRESTController.getStatus)
this.router.post('/peers', this.ipfsRESTController.getPeers)
this.router.post('/relays', this.ipfsRESTController.getRelays)
this.router.post('/connect', this.ipfsRESTController.connect)
this.router.get('/node', this.ipfsRESTController.getThisNode)
// Attach the Controller routes to the Koa app.
app.use(this.router.routes())
app.use(this.router.allowedMethods())
}
}
// module.exports = BchRouter
export default IpfsRouter
+2 -2
View File
@@ -1,4 +1,4 @@
const LogsApiLib = require('../../../adapters/logapi')
import LogsApiLib from '../../../adapters/logapi.js'
const logsApiLib = new LogsApiLib()
let _this
@@ -62,4 +62,4 @@ class LogsApi {
}
}
module.exports = LogsApi
export default LogsApi
+3 -3
View File
@@ -3,10 +3,10 @@
*/
// Public npm libraries.
const Router = require('koa-router')
import Router from 'koa-router'
// Local libraries.
const LogsRESTControllerLib = require('./controller')
import LogsRESTControllerLib from './controller.js'
class LogsRouter {
constructor (localConfig = {}) {
@@ -52,4 +52,4 @@ class LogsRouter {
}
}
module.exports = LogsRouter
export default LogsRouter
+2 -2
View File
@@ -1,4 +1,4 @@
module.exports = function errorMiddleware () {
export default function errorMiddleware () {
return async (ctx, next) => {
try {
await next()
@@ -8,4 +8,4 @@ module.exports = function errorMiddleware () {
ctx.app.emit('error', err, ctx)
}
}
}
};
@@ -1,11 +1,24 @@
/*
REST API validator middleware.
These are a series of functions that ensure the user making a REST API
matches a user in the database (or not). In can do fine-grain user control
such as telling the difference between an admin, a normal user, and an
anonymous user.
This middleware is used to gatekeep access to different REST API resources.
CT 9/17/22:
This library was lightly refactored to make it work with the new unit tests.
This not and the commented code below can be deleted once it is verified that
this refactor did not result in any breaking changes.
*/
const User = require('../../../adapters/localdb/models/users')
const config = require('../../../../config')
const jwt = require('jsonwebtoken')
const { wlogger } = require('../../../adapters/wlogger')
import User from '../../../adapters/localdb/models/users.js'
import config from '../../../../config/index.js'
import jwt from 'jsonwebtoken'
import wlogger from '../../../adapters/wlogger.js'
let _this
@@ -20,12 +33,10 @@ class Validators {
async ensureUser (ctx, next) {
try {
// console.log(`getToken: ${typeof (getToken)}`)
const token = _this.getToken(ctx)
if (!token) {
// console.log(`Err: Token not provided.`)
ctx.throw(401)
throw new Error('Token could not be retrieved from header')
}
let decoded = null
@@ -34,20 +45,23 @@ class Validators {
// console.log(`config: ${JSON.stringify(config, null, 2)}`)
decoded = _this.jwt.verify(token, config.token)
} catch (err) {
// console.log(`Err: Token could not be decoded: ${err}`)
ctx.throw(401)
throw new Error('Could not verify JWT')
}
ctx.state.user = await _this.User.findById(decoded.id, '-password')
if (!ctx.state.user) {
// console.log(`Err: Could not find user.`)
ctx.throw(401)
// console.log('Err: Could not find user.')
throw new Error('Could not find user')
}
// return next()
return true
} catch (error) {
ctx.throw(401)
// console.log('Ensure user error: ', error)
// console.log('ctx: ', ctx)
ctx.status = 401
ctx.throw(401, error.message)
}
}
@@ -60,7 +74,8 @@ class Validators {
if (!token) {
// console.log(`Err: Token not provided.`)
ctx.throw(401)
// ctx.throw(401)
throw new Error('Token could not be retrieved from header')
}
let decoded = null
@@ -70,22 +85,26 @@ class Validators {
decoded = _this.jwt.verify(token, config.token)
} catch (err) {
// console.log(`Err: Token could not be decoded: ${err}`)
ctx.throw(401)
// ctx.throw(401)
throw new Error('Could not verify JWT')
}
ctx.state.user = await _this.User.findById(decoded.id, '-password')
if (!ctx.state.user) {
// console.log(`Err: Could not find user.`)
ctx.throw(401)
// ctx.throw(401)
throw new Error('Could not find user')
}
if (ctx.state.user.type !== 'admin') {
ctx.throw(401, 'not admin')
// ctx.throw(401, 'not admin')
throw new Error('User is not an admin')
}
// return next()
return true
} catch (error) {
ctx.status = 401
ctx.throw(401, error.message)
}
}
@@ -101,7 +120,8 @@ class Validators {
if (!token) {
// console.log(`Err: Token not provided.`)
ctx.throw(401)
// ctx.throw(401)
throw new Error('Token could not be retrieved from header')
}
// The user ID targeted in this API call.
@@ -114,14 +134,16 @@ class Validators {
// console.log(`config: ${JSON.stringify(config, null, 2)}`)
decoded = _this.jwt.verify(token, config.token)
} catch (err) {
// console.log(`Err: Token could not be decoded: ${err}`)
ctx.throw(401)
console.log(`Err: Token could not be decoded: ${err}`)
// ctx.throw(401)
throw new Error('Could not verify JWT')
}
ctx.state.user = await _this.User.findById(decoded.id, '-password')
if (!ctx.state.user) {
// console.log(`Err: Could not find user.`)
ctx.throw(401)
// ctx.throw(401)
throw new Error('Could not find user')
}
// console.log('ctx.state.user: ', ctx.state.user)
@@ -135,7 +157,8 @@ class Validators {
// If they don't match, then the calling user better be an admin.
if (ctx.state.user.type !== 'admin') {
ctx.throw(401, 'not admin')
// ctx.throw(401, 'not admin')
throw new Error('User is not an admin')
} else {
wlogger.verbose("It's ok. The user is an admin.")
}
@@ -144,6 +167,8 @@ class Validators {
// return next()
return true
} catch (error) {
// console.log('Error in ensureTargetUserOrAdmin(): ', error)
ctx.status = 401
ctx.throw(401, error.message)
}
}
@@ -166,4 +191,4 @@ class Validators {
}
}
module.exports = Validators
export default Validators
+5 -5
View File
@@ -2,7 +2,7 @@
REST API Controller library for the /user route
*/
const { wlogger } = require('../../../adapters/wlogger')
import wlogger from '../../../adapters/wlogger.js'
let _this
@@ -36,7 +36,7 @@ class UserRESTControllerLib {
* @apiGroup REST Users
*
* @apiExample Example usage:
* curl -H "Content-Type: application/json" -X POST -d '{ "user": { "email": "email@format.com", "name": "my name", "password": "secretpasas" } }' localhost:5001/users
* curl -H "Content-Type: application/json" -X POST -d '{ "user": { "email": "email@format.com", "name": "my name", "password": "secretpasas" } }' localhost:5010/users
*
* @apiParam {Object} user User object (required)
* @apiParam {String} user.email Email
@@ -124,7 +124,7 @@ class UserRESTControllerLib {
ctx.body = { users }
} catch (err) {
wlogger.error('Error in users/controller.js/getUsers(): '.err)
wlogger.error('Error in users/controller.js/getUsers(): ', err)
ctx.throw(422, err.message)
}
}
@@ -136,7 +136,7 @@ class UserRESTControllerLib {
* @apiGroup REST Users
*
* @apiExample Example usage:
* curl -H "Content-Type: application/json" -X GET localhost:5000/users/56bd1da600a526986cf65c80
* curl -H "Content-Type: application/json" -X GET localhost:5010/users/56bd1da600a526986cf65c80
*
* @apiSuccess {Object} users User object
* @apiSuccess {ObjectId} users._id User id
@@ -281,4 +281,4 @@ class UserRESTControllerLib {
}
}
module.exports = UserRESTControllerLib
export default UserRESTControllerLib
+5 -4
View File
@@ -3,11 +3,12 @@
*/
// Public npm libraries.
const Router = require('koa-router')
import Router from 'koa-router'
// Local libraries.
const UserRESTControllerLib = require('./controller')
const Validators = require('../middleware/validators')
import UserRESTControllerLib from './controller.js'
import Validators from '../middleware/validators.js'
let _this
@@ -85,4 +86,4 @@ class UserRouter {
}
}
module.exports = UserRouter
export default UserRouter
+65
View File
@@ -0,0 +1,65 @@
/*
This Controller library is concerned with timer-based functions that are
kicked off periodicially.
*/
import config from '../../config/index.js'
class TimerControllers {
constructor (localConfig = {}) {
// Dependency Injection.
this.adapters = localConfig.adapters
if (!this.adapters) {
throw new Error(
'Instance of Adapters library required when instantiating Timer Controller libraries.'
)
}
this.useCases = localConfig.useCases
if (!this.useCases) {
throw new Error(
'Instance of Use Cases library required when instantiating Timer Controller libraries.'
)
}
this.debugLevel = localConfig.debugLevel
// Encapsulate dependencies
this.config = config
// Bind 'this' object to all subfunctions.
this.exampleTimerFunc = this.exampleTimerFunc.bind(this)
// this.startTimers()
}
// Start all the time-based controllers.
startTimers () {
// Any new timer control functions can be added here. They will be started
// when the server starts.
this.optimizeWalletHandle = setInterval(this.exampleTimerFunc, 60000 * 10)
return true
}
stopTimers () {
clearInterval(this.optimizeWalletHandle)
}
// Replace this example function with your own timer handler.
exampleTimerFunc (negativeTest) {
try {
console.log('Example timer controller executed.')
if (negativeTest) throw new Error('test error')
return true
} catch (err) {
console.error('Error in exampleTimerFunc(): ', err)
// Note: Do not throw an error. This is a top-level function.
return false
}
}
}
export default TimerControllers
+1 -1
View File
@@ -21,4 +21,4 @@ class User {
}
}
module.exports = User
export default User
+143
View File
@@ -0,0 +1,143 @@
/*
Use Cases for interacting with the BCH blockchain.
*/
class BCHUseCases {
constructor (localConfig = {}) {
// console.log('User localConfig: ', localConfig)
this.adapters = localConfig.adapters
if (!this.adapters) {
throw new Error(
'Instance of adapters must be passed in when instantiating BCH Use Cases library.'
)
}
// Encapsulate dependencies
this.bchjs = this.adapters.bchjs
}
// Get transaction history for an address, sorted by block height.
async getTransactions (rpcData) {
try {
// console.log(
// `getTransactions rpcData: ${JSON.stringify(rpcData, null, 2)}`
// )
// Get the list of addresses.
const addr = rpcData.payload.params.address
// Default to descending sorting.
let sortOrder = rpcData.payload.params.sortOrder
if (!sortOrder) sortOrder = 'DESCENDING'
// console.log('sortOrder: ', sortOrder)
// Default to page 1
let page = rpcData.payload.params.page
if (!page) page = 0
// console.log('page: ', page)
// Get the transaction history for the list of addresses.
const data = await this.bchjs.Electrumx.transactions([addr])
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
if (!data.success) {
throw new Error('Could not query Fulcrum indexer.')
}
// console.log(`transactions: ${JSON.stringify(transactions, null, 2)}`);
// Sort the transactions.
const txsArr = await this.bchjs.Electrumx.sortAllTxs(
data.transactions[0].transactions,
sortOrder
)
// console.log(`txsArr: ${JSON.stringify(txsArr, null, 2)}`)
// Paginate the results
const pagedResults = this.bchjs.Util.chunk100(txsArr)
// console.log(
// `pagedResults[page]: ${JSON.stringify(pagedResults[page], null, 2)}`
// )
const retObj = {
address: addr,
txs: pagedResults[page],
status: 200,
success: true
}
// console.log(`retObj: ${JSON.stringify(retObj, null, 2)}`)
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH transactions(): ', err)
// throw err
// Return an error response
return {
success: false,
status: 422,
message: err.message,
endpoint: 'txHistory'
}
}
}
// Get transaction data for an array of TXIDs.
async getTxData (rpcData) {
try {
// console.log('transaction rpcData: ', rpcData)
const txids = rpcData.payload.params.txids
// console.log(`txids: ${JSON.stringify(txids, null, 2)}`)
if (!Array.isArray(txids)) {
return {
success: false,
status: 422,
message: 'Input txids must be an array of transaction IDs.',
endpoint: 'txData'
}
}
if (txids.length > 20) {
return {
success: false,
status: 422,
message: 'Array input must be 20 elements or less.',
endpoint: 'txData'
}
}
const txData = []
for (let i = 0; i < txids.length; i++) {
const thisTxid = txids[i]
// console.log(`this.bchjs.restURL: ${this.bchjs.restURL}`)
const data = await this.bchjs.Transaction.get(thisTxid.toString())
// console.log(`data: ${JSON.stringify(data, null, 2)}`)
txData.push(data.txData)
}
const retObj = {
status: 200,
txData
}
return retObj
} catch (err) {
console.error('Error in JSON RPC BCH getTxData(): ', err)
// throw err
// Return an error response
return {
success: false,
status: 422,
message: err.message,
endpoint: 'txData'
}
}
}
}
// module.exports = BCHUseCases
export default BCHUseCases
+12 -2
View File
@@ -4,7 +4,9 @@
https://troutsblog.com/blog/clean-architecture
*/
const UserUseCases = require('./user')
// Local libraries
import UserUseCases from './user.js'
import BCHUseCases from './bch/index.js'
class UseCases {
constructor (localConfig = {}) {
@@ -17,7 +19,15 @@ class UseCases {
// console.log('use-cases/index.js localConfig: ', localConfig)
this.user = new UserUseCases(localConfig)
this.bch = new BCHUseCases(localConfig)
}
// Run any startup Use Cases at the start of the app.
async start () {
console.log('Async Use Cases have been started.')
return true
}
}
module.exports = UseCases
export default UseCases
+4 -3
View File
@@ -3,8 +3,9 @@
functions are called by the /user REST API endpoints.
*/
const UserEntity = require('../entities/user')
const { wlogger } = require('../adapters/wlogger')
import UserEntity from '../entities/user.js'
import wlogger from '../adapters/wlogger.js'
class UserLib {
constructor (localConfig = {}) {
@@ -181,4 +182,4 @@ class UserLib {
}
}
module.exports = UserLib
export default UserLib
+3
View File
@@ -0,0 +1,3 @@
/key/swarm/psk/1.0.0/
/base16/
bbd935b70105b03ebd0c6a3c2d2730cd22fc0d18c490ccf689b6c8a22e1bed2a
+10 -6
View File
@@ -5,14 +5,18 @@
*/
// Public npm libraries
const assert = require('chai').assert
const axios = require('axios').default
import { assert } from 'chai'
import axios from 'axios'
// const sinon = require('sinon')
// Local support libraries
const config = require('../../../config')
const Server = require('../../../bin/server')
const testUtils = require('../../utils/test-utils')
const AdminLib = require('../../../src/adapters/admin')
import config from '../../../config/index.js'
import Server from '../../../bin/server.js'
import testUtils from '../../utils/test-utils.js'
import AdminLib from '../../../src/adapters/admin.js'
const adminLib = new AdminLib()
// const request = supertest.agent(app.listen())
+10 -14
View File
@@ -1,20 +1,19 @@
const testUtils = require('../../utils/test-utils')
const assert = require('chai').assert
const config = require('../../../config')
const axios = require('axios').default
const sinon = require('sinon')
import testUtils from '../../utils/test-utils.js'
import { assert } from 'chai'
import config from '../../../config/index.js'
import axios from 'axios'
import sinon from 'sinon'
import util from 'util'
const util = require('util')
import UserController from '../../../src/controllers/rest-api/users/controller.js'
import Adapters from '../../../src/adapters/index.js'
import UseCases from '../../../src/use-cases/index.js'
util.inspect.defaultOptions = { depth: 1 }
const LOCALHOST = `http://localhost:${config.port}`
const context = {}
const UserController = require('../../../src/controllers/rest-api/users/controller')
const Adapters = require('../../../src/adapters')
const adapters = new Adapters()
const UseCases = require('../../../src/use-cases/')
let uut
let sandbox
@@ -39,7 +38,7 @@ describe('Users', () => {
// Get the JWT used to log in as the admin 'system' user.
const adminJWT = await testUtils.getAdminJWT()
// console.log(`adminJWT: ${admi nJWT}`)
console.log(`adminJWT: ${adminJWT}`)
context.adminJWT = adminJWT
// const admin = await testUtils.loginAdminUser()
@@ -71,9 +70,6 @@ describe('Users', () => {
await axios(options)
/* console.log(
`result stringified: ${JSON.stringify(result.data, null, 2)}`
) */
assert(false, 'Unexpected result')
} catch (err) {
assert(err.response.status === 422, 'Error code 422 expected.')
+7 -7
View File
@@ -1,15 +1,15 @@
const config = require('../../../config')
const axios = require('axios').default
const assert = require('chai').assert
const sinon = require('sinon')
import config from '../../../config/index.js'
import axios from 'axios'
import { assert } from 'chai'
import sinon from 'sinon'
import { context as mockContext } from '../../unit/mocks/ctx-mock.js'
import ContactController from '../../../src/controllers/rest-api/contact/controller.js'
// Mock data
// const mockData = require('./mocks/contact-mocks')
const LOCALHOST = `http://localhost:${config.port}`
const mockContext = require('../../unit/mocks/ctx-mock').context
const ContactController = require('../../../src/controllers/rest-api/contact/controller')
let uut
let sandbox
+7 -9
View File
@@ -1,17 +1,15 @@
const config = require('../../../config')
const assert = require('chai').assert
import config from '../../../config/index.js'
import { assert } from 'chai'
import axios from 'axios'
import sinon from 'sinon'
import util from 'util'
const axios = require('axios').default
const sinon = require('sinon')
const util = require('util')
import LogsController from '../../../src/controllers/rest-api/logs/controller.js'
import { context as mockContext } from '../../unit/mocks/ctx-mock.js'
util.inspect.defaultOptions = { depth: 1 }
const LOCALHOST = `http://localhost:${config.port}`
const LogsController = require('../../../src/controllers/rest-api/logs/controller')
const mockContext = require('../../unit/mocks/ctx-mock').context
let sandbox
let uut
describe('LogsApi', () => {
@@ -1,12 +1,10 @@
const assert = require('chai').assert
const testUtils = require('../../utils/test-utils')
const Validators = require('../../../src/controllers/rest-api/middleware/validators')
const sinon = require('sinon')
const mockContext = require('../../unit/mocks/ctx-mock').context
const util = require('util')
/*
import { assert } from 'chai';
import testUtils from '../../utils/test-utils.js';
import Validators from '../../../src/controllers/rest-api/middleware/validators.js';
import sinon from 'sinon';
import { context as mockContext } from '../../unit/mocks/ctx-mock.js';
import util from 'util';
util.inspect.defaultOptions = { depth: 1 }
const context = {}
@@ -303,3 +301,4 @@ describe('Validators', () => {
})
})
})
*/
+4 -7
View File
@@ -1,10 +1,7 @@
const assert = require('chai').assert
const Admin = require('../../../src/adapters/admin')
const sinon = require('sinon')
const util = require('util')
import { assert } from 'chai'
import Admin from '../../../src/adapters/admin.js'
import sinon from 'sinon'
import util from 'util'
util.inspect.defaultOptions = { depth: 1 }
let sandbox
+12 -4
View File
@@ -5,10 +5,11 @@
// Public npm libraries
const BCHJS = require('@psf/bch-js')
const IpfsCoord = require('ipfs-coord')
const IPFS = require('ipfs')
const IPFS = require('ipfs-http-client')
const EventEmitter = require('events')
const { v4: uid } = require('uuid')
const jsonrpc = require('jsonrpc-lite')
const http = require('http')
let _this
@@ -88,8 +89,14 @@ class TestUtils {
async startIpfs () {
try {
const ipfsOptionsExternal = {
host: 'localhost',
port: 5001,
agent: http.Agent({ keepAlive: true, maxSockets: 2000 })
}
// Start the IPFS node.
this.ipfs = await IPFS.create()
this.ipfs = await IPFS.create(ipfsOptionsExternal)
await this.ipfs.config.profiles.apply('server')
// Start ipfs-coord.
@@ -101,7 +108,8 @@ class TestUtils {
privateLog: this.rpcHandler, // Default to console.log
isCircuitRelay: false,
apiInfo: 'none',
announceJsonLd: announceJsonLd
announceJsonLd,
nodeType: 'external'
})
await this.ipfsCoord.start()
@@ -214,7 +222,7 @@ class TestUtils {
const id = uid()
const cmd = jsonrpc.request(id, 'bch', {
endpoint: 'transactions',
addresses: ['bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj']
address: 'bitcoincash:qrl2nlsaayk6ekxn80pq0ks32dya8xfclyktem2mqj'
})
const cmdStr = JSON.stringify(cmd)
+2 -2
View File
@@ -1,4 +1,4 @@
{
"uutAddr": "/ip4/127.0.0.1/tcp/5701/p2p/QmWkjYRRTaxVEuGK8ip2X3trVyJShFs6U9g1h9x6fK5mZ2",
"uutId": "QmWkjYRRTaxVEuGK8ip2X3trVyJShFs6U9g1h9x6fK5mZ2"
"uutAddr": "/ip4/88.99.188.196/tcp/4001/p2p/12D3KooWT2tDg2pHwKz84Htzh2KsfSUZbZXmoAUFnaSwUVrDsag3/p2p-circuit/ipfs/12D3KooWNuZPDb15ENgk2CYF2dByq1oK6CQ5tUpRW9CpwwNynuJY",
"uutId": "12D3KooWNuZPDb15ENgk2CYF2dByq1oK6CQ5tUpRW9CpwwNynuJY"
}
@@ -0,0 +1,133 @@
/*
Integration tests for the endpoints in controllers/json-rpc/bch
*/
// Global npm libraries
const assert = require('chai').assert
// Local libraries
const BCHController = require('../../../../src/controllers/json-rpc/bch')
const Adapters = require('../../../../src/adapters')
const UseCases = require('../../../../src/use-cases')
describe('#BCH', () => {
let uut
before(async () => {
const adapters = new Adapters()
const useCases = new UseCases({ adapters })
// await adapters.start()
uut = new BCHController({ adapters, useCases })
})
describe('#utxoIsValid', () => {
it('should return true for valid UTXO with fullnode properties', async () => {
const rpcData = {
payload: {
params: {
utxo: {
txid: 'a2059b1321e96a90a386894a68fa5829756118895b3cdb9a0393d94fd2ceed93',
vout: 0
}
}
}
}
const result = await uut.utxoIsValid(rpcData)
// console.log('result: ', result)
assert.equal(result.isValid, true)
})
it('should return true for valid UTXO with fulcrum properties', async () => {
const rpcData = {
payload: {
params: {
utxo: {
tx_hash: 'a2059b1321e96a90a386894a68fa5829756118895b3cdb9a0393d94fd2ceed93',
tx_pos: 0
}
}
}
}
const result = await uut.utxoIsValid(rpcData)
// console.log('result: ', result)
assert.equal(result.isValid, true)
})
it('should return false for valid UTXO with fullnode properties', async () => {
const rpcData = {
payload: {
params: {
utxo: {
txid: '17754221b29f189532d4fc2ae89fb467ad2dede30fdec4854eb2129b3ba90d7a',
vout: 0
}
}
}
}
const result = await uut.utxoIsValid(rpcData)
// console.log('result: ', result)
assert.equal(result.isValid, false)
})
it('should return false for valid UTXO with fulcrum properties', async () => {
const rpcData = {
payload: {
params: {
utxo: {
tx_hash: '17754221b29f189532d4fc2ae89fb467ad2dede30fdec4854eb2129b3ba90d7a',
tx_pos: 0
}
}
}
}
const result = await uut.utxoIsValid(rpcData)
// console.log('result: ', result
assert.equal(result.isValid, false)
})
})
describe('#getTokenData', () => {
it('should return data for a token', async () => {
const rpcData = {
payload: {
params: {
tokenId: '5f31905f335fa932879c5aabfd1c14ac748f6696148bd300f845ea5016ad573e'
}
}
}
const result = await uut.getTokenData(rpcData)
console.log('result: ', result)
// assert.equal(result.isValid, true)
assert.property(result.tokenData, 'immutableData')
assert.property(result.tokenData, 'mutableData')
assert.equal(result.success, true)
})
it('should return data for a token with tx history', async () => {
const rpcData = {
payload: {
params: {
tokenId: '43eddfb11c9941edffb8c8815574bb0a43969a7b1de39ad14cd043eaa24fd38d',
withTxHistory: true
}
}
}
const result = await uut.getTokenData(rpcData)
// console.log('result: ', result)
assert.isArray(result.tokenData.genesisData.txs)
})
})
})
@@ -0,0 +1,130 @@
/*
Integration tests for the BCH Use Cases library
*/
// Global npm libraries
const assert = require('chai').assert
// Local libraries
const BCHUseCases = require('../../../../src/use-cases/bch')
const Adapters = require('../../../../src/adapters')
describe('#BCH', () => {
let uut
before(async () => {
const adapters = new Adapters()
// await adapters.start()
uut = new BCHUseCases({ adapters })
})
describe('#getTransactions', () => {
it('should get transactions for an address, with default descending sorting', async () => {
const rpcData = {
payload: {
params: {
address: 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v'
}
}
}
const result = await uut.getTransactions(rpcData)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(result.success, true)
assert.equal(result.status, 200)
assert.isArray(result.txs)
// Assert descending sort order.
assert.isAbove(result.txs[0].height, result.txs[1].height)
})
it('should get transactions for an address, with explicit descending sorting', async () => {
const rpcData = {
payload: {
params: {
address: 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v',
sortOrder: 'DESCENDING'
}
}
}
const result = await uut.getTransactions(rpcData)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(result.success, true)
assert.equal(result.status, 200)
assert.isArray(result.txs)
// Assert descending sort order.
assert.isAbove(result.txs[0].height, result.txs[1].height)
})
it('should sort in ascending order', async () => {
const rpcData = {
payload: {
params: {
address: 'bitcoincash:qpdh9s677ya8tnx7zdhfrn8qfyvy22wj4qa7nwqa5v',
sortOrder: 'ASCENDING'
}
}
}
const result = await uut.getTransactions(rpcData)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(result.success, true)
assert.equal(result.status, 200)
assert.isArray(result.txs)
// Assert descending sort order.
assert.isAbove(result.txs[1].height, result.txs[0].height)
})
})
describe('#getTxData', () => {
it('should get data for a single non-SLP tx', async () => {
const txids = [
'11384d7e5a8af93806591debe5bbe2d7826aeea987b874dfbe372dfdcc0ee54f'
]
const rpcData = {
payload: {
params: {
txids
}
}
}
const result = await uut.getTxData(rpcData)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(result.status, 200)
assert.isArray(result.txData)
assert.equal(result.txData.length, 1)
})
it('should get data on multiple non-SLP txs', async () => {
const txids = [
'11384d7e5a8af93806591debe5bbe2d7826aeea987b874dfbe372dfdcc0ee54f',
'f9b54fd8d27b0237923437ed4df8d45557f52b3ad4d8d03d4104e925c84ab4ca'
]
const rpcData = {
payload: {
params: {
txids
}
}
}
const result = await uut.getTxData(rpcData)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(result.status, 200)
assert.isArray(result.txData)
assert.equal(result.txData.length, 2)
})
})
})
+57
View File
@@ -0,0 +1,57 @@
/*
Unit tests for the adapters index.js library
*/
// Global npm libraries
import { assert } from 'chai'
import sinon from 'sinon'
// Local libraries
import Adapters from '../../../src/adapters/index.js'
describe('#adapters', () => {
let uut, sandbox
beforeEach(() => {
uut = new Adapters()
sandbox = sinon.createSandbox()
})
afterEach(() => {
sandbox.restore()
})
describe('#start', () => {
it('should start the async adapters', async () => {
// Mock dependencies
uut.config.getJwtAtStartup = true
uut.config.useIpfs = true
uut.config.env = 'not-a-test'
sandbox.stub(uut.fullStackJwt, 'getJWT').resolves()
sandbox.stub(uut.fullStackJwt, 'instanceBchjs').resolves()
sandbox.stub(uut.ipfs, 'start').resolves()
const result = await uut.start()
assert.equal(result, true)
})
it('should catch and throw an error', async () => {
try {
// Force an error
uut.config.getJwtAtStartup = false
uut.config.env = 'dev'
sandbox.stub(uut.ipfs, 'start').rejects(new Error('test error'))
await uut.start()
assert.fail('Unexpected result')
} catch (err) {
// console.log('err: ', err)
assert.include(err.message, 'test error')
}
})
})
})
+3 -4
View File
@@ -1,7 +1,6 @@
const assert = require('chai').assert
const sinon = require('sinon')
const ContactLib = require('../../../src/adapters/contact')
import { assert } from 'chai'
import sinon from 'sinon'
import ContactLib from '../../../src/adapters/contact.js'
let uut
let sandbox
@@ -3,10 +3,10 @@
*/
const assert = require('chai').assert
const sinon = require('sinon')
import { assert } from 'chai'
const FullStackJWT = require('../../../src/adapters/fullstack-jwt')
import sinon from 'sinon'
import FullStackJWT from '../../../src/adapters/fullstack-jwt.js'
describe('#FullStackJWT', () => {
let sandbox
+80 -20
View File
@@ -2,19 +2,20 @@
Unit tests for the IPFS Adapter.
*/
const assert = require('chai').assert
const sinon = require('sinon')
import { assert } from 'chai'
const IPFSCoordAdapter = require('../../../src/adapters/ipfs/ipfs-coord')
const IPFSMock = require('../mocks/ipfs-mock')
const IPFSCoordMock = require('../mocks/ipfs-coord-mock')
import sinon from 'sinon'
import IPFSCoordAdapter from '../../../src/adapters/ipfs/ipfs-coord.js'
import create from '../mocks/ipfs-mock.js'
import IPFSCoordMock from '../mocks/ipfs-coord-mock.js'
import config from '../../../config/index.js'
describe('#IPFS', () => {
let uut
let sandbox
beforeEach(() => {
const ipfs = IPFSMock.create()
const ipfs = create()
const bchjs = {}
uut = new IPFSCoordAdapter({ ipfs, bchjs })
@@ -39,7 +40,7 @@ describe('#IPFS', () => {
it('should throw an error if bchjs instance is not included', () => {
try {
const ipfs = IPFSMock.create()
const ipfs = create()
uut = new IPFSCoordAdapter({ ipfs })
assert.fail('Unexpected code path')
@@ -62,6 +63,45 @@ describe('#IPFS', () => {
assert.equal(result, true)
})
it('should get the public IP address if this node is a Circuit Relay', async () => {
// Mock dependencies.
uut.IpfsCoord = IPFSCoordMock
sandbox.stub(uut, 'publicIp').resolves('123')
// Force Circuit Relay
uut.config.isCircuitRelay = true
const result = await uut.start()
// console.log('result: ', result)
assert.equal(result, true)
})
it('should exit quietly if this node is a Circuit Relay and there is an issue getting the IP address', async () => {
// Mock dependencies.
uut.IpfsCoord = IPFSCoordMock
sandbox.stub(uut, 'publicIp').rejects(new Error('test error'))
// Force Circuit Relay
uut.config.isCircuitRelay = true
const result = await uut.start()
// console.log('result: ', result)
assert.equal(result, true)
})
it('should return a promise that resolves into an instance of IPFS in production mode', async () => {
uut.config.isProduction = true
// Mock dependencies.
uut.IpfsCoord = IPFSCoordMock
const result = await uut.start()
// console.log('result: ', result)
assert.equal(result, true)
config.isProduction = false
})
})
describe('#attachRPCRouter', () => {
@@ -75,8 +115,9 @@ describe('#IPFS', () => {
}
},
adapters: {
orbit: {
privateLog: () => {}
pubsub: {
privateLog: () => {
}
}
}
}
@@ -86,16 +127,35 @@ describe('#IPFS', () => {
uut.attachRPCRouter(router)
})
// it('should throw an error if ipfs-coord has not been instantiated', () => {
// try {
// const router = console.log
//
// uut.attachRPCRouter(router)
//
// assert.fail('Unexpected code path')
// } catch (err) {
// assert.include(err.message, 'Cannot read property')
// }
// })
it('should catch and throw an error', () => {
try {
// Force an error
delete uut.ipfsCoord.adapters
const router = console.log
uut.attachRPCRouter(router)
assert.fail('Unexpected code path')
} catch (err) {
assert.include(err.message, 'Cannot read')
}
})
})
describe('#subscribeToChat', () => {
it('should subscribe to the chat channel', async () => {
// Mock dependencies
uut.ipfsCoord = {
adapters: {
pubsub: {
subscribeToPubsubChannel: async () => {
}
}
}
}
await uut.subscribeToChat()
})
})
})
+181 -7
View File
@@ -2,19 +2,22 @@
Unit tests for the index.js file for the IPFS and ipfs-coord libraries.
*/
const assert = require('chai').assert
const sinon = require('sinon')
import { assert } from 'chai'
import BCHJS from '@psf/bch-js'
const IPFSLib = require('../../../src/adapters/ipfs')
const IPFSMock = require('../mocks/ipfs-mock')
const IPFSCoordMock = require('../mocks/ipfs-coord-mock')
import sinon from 'sinon'
import IPFSLib from '../../../src/adapters/ipfs/index.js'
// import create from '../mocks/ipfs-mock.js'
import IPFSCoordMock from '../mocks/ipfs-coord-mock.js'
describe('#IPFS-adapter-index', () => {
let uut
let sandbox
let bchjs
beforeEach(() => {
uut = new IPFSLib()
bchjs = new BCHJS()
uut = new IPFSLib({ bchjs })
sandbox = sinon.createSandbox()
})
@@ -38,7 +41,9 @@ describe('#IPFS-adapter-index', () => {
it('should return a promise that resolves into an instance of IPFS.', async () => {
// Mock dependencies.
uut.ipfsAdapter = new IPFSMock()
uut.ipfsAdapter = {
start: async () => {}
}
uut.IpfsCoordAdapter = IPFSCoordMock
const result = await uut.start({ bchjs: {} })
@@ -59,5 +64,174 @@ describe('#IPFS-adapter-index', () => {
assert.include(err.message, 'test error')
}
})
it('should handle lock-file errors', async () => {
try {
// Force an error
sandbox
.stub(uut.ipfsAdapter, 'start')
.rejects(new Error('Lock already being held'))
// Prevent process from exiting
sandbox.stub(uut.process, 'exit').returns()
await uut.start({ bchjs })
assert.fail('Unexpected code path.')
} catch (err) {
assert.include(err.message, 'Lock already being held')
}
})
})
describe('#getStatus', () => {
it('should return an object with node metrics', () => {
// Force uut to have the needed properties
uut.ipfsCoordAdapter = {
ipfsCoord: {
thisNode: {
ipfsId: 'fake-id',
ipfsMultiaddrs: [],
bchAddr: 'fake-bch-addr',
slpAddr: 'fake-slp-addr',
pubKey: 'fake-pubkey',
peerList: [],
relayData: []
}
}
}
const result = uut.getStatus()
// console.log('result: ', result)
assert.property(result, 'ipfsId')
assert.property(result, 'multiAddrs')
assert.property(result, 'bchAddr')
assert.property(result, 'slpAddr')
assert.property(result, 'pubKey')
assert.property(result, 'peers')
assert.property(result, 'relays')
})
it('should catch, report, and throw errors', () => {
try {
uut.getStatus()
assert.fail('Unexpected code path')
} catch (err) {
// console.log('err.message: ', err.message)
assert.include(err.message, 'Cannot read properties')
}
})
})
describe('#_removeDuplicatePeers', () => {
it('should return the same array when there are no duplicates', () => {
const inArray = [
'12D3KooWPpBXhhAeoCZCGuQ3KR4xwHzzvtP57f6zLmo8P7ZFBJFE',
'12D3KooWRBhwfeP2Y9CDkFRBAZ1pmxUadH36TKuk3KtKm5XXP8mA',
'12D3KooWGsgHWyDLKuV4ZSfRJfsxQJj77rxx3i8Px3qXKHsLN7a2',
'12D3KooWJyc54njjeZGbLew4D8u1ghrmZTTPyh3QpBF7dxtd3zGY',
'12D3KooWDtj9cfj1SKuLbDNKvKRKSsGN8qivq9M8CYpLPDpcD5pu'
]
const result = uut._removeDuplicatePeers(inArray)
// console.log('result: ', result)
assert.equal(result.length, inArray.length)
})
it('should remove duplicates from an array', () => {
const inArray = [
'12D3KooWPpBXhhAeoCZCGuQ3KR4xwHzzvtP57f6zLmo8P7ZFBJFE',
'12D3KooWRBhwfeP2Y9CDkFRBAZ1pmxUadH36TKuk3KtKm5XXP8mA',
'12D3KooWGsgHWyDLKuV4ZSfRJfsxQJj77rxx3i8Px3qXKHsLN7a2',
'12D3KooWJyc54njjeZGbLew4D8u1ghrmZTTPyh3QpBF7dxtd3zGY',
'12D3KooWDtj9cfj1SKuLbDNKvKRKSsGN8qivq9M8CYpLPDpcD5pu',
'12D3KooWPpBXhhAeoCZCGuQ3KR4xwHzzvtP57f6zLmo8P7ZFBJFE',
'12D3KooWRBhwfeP2Y9CDkFRBAZ1pmxUadH36TKuk3KtKm5XXP8mA'
]
const result = uut._removeDuplicatePeers(inArray)
// console.log('result: ', result)
assert.equal(result.length, inArray.length - 2)
})
})
describe('#getPeers', () => {
it('should return an array of current JSON data about each peer when showAll is true', async () => {
// Mock dependencies
uut.ipfsCoordAdapter.ipfsCoord = {
thisNode: {
peerData: [{ from: 'a', data: { jsonLd: { name: 'a', protocol: 'test', version: '1' } } }, { from: 'b' }]
},
adapters: {
ipfs: {
getPeers: async () => ['a', 'b']
}
}
}
const result = await uut.getPeers(true)
assert.isArray(result)
})
it('should catch, report, and throw errors', async () => {
try {
// Force an error
uut.ipfsCoordAdapter.ipfsCoord = {
thisNode: {},
adapters: {
ipfs: {
getPeers: async () => { throw new Error('test error') }
}
}
}
await uut.getPeers()
assert.fail('Unexpected code path')
} catch (err) {
// console.log('err.message: ', err.message)
assert.include(err.message, 'test error')
}
})
})
describe('#getRelays', () => {
it('should return known relays', () => {
uut.ipfsCoordAdapter.ipfsCoord = {
thisNode: {
peerData: [{ from: 'a', data: { jsonLd: { name: 'a', description: 'test' } } }, { from: 'b' }],
relayData: [{ ipfsId: 'c' }, { ipfsId: 'a' }]
}
}
const result = uut.getRelays()
// console.log('result: ', result)
assert.isArray(result.v2Relays)
assert.equal(result.v2Relays.length, 2)
assert.property(result.v2Relays[0], 'name')
assert.property(result.v2Relays[0], 'description')
assert.property(result.v2Relays[1], 'name')
assert.property(result.v2Relays[1], 'description')
})
it('should catch, report, and throw errors', () => {
try {
// Force an error
uut.ipfsCoordAdapter.ipfsCoord = { thisNode: {} }
uut.getRelays()
assert.fail('Unexpected code path')
} catch (err) {
// console.log('err.message: ', err.message)
assert.include(err.message, 'Cannot read')
}
})
})
})
+201 -9
View File
@@ -2,44 +2,79 @@
Unit tests for the IPFS Adapter.
*/
const assert = require('chai').assert
const sinon = require('sinon')
// Global npm libraries
import { assert } from 'chai'
import sinon from 'sinon'
import cloneDeep from 'lodash.clonedeep'
import { peerIdFromString } from '@libp2p/peer-id'
const IPFSLib = require('../../../src/adapters/ipfs/ipfs')
const IPFSMock = require('../mocks/ipfs-mock')
// Local libraries
import IPFSLib from '../../../src/adapters/ipfs/ipfs.js'
// import create from '../mocks/ipfs-mock.js'
import config from '../../../config/index.js'
import createHeliaLib from '../mocks/helia-mock.js'
// config.isProduction = true;
describe('#IPFS-adapter', () => {
let uut
let sandbox
let ipfs
beforeEach(() => {
uut = new IPFSLib()
ipfs = cloneDeep(createHeliaLib)
sandbox = sinon.createSandbox()
})
afterEach(() => sandbox.restore())
afterEach(() => {
sandbox.restore()
})
describe('#constructor', () => {
it('should instantiate IPFS Lib in dev mode.', async () => {
const _uut = new IPFSLib()
assert.exists(_uut)
assert.isFunction(_uut.start)
assert.isFunction(_uut.stop)
})
it('should instantiate dev IPFS Lib in production mode.', async () => {
config.isProduction = true
const _uut = new IPFSLib()
assert.exists(_uut)
assert.isFunction(_uut.start)
assert.isFunction(_uut.stop)
config.isProduction = false
})
})
describe('#start', () => {
it('should return a promise that resolves into an instance of IPFS.', async () => {
// Mock dependencies.
uut.IPFS = IPFSMock
sandbox.stub(uut, 'createNode').resolves(ipfs)
sandbox.stub(uut, 'publicIp').resolves('192.168.2.4')
sandbox.stub(uut, 'multiaddr').returns('/ip4/fake-multiaddr')
const result = await uut.start()
// console.log('result: ', result)
// Assert properties of the instance are set.
assert.equal(uut.isReady, true)
assert.property(uut, 'multiaddrs')
assert.property(uut, 'id')
assert.property(result, 'config')
// Output should be an instance of IPFS
assert.property(result, 'libp2p')
})
it('should catch and throw an error', async () => {
try {
// Force an error
sandbox.stub(uut.IPFS, 'create').rejects(new Error('test error'))
sandbox.stub(uut, 'createNode').rejects(new Error('test error'))
await uut.start()
assert.fail('Unexpected code path.')
} catch (err) {
// console.log(err)
@@ -47,4 +82,161 @@ describe('#IPFS-adapter', () => {
}
})
})
describe('#stop', () => {
it('should stop the IPFS node', async () => {
// Mock dependencies
uut.ipfs = {
stop: () => {
}
}
const result = await uut.stop()
assert.equal(result, true)
})
})
describe('#ensureBlocksDir', () => {
it('should create directory if it does not exist', () => {
// Force desired code path
sandbox.stub(uut.fs, 'existsSync').returns(false)
sandbox.stub(uut.fs, 'mkdirSync').returns(true)
const result = uut.ensureBlocksDir()
assert.equal(result, true)
})
it('should report and throw errors', () => {
// Force an error
sandbox.stub(uut.fs, 'existsSync').throws(new Error('test error'))
try {
uut.ensureBlocksDir()
assert.fail('Unexpected code path')
} catch (err) {
assert.include(err.message, 'test error')
}
})
})
describe('#createNode', () => {
it('should report and throw errors', async () => {
// Force an error
sandbox.stub(uut, 'createLibp2p').rejects(new Error('test error'))
try {
await uut.createNode()
assert.fail('Unexpected code path')
} catch (err) {
assert.include(err.message, 'test error')
}
})
it('should create an IPFS node from Helia', async () => {
uut.config.isCircuitRelay = false
const result = await uut.createNode()
// console.log('result: ', result)
// Assert the returned IPFS node has expected properties
assert.property(result, 'libp2p')
assert.property(result, 'blockstore')
// Stop the IPFS node
await result.stop()
})
it('should create a Circuit Relay if configured', async () => {
uut.config.isCircuitRelay = true
const result = await uut.createNode()
// Assert the returned IPFS node has expected properties
assert.property(result, 'libp2p')
assert.property(result, 'blockstore')
// Stop the IPFS node
await result.stop()
})
it('should create a new private key on first run', async () => {
uut.config.isCircuitRelay = false
// Mock dependencies and force desired code path.
let beenCalled = false
sandbox.stub(uut, 'getKeychain').resolves({
exportPeerId: async () => {
if (!beenCalled) {
beenCalled = true
throw new Error('test error')
}
return peerIdFromString('12D3KooWSXF1PnEfiA8bCG8SJduCvzdwHtvhVPK4WC6zzDoto2XP')
},
createKey: async () => {}
})
sandbox.stub(uut, 'createLibp2p').resolves()
sandbox.stub(uut, 'createHelia').resolves({})
const result = await uut.createNode()
// console.log('result: ', result)
assert.property(result, 'fs')
})
it('should not use circuit relay when CONNECT_PREF is set to direct', async () => {
process.env.CONNECT_PREF = 'direct'
uut.config.isCircuitRelay = false
const result = await uut.createNode()
// console.log('result: ', result)
delete process.env.CONNECT_PREF
// Assert the returned IPFS node has expected properties
assert.property(result, 'libp2p')
assert.property(result, 'blockstore')
// Stop the IPFS node
await result.stop()
})
})
describe('#getSeed', () => {
it('should read the seed from the JSON file', async () => {
// Mock dependencies and force desired code path
sandbox.stub(uut.jsonFiles, 'readJSON').resolves('12345678')
const result = await uut.getSeed()
// console.log('result: ', result)
assert.isString(result)
})
it('should generate a new seed if the JSON file is not found', async () => {
// Mock dependencies and force desired code path
sandbox.stub(uut.jsonFiles, 'readJSON').rejects(new Error('test error'))
sandbox.stub(uut.jsonFiles, 'writeJSON').resolves()
const result = await uut.getSeed()
// console.log('result: ', result)
assert.isString(result)
})
it('should catch, report, and throw errors', async () => {
try {
// Force an error
sandbox.stub(uut.jsonFiles, 'readJSON').rejects(new Error('test error'))
sandbox.stub(uut.jsonFiles, 'writeJSON').rejects(new Error('test error'))
await uut.getSeed()
assert.fail('Unexpected code path')
} catch (err) {
assert.include(err.message, 'test error')
}
})
})
})
+10 -6
View File
@@ -1,11 +1,15 @@
const assert = require('chai').assert
const fs = require('fs')
const sinon = require('sinon')
import { assert } from 'chai'
import fs from 'fs'
import sinon from 'sinon'
import util from 'util'
const util = require('util')
import JsonFiles from '../../../src/adapters/json-files.js'
// Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
import * as url from 'url'
util.inspect.defaultOptions = { depth: 1 }
const JsonFiles = require('../../../src/adapters/json-files')
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const JSON_FILE = 'test-json-file.json'
const JSON_PATH = `${__dirname.toString()}/${JSON_FILE}`
+34 -38
View File
@@ -1,12 +1,15 @@
const assert = require('chai').assert
import { assert } from 'chai'
import sinon from 'sinon'
import util from 'util'
const sinon = require('sinon')
import LogsApiLib from '../../../src/adapters/logapi.js'
import mockData from '../mocks/log-api-mock.js'
const util = require('util')
// Hack to get __dirname back.
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
import * as url from 'url'
util.inspect.defaultOptions = { depth: 1 }
const LogsApiLib = require('../../../src/adapters/logapi')
const mockData = require('../mocks/log-api-mock')
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const context = {}
let sandbox
@@ -32,19 +35,18 @@ describe('#LogsApiLib', () => {
})
it('should return log', async () => {
try {
const pass = 'test'
const result = await uut.getLogs(pass)
// console.log('result', result)
// Mock dependencies
sandbox.stub(uut, 'generateFileName').returns(`${__dirname.toString()}/../mocks/adapters/fake-log`)
assert.isTrue(result.success)
assert.isArray(result.data)
assert.property(result.data[0], 'message')
assert.property(result.data[0], 'level')
assert.property(result.data[0], 'timestamp')
} catch (err) {
assert(false, 'Unexpected result')
}
const pass = 'test'
const result = await uut.getLogs(pass)
// console.log('result', result)
assert.isTrue(result.success)
assert.isArray(result.data)
assert.property(result.data[0], 'message')
assert.property(result.data[0], 'level')
assert.property(result.data[0], 'timestamp')
})
it('should return false if files are not found!', async () => {
@@ -201,31 +203,25 @@ describe('#LogsApiLib', () => {
})
it('should ignore fileReader callback errors', async () => {
try {
// https://sinonjs.org/releases/latest/stubs/
// About yields
sandbox.stub(uut.lineReader, 'eachLine').yieldsRight({}, true)
// https://sinonjs.org/releases/latest/stubs/
// About yields
sandbox.stub(uut.lineReader, 'eachLine').yieldsRight({}, true)
const fileName = context.fileName
const result = await uut.readLines(fileName)
assert.isArray(result)
} catch (err) {
assert.fail('Unexpected result')
}
const fileName = `${__dirname.toString()}/../mocks/adapters/fake-log`
const result = await uut.readLines(fileName)
assert.isArray(result)
})
it('should return data', async () => {
try {
const fileName = context.fileName
const result = await uut.readLines(fileName)
const fileName = `${__dirname.toString()}/../mocks/adapters/fake-log`
assert.isArray(result)
assert.property(result[1], 'message')
assert.property(result[1], 'level')
assert.property(result[1], 'timestamp')
} catch (err) {
assert.fail('Unexpected result')
}
const result = await uut.readLines(fileName)
assert.isArray(result)
assert.property(result[1], 'message')
assert.property(result[1], 'level')
assert.property(result[1], 'timestamp')
})
})
})
@@ -3,10 +3,10 @@
*/
// Public npm libraries
const assert = require('chai').assert
const sinon = require('sinon')
import { assert } from 'chai'
const NodeMailer = require('../../../src/adapters/nodemailer')
import sinon from 'sinon'
import NodeMailer from '../../../src/adapters/nodemailer.js'
let sandbox
let uut
+3 -4
View File
@@ -1,7 +1,6 @@
const assert = require('chai').assert
const PassportLib = require('../../../src/adapters/passport')
const sinon = require('sinon')
import { assert } from 'chai'
import PassportLib from '../../../src/adapters/passport.js'
import sinon from 'sinon'
let uut
let sandbox
+7 -6
View File
@@ -2,16 +2,17 @@
Unit tests for the users Mongoose model.
*/
const assert = require('chai').assert
const sinon = require('sinon')
const mongoose = require('mongoose')
import { assert } from 'chai'
import sinon from 'sinon'
import mongoose from 'mongoose'
import User from '../../../src/adapters/localdb/models/users.js'
import config from '../../../config/index.js'
// Set the environment variable to signal this is a test.
process.env.SVC_ENV = 'test'
const User = require('../../../src/adapters/localdb/models/users')
const config = require('../../../config')
describe('#User-Adapter', () => {
// let uut
let sandbox
+3 -4
View File
@@ -1,7 +1,6 @@
const assert = require('chai').assert
const { Wlogger } = require('../../../src/adapters/wlogger')
const sinon = require('sinon')
import { assert } from 'chai'
import { Wlogger } from '../../../src/adapters/wlogger.js'
import sinon from 'sinon'
let uut
let sandbox
+7 -6
View File
@@ -3,10 +3,10 @@
*/
// Public npm libraries
const assert = require('chai').assert
const sinon = require('sinon')
import sinon from 'sinon'
import { assert } from 'chai'
const Controllers = require('../../../src/controllers')
import Controllers from '../../../src/controllers/index.js'
describe('#Controllers', () => {
let uut
@@ -33,6 +33,9 @@ describe('#Controllers', () => {
attachRPCRouter: () => {}
}
// Mock the timer controllers
sandbox.stub(uut.timerControllers, 'startTimers').returns()
const app = {
use: () => {}
}
@@ -45,9 +48,7 @@ describe('#Controllers', () => {
it('should catch and throw errors', async () => {
try {
// Force an error
sandbox
.stub(uut.adapters.fullStackJwt, 'getJWT')
.rejects(new Error('test error'))
sandbox.stub(uut, 'attachRPCControllers').throws(new Error('test error'))
const app = {
use: () => {}
@@ -5,18 +5,20 @@
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
const sinon = require('sinon')
const assert = require('chai').assert
const { v4: uid } = require('uuid')
import jsonrpc from 'jsonrpc-lite'
import sinon from 'sinon'
import { assert } from 'chai'
import { v4 as uid } from 'uuid'
// Local libraries
import Validators from '../../../../src/controllers/json-rpc/validators.js'
import adapters from '../../mocks/adapters/index.js'
// Set the environment variable to signal this is a test.
process.env.SVC_ENV = 'test'
// Local libraries
const Validators = require('../../../../src/controllers/json-rpc/validators')
const adapters = require('../../mocks/adapters')
describe('#validators', () => {
let uut
let sandbox
@@ -5,15 +5,16 @@
*/
// Public npm libraries
const sinon = require('sinon')
const assert = require('chai').assert
import sinon from 'sinon'
import { assert } from 'chai'
// Local libraries
import RateLimit from '../../../../src/controllers/json-rpc/rate-limit.js'
// Set the environment variable to signal this is a test.
process.env.SVC_ENV = 'test'
// Local libraries
const RateLimit = require('../../../../src/controllers/json-rpc/rate-limit')
describe('#rate-limit', () => {
let uut
let sandbox
@@ -3,11 +3,12 @@
*/
// Public npm libraries
const sinon = require('sinon')
const assert = require('chai').assert
import sinon from 'sinon'
import { assert } from 'chai'
// Local libraries
const AboutRPC = require('../../../../src/controllers/json-rpc/about')
import AboutRPC from '../../../../src/controllers/json-rpc/about/index.js'
describe('#AboutRPC', () => {
let uut
@@ -3,20 +3,22 @@
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
const sinon = require('sinon')
const assert = require('chai').assert
const { v4: uid } = require('uuid')
import jsonrpc from 'jsonrpc-lite'
import sinon from 'sinon'
import { assert } from 'chai'
import { v4 as uid } from 'uuid'
// Local libraries
import AuthRPC from '../../../../src/controllers/json-rpc/auth/index.js'
import RateLimit from '../../../../src/controllers/json-rpc/rate-limit.js'
import adapters from '../../mocks/adapters/index.js'
import UseCasesMock from '../../mocks/use-cases/index.js'
// Set the environment variable to signal this is a test.
process.env.SVC_ENV = 'test'
// Local libraries
const AuthRPC = require('../../../../src/controllers/json-rpc/auth')
const RateLimit = require('../../../../src/controllers/json-rpc/rate-limit')
const adapters = require('../../mocks/adapters')
const UseCasesMock = require('../../mocks/use-cases')
describe('#AuthRPC', () => {
let uut
let sandbox
@@ -3,20 +3,21 @@
*/
// Public npm libraries
const jsonrpc = require('jsonrpc-lite')
const sinon = require('sinon')
const assert = require('chai').assert
const { v4: uid } = require('uuid')
import jsonrpc from 'jsonrpc-lite'
import sinon from 'sinon'
import { assert } from 'chai'
// const { v4: uid } = require('uuid')
import { v4 as uid } from 'uuid'
// Local libraries
import BCHRPC from '../../../../src/controllers/json-rpc/bch/index.js'
import RateLimit from '../../../../src/controllers/json-rpc/rate-limit.js'
import adapters from '../../mocks/adapters/index.js'
import UseCasesMock from '../../mocks/use-cases/index.js'
// Set the environment variable to signal this is a test.
process.env.SVC_ENV = 'test'
// Local libraries
const BCHRPC = require('../../../../src/controllers/json-rpc/bch')
const RateLimit = require('../../../../src/controllers/json-rpc/rate-limit')
const adapters = require('../../mocks/adapters')
const UseCasesMock = require('../../mocks/use-cases')
describe('#BCHRPC', () => {
let uut
let sandbox
@@ -61,15 +62,15 @@ describe('#BCHRPC', () => {
})
describe('#bchRouter', () => {
it('should route to the transactions method', async () => {
it('should route to the txHistory method', async () => {
// Mock dependencies
sandbox.stub(uut, 'transactions').resolves(true)
sandbox.stub(uut, 'txHistory').resolves(true)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const txCall = jsonrpc.request(id, 'bch', {
endpoint: 'transactions'
endpoint: 'txHistory'
})
const jsonStr = JSON.stringify(txCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
@@ -118,6 +119,25 @@ describe('#BCHRPC', () => {
assert.equal(result, true)
})
it('should route to the utxosBulk method', async () => {
// Mock dependencies
sandbox.stub(uut, 'utxosBulk').resolves(true)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const txCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxosBulk'
})
const jsonStr = JSON.stringify(txCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
rpcData.from = 'Origin request'
const result = await uut.bchRouter(rpcData)
assert.equal(result, true)
})
it('should route to the broadcast method', async () => {
// Mock dependencies
sandbox.stub(uut, 'broadcast').resolves(true)
@@ -137,15 +157,91 @@ describe('#BCHRPC', () => {
assert.equal(result, true)
})
it('should route to the transaction method', async () => {
it('should route to the txData method', async () => {
// Mock dependencies
sandbox.stub(uut, 'transaction').resolves(true)
sandbox.stub(uut, 'txData').resolves(true)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'transaction'
endpoint: 'txData'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
rpcData.from = 'Origin request'
const result = await uut.bchRouter(rpcData)
assert.equal(result, true)
})
it('should route to the pubkey method', async () => {
// Mock dependencies
sandbox.stub(uut, 'pubKey').resolves(true)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'pubkey'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
rpcData.from = 'Origin request'
const result = await uut.bchRouter(rpcData)
assert.equal(result, true)
})
it('should route to the utxoIsValid method', async () => {
// Mock dependencies
sandbox.stub(uut, 'utxoIsValid').resolves(true)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxoIsValid'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
rpcData.from = 'Origin request'
const result = await uut.bchRouter(rpcData)
assert.equal(result, true)
})
it('should route to the getTokenData method', async () => {
// Mock dependencies
sandbox.stub(uut, 'getTokenData').resolves(true)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'getTokenData'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
rpcData.from = 'Origin request'
const result = await uut.bchRouter(rpcData)
assert.equal(result, true)
})
it('should route to the getTokenData2 method', async () => {
// Mock dependencies
sandbox.stub(uut, 'getTokenData2').resolves(true)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'getTokenData2'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
@@ -158,13 +254,13 @@ describe('#BCHRPC', () => {
it('should return 500 status on routing issue', async () => {
// Mock dependencies
sandbox.stub(uut, 'transactions').rejects(new Error('test error'))
sandbox.stub(uut, 'txHistory').rejects(new Error('test error'))
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const txCall = jsonrpc.request(id, 'bch', {
endpoint: 'transactions'
endpoint: 'txHistory'
})
const jsonStr = JSON.stringify(txCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
@@ -175,29 +271,24 @@ describe('#BCHRPC', () => {
assert.equal(result.success, false)
assert.equal(result.status, 500)
assert.equal(result.message, 'test error')
assert.equal(result.endpoint, 'transactions')
assert.equal(result.endpoint, 'txHistory')
})
})
describe('#transactions', () => {
describe('#txHistory', () => {
it('should return data from bchjs', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.Electrumx, 'transactions')
.resolves({ success: true })
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const txCall = jsonrpc.request(id, 'bch', {
endpoint: 'transactions',
endpoint: 'txHistory',
addresses: 'testAddr'
})
const jsonStr = JSON.stringify(txCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.transactions(rpcData)
// console.log('response: ', response)
const response = await uut.txHistory(rpcData)
console.log('response: ', response)
assert.equal(response.success, true)
assert.equal(response.status, 200)
@@ -206,26 +297,26 @@ describe('#BCHRPC', () => {
it('should return an error for invalid address', async () => {
// Force an error
sandbox
.stub(uut.bchjs.Electrumx, 'transactions')
.stub(uut.useCases.bch, 'getTransactions')
.rejects(new Error('Invalid address'))
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const txCall = jsonrpc.request(id, 'bch', {
endpoint: 'transactions',
endpoint: 'txHistory',
addresses: 'testAddr'
})
const jsonStr = JSON.stringify(txCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.transactions(rpcData)
const response = await uut.txHistory(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'Invalid address')
assert.equal(response.endpoint, 'transactions')
assert.equal(response.endpoint, 'txHistory')
})
})
@@ -287,7 +378,7 @@ describe('#BCHRPC', () => {
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxos',
addresses: 'testAddr'
address: 'testAddr'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
@@ -308,7 +399,7 @@ describe('#BCHRPC', () => {
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxos',
addresses: 'testAddr'
address: 'testAddr'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
@@ -323,6 +414,98 @@ describe('#BCHRPC', () => {
})
})
describe('#utxosBulk', () => {
it('should return UTXO data from bchjs for multiple addresses', async () => {
// Mock dependencies
sandbox.stub(uut.bchjs.Utxo, 'get').resolves({ success: true })
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxosBulk',
addresses: ['testAddr1', 'testAddr2']
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.utxosBulk(rpcData)
// console.log('response: ', response)
assert.equal(response.success, true)
assert.equal(response.status, 200)
})
it('should return an error for invalid address', async () => {
// Force an error
sandbox.stub(uut.bchjs.Utxo, 'get').rejects(new Error('Invalid address'))
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxosBulk',
addresses: ['testAddr1', 'testAddr2']
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.utxosBulk(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'Invalid address')
assert.equal(response.endpoint, 'utxosBulk')
})
it('should throw error if input is not an array', async () => {
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxosBulk',
addresses: 'singleAddress'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.utxosBulk(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'addresses parameter must be an array')
assert.equal(response.endpoint, 'utxosBulk')
})
it('should throw error if input array is larger than 20 elements', async () => {
// Generate an array larger than 20 elements
const inputArray = []
for (let i = 0; i < 25; i++) {
inputArray.push(i)
}
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'utxosBulk',
addresses: inputArray
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.utxosBulk(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'addresses parameter must not exceed 20 elements')
assert.equal(response.endpoint, 'utxosBulk')
})
})
describe('#broadcast', () => {
it('should return data from bchjs', async () => {
// Mock dependencies
@@ -371,24 +554,47 @@ describe('#BCHRPC', () => {
assert.equal(response.message, 'Invalid data')
assert.equal(response.endpoint, 'broadcast')
})
})
describe('#transaction', () => {
it('should return data from bchjs', async () => {
// Mock dependencies
sandbox.stub(uut.bchjs.Transaction, 'get').resolves({ success: true })
it('should return an error if full node returns a string error', async () => {
// Force an error
sandbox
.stub(uut.bchjs.RawTransactions, 'sendRawTransaction')
// .rejects(new Error('Invalid data'))
.rejects({ error: 'Invalid data' })
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'transaction',
endpoint: 'broadcast',
hex: 'testHex'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.broadcast(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'Invalid data')
assert.equal(response.endpoint, 'broadcast')
})
})
describe('#txData', () => {
it('should route data to the use-case library', async () => {
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'txData',
txid: 'testData'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.transaction(rpcData)
const response = await uut.txData(rpcData)
// console.log('response: ', response)
assert.equal(response.success, true)
@@ -398,26 +604,284 @@ describe('#BCHRPC', () => {
it('should return an error for invalid input', async () => {
// Force an error
sandbox
.stub(uut.bchjs.Transaction, 'get')
.stub(uut.useCases.bch, 'getTxData')
.rejects(new Error('Invalid data'))
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'transaction',
endpoint: 'txData',
txid: 'testTxid'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.transaction(rpcData)
const response = await uut.txData(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'Invalid data')
assert.equal(response.endpoint, 'transaction')
assert.equal(response.endpoint, 'txData')
})
})
describe('#pubKey', () => {
it('should return data from bchjs', async () => {
// Mock dependencies
const mock = {
success: true,
publicKey:
'033f267fec0f7eb2b27f8c2e3052b3d03b09d36b47de4082ffb638ffb334ef0eee'
}
sandbox.stub(uut.bchjs.encryption, 'getPubKey').resolves(mock)
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'pubkey',
address: 'bitcoincash:qpnty9t0w93fez04h7yzevujpv8pun204qv6yfuahk'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.pubKey(rpcData)
assert.equal(response.success, true)
assert.equal(response.status, 200)
assert.property(response, 'pubkey')
const pubKey = response.pubkey
assert.property(pubKey, 'publicKey')
assert.equal(pubKey.publicKey, mock.publicKey)
})
it('should throw an error if public key is not found', async () => {
// Force an error
sandbox
.stub(uut.bchjs.encryption, 'getPubKey')
.rejects({ success: false, error: 'No transaction history.' })
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'pubkey',
address: 'bitcoincash:qrnx7l2e6yejgswehf54gs30ljzumnhqdqgn8yscr2'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.pubKey(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'No transaction history.')
assert.equal(response.endpoint, 'pubkey')
})
it('should return an error for invalid input', async () => {
// Force an error
sandbox
.stub(uut.bchjs.encryption, 'getPubKey')
.rejects(new Error('Invalid data'))
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const rpcCall = jsonrpc.request(id, 'bch', {
endpoint: 'pubkey',
address: 'bitcoincash'
})
const jsonStr = JSON.stringify(rpcCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const response = await uut.pubKey(rpcData)
// console.log('response: ', response)
assert.equal(response.success, false)
assert.equal(response.status, 422)
assert.equal(response.message, 'Invalid data')
assert.equal(response.endpoint, 'pubkey')
})
})
describe('#utxoIsValid', () => {
it('should return false if UTXO.isValid() returns false', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.Utxo, 'isValid')
.resolves(false)
const rpcData = {
payload: {
params: {
utxo: {
txid: 'b94e1ff82eb5781f98296f0af2488ff06202f12ee92b0175963b8dba688d1b40',
vout: 0
}
}
}
}
const result = await uut.utxoIsValid(rpcData)
// console.log('result: ', result)
assert.equal(result.isValid, false)
assert.equal(result.success, true)
})
it('should return true if UTXO.isValid() returns true', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.Utxo, 'isValid')
.resolves(true)
const rpcData = {
payload: {
params: {
utxo: {
txid: 'b94e1ff82eb5781f98296f0af2488ff06202f12ee92b0175963b8dba688d1b40',
vout: 0
}
}
}
}
const result = await uut.utxoIsValid(rpcData)
// console.log('result: ', result)
assert.equal(result.isValid, true)
assert.equal(result.success, true)
})
it('should catch and return errors', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.Utxo, 'isValid')
// .rejects(new Error('test error'))
.rejects({ error: 'test error' })
const rpcData = {
payload: {
params: {
utxo: {
txid: 'b94e1ff82eb5781f98296f0af2488ff06202f12ee92b0175963b8dba688d1b40',
vout: 0
}
}
}
}
const result = await uut.utxoIsValid(rpcData)
// console.log('result: ', result)
assert.equal(result.success, false)
assert.equal(result.status, 422)
assert.equal(result.message, 'test error')
assert.equal(result.endpoint, 'utxoIsValid')
})
})
describe('#getTokenData', () => {
it('should return data from PsfSlpIndexer.getTokenData()', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.PsfSlpIndexer, 'getTokenData')
.resolves({ a: 'b' })
const rpcData = {
payload: {
params: {
tokenId: 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d'
}
}
}
const result = await uut.getTokenData(rpcData)
// console.log('result: ', result)
assert.equal(result.success, true)
assert.equal(result.status, 200)
assert.equal(result.endpoint, 'getTokenData')
assert.property(result, 'tokenData')
})
it('should catch and return errors', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.PsfSlpIndexer, 'getTokenData')
// .rejects(new Error('test error'))
.rejects({ error: 'test error' })
const rpcData = {
payload: {
params: {
tokenId: 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d'
}
}
}
const result = await uut.getTokenData(rpcData)
// console.log('result: ', result)
assert.equal(result.success, false)
assert.equal(result.status, 422)
assert.equal(result.message, 'test error')
assert.equal(result.endpoint, 'getTokenData')
})
})
describe('#getTokenData2', () => {
it('should return data from PsfSlpIndexer.getTokenData2()', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.PsfSlpIndexer, 'getTokenData2')
.resolves({ a: 'b' })
const rpcData = {
payload: {
params: {
tokenId: 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d'
}
}
}
const result = await uut.getTokenData2(rpcData)
// console.log('result: ', result)
assert.equal(result.success, true)
assert.equal(result.status, 200)
assert.equal(result.endpoint, 'getTokenData2')
assert.property(result, 'tokenData')
})
it('should catch and return errors', async () => {
// Mock dependencies
sandbox
.stub(uut.bchjs.PsfSlpIndexer, 'getTokenData2')
// .rejects(new Error('test error'))
.rejects({ error: 'test error' })
const rpcData = {
payload: {
params: {
tokenId: 'c85042ab08a2099f27de880a30f9a42874202751d834c42717a20801a00aab0d'
}
}
}
const result = await uut.getTokenData2(rpcData)
// console.log('result: ', result)
assert.equal(result.success, false)
assert.equal(result.status, 422)
assert.equal(result.message, 'test error')
assert.equal(result.endpoint, 'getTokenData2')
})
})
})
@@ -3,19 +3,21 @@
*/
// Public npm libraries
const assert = require('chai').assert
const jsonrpc = require('jsonrpc-lite')
const sinon = require('sinon')
const { v4: uid } = require('uuid')
import { assert } from 'chai'
import jsonrpc from 'jsonrpc-lite'
import sinon from 'sinon'
import { v4 as uid } from 'uuid'
// Local libraries.
import JSONRPC from '../../../../src/controllers/json-rpc/index.js'
import adapters from '../../mocks/adapters/index.js'
import UseCasesMock from '../../mocks/use-cases/index.js'
// Set the environment variable to signal this is a test.
process.env.SVC_ENV = 'test'
// Local libraries.
const JSONRPC = require('../../../../src/controllers/json-rpc')
const adapters = require('../../mocks/adapters')
const UseCasesMock = require('../../mocks/use-cases')
describe('#JSON RPC', () => {
let uut
let sandbox
@@ -207,5 +209,120 @@ describe('#JSON RPC', () => {
assert.equal(obj.result.method, 'bch')
assert.equal(obj.id, id)
})
it('should exit quietly for duplicate RPC message', async () => {
const id = uid()
const json = jsonrpc.request(id, 'unknownMethod', {})
const str = JSON.stringify(json)
// Call router once.
await uut.router(str, 'peerA')
// Call the router again with the same input.
const result = await uut.router(str, 'peerA')
assert.equal(result, false)
})
it('should ignore metric queries from ipfs-coord', async () => {
const id = uid()
const json = jsonrpc.request(id, 'unknownMethod', {})
const str = JSON.stringify(json)
// Force the RPC type to be 'success', to indicate an RPC that was
// processed internal to ipfs-coord.
sandbox.stub(uut.jsonrpc, 'parse').returns({
payload: {},
type: 'success'
})
// Call the router again with the same input.
const result = await uut.router(str, 'peerA')
assert.equal(result, false)
})
it('should report errors when trying to send messages to peers', async () => {
const id = uid()
const json = jsonrpc.request(id, 'unknownMethod', {})
const str = JSON.stringify(json)
// Force issue with sendPrivateMessage()
sandbox
.stub(uut.ipfsCoord.useCases.peer, 'sendPrivateMessage')
.rejects('test error')
// Call the router again with the same input.
const result = await uut.router(str, 'peerA')
// console.log('result: ', result)
assert.property(result, 'from')
assert.property(result, 'retStr')
})
})
describe('#_checkIfAlreadyProcessed', () => {
it('should return false the first time an RPC command is seen', () => {
const data = {
payload: {
jsonrpc: '2.0',
id: '6c515f3c-cf8a-42ec-870e-e416edd4923f',
method: 'unknownMethod',
params: {}
},
type: 'request'
}
const result = uut._checkIfAlreadyProcessed(data)
assert.equal(result, false)
})
it('should return true the second time an RPC command is seen', () => {
const data = {
payload: {
jsonrpc: '2.0',
id: '6c515f3c-cf8a-42ec-870e-e416edd4923f',
method: 'unknownMethod',
params: {}
},
type: 'request'
}
// First call.
uut._checkIfAlreadyProcessed(data)
// Second call.
const result = uut._checkIfAlreadyProcessed(data)
assert.equal(result, true)
})
it('should push out old data from the cache for new data', () => {
const data = {
payload: {
jsonrpc: '2.0',
id: '6c515f3c-cf8a-42ec-870e-e416edd4923f',
method: 'unknownMethod',
params: {}
},
type: 'request'
}
uut.MSG_CACHE_SIZE = 0
const result = uut._checkIfAlreadyProcessed(data)
assert.equal(result, false)
})
it('should return true on error', () => {
const result = uut._checkIfAlreadyProcessed()
assert.equal(result, true)
})
})
})

Some files were not shown because too many files have changed in this diff Show More