Settings

Blockchain
Network
Unit
Language
Theme
Sound New Block

Transaction

4f645bf106699f46d332dc03fa3f44fa40ae8599af368f8f839fafd66dfa91cd
Timestamp (utc)
2021-02-20 00:48:45
Fee Paid
0.00022256 BSV
(
0.00930885 BSV
-
0.00908629 BSV
)
Fee Rate
995.2 sat/KB
Version
1
Confirmations
315,916
Size Stats
22,356 B

3 Outputs

Total Output:
0.00908629 BSV
  • jrun cryptofightsMPV{"in":0,"ref":["601edbeb03cc17a04d7ef75d78deddf3c51cd45c84d0850effc475cc2f6ca0b5_o1","14fa74c719f848439c1fcae4f94f7d047444dbacad2348fefa578e60a83891d1_o1","e3c773ec17ed09e32cc39dcacdc0097875de22feae90739476f5ce5921328277_o1","384125df69ae11bcad90feee6ac9308bd186f08a8ab6bd2606719e0adecd1eee_o1","0e48ad5ad7b313698bcd4fbe75cb245beb8f7b333d8cfee68fa9192d25324033_o1","00c46a6105cdf730944a15852f50eddc500f1eda01e5e8952fc9ea599916214a_o1","1fcebe6534c204d4661c10aca3b6450eb3a5c2135ec11e91f8c5b86212c7c40d_o1","1598c97f5c5e0e26ac7d819a351b1f0411e3c28261b1bc6d7ffd076e98d11ded_o1","58133150b2f2adb440da08b34399b39a31ba2e70de3a30071bfce4caa27ccce9_o1","c0555bba5a49342eb021c206a8710d9aebd6f06103afa4e2f160c272b00372bd_o1","ee4fe3ccb1469a4c6036d141e2f7857d74ac53a16e1f73e62e4eef17a9c5f0b0_o1","20af650ed493f124361af75c0d2131238266d3cb9098e1b819ca9ef176ed2c1c_o1","363e1420840195239965db31907d9d1635eaf6993a07f963749f6cdd201bf0ec_o1","e3a71f1844f597ad4f8af1485f385b518c239d11c338503870d459306024df81_o1","7bdc5790e34a0a7adf4c529fdc5880f714149bad3efdf7ceb2a870286b8f05d3_o1","68b0772a4f166e9e67e518ba6a53c03d7b66575d33ff132094856dbfbedf2d7f_o1","438bfb5abc25e9bd04217610b78df75d748f3a63153084f9b33bd871172cb492_o1","c7347a4fe3f694505bd2c03733c903e4931a5024e60019e98f62f0be831fdc9d_o1","80cf361259fa8fb944e3a524cf31c5f485c217f7b4a4fb14bafc278b5a938975_o1","e9c568244b6cf874b22072812cdfd51d272b4e831f5cdf3912d48745bc7c701e_o1","59ef89bb4ea3ee4c9b04af9fe61548415966084563e3f18118b477e941ce424f_o1","1c1accbca985304f5b5d3f8058d640d6a2b47edb8c9119ec1adbcacd0defe53c_o1","abe0abcf22cfc229e213baf09402ab4c2f4c061ddd7409a56f48323f4f941f46_o1"],"out":["650aa42a3292fe85d7dabc830030e023642ac9575ebec3c8fd4cf0f203d555a8"],"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(KronoCoin.origin, this.onKronoCoin);\n this.jigHandlers.set(KronoItem.origin, this.onItem);\n\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('CreateFighter', this.CreateFighter);\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('GetFighters', this.GetFighters);\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('GetPlayer', this.GetPlayer);\n this.eventHandlers.set('GetBattles', this.GetBattles);\n this.eventHandlers.set('GetBalance', this.getBalance);\n this.eventHandlers.set('GetBattleHistory', this.GetBattleHistory);\n this.eventHandlers.set('GetLastBattleUpdated', this.GetLastBattleUpdated);\n \n this.eventHandlers.set('LevelUp', this.LevelUp);\n this.eventHandlers.set('RedeemItem', this.RedeemItem);\n\n const lock = new CoinLock(this.wallet.ownerPair.pubKey.toString());\n this.coinScript = lock.script();\n console.log('COIN SCRIPT:', this.coinScript);\n this.emit('subscribe', this.coinScript);\n\n this._battles = new Map();\n this._fighters = new Map();\n this._items = new Map();\n this.emit('subscribe', 'QueueStatus');\n // this.wallet.setTimeout(() => this.recordVictories(), 0);\n // this.wallet.setTimeout(() => this.dispose(), 0);\n }\n\n onFighter(fighter) {\n this._fighters.set(fighter.origin, fighter.toObject());\n this.emit('client', 'FighterUpdated', this._fighters.get(fighter.origin));\n }\n\n onItem(item) {\n this._items.set(item.origin, item.toObject());\n this.emit('client', 'ItemUpdated', this._items.get(item.origin));\n }\n\n async onKronoCoin() {\n this.emit('client', 'BalanceUpdated', await this.getBalance());\n }\n\n onBattleCreated(message) {\n const { id } = message.payloadObj;\n if(id === this.currentId) {\n delete this.queueMessage;\n }\n this.emit('client', 'BattleCreated', message.payloadObj);\n console.log(`BattleCreated: ${message.payload}`);\n }\n\n _queueStatus(message) {\n this.emit('client', 'QueueStatus', message.payload);\n }\n\n async onBattleUpdated(message) {\n this.emit('client', 'BattleUpdated', message.payloadObj);\n console.log(`BattleUpdated: ${message.payload}`);\n const { location, battleId } = message.payloadObj;\n\n console.log('Handling BattleUpdated - BU:', battleId, ' CURR:', this.currentId);\n if(battleId === this.currentId) {\n console.log('Updating battleLocation');\n this.battleLocation = location;\n }\n }\n\n async onBattleCompleted(message) {\n const { location, battleId } = message.payloadObj;\n const battle = await this.wallet.loadJig(location);\n this._battles.set(battle.origin, battle.toObject());\n \n if (battleId === this.currentId) {\n const battleState = battle.getState();\n this.emit('client', 'BattleUpdated', battleState);\n console.log(`BattleUpdated: ${JSON.stringify(battleState)}`);\n this.emit('client', 'BattleCompleted', this._battles.get(battle.origin));\n console.log('BattleCompleted', this._battles.get(battle.origin));\n console.log(`BattleCompleted: ${JSON.stringify(this._battles.get(battle.origin))}`);\n // delete this.battle;\n // delete this.currentId;\n }\n\n if(battle.owner === this.address) {\n const { fighter } = battle.victor;\n fighter.recordVictory(battle);\n await fighter.sync();\n this.onFighter(fighter);\n }\n }\n\n async recordVictories() {\n console.log('Record Victories');\n try {\n const battles = await this.wallet.loadJigIndex({\n criteria: {kind: Battle.origin},\n projection: {value: false}\n });\n for(let b of battles) {\n const battle = await this.wallet.loadJig(b.location);\n await battle.victor.fighter.sync();\n battle.victor.fighter.recordVictory(battle);\n await battle.victor.fighter.sync();\n this.onFighter(battle.victor.fighter);\n }\n } catch(e) {\n console.error('Record Victories Error:', e.message);\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 const { id, rawtx } = 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 \n const rules = ClientAgent.lobbies.find(lobby => lobby.origin === this.queueMessage.subject);\n console.log(`Executed ClientAgent.lobbies.find.`); // Added debug log #2\n if (!rules) throw new Error('Invalid Lobby');\n console.log(`Lobby is valid`); // Added debug log #3\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.currentId = id;\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 } = request;\n const battle = await this.wallet.loadJig(this.battleLocation);\n if(!battle) {\n console.log('No Battle');\n } else {\n console.log('ACT BATTLE:', battle.toObject());\n }\n const {id, location} = battle;\n const message = this.wallet.buildMessage({\n context: [id],\n subject: 'Act',\n payload: JSON.stringify({ location, actionIndex })\n });\n await this.blockchain.sendMessage(message);\n }\n\n async onActionError(message) {\n throw new Error(message.payload);\n }\n\n async CreateFighter(request) {\n delete request.skills;\n const message = this.wallet.buildMessage({\n to: [MintConfig.pubkey],\n subject: 'FighterRequest',\n context: [this.currentId],\n payload: JSON.stringify({\n ...request,\n owner: this.address\n })\n });\n const resp = await this.blockchain.sendMessage(message, MintConfig.postTo);\n const fighter = await this.wallet.loadJig(resp.location);\n this.onFighter(fighter);\n return fighter;\n }\n\n async EnterQueue(request) {\n const rules = ClientAgent.lobbies[request.lobbyId-1];\n console.log('RULES:', rules && rules.origin);\n const fighter = await this.wallet.loadJig(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 const skills = request.actionIds;\n console.log('Load Coin');\n let coins = await this.selectCoins(rules.fee);\n\n console.log('Build Message');\n this.queueMessage = {\n to: [QueueConfig.pubkey],\n subject: rules.origin,\n payload: JSON.stringify({\n pubkey: this.pubkey,\n owner: this.address,\n fighterLocation: fighter.location,\n itemLocations: items.map(i => i && i.location),\n skills,\n coinLocations: coins.map(c => c.location)\n })\n };\n \n await this._enqueue();\n return request.lobbyId;\n }\n\n async _enqueue() {\n if(!this.queueMessage) return;\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 QueueConfig.postTo\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 to: [QueueConfig.pubkey],\n subject: 'RefreshQueue',\n payload: JSON.stringify({queueId})\n }),\n QueueConfig.postTo\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 const message = this.wallet.buildMessage({\n to: [QueueConfig.pubkey],\n subject: 'ExitQueue'\n });\n await this.blockchain.sendMessage(message, QueueConfig.postTo);\n this._exitQueue();\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 message = this.wallet.buildMessage({\n to: [ValidatorConfig.pubkey],\n context: [this.currentId],\n subject: 'Forfeit',\n payload: JSON.stringify({ location: this.battleLocation })\n });\n await this.blockchain.sendMessage(message);\n }\n \n \n async GetBattles() {\n if(!this.historyLoaded) {\n const tokens = await this.blockchain.jigQuery({ \n criteria: {\n kind: BattleToken.origin,\n owner: this.address\n },\n limit: 20,\n sort: {ts: -1}\n });\n console.log('Tokens:', tokens.length);\n await Promise.all(tokens.map(async t => {\n const token = await this.blockchain.loadJigData(t.location);\n console.log(`Token: ${JSON.stringify(token)}`);\n if(token && token.value) {\n this._battles.set(token.value.battle.origin, token.value.battle);\n }\n }));\n this.historyLoaded = true;\n }\n console.log('Battles:', this._battles.size);\n return [...this._battles.values()];\n }\n\n async GetFighters() {\n if(!this._fighters.size) {\n const index = await this.wallet.loadJigIndex({\n criteria: {kind: Fighter.origin}\n });\n index.forEach(f => this._fighters.set(f.origin, f.value));\n }\n return [...this._fighters.values()];\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 GetItems() {\n if(!this._items.size) {\n const index = await this.wallet.loadJigIndex({\n criteria: {kind: KronoItem.origin},\n projection: {'value.mint': false}\n });\n index.forEach(i => this._items.set(i.origin, i.value));\n }\n return [...this._items.values()];\n }\n\n async GetPlayer() {\n const [fIndex, iIndex,] = await Promise.all([\n this.wallet.loadJigIndex({criteria: {kind: Fighter.origin}, projection: {value: false}}),\n this.wallet.loadJigIndex({criteria: {kind: KronoItem.origin}, projection: {value: false}})\n ]);\n\n const balance = await this.getBalance();\n const config = {\n address: this.address,\n pubkey: this.pubkey,\n owner: this.address,\n handle: this.wallet.handle,\n balance,\n xpTable: {\n cumulativeXp: Fighter.LevelUpXP,\n xpPerKill: Battle.LevelXPReward\n },\n lobbiesPerLevel: Fighter.LobbiesPerLevel,\n tierPerLobby: Fighter.TierPerLobby,\n abilityScoreLevels: Fighter.AbilityScoreLevels,\n skillLevels: Fighter.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 fighterCount: fIndex.length,\n itemCount: iIndex.length,\n lobbies: KronoClass.deepClone(this.constructor.lobbies)\n };\n\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 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 }), MintConfig.postTo);\n\n const t = await this.wallet.loadTransaction(rawtx);\n fighter = t.outputs.find(o => o instanceof Fighter);\n await t.publish();\n await fighter.sync();\n // this.onFighter(fighter);\n return fighter.toObject();\n }\n\n async RedeemItem(itemId) {\n const message = this.wallet.buildMessage({\n to: [MintConfig.pubkey],\n subject: 'RedeemItemRequest',\n payload: JSON.stringify({owner: this.address, itemId})\n });\n\n const item = await this.blockchain.sendMessage(message, MintConfig.postTo);\n this._items.set(item.origin, item);\n return item;\n }\n\n async dispose() {\n const index = await this.wallet.loadJigIndex({ projection: { value: false } });\n const deprecated = index\n .filter(data => !this.constructor.whitelist.includes(data.kind))\n .slice(0, 50);\n if (!deprecated.length) return;\n for (const j of deprecated) {\n try {\n const jig = await this.wallet.loadJig(j.location);\n await jig.sync({inner: false});\n console.log('Disposing:', jig.constructor.name, jig.location);\n jig.destroy();\n await jig.sync({forward: false});\n } catch(e) {\n console.error('Dispose Error:', e.message, e.stack);\n }\n }\n }\n\n static async preDeploy() {\n ClientAgent.lobbies = [\n ClientAgent.deps.Bot1ValidatorAgent,\n ClientAgent.deps.Bot2ValidatorAgent,\n ClientAgent.deps.Bot3ValidatorAgent,\n ClientAgent.deps.Bot4ValidatorAgent,\n ClientAgent.deps.Bot5ValidatorAgent,\n ClientAgent.deps.Bot6ValidatorAgent,\n ClientAgent.deps.Tier7ValidatorAgent,\n ];\n\n ClientAgent.whitelist = [\n ClientAgent.deps.Battle.origin,\n // ClientAgent.deps.BattleToken.origin,\n ClientAgent.deps.Fighter.origin,\n ClientAgent.deps.KronoItem.origin,\n ClientAgent.deps.KronoCoin\n ];\n }\n}",{"agentId":"client","deps":{"Agent":{"$jig":0},"Battle":{"$jig":1},"BattleToken":{"$jig":2},"BattleUtils":{"$jig":3},"Bot1ValidatorAgent":{"$jig":4},"Bot2ValidatorAgent":{"$jig":5},"Bot3ValidatorAgent":{"$jig":6},"Bot4ValidatorAgent":{"$jig":7},"Bot5ValidatorAgent":{"$jig":8},"Bot6ValidatorAgent":{"$jig":9},"CoinLock":{"$jig":10},"Constants":{"$jig":11},"Fighter":{"$jig":12},"KronoClass":{"$jig":13},"KronoCoin":{"$jig":14},"KronoError":{"$jig":15},"KronoItem":{"$jig":16},"MintConfig":{"$jig":17},"QueueConfig":{"$jig":18},"Sha256":{"$jig":19},"Tier7ValidatorAgent":{"$jig":20},"ValidatorConfig":{"$jig":21},"XpTest":{"$jig":22}},"hash":"c31f6bda7d968c77b5f8db526341c12e17541096d6d1100a295c760417da8c7e","lobbies":[{"$dup":["1","deps","Bot1ValidatorAgent"]},{"$dup":["1","deps","Bot2ValidatorAgent"]},{"$dup":["1","deps","Bot3ValidatorAgent"]},{"$dup":["1","deps","Bot4ValidatorAgent"]},{"$dup":["1","deps","Bot5ValidatorAgent"]},{"$dup":["1","deps","Bot6ValidatorAgent"]},{"$dup":["1","deps","Tier7ValidatorAgent"]}],"sealed":false,"whitelist":["14fa74c719f848439c1fcae4f94f7d047444dbacad2348fefa578e60a83891d1_o1","363e1420840195239965db31907d9d1635eaf6993a07f963749f6cdd201bf0ec_o1","438bfb5abc25e9bd04217610b78df75d748f3a63153084f9b33bd871172cb492_o1",{"$dup":["1","deps","KronoCoin"]}]}]}]}
    https://whatsonchain.com/tx/4f645bf106699f46d332dc03fa3f44fa40ae8599af368f8f839fafd66dfa91cd