From c5c64bf839a25d525341de1ec8b45757300151fa Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Wed, 26 Oct 2022 09:00:02 +0530 Subject: [PATCH 1/7] Added hashbattle contract on mainnet --- Mainnet/HashBattle/HashBattle.sln | 31 +++ Mainnet/HashBattle/HashBattle/Arena.cs | 194 ++++++++++++++++++ .../HashBattle/HashBattle/HashBattle.csproj | 11 + .../HashBattle/HashBattleTest/ArenaTest.cs | 145 +++++++++++++ .../HashBattleTest/HashBattleTest.csproj | 28 +++ .../HashBattleTest/InMemoryState.cs | 83 ++++++++ Mainnet/HashBattle/README.MD | 15 ++ 7 files changed, 507 insertions(+) create mode 100644 Mainnet/HashBattle/HashBattle.sln create mode 100644 Mainnet/HashBattle/HashBattle/Arena.cs create mode 100644 Mainnet/HashBattle/HashBattle/HashBattle.csproj create mode 100644 Mainnet/HashBattle/HashBattleTest/ArenaTest.cs create mode 100644 Mainnet/HashBattle/HashBattleTest/HashBattleTest.csproj create mode 100644 Mainnet/HashBattle/HashBattleTest/InMemoryState.cs create mode 100644 Mainnet/HashBattle/README.MD diff --git a/Mainnet/HashBattle/HashBattle.sln b/Mainnet/HashBattle/HashBattle.sln new file mode 100644 index 00000000..11cccce2 --- /dev/null +++ b/Mainnet/HashBattle/HashBattle.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31624.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashBattle", "HashBattle\HashBattle.csproj", "{D711FA52-750E-481B-9BC5-2E07EBF58240}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashBattleTest", "HashBattleTest\HashBattleTest.csproj", "{2A7F2670-A17F-46E6-BF35-A2C55BC7DCB1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D711FA52-750E-481B-9BC5-2E07EBF58240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D711FA52-750E-481B-9BC5-2E07EBF58240}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D711FA52-750E-481B-9BC5-2E07EBF58240}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D711FA52-750E-481B-9BC5-2E07EBF58240}.Release|Any CPU.Build.0 = Release|Any CPU + {2A7F2670-A17F-46E6-BF35-A2C55BC7DCB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A7F2670-A17F-46E6-BF35-A2C55BC7DCB1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A7F2670-A17F-46E6-BF35-A2C55BC7DCB1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A7F2670-A17F-46E6-BF35-A2C55BC7DCB1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {88A96B52-6F00-40C9-AA28-C3D79E3BC0DF} + EndGlobalSection +EndGlobal diff --git a/Mainnet/HashBattle/HashBattle/Arena.cs b/Mainnet/HashBattle/HashBattle/Arena.cs new file mode 100644 index 00000000..8fd58dc8 --- /dev/null +++ b/Mainnet/HashBattle/HashBattle/Arena.cs @@ -0,0 +1,194 @@ +using Stratis.SmartContracts; +using System; +using System.Text; + +/// +/// A Stratis smart contract for running a game battle where owner will start the battle and maximum 4 users can enter a battle +/// +public class Arena : SmartContract +{ + public Arena(ISmartContractState smartContractState) + : base(smartContractState) + { + BattleOwner = Message.Sender; + } + + /// + /// Set the address deploying the contract as battle owner + /// + private Address BattleOwner + { + get => PersistentState.GetAddress(nameof(BattleOwner)); + set => PersistentState.SetAddress(nameof(BattleOwner), value); + } + + /// + /// Battle owner will start the battle + /// + public bool StartBattle(ulong battleId, ulong fee) + { + Assert(Message.Sender == BattleOwner, "Only battle owner can start game."); + + var battle = new BattleMain(); + battle.BattleId = battleId; + battle.MaxUsers = 4; + battle.Fee = fee; + battle.Users = new Address[battle.MaxUsers]; + SetBattle(battleId, battle); + + Log(battle); + return true; + } + + /// + /// 4 different user will enter the battle + /// + public bool EnterBattle(ulong battleId, uint userindex) + { + var battle = GetBattle(battleId); + + Assert(battle.Winner == Address.Zero, "Battle ended."); + + Assert(battle.Fee == Message.Value, "Battle amount is not matching."); + + var user = GetUser(battleId, Message.Sender); + + Assert(!user.ScoreSubmitted, "The user already submitted score."); + + user.Address = Message.Sender; + + SetUser(battleId, Message.Sender, user); + + battle.Users.SetValue(user.Address, userindex); + SetBattle(battleId, battle); + + Log(battle); + return true; + } + + /// + /// 4 different user will end the battle and submit the score + /// + public bool EndBattle(Address userAddress, ulong battleId, uint score, bool IsBattleOver) + { + Assert(Message.Sender == BattleOwner, "Only battle owner can end game."); + + var battle = GetBattle(battleId); + + Assert(battle.Winner == Address.Zero, "Battle ended."); + + var user = GetUser(battleId, userAddress); + + Assert(!user.ScoreSubmitted, "The user already submitted score."); + + user.Score = score; + user.ScoreSubmitted = true; + + SetUser(battleId, userAddress, user); + + if (IsBattleOver) + ProcessWinner(battle); + + Log(user); + return true; + } + + /// + /// Get winner address + /// + public Address GetWinner(ulong battleId) + { + var battle = GetBattle(battleId); + Log(battle); + return battle.Winner; + } + + /// + /// Process winner when all user scores are submitted + /// + private void ProcessWinner(BattleMain battle) + { + if (battle.Users.Length <= 4) + { + foreach (Address userAddress in battle.Users) + { + var user = GetUser(battle.BattleId, userAddress); + if (!user.ScoreSubmitted) + return; + } + } + uint winnerIndex = GetWinnerIndex(battle.BattleId, battle.Users); + if (battle.Winner == Address.Zero) + { + battle.Winner = battle.Users[winnerIndex]; + SetBattle(battle.BattleId, battle); + ProcessPrize(battle.BattleId); + } + } + + /// + /// Get winner user index from battle users + /// + private uint GetWinnerIndex(ulong battleid, Address[] users) + { + uint winningScore = 0; + uint winningScoreIndex = 0; + for (uint i = 0; i < users.Length; i++) + { + var user = GetUser(battleid, users[i]); + if (user.Score > winningScore) + { + winningScore = user.Score; + winningScoreIndex = i; + } + } + return winningScoreIndex; + } + + /// + /// Send 3/4 amount to winner and 1/4 amount to battle owner + /// + private void ProcessPrize(ulong battleid) + { + var battle = GetBattle(battleid); + ulong prize = battle.Fee * (battle.MaxUsers - 1); + Transfer(battle.Winner, prize); + Transfer(BattleOwner, battle.Fee); + } + + private void SetUser(ulong battleid, Address address, BattleUser user) + { + PersistentState.SetStruct($"user:{battleid}:{address}", user); + } + + private BattleUser GetUser(ulong battleid, Address address) + { + return PersistentState.GetStruct($"user:{battleid}:{address}"); + } + + private void SetBattle(ulong battleid, BattleMain battle) + { + PersistentState.SetStruct($"battle:{battleid}", battle); + } + + private BattleMain GetBattle(ulong battleid) + { + return PersistentState.GetStruct($"battle:{battleid}"); + } + + public struct BattleMain + { + public ulong BattleId; + public Address Winner; + public Address[] Users; + public uint MaxUsers; + public ulong Fee; + } + + public struct BattleUser + { + public Address Address; + public uint Score; + public bool ScoreSubmitted; + } +} diff --git a/Mainnet/HashBattle/HashBattle/HashBattle.csproj b/Mainnet/HashBattle/HashBattle/HashBattle.csproj new file mode 100644 index 00000000..780e51c7 --- /dev/null +++ b/Mainnet/HashBattle/HashBattle/HashBattle.csproj @@ -0,0 +1,11 @@ + + + + netcoreapp2.1 + + 8.0 + + + + + diff --git a/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs new file mode 100644 index 00000000..29391d2d --- /dev/null +++ b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs @@ -0,0 +1,145 @@ +using System; +using Moq; +using Stratis.SmartContracts; +using Stratis.SmartContracts.CLR; +using Xunit; +using static Arena; + +namespace HashBattleTest +{ + public class ArenaTest + { + private readonly IPersistentState state; + private readonly Mock mockContractState; + private readonly Mock mockPersistentState; + private readonly Mock mockContractLogger; + private readonly Mock mTransactionExecutor; + private Address contract; + private Address ownerAddress; + private Address playerAddress1; + private Address playerAddress2; + private Address playerAddress3; + private Address playerAddress4; + + public ArenaTest() + { + this.state = new InMemoryState(); + this.mockPersistentState = new Mock(); + this.mockContractState = new Mock(); + this.mockContractLogger = new Mock(); + this.mTransactionExecutor = new Mock(); + this.mockContractState.Setup(s => s.PersistentState).Returns(this.state); + this.mockContractState.Setup(s => s.ContractLogger).Returns(this.mockContractLogger.Object); + this.mockContractState.Setup(s => s.InternalTransactionExecutor).Returns(this.mTransactionExecutor.Object); + this.contract = "0x0000000000000000000000000000000000000001".HexToAddress(); + this.ownerAddress = "0x0000000000000000000000000000000000000002".HexToAddress(); + this.playerAddress1 = "0x0000000000000000000000000000000000000003".HexToAddress(); + this.playerAddress2 = "0x0000000000000000000000000000000000000004".HexToAddress(); + this.playerAddress3 = "0x0000000000000000000000000000000000000005".HexToAddress(); + this.playerAddress4 = "0x0000000000000000000000000000000000000006".HexToAddress(); + } + + + [Fact] + public void TestBattle() + { + Arena arena = StartBattleTest(); + Player1EnterGameTest(arena); + Player2EnterGameTest(arena); + Player3EnterGameTest(arena); + Player4EnterGameTest(arena); + Player1EndGameTest(arena); + Player2EndGameTest(arena); + Player3EndGameTest(arena); + Player4EndGameTest(arena); + GetGameWinnerTest(arena); + } + + private Arena StartBattleTest() + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); + Arena arena = new Arena(this.mockContractState.Object); + arena.StartBattle(1, 1); + + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + return arena; + } + + private void Player1EnterGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress1, 1)); + arena.EnterBattle(1, 0); + + Assert.Equal(this.playerAddress1, state.GetStruct($"user:{1}:{this.playerAddress1}").Address); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + } + + private void Player2EnterGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress2, 1)); + arena.EnterBattle(1, 1); + + Assert.Equal(this.playerAddress2, state.GetStruct($"user:{1}:{this.playerAddress2}").Address); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + } + + private void Player3EnterGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress3, 1)); + arena.EnterBattle(1, 2); + + Assert.Equal(this.playerAddress3, state.GetStruct($"user:{1}:{this.playerAddress3}").Address); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + } + + private void Player4EnterGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress4, 1)); + arena.EnterBattle(1, 3); + + Assert.Equal(this.playerAddress4, state.GetStruct($"user:{1}:{this.playerAddress4}").Address); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + } + + private void Player1EndGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); + arena.EndBattle(this.playerAddress1, 1, 10, false); + + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress1}"))); + } + + private void Player2EndGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); + arena.EndBattle(this.playerAddress2, 1, 20, false); + + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress2}"))); + } + + private void Player3EndGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); + arena.EndBattle(this.playerAddress3, 1, 30, false); + + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress3}"))); + } + + private void Player4EndGameTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); + arena.EndBattle(this.playerAddress4, 1, 40, true); + + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress4}"))); + } + + private void GetGameWinnerTest(Arena arena) + { + this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); + Address winner = arena.GetWinner(1); + + Assert.Equal(this.playerAddress4, winner); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + } + } +} diff --git a/Mainnet/HashBattle/HashBattleTest/HashBattleTest.csproj b/Mainnet/HashBattle/HashBattleTest/HashBattleTest.csproj new file mode 100644 index 00000000..b71e8f64 --- /dev/null +++ b/Mainnet/HashBattle/HashBattleTest/HashBattleTest.csproj @@ -0,0 +1,28 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Mainnet/HashBattle/HashBattleTest/InMemoryState.cs b/Mainnet/HashBattle/HashBattleTest/InMemoryState.cs new file mode 100644 index 00000000..8f20e1db --- /dev/null +++ b/Mainnet/HashBattle/HashBattleTest/InMemoryState.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using Stratis.SmartContracts; + +namespace HashBattleTest +{ + public class InMemoryState : IPersistentState + { + private readonly Dictionary storage = new Dictionary(); + public bool IsContractResult { get; set; } + public void Clear(string key) => storage.Remove(key); + + public T GetValue(string key) => (T)storage.GetValueOrDefault(key, default(T)); + + public void AddOrReplace(string key, object value) + { + if (!storage.TryAdd(key, value)) + storage[key] = value; + } + public Address GetAddress(string key) => GetValue
(key); + + public T[] GetArray(string key) => GetValue(key); + + public bool GetBool(string key) => GetValue(key); + + public byte[] GetBytes(byte[] key) => throw new NotImplementedException(); + + public byte[] GetBytes(string key) => GetValue(key); + + public char GetChar(string key) => GetValue(key); + + public int GetInt32(string key) => GetValue(key); + + public long GetInt64(string key) => GetValue(key); + + public string GetString(string key) => GetValue(key); + + public T GetStruct(string key) + where T : struct => GetValue(key); + + public uint GetUInt32(string key) => GetValue(key); + + public ulong GetUInt64(string key) => GetValue(key); + + public UInt128 GetUInt128(string key) => GetValue(key); + + public UInt256 GetUInt256(string key) => GetValue(key); + + public bool IsContract(Address address) => IsContractResult; + + public void SetAddress(string key, Address value) => AddOrReplace(key, value); + + public void SetArray(string key, Array a) => AddOrReplace(key, a); + + public void SetBool(string key, bool value) => AddOrReplace(key, value); + + public void SetBytes(byte[] key, byte[] value) + { + throw new NotImplementedException(); + } + + public void SetBytes(string key, byte[] value) => AddOrReplace(key, value); + + public void SetChar(string key, char value) => AddOrReplace(key, value); + + public void SetInt32(string key, int value) => AddOrReplace(key, value); + + public void SetInt64(string key, long value) => AddOrReplace(key, value); + + public void SetString(string key, string value) => AddOrReplace(key, value); + + public void SetStruct(string key, T value) + where T : struct => AddOrReplace(key, value); + + public void SetUInt32(string key, uint value) => AddOrReplace(key, value); + + public void SetUInt64(string key, ulong value) => AddOrReplace(key, value); + + public void SetUInt128(string key, UInt128 value) => AddOrReplace(key, value); + + public void SetUInt256(string key, UInt256 value) => AddOrReplace(key, value); + } +} diff --git a/Mainnet/HashBattle/README.MD b/Mainnet/HashBattle/README.MD new file mode 100644 index 00000000..d6fdfb83 --- /dev/null +++ b/Mainnet/HashBattle/README.MD @@ -0,0 +1,15 @@ +# Hashbattle Smart Contract + +**Compiler Version** +``` +v2.0.0 +``` +**Contract Hash** +``` +5fce69c0bdd6e6cf7d1a3ef04c463c6bfb4066bb043dac29d90e2c0806e47c98 +``` + +**Contract Byte Code** +``` +4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0102009C4DC5BE0000000000000000E00022200B013000001000000002000000000000B22E0000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000602E00004F000000000000000000000000000000000000000000000000000000004000000C000000442E00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000B80E0000002000000010000000020000000000000000000000000000200000602E72656C6F6300000C000000004000000002000000120000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000942E000000000000480000000200050030240000140A00000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000660203280400000A0202280500000A6F0600000A28030000062A4602280700000A72010000706F0800000A2A4A02280700000A7201000070036F0900000A2A001330030064000000010000110202280500000A6F0600000A022802000006280A00000A7219000070280B00000A1200FE15030000021200037D0100000412001A7D040000041200047D050000041200067B040000048D070000017D03000004020306280D0000060206280100002B172A13300400B6000000020000110203280E0000060A02067B020000047E0D00000A280A00000A725D000070280B00000A02067B0500000402280500000A6F0E00000AFE017279000070280B00000A020302280500000A6F0600000A280C0000060B02077B0800000416FE0172D9000070280B00000A120102280500000A6F0600000A7D06000004020302280500000A6F0600000A07280B000006067B03000004077B060000048C07000001046E6F0F00000A020306280D0000060206280100002B172A0000133004008E000000020000110202280500000A6F0600000A022802000006280A00000A721D010070280B00000A0204280E0000060A02067B020000047E0D00000A280A00000A725D000070280B00000A020403280C0000060B02077B0800000416FE0172D9000070280B00000A1201057D070000041201177D0800000402040307280B0000060E042C07020628080000060207280200002B172A00001330020016000000010000110203280E0000060A0206280100002B067B020000042A0000133003008F00000003000011037B030000048E691A3032037B030000040B160C2B210708A3070000010D02037B0100000409280C0000067B080000042D012A0817580C08078E6932D902037B01000004037B0300000428090000060A037B020000047E0D00000A280A00000A2C2C0F01037B0300000406A3070000017D0200000402037B0100000403280D00000602037B01000004280A0000062A00133004003700000004000011160A160B160C2B2502030408A307000001280C0000060D097B07000004063609097B070000040A080B0817D70C086E048E696A32D3072A00133003003B000000050000110203280E0000060A067B05000004067B0400000417DB6ED90B02067B0200000407281000000A2602022802000006067B05000004281000000A262A8E02280700000A725D010070038C0E000001048C07000001281100000A056F0300002B2A8A02280700000A725D010070038C0E000001048C07000001281100000A6F0400002B2A7602280700000A7277010070038C0E000001281400000A046F0500002B2A7202280700000A7277010070038C0E000001281400000A6F0600002B2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C0000007C030000237E0000E80300004403000023537472696E6773000000002C0700009001000023555300BC080000100000002347554944000000CC0800004801000023426C6F6200000000000000020000015715A201090A000000FA013300160000010000000F00000004000000080000000E000000170000001400000003000000050000000100000001000000020000000100000002000000020000000600000000009701010000000000060028015202060048015202060014013F020F00720200000A00D802BA020A00C800BA020A00AA02BA020600B200A9010A006000BA020A00EF00BA0206003103A9010600E602A9010A000103BA0206000100A90106008C01A901000000000800000000000100010001001000110000001500010001000A011000B0010000210001000F000A0110000C020000210006000F0006002E00B0000600E501580006008402B30006008102B80006005800B0000600AA0258000600BC00B80006004000BB0050200000000086183902100001006A20000000008108EC011B0002007C20000000008108FC01BE00020090200000000086009F00C400030000210000000086007F00CA000500C4210000000086007500D00007006022000000008600E201D9000B008422000000008100D401DF000C0020230000000081001803E5000D0064230000000081007F01ED000F00AB230000000081001F02F2001000CF230000000081001702FB001300F22300000000810095000301150010240000000081008B000A01170000000100DC00000001007901000001003700000002005C0000000100370000000200270300000100900200000200370000000300C200000004002C0200000100370000000100AB00000001004F00000002008A02000001004F00000001004F0000000200B202000003002702000001004F0000000200B202000001004F0000000200AB00000001004F00090039020100110039020600190039020A002900390210002900690016004900C0011B0029000001200051009C0225005100A7022B00390037033700290011033F002900930145003900BB015800490066015C005900700160002900CB0183007900D1028B005100F70292005100ED029A007900D102A1002E000B0015012E0013001E012E001B003D01320051006B0075007D0002000100000000021001020002000300010003000300048000000000000000000000000000000000D8020000040000000000000000000000A7001700000000000200000000000000000000000000BA0200000000030002000400020019004C0019006600250066002700660025004C0027004C0000000055496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C696200426174746C65496400626174746C6549640053636F72655375626D697474656400626174746C656964004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F72650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E745374617465006765745F50657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E67004C6F6700536D617274436F6E74726163742E646C6C0053797374656D00426174746C654D61696E005A65726F006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F426174746C654F776E6572007365745F426174746C654F776E657200426174746C6555736572004765745573657200536574557365720075736572004973426174746C654F766572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573004D6178557365727300757365727300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C74004173736572740047657457696E6E6572496E6465780075736572696E646578004172726179006F705F457175616C6974790000001742006100740074006C0065004F0077006E006500720000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001B42006100740074006C006500200065006E006400650064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00001975007300650072003A007B0030007D003A007B0031007D00001562006100740074006C0065003A007B0030007D000000000053FFE06AD37C28419B1B527317B313CF000420010108032000010520010111110520010112190420001225042000111D0420001229052001111D0E062002010E111D040701110C07000202111D111D05200201020E06300101011E00040A01110C060702110C11100306111D0320000B052002011C0A040A011110090704091D111D08111D0707040909091110050702110C0B0720021235111D0B0600030E0E1C1C07300102010E1E00063001011E000E0500020E0E1C087CEC85D7BEA7798E02060B04061D111D02060902060205200101111D052002020B0B052002020B0908200402111D0B0902052001111D0B05200101110C072002090B1D111D042001010B082003010B111D111007200211100B111D062002010B110C052001110C0B042800111D0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F777301080100020000000000000000000000000000000000000010000000000000000000000000000000882E00000000000000000000A22E0000002000000000000000000000000000000000000000000000942E0000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000B43E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +``` From aef28430ad6e532cd9310264c9e111e45900b9d4 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Fri, 21 Apr 2023 19:06:42 +0530 Subject: [PATCH 2/7] Refactoring as per suggested changes --- Mainnet/HashBattle/HashBattle/Arena.cs | 137 +++++++++++++----- .../HashBattle/HashBattleTest/ArenaTest.cs | 37 +++-- .../HashBattleTest/InMemoryState.cs | 67 +++++---- Mainnet/HashBattle/README.MD | 4 +- 4 files changed, 156 insertions(+), 89 deletions(-) diff --git a/Mainnet/HashBattle/HashBattle/Arena.cs b/Mainnet/HashBattle/HashBattle/Arena.cs index 8fd58dc8..b7cf13f3 100644 --- a/Mainnet/HashBattle/HashBattle/Arena.cs +++ b/Mainnet/HashBattle/HashBattle/Arena.cs @@ -11,6 +11,7 @@ public Arena(ISmartContractState smartContractState) : base(smartContractState) { BattleOwner = Message.Sender; + NextBattleId = 1; } /// @@ -22,34 +23,74 @@ private Address BattleOwner set => PersistentState.SetAddress(nameof(BattleOwner), value); } + public Address PendingBattleOwner + { + get => PersistentState.GetAddress(nameof(PendingBattleOwner)); + private set => PersistentState.SetAddress(nameof(PendingBattleOwner), value); + } + + public void SetPendingBattleOwnership(Address pendingBattleOwner) + { + Assert(Message.Sender == BattleOwner, "UNAUTHORIZED"); + + PendingBattleOwner = pendingBattleOwner; + + Log(new SetPendingDeployerOwnershipLog { From = Message.Sender, To = pendingBattleOwner }); + } + + public void ClaimPendingbattleOwnership() + { + var pendingBattleOwner = PendingBattleOwner; + + Assert(Message.Sender == pendingBattleOwner, "UNAUTHORIZED"); + + var oldOwner = BattleOwner; + + BattleOwner = pendingBattleOwner; + PendingBattleOwner = Address.Zero; + + Log(new ClaimPendingDeployerOwnershipLog { From = oldOwner, To = pendingBattleOwner }); + } + + /// + /// Set the unique battleid of each battle + /// + public ulong NextBattleId + { + get => PersistentState.GetUInt64(ArenaStateKeys.NextBattleId); + private set => PersistentState.SetUInt64(ArenaStateKeys.NextBattleId, value); + } + /// /// Battle owner will start the battle /// - public bool StartBattle(ulong battleId, ulong fee) + public ulong StartBattle(ulong fee) { Assert(Message.Sender == BattleOwner, "Only battle owner can start game."); + ulong battleId = NextBattleId; + NextBattleId += 1; + var battle = new BattleMain(); battle.BattleId = battleId; - battle.MaxUsers = 4; battle.Fee = fee; - battle.Users = new Address[battle.MaxUsers]; + battle.Users = new Address[MaxUsers]; SetBattle(battleId, battle); - Log(battle); - return true; + Log(new BattleEventLog { Event = "Start", BattleId = battleId, Address = Message.Sender }); + return battleId; } /// /// 4 different user will enter the battle /// - public bool EnterBattle(ulong battleId, uint userindex) + public void EnterBattle(ulong battleId) { var battle = GetBattle(battleId); Assert(battle.Winner == Address.Zero, "Battle ended."); - Assert(battle.Fee == Message.Value, "Battle amount is not matching."); + Assert(battle.Fee == Message.Value, "Battle fee is not matching with entry fee paid."); var user = GetUser(battleId, Message.Sender); @@ -59,17 +100,19 @@ public bool EnterBattle(ulong battleId, uint userindex) SetUser(battleId, Message.Sender, user); + uint userindex = GetUserIndex(battleId); battle.Users.SetValue(user.Address, userindex); + SetUserIndex(battleId, (userindex + 1)); + SetBattle(battleId, battle); - Log(battle); - return true; + Log(new BattleEventLog { Event = "Enter", BattleId = battleId, Address = Message.Sender }); } /// /// 4 different user will end the battle and submit the score /// - public bool EndBattle(Address userAddress, ulong battleId, uint score, bool IsBattleOver) + public void EndBattle(Address userAddress, ulong battleId, uint score) { Assert(Message.Sender == BattleOwner, "Only battle owner can end game."); @@ -86,11 +129,13 @@ public bool EndBattle(Address userAddress, ulong battleId, uint score, bool IsBa SetUser(battleId, userAddress, user); - if (IsBattleOver) + uint ScoreSubmittedCount = GetScoreSubmittedCount(battleId); + ScoreSubmittedCount += 1; + if (ScoreSubmittedCount == MaxUsers) ProcessWinner(battle); - Log(user); - return true; + SetScoreSubmittedCount(battleId, ScoreSubmittedCount); + Log(new BattleEventLog { Event = "End", BattleId = battleId, Address = Message.Sender }); } /// @@ -99,7 +144,6 @@ public bool EndBattle(Address userAddress, ulong battleId, uint score, bool IsBa public Address GetWinner(ulong battleId) { var battle = GetBattle(battleId); - Log(battle); return battle.Winner; } @@ -108,22 +152,10 @@ public Address GetWinner(ulong battleId) /// private void ProcessWinner(BattleMain battle) { - if (battle.Users.Length <= 4) - { - foreach (Address userAddress in battle.Users) - { - var user = GetUser(battle.BattleId, userAddress); - if (!user.ScoreSubmitted) - return; - } - } uint winnerIndex = GetWinnerIndex(battle.BattleId, battle.Users); - if (battle.Winner == Address.Zero) - { - battle.Winner = battle.Users[winnerIndex]; - SetBattle(battle.BattleId, battle); - ProcessPrize(battle.BattleId); - } + battle.Winner = battle.Users[winnerIndex]; + SetBattle(battle.BattleId, battle); + ProcessPrize(battle.BattleId); } /// @@ -151,44 +183,75 @@ private uint GetWinnerIndex(ulong battleid, Address[] users) private void ProcessPrize(ulong battleid) { var battle = GetBattle(battleid); - ulong prize = battle.Fee * (battle.MaxUsers - 1); + ulong prize = battle.Fee * (MaxUsers - 1); Transfer(battle.Winner, prize); Transfer(BattleOwner, battle.Fee); } - private void SetUser(ulong battleid, Address address, BattleUser user) { PersistentState.SetStruct($"user:{battleid}:{address}", user); } - private BattleUser GetUser(ulong battleid, Address address) { return PersistentState.GetStruct($"user:{battleid}:{address}"); } - private void SetBattle(ulong battleid, BattleMain battle) { PersistentState.SetStruct($"battle:{battleid}", battle); } - private BattleMain GetBattle(ulong battleid) { return PersistentState.GetStruct($"battle:{battleid}"); } + private void SetUserIndex(ulong battleid, uint userindex) + { + PersistentState.SetUInt32($"user:{battleid}", userindex); + } + private uint GetUserIndex(ulong battleid) + { + return PersistentState.GetUInt32($"user:{battleid}"); + } + private void SetScoreSubmittedCount(ulong battleid, uint scoresubmitcount) + { + PersistentState.SetUInt32($"scoresubmit:{battleid}", scoresubmitcount); + } + private uint GetScoreSubmittedCount(ulong battleid) + { + return PersistentState.GetUInt32($"scoresubmit:{battleid}"); + } + private const uint MaxUsers = 4; public struct BattleMain { public ulong BattleId; public Address Winner; public Address[] Users; - public uint MaxUsers; public ulong Fee; } - public struct BattleUser { public Address Address; public uint Score; public bool ScoreSubmitted; } -} + public struct ArenaStateKeys + { + public const string NextBattleId = "AA"; + } + public struct ClaimPendingDeployerOwnershipLog + { + [Index] public Address From; + [Index] public Address To; + } + public struct SetPendingDeployerOwnershipLog + { + [Index] public Address From; + [Index] public Address To; + } + public struct BattleEventLog + { + [Index] public string Event; + [Index] public ulong BattleId; + [Index] public Address Address; + } +} \ No newline at end of file diff --git a/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs index 29391d2d..2abe5a36 100644 --- a/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs +++ b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs @@ -59,78 +59,78 @@ private Arena StartBattleTest() { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); Arena arena = new Arena(this.mockContractState.Object); - arena.StartBattle(1, 1); + ulong battleId = arena.StartBattle(1); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Start", BattleId = battleId, Address = this.ownerAddress })); return arena; } private void Player1EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress1, 1)); - arena.EnterBattle(1, 0); + arena.EnterBattle(1); Assert.Equal(this.playerAddress1, state.GetStruct($"user:{1}:{this.playerAddress1}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress1 })); } private void Player2EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress2, 1)); - arena.EnterBattle(1, 1); + arena.EnterBattle(1); Assert.Equal(this.playerAddress2, state.GetStruct($"user:{1}:{this.playerAddress2}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress2 })); } private void Player3EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress3, 1)); - arena.EnterBattle(1, 2); + arena.EnterBattle(1); Assert.Equal(this.playerAddress3, state.GetStruct($"user:{1}:{this.playerAddress3}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress3 })); } private void Player4EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress4, 1)); - arena.EnterBattle(1, 3); + arena.EnterBattle(1); Assert.Equal(this.playerAddress4, state.GetStruct($"user:{1}:{this.playerAddress4}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress4 })); } private void Player1EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress1, 1, 10, false); + arena.EndBattle(this.playerAddress1, 1, 10); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); } private void Player2EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress2, 1, 20, false); + arena.EndBattle(this.playerAddress2, 1, 20); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress2}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); } private void Player3EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress3, 1, 30, false); + arena.EndBattle(this.playerAddress3, 1, 30); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress3}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); } private void Player4EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress4, 1, 40, true); + arena.EndBattle(this.playerAddress4, 1, 40); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress4}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); } private void GetGameWinnerTest(Arena arena) @@ -139,7 +139,6 @@ private void GetGameWinnerTest(Arena arena) Address winner = arena.GetWinner(1); Assert.Equal(this.playerAddress4, winner); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); } } } diff --git a/Mainnet/HashBattle/HashBattleTest/InMemoryState.cs b/Mainnet/HashBattle/HashBattleTest/InMemoryState.cs index 8f20e1db..c561a923 100644 --- a/Mainnet/HashBattle/HashBattleTest/InMemoryState.cs +++ b/Mainnet/HashBattle/HashBattleTest/InMemoryState.cs @@ -7,77 +7,82 @@ namespace HashBattleTest public class InMemoryState : IPersistentState { private readonly Dictionary storage = new Dictionary(); + public bool IsContractResult { get; set; } - public void Clear(string key) => storage.Remove(key); - public T GetValue(string key) => (T)storage.GetValueOrDefault(key, default(T)); + public void Clear(string key) => this.storage.Remove(key); + + public T GetValue(string key) => (T)this.storage.GetValueOrDefault(key, default(T)); public void AddOrReplace(string key, object value) { - if (!storage.TryAdd(key, value)) - storage[key] = value; + if (!this.storage.TryAdd(key, value)) + { + this.storage[key] = value; + } } - public Address GetAddress(string key) => GetValue
(key); - public T[] GetArray(string key) => GetValue(key); + public Address GetAddress(string key) => this.GetValue
(key); + + public T[] GetArray(string key) => this.GetValue(key); - public bool GetBool(string key) => GetValue(key); + public bool GetBool(string key) => this.GetValue(key); public byte[] GetBytes(byte[] key) => throw new NotImplementedException(); - public byte[] GetBytes(string key) => GetValue(key); + public byte[] GetBytes(string key) => this.GetValue(key); - public char GetChar(string key) => GetValue(key); + public char GetChar(string key) => this.GetValue(key); - public int GetInt32(string key) => GetValue(key); + public int GetInt32(string key) => this.GetValue(key); - public long GetInt64(string key) => GetValue(key); + public long GetInt64(string key) => this.GetValue(key); - public string GetString(string key) => GetValue(key); + public string GetString(string key) => this.GetValue(key); public T GetStruct(string key) - where T : struct => GetValue(key); + where T : struct => this.GetValue(key); - public uint GetUInt32(string key) => GetValue(key); + public uint GetUInt32(string key) => this.GetValue(key); - public ulong GetUInt64(string key) => GetValue(key); + public ulong GetUInt64(string key) => this.GetValue(key); - public UInt128 GetUInt128(string key) => GetValue(key); + public UInt128 GetUInt128(string key) => this.GetValue(key); - public UInt256 GetUInt256(string key) => GetValue(key); + public UInt256 GetUInt256(string key) => this.GetValue(key); - public bool IsContract(Address address) => IsContractResult; + public bool IsContract(Address address) => this.IsContractResult; - public void SetAddress(string key, Address value) => AddOrReplace(key, value); + public void SetAddress(string key, Address value) => this.AddOrReplace(key, value); - public void SetArray(string key, Array a) => AddOrReplace(key, a); + public void SetArray(string key, Array a) => this.AddOrReplace(key, a); - public void SetBool(string key, bool value) => AddOrReplace(key, value); + public void SetBool(string key, bool value) => this.AddOrReplace(key, value); public void SetBytes(byte[] key, byte[] value) { throw new NotImplementedException(); } - public void SetBytes(string key, byte[] value) => AddOrReplace(key, value); + public void SetBytes(string key, byte[] value) => this.AddOrReplace(key, value); - public void SetChar(string key, char value) => AddOrReplace(key, value); + public void SetChar(string key, char value) => this.AddOrReplace(key, value); - public void SetInt32(string key, int value) => AddOrReplace(key, value); + public void SetInt32(string key, int value) => this.AddOrReplace(key, value); - public void SetInt64(string key, long value) => AddOrReplace(key, value); + public void SetInt64(string key, long value) => this.AddOrReplace(key, value); - public void SetString(string key, string value) => AddOrReplace(key, value); + public void SetString(string key, string value) => this.AddOrReplace(key, value); public void SetStruct(string key, T value) - where T : struct => AddOrReplace(key, value); + where T : struct => this.AddOrReplace(key, value); - public void SetUInt32(string key, uint value) => AddOrReplace(key, value); + public void SetUInt32(string key, uint value) => this.AddOrReplace(key, value); - public void SetUInt64(string key, ulong value) => AddOrReplace(key, value); + public void SetUInt64(string key, ulong value) => this.AddOrReplace(key, value); - public void SetUInt128(string key, UInt128 value) => AddOrReplace(key, value); + public void SetUInt128(string key, UInt128 value) => this.AddOrReplace(key, value); - public void SetUInt256(string key, UInt256 value) => AddOrReplace(key, value); + public void SetUInt256(string key, UInt256 value) => this.AddOrReplace(key, value); } } diff --git a/Mainnet/HashBattle/README.MD b/Mainnet/HashBattle/README.MD index d6fdfb83..c20abe6b 100644 --- a/Mainnet/HashBattle/README.MD +++ b/Mainnet/HashBattle/README.MD @@ -6,10 +6,10 @@ v2.0.0 ``` **Contract Hash** ``` -5fce69c0bdd6e6cf7d1a3ef04c463c6bfb4066bb043dac29d90e2c0806e47c98 +5e13829d8515fedcf41864565fb3cb24a53176209cdb16086b009441ec42c623 ``` **Contract Byte Code** ``` -4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0102009C4DC5BE0000000000000000E00022200B013000001000000002000000000000B22E0000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000602E00004F000000000000000000000000000000000000000000000000000000004000000C000000442E00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000B80E0000002000000010000000020000000000000000000000000000200000602E72656C6F6300000C000000004000000002000000120000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000942E000000000000480000000200050030240000140A00000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000660203280400000A0202280500000A6F0600000A28030000062A4602280700000A72010000706F0800000A2A4A02280700000A7201000070036F0900000A2A001330030064000000010000110202280500000A6F0600000A022802000006280A00000A7219000070280B00000A1200FE15030000021200037D0100000412001A7D040000041200047D050000041200067B040000048D070000017D03000004020306280D0000060206280100002B172A13300400B6000000020000110203280E0000060A02067B020000047E0D00000A280A00000A725D000070280B00000A02067B0500000402280500000A6F0E00000AFE017279000070280B00000A020302280500000A6F0600000A280C0000060B02077B0800000416FE0172D9000070280B00000A120102280500000A6F0600000A7D06000004020302280500000A6F0600000A07280B000006067B03000004077B060000048C07000001046E6F0F00000A020306280D0000060206280100002B172A0000133004008E000000020000110202280500000A6F0600000A022802000006280A00000A721D010070280B00000A0204280E0000060A02067B020000047E0D00000A280A00000A725D000070280B00000A020403280C0000060B02077B0800000416FE0172D9000070280B00000A1201057D070000041201177D0800000402040307280B0000060E042C07020628080000060207280200002B172A00001330020016000000010000110203280E0000060A0206280100002B067B020000042A0000133003008F00000003000011037B030000048E691A3032037B030000040B160C2B210708A3070000010D02037B0100000409280C0000067B080000042D012A0817580C08078E6932D902037B01000004037B0300000428090000060A037B020000047E0D00000A280A00000A2C2C0F01037B0300000406A3070000017D0200000402037B0100000403280D00000602037B01000004280A0000062A00133004003700000004000011160A160B160C2B2502030408A307000001280C0000060D097B07000004063609097B070000040A080B0817D70C086E048E696A32D3072A00133003003B000000050000110203280E0000060A067B05000004067B0400000417DB6ED90B02067B0200000407281000000A2602022802000006067B05000004281000000A262A8E02280700000A725D010070038C0E000001048C07000001281100000A056F0300002B2A8A02280700000A725D010070038C0E000001048C07000001281100000A6F0400002B2A7602280700000A7277010070038C0E000001281400000A046F0500002B2A7202280700000A7277010070038C0E000001281400000A6F0600002B2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C0000007C030000237E0000E80300004403000023537472696E6773000000002C0700009001000023555300BC080000100000002347554944000000CC0800004801000023426C6F6200000000000000020000015715A201090A000000FA013300160000010000000F00000004000000080000000E000000170000001400000003000000050000000100000001000000020000000100000002000000020000000600000000009701010000000000060028015202060048015202060014013F020F00720200000A00D802BA020A00C800BA020A00AA02BA020600B200A9010A006000BA020A00EF00BA0206003103A9010600E602A9010A000103BA0206000100A90106008C01A901000000000800000000000100010001001000110000001500010001000A011000B0010000210001000F000A0110000C020000210006000F0006002E00B0000600E501580006008402B30006008102B80006005800B0000600AA0258000600BC00B80006004000BB0050200000000086183902100001006A20000000008108EC011B0002007C20000000008108FC01BE00020090200000000086009F00C400030000210000000086007F00CA000500C4210000000086007500D00007006022000000008600E201D9000B008422000000008100D401DF000C0020230000000081001803E5000D0064230000000081007F01ED000F00AB230000000081001F02F2001000CF230000000081001702FB001300F22300000000810095000301150010240000000081008B000A01170000000100DC00000001007901000001003700000002005C0000000100370000000200270300000100900200000200370000000300C200000004002C0200000100370000000100AB00000001004F00000002008A02000001004F00000001004F0000000200B202000003002702000001004F0000000200B202000001004F0000000200AB00000001004F00090039020100110039020600190039020A002900390210002900690016004900C0011B0029000001200051009C0225005100A7022B00390037033700290011033F002900930145003900BB015800490066015C005900700160002900CB0183007900D1028B005100F70292005100ED029A007900D102A1002E000B0015012E0013001E012E001B003D01320051006B0075007D0002000100000000021001020002000300010003000300048000000000000000000000000000000000D8020000040000000000000000000000A7001700000000000200000000000000000000000000BA0200000000030002000400020019004C0019006600250066002700660025004C0027004C0000000055496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C696200426174746C65496400626174746C6549640053636F72655375626D697474656400626174746C656964004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F72650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E745374617465006765745F50657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E67004C6F6700536D617274436F6E74726163742E646C6C0053797374656D00426174746C654D61696E005A65726F006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F426174746C654F776E6572007365745F426174746C654F776E657200426174746C6555736572004765745573657200536574557365720075736572004973426174746C654F766572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573004D6178557365727300757365727300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C74004173736572740047657457696E6E6572496E6465780075736572696E646578004172726179006F705F457175616C6974790000001742006100740074006C0065004F0077006E006500720000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001B42006100740074006C006500200065006E006400650064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00001975007300650072003A007B0030007D003A007B0031007D00001562006100740074006C0065003A007B0030007D000000000053FFE06AD37C28419B1B527317B313CF000420010108032000010520010111110520010112190420001225042000111D0420001229052001111D0E062002010E111D040701110C07000202111D111D05200201020E06300101011E00040A01110C060702110C11100306111D0320000B052002011C0A040A011110090704091D111D08111D0707040909091110050702110C0B0720021235111D0B0600030E0E1C1C07300102010E1E00063001011E000E0500020E0E1C087CEC85D7BEA7798E02060B04061D111D02060902060205200101111D052002020B0B052002020B0908200402111D0B0902052001111D0B05200101110C072002090B1D111D042001010B082003010B111D111007200211100B111D062002010B110C052001110C0B042800111D0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F777301080100020000000000000000000000000000000000000010000000000000000000000000000000882E00000000000000000000A22E0000002000000000000000000000000000000000000000000000942E0000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000B43E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010200AAAAE3BF0000000000000000E00022200B013000001600000002000000000000A6340000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000543400004F000000000000000000000000000000000000000000000000000000004000000C000000383400001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000AC140000002000000016000000020000000000000000000000000000200000602E72656C6F6300000C000000004000000002000000180000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000883400000000000048000000020005000C2600002C0E00000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000860203280500000A0202280600000A6F0700000A280300000602176A28090000062A4602280800000A72010000706F0900000A2A4A02280800000A7201000070036F0A00000A2A4602280800000A72190000706F0900000A2A4A02280800000A7219000070036F0A00000A2A1330030052000000010000110202280600000A6F0700000A022802000006280B00000A723F000070280C00000A02032805000006021200FE1507000002120002280600000A6F0700000A7D0C0000041200037D0D00000406280100002B2A0000133003005C000000020000110228040000060A0202280600000A6F0700000A06280B00000A723F000070280C00000A0228020000060B02062803000006027E0E00000A2805000006021202FE15060000021202077D0A0000041202067D0B00000408280200002B2A4602280800000A72590000706F0F00000A2A4A02280800000A7259000070036F1000000A2A000000133003009B000000030000110202280600000A6F0700000A022802000006280B00000A725F000070280C00000A0228080000060A02022808000006176AD728090000061201FE15030000021201067D020000041201037D0500000412011A8D070000017D040000040206072813000006021202FE1508000002120272A30000707D0E0000041202067D0F000004120202280600000A6F0700000A7D1000000408280300002B062A0013300400F500000004000011020328140000060A02067B030000047E0E00000A280B00000A72AF000070280C00000A02067B0500000402280600000A6F1100000AFE0172CB000070280C00000A020302280600000A6F0700000A28120000060B02077B0800000416FE01722B010070280C00000A120102280600000A6F0700000A7D06000004020302280600000A6F0700000A072811000006020328160000060C067B04000004077B060000048C07000001086E6F1200000A02030817D728150000060203062813000006021203FE15080000021203726F0100707D0E0000041203037D0F000004120302280600000A6F0700000A7D1000000409280300002B2A00000013300400CF000000040000110202280600000A6F0700000A022802000006280B00000A727B010070280C00000A020428140000060A02067B030000047E0E00000A280B00000A72AF000070280C00000A02040328120000060B02077B0800000416FE01722B010070280C00000A1201057D070000041201177D08000004020403072811000006020428180000060C0817D70C081A33070206280E0000060204082817000006021203FE1508000002120372BB0100707D0E0000041203047D0F000004120302280600000A6F0700000A7D1000000409280300002B2A36020328140000067B030000042A00000013300300400000000500001102037B02000004037B04000004280F0000060A0F01037B0400000406A3070000017D0300000402037B0200000403281300000602037B0200000428100000062A133004003700000006000011160A160B160C2B2502030408A30700000128120000060D097B07000004063609097B070000040A080B0817D70C086E048E696A32D3072A00133003003400000007000011020328140000060A067B05000004196AD90B02067B0300000407281300000A2602022802000006067B05000004281300000A262A8E02280800000A72C3010070038C0F000001048C07000001281400000A056F0400002B2A8A02280800000A72C3010070038C0F000001048C07000001281400000A6F0500002B2A7602280800000A72DD010070038C0F000001281700000A046F0600002B2A7202280800000A72DD010070038C0F000001281700000A6F0700002B2A7602280800000A72F3010070038C0F000001281700000A046F1800000A2A7202280800000A72F3010070038C0F000001281700000A6F1900000A2A7602280800000A7205020070038C0F000001281700000A046F1800000A2A7202280800000A7205020070038C0F000001281700000A6F1900000A2A42534A4201000100000000000C00000076342E302E33303331390000000005006C0000003C050000237E0000A8050000B804000023537472696E677300000000600A00002802000023555300880C0000100000002347554944000000980C00009401000023426C6F620000000000000002000001579DA201090A000000FA01330016000001000000100000000800000010000000180000001D00000019000000020000000A00000001000000070000000100000003000000060000000100000002000000060000000700000000002B0201000000000006006201580306009101580306004E0145030F00780300000A00ED03C0030A000201C0030A00B003C0030600EC003D020A008201C0030A009A00C0030A002901C0030600A5043D020600FB033D020A001604C003060022003D020600D5013D02000000002900000000000100010001001000320000001500010001000A011000490200002100020019000A0110001F0300002100060019000A011000D70300002100090019000A011000DC01000021000A0019000A011000FD01000021000C0019000A0110001C02000021000E00190051808703ED0006006800F0000600B7025A0006008A03F30006009200F0000600B0035A000600F600ED0006007A00F80056806400FB00060044025A00060054025A00060044025A00060054025A0006002604FB0006006800F0000600B0035A0050200000000086183F03100001007220000000008108BE021B0002008420000000008108CE02FE0002009720000000008608DE021B000300A920000000008108F502FE000300BC200000000086005C02FE0004001C2100000000860076020600050084210000000086084F00850005009621000000008108600004010500AC21000000008600D900090106005422000000008600B900040107005823000000008600AF000E0108003324000000008600B40216010B004424000000008100A6021C010C009024000000008100720422010D00D424000000008100C80104010F00142500000000810032032A01100038250000000081002A03330113005B25000000008100CF003B0115007925000000008100C5004201170096250000000081008E0448011800B42500000000810081044E011A00D125000000008100430448011B00EF250000000081002C044E011D0000000100160100000100C20100000100C201000001000C0300000100C20100000100960000000100710000000100960300000200710000000300FC0000000100710000000100E50000000100890000000200900300000100890000000100890000000200B803000003003A0300000100890000000200B80300000100890000000200E500000001008900000001008900000002009B04000001008900000001008900000002005A0400000100890009003F03010011003F03060019003F030A0049003F03060029003F0310002900A3001600510092021B0029003A0120005900A20325005900AD032B003900AB04370029006B043F00290027024500390057025A0059001500630059001F0068005100AF0185006100B901890029009D02A1008100E603A90059000C04B00059000204BD008100E603C40059000B00CF0059000100D50009000400E3000E002400E8002E000B005C012E00130065012E001B008401410123008D01610123008D01810123008D01A10123008D01C10123008D01E10123008D01010223008D010000010000000500320051006E007B008F0093009B00020001000000130353010000F9025301000064005801020002000300010003000300020004000500010005000500020008000700010009000700048000000000000000000000000000000000ED030000040000000000000000000000DA003800000000000200000000000000000000000000C003000000000300020004000200050002000600020007000200080002001B004C001B005E001B0076002B00B8002D00B8002B00CA002D00CA00000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C6549640053636F72655375626D697474656400626174746C656964004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F72650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E745374617465006765745F50657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E6700436C61696D50656E64696E674465706C6F7965724F776E6572736869704C6F670053657450656E64696E674465706C6F7965724F776E6572736869704C6F6700426174746C654576656E744C6F6700536D617274436F6E74726163742E646C6C0053797374656D0046726F6D00426174746C654D61696E00546F005A65726F0053657450656E64696E67426174746C654F776E65727368697000436C61696D50656E64696E67626174746C654F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F426174746C654F776E6572007365745F426174746C654F776E6572006765745F50656E64696E67426174746C654F776E6572007365745F50656E64696E67426174746C654F776E65720070656E64696E67426174746C654F776E657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573004D6178557365727300757365727300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E747261637473004172656E6153746174654B65797300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C74004576656E740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E740073636F72657375626D6974636F756E74004173736572740047657457696E6E6572496E6465780047657455736572496E6465780053657455736572496E6465780075736572696E646578004172726179006F705F457175616C6974790000001742006100740074006C0065004F0077006E00650072000025500065006E00640069006E00670042006100740074006C0065004F0077006E0065007200001955004E0041005500540048004F00520049005A004500440000054100410000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00000B53007400610072007400001B42006100740074006C006500200065006E006400650064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00000B45006E00740065007200003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00000745006E006400001975007300650072003A007B0030007D003A007B0031007D00001562006100740074006C0065003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D0000000000CFF3EE9009948343B2584BB5AFD6DD78000420010108032000010520010111110520010112190420001229042000111D042000122D052001111D0E062002010E111D040701111C07000202111D111D05200201020E06300101011E00040A01111C080703111D111D11180306111D040A0111180420010B0E052002010E0B0707030B110C1120040A011120090704110C11100911200320000B052002011C0A030701090707040909091110050702110C0B0720021239111D0B0600030E0E1C1C07300102010E1E00040A011110063001011E000E0500020E0E1C040A01110C052002010E09042001090E087CEC85D7BEA7798E0404000000044100410002060902060B04061D111D02060202060E05200101111D042001010B0420010B0B07200301111D0B09052001111D0B05200101110C072002090B1D111D082003010B111D111007200211100B111D062002010B110C052001110C0B052002010B09042001090B042800111D0328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F77730108010002000000000004010000000000000000000000000000000000100000000000000000000000000000007C34000000000000000000009634000000200000000000000000000000000000000000000000000088340000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000A83400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ``` From bc2fabeebac72c633678a83f94382e0e1487a5d2 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Thu, 1 Jun 2023 10:30:44 +0530 Subject: [PATCH 3/7] Added feedback changes --- Mainnet/HashBattle/HashBattle/Arena.cs | 264 +++++++++--------- .../HashBattle/HashBattle/HashBattle.csproj | 4 +- .../HashBattle/HashBattleTest/ArenaTest.cs | 4 - Mainnet/HashBattle/README.MD | 4 +- 4 files changed, 143 insertions(+), 133 deletions(-) diff --git a/Mainnet/HashBattle/HashBattle/Arena.cs b/Mainnet/HashBattle/HashBattle/Arena.cs index b7cf13f3..dae30c49 100644 --- a/Mainnet/HashBattle/HashBattle/Arena.cs +++ b/Mainnet/HashBattle/HashBattle/Arena.cs @@ -7,80 +7,111 @@ ///
public class Arena : SmartContract { - public Arena(ISmartContractState smartContractState) - : base(smartContractState) + private const uint MaxUsers = 4; + public struct BattleMain { - BattleOwner = Message.Sender; - NextBattleId = 1; + public ulong BattleId; + public Address Winner; + public Address[] Users; + public ulong Fee; + public bool IsCancelled; + } + public struct BattleUser + { + public uint Score; + public bool ScoreSubmitted; + } + public struct BattleHighestScorer + { + public uint Score; + public Address[] Scorers; + } + public struct ClaimPendingDeployerOwnershipLog + { + [Index] public Address From; + [Index] public Address To; + } + public struct SetPendingDeployerOwnershipLog + { + [Index] public Address From; + [Index] public Address To; + } + public struct BattleEventLog + { + [Index] public string Event; + [Index] public ulong BattleId; + [Index] public Address Address; } - /// /// Set the address deploying the contract as battle owner /// - private Address BattleOwner + public Address Owner { - get => PersistentState.GetAddress(nameof(BattleOwner)); - set => PersistentState.SetAddress(nameof(BattleOwner), value); + get => State.GetAddress(nameof(Owner)); + private set => State.SetAddress(nameof(Owner), value); } - - public Address PendingBattleOwner + public Address PendingOwner + { + get => State.GetAddress(nameof(PendingOwner)); + private set => State.SetAddress(nameof(PendingOwner), value); + } + /// + /// Set the unique battleId of each battle + /// + public ulong NextBattleId { - get => PersistentState.GetAddress(nameof(PendingBattleOwner)); - private set => PersistentState.SetAddress(nameof(PendingBattleOwner), value); + get => State.GetUInt64(nameof(NextBattleId)); + private set => State.SetUInt64(nameof(NextBattleId), value); } - public void SetPendingBattleOwnership(Address pendingBattleOwner) + public Arena(ISmartContractState smartContractState) : base(smartContractState) { - Assert(Message.Sender == BattleOwner, "UNAUTHORIZED"); + Owner = Message.Sender; + NextBattleId = 1; + } + public void SetPendingOwnership(Address pendingOwner) + { + EnsureOwnerOnly(); - PendingBattleOwner = pendingBattleOwner; + PendingOwner = pendingOwner; - Log(new SetPendingDeployerOwnershipLog { From = Message.Sender, To = pendingBattleOwner }); + Log(new SetPendingDeployerOwnershipLog { From = Message.Sender, To = pendingOwner }); } - - public void ClaimPendingbattleOwnership() + public void ClaimPendingOwnership() { - var pendingBattleOwner = PendingBattleOwner; - - Assert(Message.Sender == pendingBattleOwner, "UNAUTHORIZED"); + var pendingOwner = PendingOwner; - var oldOwner = BattleOwner; + Assert(Message.Sender == pendingOwner, "HASHBATTLE: UNAUTHORIZED"); - BattleOwner = pendingBattleOwner; - PendingBattleOwner = Address.Zero; + var oldOwner = Owner; - Log(new ClaimPendingDeployerOwnershipLog { From = oldOwner, To = pendingBattleOwner }); - } + Owner = pendingOwner; + PendingOwner = Address.Zero; - /// - /// Set the unique battleid of each battle - /// - public ulong NextBattleId - { - get => PersistentState.GetUInt64(ArenaStateKeys.NextBattleId); - private set => PersistentState.SetUInt64(ArenaStateKeys.NextBattleId, value); + Log(new ClaimPendingDeployerOwnershipLog { From = oldOwner, To = pendingOwner }); } - /// /// Battle owner will start the battle /// public ulong StartBattle(ulong fee) { - Assert(Message.Sender == BattleOwner, "Only battle owner can start game."); + Assert(Message.Sender == Owner, "Only battle owner can start game."); + Assert(fee < ulong.MaxValue / MaxUsers, "Fee is too high"); - ulong battleId = NextBattleId; + var battleId = NextBattleId; NextBattleId += 1; - var battle = new BattleMain(); - battle.BattleId = battleId; - battle.Fee = fee; - battle.Users = new Address[MaxUsers]; + var battle = new BattleMain + { + BattleId = battleId, + Fee = fee, + Users = new Address[MaxUsers] + }; SetBattle(battleId, battle); Log(new BattleEventLog { Event = "Start", BattleId = battleId, Address = Message.Sender }); return battleId; } - /// /// 4 different user will enter the battle /// @@ -88,7 +119,7 @@ public void EnterBattle(ulong battleId) { var battle = GetBattle(battleId); - Assert(battle.Winner == Address.Zero, "Battle ended."); + Assert(battle.Winner == Address.Zero, "Battle not found."); Assert(battle.Fee == Message.Value, "Battle fee is not matching with entry fee paid."); @@ -96,29 +127,27 @@ public void EnterBattle(ulong battleId) Assert(!user.ScoreSubmitted, "The user already submitted score."); - user.Address = Message.Sender; - SetUser(battleId, Message.Sender, user); - uint userindex = GetUserIndex(battleId); - battle.Users.SetValue(user.Address, userindex); + var userindex = GetUserIndex(battleId); + Assert(userindex != MaxUsers, "Max user reached for this battle."); + battle.Users.SetValue(Message.Sender, userindex); SetUserIndex(battleId, (userindex + 1)); SetBattle(battleId, battle); Log(new BattleEventLog { Event = "Enter", BattleId = battleId, Address = Message.Sender }); } - /// /// 4 different user will end the battle and submit the score /// public void EndBattle(Address userAddress, ulong battleId, uint score) { - Assert(Message.Sender == BattleOwner, "Only battle owner can end game."); + Assert(Message.Sender == Owner, "Only battle owner can end game."); var battle = GetBattle(battleId); - Assert(battle.Winner == Address.Zero, "Battle ended."); + Assert(battle.Winner == Address.Zero, "Battle not found."); var user = GetUser(battleId, userAddress); @@ -129,15 +158,33 @@ public void EndBattle(Address userAddress, ulong battleId, uint score) SetUser(battleId, userAddress, user); - uint ScoreSubmittedCount = GetScoreSubmittedCount(battleId); + var ScoreSubmittedCount = GetScoreSubmittedCount(battleId); ScoreSubmittedCount += 1; + SetScoreSubmittedCount(battleId, ScoreSubmittedCount); + + var highestScorer = GetHighestScorer(battleId); + + if (score > highestScorer.Score) + SetHighestScorer(battleId, new BattleHighestScorer { Scorers = new Address[] { userAddress }, Score = score }); + else if (score == highestScorer.Score) + { + var scorers = highestScorer.Scorers; + Array.Resize(ref scorers, scorers.Length + 1); + scorers[scorers.Length - 1] = userAddress; + SetHighestScorer(battleId, new BattleHighestScorer { Scorers = scorers, Score = score }); + } + if (ScoreSubmittedCount == MaxUsers) - ProcessWinner(battle); + { + highestScorer = GetHighestScorer(battleId); + if (highestScorer.Scorers.Length > 1) + CancelBattle(battle); + else + ProcessWinner(battle, highestScorer.Scorers[0]); + } - SetScoreSubmittedCount(battleId, ScoreSubmittedCount); Log(new BattleEventLog { Event = "End", BattleId = battleId, Address = Message.Sender }); } - /// /// Get winner address /// @@ -146,112 +193,79 @@ public Address GetWinner(ulong battleId) var battle = GetBattle(battleId); return battle.Winner; } - /// /// Process winner when all user scores are submitted /// - private void ProcessWinner(BattleMain battle) + private void ProcessWinner(BattleMain battle, Address winnerAddress) { - uint winnerIndex = GetWinnerIndex(battle.BattleId, battle.Users); - battle.Winner = battle.Users[winnerIndex]; + battle.Winner = winnerAddress; SetBattle(battle.BattleId, battle); - ProcessPrize(battle.BattleId); - } - - /// - /// Get winner user index from battle users - /// - private uint GetWinnerIndex(ulong battleid, Address[] users) - { - uint winningScore = 0; - uint winningScoreIndex = 0; - for (uint i = 0; i < users.Length; i++) - { - var user = GetUser(battleid, users[i]); - if (user.Score > winningScore) - { - winningScore = user.Score; - winningScoreIndex = i; - } - } - return winningScoreIndex; + ProcessPrize(battle); } - /// /// Send 3/4 amount to winner and 1/4 amount to battle owner /// - private void ProcessPrize(ulong battleid) + private void ProcessPrize(BattleMain battle) { - var battle = GetBattle(battleid); - ulong prize = battle.Fee * (MaxUsers - 1); + var prize = battle.Fee * (MaxUsers - 1); Transfer(battle.Winner, prize); - Transfer(BattleOwner, battle.Fee); - } - private void SetUser(ulong battleid, Address address, BattleUser user) - { - PersistentState.SetStruct($"user:{battleid}:{address}", user); - } - private BattleUser GetUser(ulong battleid, Address address) - { - return PersistentState.GetStruct($"user:{battleid}:{address}"); + Transfer(Owner, battle.Fee); } - private void SetBattle(ulong battleid, BattleMain battle) + /// + /// Cancel battle and refund the fee amount + /// + private void CancelBattle(BattleMain battle) { - PersistentState.SetStruct($"battle:{battleid}", battle); + battle.IsCancelled = true; + SetBattle(battle.BattleId, battle); + + Transfer(battle.Users[0], battle.Fee); + Transfer(battle.Users[1], battle.Fee); + Transfer(battle.Users[2], battle.Fee); + Transfer(battle.Users[3], battle.Fee); } - private BattleMain GetBattle(ulong battleid) + private void SetBattle(ulong battleId, BattleMain battle) { - return PersistentState.GetStruct($"battle:{battleid}"); + State.SetStruct($"battle:{battleId}", battle); } - private void SetUserIndex(ulong battleid, uint userindex) + public BattleMain GetBattle(ulong battleId) { - PersistentState.SetUInt32($"user:{battleid}", userindex); + return State.GetStruct($"battle:{battleId}"); } - private uint GetUserIndex(ulong battleid) + private void SetUser(ulong battleId, Address address, BattleUser user) { - return PersistentState.GetUInt32($"user:{battleid}"); + State.SetStruct($"user:{battleId}-{address}", user); } - private void SetScoreSubmittedCount(ulong battleid, uint scoresubmitcount) + public BattleUser GetUser(ulong battleId, Address address) { - PersistentState.SetUInt32($"scoresubmit:{battleid}", scoresubmitcount); + return State.GetStruct($"user:{battleId}-{address}"); } - private uint GetScoreSubmittedCount(ulong battleid) + private void SetHighestScorer(ulong battleId, BattleHighestScorer highestScorer) { - return PersistentState.GetUInt32($"scoresubmit:{battleid}"); + State.SetStruct($"scorer:{battleId}", highestScorer); } - - private const uint MaxUsers = 4; - public struct BattleMain + public BattleHighestScorer GetHighestScorer(ulong battleId) { - public ulong BattleId; - public Address Winner; - public Address[] Users; - public ulong Fee; + return State.GetStruct($"scorer:{battleId}"); } - public struct BattleUser + private void SetUserIndex(ulong battleId, uint userindex) { - public Address Address; - public uint Score; - public bool ScoreSubmitted; + State.SetUInt32($"user:{battleId}", userindex); } - public struct ArenaStateKeys + private uint GetUserIndex(ulong battleId) { - public const string NextBattleId = "AA"; + return State.GetUInt32($"user:{battleId}"); } - public struct ClaimPendingDeployerOwnershipLog + private void SetScoreSubmittedCount(ulong battleId, uint scoresubmitcount) { - [Index] public Address From; - [Index] public Address To; + State.SetUInt32($"scoresubmit:{battleId}", scoresubmitcount); } - public struct SetPendingDeployerOwnershipLog + private uint GetScoreSubmittedCount(ulong battleId) { - [Index] public Address From; - [Index] public Address To; + return State.GetUInt32($"scoresubmit:{battleId}"); } - public struct BattleEventLog + private void EnsureOwnerOnly() { - [Index] public string Event; - [Index] public ulong BattleId; - [Index] public Address Address; + Assert(Message.Sender == Owner, "HASHBATTLE: UNAUTHORIZED"); } } \ No newline at end of file diff --git a/Mainnet/HashBattle/HashBattle/HashBattle.csproj b/Mainnet/HashBattle/HashBattle/HashBattle.csproj index 780e51c7..1f433bdc 100644 --- a/Mainnet/HashBattle/HashBattle/HashBattle.csproj +++ b/Mainnet/HashBattle/HashBattle/HashBattle.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.1 @@ -6,6 +6,6 @@ 8.0 - + diff --git a/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs index 2abe5a36..2b1e2146 100644 --- a/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs +++ b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs @@ -70,7 +70,6 @@ private void Player1EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress1, 1)); arena.EnterBattle(1); - Assert.Equal(this.playerAddress1, state.GetStruct($"user:{1}:{this.playerAddress1}").Address); this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress1 })); } @@ -79,7 +78,6 @@ private void Player2EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress2, 1)); arena.EnterBattle(1); - Assert.Equal(this.playerAddress2, state.GetStruct($"user:{1}:{this.playerAddress2}").Address); this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress2 })); } @@ -88,7 +86,6 @@ private void Player3EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress3, 1)); arena.EnterBattle(1); - Assert.Equal(this.playerAddress3, state.GetStruct($"user:{1}:{this.playerAddress3}").Address); this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress3 })); } @@ -97,7 +94,6 @@ private void Player4EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress4, 1)); arena.EnterBattle(1); - Assert.Equal(this.playerAddress4, state.GetStruct($"user:{1}:{this.playerAddress4}").Address); this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress4 })); } diff --git a/Mainnet/HashBattle/README.MD b/Mainnet/HashBattle/README.MD index c20abe6b..f6aa6f96 100644 --- a/Mainnet/HashBattle/README.MD +++ b/Mainnet/HashBattle/README.MD @@ -6,10 +6,10 @@ v2.0.0 ``` **Contract Hash** ``` -5e13829d8515fedcf41864565fb3cb24a53176209cdb16086b009441ec42c623 +fbbeefdf5a2eee7b739911cfbfa43dcdace5867813806a19273f1be3487568e4 ``` **Contract Byte Code** ``` -4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010200AAAAE3BF0000000000000000E00022200B013000001600000002000000000000A6340000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000543400004F000000000000000000000000000000000000000000000000000000004000000C000000383400001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000AC140000002000000016000000020000000000000000000000000000200000602E72656C6F6300000C000000004000000002000000180000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000883400000000000048000000020005000C2600002C0E00000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000860203280500000A0202280600000A6F0700000A280300000602176A28090000062A4602280800000A72010000706F0900000A2A4A02280800000A7201000070036F0A00000A2A4602280800000A72190000706F0900000A2A4A02280800000A7219000070036F0A00000A2A1330030052000000010000110202280600000A6F0700000A022802000006280B00000A723F000070280C00000A02032805000006021200FE1507000002120002280600000A6F0700000A7D0C0000041200037D0D00000406280100002B2A0000133003005C000000020000110228040000060A0202280600000A6F0700000A06280B00000A723F000070280C00000A0228020000060B02062803000006027E0E00000A2805000006021202FE15060000021202077D0A0000041202067D0B00000408280200002B2A4602280800000A72590000706F0F00000A2A4A02280800000A7259000070036F1000000A2A000000133003009B000000030000110202280600000A6F0700000A022802000006280B00000A725F000070280C00000A0228080000060A02022808000006176AD728090000061201FE15030000021201067D020000041201037D0500000412011A8D070000017D040000040206072813000006021202FE1508000002120272A30000707D0E0000041202067D0F000004120202280600000A6F0700000A7D1000000408280300002B062A0013300400F500000004000011020328140000060A02067B030000047E0E00000A280B00000A72AF000070280C00000A02067B0500000402280600000A6F1100000AFE0172CB000070280C00000A020302280600000A6F0700000A28120000060B02077B0800000416FE01722B010070280C00000A120102280600000A6F0700000A7D06000004020302280600000A6F0700000A072811000006020328160000060C067B04000004077B060000048C07000001086E6F1200000A02030817D728150000060203062813000006021203FE15080000021203726F0100707D0E0000041203037D0F000004120302280600000A6F0700000A7D1000000409280300002B2A00000013300400CF000000040000110202280600000A6F0700000A022802000006280B00000A727B010070280C00000A020428140000060A02067B030000047E0E00000A280B00000A72AF000070280C00000A02040328120000060B02077B0800000416FE01722B010070280C00000A1201057D070000041201177D08000004020403072811000006020428180000060C0817D70C081A33070206280E0000060204082817000006021203FE1508000002120372BB0100707D0E0000041203047D0F000004120302280600000A6F0700000A7D1000000409280300002B2A36020328140000067B030000042A00000013300300400000000500001102037B02000004037B04000004280F0000060A0F01037B0400000406A3070000017D0300000402037B0200000403281300000602037B0200000428100000062A133004003700000006000011160A160B160C2B2502030408A30700000128120000060D097B07000004063609097B070000040A080B0817D70C086E048E696A32D3072A00133003003400000007000011020328140000060A067B05000004196AD90B02067B0300000407281300000A2602022802000006067B05000004281300000A262A8E02280800000A72C3010070038C0F000001048C07000001281400000A056F0400002B2A8A02280800000A72C3010070038C0F000001048C07000001281400000A6F0500002B2A7602280800000A72DD010070038C0F000001281700000A046F0600002B2A7202280800000A72DD010070038C0F000001281700000A6F0700002B2A7602280800000A72F3010070038C0F000001281700000A046F1800000A2A7202280800000A72F3010070038C0F000001281700000A6F1900000A2A7602280800000A7205020070038C0F000001281700000A046F1800000A2A7202280800000A7205020070038C0F000001281700000A6F1900000A2A42534A4201000100000000000C00000076342E302E33303331390000000005006C0000003C050000237E0000A8050000B804000023537472696E677300000000600A00002802000023555300880C0000100000002347554944000000980C00009401000023426C6F620000000000000002000001579DA201090A000000FA01330016000001000000100000000800000010000000180000001D00000019000000020000000A00000001000000070000000100000003000000060000000100000002000000060000000700000000002B0201000000000006006201580306009101580306004E0145030F00780300000A00ED03C0030A000201C0030A00B003C0030600EC003D020A008201C0030A009A00C0030A002901C0030600A5043D020600FB033D020A001604C003060022003D020600D5013D02000000002900000000000100010001001000320000001500010001000A011000490200002100020019000A0110001F0300002100060019000A011000D70300002100090019000A011000DC01000021000A0019000A011000FD01000021000C0019000A0110001C02000021000E00190051808703ED0006006800F0000600B7025A0006008A03F30006009200F0000600B0035A000600F600ED0006007A00F80056806400FB00060044025A00060054025A00060044025A00060054025A0006002604FB0006006800F0000600B0035A0050200000000086183F03100001007220000000008108BE021B0002008420000000008108CE02FE0002009720000000008608DE021B000300A920000000008108F502FE000300BC200000000086005C02FE0004001C2100000000860076020600050084210000000086084F00850005009621000000008108600004010500AC21000000008600D900090106005422000000008600B900040107005823000000008600AF000E0108003324000000008600B40216010B004424000000008100A6021C010C009024000000008100720422010D00D424000000008100C80104010F00142500000000810032032A01100038250000000081002A03330113005B25000000008100CF003B0115007925000000008100C5004201170096250000000081008E0448011800B42500000000810081044E011A00D125000000008100430448011B00EF250000000081002C044E011D0000000100160100000100C20100000100C201000001000C0300000100C20100000100960000000100710000000100960300000200710000000300FC0000000100710000000100E50000000100890000000200900300000100890000000100890000000200B803000003003A0300000100890000000200B80300000100890000000200E500000001008900000001008900000002009B04000001008900000001008900000002005A0400000100890009003F03010011003F03060019003F030A0049003F03060029003F0310002900A3001600510092021B0029003A0120005900A20325005900AD032B003900AB04370029006B043F00290027024500390057025A0059001500630059001F0068005100AF0185006100B901890029009D02A1008100E603A90059000C04B00059000204BD008100E603C40059000B00CF0059000100D50009000400E3000E002400E8002E000B005C012E00130065012E001B008401410123008D01610123008D01810123008D01A10123008D01C10123008D01E10123008D01010223008D010000010000000500320051006E007B008F0093009B00020001000000130353010000F9025301000064005801020002000300010003000300020004000500010005000500020008000700010009000700048000000000000000000000000000000000ED030000040000000000000000000000DA003800000000000200000000000000000000000000C003000000000300020004000200050002000600020007000200080002001B004C001B005E001B0076002B00B8002D00B8002B00CA002D00CA00000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C6549640053636F72655375626D697474656400626174746C656964004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F72650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E745374617465006765745F50657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E6700436C61696D50656E64696E674465706C6F7965724F776E6572736869704C6F670053657450656E64696E674465706C6F7965724F776E6572736869704C6F6700426174746C654576656E744C6F6700536D617274436F6E74726163742E646C6C0053797374656D0046726F6D00426174746C654D61696E00546F005A65726F0053657450656E64696E67426174746C654F776E65727368697000436C61696D50656E64696E67626174746C654F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F426174746C654F776E6572007365745F426174746C654F776E6572006765745F50656E64696E67426174746C654F776E6572007365745F50656E64696E67426174746C654F776E65720070656E64696E67426174746C654F776E657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573004D6178557365727300757365727300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E747261637473004172656E6153746174654B65797300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C74004576656E740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E740073636F72657375626D6974636F756E74004173736572740047657457696E6E6572496E6465780047657455736572496E6465780053657455736572496E6465780075736572696E646578004172726179006F705F457175616C6974790000001742006100740074006C0065004F0077006E00650072000025500065006E00640069006E00670042006100740074006C0065004F0077006E0065007200001955004E0041005500540048004F00520049005A004500440000054100410000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00000B53007400610072007400001B42006100740074006C006500200065006E006400650064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00000B45006E00740065007200003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00000745006E006400001975007300650072003A007B0030007D003A007B0031007D00001562006100740074006C0065003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D0000000000CFF3EE9009948343B2584BB5AFD6DD78000420010108032000010520010111110520010112190420001229042000111D042000122D052001111D0E062002010E111D040701111C07000202111D111D05200201020E06300101011E00040A01111C080703111D111D11180306111D040A0111180420010B0E052002010E0B0707030B110C1120040A011120090704110C11100911200320000B052002011C0A030701090707040909091110050702110C0B0720021239111D0B0600030E0E1C1C07300102010E1E00040A011110063001011E000E0500020E0E1C040A01110C052002010E09042001090E087CEC85D7BEA7798E0404000000044100410002060902060B04061D111D02060202060E05200101111D042001010B0420010B0B07200301111D0B09052001111D0B05200101110C072002090B1D111D082003010B111D111007200211100B111D062002010B110C052001110C0B052002010B09042001090B042800111D0328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F77730108010002000000000004010000000000000000000000000000000000100000000000000000000000000000007C34000000000000000000009634000000200000000000000000000000000000000000000000000088340000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000A83400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0102008F0AD9E30000000000000000E00022200B013000001800000002000000000000E2360000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000903600004F000000000000000000000000000000000000000000000000000000004000000C000000743600001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000E8160000002000000018000000020000000000000000000000000000200000602E72656C6F6300000C0000000040000000020000001A0000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C43600000000000048000000020005002C270000480F000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004602280500000A72010000706F0600000A2A4A02280500000A7201000070036F0700000A2A4602280500000A720D0000706F0600000A2A4A02280500000A720D000070036F0700000A2A4602280500000A72270000706F0800000A2A4A02280500000A7227000070036F0900000A2A860203280A00000A0202280B00000A6F0C00000A280200000602176A28060000062A00000013300300370000000100001102281B00000602032804000006021200FE1507000002120002280B00000A6F0C00000A7D0D0000041200037D0E00000406280100002B2A00133003005C000000020000110228030000060A0202280B00000A6F0C00000A06280E00000A7241000070280F00000A0228010000060B02062802000006027E1000000A2804000006021202FE15060000021202077D0B0000041202067D0C00000408280200002B2A13300300B4000000030000110202280B00000A6F0C00000A022801000006280E00000A7273000070280F00000A020321FFFFFFFFFFFFFF3FFE0572B7000070280F00000A0228050000060A02022805000006176AD728060000061202FE15030000021202067D020000041202037D0500000412021A8D060000017D04000004080B0206072811000006021203FE1508000002120372D70000707D0F0000041203067D10000004120302280B00000A6F0C00000A7D1100000409280300002B062A13300400FA00000004000011020328120000060A02067B030000047E1000000A280E00000A72E3000070280F00000A02067B0500000402280B00000A6F1100000AFE017207010070280F00000A020302280B00000A6F0C00000A28140000060B02077B0800000416FE017267010070280F00000A020302280B00000A6F0C00000A072813000006020328180000060C02081AFE0116FE0172AB010070280F00000A067B0400000402280B00000A6F0C00000A8C06000001086E6F1200000A02030817D728170000060203062811000006021203FE1508000002120372EF0100707D0F0000041203037D10000004120302280B00000A6F0C00000A7D1100000409280300002B2A00001330070087010000050000110202280B00000A6F0C00000A022801000006280E00000A72FB010070280F00000A020428120000060A02067B030000047E1000000A280E00000A72E3000070280F00000A02040328140000060B02077B0800000416FE017267010070280F00000A1201057D070000041201177D080000040204030728130000060204281A0000060C0817D70C0204082819000006020428160000060D05097B09000004363002041204FE15050000021204178D06000001251603A4060000017D0A0000041204057D09000004110428150000062B4E05097B090000043345097B0A0000041305120511058E6917D6280400002B110511058E6917DA03A40600000102041204FE1505000002120411057D0A0000041204057D0900000411042815000006081A332F020428160000060D097B0A0000048E69173109020628100000062B130206097B0A00000416A306000001280E000006021206FE15080000021206723B0200707D0F0000041206047D10000004120602280B00000A6F0C00000A7D110000041106280300002B2A36020328120000067B030000042A760F01047D0300000402037B020000040328110000060203280F0000062A00133003002C00000006000011037B05000004196AD90A02037B0300000406281400000A2602022801000006037B05000004281400000A262A133003007A000000000000000F01177D0600000402037B0200000403281100000602037B0400000416A306000001037B05000004281400000A2602037B0400000417A306000001037B05000004281400000A2602037B0400000418A306000001037B05000004281400000A2602037B0400000419A306000001037B05000004281400000A262A7602280500000A7243020070038C0F000001281500000A046F0500002B2A7202280500000A7243020070038C0F000001281500000A6F0600002B2A8E02280500000A7259020070038C0F000001048C06000001281800000A056F0700002B2A8A02280500000A7259020070038C0F000001048C06000001281800000A6F0800002B2A7602280500000A7273020070038C0F000001281500000A046F0900002B2A7202280500000A7273020070038C0F000001281500000A6F0A00002B2A7602280500000A7289020070038C0F000001281500000A046F1900000A2A7202280500000A7289020070038C0F000001281500000A6F1A00000A2A7602280500000A729B020070038C0F000001281500000A046F1900000A2A7202280500000A729B020070038C0F000001281500000A6F1A00000A2A8A0202280B00000A6F0C00000A022801000006280E00000A7241000070280F00000A2A42534A4201000100000000000C00000076342E302E33303331390000000005006C0000007C050000237E0000E8050000E004000023537472696E677300000000C80A0000BC02000023555300840D0000100000002347554944000000940D0000B401000023426C6F620000000000000002000001571DA201090A000000FA013300160000010000001000000008000000110000001B000000200000001A000000010000000A000000060000000100000003000000060000000100000002000000060000000A00000000003802010000000000060068017F03060097017F03060054016C030F009F0300000A001504F7030A00E703F7030A001C01F7030600FC004A020A008801F7030A004301F7030A009D00F7030600BE044A02060023044A020A003E04F703060022004A020600E2014A02000000002900000000000100010001001000320000001500010001000A01100056020000210002001C000A01100046030000210007001C000A01100002030000210009001C000A011000E901000021000B001C000A0110000A02000021000D001C000A0110002902000021000F001C005180B60301010600680004010600B80265000600B903070106009500040106007A000C01060006010101060086000C010600060101010600AE03070106005102650006006102650006005102650006006102650006004E040F010600680004010600E70365005020000000008608BF02380001006220000000008108C902120101007520000000008608D302380002008720000000008108E402120102009A200000000086084F0087000300AC20000000008108600018010300BF2000000000861866032D000400E4200000000086007F021201050028210000000086006902060006009021000000008600E9001D0106005022000000008600C900180107005823000000008600B20022010800EB24000000008600B5022A010B00F924000000008100A70230010C001825000000008100CE0138010E005025000000008100BC0038010F00D625000000008100DF003E011000F425000000008600D50045011200112600000000810059034B0113003526000000008600510354011600582600000000810027035C0118007626000000008600160363011A009326000000008100A70469011B00B1260000000081009A046F011D00CE260000000081006B0469011E00EC2600000000810054046F0120000927000000008100C4040600210000000100C80100000100C80100000100C80100000100300100000100F50200000100990000000100710000000100CD03000002007100000003000C0100000100710000000100F50000000200BF0300000100F50000000100F50000000100710000000200F50000000100710000000100710000000200EF0300000300610300000100710000000200EF0300000100710000000200380300000100710000000100710000000200B404000001007100000001007100000002008204000001007100090066030100110066030600190066030A004900660306002900120110005100D90315005100E4031B0051001500220051001F002700290066032D002900A60033005900930238002900340242003100D4045700290093045F003100640265005900B50187006100BF018B006100DB01A20029009E02B50081000E04BD0051003404C30051002A04D00081000E04D70051000B00E80051000100EE0009000400FC002E000B007D012E00130086012E001B00A50161012300AE0181012300AE01A1012300AE01C1012300AE01E1012300AE0101022300AE0121022300AE013D004E006E007D009100B100020001000000FC0274010000E802740100006400790102000100030001000200030002000300050001000400050002000500070001000600070004800000000000000000000000000000000015040000040000000000000000000000F3003800000000000200000000000000000000000000F703000000000300020004000200050002000600020007000200080002001B0049001B0069001B0078002700AC002D00CB002F00CB002D00DE002F00DE002D00E3002F00E300000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C65496400497343616E63656C6C65640053636F72655375626D6974746564004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C650043616E63656C426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F7265006765745F53746174650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500526573697A6500537472696E6700436C61696D50656E64696E674465706C6F7965724F776E6572736869704C6F670053657450656E64696E674465706C6F7965724F776E6572736869704C6F6700426174746C654576656E744C6F6700536D617274436F6E74726163742E646C6C0053797374656D0046726F6D00426174746C654D61696E00546F005A65726F00436C61696D50656E64696E674F776E6572736869700053657450656E64696E674F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F4F776E6572007365745F4F776E6572006765745F50656E64696E674F776E6572007365745F50656E64696E674F776E65720070656E64696E674F776E657200426174746C654869676865737453636F726572004765744869676865737453636F726572005365744869676865737453636F726572006869676865737453636F72657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F6465730053636F72657273004D617855736572730077696E6E65724164647265737300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C74004576656E740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E740073636F72657375626D6974636F756E74004173736572740047657455736572496E6465780053657455736572496E6465780075736572696E64657800417272617900456E737572654F776E65724F6E6C79006F705F457175616C69747900000B4F0077006E00650072000019500065006E00640069006E0067004F0077006E006500720000194E0065007800740042006100740074006C006500490064000031480041005300480042004100540054004C0045003A00200055004E0041005500540048004F00520049005A004500440000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001F460065006500200069007300200074006F006F0020006800690067006800000B53007400610072007400002342006100740074006C00650020006E006F007400200066006F0075006E0064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E0000434D00610078002000750073006500720020007200650061006300680065006400200066006F00720020007400680069007300200062006100740074006C0065002E00000B45006E00740065007200003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00000745006E006400001562006100740074006C0065003A007B0030007D00001975007300650072003A007B0030007D002D007B0031007D000115730063006F007200650072003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D00000021967F4B3A466841A58D3F75EE1EBBE700042001010803200001052001011111042000122905200111190E062002010E11190420010B0E052002010E0B05200101121D042000122D0420001119040701111C06300101011E00040A01111C080703111911191118070002021119111905200201020E03061119040A0111180907040B110C110C1120040A011120090704110C11100911200320000B052002011C0A100707110C111009111411141D111911200910010201101D1E0008040A0111190307010B072002123911190B0500020E0E1C07300102010E1E00040A01110C063001011E000E0600030E0E1C1C040A011110040A011114052002010E09042001090E087CEC85D7BEA7798E040400000002060902060B04061D111902060202060E052001011119042001010B0420010B0B0720030111190B0905200111190B07200201110C111905200101110C062002010B110C052001110C0B082003010B1119111007200211100B1119062002010B111405200111140B052002010B09042001090B04280011190328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F77730108010002000000000004010000000000000000000000000000000010000000000000000000000000000000B83600000000000000000000D2360000002000000000000000000000000000000000000000000000C4360000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000E43600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ``` From e4f1855eba9c788cd5d959bc6408b0dd9a1e4907 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 19 Jun 2023 10:16:36 +0530 Subject: [PATCH 4/7] added new feedback changes --- Mainnet/HashBattle/HashBattle/Arena.cs | 174 ++++++++++-------- .../HashBattle/HashBattleTest/ArenaTest.cs | 20 +- 2 files changed, 111 insertions(+), 83 deletions(-) diff --git a/Mainnet/HashBattle/HashBattle/Arena.cs b/Mainnet/HashBattle/HashBattle/Arena.cs index dae30c49..a920a0a2 100644 --- a/Mainnet/HashBattle/HashBattle/Arena.cs +++ b/Mainnet/HashBattle/HashBattle/Arena.cs @@ -7,40 +7,45 @@ ///
public class Arena : SmartContract { - private const uint MaxUsers = 4; - public struct BattleMain + private void SetBattle(ulong battleId, BattleMain battle) { - public ulong BattleId; - public Address Winner; - public Address[] Users; - public ulong Fee; - public bool IsCancelled; + State.SetStruct($"battle:{battleId}", battle); } - public struct BattleUser + public BattleMain GetBattle(ulong battleId) { - public uint Score; - public bool ScoreSubmitted; + return State.GetStruct($"battle:{battleId}"); } - public struct BattleHighestScorer + private void SetUser(ulong battleId, Address address, BattleUser user) { - public uint Score; - public Address[] Scorers; + State.SetStruct($"user:{battleId}:{address}", user); } - public struct ClaimPendingDeployerOwnershipLog + public BattleUser GetUser(ulong battleId, Address address) { - [Index] public Address From; - [Index] public Address To; + return State.GetStruct($"user:{battleId}:{address}"); } - public struct SetPendingDeployerOwnershipLog + private void SetHighestScorer(ulong battleId, BattleHighestScorer highestScorer) { - [Index] public Address From; - [Index] public Address To; + State.SetStruct($"scorer:{battleId}", highestScorer); } - public struct BattleEventLog + public BattleHighestScorer GetHighestScorer(ulong battleId) { - [Index] public string Event; - [Index] public ulong BattleId; - [Index] public Address Address; + return State.GetStruct($"scorer:{battleId}"); + } + private void SetUserIndex(ulong battleId, uint userindex) + { + State.SetUInt32($"user:{battleId}", userindex); + } + private uint GetUserIndex(ulong battleId) + { + return State.GetUInt32($"user:{battleId}"); + } + private void SetScoreSubmittedCount(ulong battleId, uint scoresubmitcount) + { + State.SetUInt32($"scoresubmit:{battleId}", scoresubmitcount); + } + private uint GetScoreSubmittedCount(ulong battleId) + { + return State.GetUInt32($"scoresubmit:{battleId}"); } /// /// Set the address deploying the contract as battle owner @@ -55,6 +60,11 @@ public Address PendingOwner get => State.GetAddress(nameof(PendingOwner)); private set => State.SetAddress(nameof(PendingOwner), value); } + public uint MaxUsers + { + get => State.GetUInt32(nameof(MaxUsers)); + private set => State.SetUInt32(nameof(MaxUsers), value); + } /// /// Set the unique battleId of each battle /// @@ -64,31 +74,41 @@ public ulong NextBattleId private set => State.SetUInt64(nameof(NextBattleId), value); } - public Arena(ISmartContractState smartContractState) : base(smartContractState) + public Arena(ISmartContractState smartContractState, uint maxUsers) : base(smartContractState) { Owner = Message.Sender; + MaxUsers = maxUsers; NextBattleId = 1; } - public void SetPendingOwnership(Address pendingOwner) + + /// + /// Only owner can set new owner and new owner will be in pending state + /// till new owner will call method. + /// + /// The new owner which is going to be in pending state + public void SetPendingOwner(Address newOwner) { EnsureOwnerOnly(); + PendingOwner = newOwner; - PendingOwner = pendingOwner; - - Log(new SetPendingDeployerOwnershipLog { From = Message.Sender, To = pendingOwner }); + Log(new OwnershipTransferRequestedLog { CurrentOwner = Owner, PendingOwner = newOwner }); } - public void ClaimPendingOwnership() + + /// + /// Waiting be called after new owner is requested by call. + /// Pending owner will be new owner after successfull call. + /// + public void ClaimOwnership() { - var pendingOwner = PendingOwner; + var newOwner = PendingOwner; - Assert(Message.Sender == pendingOwner, "HASHBATTLE: UNAUTHORIZED"); + Assert(newOwner == Message.Sender, "ClaimOwnership must be called by the new(pending) owner."); var oldOwner = Owner; - - Owner = pendingOwner; + Owner = newOwner; PendingOwner = Address.Zero; - Log(new ClaimPendingDeployerOwnershipLog { From = oldOwner, To = pendingOwner }); + Log(new OwnershipTransferedLog { PreviousOwner = oldOwner, NewOwner = newOwner }); } /// /// Battle owner will start the battle @@ -109,7 +129,7 @@ public ulong StartBattle(ulong fee) }; SetBattle(battleId, battle); - Log(new BattleEventLog { Event = "Start", BattleId = battleId, Address = Message.Sender }); + Log(new BattleStartedLog { BattleId = battleId, Address = Message.Sender }); return battleId; } /// @@ -132,11 +152,11 @@ public void EnterBattle(ulong battleId) var userindex = GetUserIndex(battleId); Assert(userindex != MaxUsers, "Max user reached for this battle."); battle.Users.SetValue(Message.Sender, userindex); - SetUserIndex(battleId, (userindex + 1)); + SetUserIndex(battleId, userindex + 1); SetBattle(battleId, battle); - Log(new BattleEventLog { Event = "Enter", BattleId = battleId, Address = Message.Sender }); + Log(new BattleEnteredLog { BattleId = battleId, Address = Message.Sender }); } /// /// 4 different user will end the battle and submit the score @@ -145,6 +165,9 @@ public void EndBattle(Address userAddress, ulong battleId, uint score) { Assert(Message.Sender == Owner, "Only battle owner can end game."); + var ScoreSubmittedCount = GetScoreSubmittedCount(battleId); + Assert(ScoreSubmittedCount < MaxUsers, "All users already submitted score."); + var battle = GetBattle(battleId); Assert(battle.Winner == Address.Zero, "Battle not found."); @@ -153,37 +176,39 @@ public void EndBattle(Address userAddress, ulong battleId, uint score) Assert(!user.ScoreSubmitted, "The user already submitted score."); - user.Score = score; user.ScoreSubmitted = true; SetUser(battleId, userAddress, user); - var ScoreSubmittedCount = GetScoreSubmittedCount(battleId); ScoreSubmittedCount += 1; SetScoreSubmittedCount(battleId, ScoreSubmittedCount); var highestScorer = GetHighestScorer(battleId); if (score > highestScorer.Score) - SetHighestScorer(battleId, new BattleHighestScorer { Scorers = new Address[] { userAddress }, Score = score }); + { + highestScorer.Score = score; + highestScorer.HighestScorer = userAddress; + highestScorer.HighestScoreCount = 1; + + SetHighestScorer(battleId, highestScorer); + } else if (score == highestScorer.Score) { - var scorers = highestScorer.Scorers; - Array.Resize(ref scorers, scorers.Length + 1); - scorers[scorers.Length - 1] = userAddress; - SetHighestScorer(battleId, new BattleHighestScorer { Scorers = scorers, Score = score }); + highestScorer.HighestScoreCount++; + SetHighestScorer(battleId, highestScorer); } if (ScoreSubmittedCount == MaxUsers) { highestScorer = GetHighestScorer(battleId); - if (highestScorer.Scorers.Length > 1) + if (highestScorer.HighestScoreCount > 1) CancelBattle(battle); else - ProcessWinner(battle, highestScorer.Scorers[0]); + ProcessWinner(battle, highestScorer.HighestScorer); } - Log(new BattleEventLog { Event = "End", BattleId = battleId, Address = Message.Sender }); + Log(new BattleEndedLog { BattleId = battleId, Address = Message.Sender }); } /// /// Get winner address @@ -224,48 +249,51 @@ private void CancelBattle(BattleMain battle) Transfer(battle.Users[2], battle.Fee); Transfer(battle.Users[3], battle.Fee); } - private void SetBattle(ulong battleId, BattleMain battle) - { - State.SetStruct($"battle:{battleId}", battle); - } - public BattleMain GetBattle(ulong battleId) - { - return State.GetStruct($"battle:{battleId}"); - } - private void SetUser(ulong battleId, Address address, BattleUser user) + private void EnsureOwnerOnly() { - State.SetStruct($"user:{battleId}-{address}", user); + Assert(Message.Sender == Owner, "The method is owner only."); } - public BattleUser GetUser(ulong battleId, Address address) + public struct BattleMain { - return State.GetStruct($"user:{battleId}-{address}"); + public ulong BattleId; + public Address Winner; + public Address[] Users; + public ulong Fee; + public bool IsCancelled; } - private void SetHighestScorer(ulong battleId, BattleHighestScorer highestScorer) + public struct BattleUser { - State.SetStruct($"scorer:{battleId}", highestScorer); + public bool ScoreSubmitted; } - public BattleHighestScorer GetHighestScorer(ulong battleId) + public struct BattleHighestScorer { - return State.GetStruct($"scorer:{battleId}"); + public uint Score; + public uint HighestScoreCount; + public Address HighestScorer; } - private void SetUserIndex(ulong battleId, uint userindex) + public struct OwnershipTransferedLog { - State.SetUInt32($"user:{battleId}", userindex); + [Index] public Address PreviousOwner; + [Index] public Address NewOwner; } - private uint GetUserIndex(ulong battleId) + public struct OwnershipTransferRequestedLog { - return State.GetUInt32($"user:{battleId}"); + [Index] public Address CurrentOwner; + [Index] public Address PendingOwner; } - private void SetScoreSubmittedCount(ulong battleId, uint scoresubmitcount) + public struct BattleStartedLog { - State.SetUInt32($"scoresubmit:{battleId}", scoresubmitcount); + [Index] public ulong BattleId; + [Index] public Address Address; } - private uint GetScoreSubmittedCount(ulong battleId) + public struct BattleEnteredLog { - return State.GetUInt32($"scoresubmit:{battleId}"); + [Index] public ulong BattleId; + [Index] public Address Address; } - private void EnsureOwnerOnly() + public struct BattleEndedLog { - Assert(Message.Sender == Owner, "HASHBATTLE: UNAUTHORIZED"); + [Index] public ulong BattleId; + [Index] public Address Address; } } \ No newline at end of file diff --git a/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs index 2b1e2146..b2227cf1 100644 --- a/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs +++ b/Mainnet/HashBattle/HashBattleTest/ArenaTest.cs @@ -58,10 +58,10 @@ public void TestBattle() private Arena StartBattleTest() { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - Arena arena = new Arena(this.mockContractState.Object); + Arena arena = new Arena(this.mockContractState.Object, 4); ulong battleId = arena.StartBattle(1); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Start", BattleId = battleId, Address = this.ownerAddress })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleStartedLog { BattleId = battleId, Address = this.ownerAddress })); return arena; } @@ -70,7 +70,7 @@ private void Player1EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress1, 1)); arena.EnterBattle(1); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress1 })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress1 })); } private void Player2EnterGameTest(Arena arena) @@ -78,7 +78,7 @@ private void Player2EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress2, 1)); arena.EnterBattle(1); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress2 })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress2 })); } private void Player3EnterGameTest(Arena arena) @@ -86,7 +86,7 @@ private void Player3EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress3, 1)); arena.EnterBattle(1); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress3 })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress3 })); } private void Player4EnterGameTest(Arena arena) @@ -94,7 +94,7 @@ private void Player4EnterGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress4, 1)); arena.EnterBattle(1); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "Enter", BattleId = 1, Address = this.playerAddress4 })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress4 })); } private void Player1EndGameTest(Arena arena) @@ -102,7 +102,7 @@ private void Player1EndGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); arena.EndBattle(this.playerAddress1, 1, 10); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void Player2EndGameTest(Arena arena) @@ -110,7 +110,7 @@ private void Player2EndGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); arena.EndBattle(this.playerAddress2, 1, 20); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void Player3EndGameTest(Arena arena) @@ -118,7 +118,7 @@ private void Player3EndGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); arena.EndBattle(this.playerAddress3, 1, 30); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void Player4EndGameTest(Arena arena) @@ -126,7 +126,7 @@ private void Player4EndGameTest(Arena arena) this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); arena.EndBattle(this.playerAddress4, 1, 40); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEventLog { Event = "End", BattleId = 1, Address = this.ownerAddress })); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void GetGameWinnerTest(Arena arena) From f96982c38a57c040cebd4a2ba56b1c799bdd1358 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 19 Jun 2023 10:20:01 +0530 Subject: [PATCH 5/7] updated read me file --- Mainnet/HashBattle/README.MD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mainnet/HashBattle/README.MD b/Mainnet/HashBattle/README.MD index f6aa6f96..b978d9ba 100644 --- a/Mainnet/HashBattle/README.MD +++ b/Mainnet/HashBattle/README.MD @@ -6,10 +6,10 @@ v2.0.0 ``` **Contract Hash** ``` -fbbeefdf5a2eee7b739911cfbfa43dcdace5867813806a19273f1be3487568e4 +f020a1b71a62a18b53318e8c28266921403d27ac563dcf42e88e7788a0e93c0a ``` **Contract Byte Code** ``` -4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0102008F0AD9E30000000000000000E00022200B013000001800000002000000000000E2360000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000903600004F000000000000000000000000000000000000000000000000000000004000000C000000743600001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000E8160000002000000018000000020000000000000000000000000000200000602E72656C6F6300000C0000000040000000020000001A0000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C43600000000000048000000020005002C270000480F000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004602280500000A72010000706F0600000A2A4A02280500000A7201000070036F0700000A2A4602280500000A720D0000706F0600000A2A4A02280500000A720D000070036F0700000A2A4602280500000A72270000706F0800000A2A4A02280500000A7227000070036F0900000A2A860203280A00000A0202280B00000A6F0C00000A280200000602176A28060000062A00000013300300370000000100001102281B00000602032804000006021200FE1507000002120002280B00000A6F0C00000A7D0D0000041200037D0E00000406280100002B2A00133003005C000000020000110228030000060A0202280B00000A6F0C00000A06280E00000A7241000070280F00000A0228010000060B02062802000006027E1000000A2804000006021202FE15060000021202077D0B0000041202067D0C00000408280200002B2A13300300B4000000030000110202280B00000A6F0C00000A022801000006280E00000A7273000070280F00000A020321FFFFFFFFFFFFFF3FFE0572B7000070280F00000A0228050000060A02022805000006176AD728060000061202FE15030000021202067D020000041202037D0500000412021A8D060000017D04000004080B0206072811000006021203FE1508000002120372D70000707D0F0000041203067D10000004120302280B00000A6F0C00000A7D1100000409280300002B062A13300400FA00000004000011020328120000060A02067B030000047E1000000A280E00000A72E3000070280F00000A02067B0500000402280B00000A6F1100000AFE017207010070280F00000A020302280B00000A6F0C00000A28140000060B02077B0800000416FE017267010070280F00000A020302280B00000A6F0C00000A072813000006020328180000060C02081AFE0116FE0172AB010070280F00000A067B0400000402280B00000A6F0C00000A8C06000001086E6F1200000A02030817D728170000060203062811000006021203FE1508000002120372EF0100707D0F0000041203037D10000004120302280B00000A6F0C00000A7D1100000409280300002B2A00001330070087010000050000110202280B00000A6F0C00000A022801000006280E00000A72FB010070280F00000A020428120000060A02067B030000047E1000000A280E00000A72E3000070280F00000A02040328140000060B02077B0800000416FE017267010070280F00000A1201057D070000041201177D080000040204030728130000060204281A0000060C0817D70C0204082819000006020428160000060D05097B09000004363002041204FE15050000021204178D06000001251603A4060000017D0A0000041204057D09000004110428150000062B4E05097B090000043345097B0A0000041305120511058E6917D6280400002B110511058E6917DA03A40600000102041204FE1505000002120411057D0A0000041204057D0900000411042815000006081A332F020428160000060D097B0A0000048E69173109020628100000062B130206097B0A00000416A306000001280E000006021206FE15080000021206723B0200707D0F0000041206047D10000004120602280B00000A6F0C00000A7D110000041106280300002B2A36020328120000067B030000042A760F01047D0300000402037B020000040328110000060203280F0000062A00133003002C00000006000011037B05000004196AD90A02037B0300000406281400000A2602022801000006037B05000004281400000A262A133003007A000000000000000F01177D0600000402037B0200000403281100000602037B0400000416A306000001037B05000004281400000A2602037B0400000417A306000001037B05000004281400000A2602037B0400000418A306000001037B05000004281400000A2602037B0400000419A306000001037B05000004281400000A262A7602280500000A7243020070038C0F000001281500000A046F0500002B2A7202280500000A7243020070038C0F000001281500000A6F0600002B2A8E02280500000A7259020070038C0F000001048C06000001281800000A056F0700002B2A8A02280500000A7259020070038C0F000001048C06000001281800000A6F0800002B2A7602280500000A7273020070038C0F000001281500000A046F0900002B2A7202280500000A7273020070038C0F000001281500000A6F0A00002B2A7602280500000A7289020070038C0F000001281500000A046F1900000A2A7202280500000A7289020070038C0F000001281500000A6F1A00000A2A7602280500000A729B020070038C0F000001281500000A046F1900000A2A7202280500000A729B020070038C0F000001281500000A6F1A00000A2A8A0202280B00000A6F0C00000A022801000006280E00000A7241000070280F00000A2A42534A4201000100000000000C00000076342E302E33303331390000000005006C0000007C050000237E0000E8050000E004000023537472696E677300000000C80A0000BC02000023555300840D0000100000002347554944000000940D0000B401000023426C6F620000000000000002000001571DA201090A000000FA013300160000010000001000000008000000110000001B000000200000001A000000010000000A000000060000000100000003000000060000000100000002000000060000000A00000000003802010000000000060068017F03060097017F03060054016C030F009F0300000A001504F7030A00E703F7030A001C01F7030600FC004A020A008801F7030A004301F7030A009D00F7030600BE044A02060023044A020A003E04F703060022004A020600E2014A02000000002900000000000100010001001000320000001500010001000A01100056020000210002001C000A01100046030000210007001C000A01100002030000210009001C000A011000E901000021000B001C000A0110000A02000021000D001C000A0110002902000021000F001C005180B60301010600680004010600B80265000600B903070106009500040106007A000C01060006010101060086000C010600060101010600AE03070106005102650006006102650006005102650006006102650006004E040F010600680004010600E70365005020000000008608BF02380001006220000000008108C902120101007520000000008608D302380002008720000000008108E402120102009A200000000086084F0087000300AC20000000008108600018010300BF2000000000861866032D000400E4200000000086007F021201050028210000000086006902060006009021000000008600E9001D0106005022000000008600C900180107005823000000008600B20022010800EB24000000008600B5022A010B00F924000000008100A70230010C001825000000008100CE0138010E005025000000008100BC0038010F00D625000000008100DF003E011000F425000000008600D50045011200112600000000810059034B0113003526000000008600510354011600582600000000810027035C0118007626000000008600160363011A009326000000008100A70469011B00B1260000000081009A046F011D00CE260000000081006B0469011E00EC2600000000810054046F0120000927000000008100C4040600210000000100C80100000100C80100000100C80100000100300100000100F50200000100990000000100710000000100CD03000002007100000003000C0100000100710000000100F50000000200BF0300000100F50000000100F50000000100710000000200F50000000100710000000100710000000200EF0300000300610300000100710000000200EF0300000100710000000200380300000100710000000100710000000200B404000001007100000001007100000002008204000001007100090066030100110066030600190066030A004900660306002900120110005100D90315005100E4031B0051001500220051001F002700290066032D002900A60033005900930238002900340242003100D4045700290093045F003100640265005900B50187006100BF018B006100DB01A20029009E02B50081000E04BD0051003404C30051002A04D00081000E04D70051000B00E80051000100EE0009000400FC002E000B007D012E00130086012E001B00A50161012300AE0181012300AE01A1012300AE01C1012300AE01E1012300AE0101022300AE0121022300AE013D004E006E007D009100B100020001000000FC0274010000E802740100006400790102000100030001000200030002000300050001000400050002000500070001000600070004800000000000000000000000000000000015040000040000000000000000000000F3003800000000000200000000000000000000000000F703000000000300020004000200050002000600020007000200080002001B0049001B0069001B0078002700AC002D00CB002F00CB002D00DE002F00DE002D00E3002F00E300000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C65496400497343616E63656C6C65640053636F72655375626D6974746564004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C650043616E63656C426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F7265006765745F53746174650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500526573697A6500537472696E6700436C61696D50656E64696E674465706C6F7965724F776E6572736869704C6F670053657450656E64696E674465706C6F7965724F776E6572736869704C6F6700426174746C654576656E744C6F6700536D617274436F6E74726163742E646C6C0053797374656D0046726F6D00426174746C654D61696E00546F005A65726F00436C61696D50656E64696E674F776E6572736869700053657450656E64696E674F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F4F776E6572007365745F4F776E6572006765745F50656E64696E674F776E6572007365745F50656E64696E674F776E65720070656E64696E674F776E657200426174746C654869676865737453636F726572004765744869676865737453636F726572005365744869676865737453636F726572006869676865737453636F72657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F6465730053636F72657273004D617855736572730077696E6E65724164647265737300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C74004576656E740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E740073636F72657375626D6974636F756E74004173736572740047657455736572496E6465780053657455736572496E6465780075736572696E64657800417272617900456E737572654F776E65724F6E6C79006F705F457175616C69747900000B4F0077006E00650072000019500065006E00640069006E0067004F0077006E006500720000194E0065007800740042006100740074006C006500490064000031480041005300480042004100540054004C0045003A00200055004E0041005500540048004F00520049005A004500440000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001F460065006500200069007300200074006F006F0020006800690067006800000B53007400610072007400002342006100740074006C00650020006E006F007400200066006F0075006E0064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E0000434D00610078002000750073006500720020007200650061006300680065006400200066006F00720020007400680069007300200062006100740074006C0065002E00000B45006E00740065007200003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00000745006E006400001562006100740074006C0065003A007B0030007D00001975007300650072003A007B0030007D002D007B0031007D000115730063006F007200650072003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D00000021967F4B3A466841A58D3F75EE1EBBE700042001010803200001052001011111042000122905200111190E062002010E11190420010B0E052002010E0B05200101121D042000122D0420001119040701111C06300101011E00040A01111C080703111911191118070002021119111905200201020E03061119040A0111180907040B110C110C1120040A011120090704110C11100911200320000B052002011C0A100707110C111009111411141D111911200910010201101D1E0008040A0111190307010B072002123911190B0500020E0E1C07300102010E1E00040A01110C063001011E000E0600030E0E1C1C040A011110040A011114052002010E09042001090E087CEC85D7BEA7798E040400000002060902060B04061D111902060202060E052001011119042001010B0420010B0B0720030111190B0905200111190B07200201110C111905200101110C062002010B110C052001110C0B082003010B1119111007200211100B1119062002010B111405200111140B052002010B09042001090B04280011190328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F77730108010002000000000004010000000000000000000000000000000010000000000000000000000000000000B83600000000000000000000D2360000002000000000000000000000000000000000000000000000C4360000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000E43600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0102006CF437BE0000000000000000E00022200B013000001A0000000200000000000022380000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000D03700004F000000000000000000000000000000000000000000000000000000004000000C000000B43700001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E746578740000002818000000200000001A000000020000000000000000000000000000200000602E72656C6F6300000C0000000040000000020000001C00000000000000000000000000004000004200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000438000000000000480000000200050010270000A410000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007602280500000A7201000070038C0B000001280600000A046F0100002B2A7202280500000A7201000070038C0B000001280600000A6F0200002B2A8E02280500000A7217000070038C0B000001048C06000001280900000A056F0300002B2A8A02280500000A7217000070038C0B000001048C06000001280900000A6F0400002B2A7602280500000A7231000070038C0B000001280600000A046F0500002B2A7202280500000A7231000070038C0B000001280600000A6F0600002B2A7602280500000A7247000070038C0B000001280600000A046F0A00000A2A7202280500000A7247000070038C0B000001280600000A6F0B00000A2A7602280500000A7259000070038C0B000001280600000A046F0A00000A2A7202280500000A7259000070038C0B000001280600000A6F0B00000A2A4602280500000A72790000706F0C00000A2A4A02280500000A7279000070036F0D00000A2A4602280500000A72850000706F0C00000A2A4A02280500000A7285000070036F0D00000A2A4602280500000A729F0000706F0B00000A2A4A02280500000A729F000070036F0A00000A2A4602280500000A72B10000706F0E00000A2A4A02280500000A72B1000070036F0F00000A2AA20203281000000A0202281100000A6F1200000A280C0000060204281000000602176A28120000062A13300300320000000100001102281D0000060203280E000006021200FE1507000002120002280B0000067D0C0000041200037D0D00000406280700002B2A0000133003005C0000000200001102280D0000060A020602281100000A6F1200000A281400000A72CB000070281500000A02280B0000060B0206280C000006027E1600000A280E000006021202FE15060000021202077D0A0000041202067D0B00000408280800002B2A13300400AE000000030000110202281100000A6F1200000A02280B000006281400000A723D010070281500000A0203156A02280F0000066E5CFE057281010070281500000A0228110000060A02022811000006176AD728120000061202FE15030000021202067D010000041202037D04000004120202280F0000068D060000017D03000004080B0206072801000006021203FE15080000021203067D0E000004120302281100000A6F1200000A7D0F00000409280900002B062A000013300400F300000004000011020328020000060A02067B020000047E1600000A281400000A72A1010070281500000A02067B0400000402281100000A6F1700000AFE0172C5010070281500000A020302281100000A6F1200000A28040000060B02077B0600000416FE017225020070281500000A020302281100000A6F1200000A072803000006020328080000060C020802280F000006FE0116FE017269020070281500000A067B0300000402281100000A6F1200000A8C06000001086E6F1800000A02030817D728070000060203062801000006021203FE15090000021203037D10000004120302281100000A6F1200000A7D1100000409280A00002B2A001330040045010000050000110202281100000A6F1200000A02280B000006281400000A72AD020070281500000A0204280A0000060A020602280F000006FE0572ED020070281500000A020428020000060B02077B020000047E1600000A281400000A72A1010070281500000A02040328040000060C02087B0600000416FE017225020070281500000A1202177D060000040204030828030000060617D70A0204062809000006020428060000060D05097B0700000436221203057D070000041203037D090000041203177D0800000402040928050000062B1D05097B07000004331412037C08000004254B17D75402040928050000060602280F0000063327020428060000060D097B080000041736090207281C0000062B0D0207097B09000004281A000006021204FE150A0000021204047D12000004120402281100000A6F1200000A7D130000041104280B00002B2A36020328020000067B020000042A760F01047D0200000402037B010000040328010000060203281B0000062A000000133003003300000006000011037B0400000402280F00000617DB6ED90A02037B0200000406281900000A260202280B000006037B04000004281900000A262A00133003007A000000000000000F01177D0500000402037B0100000403280100000602037B0300000416A306000001037B04000004281900000A2602037B0300000417A306000001037B04000004281900000A2602037B0300000418A306000001037B04000004281900000A2602037B0300000419A306000001037B04000004281900000A262A8A0202281100000A6F1200000A02280B000006281400000A7233030070281500000A2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C000000EC050000237E0000580600001C05000023537472696E677300000000740B00006803000023555300DC0E0000100000002347554944000000EC0E0000B801000023426C6F6200000000000000020000015715A201090A000000FA01330016000001000000100000000A000000130000001D00000022000000190000000D000000060000000100000004000000080000000100000002000000080000000B00000000004802010000000000060068019C03060097019C030600540189030F00BC0300000A00440426040A00160426040A001C0126040600FC005A020A00880126040A0043012604060022005A020600DB015A02060052045A020A009D0026040600F9045A020A006D042604000000002900000000000100010001001000320000001500010001000A01100061020000210001001E000A01100063030000210006001E000A0110001F030000210007001E000A011000F101000021000A001E000A0110002A02000021000C001E000A0110001902000021000E001E000A01100008020000210010001E000A011000E2010000210012001E0006006800F2000600A5029B000600E803F50006009500F20006007A00FA0006008600FA0006000601FD000600AB04FD00060047039B000600F2029B0006000D039B00060000039B000600E5029B0006006800F200060016049B0006006800F200060016049B0006006800F200060016049B005020000000008100DF00000101006E20000000008600D500070103008B2000000000810076030D010400AF200000000086006E0316010700D22000000000810044031E010900F020000000008600330325010B000D21000000008100E2042B010C002B21000000008100D50431010E00482100000000810094042B010F0066210000000081007D04310111008321000000008608AC026E0012009521000000008108B60236011200A821000000008608C0026E001300BA21000000008108D10236011300CD21000000008608CB033C011400DF21000000008108D80340011400F2210000000086084F00BD0015000422000000008108600045011500172200000000861883034A0116004022000000008600E202360118008022000000008600710206001900E822000000008600E90051011900A423000000008600C90045011A00A424000000008600B20056011B00F525000000008600A2025E011E000326000000008100940264011F002426000000008100CE016C0121006426000000008100BC006C012200EA26000000008100FF040600230000000100710000000200F500000001007100000001007100000002001E04000003007E03000001007100000002001E0400000100710000000200550300000100710000000100710000000200EF0400000100710000000100710000000200BD0400000100710000000100C80100000100C80100000100C80100000100C80100000100300100000200E50300000100160300000100990000000100710000000100FC03000002007100000003000C0100000100710000000100F50000000200EE0300000100F50000000100F500090083030100110083030600190083030A0049008303060029001201100061003D041500510063041B0051005904280061003D042F0051000B004000510001004600510008044B0051001304510051001500580051001F005D002900830363002900A6006900710080026E0029004402780031000F058D002900CE04950031006C029B007100B501BD007900BF01C10029008B02E1002E000B007F012E00130088012E001B00A70141012300B00161012300B00181012300B001A1012300B001C1012300B001E1012300B00101022300B00121022300B00141022300B00161022300B00173008400A400B300CC00DD00020001000000190372010000E50272010000DC037701000064007B0102000B00030001000C00030002000D00050001000E00050002000F00070001001000070002001100090001001200090004800000000000000000000000000000000044040000040000000000000000000000E9003800000000000200000000000000000000000000260400000000030002000400020005000200060002000700020008000200090002000A0002000F002300110023000F003600110036000F003B0011003B0027007F0027009F002700AE002700C7002700D800000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C65496400497343616E63656C6C65640053636F72655375626D6974746564004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C650043616E63656C426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F7265006765745F53746174650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E6700426174746C65456E6465644C6F67004F776E6572736869705472616E7366657265644C6F6700426174746C65456E74657265644C6F6700426174746C65537461727465644C6F67004F776E6572736869705472616E736665725265717565737465644C6F6700536D617274436F6E74726163742E646C6C0053797374656D00426174746C654D61696E005A65726F00436C61696D4F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F4F776E6572007365745F4F776E6572006765745F50656E64696E674F776E6572007365745F50656E64696E674F776E65720053657450656E64696E674F776E65720050726576696F75734F776E65720043757272656E744F776E6572004E65774F776E6572006E65774F776E657200426174746C654869676865737453636F726572004765744869676865737453636F726572005365744869676865737453636F726572006869676865737453636F72657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573006765745F4D61785573657273007365745F4D61785573657273006D617855736572730077696E6E65724164647265737300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E74004869676865737453636F7265436F756E740073636F72657375626D6974636F756E74004173736572740047657455736572496E6465780053657455736572496E6465780075736572696E64657800417272617900456E737572654F776E65724F6E6C79006F705F457175616C6974790000001562006100740074006C0065003A007B0030007D00001975007300650072003A007B0030007D003A007B0031007D000015730063006F007200650072003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D00000B4F0077006E00650072000019500065006E00640069006E0067004F0077006E006500720000114D00610078005500730065007200730000194E0065007800740042006100740074006C00650049006400007143006C00610069006D004F0077006E0065007200730068006900700020006D007500730074002000620065002000630061006C006C0065006400200062007900200074006800650020006E00650077002800700065006E00640069006E006700290020006F0077006E00650072002E0000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001F460065006500200069007300200074006F006F0020006800690067006800002342006100740074006C00650020006E006F007400200066006F0075006E0064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E0000434D00610078002000750073006500720020007200650061006300680065006400200066006F00720020007400680069007300200062006100740074006C0065002E00003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00004541006C006C00200075007300650072007300200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00003354006800650020006D006500740068006F00640020006900730020006F0077006E006500720020006F006E006C0079002E00000013F332FF5FC4F742B898F665E5996BB50004200101080320000105200101111104200012290500020E0E1C07300102010E1E00040A01110C063001011E000E0600030E0E1C1C040A011110040A011114052002010E09042001090E05200111190E062002010E11190420010B0E052002010E0B05200101121D04200012390420001119040701111C06300101011E00040A01111C080703111911191118070002021119111905200201020E03061119040A0111180907040B110C110C1120040A011120090704110C11100911240320000B052002011C0A040A0111240B070509110C111011141128040A0111280307010B072002124111190B087CEC85D7BEA7798E02060B04061D1119020602020609062002010B110C052001110C0B082003010B1119111007200211100B1119062002010B111405200111140B052002010B09042001090B052001011119032000090420010109042001010B06200201121D090420010B0B0720030111190B0905200111190B07200201110C111905200101110C0428001119032800090328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F777301080100020000000000040100000000000000000000000000000000000010000000000000000000000000000000F837000000000000000000001238000000200000000000000000000000000000000000000000000004380000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000243800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ``` From 6463f9be7222b2dbc479c013f31a748e4b0b1d19 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Tue, 20 Jun 2023 08:56:26 +0530 Subject: [PATCH 6/7] Added feedback changes --- Mainnet/HashBattle/HashBattle/Arena.cs | 6 +++--- Mainnet/HashBattle/README.MD | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Mainnet/HashBattle/HashBattle/Arena.cs b/Mainnet/HashBattle/HashBattle/Arena.cs index a920a0a2..8b39512f 100644 --- a/Mainnet/HashBattle/HashBattle/Arena.cs +++ b/Mainnet/HashBattle/HashBattle/Arena.cs @@ -108,7 +108,7 @@ public void ClaimOwnership() Owner = newOwner; PendingOwner = Address.Zero; - Log(new OwnershipTransferedLog { PreviousOwner = oldOwner, NewOwner = newOwner }); + Log(new OwnershipTransferredLog { PreviousOwner = oldOwner, NewOwner = newOwner }); } /// /// Battle owner will start the battle @@ -119,7 +119,7 @@ public ulong StartBattle(ulong fee) Assert(fee < ulong.MaxValue / MaxUsers, "Fee is too high"); var battleId = NextBattleId; - NextBattleId += 1; + NextBattleId = battleId + 1; var battle = new BattleMain { @@ -271,7 +271,7 @@ public struct BattleHighestScorer public uint HighestScoreCount; public Address HighestScorer; } - public struct OwnershipTransferedLog + public struct OwnershipTransferredLog { [Index] public Address PreviousOwner; [Index] public Address NewOwner; diff --git a/Mainnet/HashBattle/README.MD b/Mainnet/HashBattle/README.MD index b978d9ba..ea8daf98 100644 --- a/Mainnet/HashBattle/README.MD +++ b/Mainnet/HashBattle/README.MD @@ -6,10 +6,10 @@ v2.0.0 ``` **Contract Hash** ``` -f020a1b71a62a18b53318e8c28266921403d27ac563dcf42e88e7788a0e93c0a +07e52e71a4ce2afa30d03280b15a205b53eb7131c5fae709031fdf570d4a80b2 ``` **Contract Byte Code** ``` -4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0102006CF437BE0000000000000000E00022200B013000001A0000000200000000000022380000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000D03700004F000000000000000000000000000000000000000000000000000000004000000C000000B43700001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E746578740000002818000000200000001A000000020000000000000000000000000000200000602E72656C6F6300000C0000000040000000020000001C00000000000000000000000000004000004200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000438000000000000480000000200050010270000A410000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007602280500000A7201000070038C0B000001280600000A046F0100002B2A7202280500000A7201000070038C0B000001280600000A6F0200002B2A8E02280500000A7217000070038C0B000001048C06000001280900000A056F0300002B2A8A02280500000A7217000070038C0B000001048C06000001280900000A6F0400002B2A7602280500000A7231000070038C0B000001280600000A046F0500002B2A7202280500000A7231000070038C0B000001280600000A6F0600002B2A7602280500000A7247000070038C0B000001280600000A046F0A00000A2A7202280500000A7247000070038C0B000001280600000A6F0B00000A2A7602280500000A7259000070038C0B000001280600000A046F0A00000A2A7202280500000A7259000070038C0B000001280600000A6F0B00000A2A4602280500000A72790000706F0C00000A2A4A02280500000A7279000070036F0D00000A2A4602280500000A72850000706F0C00000A2A4A02280500000A7285000070036F0D00000A2A4602280500000A729F0000706F0B00000A2A4A02280500000A729F000070036F0A00000A2A4602280500000A72B10000706F0E00000A2A4A02280500000A72B1000070036F0F00000A2AA20203281000000A0202281100000A6F1200000A280C0000060204281000000602176A28120000062A13300300320000000100001102281D0000060203280E000006021200FE1507000002120002280B0000067D0C0000041200037D0D00000406280700002B2A0000133003005C0000000200001102280D0000060A020602281100000A6F1200000A281400000A72CB000070281500000A02280B0000060B0206280C000006027E1600000A280E000006021202FE15060000021202077D0A0000041202067D0B00000408280800002B2A13300400AE000000030000110202281100000A6F1200000A02280B000006281400000A723D010070281500000A0203156A02280F0000066E5CFE057281010070281500000A0228110000060A02022811000006176AD728120000061202FE15030000021202067D010000041202037D04000004120202280F0000068D060000017D03000004080B0206072801000006021203FE15080000021203067D0E000004120302281100000A6F1200000A7D0F00000409280900002B062A000013300400F300000004000011020328020000060A02067B020000047E1600000A281400000A72A1010070281500000A02067B0400000402281100000A6F1700000AFE0172C5010070281500000A020302281100000A6F1200000A28040000060B02077B0600000416FE017225020070281500000A020302281100000A6F1200000A072803000006020328080000060C020802280F000006FE0116FE017269020070281500000A067B0300000402281100000A6F1200000A8C06000001086E6F1800000A02030817D728070000060203062801000006021203FE15090000021203037D10000004120302281100000A6F1200000A7D1100000409280A00002B2A001330040045010000050000110202281100000A6F1200000A02280B000006281400000A72AD020070281500000A0204280A0000060A020602280F000006FE0572ED020070281500000A020428020000060B02077B020000047E1600000A281400000A72A1010070281500000A02040328040000060C02087B0600000416FE017225020070281500000A1202177D060000040204030828030000060617D70A0204062809000006020428060000060D05097B0700000436221203057D070000041203037D090000041203177D0800000402040928050000062B1D05097B07000004331412037C08000004254B17D75402040928050000060602280F0000063327020428060000060D097B080000041736090207281C0000062B0D0207097B09000004281A000006021204FE150A0000021204047D12000004120402281100000A6F1200000A7D130000041104280B00002B2A36020328020000067B020000042A760F01047D0200000402037B010000040328010000060203281B0000062A000000133003003300000006000011037B0400000402280F00000617DB6ED90A02037B0200000406281900000A260202280B000006037B04000004281900000A262A00133003007A000000000000000F01177D0500000402037B0100000403280100000602037B0300000416A306000001037B04000004281900000A2602037B0300000417A306000001037B04000004281900000A2602037B0300000418A306000001037B04000004281900000A2602037B0300000419A306000001037B04000004281900000A262A8A0202281100000A6F1200000A02280B000006281400000A7233030070281500000A2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C000000EC050000237E0000580600001C05000023537472696E677300000000740B00006803000023555300DC0E0000100000002347554944000000EC0E0000B801000023426C6F6200000000000000020000015715A201090A000000FA01330016000001000000100000000A000000130000001D00000022000000190000000D000000060000000100000004000000080000000100000002000000080000000B00000000004802010000000000060068019C03060097019C030600540189030F00BC0300000A00440426040A00160426040A001C0126040600FC005A020A00880126040A0043012604060022005A020600DB015A02060052045A020A009D0026040600F9045A020A006D042604000000002900000000000100010001001000320000001500010001000A01100061020000210001001E000A01100063030000210006001E000A0110001F030000210007001E000A011000F101000021000A001E000A0110002A02000021000C001E000A0110001902000021000E001E000A01100008020000210010001E000A011000E2010000210012001E0006006800F2000600A5029B000600E803F50006009500F20006007A00FA0006008600FA0006000601FD000600AB04FD00060047039B000600F2029B0006000D039B00060000039B000600E5029B0006006800F200060016049B0006006800F200060016049B0006006800F200060016049B005020000000008100DF00000101006E20000000008600D500070103008B2000000000810076030D010400AF200000000086006E0316010700D22000000000810044031E010900F020000000008600330325010B000D21000000008100E2042B010C002B21000000008100D50431010E00482100000000810094042B010F0066210000000081007D04310111008321000000008608AC026E0012009521000000008108B60236011200A821000000008608C0026E001300BA21000000008108D10236011300CD21000000008608CB033C011400DF21000000008108D80340011400F2210000000086084F00BD0015000422000000008108600045011500172200000000861883034A0116004022000000008600E202360118008022000000008600710206001900E822000000008600E90051011900A423000000008600C90045011A00A424000000008600B20056011B00F525000000008600A2025E011E000326000000008100940264011F002426000000008100CE016C0121006426000000008100BC006C012200EA26000000008100FF040600230000000100710000000200F500000001007100000001007100000002001E04000003007E03000001007100000002001E0400000100710000000200550300000100710000000100710000000200EF0400000100710000000100710000000200BD0400000100710000000100C80100000100C80100000100C80100000100C80100000100300100000200E50300000100160300000100990000000100710000000100FC03000002007100000003000C0100000100710000000100F50000000200EE0300000100F50000000100F500090083030100110083030600190083030A0049008303060029001201100061003D041500510063041B0051005904280061003D042F0051000B004000510001004600510008044B0051001304510051001500580051001F005D002900830363002900A6006900710080026E0029004402780031000F058D002900CE04950031006C029B007100B501BD007900BF01C10029008B02E1002E000B007F012E00130088012E001B00A70141012300B00161012300B00181012300B001A1012300B001C1012300B001E1012300B00101022300B00121022300B00141022300B00161022300B00173008400A400B300CC00DD00020001000000190372010000E50272010000DC037701000064007B0102000B00030001000C00030002000D00050001000E00050002000F00070001001000070002001100090001001200090004800000000000000000000000000000000044040000040000000000000000000000E9003800000000000200000000000000000000000000260400000000030002000400020005000200060002000700020008000200090002000A0002000F002300110023000F003600110036000F003B0011003B0027007F0027009F002700AE002700C7002700D800000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C65496400497343616E63656C6C65640053636F72655375626D6974746564004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C650043616E63656C426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F7265006765745F53746174650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E6700426174746C65456E6465644C6F67004F776E6572736869705472616E7366657265644C6F6700426174746C65456E74657265644C6F6700426174746C65537461727465644C6F67004F776E6572736869705472616E736665725265717565737465644C6F6700536D617274436F6E74726163742E646C6C0053797374656D00426174746C654D61696E005A65726F00436C61696D4F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F4F776E6572007365745F4F776E6572006765745F50656E64696E674F776E6572007365745F50656E64696E674F776E65720053657450656E64696E674F776E65720050726576696F75734F776E65720043757272656E744F776E6572004E65774F776E6572006E65774F776E657200426174746C654869676865737453636F726572004765744869676865737453636F726572005365744869676865737453636F726572006869676865737453636F72657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573006765745F4D61785573657273007365745F4D61785573657273006D617855736572730077696E6E65724164647265737300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E74004869676865737453636F7265436F756E740073636F72657375626D6974636F756E74004173736572740047657455736572496E6465780053657455736572496E6465780075736572696E64657800417272617900456E737572654F776E65724F6E6C79006F705F457175616C6974790000001562006100740074006C0065003A007B0030007D00001975007300650072003A007B0030007D003A007B0031007D000015730063006F007200650072003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D00000B4F0077006E00650072000019500065006E00640069006E0067004F0077006E006500720000114D00610078005500730065007200730000194E0065007800740042006100740074006C00650049006400007143006C00610069006D004F0077006E0065007200730068006900700020006D007500730074002000620065002000630061006C006C0065006400200062007900200074006800650020006E00650077002800700065006E00640069006E006700290020006F0077006E00650072002E0000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001F460065006500200069007300200074006F006F0020006800690067006800002342006100740074006C00650020006E006F007400200066006F0075006E0064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E0000434D00610078002000750073006500720020007200650061006300680065006400200066006F00720020007400680069007300200062006100740074006C0065002E00003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00004541006C006C00200075007300650072007300200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00003354006800650020006D006500740068006F00640020006900730020006F0077006E006500720020006F006E006C0079002E00000013F332FF5FC4F742B898F665E5996BB50004200101080320000105200101111104200012290500020E0E1C07300102010E1E00040A01110C063001011E000E0600030E0E1C1C040A011110040A011114052002010E09042001090E05200111190E062002010E11190420010B0E052002010E0B05200101121D04200012390420001119040701111C06300101011E00040A01111C080703111911191118070002021119111905200201020E03061119040A0111180907040B110C110C1120040A011120090704110C11100911240320000B052002011C0A040A0111240B070509110C111011141128040A0111280307010B072002124111190B087CEC85D7BEA7798E02060B04061D1119020602020609062002010B110C052001110C0B082003010B1119111007200211100B1119062002010B111405200111140B052002010B09042001090B052001011119032000090420010109042001010B06200201121D090420010B0B0720030111190B0905200111190B07200201110C111905200101110C0428001119032800090328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F777301080100020000000000040100000000000000000000000000000000000010000000000000000000000000000000F837000000000000000000001238000000200000000000000000000000000000000000000000000004380000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000243800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010200E6EB4ACA0000000000000000E00022200B013000001A000000020000000000001E380000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000CC3700004F000000000000000000000000000000000000000000000000000000004000000C000000B03700001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E746578740000002418000000200000001A000000020000000000000000000000000000200000602E72656C6F6300000C0000000040000000020000001C0000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003800000000000048000000020005000C270000A410000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007602280500000A7201000070038C0B000001280600000A046F0100002B2A7202280500000A7201000070038C0B000001280600000A6F0200002B2A8E02280500000A7217000070038C0B000001048C06000001280900000A056F0300002B2A8A02280500000A7217000070038C0B000001048C06000001280900000A6F0400002B2A7602280500000A7231000070038C0B000001280600000A046F0500002B2A7202280500000A7231000070038C0B000001280600000A6F0600002B2A7602280500000A7247000070038C0B000001280600000A046F0A00000A2A7202280500000A7247000070038C0B000001280600000A6F0B00000A2A7602280500000A7259000070038C0B000001280600000A046F0A00000A2A7202280500000A7259000070038C0B000001280600000A6F0B00000A2A4602280500000A72790000706F0C00000A2A4A02280500000A7279000070036F0D00000A2A4602280500000A72850000706F0C00000A2A4A02280500000A7285000070036F0D00000A2A4602280500000A729F0000706F0B00000A2A4A02280500000A729F000070036F0A00000A2A4602280500000A72B10000706F0E00000A2A4A02280500000A72B1000070036F0F00000A2AA20203281000000A0202281100000A6F1200000A280C0000060204281000000602176A28120000062A13300300320000000100001102281D0000060203280E000006021200FE1507000002120002280B0000067D0C0000041200037D0D00000406280700002B2A0000133003005C0000000200001102280D0000060A020602281100000A6F1200000A281400000A72CB000070281500000A02280B0000060B0206280C000006027E1600000A280E000006021202FE15060000021202077D0A0000041202067D0B00000408280800002B2A13300400A9000000030000110202281100000A6F1200000A02280B000006281400000A723D010070281500000A0203156A02280F0000066E5CFE057281010070281500000A0228110000060A0206176AD728120000061202FE15030000021202067D010000041202037D04000004120202280F0000068D060000017D03000004080B0206072801000006021203FE15080000021203067D0E000004120302281100000A6F1200000A7D0F00000409280900002B062A00000013300400F300000004000011020328020000060A02067B020000047E1600000A281400000A72A1010070281500000A02067B0400000402281100000A6F1700000AFE0172C5010070281500000A020302281100000A6F1200000A28040000060B02077B0600000416FE017225020070281500000A020302281100000A6F1200000A072803000006020328080000060C020802280F000006FE0116FE017269020070281500000A067B0300000402281100000A6F1200000A8C06000001086E6F1800000A02030817D728070000060203062801000006021203FE15090000021203037D10000004120302281100000A6F1200000A7D1100000409280A00002B2A001330040045010000050000110202281100000A6F1200000A02280B000006281400000A72AD020070281500000A0204280A0000060A020602280F000006FE0572ED020070281500000A020428020000060B02077B020000047E1600000A281400000A72A1010070281500000A02040328040000060C02087B0600000416FE017225020070281500000A1202177D060000040204030828030000060617D70A0204062809000006020428060000060D05097B0700000436221203057D070000041203037D090000041203177D0800000402040928050000062B1D05097B07000004331412037C08000004254B17D75402040928050000060602280F0000063327020428060000060D097B080000041736090207281C0000062B0D0207097B09000004281A000006021204FE150A0000021204047D12000004120402281100000A6F1200000A7D130000041104280B00002B2A36020328020000067B020000042A760F01047D0200000402037B010000040328010000060203281B0000062A000000133003003300000006000011037B0400000402280F00000617DB6ED90A02037B0200000406281900000A260202280B000006037B04000004281900000A262A00133003007A000000000000000F01177D0500000402037B0100000403280100000602037B0300000416A306000001037B04000004281900000A2602037B0300000417A306000001037B04000004281900000A2602037B0300000418A306000001037B04000004281900000A2602037B0300000419A306000001037B04000004281900000A262A8A0202281100000A6F1200000A02280B000006281400000A7233030070281500000A2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C000000EC050000237E0000580600001C05000023537472696E677300000000740B00006803000023555300DC0E0000100000002347554944000000EC0E0000B801000023426C6F6200000000000000020000015715A201090A000000FA01330016000001000000100000000A000000130000001D00000022000000190000000D000000060000000100000004000000080000000100000002000000080000000B00000000004902010000000000060068019D03060097019D03060054018A030F00BD0300000A00450427040A00170427040A001C0127040600FC005B020A00880127040A0043012704060022005B020600DB015B02060053045B020A009D0027040600FA045B020A006E042704000000002900000000000100010001001000320000001500010001000A01100062020000210001001E000A01100064030000210006001E000A01100020030000210007001E000A0110000202000021000A001E000A0110002B02000021000C001E000A0110001A02000021000E001E000A011000F1010000210010001E000A011000E2010000210012001E0006006800F2000600A6029B000600E903F50006009500F20006007A00FA0006008600FA0006000601FD000600AC04FD00060048039B000600F3029B0006000E039B00060001039B000600E6029B0006006800F200060017049B0006006800F200060017049B0006006800F200060017049B005020000000008100DF00000101006E20000000008600D500070103008B2000000000810077030D010400AF200000000086006F0316010700D22000000000810045031E010900F020000000008600340325010B000D21000000008100E3042B010C002B21000000008100D60431010E00482100000000810095042B010F0066210000000081007E04310111008321000000008608AD026E0012009521000000008108B70236011200A821000000008608C1026E001300BA21000000008108D20236011300CD21000000008608CC033C011400DF21000000008108D90340011400F2210000000086084F00BD0015000422000000008108600045011500172200000000861884034A0116004022000000008600E302360118008022000000008600720206001900E822000000008600E90051011900A023000000008600C90045011A00A024000000008600B20056011B00F125000000008600A3025E011E00FF25000000008100950264011F002026000000008100CE016C0121006026000000008100BC006C012200E62600000000810000050600230000000100710000000200F500000001007100000001007100000002001F04000003007F03000001007100000002001F0400000100710000000200560300000100710000000100710000000200F00400000100710000000100710000000200BE0400000100710000000100C80100000100C80100000100C80100000100C80100000100300100000200E60300000100170300000100990000000100710000000100FD03000002007100000003000C0100000100710000000100F50000000200EF0300000100F50000000100F500090084030100110084030600190084030A0049008403060029001201100061003E041500510064041B0051005A04280061003E042F0051000B004000510001004600510009044B0051001404510051001500580051001F005D002900840363002900A6006900710081026E00290045027800310010058D002900CF04950031006D029B007100B501BD007900BF01C10029008C02E1002E000B007F012E00130088012E001B00A70141012300B00161012300B00181012300B001A1012300B001C1012300B001E1012300B00101022300B00121022300B00141022300B00161022300B00173008400A400B300CC00DD000200010000001A0372010000E60272010000DD037701000064007B0102000B00030001000C00030002000D00050001000E00050002000F00070001001000070002001100090001001200090004800000000000000000000000000000000045040000040000000000000000000000E9003800000000000200000000000000000000000000270400000000030002000400020005000200060002000700020008000200090002000A0002000F002300110023000F003600110036000F003B0011003B0027007F0027009F002700AE002700C7002700D800000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C65496400497343616E63656C6C65640053636F72655375626D6974746564004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C650043616E63656C426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F7265006765745F53746174650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E6700426174746C65456E6465644C6F6700426174746C65456E74657265644C6F67004F776E6572736869705472616E736665727265644C6F6700426174746C65537461727465644C6F67004F776E6572736869705472616E736665725265717565737465644C6F6700536D617274436F6E74726163742E646C6C0053797374656D00426174746C654D61696E005A65726F00436C61696D4F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F4F776E6572007365745F4F776E6572006765745F50656E64696E674F776E6572007365745F50656E64696E674F776E65720053657450656E64696E674F776E65720050726576696F75734F776E65720043757272656E744F776E6572004E65774F776E6572006E65774F776E657200426174746C654869676865737453636F726572004765744869676865737453636F726572005365744869676865737453636F726572006869676865737453636F72657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573006765745F4D61785573657273007365745F4D61785573657273006D617855736572730077696E6E65724164647265737300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E74004869676865737453636F7265436F756E740073636F72657375626D6974636F756E74004173736572740047657455736572496E6465780053657455736572496E6465780075736572696E64657800417272617900456E737572654F776E65724F6E6C79006F705F457175616C69747900001562006100740074006C0065003A007B0030007D00001975007300650072003A007B0030007D003A007B0031007D000015730063006F007200650072003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D00000B4F0077006E00650072000019500065006E00640069006E0067004F0077006E006500720000114D00610078005500730065007200730000194E0065007800740042006100740074006C00650049006400007143006C00610069006D004F0077006E0065007200730068006900700020006D007500730074002000620065002000630061006C006C0065006400200062007900200074006800650020006E00650077002800700065006E00640069006E006700290020006F0077006E00650072002E0000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001F460065006500200069007300200074006F006F0020006800690067006800002342006100740074006C00650020006E006F007400200066006F0075006E0064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E0000434D00610078002000750073006500720020007200650061006300680065006400200066006F00720020007400680069007300200062006100740074006C0065002E00003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00004541006C006C00200075007300650072007300200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00003354006800650020006D006500740068006F00640020006900730020006F0077006E006500720020006F006E006C0079002E000000F641A50CB4EA5F4D9C24BB4EACC176CA0004200101080320000105200101111104200012290500020E0E1C07300102010E1E00040A01110C063001011E000E0600030E0E1C1C040A011110040A011114052002010E09042001090E05200111190E062002010E11190420010B0E052002010E0B05200101121D04200012390420001119040701111C06300101011E00040A01111C080703111911191118070002021119111905200201020E03061119040A0111180907040B110C110C1120040A011120090704110C11100911240320000B052002011C0A040A0111240B070509110C111011141128040A0111280307010B072002124111190B087CEC85D7BEA7798E02060B04061D1119020602020609062002010B110C052001110C0B082003010B1119111007200211100B1119062002010B111405200111140B052002010B09042001090B052001011119032000090420010109042001010B06200201121D090420010B0B0720030111190B0905200111190B07200201110C111905200101110C0428001119032800090328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F777301080100020000000000040100000000000000000000000000000000000010000000000000000000000000000000F437000000000000000000000E38000000200000000000000000000000000000000000000000000000380000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF25002000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000203800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ``` From b3661504555956bbcb9a70fc37666d7e0bdd7203 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Tue, 20 Jun 2023 09:05:49 +0530 Subject: [PATCH 7/7] Added feedback changes --- Testnet/HashBattle/HashBattle/Arena.cs | 303 ++++++++++++------ .../HashBattle/HashBattle/HashBattle.csproj | 6 +- .../HashBattle/HashBattleTest/ArenaTest.cs | 43 ++- .../HashBattleTest/InMemoryState.cs | 67 ++-- Testnet/HashBattle/README.MD | 4 +- 5 files changed, 264 insertions(+), 159 deletions(-) diff --git a/Testnet/HashBattle/HashBattle/Arena.cs b/Testnet/HashBattle/HashBattle/Arena.cs index 8fd58dc8..8b39512f 100644 --- a/Testnet/HashBattle/HashBattle/Arena.cs +++ b/Testnet/HashBattle/HashBattle/Arena.cs @@ -7,188 +7,293 @@ /// public class Arena : SmartContract { - public Arena(ISmartContractState smartContractState) - : base(smartContractState) + private void SetBattle(ulong battleId, BattleMain battle) { - BattleOwner = Message.Sender; + State.SetStruct($"battle:{battleId}", battle); + } + public BattleMain GetBattle(ulong battleId) + { + return State.GetStruct($"battle:{battleId}"); + } + private void SetUser(ulong battleId, Address address, BattleUser user) + { + State.SetStruct($"user:{battleId}:{address}", user); + } + public BattleUser GetUser(ulong battleId, Address address) + { + return State.GetStruct($"user:{battleId}:{address}"); + } + private void SetHighestScorer(ulong battleId, BattleHighestScorer highestScorer) + { + State.SetStruct($"scorer:{battleId}", highestScorer); + } + public BattleHighestScorer GetHighestScorer(ulong battleId) + { + return State.GetStruct($"scorer:{battleId}"); + } + private void SetUserIndex(ulong battleId, uint userindex) + { + State.SetUInt32($"user:{battleId}", userindex); + } + private uint GetUserIndex(ulong battleId) + { + return State.GetUInt32($"user:{battleId}"); + } + private void SetScoreSubmittedCount(ulong battleId, uint scoresubmitcount) + { + State.SetUInt32($"scoresubmit:{battleId}", scoresubmitcount); + } + private uint GetScoreSubmittedCount(ulong battleId) + { + return State.GetUInt32($"scoresubmit:{battleId}"); } - /// /// Set the address deploying the contract as battle owner /// - private Address BattleOwner + public Address Owner + { + get => State.GetAddress(nameof(Owner)); + private set => State.SetAddress(nameof(Owner), value); + } + public Address PendingOwner + { + get => State.GetAddress(nameof(PendingOwner)); + private set => State.SetAddress(nameof(PendingOwner), value); + } + public uint MaxUsers + { + get => State.GetUInt32(nameof(MaxUsers)); + private set => State.SetUInt32(nameof(MaxUsers), value); + } + /// + /// Set the unique battleId of each battle + /// + public ulong NextBattleId { - get => PersistentState.GetAddress(nameof(BattleOwner)); - set => PersistentState.SetAddress(nameof(BattleOwner), value); + get => State.GetUInt64(nameof(NextBattleId)); + private set => State.SetUInt64(nameof(NextBattleId), value); + } + + public Arena(ISmartContractState smartContractState, uint maxUsers) : base(smartContractState) + { + Owner = Message.Sender; + MaxUsers = maxUsers; + NextBattleId = 1; } + /// + /// Only owner can set new owner and new owner will be in pending state + /// till new owner will call method. + /// + /// The new owner which is going to be in pending state + public void SetPendingOwner(Address newOwner) + { + EnsureOwnerOnly(); + PendingOwner = newOwner; + + Log(new OwnershipTransferRequestedLog { CurrentOwner = Owner, PendingOwner = newOwner }); + } + + /// + /// Waiting be called after new owner is requested by call. + /// Pending owner will be new owner after successfull call. + /// + public void ClaimOwnership() + { + var newOwner = PendingOwner; + + Assert(newOwner == Message.Sender, "ClaimOwnership must be called by the new(pending) owner."); + + var oldOwner = Owner; + Owner = newOwner; + PendingOwner = Address.Zero; + + Log(new OwnershipTransferredLog { PreviousOwner = oldOwner, NewOwner = newOwner }); + } /// /// Battle owner will start the battle /// - public bool StartBattle(ulong battleId, ulong fee) + public ulong StartBattle(ulong fee) { - Assert(Message.Sender == BattleOwner, "Only battle owner can start game."); + Assert(Message.Sender == Owner, "Only battle owner can start game."); + Assert(fee < ulong.MaxValue / MaxUsers, "Fee is too high"); + + var battleId = NextBattleId; + NextBattleId = battleId + 1; - var battle = new BattleMain(); - battle.BattleId = battleId; - battle.MaxUsers = 4; - battle.Fee = fee; - battle.Users = new Address[battle.MaxUsers]; + var battle = new BattleMain + { + BattleId = battleId, + Fee = fee, + Users = new Address[MaxUsers] + }; SetBattle(battleId, battle); - Log(battle); - return true; + Log(new BattleStartedLog { BattleId = battleId, Address = Message.Sender }); + return battleId; } - /// /// 4 different user will enter the battle /// - public bool EnterBattle(ulong battleId, uint userindex) + public void EnterBattle(ulong battleId) { var battle = GetBattle(battleId); - Assert(battle.Winner == Address.Zero, "Battle ended."); + Assert(battle.Winner == Address.Zero, "Battle not found."); - Assert(battle.Fee == Message.Value, "Battle amount is not matching."); + Assert(battle.Fee == Message.Value, "Battle fee is not matching with entry fee paid."); var user = GetUser(battleId, Message.Sender); Assert(!user.ScoreSubmitted, "The user already submitted score."); - user.Address = Message.Sender; - SetUser(battleId, Message.Sender, user); - battle.Users.SetValue(user.Address, userindex); + var userindex = GetUserIndex(battleId); + Assert(userindex != MaxUsers, "Max user reached for this battle."); + battle.Users.SetValue(Message.Sender, userindex); + SetUserIndex(battleId, userindex + 1); + SetBattle(battleId, battle); - Log(battle); - return true; + Log(new BattleEnteredLog { BattleId = battleId, Address = Message.Sender }); } - /// /// 4 different user will end the battle and submit the score /// - public bool EndBattle(Address userAddress, ulong battleId, uint score, bool IsBattleOver) + public void EndBattle(Address userAddress, ulong battleId, uint score) { - Assert(Message.Sender == BattleOwner, "Only battle owner can end game."); + Assert(Message.Sender == Owner, "Only battle owner can end game."); + + var ScoreSubmittedCount = GetScoreSubmittedCount(battleId); + Assert(ScoreSubmittedCount < MaxUsers, "All users already submitted score."); var battle = GetBattle(battleId); - Assert(battle.Winner == Address.Zero, "Battle ended."); + Assert(battle.Winner == Address.Zero, "Battle not found."); var user = GetUser(battleId, userAddress); Assert(!user.ScoreSubmitted, "The user already submitted score."); - user.Score = score; user.ScoreSubmitted = true; SetUser(battleId, userAddress, user); - if (IsBattleOver) - ProcessWinner(battle); + ScoreSubmittedCount += 1; + SetScoreSubmittedCount(battleId, ScoreSubmittedCount); - Log(user); - return true; - } + var highestScorer = GetHighestScorer(battleId); + + if (score > highestScorer.Score) + { + highestScorer.Score = score; + highestScorer.HighestScorer = userAddress; + highestScorer.HighestScoreCount = 1; + + SetHighestScorer(battleId, highestScorer); + } + else if (score == highestScorer.Score) + { + highestScorer.HighestScoreCount++; + SetHighestScorer(battleId, highestScorer); + } + if (ScoreSubmittedCount == MaxUsers) + { + highestScorer = GetHighestScorer(battleId); + if (highestScorer.HighestScoreCount > 1) + CancelBattle(battle); + else + ProcessWinner(battle, highestScorer.HighestScorer); + } + + Log(new BattleEndedLog { BattleId = battleId, Address = Message.Sender }); + } /// /// Get winner address /// public Address GetWinner(ulong battleId) { var battle = GetBattle(battleId); - Log(battle); return battle.Winner; } - /// /// Process winner when all user scores are submitted /// - private void ProcessWinner(BattleMain battle) + private void ProcessWinner(BattleMain battle, Address winnerAddress) { - if (battle.Users.Length <= 4) - { - foreach (Address userAddress in battle.Users) - { - var user = GetUser(battle.BattleId, userAddress); - if (!user.ScoreSubmitted) - return; - } - } - uint winnerIndex = GetWinnerIndex(battle.BattleId, battle.Users); - if (battle.Winner == Address.Zero) - { - battle.Winner = battle.Users[winnerIndex]; - SetBattle(battle.BattleId, battle); - ProcessPrize(battle.BattleId); - } - } - - /// - /// Get winner user index from battle users - /// - private uint GetWinnerIndex(ulong battleid, Address[] users) - { - uint winningScore = 0; - uint winningScoreIndex = 0; - for (uint i = 0; i < users.Length; i++) - { - var user = GetUser(battleid, users[i]); - if (user.Score > winningScore) - { - winningScore = user.Score; - winningScoreIndex = i; - } - } - return winningScoreIndex; + battle.Winner = winnerAddress; + SetBattle(battle.BattleId, battle); + ProcessPrize(battle); } - /// /// Send 3/4 amount to winner and 1/4 amount to battle owner /// - private void ProcessPrize(ulong battleid) + private void ProcessPrize(BattleMain battle) { - var battle = GetBattle(battleid); - ulong prize = battle.Fee * (battle.MaxUsers - 1); + var prize = battle.Fee * (MaxUsers - 1); Transfer(battle.Winner, prize); - Transfer(BattleOwner, battle.Fee); + Transfer(Owner, battle.Fee); } - - private void SetUser(ulong battleid, Address address, BattleUser user) - { - PersistentState.SetStruct($"user:{battleid}:{address}", user); - } - - private BattleUser GetUser(ulong battleid, Address address) + /// + /// Cancel battle and refund the fee amount + /// + private void CancelBattle(BattleMain battle) { - return PersistentState.GetStruct($"user:{battleid}:{address}"); - } + battle.IsCancelled = true; + SetBattle(battle.BattleId, battle); - private void SetBattle(ulong battleid, BattleMain battle) - { - PersistentState.SetStruct($"battle:{battleid}", battle); + Transfer(battle.Users[0], battle.Fee); + Transfer(battle.Users[1], battle.Fee); + Transfer(battle.Users[2], battle.Fee); + Transfer(battle.Users[3], battle.Fee); } - - private BattleMain GetBattle(ulong battleid) + private void EnsureOwnerOnly() { - return PersistentState.GetStruct($"battle:{battleid}"); + Assert(Message.Sender == Owner, "The method is owner only."); } - public struct BattleMain { public ulong BattleId; public Address Winner; public Address[] Users; - public uint MaxUsers; public ulong Fee; + public bool IsCancelled; } - public struct BattleUser { - public Address Address; - public uint Score; public bool ScoreSubmitted; } -} + public struct BattleHighestScorer + { + public uint Score; + public uint HighestScoreCount; + public Address HighestScorer; + } + public struct OwnershipTransferredLog + { + [Index] public Address PreviousOwner; + [Index] public Address NewOwner; + } + public struct OwnershipTransferRequestedLog + { + [Index] public Address CurrentOwner; + [Index] public Address PendingOwner; + } + public struct BattleStartedLog + { + [Index] public ulong BattleId; + [Index] public Address Address; + } + public struct BattleEnteredLog + { + [Index] public ulong BattleId; + [Index] public Address Address; + } + public struct BattleEndedLog + { + [Index] public ulong BattleId; + [Index] public Address Address; + } +} \ No newline at end of file diff --git a/Testnet/HashBattle/HashBattle/HashBattle.csproj b/Testnet/HashBattle/HashBattle/HashBattle.csproj index 780e51c7..2568c851 100644 --- a/Testnet/HashBattle/HashBattle/HashBattle.csproj +++ b/Testnet/HashBattle/HashBattle/HashBattle.csproj @@ -2,10 +2,10 @@ netcoreapp2.1 - - 8.0 + + 8.0 - + diff --git a/Testnet/HashBattle/HashBattleTest/ArenaTest.cs b/Testnet/HashBattle/HashBattleTest/ArenaTest.cs index 29391d2d..b2227cf1 100644 --- a/Testnet/HashBattle/HashBattleTest/ArenaTest.cs +++ b/Testnet/HashBattle/HashBattleTest/ArenaTest.cs @@ -58,79 +58,75 @@ public void TestBattle() private Arena StartBattleTest() { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - Arena arena = new Arena(this.mockContractState.Object); - arena.StartBattle(1, 1); + Arena arena = new Arena(this.mockContractState.Object, 4); + ulong battleId = arena.StartBattle(1); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleStartedLog { BattleId = battleId, Address = this.ownerAddress })); return arena; } private void Player1EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress1, 1)); - arena.EnterBattle(1, 0); + arena.EnterBattle(1); - Assert.Equal(this.playerAddress1, state.GetStruct($"user:{1}:{this.playerAddress1}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress1 })); } private void Player2EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress2, 1)); - arena.EnterBattle(1, 1); + arena.EnterBattle(1); - Assert.Equal(this.playerAddress2, state.GetStruct($"user:{1}:{this.playerAddress2}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress2 })); } private void Player3EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress3, 1)); - arena.EnterBattle(1, 2); + arena.EnterBattle(1); - Assert.Equal(this.playerAddress3, state.GetStruct($"user:{1}:{this.playerAddress3}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress3 })); } private void Player4EnterGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.playerAddress4, 1)); - arena.EnterBattle(1, 3); + arena.EnterBattle(1); - Assert.Equal(this.playerAddress4, state.GetStruct($"user:{1}:{this.playerAddress4}").Address); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEnteredLog { BattleId = 1, Address = this.playerAddress4 })); } private void Player1EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress1, 1, 10, false); + arena.EndBattle(this.playerAddress1, 1, 10); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress1}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void Player2EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress2, 1, 20, false); + arena.EndBattle(this.playerAddress2, 1, 20); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress2}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void Player3EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress3, 1, 30, false); + arena.EndBattle(this.playerAddress3, 1, 30); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress3}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void Player4EndGameTest(Arena arena) { this.mockContractState.Setup(m => m.Message).Returns(new Message(this.contract, this.ownerAddress, 0)); - arena.EndBattle(this.playerAddress4, 1, 40, true); + arena.EndBattle(this.playerAddress4, 1, 40); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"user:{1}:{this.playerAddress4}"))); + this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, new BattleEndedLog { BattleId = 1, Address = this.ownerAddress })); } private void GetGameWinnerTest(Arena arena) @@ -139,7 +135,6 @@ private void GetGameWinnerTest(Arena arena) Address winner = arena.GetWinner(1); Assert.Equal(this.playerAddress4, winner); - this.mockContractLogger.Verify(m => m.Log(this.mockContractState.Object, state.GetStruct($"battle:{1}"))); } } } diff --git a/Testnet/HashBattle/HashBattleTest/InMemoryState.cs b/Testnet/HashBattle/HashBattleTest/InMemoryState.cs index 8f20e1db..c561a923 100644 --- a/Testnet/HashBattle/HashBattleTest/InMemoryState.cs +++ b/Testnet/HashBattle/HashBattleTest/InMemoryState.cs @@ -7,77 +7,82 @@ namespace HashBattleTest public class InMemoryState : IPersistentState { private readonly Dictionary storage = new Dictionary(); + public bool IsContractResult { get; set; } - public void Clear(string key) => storage.Remove(key); - public T GetValue(string key) => (T)storage.GetValueOrDefault(key, default(T)); + public void Clear(string key) => this.storage.Remove(key); + + public T GetValue(string key) => (T)this.storage.GetValueOrDefault(key, default(T)); public void AddOrReplace(string key, object value) { - if (!storage.TryAdd(key, value)) - storage[key] = value; + if (!this.storage.TryAdd(key, value)) + { + this.storage[key] = value; + } } - public Address GetAddress(string key) => GetValue
(key); - public T[] GetArray(string key) => GetValue(key); + public Address GetAddress(string key) => this.GetValue
(key); + + public T[] GetArray(string key) => this.GetValue(key); - public bool GetBool(string key) => GetValue(key); + public bool GetBool(string key) => this.GetValue(key); public byte[] GetBytes(byte[] key) => throw new NotImplementedException(); - public byte[] GetBytes(string key) => GetValue(key); + public byte[] GetBytes(string key) => this.GetValue(key); - public char GetChar(string key) => GetValue(key); + public char GetChar(string key) => this.GetValue(key); - public int GetInt32(string key) => GetValue(key); + public int GetInt32(string key) => this.GetValue(key); - public long GetInt64(string key) => GetValue(key); + public long GetInt64(string key) => this.GetValue(key); - public string GetString(string key) => GetValue(key); + public string GetString(string key) => this.GetValue(key); public T GetStruct(string key) - where T : struct => GetValue(key); + where T : struct => this.GetValue(key); - public uint GetUInt32(string key) => GetValue(key); + public uint GetUInt32(string key) => this.GetValue(key); - public ulong GetUInt64(string key) => GetValue(key); + public ulong GetUInt64(string key) => this.GetValue(key); - public UInt128 GetUInt128(string key) => GetValue(key); + public UInt128 GetUInt128(string key) => this.GetValue(key); - public UInt256 GetUInt256(string key) => GetValue(key); + public UInt256 GetUInt256(string key) => this.GetValue(key); - public bool IsContract(Address address) => IsContractResult; + public bool IsContract(Address address) => this.IsContractResult; - public void SetAddress(string key, Address value) => AddOrReplace(key, value); + public void SetAddress(string key, Address value) => this.AddOrReplace(key, value); - public void SetArray(string key, Array a) => AddOrReplace(key, a); + public void SetArray(string key, Array a) => this.AddOrReplace(key, a); - public void SetBool(string key, bool value) => AddOrReplace(key, value); + public void SetBool(string key, bool value) => this.AddOrReplace(key, value); public void SetBytes(byte[] key, byte[] value) { throw new NotImplementedException(); } - public void SetBytes(string key, byte[] value) => AddOrReplace(key, value); + public void SetBytes(string key, byte[] value) => this.AddOrReplace(key, value); - public void SetChar(string key, char value) => AddOrReplace(key, value); + public void SetChar(string key, char value) => this.AddOrReplace(key, value); - public void SetInt32(string key, int value) => AddOrReplace(key, value); + public void SetInt32(string key, int value) => this.AddOrReplace(key, value); - public void SetInt64(string key, long value) => AddOrReplace(key, value); + public void SetInt64(string key, long value) => this.AddOrReplace(key, value); - public void SetString(string key, string value) => AddOrReplace(key, value); + public void SetString(string key, string value) => this.AddOrReplace(key, value); public void SetStruct(string key, T value) - where T : struct => AddOrReplace(key, value); + where T : struct => this.AddOrReplace(key, value); - public void SetUInt32(string key, uint value) => AddOrReplace(key, value); + public void SetUInt32(string key, uint value) => this.AddOrReplace(key, value); - public void SetUInt64(string key, ulong value) => AddOrReplace(key, value); + public void SetUInt64(string key, ulong value) => this.AddOrReplace(key, value); - public void SetUInt128(string key, UInt128 value) => AddOrReplace(key, value); + public void SetUInt128(string key, UInt128 value) => this.AddOrReplace(key, value); - public void SetUInt256(string key, UInt256 value) => AddOrReplace(key, value); + public void SetUInt256(string key, UInt256 value) => this.AddOrReplace(key, value); } } diff --git a/Testnet/HashBattle/README.MD b/Testnet/HashBattle/README.MD index d6fdfb83..ea8daf98 100644 --- a/Testnet/HashBattle/README.MD +++ b/Testnet/HashBattle/README.MD @@ -6,10 +6,10 @@ v2.0.0 ``` **Contract Hash** ``` -5fce69c0bdd6e6cf7d1a3ef04c463c6bfb4066bb043dac29d90e2c0806e47c98 +07e52e71a4ce2afa30d03280b15a205b53eb7131c5fae709031fdf570d4a80b2 ``` **Contract Byte Code** ``` -4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0102009C4DC5BE0000000000000000E00022200B013000001000000002000000000000B22E0000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000602E00004F000000000000000000000000000000000000000000000000000000004000000C000000442E00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000B80E0000002000000010000000020000000000000000000000000000200000602E72656C6F6300000C000000004000000002000000120000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000942E000000000000480000000200050030240000140A00000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000660203280400000A0202280500000A6F0600000A28030000062A4602280700000A72010000706F0800000A2A4A02280700000A7201000070036F0900000A2A001330030064000000010000110202280500000A6F0600000A022802000006280A00000A7219000070280B00000A1200FE15030000021200037D0100000412001A7D040000041200047D050000041200067B040000048D070000017D03000004020306280D0000060206280100002B172A13300400B6000000020000110203280E0000060A02067B020000047E0D00000A280A00000A725D000070280B00000A02067B0500000402280500000A6F0E00000AFE017279000070280B00000A020302280500000A6F0600000A280C0000060B02077B0800000416FE0172D9000070280B00000A120102280500000A6F0600000A7D06000004020302280500000A6F0600000A07280B000006067B03000004077B060000048C07000001046E6F0F00000A020306280D0000060206280100002B172A0000133004008E000000020000110202280500000A6F0600000A022802000006280A00000A721D010070280B00000A0204280E0000060A02067B020000047E0D00000A280A00000A725D000070280B00000A020403280C0000060B02077B0800000416FE0172D9000070280B00000A1201057D070000041201177D0800000402040307280B0000060E042C07020628080000060207280200002B172A00001330020016000000010000110203280E0000060A0206280100002B067B020000042A0000133003008F00000003000011037B030000048E691A3032037B030000040B160C2B210708A3070000010D02037B0100000409280C0000067B080000042D012A0817580C08078E6932D902037B01000004037B0300000428090000060A037B020000047E0D00000A280A00000A2C2C0F01037B0300000406A3070000017D0200000402037B0100000403280D00000602037B01000004280A0000062A00133004003700000004000011160A160B160C2B2502030408A307000001280C0000060D097B07000004063609097B070000040A080B0817D70C086E048E696A32D3072A00133003003B000000050000110203280E0000060A067B05000004067B0400000417DB6ED90B02067B0200000407281000000A2602022802000006067B05000004281000000A262A8E02280700000A725D010070038C0E000001048C07000001281100000A056F0300002B2A8A02280700000A725D010070038C0E000001048C07000001281100000A6F0400002B2A7602280700000A7277010070038C0E000001281400000A046F0500002B2A7202280700000A7277010070038C0E000001281400000A6F0600002B2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C0000007C030000237E0000E80300004403000023537472696E6773000000002C0700009001000023555300BC080000100000002347554944000000CC0800004801000023426C6F6200000000000000020000015715A201090A000000FA013300160000010000000F00000004000000080000000E000000170000001400000003000000050000000100000001000000020000000100000002000000020000000600000000009701010000000000060028015202060048015202060014013F020F00720200000A00D802BA020A00C800BA020A00AA02BA020600B200A9010A006000BA020A00EF00BA0206003103A9010600E602A9010A000103BA0206000100A90106008C01A901000000000800000000000100010001001000110000001500010001000A011000B0010000210001000F000A0110000C020000210006000F0006002E00B0000600E501580006008402B30006008102B80006005800B0000600AA0258000600BC00B80006004000BB0050200000000086183902100001006A20000000008108EC011B0002007C20000000008108FC01BE00020090200000000086009F00C400030000210000000086007F00CA000500C4210000000086007500D00007006022000000008600E201D9000B008422000000008100D401DF000C0020230000000081001803E5000D0064230000000081007F01ED000F00AB230000000081001F02F2001000CF230000000081001702FB001300F22300000000810095000301150010240000000081008B000A01170000000100DC00000001007901000001003700000002005C0000000100370000000200270300000100900200000200370000000300C200000004002C0200000100370000000100AB00000001004F00000002008A02000001004F00000001004F0000000200B202000003002702000001004F0000000200B202000001004F0000000200AB00000001004F00090039020100110039020600190039020A002900390210002900690016004900C0011B0029000001200051009C0225005100A7022B00390037033700290011033F002900930145003900BB015800490066015C005900700160002900CB0183007900D1028B005100F70292005100ED029A007900D102A1002E000B0015012E0013001E012E001B003D01320051006B0075007D0002000100000000021001020002000300010003000300048000000000000000000000000000000000D8020000040000000000000000000000A7001700000000000200000000000000000000000000BA0200000000030002000400020019004C0019006600250066002700660025004C0027004C0000000055496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C696200426174746C65496400626174746C6549640053636F72655375626D697474656400626174746C656964004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F72650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E745374617465006765745F50657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E67004C6F6700536D617274436F6E74726163742E646C6C0053797374656D00426174746C654D61696E005A65726F006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F426174746C654F776E6572007365745F426174746C654F776E657200426174746C6555736572004765745573657200536574557365720075736572004973426174746C654F766572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573004D6178557365727300757365727300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C74004173736572740047657457696E6E6572496E6465780075736572696E646578004172726179006F705F457175616C6974790000001742006100740074006C0065004F0077006E006500720000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001B42006100740074006C006500200065006E006400650064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00001975007300650072003A007B0030007D003A007B0031007D00001562006100740074006C0065003A007B0030007D000000000053FFE06AD37C28419B1B527317B313CF000420010108032000010520010111110520010112190420001225042000111D0420001229052001111D0E062002010E111D040701110C07000202111D111D05200201020E06300101011E00040A01110C060702110C11100306111D0320000B052002011C0A040A011110090704091D111D08111D0707040909091110050702110C0B0720021235111D0B0600030E0E1C1C07300102010E1E00063001011E000E0500020E0E1C087CEC85D7BEA7798E02060B04061D111D02060902060205200101111D052002020B0B052002020B0908200402111D0B0902052001111D0B05200101110C072002090B1D111D042001010B082003010B111D111007200211100B111D062002010B110C052001110C0B042800111D0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F777301080100020000000000000000000000000000000000000010000000000000000000000000000000882E00000000000000000000A22E0000002000000000000000000000000000000000000000000000942E0000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000B43E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010200E6EB4ACA0000000000000000E00022200B013000001A000000020000000000001E380000002000000040000000000010002000000002000004000000000000000400000000000000006000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000CC3700004F000000000000000000000000000000000000000000000000000000004000000C000000B03700001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E746578740000002418000000200000001A000000020000000000000000000000000000200000602E72656C6F6300000C0000000040000000020000001C0000000000000000000000000000400000420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003800000000000048000000020005000C270000A410000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007602280500000A7201000070038C0B000001280600000A046F0100002B2A7202280500000A7201000070038C0B000001280600000A6F0200002B2A8E02280500000A7217000070038C0B000001048C06000001280900000A056F0300002B2A8A02280500000A7217000070038C0B000001048C06000001280900000A6F0400002B2A7602280500000A7231000070038C0B000001280600000A046F0500002B2A7202280500000A7231000070038C0B000001280600000A6F0600002B2A7602280500000A7247000070038C0B000001280600000A046F0A00000A2A7202280500000A7247000070038C0B000001280600000A6F0B00000A2A7602280500000A7259000070038C0B000001280600000A046F0A00000A2A7202280500000A7259000070038C0B000001280600000A6F0B00000A2A4602280500000A72790000706F0C00000A2A4A02280500000A7279000070036F0D00000A2A4602280500000A72850000706F0C00000A2A4A02280500000A7285000070036F0D00000A2A4602280500000A729F0000706F0B00000A2A4A02280500000A729F000070036F0A00000A2A4602280500000A72B10000706F0E00000A2A4A02280500000A72B1000070036F0F00000A2AA20203281000000A0202281100000A6F1200000A280C0000060204281000000602176A28120000062A13300300320000000100001102281D0000060203280E000006021200FE1507000002120002280B0000067D0C0000041200037D0D00000406280700002B2A0000133003005C0000000200001102280D0000060A020602281100000A6F1200000A281400000A72CB000070281500000A02280B0000060B0206280C000006027E1600000A280E000006021202FE15060000021202077D0A0000041202067D0B00000408280800002B2A13300400A9000000030000110202281100000A6F1200000A02280B000006281400000A723D010070281500000A0203156A02280F0000066E5CFE057281010070281500000A0228110000060A0206176AD728120000061202FE15030000021202067D010000041202037D04000004120202280F0000068D060000017D03000004080B0206072801000006021203FE15080000021203067D0E000004120302281100000A6F1200000A7D0F00000409280900002B062A00000013300400F300000004000011020328020000060A02067B020000047E1600000A281400000A72A1010070281500000A02067B0400000402281100000A6F1700000AFE0172C5010070281500000A020302281100000A6F1200000A28040000060B02077B0600000416FE017225020070281500000A020302281100000A6F1200000A072803000006020328080000060C020802280F000006FE0116FE017269020070281500000A067B0300000402281100000A6F1200000A8C06000001086E6F1800000A02030817D728070000060203062801000006021203FE15090000021203037D10000004120302281100000A6F1200000A7D1100000409280A00002B2A001330040045010000050000110202281100000A6F1200000A02280B000006281400000A72AD020070281500000A0204280A0000060A020602280F000006FE0572ED020070281500000A020428020000060B02077B020000047E1600000A281400000A72A1010070281500000A02040328040000060C02087B0600000416FE017225020070281500000A1202177D060000040204030828030000060617D70A0204062809000006020428060000060D05097B0700000436221203057D070000041203037D090000041203177D0800000402040928050000062B1D05097B07000004331412037C08000004254B17D75402040928050000060602280F0000063327020428060000060D097B080000041736090207281C0000062B0D0207097B09000004281A000006021204FE150A0000021204047D12000004120402281100000A6F1200000A7D130000041104280B00002B2A36020328020000067B020000042A760F01047D0200000402037B010000040328010000060203281B0000062A000000133003003300000006000011037B0400000402280F00000617DB6ED90A02037B0200000406281900000A260202280B000006037B04000004281900000A262A00133003007A000000000000000F01177D0500000402037B0100000403280100000602037B0300000416A306000001037B04000004281900000A2602037B0300000417A306000001037B04000004281900000A2602037B0300000418A306000001037B04000004281900000A2602037B0300000419A306000001037B04000004281900000A262A8A0202281100000A6F1200000A02280B000006281400000A7233030070281500000A2A00000042534A4201000100000000000C00000076342E302E33303331390000000005006C000000EC050000237E0000580600001C05000023537472696E677300000000740B00006803000023555300DC0E0000100000002347554944000000EC0E0000B801000023426C6F6200000000000000020000015715A201090A000000FA01330016000001000000100000000A000000130000001D00000022000000190000000D000000060000000100000004000000080000000100000002000000080000000B00000000004902010000000000060068019D03060097019D03060054018A030F00BD0300000A00450427040A00170427040A001C0127040600FC005B020A00880127040A0043012704060022005B020600DB015B02060053045B020A009D0027040600FA045B020A006E042704000000002900000000000100010001001000320000001500010001000A01100062020000210001001E000A01100064030000210006001E000A01100020030000210007001E000A0110000202000021000A001E000A0110002B02000021000C001E000A0110001A02000021000E001E000A011000F1010000210010001E000A011000E2010000210012001E0006006800F2000600A6029B000600E903F50006009500F20006007A00FA0006008600FA0006000601FD000600AC04FD00060048039B000600F3029B0006000E039B00060001039B000600E6029B0006006800F200060017049B0006006800F200060017049B0006006800F200060017049B005020000000008100DF00000101006E20000000008600D500070103008B2000000000810077030D010400AF200000000086006F0316010700D22000000000810045031E010900F020000000008600340325010B000D21000000008100E3042B010C002B21000000008100D60431010E00482100000000810095042B010F0066210000000081007E04310111008321000000008608AD026E0012009521000000008108B70236011200A821000000008608C1026E001300BA21000000008108D20236011300CD21000000008608CC033C011400DF21000000008108D90340011400F2210000000086084F00BD0015000422000000008108600045011500172200000000861884034A0116004022000000008600E302360118008022000000008600720206001900E822000000008600E90051011900A023000000008600C90045011A00A024000000008600B20056011B00F125000000008600A3025E011E00FF25000000008100950264011F002026000000008100CE016C0121006026000000008100BC006C012200E62600000000810000050600230000000100710000000200F500000001007100000001007100000002001F04000003007F03000001007100000002001F0400000100710000000200560300000100710000000100710000000200F00400000100710000000100710000000200BE0400000100710000000100C80100000100C80100000100C80100000100C80100000100300100000200E60300000100170300000100990000000100710000000100FD03000002007100000003000C0100000100710000000100F50000000200EF0300000100F50000000100F500090084030100110084030600190084030A0049008403060029001201100061003E041500510064041B0051005A04280061003E042F0051000B004000510001004600510009044B0051001404510051001500580051001F005D002900840363002900A6006900710081026E00290045027800310010058D002900CF04950031006D029B007100B501BD007900BF01C10029008C02E1002E000B007F012E00130088012E001B00A70141012300B00161012300B00181012300B001A1012300B001C1012300B001E1012300B00101022300B00121022300B00141022300B00161022300B00173008400A400B300CC00DD000200010000001A0372010000E60272010000DD037701000064007B0102000B00030001000C00030002000D00050001000E00050002000F00070001001000070002001100090001001200090004800000000000000000000000000000000045040000040000000000000000000000E9003800000000000200000000000000000000000000270400000000030002000400020005000200060002000700020008000200090002000A0002000F002300110023000F003600110036000F003B0011003B0027007F0027009F002700AE002700C7002700D800000000000047657455496E7433320053657455496E7433320047657455496E7436340053657455496E743634003C4D6F64756C653E004172656E610053797374656D2E507269766174652E436F72654C6962006765745F4E657874426174746C654964007365745F4E657874426174746C65496400626174746C65496400497343616E63656C6C65640053636F72655375626D6974746564004665650066656500494D657373616765006765745F4D65737361676500456E64426174746C650043616E63656C426174746C6500456E746572426174746C6500476574426174746C6500536574426174746C65005374617274426174746C6500626174746C650056616C7565547970650053636F72650073636F7265006765745F53746174650049536D617274436F6E7472616374537461746500736D617274436F6E74726163745374617465004950657273697374656E7453746174650044656275676761626C6541747472696275746500436F6D70696C6174696F6E52656C61786174696F6E7341747472696275746500496E6465784174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465006765745F56616C75650053657456616C75650076616C75650050726F636573735072697A6500537472696E6700426174746C65456E6465644C6F6700426174746C65456E74657265644C6F67004F776E6572736869705472616E736665727265644C6F6700426174746C65537461727465644C6F67004F776E6572736869705472616E736665725265717565737465644C6F6700536D617274436F6E74726163742E646C6C0053797374656D00426174746C654D61696E005A65726F00436C61696D4F776E657273686970006765745F53656E646572005472616E736665720050726F6365737357696E6E65720047657457696E6E6572006765745F4F776E6572007365745F4F776E6572006765745F50656E64696E674F776E6572007365745F50656E64696E674F776E65720053657450656E64696E674F776E65720050726576696F75734F776E65720043757272656E744F776E6572004E65774F776E6572006E65774F776E657200426174746C654869676865737453636F726572004765744869676865737453636F726572005365744869676865737453636F726572006869676865737453636F72657200426174746C6555736572004765745573657200536574557365720075736572002E63746F720053797374656D2E446961676E6F73746963730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300446562756767696E674D6F646573006765745F4D61785573657273007365745F4D61785573657273006D617855736572730077696E6E65724164647265737300757365724164647265737300476574416464726573730053657441646472657373006164647265737300537472617469732E536D617274436F6E74726163747300466F726D617400536D617274436F6E7472616374004F626A656374004765745374727563740053657453747275637400495472616E73666572526573756C740047657453636F72655375626D6974746564436F756E740053657453636F72655375626D6974746564436F756E74004869676865737453636F7265436F756E740073636F72657375626D6974636F756E74004173736572740047657455736572496E6465780053657455736572496E6465780075736572696E64657800417272617900456E737572654F776E65724F6E6C79006F705F457175616C69747900001562006100740074006C0065003A007B0030007D00001975007300650072003A007B0030007D003A007B0031007D000015730063006F007200650072003A007B0030007D00001175007300650072003A007B0030007D00001F730063006F00720065007300750062006D00690074003A007B0030007D00000B4F0077006E00650072000019500065006E00640069006E0067004F0077006E006500720000114D00610078005500730065007200730000194E0065007800740042006100740074006C00650049006400007143006C00610069006D004F0077006E0065007200730068006900700020006D007500730074002000620065002000630061006C006C0065006400200062007900200074006800650020006E00650077002800700065006E00640069006E006700290020006F0077006E00650072002E0000434F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E002000730074006100720074002000670061006D0065002E00001F460065006500200069007300200074006F006F0020006800690067006800002342006100740074006C00650020006E006F007400200066006F0075006E0064002E00005F42006100740074006C006500200066006500650020006900730020006E006F00740020006D00610074006300680069006E00670020007700690074006800200065006E007400720079002000660065006500200070006100690064002E00004354006800650020007500730065007200200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E0000434D00610078002000750073006500720020007200650061006300680065006400200066006F00720020007400680069007300200062006100740074006C0065002E00003F4F006E006C007900200062006100740074006C00650020006F0077006E00650072002000630061006E00200065006E0064002000670061006D0065002E00004541006C006C00200075007300650072007300200061006C007200650061006400790020007300750062006D00690074007400650064002000730063006F00720065002E00003354006800650020006D006500740068006F00640020006900730020006F0077006E006500720020006F006E006C0079002E000000F641A50CB4EA5F4D9C24BB4EACC176CA0004200101080320000105200101111104200012290500020E0E1C07300102010E1E00040A01110C063001011E000E0600030E0E1C1C040A011110040A011114052002010E09042001090E05200111190E062002010E11190420010B0E052002010E0B05200101121D04200012390420001119040701111C06300101011E00040A01111C080703111911191118070002021119111905200201020E03061119040A0111180907040B110C110C1120040A011120090704110C11100911240320000B052002011C0A040A0111240B070509110C111011141128040A0111280307010B072002124111190B087CEC85D7BEA7798E02060B04061D1119020602020609062002010B110C052001110C0B082003010B1119111007200211100B1119062002010B111405200111140B052002010B09042001090B052001011119032000090420010109042001010B06200201121D090420010B0B0720030111190B0905200111190B07200201110C111905200101110C0428001119032800090328000B0801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F777301080100020000000000040100000000000000000000000000000000000010000000000000000000000000000000F437000000000000000000000E38000000200000000000000000000000000000000000000000000000380000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF25002000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000203800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ```