|
@@ -1,11 +1,13 @@
|
|
/* Import modules. */
|
|
/* Import modules. */
|
|
-import { sendCoin } from '@nexajs/purse'
|
|
|
|
|
|
+import { sendCoins } from '@nexajs/purse'
|
|
|
|
+
|
|
|
|
+import { encodeNullData } from '@nexajs/script'
|
|
|
|
|
|
import { useWalletStore } from '@/stores/wallet'
|
|
import { useWalletStore } from '@/stores/wallet'
|
|
|
|
|
|
export default async function () {
|
|
export default async function () {
|
|
const Wallet = useWalletStore()
|
|
const Wallet = useWalletStore()
|
|
-
|
|
|
|
|
|
+
|
|
/* Validate play address. */
|
|
/* Validate play address. */
|
|
if (!this.address) {
|
|
if (!this.address) {
|
|
throw new Error('Missing play address.')
|
|
throw new Error('Missing play address.')
|
|
@@ -20,57 +22,29 @@ export default async function () {
|
|
const receivers = []
|
|
const receivers = []
|
|
|
|
|
|
/* Initialize user data. */
|
|
/* 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. */
|
|
/* Validate user data. */
|
|
if (userData) {
|
|
if (userData) {
|
|
console.log('USER DATA', 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).
|
|
// TODO Validate data length is less than OP_RETURN max (220).
|
|
|
|
|
|
/* Add OP_RETURN data. */
|
|
/* Add OP_RETURN data. */
|
|
receivers.push({
|
|
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. */
|
|
// /* Calculate the total balance of the unspent outputs. */
|
|
// const unspentSatoshis = coins
|
|
// const unspentSatoshis = coins
|
|
@@ -96,22 +70,8 @@ export default async function () {
|
|
})
|
|
})
|
|
console.log('\n Receivers:', receivers)
|
|
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. */
|
|
/* Send UTXO request. */
|
|
- const response = await sendCoin(Wallet.coins, receivers)
|
|
|
|
|
|
+ const response = await sendCoins(Wallet.wallet.coins, receivers)
|
|
console.log('Send UTXO (response):', response)
|
|
console.log('Send UTXO (response):', response)
|
|
|
|
|
|
try {
|
|
try {
|