Transaction

28c4bdad0c774d557a7a3a9ba68c92108851a148a2b3de980edd88f2a11683e2
( - )
179,083
2021-06-25 12:25:23
1
16,302 B

3 Outputs

Total Output:
  • jrun cryptofightsM©>{"in":0,"ref":["b08d48af3b3620afd877ba969c6a1e60a204e8456aa7e8ba7e8e68aa0d479561_o1","047c84687ebaa8379c5b60d3ed78a10ed310f47672e3a836b60fc1c455704c9f_o1","d6edec4a1c79ea975d3fe3608ddaccb9a3e5d69d908114055c8b7733deb9b134_o1","24da7c843b463f23e1e0cc9a73f4d95202b330194bcc100ee79edc90f78a0f8b_o1","9125fb2bf949e8f7c6f32401c9fbe1ed724528afdb9fe93a556edc28f6c3a911_o1","49932fba5a7a47d91cd61007a993eaefaf12b99344ab1240419aab2ab0eed6db_o1","5b259cd9534b3c87b7c205b7f7f62e490535f3b9aec97ae59d6289355b99df15_o1","da809888cd16b26b14db1c26bc3b894fc2d3322be5b13871b4e72bb4625b580e_o1","9f0e192f744258c3484a1c19fa88ef68e46ee6cf75acc78cfe2ad5a0d2340d0e_o1","42289e099b0bf4c28d36d7041004662c7413529905d0b1977fcef0602da4f33b_o1","aa2ebcab82c10e20f2f8cb0751fc5e1692252ce71fe3ba62c75a984da7d8e1f9_o1"],"out":["d8993ef2880a4d9da67e273527a3d0ea3833a135be15c3a4b3c13a12f2451783"],"del":[],"cre":["n2Bd4cWhEQK1aVjb1R7EBGV9mrw3etvSdC"],"exec":[{"op":"DEPLOY","data":["class ClientAgent extends Agent {\n async init() {\n this.jigHandlers.set(Fighter.origin, this.onFighter);\n this.jigHandlers.set(FyxItem.origin, this.onItem);\n\n this.messageHandlers.set('BattleFound', () => this.emit('client', 'BattleFound'));\n this.messageHandlers.set('BattleCreated', this.onBattleCreated);\n this.messageHandlers.set('BattleUpdated', this.onBattleUpdated);\n this.messageHandlers.set('BattleCompleted', this.onBattleCompleted);\n this.messageHandlers.set('ActionError', this.onActionError);\n this.messageHandlers.set('ExitQueue', this._exitQueue);\n this.messageHandlers.set('SignBattle', this.signBattle);\n this.messageHandlers.set('QueueStatus', this._queueStatus);\n this.messageHandlers.set('Requeue', this._enqueue);\n\n this.eventHandlers.set('Act', this.Act);\n this.eventHandlers.set('EnterQueue', this.EnterQueue);\n this.eventHandlers.set('ExitQueue', this.ExitQueue);\n this.eventHandlers.set('Forfeit', this.Forfeit);\n this.eventHandlers.set('SimulateFighterState', this.SimulateFighterState);\n this.eventHandlers.set('SimulateFightersState', this.SimulateFightersState);\n this.eventHandlers.set('GetItems', this.GetItems);\n this.eventHandlers.set('GetLastBattleUpdated', this.GetLastBattleUpdated);\n \n this.eventHandlers.set('LevelUp', this.LevelUp);\n\n const url = `${Config.baseUrl}/cryptofights/lobbies`;\n console.log(`Fetching lobbies: ${url}`);\n const {data: lobbies} = await this.lib.axios(url);\n this.lobbies = lobbies;\n console.log(`Lobbies: ${JSON.stringify(this.lobbies)}`);\n\n this.battle = {};\n this.battleUpdates = {};\n this.emit('subscribe', 'QueueStatus');\n }\n\n onFighter(fighter) {\n this.emit('client', 'FighterUpdated', fighter.toObject());\n }\n\n onItem(item) {\n this.emit('client', 'ItemUpdated', item.toObject());\n }\n\n async onBattleCreated(message) {\n const { id, origin } = message.payloadObj;\n if(!this.battle || id !== this.battle.id) return;\n delete this.queueMessage;\n\n\n this.addToQueue(async () => {\n const battle = await this.wallet.loadJig(origin);\n this.emit('client', 'BattleCreated', battle.toObject());\n \n this.battle.states.forEach((state) => {\n if(!state) return;\n this.emit('client', 'BattleUpdated', state);\n });\n });\n \n }\n\n _queueStatus(message) {\n this.emit('client', 'QueueStatus', message.payload);\n }\n\n async onBattleUpdated(message) {\n console.log(`BattleUpdated: ${message.payload}`);\n const state = message.payloadObj;\n\n if(!this.battle || state.battleId !== this.battle.id) return;\n this.addToQueue(async () => {\n this.updateBattle(state);\n });\n }\n\n updateBattle(state) {\n console.log('updateBattle', JSON.stringify(state));\n this.battle.states[state.turnCount] = state;\n if(state.turnCount <= this.battle.turnCount) return;\n this.battle.turnCount = state.turnCount;\n this.battlePromise = this.wallet.loadJig(state.location);\n this.emit('client', 'BattleUpdated', state);\n }\n\n async onBattleCompleted(message) {\n const { origin } = message.payloadObj;\n // const battleData = message.payloadObj;\n await this.addToQueue(async () => {\n const { data: battleData} = await this.lib.axios(`${Config.baseUrl}/battles/${origin}`);\n \n if(battleData.victor.userId === this.wallet.handle) {\n const battle = await this.wallet.loadJig(battleData.location);\n const { fighter } = battle.victor;\n await fighter.sync();\n fighter.recordVictory(battle);\n await fighter.sync();\n this.onFighter(fighter);\n }\n delete this.battle;\n \n this.emit('client', 'BattleCompleted', battleData);\n console.log(`BattleCompleted: ${JSON.stringify(battleData)}`);\n });\n }\n\n async signBattle(message) {\n console.log('signBattle');\n if (!this.queueMessage || !message.context.includes(this.queueId)){\n console.log('Invalid Queue:', this.queueMessage, this.queueId);\n return;\n }\n delete this.queueMessage;\n const { id, rawtx, paths } = message.payloadObj;\n console.log(`Client-Agent - signBattle: id = ${id}, rawtx = ${rawtx}`);\n const { Br, Tx} = this.bsv;\n let tx = this.bsv.Tx.fromHex(rawtx);\n console.log(`Client-Agent - signBattle: tx = ${tx}`);\n const outputs = await Promise.all(tx.txIns.map(async txIn => {\n const txid = new Br(txIn.txHashBuf).readReverse().toString('hex');\n const outTx = Tx.fromHex(await this.blockchain.fetch(txid));\n return {\n location: `${txid}_o${txIn.txOutNum}`,\n script: outTx.txOuts[txIn.txOutNum].script.toString(),\n };\n }));\n console.log('OUTPUTS:', JSON.stringify(outputs, null, 2));\n const t = await this.wallet.loadTransaction(rawtx);\n console.log(`Executed wallet.loadTransaction.`); // Added debug log #1\n this.emit('setDerivations', paths);\n const newRawTx = await t.export({sign: true, pay: false});\n console.log(`Executed t.export.`);// Added debug log #4\n tx = this.bsv.Tx.fromHex(newRawTx);\n console.log(`Executed this.bsv.Tx.fromHex(newRawTx).`);// Added debug log #5\n let sigs = tx.txIns.map(txIn => txIn.scriptVi.toNumber() && txIn.script.toString());\n console.log('SIGS AFTER:', sigs);\n\n this.battle = {\n id,\n turnCount: -1,\n states: [],\n actLocations: new Set()\n };\n console.log('this.battle set', this.battle);\n const sigMessage = this.wallet.buildMessage({\n to: [message.from],\n subject: 'BattleSigned',\n context: [id],\n payload: JSON.stringify({\n id,\n sigs\n })\n });\n await this.blockchain.sendMessage(sigMessage);\n }\n\n async Act(request) {\n console.log('Act', JSON.stringify(request));\n const { actionIndex, stateLocation } = request;\n const battle = await this.battlePromise;\n if(!battle) throw new FyxError(400, 'Invalid battle:', stateLocation);\n if(battle.location !== stateLocation) throw new FyxError(400, `Invalid Act State location: ${stateLocation} ${battle.location}`);\n \n if(this.battle.actLocations.has(stateLocation)) {\n console.log('Duplicate act:', stateLocation);\n return;\n }\n this.battle.actLocations.add(stateLocation);\n console.log('Act owner:', battle.actor);\n\n await this.blockchain.sendMessage(this.wallet.buildMessage({\n subject: 'Act',\n context: [this.battle.id],\n payload: JSON.stringify({ location: stateLocation, actionIndex })\n }));\n }\n\n async onActionError(message) {\n throw new Error(message.payload);\n }\n\n async EnterQueue(request) {\n const rules = this.lobbies[request.lobbyId-1];\n console.log(`RULES: ${JSON.stringify(rules)}`);\n console.log('Loading Fighter:', request.fighterLocation);\n const fighter = await this.wallet.loadJig(request.fighterLocation);\n console.log('Fighter Loaded:', request.fighterLocation);\n if(!fighter) throw new Error('CLIENT: Invalid Fighter');\n console.time('Fighter Sync');\n await fighter.sync({inner: false});\n console.timeEnd('Fighter Sync');\n const items = await Promise.all(request.itemLocations.map(async location => {\n if(!location) return null;\n const item = await this.wallet.loadJig(location);\n if(!item) return;\n console.time(`Item Sync: ${location}`);\n await item.sync({inner: false});\n console.timeEnd(`Item Sync: ${location}`);\n return item;\n }));\n \n if(rules.fee && fighter.satoshis < rules.fee + 273) {\n fighter.setSatoshis(rules.fee + 273);\n await fighter.sync();\n }\n console.log(`Everything Sync'd`);\n\n\n console.log('Build Message');\n this.queueMessage = {\n subject: 'EnterQueue',\n payload: JSON.stringify({\n lobbyId: rules.rulesId,\n fighterLocation: fighter.location,\n itemLocations: items.map(i => i && i.location),\n skills: request.actionIds,\n })\n };\n \n console.log('Message Sent');\n await this._enqueue();\n console.log('Returning');\n return request.lobbyId;\n }\n\n async _enqueue() {\n if(!this.queueMessage) this._exitQueue();\n const message = this.wallet.buildMessage(this.queueMessage);\n this.queueId = message.id;\n console.log('_enqueue:', message.id);\n \n await this.blockchain.sendMessage(\n message,\n `${Config.baseUrl}/${Config.fyxId}`\n );\n this.wallet.setTimeout(async () => this._refreshQueue(message.id), 45000);\n }\n\n async _refreshQueue(queueId) {\n if(this.queueId !== queueId || !this.queueMessage) return;\n try {\n const refreshed = await this.blockchain.sendMessage(\n this.wallet.buildMessage({\n subject: 'RefreshQueue',\n payload: JSON.stringify({queueId})\n }),\n `${Config.baseUrl}/${Config.fyxId}`\n );\n console.log('Refreshed:', refreshed);\n if(refreshed) this.wallet.setTimeout(async () => this._refreshQueue(queueId), 45000);\n else {\n console.log('Queue expired.');\n this.emit('client', 'OnExitQueue', 'Refresh expired');\n }\n } catch(e) {\n console.error('Refresh Queue Error:', e.message);\n }\n }\n\n async ExitQueue() {\n delete this.queueMessage;\n const message = this.wallet.buildMessage({\n subject: 'ExitQueue'\n });\n await this.blockchain.sendMessage(message, `${Config.baseUrl}/${Config.fyxId}`);\n }\n\n async _exitQueue(message) {\n delete this.queueMessage;\n this.emit('client', 'OnExitQueue', message && message.payload);\n if(message && message.payload) {\n this.emit('client', 'Error', message.payload);\n }\n }\n\n async Forfeit() {\n const battle = await this.battlePromise;\n const message = this.wallet.buildMessage({\n subject: 'Forfeit',\n context: [this.battle.id],\n payload: JSON.stringify({ location: battle.location })\n });\n console.log(`Forfeit::Sending message ${JSON.stringify(message,null,4)} to blockchain`);\n try {\n await this.blockchain.sendMessage(message);\n } catch (e) {\n console.error('Forfeit Error:', e.message);\n }\n console.log(`Forfeit::Sending message completed`);\n }\n \n SimulateFighterState(message) {\n return BattleUtils.simulateFighterState(message);\n }\n\n SimulateFightersState(message) {\n const fighterStates = [];\n message.forEach(f => fighterStates.push(BattleUtils.simulateFighterState(f)));\n return fighterStates;\n }\n\n async GetLastBattleUpdated() {\n if(!this.battleLocation) return;\n const battle = await this.wallet.loadJig(this.battleLocation);\n return battle.getState();\n }\n\n async GetPlayer() {\n console.log('GetPlayer');\n const config = {\n address: this.purse,\n pubkey: this.pubkey,\n owner: this.address,\n userId: this.wallet.handle,\n balance: 0,\n xpTable: {\n cumulativeXp: Constants.LevelUpXP,\n xpPerKill: Battle.LevelXPReward\n },\n lobbiesPerLevel: Constants.LobbiesPerLevel,\n tierPerLobby: Constants.TierPerLobby,\n abilityScoreLevels: Constants.AbilityScoreLevels,\n skillLevels: Constants.SkillLevels,\n skills: Object.entries(Constants.SkillData).map(([k, v]) => {\n if(['location', 'origin', 'owner', 'nonce', 'deps', 'satoshis'].includes(k)) return;\n return {\n ...v,\n skillType: k\n };\n }).filter(x => !!x),\n lobbies: this.lobbies,\n singlePlayerLobbyRespawn: 180,\n tiers: Compendium.Tiers\n };\n\n console.log('Player:', config);\n return config;\n }\n\n async LevelUp(request) {\n const { fighterLocation, ability, skillType } = request;\n let fighter = await this.wallet.loadJig(fighterLocation);\n if(!fighter) throw new Error('Invalid Fighter');\n await fighter.sync();\n\n const {paths, rawtx} = await this.blockchain.sendMessage(this.wallet.buildMessage({\n subject: 'LevelUp',\n payload: JSON.stringify({\n fighterLocation: fighter.location,\n ability,\n skillType\n })\n }), `${Config.baseUrl}/${Config.fyxId}`);\n this.emit('setDerivations', paths);\n\n const t = await this.wallet.loadTransaction(rawtx);\n fighter = t.outputs.find(o => o instanceof Fighter);\n await t.publish({pay: false, sign: true});\n await fighter.sync();\n this.onFighter(fighter);\n return fighter.toObject();\n }\n\n static async preDeploy() {\n ClientAgent.whitelist = [\n ClientAgent.deps.Battle.origin,\n ClientAgent.deps.BattleToken.origin,\n ClientAgent.deps.Fighter.origin,\n ClientAgent.deps.FyxItem.origin,\n ];\n }\n}",{"agentId":"client","deps":{"Agent":{"$jig":0},"Battle":{"$jig":1},"BattleToken":{"$jig":2},"BattleUtils":{"$jig":3},"Compendium":{"$jig":4},"Config":{"$jig":5},"Constants":{"$jig":6},"Fighter":{"$jig":7},"FyxClass":{"$jig":8},"FyxError":{"$jig":9},"FyxItem":{"$jig":10}},"hash":"985db1a618413c22907a5941c94b0ddacaa67aedef9bb6d8b02981fe6be8b332","sealed":false,"whitelist":["047c84687ebaa8379c5b60d3ed78a10ed310f47672e3a836b60fc1c455704c9f_o1","d6edec4a1c79ea975d3fe3608ddaccb9a3e5d69d908114055c8b7733deb9b134_o1","4d1980f5134f73c1f5ca413dae2d84db16f1786d191f395fe2a857fa9b0ea2f1_o1","aa2ebcab82c10e20f2f8cb0751fc5e1692252ce71fe3ba62c75a984da7d8e1f9_o1"]}]}]}
    https://whatsonchain.com/tx/28c4bdad0c774d557a7a3a9ba68c92108851a148a2b3de980edd88f2a11683e2