Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contract EtherWorldStorage {
- /* Constructor */
- address owner;
- mapping (bytes32 => World) Gameworlds;
- mapping (bytes32 => uint) NamesIndex;
- World[] worldContracts;
- function EtherWorldStorage(){
- owner = msg.sender;
- }
- event WorldCreated(bytes32 indexed worldName, address indexed sender, address result );
- function createWorld(bytes32 name) returns (address a){
- if(NamesIndex[name] > 0x0){
- return 0x0;
- }
- World w = new World(name);
- NamesIndex[name] = worldContracts.length - 1;
- Gameworlds[name] = w;
- WorldCreated(name,msg.sender,w);
- return w;
- }
- function getWorldCount() returns (uint i){
- return worldContracts.length;
- }
- function destroyWorld(bytes32 world){
- World w = Gameworlds[world];
- w.destroy(owner);
- }
- function getItemPossessorsInventory(InventoryItem item) returns (address a){
- return item.getOwningInventory();
- }
- }
- public static string CreateWorld(string world)
- {
- var web3 = new Web3(Resources.Server);
- var result = web3.Personal.UnlockAccount.SendRequestAsync("0x54a222aE3d59EF92D715409f31C6eCAf331D0782", Resources.Password, 30).Result;
- if (result != true)
- {
- throw new Exception("Unable to unlock account...");
- }
- var d = Encoding.UTF8.GetBytes(world);
- string address = "0x30d578718e1da379f4B1B1ac5E9be9ba646E0bCF"; // Contract address
- var contract = web3.Eth.GetContract(Resources.ContractInterface2, address);
- var add = contract.GetFunction("createWorld"); // Add method
- var worldCreatedEvent= contract.GetEvent("WorldCreated");
- var filterAll = worldCreatedEvent.CreateFilterAsync().Result;
- var totalGas = new HexBigInteger(GetGasPrice(add, d).Value*2);
- HexBigInteger gasPrice = new HexBigInteger(new BigInteger(0.144));
- var callResult = add.SendTransactionAsync("0x54a222aE3d59EF92D715409f31C6eCAf331D0782", totalGas,new HexBigInteger(0), d);
- var theResult = GetReceiptAsync(web3, callResult.Result);
- var log = worldCreatedEvent.GetAllChanges<dynamic>(filterAll).Result;
- return log[0].Event;
- return callResult.Result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement