Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public Task Handle(ContractCreated message)
        {
            Data.ContractId      = message.ContractId;
            Data.ContractCreated = true;

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

            TryComplete();

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