wezrule / UE4NanoPlugin

Plugin for integrating the feeless and instant Nano cryptocurrency into Unreal Engine 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UE4NanoPlugin

Plugin for integrating the Nano cryptocurrency into the Unreal Engine 4.

Tested on Windows/Linux/MacOS/Android/iOS with Unreal Enginge 4.25.3

Features include: functions for processing blocks, creating seeds + reading/saving them to disk in password-protected encrypted files. Generating qr codes, listening for payments to single accounts, private key payouts and many more

How to test the plugin:

1 - git clone https://github.com/wezrule/UE4NanoPlugin
2 - Open the project UENano.uproject (if there is an error then right click and generate project files, open up and build manually)
3 - The rpc/websocket settings are located in NanoGameInstance blueprint (leave unchanged to use the publically available servers)
4 - Run the map, first create a seed then top up the account and try all the other functions (a video is coming soon demonstrating this)

The test level:
Windows1
Video explaining the test level:
https://youtu.be/RTD2b78X1oc

How to add the plugin to your project

  1. Copy Plugins folder to an Unreal Engine project root directory.
  2. Build your project

To run your own test servers (recommended for any intense testing)

Requires a nano node, npm and nodejs installed.

  1. Run the nano_node after enabling rpc and websocket in config-node.toml file. nano_node --daemon
  2. cd TestServer
  3. Modify the config.js settings to be applicable for your system.
  4. npm install
  5. node server.js

A nano node is required to be running which the websocket & http server (for RPC request) will talk with. Websocket & RPC should be enabled in the node-config.toml nano file. A http server (for RPC requests) is definitely needed for communicating with the nano node via JSON-RPC, a test node.js server is supplied for this called server.js. A websocket server to receive notifications from nano network is highly recommended to make the most use of the plugin functionality. Another test server called websocket_node.js is supplied for this, both are found in the ./TestServer directory. Running server.js will also run websocket_node.js. The websocket script makes 2 connections to the node, 1 is filtered output and 1 gets all websocket events (usual for visualisers). If you only need filtered output (recommended!) then disable allow_listen_all=false in config.js.

NanoBlueprintLibrary.cpp contains various generic functions such as creating seeds, encrypting/decrypting them using AES with a password, converting to accounts, converting between Raw and Nano and various other things.
NanoWebsocket.cpp maintains the websocket connection to the proxies. NanoManager.cpp is where the other functionality is located

Video explaining how to integrate the plugin:
https://youtu.be/HC_ps_8i-m8

Some notes when hooking the plugin into your game

Anything with *WaitForConfirmation in the name requires that the account being utilised has been Watched. This means that the websocket filtered connection is listening for events for this account, this creates a better user experience as websocket events are received as soon as the node processing them. All these functions have fallback methods which involve polling the node periodically (generally every 5 seconds). Anything taking a Websocket argument doesn't require explicit listening (such as the listening payment and payout functions). For watching (and unwatching an account):
WatchUnwatch

All setups should set the rpc url, the plugin is pretty useless without an RPC connection, set it after creating the object: NanoManagerConstruct

Following that construct the websocket and call SetupFilteredConfirmationMessageWebsocketListener, the last step is crucial as it listens to the websocket and fires off the various delegates which are bounded. The websocket connection will continuously attempt to reconnect if connection is lost, but will never call OnConnect again (this is to prevent some re-initialization errors seen in plugin implementations) NanoWebsocketConstruct

Always check the Error boolean in all event responses, e.g:
errors

Recommendation setups for:

Arcade machines

Listen to payment - Have 1 seed per arcade machine, start at first index then increment each time a payment is needed. This only checks pending blocks, don't have anything else pocketing these funds automatically. Every time a new payment is needed, move to the next index. Only 1 payment can be listening at any 1 time!
Create a QR code for the account/amount required:
CreateQRcodeAccount
It looks like this:
qrcode
Then listen for the payment:
ListenPaymentCancel
For payouts do a similar process with showing a QR Code (use the variant taking a private key), and listen for payout:
ListenPayoutAndCancel

Single player

Create seed for player and store it encrypted with password (also check for local seed files if they want to open them)
CreateSeed

Loop through seed files:
LoopThroughSeedFiles

Save seed:
Save seed

Send and wait for confirmation:
sendwaitconfirmation

Multiplayer

Process seed (as above) Create block locally and hand off to server
Step1Server
Server does validation (checks block is valid) then does appropriate action
Step2Server

Utility functions

Automatically pocket any pending funds AutomaticallyPocketUnpocket

Listen to all websocket confirmations ListenUnlistenAllConfirmation

Other functions

Create a block:
MakeBlock

Generate work:
WorkGenerate

Get pending blocks:
Pending

Process a block:
ProcessWithBlock

Get the account frontier (Note: is the account doesn't exist yet, the frontier points to the account, if wanting to use this result as a "previous", need to check if it exists the account and if so branch and change to 0!: AccountFrontier

Getting a wallet balance:
GetWalletBalance

Checking if a block is confirmed:
blockConfirmed

Nano unit functions

NanoUnitFuncs

Debug only (unless making a faucet)

Request nano:
requestnano

A video showing the plugin integrated with the ActionRPG sample game https://www.youtube.com/watch?v=gMtzOkaNnXc
A playable multiplayer game with Nano integrated: https://unreal.nanos.cc/

Limitations

  • The test servers should not be used in production due to lack of security/ddos protection. Likely canditates for a future version are the NanoRPCProxy.
  • Only supports state blocks (v1)
  • RawToNano blueprint function does not check locale and always outputs a decimal point (.), but NanoToRaw does accept both commar (,) and period (.).
  • File permissions are always requested on Android/iOS. Also unsure if seed fields won't always remain after uninstalling the app.
  • Not tested on other platforms like consoles
  • UNanoManager & UWebsocketManager must be GameInstance variables to maintain connections between levels.

Where are AES encrypted files stored?

Windows
C:\Users\<user>\AppData\Local\NanoGames

Linux
/home/<user>/NanoGames

MacOS
/Users/<user>/Library/NanoGames

Other (e.g Android/iOS)
<project folder>/NanoGames

Working on various other platforms:
AndroidPlay
Screenshot from 2020-10-29 17-42-33 MacEditor

You can of course also use this in C++ projects.

Any donation contributions are welcome: nano_15qry5fsh4mjbsgsqj148o8378cx5ext4dpnh5ex99gfck686nxkiuk9uouy download

About

Plugin for integrating the feeless and instant Nano cryptocurrency into Unreal Engine 4


Languages

Language:Objective-C 85.2%Language:C 8.0%Language:C++ 6.2%Language:JavaScript 0.4%Language:C# 0.1%