Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. contract EtherWorldStorage {
  2. /* Constructor */
  3. address owner;
  4. mapping (bytes32 => World) Gameworlds;
  5.  
  6. mapping (bytes32 => uint) NamesIndex;
  7. World[] worldContracts;
  8.  
  9. function EtherWorldStorage(){
  10. owner = msg.sender;
  11. }
  12.  
  13.  
  14. event WorldCreated(bytes32 indexed worldName, address indexed sender, address result );
  15.  
  16. function createWorld(bytes32 name) returns (address a){
  17. if(NamesIndex[name] > 0x0){
  18. return 0x0;
  19. }
  20. World w = new World(name);
  21. NamesIndex[name] = worldContracts.length - 1;
  22. Gameworlds[name] = w;
  23. WorldCreated(name,msg.sender,w);
  24. return w;
  25. }
  26.  
  27. function getWorldCount() returns (uint i){
  28. return worldContracts.length;
  29. }
  30.  
  31. function destroyWorld(bytes32 world){
  32.  
  33. World w = Gameworlds[world];
  34. w.destroy(owner);
  35. }
  36.  
  37.  
  38. function getItemPossessorsInventory(InventoryItem item) returns (address a){
  39. return item.getOwningInventory();
  40. }
  41.  
  42. }
  43.  
  44. public static string CreateWorld(string world)
  45. {
  46. var web3 = new Web3(Resources.Server);
  47. var result = web3.Personal.UnlockAccount.SendRequestAsync("0x54a222aE3d59EF92D715409f31C6eCAf331D0782", Resources.Password, 30).Result;
  48. if (result != true)
  49. {
  50. throw new Exception("Unable to unlock account...");
  51. }
  52.  
  53.  
  54.  
  55.  
  56. var d = Encoding.UTF8.GetBytes(world);
  57.  
  58.  
  59. string address = "0x30d578718e1da379f4B1B1ac5E9be9ba646E0bCF"; // Contract address
  60. var contract = web3.Eth.GetContract(Resources.ContractInterface2, address);
  61.  
  62. var add = contract.GetFunction("createWorld"); // Add method
  63. var worldCreatedEvent= contract.GetEvent("WorldCreated");
  64. var filterAll = worldCreatedEvent.CreateFilterAsync().Result;
  65. var totalGas = new HexBigInteger(GetGasPrice(add, d).Value*2);
  66.  
  67. HexBigInteger gasPrice = new HexBigInteger(new BigInteger(0.144));
  68.  
  69. var callResult = add.SendTransactionAsync("0x54a222aE3d59EF92D715409f31C6eCAf331D0782", totalGas,new HexBigInteger(0), d);
  70. var theResult = GetReceiptAsync(web3, callResult.Result);
  71. var log = worldCreatedEvent.GetAllChanges<dynamic>(filterAll).Result;
  72.  
  73.  
  74. return log[0].Event;
  75. return callResult.Result;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement