Bladeren bron

Update to latest libs.

Shomari 2 maanden geleden
bovenliggende
commit
4df406fdca
1 gewijzigde bestanden met toevoegingen van 16 en 56 verwijderingen
  1. 16 56
      web/stores/game/rollDice.ts

+ 16 - 56
web/stores/game/rollDice.ts

@@ -1,11 +1,13 @@
 /* Import modules. */
-import { sendCoin } from '@nexajs/purse'
+import { sendCoins } from '@nexajs/purse'
+
+import { encodeNullData } from '@nexajs/script'
 
 import { useWalletStore } from '@/stores/wallet'
 
 export default async function () {
     const Wallet = useWalletStore()
-    
+
     /* Validate play address. */
     if (!this.address) {
         throw new Error('Missing play address.')
@@ -20,57 +22,29 @@ export default async function () {
     const receivers = []
 
     /* Initialize user data. */
-    let userData = `NEXA.games~${this.authHash}`
+    const userData = [
+        'NEXA.games',
+        this.authHash,
+    ]
+    console.log('AUTH HASH', this.authHash)
+
+    /* Initialize hex data. */
+    const nullData = encodeNullData(userData)
+    // console.log('HEX DATA', nullData)
 
     /* Validate user data. */
     if (userData) {
         console.log('USER DATA', userData)
 
-        /* Initialize hex data. */
-        let hexData = ''
-
-        /* Convert user data (string) to hex. */
-        for (let i = 0; i < userData.length; i++) {
-            /* Convert to hex code. */
-            let code = userData.charCodeAt(i).toString(16)
-
-            if (userData[i] === '~') {
-                code = '09'
-            }
-
-            /* Add hex code to string. */
-            hexData += code
-        }
-        console.log('HEX DATA', hexData)
-
         // TODO Validate data length is less than OP_RETURN max (220).
 
         /* Add OP_RETURN data. */
         receivers.push({
-            data: hexData,
+            data: nullData,
         })
     }
 
-    /* Filter out ANY tokens & spent. */
-    // FIXME We should probably do something better than this, lol.
-    // const coins = Wallet.coins.filter(_coin => {
-    //     /* Initialize flag. */
-    //     let isValid = true
-    //
-    //     if (_coin.satoshis <= Wallet.DUST_LIMIT) {
-    //         /* Set flag. */
-    //         isValid = false
-    //     }
-    //
-    //     if (Wallet.spentCoins.includes(_coin.outpoint)) {
-    //         /* Set flag. */
-    //         isValid = false
-    //     }
-    //
-    //     /* Return flag. */
-    //     return isValid
-    // })
-    console.log('\n  Coins:', Wallet.coins)
+    console.log('\n  Coins:', Wallet.wallet.coins)
 
     // /* Calculate the total balance of the unspent outputs. */
     // const unspentSatoshis = coins
@@ -96,22 +70,8 @@ export default async function () {
     })
     console.log('\n  Receivers:', receivers)
 
-    // /* Calculate change value. */
-    // const changeVal = unspentSatoshis - this.satoshis - feeEstimate
-
-    /* Handle (automatic) change. */
-    // if (changeVal > Wallet.DUST_LIMIT) {
-    //     receivers.push({
-    //         address: Wallet.address,
-    //         satoshis: changeVal,
-    //     })
-    // }
-
-    /* Set automatic fee (handling) flag. */
-    // const autoFee = false
-
     /* Send UTXO request. */
-    const response = await sendCoin(Wallet.coins, receivers)
+    const response = await sendCoins(Wallet.wallet.coins, receivers)
     console.log('Send UTXO (response):', response)
 
     try {