No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app update app controller use default price for each pay call like SDK de… Apr 16, 2018
bin init commit Apr 10, 2018
config update readme Apr 16, 2018
db init commit Apr 10, 2018
lib init commit Apr 10, 2018
log init commit Apr 10, 2018
public ignore dev-wallet file and update readme Apr 16, 2018
test init commit Apr 10, 2018
tmp init commit Apr 10, 2018
vendor init commit Apr 10, 2018
.gitignore Update deps Nov 8, 2018
Dockerfile Dockerfile Apr 28, 2018
Gemfile Update deps to fix multiple security vulnerabilities Nov 16, 2018
Gemfile.lock Update deps to fix multiple security vulnerabilities Nov 16, 2018
README.md update readme client side code docs Apr 19, 2018
Rakefile init commit Apr 10, 2018
config.ru init commit Apr 10, 2018
package.json init commit Apr 10, 2018

README.md

Mobius Floppy Bird DApp

Sample Mobius DApp Store application implemented using Ruby and the Mobius DApp Store Ruby SDK.

Setup

  1. Run:
bundle
mobius-cli create dev-wallet
mv dev-wallet.html public/
  1. Start the server with rails s

  2. Open http://localhost:3000/dev-wallet.html and copy the Application Private Key.

  3. Open config/secrets.yml and paste the secret key in the shared/app/secret_key value.

shared:
  app:
    secret_key: PASTE_SECRET_KEY_HERE
    jwt_secret: 431714aa54beec753975eaffba3db12d43d4ee52cafeb3ddcdbea05903e3a3ee78ff1f49d56b23df16597bc15f6d6099aef2f668aa38f957ffc960a5445aa8fb
  1. Stop the server (Ctrl + C)

Testing

  1. Start the server with rails s

  2. Visit http://localhost:3000/dev-wallet.html

  3. Click Open under Normal Account.

  4. Play Floppy Bird! Note when you click to start playing there is a pause of a couple seconds because it is in real-time making a blockchain payment! In a real app you would withdraw a larger number of MOBI at once to have some locally on deposit for the user to charge against.

Code Overview

Server Side

The server side code is very simple and is copied from the Mobius DApp Store Ruby SDK.

There are two parts to the server code:

  1. Authentication - located in app/controllers/auth_controller.rb

  2. Payment - located in app/controllers/app_controller.rb

Both are documented in the Mobius DApp Store Ruby SDK.

Client Side

The client side code is similarly very simple. It started as a fork of https://github.com/nebez/floppybird/ and is located in public/flappy_bird.

To add MOBI payment support we made the following changes

index.html:

  1. We added a div #credits_balance on line 41 to show info such as the player's current MOBI balance.

main.js.

  1. The code expects the token value used to identify this user to be passed in via the URL token parameter and we save it in a new variable g_token on line 69

  2. In the $(document).ready callback function on line 87 we get the player's balance from the server by calling the /balance endpoint and pass in the g_token value to identify the current player. The #credits_balance div is updated with the value on response.

  3. On line 141 we create a new startGame function that delays starting a new game until payment is successful. On successful payment it calls startGameReal the original startGame function.

In the startGame function on line 148 we updated the #credits_balance div to say "Paying........."

On line 150 the pay server call is made passing g_token to identify the player. If payment is successful the game is started by calling startGameReal on line 154.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mobius-network/mobius-client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Mobius::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.