Explorar o código

Fix "sender" endcoding.

Shomari hai 2 meses
pai
achega
8f2ef40161
Modificáronse 2 ficheiros con 18 adicións e 17 borrados
  1. 12 4
      gamesdb/handlers/_getSender.js
  2. 6 13
      gamesdb/handlers/wallet.js

+ 12 - 4
gamesdb/handlers/_getSender.js

@@ -7,7 +7,11 @@ import {
 } from '@nexajs/crypto'
 
 import { getTransaction } from '@nexajs/rostrum'
-import { encodeDataPush } from '@nexajs/script'
+
+import { 
+    encodeDataPush,
+    OP,
+} from '@nexajs/script'
 
 import {
     binToHex,
@@ -38,13 +42,17 @@ export default async (_unspent) => {
     const publicKeyHash = ripemd160(sha256(scriptPushPubKey))
     // console.log('PUBLIC KEY HASH (hex)', binToHex(publicKeyHash))
 
-    const pkhScript = hexToBin('17005114' + binToHex(publicKeyHash))
-    // console.info('  Public key hash Script:', binToHex(pkhScript))
+    const scriptPubKey = new Uint8Array([
+        OP.ZERO,
+        OP.ONE,
+        ...encodeDataPush(publicKeyHash),
+    ])
+    // console.info('\n  Script Public Key:', binToHex(scriptPubKey))
 
     const address = encodeAddress(
         'nexa',
         'TEMPLATE',
-        pkhScript,
+        scriptPubKey,
     )
     // console.info('ADDRESS', address)
 

+ 6 - 13
gamesdb/handlers/wallet.js

@@ -5,12 +5,7 @@ import PouchDB from 'pouchdb'
 import { listUnspent } from '@nexajs/address'
 import { sha256 } from '@nexajs/crypto'
 import { encodePrivateKeyWif } from '@nexajs/hdnode'
-
-import {
-    buildCoins,
-    sendCoins,
-} from '@nexajs/purse'
-
+import { sendCoin } from '@nexajs/purse'
 import { encodeNullData } from '@nexajs/script'
 import { hexToBin } from '@nexajs/utils'
 import { Wallet } from '@nexajs/wallet'
@@ -135,7 +130,7 @@ export default async (_queue, _pending) => {
             wif: encodePrivateKeyWif(pk2, 'mainnet'),
         }
         coins.unshift(playerCoin)
-        console.log('\n  Coins-2:', coins)
+        // console.log('\n  Coins-2:', coins)
 
         /* Calculate the total balance of the unspent outputs. */
         const unspentSatoshis = coins
@@ -145,11 +140,11 @@ export default async (_queue, _pending) => {
         // console.log('UNSPENT SATOSHIS', unspentSatoshis)
 
         const userData = `NEXA.games~${payment.id}`
-        console.log('USER DATA', userData)
+        // console.log('BLOCKCHAIN DATA', chainData)
 
         /* Initialize hex data. */
         const nullData = encodeNullData(userData)
-        console.log('HEX DATA', nullData)
+        // console.log('HEX DATA', nullData)
 
         // NOTE: 150b (per input), 35b (per output), 10b (misc)
         // NOTE: Double the estimate (for safety).
@@ -180,10 +175,8 @@ export default async (_queue, _pending) => {
         console.log('\n  Receivers:', receivers)
 
         /* Send UTXO request. */
-        // response = await sendCoins(coins, receivers)
-        response = await buildCoins(coins, receivers)
-        // console.log('Send UTXO (response):', response)
-        return console.log('BUILD UTXO (raw):', response.raw)
+        response = await sendCoin(coins, receivers)
+        console.log('Send UTXO (response):', response)
 
         try {
             txResult = JSON.parse(response)