public async Task CreateContract(byte[] privateKey)
        {
            byte[]  publicKey  = CryptoUtils.PublicKeyFromPrivateKey(privateKey);
            Address callerAddr = Address.FromPublicKey(publicKey);

            IRpcClient writer = RpcClientFactory.Configure().WithLogger(Debug.unityLogger).WithWebSocket(WriterHost)
                                .Create();

            IRpcClient reader = RpcClientFactory.Configure().WithLogger(Debug.unityLogger).WithWebSocket(ReaderHost)
                                .Create();

            DAppChainClient client = new DAppChainClient(writer, reader)
            {
                Logger = Debug.unityLogger
            };

            client.TxMiddleware = new TxMiddleware(new ITxMiddlewareHandler[]
            {
                new NonceTxMiddleware(publicKey, client), new SignedTxMiddleware(privateKey)
            });

            client.AutoReconnect = false;

            await client.ReadClient.ConnectAsync();

            await client.WriteClient.ConnectAsync();

            Address contractAddr = await client.ResolveContractAddressAsync("ZombieBattleground");

            Contract oldContract = Contract;

            Contract = new Contract(client, contractAddr, callerAddr);
            ContractCreated?.Invoke(oldContract, Contract);
        }
Beispiel #2
0
        public Task Handle(ContractCreated message)
        {
            Data.ContractId      = message.ContractId;
            Data.ContractCreated = true;

            Log.Information($"ContractId -> {message.ContractId}");

            TryComplete();

            return(Task.CompletedTask);
        }
Beispiel #3
0
 private void Apply(ContractCreated e)
 {
     this.ContractId = e.ContractId;
     this.ClientId   = e.ClientId;
 }
Beispiel #4
0
 private void AddHashrate(ContractCreated e)
 {
     _contracts.TryGetValue(e.ContractId, out var quantity);
     quantity += e.Quantity;
     _contracts[e.ContractId] = quantity;
 }