Daan4 / nano-pool-wallet

Nano currency pool wallet proof of concept

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nano-pool-wallet

Rust

Proof of concept; work in progress; no guarantees given as per the license; should only be used for educational purposes

Also check out the Feeless project: https://github.com/feeless/feeless , which was a helpful resource for creating this project. Specifically for figuring out how to do the key derivations using Rust.

Introduction

A nano currency wallet that consists of one main account and a pool of accounts. Pool accounts are used for transactions going in/out of the main account. A pool address is reserved for each specific transaction, either for a send of any amount, for a receive of any amount, or for a receive of a specific amount. Any unexpected balances found in pool accounts are automatically sweeped to the main wallet.

The main purpose of this wallet is for identifying incoming payments without requiring an external api. By reserving a unique address for each one for the duration of the transaction the wallet owner will be able to tell which transaction is paid for (for example in the case where you are expecting two payments for two sales of the same amount).

By using a pool wallet like this you can also distribute several accounts and have them automatically connected to a main account ("hot wallet"), by routing any incoming/outgoing transactions to/from the main account. The pool accounts are generated by incrementing the account index (the main account uses index 0), so they can be pre-generated and distributed.

Sending

The balance is sent from the main account to a free pool account. If no free pool account exists a new one will be generated. Then the balance is sent from the pool account to the destination address. Finally the pool account is freed to be used for other transactions.

Receiving any amount

A free pool account is reserved, if no free account exists a new one will be generated. The reserved pool account address should be shared with the sender. As soon as any amount is received it is sent to the main account and the pool account will be freed. If no amount is received within a given time a timeout will occur and the pool account is freed.

Receiving a specific amount

A free pool account is reserved, if no free account exists a new one will be generated. The reserved pool account address should be shared with the sender. As soon as the specified amount is received it is sent to the main account and the pool account will be freed. If the amount is not received within a given time a timeout will occur and the pool account is freed.

Dev Environment Setup on Windows using WSL2 / Docker

Personally I use VSC with the Remote - WSL extension to run it in WSL2. The node container runs in WSL2, and the work server runs on the Windows host. The nano node is ran in a private dev network, where the genesis account is set up as the node rep wallet. (https://nanojson.medium.com/how-to-set-up-a-single-nano-dev-network-node-568f6a09978)

  1. Install WSL2 (https://docs.microsoft.com/en-us/windows/wsl/install)

  2. Install Docker Desktop arrrrrrrrrrnd setup the WSL2 backend (https://docs.docker.com/desktop/windows/wsl/)

  3. Allow WSL2 through the Windows firewall to connect with the Windows host (required to communicate with the work server, or to use the main/beta/test networks instead of the dev network)

  4. Run nano node; replace the tag by the latest release version (https://github.com/nanocurrency/nano-node)

sudo docker run --restart=unless-stopped -d \
  -p 44000:44000 \
  -p 44000:44000/udp \
  -p 45000:45000 \
  -p 47000:47000 \
  -v ~/nano/dev:/root \
  --entrypoint '/usr/bin/entry.sh' \
  --name nano-dev \
  nanocurrency/nano-test:V23.0RC1 \
  nano_node --daemon --network dev
  1. Change node config settings & restart the container (note: with this setup the config files are created in the NanoTest folder, while all other files are in the NanoDev folder and they have to be moved manually). Permissions have to be updated to access files in these folders
cd ~/nano/dev
sudo chmod -R 755 NanoTest
sudo chmod -R 755 NanoDev
sudo vim NanoTest/config-node.toml # make changes below
sudo vim NanoTest/config-rpc.toml # make changes below
docker restart nano-dev
# In config-node.toml
# Note that the vEthernet ip changes every time windows is restarted as of writing
node.work_peers = ["::ffff:<vEthernet WSL ip>:1000"]
node.work_threads = 0
node.websocket.address = "::ffff:0.0.0.0"
node.websocket.enable = true
node.enable_voting = true
rpc.enable = true

# In config-rpc.toml
address = "::ffff:0.0.0.0"
enable_control = true
  1. Run nano work server (https://github.com/nanocurrency/nano-work-server)
.\nano-work-server.exe --gpu 0:0 --listen-address <vEthernet WSL ip>:1000
  1. Set up the node representative. After this Nault or RPC can be used to fund dev / test accounts from the genesis account.
curl -d '{ "action" : "wallet_create" }' 127.0.0.1:45000
curl -d '{ "action" : "wallet_add", "wallet": "<wallet id returned by previous action>", "key": "34F0A37AAD20F4A260F0A5B3CB3D7FB50673212263E58A380BC10474BB039CE4"}' 127.0.0.1:45000

Run program

cargo run

Run all tests

RUST_ENV=TEST cargo test

Run tests that don't require a node

RUST_ENV=TEST cargo test no_node_required

About

Nano currency pool wallet proof of concept

License:MIT License


Languages

Language:Rust 100.0%