├── .gitignore ├── docs ├── review_02.03.22 │ ├── architecture.png │ └── architecture.puml └── rmq.md ├── .gitmodules ├── src ├── config.cpp ├── config.h ├── wire │ ├── write.cpp │ ├── uuid.h │ ├── vector.h │ ├── adapted │ │ ├── span.h │ │ ├── pair.h │ │ ├── crypto.h │ │ └── array.h │ ├── json │ │ ├── CMakeLists.txt │ │ ├── fwd.h │ │ ├── error.h │ │ └── base.h │ ├── msgpack │ │ ├── CMakeLists.txt │ │ ├── fwd.h │ │ ├── error.h │ │ └── error.cpp │ ├── wrapper │ │ ├── CMakeLists.txt │ │ ├── variant.cpp │ │ ├── trusted_array.h │ │ └── defaulted.h │ ├── CMakeLists.txt │ ├── json.h │ ├── filters.h │ ├── msgpack.h │ ├── read.cpp │ ├── fwd.h │ └── wrappers_impl.h ├── fwd.h ├── util │ ├── fwd.h │ ├── CMakeLists.txt │ ├── blocks.h │ ├── source_location.cpp │ ├── transactions.h │ ├── source_location.h │ ├── transactions.cpp │ └── blocks.cpp ├── rpc │ ├── fwd.h │ ├── lws_pub.h │ ├── scanner │ │ ├── fwd.h │ │ ├── CMakeLists.txt │ │ ├── write_commands.cpp │ │ ├── connection.h │ │ ├── queue.cpp │ │ ├── commands.cpp │ │ ├── connection.cpp │ │ ├── queue.h │ │ ├── commands.h │ │ └── client.h │ ├── CMakeLists.txt │ ├── daemon_pub.h │ ├── rates.h │ ├── rates.cpp │ ├── lws_pub.cpp │ └── daemon_pub.cpp ├── net │ ├── CMakeLists.txt │ └── http │ │ ├── CMakeLists.txt │ │ ├── slice_body.h │ │ └── client.h ├── lmdb │ ├── CMakeLists.txt │ ├── lws_error.cpp │ └── lws_error.h ├── db │ ├── CMakeLists.txt │ ├── string.h │ ├── string.cpp │ └── fwd.h ├── lws_version.h.in ├── rest_server.h └── options.h ├── .github └── workflows │ └── docker-build.yml ├── LICENSE └── tests ├── CMakeLists.txt └── unit ├── net ├── CMakeLists.txt └── http │ └── CMakeLists.txt ├── main.cpp ├── framework.test.cpp ├── wire ├── json │ └── CMakeLists.txt ├── msgpack │ └── CMakeLists.txt ├── CMakeLists.txt └── base.test.h ├── framework.test.h ├── scanner.test.h ├── db ├── print.test.h ├── chain.test.h ├── CMakeLists.txt ├── storage.test.h └── data.test.cpp ├── rpc └── CMakeLists.txt └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /docs/review_02.03.22/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/monero-lws/HEAD/docs/review_02.03.22/architecture.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/monero"] 2 | path = external/monero 3 | url = https://github.com/monero-project/monero.git 4 | -------------------------------------------------------------------------------- /src/config.cpp: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | namespace lws 4 | { 5 | namespace config 6 | { 7 | cryptonote::network_type network = cryptonote::MAINNET; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cryptonote_config.h" 4 | 5 | namespace lws 6 | { 7 | namespace config 8 | { 9 | extern cryptonote::network_type network; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.github/workflows/docker-build.yml: -------------------------------------------------------------------------------- 1 | name: Build+Push Daemon/Admin Docker Image 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | 7 | jobs: 8 | build_and_push: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Build Docker image 14 | run: docker build --no-cache --tag vtnerd/monero-lws:master . 15 | - name: Add additional tags 16 | run: docker image tag vtnerd/monero-lws:master ghcr.io/vtnerd/monero-lws:master 17 | 18 | - name: Login to GitHub Container Registry 19 | uses: docker/login-action@v3 20 | with: 21 | registry: ghcr.io 22 | username: ${{ github.actor }} 23 | password: ${{ secrets.GITHUB_TOKEN }} 24 | - name: Push to GitHub Container Registry 25 | run: docker push -a ghcr.io/vtnerd/monero-lws 26 | 27 | - name: Login to Docker.io 28 | uses: docker/login-action@v3 29 | with: 30 | username: ${{ github.actor }} 31 | password: ${{ secrets.DOCKER_VTNERD_TOKEN }} 32 | - name: Push to Docker.io 33 | run: docker push -a vtnerd/monero-lws 34 | -------------------------------------------------------------------------------- /docs/review_02.03.22/architecture.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | hide circle 3 | hide members 4 | 5 | entity "Light Wallet client" as Client { 6 | * e.g. MyMonero app, OpenMonero 7 | html, etc. 8 | } 9 | show Client fields 10 | 11 | package "monero-lws" <> { 12 | entity "monero-lws-daemon" as MoneroLWSDaemon { 13 | * implements light wallet server REST API 14 | * takes addresses and view keys and scans 15 | for transactions in real-time 16 | } 17 | show MoneroLWSDaemon fields 18 | entity "monero-lws-admin" as MoneroLWSAdmin { 19 | * admin uses this program to perform various 20 | administrative tasks managing the server, 21 | such as accept or reject requests to 22 | add an address to the server 23 | } 24 | show MoneroLWSAdmin fields 25 | entity "monero-lws database" as MoneroLWSdb { 26 | * uses LMDB, which reads/writes from/to 27 | files on the host machine by default 28 | } 29 | show MoneroLWSdb fields 30 | 31 | MoneroLWSDaemon -up-> MoneroLWSdb 32 | MoneroLWSAdmin -up-> MoneroLWSdb 33 | } 34 | 35 | entity monerod { 36 | * running Monero daemon 37 | } 38 | show monerod fields 39 | 40 | entity "Exchange rate API provider (optional)" as ExchangeRateProvider { 41 | * currently cryptocompare.com 42 | * disabled by default 43 | } 44 | show ExchangeRateProvider fields 45 | 46 | Client -right-> MoneroLWSDaemon 47 | MoneroLWSDaemon -down-> monerod 48 | MoneroLWSDaemon -down-> ExchangeRateProvider 49 | @enduml 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2020, The Monero Project 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its contributors 16 | may be used to endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_subdirectory(unit) 30 | -------------------------------------------------------------------------------- /src/wire/write.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "write.h" 29 | 30 | wire::writer::~writer() noexcept 31 | {} 32 | -------------------------------------------------------------------------------- /src/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | namespace lws 31 | { 32 | class account; 33 | class rest_server; 34 | class scanner; 35 | } 36 | -------------------------------------------------------------------------------- /src/util/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | namespace lws 31 | { 32 | class gamma_picker; 33 | struct random_output; 34 | struct random_ring; 35 | } 36 | -------------------------------------------------------------------------------- /tests/unit/net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_subdirectory(http) 30 | 31 | add_library(monero-lws-unit-net) 32 | target_link_libraries(monero-lws-unit-net monero-lws-unit-net-http) 33 | -------------------------------------------------------------------------------- /tests/unit/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "framework.test.h" 29 | 30 | int main(int argc, char* argv[]) 31 | { 32 | return lest::run(lws_test::get_tests(), argc, argv); 33 | } 34 | -------------------------------------------------------------------------------- /src/rpc/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | namespace lws 31 | { 32 | namespace rpc 33 | { 34 | class client; 35 | } 36 | struct rates; 37 | class scan_manager; 38 | } 39 | -------------------------------------------------------------------------------- /tests/unit/framework.test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "framework.test.h" 29 | 30 | namespace lws_test 31 | { 32 | lest::tests& get_tests() 33 | { 34 | static lest::tests instance; 35 | return instance; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/unit/net/http/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_library(monero-lws-unit-net-http OBJECT client.test.cpp) 30 | target_link_libraries( 31 | monero-lws-unit-net-http 32 | monero-lws-net-http 33 | monero-lws-unit-framework 34 | monero::libraries) 35 | -------------------------------------------------------------------------------- /src/wire/uuid.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | namespace wire 34 | { 35 | template<> 36 | struct is_blob 37 | : std::true_type 38 | {}; 39 | } 40 | -------------------------------------------------------------------------------- /tests/unit/wire/json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 30 | add_library(monero-lws-unit-wire-json OBJECT read.write.test.cpp) 31 | target_link_libraries( 32 | monero-lws-unit-wire-json 33 | monero-lws-unit-framework 34 | monero-lws-wire-json 35 | monero::libraries 36 | ) 37 | 38 | -------------------------------------------------------------------------------- /tests/unit/wire/msgpack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 30 | add_library(monero-lws-unit-wire-msgpack OBJECT read.write.test.cpp) 31 | target_link_libraries( 32 | monero-lws-unit-wire-msgpack 33 | monero-lws-unit-framework 34 | monero-lws-wire-msgpack 35 | monero::libraries 36 | ) 37 | 38 | -------------------------------------------------------------------------------- /src/wire/vector.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include "wire/traits.h" 34 | 35 | namespace wire 36 | { 37 | template 38 | struct is_array> 39 | : std::true_type 40 | {}; 41 | } 42 | -------------------------------------------------------------------------------- /tests/unit/framework.test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #define lest_FEATURE_AUTO_REGISTER 1 31 | #include "lest.hpp" 32 | 33 | #define LWS_CASE(name) \ 34 | lest_CASE(lws_test::get_tests(), name) 35 | 36 | namespace lws_test 37 | { 38 | lest::tests& get_tests(); 39 | } 40 | -------------------------------------------------------------------------------- /src/net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_subdirectory(http) 30 | 31 | set(monero-lws-net_sources zmq_async.cpp) 32 | set(monero-lws-net_headers zmq_async.h) 33 | 34 | add_library(monero-lws-net ${monero-lws-net_sources} ${monero-lws-net_headers}) 35 | target_link_libraries(monero-lws-net monero-lws-net-http monero::libraries) 36 | -------------------------------------------------------------------------------- /src/net/http/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws-net-http_sources client.cpp) 30 | set(monero-lws-net-http_headers client.h slice_body.h) 31 | 32 | add_library(monero-lws-net-http ${monero-lws-net-http_sources} ${monero-lws-net-http_headers}) 33 | target_link_libraries(monero-lws-net-http ${Boost_SYSTEM_LIBRARY} monero::libraries) 34 | -------------------------------------------------------------------------------- /src/wire/adapted/span.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include "span.h" // monero/contrib/epee/include 31 | #include "wire/traits.h" 32 | 33 | namespace wire 34 | { 35 | //! Enable span types for array output 36 | template 37 | struct is_array> 38 | : std::true_type 39 | {}; 40 | } 41 | -------------------------------------------------------------------------------- /tests/unit/scanner.test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include 29 | #include "byte_slice.h" // monero/contrib/epee/include 30 | #include "fwd.h" 31 | 32 | namespace lws_test 33 | { 34 | constexpr const char rpc_rendevous[] = "inproc://fake_daemon"; 35 | void rpc_thread(void* ctx, const std::vector& reply); 36 | } 37 | -------------------------------------------------------------------------------- /src/rpc/lws_pub.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include "db/fwd.h" 31 | #include "rpc/fwd.h" 32 | #include "crypto/hash.h" // monero/src 33 | #include "span.h" 34 | 35 | namespace lws { namespace rpc 36 | { 37 | void publish_scanned(rpc::client& client, const crypto::hash& id, epee::span users); 38 | }} // lws // rpc 39 | -------------------------------------------------------------------------------- /tests/unit/wire/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022-2023, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | 30 | add_subdirectory(json) 31 | add_subdirectory(msgpack) 32 | 33 | add_library(monero-lws-unit-wire OBJECT read.write.test.cpp read.test.cpp) 34 | target_link_libraries( 35 | monero-lws-unit-wire 36 | monero-lws-unit-framework 37 | monero-lws-wire 38 | monero::libraries 39 | ) 40 | #add_test(monero-lws-unit) 41 | -------------------------------------------------------------------------------- /src/wire/json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws_wire-json_sources error.cpp read.cpp write.cpp) 30 | set(monero-lws_wire-json_headers base.h error.h fwd.h read.h write.h) 31 | 32 | add_library(monero-lws-wire-json ${monero-lws_wire-json_sources} ${monero-lws-wire-json_headers}) 33 | target_link_libraries(monero-lws-wire-json monero::libraries monero-lws-wire) 34 | -------------------------------------------------------------------------------- /tests/unit/db/print.test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "framework.test.h" 29 | #include 30 | 31 | namespace lws { namespace db 32 | { 33 | inline std::ostream& operator<<(std::ostream& out, const index_ranges& src) 34 | { 35 | using lest::to_string; 36 | return out << to_string(src.get_container()); 37 | } 38 | }} // lws // db 39 | 40 | -------------------------------------------------------------------------------- /tests/unit/rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022-2023, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_library(monero-lws-unit-rpc OBJECT admin.test.cpp) 30 | target_link_libraries( 31 | monero-lws-unit-rpc 32 | monero-lws-unit-db 33 | monero-lws-unit-framework 34 | monero-lws-common 35 | monero-lws-db 36 | monero-lws-rpc 37 | monero-lws-wire-json 38 | monero::libraries 39 | ) 40 | #add_test(monero-lws-unit) 41 | -------------------------------------------------------------------------------- /src/wire/msgpack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws_wire-msgpack_sources error.cpp read.cpp write.cpp) 30 | set(monero-lws_wire-msgpack_headers base.h error.h fwd.h read.h write.h) 31 | 32 | add_library(monero-lws-wire-msgpack ${monero-lws_wire-msgpack_sources} ${monero-lws-wire-msgpack_headers}) 33 | target_link_libraries(monero-lws-wire-msgpack monero::libraries monero-lws-wire) 34 | -------------------------------------------------------------------------------- /src/wire/wrapper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws-wire_sources variant.cpp) 30 | set(monero-lws-wire_headers variant.h) 31 | 32 | add_library(monero-lws-wire-wrapper ${monero-lws-wire_sources} ${monero-lws-wire_headers}) 33 | target_include_directories(monero-lws-wire-wrapper PUBLIC "${LMDB_INCLUDE}") 34 | target_link_libraries(monero-lws-wire-wrapper PRIVATE monero::libraries) 35 | 36 | -------------------------------------------------------------------------------- /src/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws-util_sources blocks.cpp gamma_picker.cpp random_outputs.cpp source_location.cpp transactions.cpp) 30 | set(monero-lws-util_headers blocks.h fwd.h gamma_picker.h random_outputs.h source_location.h transactions.h) 31 | 32 | add_library(monero-lws-util ${monero-lws-util_sources} ${monero-lws-util_headers}) 33 | target_link_libraries(monero-lws-util monero::libraries monero-lws-db) 34 | -------------------------------------------------------------------------------- /src/wire/wrapper/variant.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "wire/wrapper/variant.h" 30 | 31 | #include 32 | #include "wire/error.h" 33 | 34 | namespace wire 35 | { 36 | [[noreturn]] void throw_variant_exception(wire::error::schema type, const char* variant_name) 37 | { 38 | WIRE_DLOG_THROW(type, "error with variant type: " << boost::core::demangle(variant_name)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/unit/db/chain.test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "framework.test.h" 29 | 30 | #include "crypto/crypto.h" // monero/src 31 | #include "db/data.h" 32 | #include "db/storage.h" 33 | #include "span.h" // monero/contrib/epee/include 34 | 35 | namespace lws_test 36 | { 37 | void test_chain(lest::env& lest_env, lws::db::storage_reader reader, lws::db::block_id id, epee::span snapshot); 38 | } 39 | -------------------------------------------------------------------------------- /src/lmdb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws-lmdb_sources lws_database.cpp lws_error.cpp) 30 | set(monero-lws-lmdb_headers lws_database.h lws_error.h lws_key_stream.h lws_table.h lws_value_stream.h msgpack_table.h) 31 | 32 | add_library(monero-lws-lmdb ${monero-lws-lmdb_sources} ${monero-lws-lmdb_headers}) 33 | target_include_directories(monero-lws-lmdb PUBLIC "${LMDB_INCLUDE}") 34 | target_link_libraries(monero-lws-lmdb PRIVATE monero::libraries) 35 | -------------------------------------------------------------------------------- /tests/unit/db/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022-2023, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_library(monero-lws-unit-db OBJECT 30 | account.test.cpp 31 | chain.test.cpp 32 | data.test.cpp 33 | storage.test.cpp 34 | subaddress.test.cpp 35 | webhook.test.cpp 36 | ) 37 | target_link_libraries( 38 | monero-lws-unit-db 39 | monero-lws-unit-framework 40 | monero-lws-common 41 | monero-lws-db 42 | monero::libraries 43 | ${Boost_PROGRAM_OPTIONS_LIBRARY} 44 | ) 45 | #add_test(monero-lws-unit) 46 | -------------------------------------------------------------------------------- /src/db/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018-2020, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws-db_sources account.cpp data.cpp storage.cpp string.cpp) 30 | set(monero-lws-db_headers account.h data.h fwd.h storage.h string.h) 31 | 32 | add_library(monero-lws-db ${monero-lws-db_sources} ${monero-lws-db_headers}) 33 | target_include_directories(monero-lws-db PUBLIC "${LMDB_INCLUDE}") 34 | target_link_libraries(monero-lws-db monero::libraries monero-lws-common monero-lws-lmdb monero-lws-wire-msgpack ${LMDB_LIB_PATH}) 35 | -------------------------------------------------------------------------------- /src/rpc/scanner/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | namespace lws { namespace rpc { namespace scanner 30 | { 31 | class client; 32 | struct connection; 33 | struct give_accounts; 34 | struct header; 35 | struct push_accounts; 36 | class queue; 37 | template struct do_read_commands; 38 | class server; 39 | struct take_accounts; 40 | struct update_accounts; 41 | template struct write_commands; 42 | }}} // lws // rpc // scanner 43 | -------------------------------------------------------------------------------- /src/rpc/scanner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws-rpc-scanner_sources 30 | client.cpp commands.cpp connection.cpp queue.cpp server.cpp write_commands.cpp 31 | ) 32 | set(monero-lws-rpc-scanner_headers 33 | client.h commands.h connection.h fwd.h queue.h read_commands.h server.h write_commands.h 34 | ) 35 | 36 | add_library(monero-lws-rpc-scanner ${monero-lws-rpc-scanner_sources} ${monero-lws-rpc-scanner_headers}) 37 | target_link_libraries(monero-lws-rpc-scanner monero::libraries monero-lws-wire-msgpack) 38 | -------------------------------------------------------------------------------- /src/wire/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020-2023, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | set(monero-lws-wire_sources error.cpp read.cpp write.cpp) 30 | set(monero-lws-wire_headers error.h field.h filters.h fwd.h json.h read.h traits.h vector.h write.h) 31 | 32 | add_library(monero-lws-wire ${monero-lws-wire_sources} ${monero-lws-wire_headers}) 33 | target_include_directories(monero-lws-wire PUBLIC "${LMDB_INCLUDE}") 34 | target_link_libraries(monero-lws-wire PRIVATE monero::libraries) 35 | 36 | add_subdirectory(json) 37 | add_subdirectory(msgpack) 38 | add_subdirectory(wrapper) 39 | -------------------------------------------------------------------------------- /src/util/blocks.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include 29 | #include "crypto/hash.h" 30 | #include "db/data.h" 31 | #include "db/fwd.h" 32 | #include "span.h" // in monero/contrib/epee/include 33 | 34 | namespace lws 35 | { 36 | crypto::hash get_block_longhash( 37 | const std::string& bd, const db::block_id height, const unsigned major_version, const db::storage& disk, db::block_id cached_start, epee::span cached); 38 | 39 | bool verify_timestamp(std::uint64_t verify, std::vector timestamps); 40 | } 41 | -------------------------------------------------------------------------------- /src/util/source_location.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include 29 | #include 30 | #include "util/source_location.h" 31 | 32 | namespace lws 33 | { 34 | std::ostream& operator<<(std::ostream& os, const source_location loc) 35 | { 36 | if (loc.line()) 37 | { 38 | char const* const just_name = loc.file_name() ? 39 | std::strrchr(loc.file_name(), '/') : nullptr; 40 | os << (just_name ? just_name + 1 : loc.file_name()) << ':' << loc.line(); 41 | } 42 | else 43 | os << "(unknown source location)"; 44 | return os; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/wire/json/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #define WIRE_JSON_DECLARE_ENUM(type) \ 31 | const char* get_string(type) noexcept; \ 32 | void read_bytes(::wire::json_reader&, type&); \ 33 | void write_bytes(:wire::json_writer&, type) 34 | 35 | #define WIRE_JSON_DECLARE_OBJECT(type) \ 36 | void read_bytes(::wire::json_reader&, type&); \ 37 | void write_bytes(::wire::json_writer&, const type&) 38 | 39 | namespace wire 40 | { 41 | struct json; 42 | class json_reader; 43 | class json_slice_writer; 44 | class json_writer; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020-2024, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_subdirectory(scanner) 30 | 31 | set(monero-lws-rpc_sources admin.cpp client.cpp daemon_pub.cpp daemon_zmq.cpp light_wallet.cpp lws_pub.cpp rates.cpp) 32 | set(monero-lws-rpc_headers admin.h client.h daemon_pub.h daemon_zmq.h fwd.h json.h light_wallet.h lws_pub.h rates.h) 33 | 34 | add_library(monero-lws-rpc ${monero-lws-rpc_sources} ${monero-lws-rpc_headers}) 35 | target_include_directories(monero-lws-rpc PRIVATE ${RMQ_INCLUDE_DIR}) 36 | target_link_libraries(monero-lws-rpc monero::libraries monero-lws-util monero-lws-wire-json monero-lws-wire-wrapper ${RMQ_LIBRARY}) 37 | -------------------------------------------------------------------------------- /src/lmdb/lws_error.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "lws_error.h" 29 | 30 | #include "lmdb/error.h" // monero/src 31 | #include "misc_log_ex.h" // monero/src 32 | 33 | std::error_code lws::log_lmdb_error(const int err, const int line, const char* file, int skip) 34 | { 35 | const std::error_code code{lmdb::error(err)}; 36 | 37 | if (err != skip) 38 | { 39 | char const* const name_end = std::strrchr(file, '/'); 40 | if (name_end) 41 | file = name_end + 1; 42 | 43 | MERROR("lmdb error (" << file << ':' << line << "): " << code.message()); 44 | } 45 | return code; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/util/transactions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "common/pod-class.h" 33 | #include "ringct/rctTypes.h" 34 | 35 | namespace crypto 36 | { 37 | POD_CLASS hash8; 38 | POD_CLASS key_derivation; 39 | } 40 | 41 | namespace lws 42 | { 43 | void decrypt_payment_id(crypto::hash8& out, const crypto::key_derivation& key); 44 | boost::optional> decode_amount(const rct::key& commitment, const rct::ecdhTuple& info, const crypto::key_derivation& sk, std::size_t index, const bool bulletproof2); 45 | } 46 | -------------------------------------------------------------------------------- /src/lmdb/lws_error.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | 31 | #define MLWS_LMDB_CHECK(...) \ 32 | do \ 33 | { \ 34 | const int err = __VA_ARGS__ ; \ 35 | if (err) \ 36 | return ::lws::log_lmdb_error(err, __LINE__, __FILE__); \ 37 | } while (0) 38 | 39 | namespace lws 40 | { 41 | std::error_code log_lmdb_error(int err, int line, const char* file, int skip = 0); 42 | } 43 | -------------------------------------------------------------------------------- /src/wire/msgpack/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #define WIRE_MSGPACK_DECLARE_ENUM(type) \ 31 | const char* get_string(type) noexcept; \ 32 | void read_bytes(::wire::msgpack_reader&, type&); \ 33 | void write_bytes(:wire::msgpack_writer&, type) 34 | 35 | #define WIRE_MSGPACK_DECLARE_OBJECT(type) \ 36 | void read_bytes(::wire::msgpack_reader&, type&); \ 37 | void write_bytes(::wire::msgpack_writer&, const type&) 38 | 39 | namespace wire 40 | { 41 | struct msgpack; 42 | class msgpack_reader; 43 | class msgpack_slice_writer; 44 | class msgpack_writer; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /docs/rmq.md: -------------------------------------------------------------------------------- 1 | # monero-lws RabbitMQ Usage 2 | Monero-lws uses RabbitMQ to provide JSON notifications of payment_id 3 | (web)hooks. The feature is optional - by default LWS is _not_ compiled with 4 | RabbitMQ support. The cmake option -DWITH_RMQ=ON must be specified during the 5 | configuration stage to enable the feature. 6 | 7 | The notification location is specified with `--rmq-address`, the login details 8 | are specified with `--rmq-credentials` (specified as `user:pass`), the exchange 9 | is specified with `--rmq-exchange`, and routing name is specified with 10 | `--rmq-routing`. 11 | 12 | ## `json-full-payment_hook` 13 | Only events of this type are sent to RabbitMQ. They are always "simulcast" with 14 | the webhook URL. If the webhook URL is `zmq` then no simulcast occurs - the 15 | event is only sent via ZeroMQ and/or RabbitMQ (if both are configured then it 16 | sent to both, otherwise it is only sent to the one configured). 17 | 18 | Example of the "raw" output to RabbitMQ: 19 | 20 | ```json 21 | { 22 | "index": 2, 23 | "event": { 24 | "event": "tx-confirmation", 25 | "payment_id": "4f695d197f2a3c54", 26 | "token": "single zmq wallet", 27 | "confirmations": 1, 28 | "event_id": "3894f98f5dd54af5857e4f8a961a4e57", 29 | "tx_info": { 30 | "id": { 31 | "high": 0, 32 | "low": 5666768 33 | }, 34 | "block": 2265961, 35 | "index": 1, 36 | "amount": 3117324236131, 37 | "timestamp": 1687301600, 38 | "tx_hash": "ef3187775584351cc5109de124b877bcc530fb3fdbf77895329dd447902cc566", 39 | "tx_prefix_hash": "064884b8a8f903edcfebab830707ed44b633438b47c95a83320f4438b1b28626", 40 | "tx_public": "54dce1a6eebafa2fdedcea5e373ef9de1c3d2737ae9f809e80958d1ba4590d74", 41 | "rct_mask": "4cdc4c4e340aacb4741ba20f9b0b859242ecdad2fcc251f71d81123a47db3400", 42 | "payment_id": "4f695d197f2a3c54", 43 | "unlock_time": 0, 44 | "mixin_count": 15, 45 | "coinbase": false 46 | } 47 | } 48 | } 49 | ``` 50 | > `index` is a counter used to detect dropped messages. It is not useful to 51 | RabbitMQ but is a carry-over from ZeroMQ (the same serialized message is used 52 | to send to both). 53 | 54 | > The `block` and `id` fields in the above example are NOT present when 55 | `confirmations == 0`. 56 | -------------------------------------------------------------------------------- /tests/unit/db/storage.test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include "crypto/crypto.h" // monero/src/ 32 | #include "db/account.h" 33 | #include "db/data.h" 34 | #include "db/storage.h" 35 | 36 | namespace lws { namespace db { namespace test 37 | { 38 | struct cleanup_db 39 | { 40 | ~cleanup_db(); 41 | }; 42 | 43 | lws::db::storage get_fresh_db(); 44 | lws::db::account make_db_account(const lws::db::account_address& pubs, const crypto::secret_key& key); 45 | lws::account make_account(const lws::db::account_address& pubs, const crypto::secret_key& key); 46 | }}} // lws // db // test 47 | -------------------------------------------------------------------------------- /src/wire/adapted/pair.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include "wire/field.h" 31 | #include "wire/read.h" 32 | #include "wire/write.h" 33 | 34 | namespace wire 35 | { 36 | template 37 | void map_pair(F& format, T& self) 38 | { 39 | wire::object(format, WIRE_FIELD_ID(0, first), WIRE_FIELD_ID(1, second)); 40 | } 41 | 42 | template 43 | void read_bytes(R& source, std::pair& dest) 44 | { map_pair(source, dest); } 45 | 46 | template 47 | void write_bytes(W& dest, const std::pair& source) 48 | { map_pair(dest, source); } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/lws_version.h.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | 31 | namespace lws { namespace version 32 | { 33 | constexpr const char branch[] = "@MLWS_COMMIT_BRANCH@"; 34 | constexpr const char commit[] = "@MLWS_COMMIT_HASH@"; 35 | constexpr const char date[] = "@MLWS_COMMIT_DATE@"; 36 | constexpr const char id[] = "1.0-alpha"; 37 | constexpr const char name[] = "monero-lws"; 38 | 39 | // openmonero is currently on 1.6 and we have multiple additions since then 40 | namespace api 41 | { 42 | constexpr const std::uint16_t major = 1; 43 | constexpr const std::uint16_t minor = 7; 44 | constexpr const std::uint32_t combined = std::uint32_t(major) << 16 | minor; 45 | } 46 | }} // lws // version 47 | 48 | -------------------------------------------------------------------------------- /src/wire/json/error.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | namespace wire 34 | { 35 | namespace error 36 | { 37 | //! Type wrapper to "grab" rapidjson errors 38 | enum class rapidjson_e : int {}; 39 | 40 | //! \return Static string describing error `value`. 41 | const char* get_string(rapidjson_e value) noexcept; 42 | 43 | //! \return Category for rapidjson generated errors. 44 | const std::error_category& rapidjson_category() noexcept; 45 | 46 | //! \return Error code with `value` and `rapidjson_category()`. 47 | inline std::error_code make_error_code(rapidjson_e value) noexcept 48 | { 49 | return std::error_code{int(value), rapidjson_category()}; 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/unit/wire/base.test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include "wire/traits.h" 34 | 35 | namespace lws_test 36 | { 37 | struct small_blob { std::uint8_t buf[4]; }; 38 | constexpr const small_blob blob_test1{{0x00, 0xFF, 0x22, 0x11}}; 39 | constexpr const small_blob blob_test2{{0x11, 0x7F, 0x7E, 0x80}}; 40 | constexpr const small_blob blob_test3{{0xDE, 0xAD, 0xBE, 0xEF}}; 41 | 42 | inline bool operator==(const small_blob& lhs, const small_blob& rhs) 43 | { 44 | return std::memcmp(lhs.buf, rhs.buf, sizeof(lhs.buf)) == 0; 45 | } 46 | } 47 | 48 | namespace wire 49 | { 50 | template<> 51 | struct is_blob 52 | : std::true_type 53 | {}; 54 | } 55 | -------------------------------------------------------------------------------- /src/rpc/daemon_pub.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include "common/expect.h" // monero/src 34 | #include "crypto/hash.h" // monero/src 35 | #include "wire/json/fwd.h" 36 | 37 | namespace cryptonote { class transaction; } 38 | namespace lws 39 | { 40 | namespace rpc 41 | { 42 | //! Represents only the last block listed in "minimal-chain_main" pub. 43 | struct minimal_chain_pub 44 | { 45 | std::uint64_t top_block_height; 46 | crypto::hash top_block_id; 47 | 48 | static expect from_json(std::string&&); 49 | }; 50 | 51 | struct full_txpool_pub 52 | { 53 | std::vector txes; 54 | 55 | static expect from_json(std::string&&); 56 | }; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/wire/json/base.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022-2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include "byte_stream.h" 34 | #include "wire/json/fwd.h" 35 | #include "wire/read.h" 36 | #include "wire/write.h" 37 | 38 | namespace wire 39 | { 40 | struct json 41 | { 42 | using input_type = json_reader; 43 | using output_type = json_slice_writer; 44 | 45 | template 46 | static std::error_code from_bytes(std::string&& source, T& dest) 47 | { 48 | return wire_read::from_bytes(std::move(source), dest); 49 | } 50 | 51 | template 52 | static std::error_code to_bytes(T& dest, const U& source) 53 | { 54 | return wire_write::to_bytes(dest, source); 55 | } 56 | }; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/db/string.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | #include "common/expect.h" 33 | #include "db/fwd.h" 34 | 35 | namespace lws 36 | { 37 | namespace db 38 | { 39 | //! Callable for converting `account_address` to/from monero base58 public address. 40 | struct address_string_ 41 | { 42 | /*! 43 | \return `address` as a monero base58 public address, using 44 | `lws::config::network` for the tag. 45 | */ 46 | std::string operator()(account_address const& address) const; 47 | /*! 48 | \return `address`, as base58 public address, using `lws::config::network` 49 | for the tag. 50 | */ 51 | expect operator()(boost::string_ref address) const noexcept; 52 | }; 53 | constexpr const address_string_ address_string{}; 54 | } // db 55 | } // lws 56 | -------------------------------------------------------------------------------- /src/wire/msgpack/error.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | 32 | namespace wire 33 | { 34 | namespace error 35 | { 36 | //! Type wrapper to "grab" rapidjson errors 37 | enum class msgpack : int 38 | { 39 | success = 0, // required for `expected` 40 | incomplete, 41 | integer_encoding, 42 | invalid, 43 | max_tree_size, 44 | not_enough_bytes, 45 | underflow_tree 46 | }; 47 | 48 | //! \return Static string describing error `value`. 49 | const char* get_string(msgpack value) noexcept; 50 | 51 | //! \return Category for msgpack generated errors. 52 | const std::error_category& msgpack_category() noexcept; 53 | 54 | //! \return Error code with `value` and `rapidjson_category()`. 55 | inline std::error_code make_error_code(msgpack value) noexcept 56 | { 57 | return std::error_code{int(value), msgpack_category()}; 58 | } 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src/rpc/scanner/write_commands.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "write_commands.h" 29 | 30 | #include 31 | #include 32 | 33 | 34 | namespace lws { namespace rpc { namespace scanner 35 | { 36 | epee::byte_slice complete_command(const std::uint8_t id, epee::byte_stream sink) 37 | { 38 | if (sink.size() < sizeof(header)) 39 | { 40 | MERROR("Message sink was unexpectedly shrunk on message"); 41 | return nullptr; 42 | } 43 | 44 | using value_type = header::length_type::value_type; 45 | if (std::numeric_limits::max() < sink.size() - sizeof(header)) 46 | { 47 | MERROR("Message to exceeds max size"); 48 | return nullptr; 49 | } 50 | 51 | const header head{0, id, header::length_type{value_type(sink.size() - sizeof(header))}}; 52 | std::memcpy(sink.data(), std::addressof(head), sizeof(head)); 53 | return epee::byte_slice{std::move(sink)}; 54 | } 55 | }}} // lws // rpc // scanner 56 | -------------------------------------------------------------------------------- /src/rpc/rates.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "byte_slice.h" 32 | #include "common/expect.h" 33 | #include "wire/json/fwd.h" 34 | 35 | namespace lws 36 | { 37 | struct rates 38 | { 39 | double AUD; 40 | double BRL; 41 | double BTC; 42 | double CAD; 43 | double CHF; 44 | double CNY; 45 | double EUR; 46 | double GBP; 47 | double HKD; 48 | double INR; 49 | double JPY; 50 | double KRW; 51 | double MXN; 52 | double NOK; 53 | double NZD; 54 | double SEK; 55 | double SGD; 56 | double TRY; 57 | double USD; 58 | double RUB; 59 | double ZAR; 60 | }; 61 | WIRE_JSON_DECLARE_OBJECT(rates); 62 | 63 | namespace rpc 64 | { 65 | struct crypto_compare_ 66 | { 67 | static const char url[]; 68 | 69 | expect operator()(std::string&& body) const; 70 | }; 71 | constexpr const crypto_compare_ crypto_compare{}; 72 | } // rpc 73 | } // lws 74 | -------------------------------------------------------------------------------- /tests/unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, The Monero Project 2 | # 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without modification, are 6 | # permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this list of 9 | # conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | # of conditions and the following disclaimer in the documentation and/or other 13 | # materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | add_library(monero-lws-unit-framework framework.test.cpp) 30 | target_include_directories(monero-lws-unit-framework PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_SOURCE_DIR}/src") 31 | target_link_libraries(monero-lws-unit-framework) 32 | 33 | add_subdirectory(db) 34 | add_subdirectory(net) 35 | add_subdirectory(rpc) 36 | add_subdirectory(wire) 37 | 38 | add_executable(monero-lws-unit main.cpp rest.test.cpp scanner.test.cpp) 39 | target_link_libraries(monero-lws-unit 40 | monero::libraries 41 | monero-lws-daemon-common 42 | monero-lws-unit-db 43 | monero-lws-unit-framework 44 | monero-lws-unit-net 45 | monero-lws-unit-net-http 46 | monero-lws-unit-rpc 47 | monero-lws-unit-wire 48 | monero-lws-unit-wire-json 49 | monero-lws-unit-wire-msgpack 50 | ${Boost_FILESYSTEM_LIBRARY} 51 | ${Boost_PROGRAM_OPTIONS_LIBRARY} 52 | ${Boost_THREAD_LIBRARY} 53 | ${Boost_THREAD_LIBS_INIT} 54 | Threads::Threads 55 | ) 56 | add_test(NAME monero-lws-unit COMMAND monero-lws-unit -v) 57 | -------------------------------------------------------------------------------- /src/wire/adapted/crypto.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | 32 | #include "crypto/crypto.h" // monero/src 33 | #include "span.h" // monero/contrib/include 34 | #include "ringct/rctTypes.h" // monero/src 35 | #include "wire/traits.h" 36 | 37 | namespace crypto 38 | { 39 | template 40 | void read_bytes(R& source, crypto::secret_key& self) 41 | { 42 | source.binary(epee::as_mut_byte_span(unwrap(unwrap(self)))); 43 | } 44 | 45 | template 46 | void write_bytes(W& dest, const crypto::secret_key& self) 47 | { 48 | dest.binary(epee::as_byte_span(unwrap(unwrap(self)))); 49 | } 50 | } 51 | 52 | namespace wire 53 | { 54 | WIRE_DECLARE_BLOB(crypto::ec_scalar); 55 | WIRE_DECLARE_BLOB(crypto::hash); 56 | WIRE_DECLARE_BLOB(crypto::hash8); 57 | WIRE_DECLARE_BLOB(crypto::key_derivation); 58 | WIRE_DECLARE_BLOB(crypto::key_image); 59 | WIRE_DECLARE_BLOB(crypto::public_key); 60 | WIRE_DECLARE_BLOB(crypto::signature); 61 | WIRE_DECLARE_BLOB(crypto::view_tag); 62 | WIRE_DECLARE_BLOB(rct::key); 63 | } 64 | -------------------------------------------------------------------------------- /src/db/string.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #include "string.h" 28 | 29 | #include "config.h" 30 | #include "cryptonote_basic/cryptonote_basic_impl.h" 31 | #include "db/data.h" 32 | #include "error.h" 33 | 34 | namespace lws 35 | { 36 | namespace db 37 | { 38 | std::string address_string_::operator()(account_address const& address) const 39 | { 40 | const cryptonote::account_public_address address_{ 41 | address.spend_public, address.view_public 42 | }; 43 | return cryptonote::get_account_address_as_str( 44 | lws::config::network, false, address_ 45 | ); 46 | } 47 | expect 48 | address_string_::operator()(boost::string_ref address) const noexcept 49 | { 50 | cryptonote::address_parse_info info{}; 51 | 52 | if (!cryptonote::get_account_address_from_str(info, lws::config::network, std::string{address})) 53 | return {lws::error::bad_address}; 54 | if (info.is_subaddress || info.has_payment_id) 55 | return {lws::error::bad_address}; 56 | 57 | return account_address{ 58 | info.address.m_view_public_key, info.address.m_spend_public_key 59 | }; 60 | } 61 | } // db 62 | } // lws 63 | -------------------------------------------------------------------------------- /src/db/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | 32 | namespace lws 33 | { 34 | class account; 35 | 36 | namespace db 37 | { 38 | enum account_flags : std::uint8_t; 39 | enum class account_id : std::uint32_t; 40 | enum class account_status : std::uint8_t; 41 | enum class block_id : std::uint64_t; 42 | enum extra : std::uint8_t; 43 | enum class extra_and_length : std::uint8_t; 44 | enum class major_index : std::uint32_t; 45 | enum class minor_index : std::uint32_t; 46 | enum class request : std::uint8_t; 47 | enum class webhook_type : std::uint8_t; 48 | 49 | struct account; 50 | struct account_address; 51 | struct address_index; 52 | struct block_info; 53 | struct key_image; 54 | struct output; 55 | struct output_id; 56 | struct request_info; 57 | struct spend; 58 | class storage; 59 | struct subaddress_map; 60 | struct transaction_link; 61 | struct view_key; 62 | struct webhook_data; 63 | struct webhook_dupsort; 64 | struct webhook_event; 65 | struct webhook_key; 66 | struct webhook_new_account; 67 | struct webhook_output; 68 | struct webhook_tx_confirmation; 69 | } // db 70 | } // lws 71 | -------------------------------------------------------------------------------- /src/wire/json.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include "wire/json/base.h" 31 | #include "wire/json/error.h" 32 | #include "wire/json/read.h" 33 | #include "wire/json/write.h" 34 | 35 | #define WIRE_JSON_DEFINE_ENUM(type, map) \ 36 | void read_bytes(::wire::json_reader& source, type& dest) \ 37 | { \ 38 | dest = type(source.enumeration(map)); \ 39 | } \ 40 | void write_bytes(::wire::json_writer& dest, const type source) \ 41 | { \ 42 | dest.enumeration(std::size_t(source), map); \ 43 | } 44 | 45 | #define WIRE_JSON_DEFINE_OBJECT(type, map) \ 46 | void read_bytes(::wire::json_reader& source, type& dest) \ 47 | { \ 48 | map(source, dest); \ 49 | } \ 50 | void write_bytes(::wire::json_writer& dest, const type& source) \ 51 | { \ 52 | map(dest, source); \ 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/util/source_location.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | #include 30 | 31 | //! Expands to an object that tracks current source location 32 | #define MLWS_CURRENT_LOCATION ::lws::source_location{__FILE__, __LINE__} 33 | 34 | namespace lws 35 | { 36 | //! Tracks source location in one object, with `std::ostream` output. 37 | class source_location 38 | { 39 | // NOTE This is available in newer Boost versions 40 | const char* file_; 41 | int line_; 42 | 43 | public: 44 | constexpr source_location() noexcept 45 | : file_(nullptr), line_(0) 46 | {} 47 | 48 | //! `file` must be in static memory 49 | constexpr source_location(const char* file, int line) noexcept 50 | : file_(file), line_(line) 51 | {} 52 | 53 | source_location(const source_location&) = default; 54 | source_location& operator=(const source_location&) = default; 55 | 56 | //! \return Possibly `nullptr`, otherwise full file path 57 | const char* file_name() const noexcept { return file_; } 58 | int line() const noexcept { return line_; } 59 | }; 60 | 61 | //! Prints `loc.file_name() + ':' + loc.line()` 62 | std::ostream& operator<<(std::ostream& os, source_location loc); 63 | } 64 | -------------------------------------------------------------------------------- /src/util/transactions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "transactions.h" 29 | 30 | #include "cryptonote_config.h" 31 | #include "crypto/crypto.h" 32 | #include "crypto/hash.h" 33 | #include "ringct/rctOps.h" 34 | 35 | void lws::decrypt_payment_id(crypto::hash8& out, const crypto::key_derivation& key) 36 | { 37 | crypto::hash hash; 38 | char data[33]; /* A hash, and an extra byte */ 39 | 40 | memcpy(data, &key, 32); 41 | data[32] = config::HASH_KEY_ENCRYPTED_PAYMENT_ID; 42 | cn_fast_hash(data, 33, hash); 43 | 44 | for (size_t b = 0; b < 8; ++b) 45 | out.data[b] ^= hash.data[b]; 46 | } 47 | 48 | boost::optional> lws::decode_amount(const rct::key& commitment, const rct::ecdhTuple& info, const crypto::key_derivation& sk, std::size_t index, const bool bulletproof2) 49 | { 50 | crypto::secret_key scalar{}; 51 | crypto::derivation_to_scalar(sk, index, scalar); 52 | 53 | rct::ecdhTuple copy{info}; 54 | rct::ecdhDecode(copy, rct::sk2rct(scalar), bulletproof2); 55 | 56 | rct::key Ctmp; 57 | rct::addKeys2(Ctmp, copy.mask, copy.amount, rct::H); 58 | if (rct::equalKeys(commitment, Ctmp)) 59 | return {{rct::h2d(copy.amount), copy.mask}}; 60 | return boost::none; 61 | } 62 | -------------------------------------------------------------------------------- /src/wire/filters.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include "lmdb/util.h" 34 | 35 | // These functions are to be used with `wire::as_object(...)` key filtering 36 | 37 | namespace wire 38 | { 39 | //! Callable that returns the value unchanged; default filter for `as_array` and `as_object`. 40 | struct identity_ 41 | { 42 | template 43 | const T& operator()(const T& value) const noexcept 44 | { 45 | return value; 46 | } 47 | }; 48 | constexpr const identity_ identity{}; 49 | 50 | //! Callable that forwards enum to get_string. 51 | struct enum_as_string_ 52 | { 53 | template 54 | auto operator()(const T value) const noexcept(noexcept(get_string(value))) -> decltype(get_string(value)) 55 | { 56 | return get_string(value); 57 | } 58 | }; 59 | constexpr const enum_as_string_ enum_as_string{}; 60 | 61 | //! Callable that converts C++11 enum class or integer to integer value. 62 | struct as_integer_ 63 | { 64 | template 65 | lmdb::native_type operator()(const T value) const noexcept 66 | { 67 | using native = lmdb::native_type; 68 | static_assert(!std::is_signed::value, "integer cannot be signed"); 69 | return native(value); 70 | } 71 | }; 72 | constexpr const as_integer_ as_integer{}; 73 | } 74 | -------------------------------------------------------------------------------- /src/wire/msgpack.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include "wire/msgpack/base.h" 31 | #include "wire/msgpack/error.h" 32 | #include "wire/msgpack/read.h" 33 | #include "wire/msgpack/write.h" 34 | 35 | #define WIRE_MSGPACK_DEFINE_ENUM(type, map) \ 36 | void read_bytes(::wire::msgpack_reader& source, type& dest) \ 37 | { \ 38 | dest = type(source.enumeration(map)); \ 39 | } \ 40 | void write_bytes(::wire::msgpack_writer& dest, const type source) \ 41 | { \ 42 | dest.enumeration(std::size_t(source), map); \ 43 | } 44 | 45 | #define WIRE_MSGPACK_DEFINE_OBJECT(type, map) \ 46 | void read_bytes(::wire::msgpack_reader& source, type& dest) \ 47 | { \ 48 | map(source, dest); \ 49 | } \ 50 | void write_bytes(::wire::msgpack_writer& dest, const type& source) \ 51 | { \ 52 | map(dest, source); \ 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/wire/msgpack/error.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "error.h" 29 | 30 | namespace wire 31 | { 32 | namespace error 33 | { 34 | const char* get_string(const msgpack value) noexcept 35 | { 36 | switch (value) 37 | { 38 | default: 39 | break; 40 | case msgpack::incomplete: 41 | return "Incomplete msgpack tree structure"; 42 | case msgpack::integer_encoding: 43 | return "Unable to encode integer in msgpack"; 44 | case msgpack::invalid: 45 | return "Invalid msgpack encoding"; 46 | case msgpack::max_tree_size: 47 | return "Exceeded tag tracking amount"; 48 | case msgpack::not_enough_bytes: 49 | return "Expected more bytes in the msgpack stream"; 50 | case msgpack::underflow_tree: 51 | return "Expected more tags"; 52 | } 53 | 54 | return "Unknown msgpack error"; 55 | } 56 | 57 | const std::error_category& msgpack_category() noexcept 58 | { 59 | struct category final : std::error_category 60 | { 61 | virtual const char* name() const noexcept override final 62 | { 63 | return "wire::error::msgpack_category()"; 64 | } 65 | 66 | virtual std::string message(int value) const override final 67 | { 68 | return get_string(msgpack(value)); 69 | } 70 | }; 71 | static const category instance{}; 72 | return instance; 73 | } 74 | } // error 75 | } // wire 76 | -------------------------------------------------------------------------------- /src/rpc/rates.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #include "rates.h" 28 | 29 | #include "wire/json.h" 30 | 31 | namespace 32 | { 33 | template 34 | void map_rates(F& format, T& self) 35 | { 36 | wire::object(format, 37 | WIRE_FIELD(AUD), 38 | WIRE_FIELD(BRL), 39 | WIRE_FIELD(BTC), 40 | WIRE_FIELD(CAD), 41 | WIRE_FIELD(CHF), 42 | WIRE_FIELD(CNY), 43 | WIRE_FIELD(EUR), 44 | WIRE_FIELD(GBP), 45 | WIRE_FIELD(HKD), 46 | WIRE_FIELD(INR), 47 | WIRE_FIELD(JPY), 48 | WIRE_FIELD(KRW), 49 | WIRE_FIELD(MXN), 50 | WIRE_FIELD(NOK), 51 | WIRE_FIELD(NZD), 52 | WIRE_FIELD(SEK), 53 | WIRE_FIELD(SGD), 54 | WIRE_FIELD(TRY), 55 | WIRE_FIELD(USD), 56 | WIRE_FIELD(RUB), 57 | WIRE_FIELD(ZAR) 58 | ); 59 | } 60 | } 61 | 62 | namespace lws 63 | { 64 | WIRE_JSON_DEFINE_OBJECT(rates, map_rates); 65 | 66 | namespace rpc 67 | { 68 | const char crypto_compare_::url[] = 69 | "https://min-api.cryptocompare.com" 70 | "/data/price?fsym=XMR&tsyms=AUD,BRL,BTC,CAD,CHF,CNY,EUR,GBP," 71 | "HKD,INR,JPY,KRW,MXN,NOK,NZD,SEK,SGD,TRY,USD,RUB,ZAR"; 72 | 73 | expect crypto_compare_::operator()(std::string&& body) const 74 | { 75 | lws::rates out{}; 76 | const std::error_code error = wire::json::from_bytes(std::move(body), out); 77 | if (error) 78 | return error; 79 | return {std::move(out)}; 80 | } 81 | } // rpc 82 | } // lws 83 | -------------------------------------------------------------------------------- /src/wire/wrapper/trusted_array.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include "wire/traits.h" 33 | #include "wire/read.h" 34 | #include "wire/write.h" 35 | 36 | namespace wire 37 | { 38 | //! \brief Wrapper that removes read constraints 39 | template 40 | struct trusted_array_ 41 | { 42 | using container_type = wire::unwrap_reference_t; 43 | T container; 44 | 45 | const container_type& get_container() const noexcept { return container; } 46 | container_type& get_container() noexcept { return container; } 47 | 48 | // concept requirements for optional fields 49 | 50 | explicit operator bool() const noexcept { return !get_container().empty(); } 51 | trusted_array_& emplace() noexcept { return *this; } 52 | 53 | trusted_array_& operator*() noexcept { return *this; } 54 | const trusted_array_& operator*() const noexcept { return *this; } 55 | 56 | void reset() { get_container().clear(); } 57 | }; 58 | 59 | template 60 | trusted_array_ trusted_array(T value) 61 | { 62 | return {std::move(value)}; 63 | } 64 | 65 | template 66 | void read_bytes(R& source, trusted_array_ dest) 67 | { 68 | wire_read::array_unchecked(source, dest.get_container(), 0, std::numeric_limits::max()); 69 | } 70 | 71 | template 72 | void write_bytes(W& dest, const trusted_array_ source) 73 | { 74 | wire_write::array(dest, source.get_container()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/wire/read.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "wire/read.h" 29 | 30 | #include 31 | 32 | void wire::reader::increment_depth() 33 | { 34 | if (++depth_ == max_read_depth()) 35 | WIRE_DLOG_THROW_(error::schema::maximum_depth); 36 | } 37 | 38 | void wire::reader::decrement_depth() 39 | { 40 | if (!depth_) 41 | throw std::logic_error{"reader::decrement_depth() already at zero"}; 42 | --depth_; 43 | } 44 | 45 | [[noreturn]] void wire::integer::throw_exception(std::intmax_t source, std::intmax_t min, std::intmax_t max) 46 | { 47 | static_assert( 48 | std::numeric_limits::max() <= std::numeric_limits::max(), 49 | "expected intmax_t::max <= uintmax_t::max" 50 | ); 51 | if (source < 0) 52 | WIRE_DLOG_THROW(error::schema::larger_integer, source << " given when " << min << " is minimum permitted"); 53 | else 54 | throw_exception(std::uintmax_t(source), std::uintmax_t(max)); 55 | } 56 | [[noreturn]] void wire::integer::throw_exception(std::uintmax_t source, std::uintmax_t max) 57 | { 58 | WIRE_DLOG_THROW(error::schema::smaller_integer, source << " given when " << max << "is maximum permitted"); 59 | } 60 | 61 | [[noreturn]] void wire_read::throw_exception(const wire::error::schema code, const char* display, epee::span names) 62 | { 63 | const char* name = nullptr; 64 | for (const char* elem : names) 65 | { 66 | if (elem != nullptr) 67 | { 68 | name = elem; 69 | break; 70 | } 71 | } 72 | WIRE_DLOG_THROW(code, display << (name ? name : "")); 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/net/http/slice_body.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "byte_slice.h" // monero/contrib/epee/include 36 | 37 | namespace net { namespace http 38 | { 39 | //! Trait for `boost::beast` body type 40 | struct slice_body 41 | { 42 | using value_type = epee::byte_slice; 43 | 44 | static std::uint64_t size(const value_type& source) noexcept 45 | { 46 | static_assert(!std::numeric_limits::is_signed, "expected unsigned"); 47 | static_assert( 48 | std::numeric_limits::max() <= std::numeric_limits::max(), 49 | "unexpected size_t max value" 50 | ); 51 | return source.size(); 52 | } 53 | 54 | struct writer 55 | { 56 | epee::byte_slice body_; 57 | 58 | using const_buffers_type = boost::asio::const_buffer; 59 | 60 | template 61 | explicit writer(boost::beast::http::header const&, value_type const& body) 62 | : body_(body.clone()) 63 | {} 64 | 65 | void init(boost::beast::error_code& ec) 66 | { 67 | ec = {}; 68 | } 69 | 70 | boost::optional> get(boost::beast::error_code& ec) 71 | { 72 | ec = {}; 73 | return {{const_buffers_type{body_.data(), body_.size()}, false}}; 74 | } 75 | }; 76 | }; 77 | }} // net // http 78 | -------------------------------------------------------------------------------- /src/rest_server.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2019, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "db/storage.h" 38 | #include "net/net_ssl.h" 39 | #include "rpc/client.h" 40 | #include "span.h" 41 | 42 | namespace lws 43 | { 44 | struct rest_server_data; 45 | class rest_server 46 | { 47 | struct internal; 48 | template struct connection; 49 | template struct handler_loop; 50 | template struct accept_loop; 51 | 52 | std::unique_ptr global_; 53 | std::list ports_; 54 | std::vector workers_; 55 | 56 | void run_io(); 57 | 58 | public: 59 | struct configuration 60 | { 61 | epee::net_utils::ssl_authentication_t auth; 62 | std::vector access_controls; 63 | std::size_t threads; 64 | std::uint32_t max_subaddresses; 65 | epee::net_utils::ssl_verification_t webhook_verify; 66 | bool allow_external; 67 | bool disable_admin_auth; 68 | bool auto_accept_creation; 69 | bool auto_accept_import; 70 | }; 71 | 72 | explicit rest_server(epee::span addresses, std::vector admin, db::storage disk, rpc::client client, configuration config); 73 | 74 | rest_server(rest_server&&) = delete; 75 | rest_server(rest_server const&) = delete; 76 | 77 | ~rest_server() noexcept; 78 | 79 | rest_server& operator=(rest_server&&) = delete; 80 | rest_server& operator=(rest_server const&) = delete; 81 | }; 82 | } 83 | -------------------------------------------------------------------------------- /src/options.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018-2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "common/command_line.h" // monero/src 36 | #include "common/util.h" // monero/src 37 | 38 | namespace lws 39 | { 40 | constexpr const char default_db_subdir[] = "/light_wallet_server"; 41 | 42 | struct options 43 | { 44 | const command_line::arg_descriptor db_path; 45 | const command_line::arg_descriptor network; 46 | 47 | options() 48 | : db_path{"db-path", "Folder for LMDB files", tools::get_default_data_dir() + default_db_subdir} 49 | , network{"network", "<\"main\"|\"stage\"|\"test\"> - Blockchain net type", "main"} 50 | {} 51 | 52 | void prepare(boost::program_options::options_description& description) const 53 | { 54 | command_line::add_arg(description, db_path); 55 | command_line::add_arg(description, network); 56 | command_line::add_arg(description, command_line::arg_help); 57 | } 58 | 59 | void set_network(boost::program_options::variables_map const& args) const 60 | { 61 | const std::string net = command_line::get_arg(args, network); 62 | if (net == "main") 63 | lws::config::network = cryptonote::MAINNET; 64 | else if (net == "stage") 65 | lws::config::network = cryptonote::STAGENET; 66 | else if (net == "test") 67 | lws::config::network = cryptonote::TESTNET; 68 | else 69 | throw std::runtime_error{"Bad --network value"}; 70 | } 71 | }; 72 | } 73 | -------------------------------------------------------------------------------- /src/rpc/scanner/connection.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "byte_slice.h" // monero/contrib/epee/include 40 | #include "byte_stream.h" // monero/contrib/epee/include 41 | #include "rpc/scanner/commands.h" 42 | 43 | namespace lws { namespace rpc { namespace scanner 44 | { 45 | //! \brief Base class for `client_connection` and `server_connection`. Always use `strand_`. 46 | struct connection 47 | { 48 | // Leave public for coroutines `read_commands` and `write_commands` 49 | epee::byte_stream read_buf_; 50 | std::deque write_bufs_; 51 | boost::asio::ip::tcp::socket sock_; 52 | boost::asio::steady_timer write_timeout_; 53 | boost::asio::io_context::strand strand_; 54 | header next_; 55 | bool cleanup_; 56 | 57 | explicit connection(boost::asio::io_context& io); 58 | ~connection(); 59 | 60 | boost::asio::io_context& context() const { return strand_.context(); } 61 | 62 | boost::asio::ip::tcp::endpoint remote_endpoint(); 63 | 64 | //! \return ASIO compatible read buffer of `size`. 65 | boost::asio::mutable_buffer read_buffer(const std::size_t size); 66 | 67 | //! \return ASIO compatible write buffer 68 | boost::asio::const_buffer write_buffer() const; 69 | 70 | //! Cancels operations on socket and timer. Also updates `cleanup_ = true`. 71 | void base_cleanup(); 72 | }; 73 | }}} // lws // rpc // scanner 74 | -------------------------------------------------------------------------------- /src/rpc/scanner/queue.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "queue.h" 29 | 30 | #include "db/account.h" 31 | 32 | namespace lws { namespace rpc { namespace scanner 33 | { 34 | queue::status queue::do_get_accounts() 35 | { 36 | status out{ 37 | std::move(replace_), std::move(push_), user_count_ 38 | }; 39 | replace_ = std::nullopt; 40 | push_.clear(); 41 | push_.shrink_to_fit(); 42 | return out; 43 | } 44 | 45 | queue::queue() 46 | : replace_(), push_(), user_count_(0), sync_(), poll_(), stop_(false) 47 | {} 48 | 49 | queue::~queue() 50 | {} 51 | 52 | void queue::stop() 53 | { 54 | { 55 | const boost::lock_guard lock{sync_}; 56 | stop_ = true; 57 | } 58 | poll_.notify_all(); 59 | } 60 | 61 | std::size_t queue::user_count() 62 | { 63 | const boost::lock_guard lock{sync_}; 64 | return user_count_; 65 | } 66 | 67 | queue::status queue::get_accounts() 68 | { 69 | const boost::lock_guard lock{sync_}; 70 | return do_get_accounts(); 71 | } 72 | 73 | queue::status queue::wait_for_accounts() 74 | { 75 | boost::unique_lock lock{sync_}; 76 | if (!replace_ && push_.empty() && !stop_) 77 | poll_.wait(lock, [this] () { return replace_ || !push_.empty() || stop_; }); 78 | return do_get_accounts(); 79 | } 80 | 81 | void queue::replace_accounts(std::vector users) 82 | { 83 | { 84 | const boost::lock_guard lock{sync_}; 85 | replace_ = std::move(users); 86 | user_count_ = replace_->size(); 87 | push_.clear(); 88 | } 89 | poll_.notify_all(); 90 | } 91 | }}} // lws // rpc // scanner 92 | -------------------------------------------------------------------------------- /tests/unit/db/data.test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "framework.test.h" 29 | 30 | #include "db/data.h" 31 | 32 | LWS_CASE("db::data::check_subaddress_dict") 33 | { 34 | EXPECT(lws::db::check_subaddress_dict({lws::db::major_index(0), lws::db::index_ranges{}})); 35 | EXPECT(lws::db::check_subaddress_dict( 36 | { 37 | lws::db::major_index(0), 38 | lws::db::index_ranges{{lws::db::index_range{{lws::db::minor_index(0), lws::db::minor_index(0)}}}} 39 | } 40 | )); 41 | EXPECT(lws::db::check_subaddress_dict( 42 | { 43 | lws::db::major_index(0), 44 | lws::db::index_ranges{{ 45 | lws::db::index_range{{lws::db::minor_index(0), lws::db::minor_index(0)}}, 46 | lws::db::index_range{{lws::db::minor_index(2), lws::db::minor_index(10)}} 47 | }} 48 | } 49 | )); 50 | 51 | EXPECT(!lws::db::check_subaddress_dict( 52 | { 53 | lws::db::major_index(0), 54 | lws::db::index_ranges{{lws::db::index_range{{lws::db::minor_index(1), lws::db::minor_index(0)}}}} 55 | } 56 | )); 57 | EXPECT(!lws::db::check_subaddress_dict( 58 | { 59 | lws::db::major_index(0), 60 | lws::db::index_ranges{{ 61 | lws::db::index_range{{lws::db::minor_index(0), lws::db::minor_index(4)}}, 62 | lws::db::index_range{{lws::db::minor_index(1), lws::db::minor_index(10)}} 63 | }} 64 | } 65 | )); 66 | EXPECT(!lws::db::check_subaddress_dict( 67 | { 68 | lws::db::major_index(0), 69 | lws::db::index_ranges{{ 70 | lws::db::index_range{{lws::db::minor_index(0), lws::db::minor_index(0)}}, 71 | lws::db::index_range{{lws::db::minor_index(1), lws::db::minor_index(10)}} 72 | }} 73 | } 74 | )); 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/wire/fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include "common/expect.h" // monero/src 34 | 35 | //! Declare an enum to be serialized as an integer 36 | #define WIRE_AS_INTEGER(type_) \ 37 | static_assert(std::is_enum(), "AS_INTEGER only enum types"); \ 38 | template \ 39 | inline void read_bytes(R& source, type_& dest) \ 40 | { \ 41 | std::underlying_type::type temp{}; \ 42 | read_bytes(source, temp); \ 43 | dest = type_(temp); \ 44 | } \ 45 | template \ 46 | inline void write_bytes(W& dest, const type_ source) \ 47 | { \ 48 | write_bytes(dest, std::underlying_type::type(source)); \ 49 | } 50 | 51 | //! Declare an enum to be serialized as a string (json) or integer (msgpack) 52 | #define WIRE_DECLARE_ENUM(type) \ 53 | const char* get_string(type) noexcept; \ 54 | expect type ## _from_string(const boost::string_ref) noexcept; \ 55 | void read_bytes(::wire::reader&, type&); \ 56 | void write_bytes(::wire::writer&, type) 57 | 58 | //! Declare a class/struct serialization for all available formats 59 | #define WIRE_DECLARE_OBJECT(type) \ 60 | void read_bytes(::wire::reader&, type&); \ 61 | void write_bytes(::wire::writer&, const type&) 62 | 63 | namespace wire 64 | { 65 | class reader; 66 | struct writer; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/rpc/scanner/commands.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "commands.h" 29 | 30 | #include "db/account.h" 31 | #include "db/data.h" 32 | #include "wire/adapted/crypto.h" 33 | #include "wire/vector.h" 34 | #include "wire/msgpack.h" 35 | #include "wire/wrapper/trusted_array.h" 36 | 37 | namespace lws { namespace rpc { namespace scanner 38 | { 39 | namespace 40 | { 41 | template 42 | void map_initialize(F& format, T& self) 43 | { 44 | wire::object(format, WIRE_FIELD_ID(0, pass), WIRE_FIELD_ID(1, threads)); 45 | } 46 | } 47 | WIRE_MSGPACK_DEFINE_OBJECT(initialize, map_initialize); 48 | 49 | namespace 50 | { 51 | template 52 | void map_account_update(F& format, T& self) 53 | { 54 | wire::object(format, 55 | wire::optional_field<0>("users", wire::trusted_array(std::ref(self.users))), 56 | wire::optional_field<1>("blocks", wire::trusted_array(std::ref(self.blocks))) 57 | ); 58 | } 59 | } 60 | WIRE_MSGPACK_DEFINE_OBJECT(update_accounts, map_account_update) 61 | 62 | namespace 63 | { 64 | template 65 | void map_push_accounts(F& format, T& self) 66 | { 67 | wire::object(format, 68 | wire::optional_field<0>("users", wire::trusted_array(std::ref(self.users))) 69 | ); 70 | } 71 | } 72 | WIRE_MSGPACK_DEFINE_OBJECT(push_accounts, map_push_accounts); 73 | 74 | namespace 75 | { 76 | template 77 | void map_replace_accounts(F& format, T& self) 78 | { 79 | wire::object(format, 80 | wire::optional_field<0>("users", wire::trusted_array(std::ref(self.users))) 81 | ); 82 | } 83 | } 84 | WIRE_MSGPACK_DEFINE_OBJECT(replace_accounts, map_replace_accounts); 85 | }}} // lws // rpc // scanner 86 | -------------------------------------------------------------------------------- /src/net/http/client.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "byte_slice.h" // monero/contrib/epee/include 38 | #include "common/expect.h" // monero/src 39 | #include "net/net_ssl.h" // monero/contrib/epee/include 40 | 41 | namespace net { namespace http 42 | { 43 | struct client_state; 44 | using server_response_func = void(boost::system::error_code, std::string); 45 | 46 | //! Primarily for webhooks, where the response is (basically) ignored. 47 | class client 48 | { 49 | std::weak_ptr state_; 50 | std::shared_ptr ssl_; 51 | boost::mutex sync_; 52 | 53 | expect queue_async(boost::asio::io_context& io, std::string url, epee::byte_slice json_body, std::function notifier); 54 | 55 | public: 56 | explicit client(epee::net_utils::ssl_verification_t verify); 57 | explicit client(std::shared_ptr ssl); 58 | ~client(); 59 | 60 | const std::shared_ptr& ssl_context() const noexcept 61 | { return ssl_; } 62 | 63 | //! Never blocks. Thread safe. \return `success()` if `url` is valid. 64 | expect post_async(boost::asio::io_context& io, std::string url, epee::byte_slice json_body); 65 | 66 | /*! Never blocks. Thread safe. Calls `notifier` with server response iff 67 | `success()` is returned. 68 | \return `success()` if `url` is valid. */ 69 | expect get_async(boost::asio::io_context& io, std::string url, std::function notifier); 70 | }; 71 | }} // net // http 72 | 73 | -------------------------------------------------------------------------------- /src/rpc/scanner/connection.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "connection.h" 29 | 30 | #include "misc_log_ex.h" // monero/contrib/epee/include 31 | 32 | namespace lws { namespace rpc { namespace scanner 33 | { 34 | connection::connection(boost::asio::io_context& io) 35 | : read_buf_(), 36 | write_bufs_(), 37 | sock_(io), 38 | write_timeout_(io), 39 | strand_(io), 40 | next_{}, 41 | cleanup_(false) 42 | {} 43 | 44 | connection::~connection() 45 | {} 46 | 47 | boost::asio::ip::tcp::endpoint connection::remote_endpoint() 48 | { 49 | boost::system::error_code error{}; 50 | return sock_.remote_endpoint(error); 51 | } 52 | 53 | boost::asio::mutable_buffer connection::read_buffer(const std::size_t size) 54 | { 55 | assert(strand_.running_in_this_thread()); 56 | read_buf_.clear(); 57 | read_buf_.put_n(0, size); 58 | return boost::asio::mutable_buffer(read_buf_.data(), size); 59 | } 60 | 61 | boost::asio::const_buffer connection::write_buffer() const 62 | { 63 | assert(strand_.running_in_this_thread()); 64 | if (write_bufs_.empty()) 65 | return boost::asio::const_buffer(nullptr, 0); 66 | return boost::asio::const_buffer(write_bufs_.front().data(), write_bufs_.front().size()); 67 | } 68 | 69 | void connection::base_cleanup() 70 | { 71 | assert(strand_.running_in_this_thread()); 72 | if (!cleanup_) 73 | MINFO("Disconnected from " << remote_endpoint() << " / " << this); 74 | cleanup_ = true; 75 | boost::system::error_code error{}; 76 | sock_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, error); 77 | error = boost::system::error_code{}; 78 | sock_.close(error); 79 | if (error) 80 | MERROR("Error when closing socket: " << error.message()); 81 | write_timeout_.cancel(); 82 | } 83 | }}} // lws // rpc // scanner 84 | -------------------------------------------------------------------------------- /src/rpc/lws_pub.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "lws_pub.h" 29 | 30 | #include 31 | #include "db/account.h" 32 | #include "rpc/client.h" 33 | #include "rpc/webhook.h" 34 | #include "wire/adapted/crypto.h" 35 | #include "wire/wrapper/array.h" 36 | #include "wire/wrappers_impl.h" 37 | #include "wire/write.h" 38 | 39 | namespace 40 | { 41 | constexpr const char json_topic[] = "json-minimal-scanned:"; 42 | constexpr const char msgpack_topic[] = "msgpack-minimal-scanned:"; 43 | 44 | struct get_address 45 | { 46 | std::reference_wrapper user; 47 | }; 48 | 49 | void write_bytes(wire::writer& dest, const get_address& self) 50 | { 51 | wire_write::bytes(dest, self.user.get().address()); 52 | } 53 | 54 | struct minimal_scanned 55 | { 56 | std::reference_wrapper id; 57 | const lws::db::block_id height; 58 | epee::span users; 59 | }; 60 | 61 | void write_bytes(wire::writer& dest, const minimal_scanned& self) 62 | { 63 | const auto just_address = [] (const lws::account& user) 64 | { 65 | return get_address{std::cref(user)}; 66 | }; 67 | 68 | wire::object(dest, 69 | WIRE_FIELD_ID(0, height), 70 | WIRE_FIELD_ID(1, id), 71 | wire::field<2>("addresses", wire::array(self.users | boost::adaptors::transformed(just_address))) 72 | ); 73 | } 74 | } // anonymous 75 | 76 | namespace lws { namespace rpc 77 | { 78 | void publish_scanned(rpc::client& client, const crypto::hash& id, epee::span users) 79 | { 80 | if (users.empty()) 81 | return; 82 | 83 | const minimal_scanned output{ 84 | std::cref(id), users[0].scan_height(), users 85 | }; 86 | const epee::span event{std::addressof(output), 1}; 87 | zmq_send(client, event, json_topic, msgpack_topic); 88 | } 89 | }} // lws // rpc 90 | -------------------------------------------------------------------------------- /src/wire/wrapper/defaulted.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021-2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | #include "wire/field.h" 34 | #include "wire/traits.h" 35 | 36 | //! An optional field that is omitted when a default value is used 37 | #define WIRE_FIELD_DEFAULTED(name, default_) \ 38 | ::wire::optional_field( #name , ::wire::defaulted(std::ref( self . name ), default_ )) 39 | 40 | namespace wire 41 | { 42 | /*! A wrapper that tells `wire::writer`s to skip field generation when default 43 | value, and tells `wire::reader`s to use default value when field not present. */ 44 | template 45 | struct defaulted_ 46 | { 47 | using value_type = typename unwrap_reference::type; 48 | 49 | T value; 50 | U default_; 51 | 52 | constexpr const value_type& get_value() const noexcept { return value; } 53 | value_type& get_value() noexcept { return value; } 54 | 55 | // concept requirements for optional fields 56 | 57 | constexpr explicit operator bool() const { return get_value() != default_; } 58 | value_type& emplace() noexcept { return get_value(); } 59 | 60 | constexpr const value_type& operator*() const noexcept { return get_value(); } 61 | value_type& operator*() noexcept { return get_value(); } 62 | 63 | void reset() { get_value() = default_; } 64 | }; 65 | 66 | //! Links `value` with `default_`. 67 | template 68 | inline constexpr defaulted_ defaulted(T value, U default_) 69 | { 70 | return {std::move(value), std::move(default_)}; 71 | } 72 | 73 | /* read/write functions not needed since `defaulted_` meets the concept 74 | requirements for an optional type (optional fields are handled 75 | directly by the generic read/write code because the field name is omitted 76 | entirely when the value is "empty"). */ 77 | } // wire 78 | 79 | -------------------------------------------------------------------------------- /src/rpc/scanner/queue.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "db/fwd.h" 37 | #include "rpc/scanner/commands.h" 38 | 39 | namespace lws { namespace rpc { namespace scanner 40 | { 41 | //! Notifies worker thread of new accounts to scan. All functions thread-safe. 42 | class queue 43 | { 44 | public: 45 | //! Status of upstream scan requests. 46 | struct status 47 | { 48 | std::optional> replace; //!< Empty optional means replace **not** requested. 49 | std::vector push; 50 | std::size_t user_count; 51 | }; 52 | 53 | private: 54 | std::optional> replace_; 55 | std::vector push_; 56 | std::size_t user_count_; 57 | boost::mutex sync_; 58 | boost::condition_variable poll_; 59 | bool stop_; 60 | 61 | status do_get_accounts(); 62 | 63 | public: 64 | queue(); 65 | ~queue(); 66 | 67 | //! `wait_for_accounts()` will return immediately, permanently. 68 | void stop(); 69 | 70 | //! \return Total number of users given to this local thread 71 | std::size_t user_count(); 72 | 73 | //! \return Replacement and "push" accounts 74 | status get_accounts(); 75 | 76 | //! Blocks until replace or push accounts become available OR `stop()` is called. 77 | status wait_for_accounts(); 78 | 79 | //! Replace existing accounts on thread with new `users` 80 | void replace_accounts(std::vector users); 81 | 82 | //! Push/add new accounts to scan on thread 83 | template 84 | void push_accounts(T begin, T end) 85 | { 86 | { 87 | const boost::lock_guard lock{sync_}; 88 | user_count_ += (end - begin); 89 | push_.insert(push_.end(), std::make_move_iterator(begin), std::make_move_iterator(end)); 90 | } 91 | poll_.notify_all(); 92 | } 93 | }; 94 | }}} // lws // rpc // scanner 95 | -------------------------------------------------------------------------------- /src/wire/adapted/array.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include "span.h" 32 | #include "wire/error.h" 33 | #include "wire/read.h" 34 | 35 | namespace wire 36 | { 37 | // enable writing of std::array 38 | template 39 | struct is_array> 40 | : std::true_type 41 | {}; 42 | 43 | // `std::array`s of `char` and `uint8_t` are not arrays 44 | template 45 | struct is_array> 46 | : std::false_type 47 | {}; 48 | template 49 | struct is_array> 50 | : std::false_type 51 | {}; 52 | 53 | template 54 | inline void read_bytes(R& source, std::array& dest) 55 | { 56 | source.binary(epee::to_mut_span(dest)); 57 | } 58 | template 59 | inline void read_bytes(R& source, std::array& dest) 60 | { 61 | source.binary(epee::to_mut_span(dest)); 62 | } 63 | 64 | template 65 | inline void write_bytes(W& dest, const std::array& source) 66 | { 67 | source.binary(epee::to_span(source)); 68 | } 69 | template 70 | inline void write_bytes(W& dest, const std::array& source) 71 | { 72 | source.binary(epee::to_span(source)); 73 | } 74 | 75 | // Read a fixed sized array 76 | template 77 | inline void read_bytes(R& source, std::array& dest) 78 | { 79 | std::size_t count = source.start_array(0); 80 | const bool json = (count == 0); 81 | if (!json && count != dest.size()) 82 | WIRE_DLOG_THROW(wire::error::schema::array, "Expected array of size " << dest.size()); 83 | 84 | for (auto& elem : dest) 85 | { 86 | if (json && source.is_array_end(count)) 87 | WIRE_DLOG_THROW(wire::error::schema::array, "Expected array of size " << dest.size()); 88 | wire_read::bytes(source, elem); 89 | --count; 90 | } 91 | if (!source.is_array_end(count)) 92 | WIRE_DLOG_THROW(wire::error::schema::array, "Expected array of size " << dest.size()); 93 | source.end_array(); 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/rpc/scanner/commands.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "crypto/hash.h" // monero/src 34 | #include "db/fwd.h" 35 | #include "wire/msgpack/fwd.h" 36 | 37 | namespace lws { namespace rpc { namespace scanner 38 | { 39 | /* 40 | `monero-lws-daemon` is "server" and `monero-lws-scanner` is "client". 41 | */ 42 | 43 | //! \brief Data sent before msgpack payload 44 | struct header 45 | { 46 | using length_type = boost::endian::little_uint32_buf_t; 47 | header() = delete; 48 | std::uint8_t version; 49 | std::uint8_t id; 50 | length_type length; 51 | }; 52 | static_assert(sizeof(header) == 6); 53 | 54 | 55 | /* 56 | Client to server messages. 57 | */ 58 | 59 | //! \brief Inform server of info needed to spawn work to client. 60 | struct initialize 61 | { 62 | initialize() = delete; 63 | static constexpr std::uint8_t id() noexcept { return 0; } 64 | std::string pass; 65 | std::uint32_t threads; 66 | }; 67 | WIRE_MSGPACK_DECLARE_OBJECT(initialize); 68 | 69 | //! Command that updates database account records 70 | struct update_accounts 71 | { 72 | update_accounts() = delete; 73 | static constexpr std::uint8_t id() noexcept { return 1; } 74 | std::vector users; 75 | std::vector blocks; 76 | }; 77 | WIRE_MSGPACK_DECLARE_OBJECT(update_accounts); 78 | 79 | 80 | /* 81 | Server to client messages. 82 | */ 83 | 84 | //! \brief New accounts to add/push to scanning list 85 | struct push_accounts 86 | { 87 | push_accounts() = delete; 88 | static constexpr std::uint8_t id() noexcept { return 0; } 89 | std::vector users; 90 | }; 91 | WIRE_MSGPACK_DECLARE_OBJECT(push_accounts); 92 | 93 | //! \brief Replace account scanning list with this new one 94 | struct replace_accounts 95 | { 96 | replace_accounts() = delete; 97 | static constexpr const std::uint8_t id() noexcept { return 1; } 98 | std::vector users; 99 | }; 100 | WIRE_MSGPACK_DECLARE_OBJECT(replace_accounts); 101 | }}} // lws // rpc // scanner 102 | -------------------------------------------------------------------------------- /src/rpc/scanner/client.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "crypto/hash.h" // monero/src 38 | #include "db/fwd.h" 39 | #include "rpc/scanner/connection.h" 40 | #include "rpc/scanner/queue.h" 41 | 42 | namespace lws { namespace rpc { namespace scanner 43 | { 44 | //! \brief 45 | class client : public connection 46 | { 47 | const std::vector> local_; 48 | const std::string pass_; 49 | std::size_t next_push_; 50 | boost::asio::steady_timer connect_timer_; 51 | const boost::asio::ip::tcp::endpoint server_address_; 52 | bool connected_; 53 | 54 | struct close; 55 | class connector; 56 | 57 | public: 58 | using command = bool(*)(const std::shared_ptr&); 59 | 60 | //! Does not start connection to `address`, see `connect`. 61 | explicit client(boost::asio::io_context& io, const std::string& address, std::string pass, std::vector> local); 62 | 63 | client(const client&) = delete; 64 | client(client&&) = delete; 65 | ~client(); 66 | client& operator=(const client&) = delete; 67 | client& operator=(client&&) = delete; 68 | 69 | //! \return Handlers for client commands 70 | static const std::array& commands() noexcept; 71 | 72 | //! Start a connect loop on `self`. 73 | static void connect(const std::shared_ptr& self); 74 | 75 | //! Push `users` to local queues. Synchronizes with latest connection. 76 | static void push_accounts(const std::shared_ptr& self, std::vector users); 77 | 78 | //! Replace `users` on local queues. Synchronizes with latest connection. 79 | static void replace_accounts(const std::shared_ptr& self, std::vector users); 80 | 81 | //! Send `users` upstream for disk storage 82 | static void send_update(const std::shared_ptr& self, std::vector users, std::vector blocks); 83 | 84 | //! Closes socket and calls stop on `io_context`. 85 | void cleanup(); 86 | }; 87 | }}} // lws // rpc // scanner 88 | -------------------------------------------------------------------------------- /src/util/blocks.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "blocks.h" 29 | 30 | #include "cryptonote_config.h" // monero/src 31 | #include "crypto/hash-ops.h" // monero/src 32 | #include "db/storage.h" 33 | #include "error.h" 34 | #include "misc_language.h" 35 | #include "string_tools.h" 36 | 37 | namespace lws 38 | { 39 | crypto::hash get_block_longhash( 40 | const std::string& bd, const db::block_id height, const unsigned major_version, const db::storage& disk, const db::block_id cached_start, epee::span cached) 41 | { 42 | crypto::hash result{}; 43 | 44 | // block 202612 bug workaround 45 | if (height == db::block_id(202612)) 46 | { 47 | static const std::string longhash_202612 = "84f64766475d51837ac9efbef1926486e58563c95a19fef4aec3254f03000000"; 48 | epee::string_tools::hex_to_pod(longhash_202612, result); 49 | return result; 50 | } 51 | if (major_version >= RX_BLOCK_VERSION) 52 | { 53 | crypto::hash hash{}; 54 | if (height != db::block_id(0)) 55 | { 56 | const uint64_t seed_height = crypto::rx_seedheight(std::uint64_t(height)); 57 | if (cached_start <= db::block_id(seed_height)) 58 | { 59 | if (cached.size() <= seed_height - std::uint64_t(cached_start)) 60 | MONERO_THROW(error::bad_blockchain, "invalid seed_height for cache or DB"); 61 | hash = cached[seed_height - std::uint64_t(cached_start)]; 62 | } 63 | else 64 | hash = MONERO_UNWRAP(MONERO_UNWRAP(disk.start_read()).get_block_hash(db::block_id(seed_height))); 65 | } 66 | else 67 | { 68 | memset(&result, 0, sizeof(crypto::hash)); // only happens when generating genesis block 69 | } 70 | crypto::rx_slow_hash(hash.data, bd.data(), bd.size(), result.data); 71 | } else { 72 | const int pow_variant = major_version >= 7 ? major_version - 6 : 0; 73 | crypto::cn_slow_hash(bd.data(), bd.size(), result, pow_variant, std::uint64_t(height)); 74 | } 75 | return result; 76 | } 77 | 78 | bool verify_timestamp(std::uint64_t check, std::vector timestamps) 79 | { 80 | if (timestamps.empty()) 81 | return true; 82 | if(check < epee::misc_utils::median(timestamps)) 83 | return false; 84 | return true; 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/wire/wrappers_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include "wire/error.h" 32 | #include "wire/read.h" 33 | #include "wire/write.h" 34 | #include "wire/wrapper/array.h" 35 | 36 | namespace wire 37 | { 38 | // 39 | // free functions for `array_` wrapper 40 | // 41 | 42 | template 43 | inline void read_bytes(R& source, array_ wrapper) 44 | { 45 | // see constraints directly above `array_` definition 46 | static_assert(std::is_same::value, "array_ must have a read constraint for memory purposes"); 47 | } 48 | 49 | template 50 | inline void read_bytes(R& source, array_>& wrapper) 51 | { 52 | using array_type = array_>; 53 | using value_type = typename array_type::value_type; 54 | using constraint = typename array_type::constraint; 55 | static_assert(constraint::template check(), "max reserve bytes exceeded for element"); 56 | wire_read::array(source, wrapper.get_read_object(), min_element_size<0>{}, constraint{}); 57 | } 58 | template 59 | inline void read_bytes(R& source, array_>& wrapper) 60 | { 61 | using array_type = array_>; 62 | using value_type = typename array_type::value_type; 63 | using constraint = typename array_type::constraint; 64 | static_assert(constraint::template check(), "max compression ratio exceeded for element"); 65 | wire_read::array(source, wrapper.get_read_object(), constraint{}); 66 | } 67 | 68 | template 69 | inline void write_bytes(W& dest, const array_& wrapper) 70 | { 71 | wire_write::array(dest, wrapper.get_container()); 72 | } 73 | template 74 | inline void write_bytes(W& dest, const array_, D>& wrapper) 75 | { 76 | using inner_type = typename array_, D>::inner_array_const; 77 | const auto wrap = [](const auto& val) -> inner_type { return {std::ref(val)}; }; 78 | wire_write::array(dest, boost::adaptors::transform(wrapper.get_container(), wrap)); 79 | } 80 | } // wire 81 | -------------------------------------------------------------------------------- /src/rpc/daemon_pub.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "daemon_pub.h" 29 | 30 | #include "cryptonote_basic/cryptonote_basic.h" // monero/src 31 | #include "rpc/daemon_zmq.h" 32 | #include "wire/adapted/crypto.h" 33 | #include "wire/error.h" 34 | #include "wire/field.h" 35 | #include "wire/traits.h" 36 | #include "wire/json/read.h" 37 | #include "wire/wrapper/array.h" 38 | #include "wire/wrappers_impl.h" 39 | 40 | namespace 41 | { 42 | using max_txes_pub = wire::max_element_count<775>; 43 | 44 | struct dummy_chain_array 45 | { 46 | using value_type = crypto::hash; 47 | 48 | std::size_t count = 0; 49 | std::reference_wrapper id; 50 | 51 | void clear() noexcept {} 52 | void reserve(std::size_t) noexcept {} 53 | 54 | std::size_t size() const noexcept { return count; } 55 | crypto::hash& back() noexcept { return id; } 56 | void emplace_back() { ++count; } 57 | }; 58 | } 59 | 60 | namespace wire 61 | { 62 | template<> 63 | struct is_array 64 | : std::true_type 65 | {}; 66 | } 67 | 68 | namespace lws 69 | { 70 | namespace rpc 71 | { 72 | static void read_bytes(wire::json_reader& src, minimal_chain_pub& self) 73 | { 74 | dummy_chain_array chain{0, std::ref(self.top_block_id)}; 75 | wire::object(src, 76 | wire::field("first_height", std::ref(self.top_block_height)), 77 | wire::field("ids", std::ref(chain)) 78 | ); 79 | 80 | self.top_block_height += chain.count - 1; 81 | if (chain.count == 0) 82 | WIRE_DLOG_THROW(wire::error::schema::binary, "expected at least one block hash"); 83 | } 84 | 85 | expect minimal_chain_pub::from_json(std::string&& source) 86 | { 87 | minimal_chain_pub out{}; 88 | std::error_code err = wire::json::from_bytes(std::move(source), out); 89 | if (err) 90 | return err; 91 | return {std::move(out)}; 92 | } 93 | 94 | static void read_bytes(wire::json_reader& source, full_txpool_pub& self) 95 | { 96 | wire_read::bytes(source, wire::array(std::ref(self.txes))); 97 | } 98 | 99 | expect full_txpool_pub::from_json(std::string&& source) 100 | { 101 | full_txpool_pub out{}; 102 | std::error_code err = wire::json::from_bytes(std::move(source), out); 103 | if (err) 104 | return err; 105 | return {std::move(out)}; 106 | } 107 | } 108 | } 109 | --------------------------------------------------------------------------------