1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /* Import modules. */
- import {
- ripemd160,
- sha256,
- } from '@nexajs/crypto'
- import { binToHex } from '@nexajs/utils'
- /* Initialize stores. */
- import { useProfileStore } from '@/stores/profile'
- /**
- * Request a New Game
- *
- * Calls game engine, with player parameters, to receive a new game id.
- */
- export default async function () {
- /* Set Nexa Games endpoint. */
- const ENDPOINT = 'https://nexa.games'
- const Profile = useProfileStore()
- /* Set RPC method. */
- const method = 'POST'
- /* Validate requested payout. */
- if (this.payout === null) {
- throw new Error('Request a payout value to continue.')
- }
- /* Validate (player) position. */
- if (this.position === null) {
- throw new Error('Select a player position to continue.')
- }
- /* Validate player seed. */
- if (this.seed === null) {
- throw new Error('Set a player-defined seed to continue.')
- }
- /* Set payout for house participants (as a percentage %). */
- // NOTE: All participant shares must total 100.
- // NOTE: At least 1 participant is required.
- const house = [{
- // NEXA.games: 0.5% is automatically subtracted from the house edge
- // value shown above to cover game engine & blockchain fees.
- // 'PUT_A_VALID_NEXA_ADDRESS_HERE': 40, // Gamemaker -- TEMP FOR DEV
- // 'PUT_A_VALID_NEXA_ADDRESS_HERE': 40, // Bankers -- TEMP FOR DEV
- // 'PUT_A_VALID_NEXA_ADDRESS_HERE': 20, // Promoter -- TEMP FOR DEV
- }]
- /* Create RPC body. */
- const body = {
- gameid: this.gameid,
- playerid: Profile.playerid,
- payout: this.payout,
- seed: this.seed,
- position: this.position,
- rtp: this.rtp,
- house,
- }
- /* Request game play. */
- const response = await $fetch(ENDPOINT + '/v1/play', {
- method,
- body,
- }).catch(err => console.error(err))
- console.info('Gameplay details:', response)
- /* Set play id. */
- this.setPlayid(response?.playid)
- /* Set (play) address. */
- this.setAddress(response?.address)
- /* Build authorization value. */
- const authValue = `${this.playid}:${this.rtp}:${this.payout}:${this.position}:${this.seed}`
- // console.log('AUTH VALUE', authValue)
- /* Double-hash authorization value. */
- this.setAuthHash(binToHex(ripemd160(sha256(authValue), 'binary')))
- // console.log('AUTH HASH', this.authHash)
- }
|