示例#1
0
        private bool CallContract(string method, object[] values)
        {
            //NOTE: NeoLux does not support CoZ testnet at the moment.
            //Modified source to add temporary support by hardcoding a single node.
            //Keep an eye out for updates.

            //Audit log
            Log.Info(string.Format("CallContract: CommitToBlockchain:{0}, method:{1}, params:{2}", Config.CommitToBlockchain.ToString(), method, String.Join(",", values)));

            if (Config.CommitToBlockchain)
            {
                try
                {
                    var key    = new KeyPair(ConvertUtility.HexToBytes(privateKey));
                    var result = NeoAPI.CallContract(environment, key, smartContractScriptHash, method, values);

                    if (result == false)
                    {
                        Log.Error("CallContract: Received false on method " + method);
                    }

                    return(result);
                }
                catch (Exception ex)
                {
                    Log.Error("CallContract: Failed on method " + method + ". " + ex.Message);
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
示例#2
0
        public bool RegisterName(string name)
        {
            if (!string.IsNullOrEmpty(this.name))
            {
                throw new Exception("Name already set");
            }

            var result = NeoAPI.CallContract(NeoAPI.Net.Test, keys, Protocol.scriptHash, "registerMailbox", new object[] { this.keys.CompressedPublicKey, name });

            if (result)
            {
                this.name = name;
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Fetches a request from the contract storage and processes it.
        /// </summary>
        private void ProcessRequest(Storage storage, BigInteger ID)
        {
            var base_key = ID.ToByteArray();

            var req_owner_key = request_owner_prefix.Concat(base_key).ToArray();
            var req_key_key   = request_key_prefix.Concat(base_key).ToArray();
            var req_uuid_key  = request_key_prefix.Concat(base_key).ToArray();
            var req_val_key   = request_value_prefix.Concat(base_key).ToArray();

            var uuid      = Encoding.UTF8.GetString(storage.Get(req_uuid_key));
            var value     = Encoding.ASCII.GetString(storage.Get(req_val_key));
            var temp      = storage.Get(req_key_key);
            var operation = (char)temp[0];
            var key       = Encoding.UTF8.GetString(temp.Skip(1).ToArray());

            switch (operation)
            {
            case 'C':
            {
                this.swarm.Create(uuid, key, value);
                break;
            }

            case 'R':
            {
                var read = this.swarm.Read(uuid, key);

                var push_tx = neo_api.CallContract(owner_keys, bluzelle_contract_hash, "api_push", new object[] { uuid, key, read });
                neo_api.WaitForTransaction(owner_keys, push_tx);

                break;
            }

            case 'U':
            {
                this.swarm.Update(uuid, key, value);

                break;
            }

            case 'D':
            {
                this.swarm.Delete(uuid, key);
                break;
            }
            }
        }
示例#4
0
        public bool SendMessage(string destName, string hash)
        {
            if (string.IsNullOrEmpty(destName))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(hash))
            {
                return(false);
            }

            if (destName.Equals(this.name))
            {
                return(false);
            }

            return(NeoAPI.CallContract(NeoAPI.Net.Test, keys, Protocol.scriptHash, "sendMessage", new object[] { this.keys.CompressedPublicKey, destName, hash }));
        }
示例#5
0
        /// <summary>
        /// Catches and processes all notifications triggered in a Neo transaction
        /// </summary>
        /// <param name="tx"></param>
        private void ProcessNotifications(Transaction tx)
        {
            // add the transaction to the cache
            transactions[tx.Hash] = tx;

            var notifications = listenerVM.GetNotifications(tx);

            if (notifications == null)
            {
                return;
            }

            foreach (var entry in notifications)
            {
                switch (entry.Name)
                {
                case "blz_create": {
                    if (entry.Args.Length != 3)
                    {
                        throw new Exception($"Swarm.Create expects 3 arguments");
                    }

                    var uuid  = (byte[])entry.Args[0];
                    var key   = (byte[])entry.Args[1];
                    var value = (byte[])entry.Args[2];

                    this.swarm.Create(uuid, key, value);
                    break;
                }

                case "blz_read":
                {
                    if (entry.Args.Length != 2)
                    {
                        throw new Exception($"Swarm.Read expects 2 arguments");
                    }

                    var uuid = (byte[])entry.Args[0];
                    var key  = (byte[])entry.Args[1];

                    var value = this.swarm.Read(uuid, key);

                    var push_tx = neo_api.CallContract(owner_keys, bluzelle_contract_hash, "api_push", new object[] { uuid, key, value });

                    neo_api.WaitForTransaction(owner_keys, push_tx);
                    break;
                }

                case "blz_update":
                {
                    if (entry.Args.Length != 3)
                    {
                        throw new Exception($"Swarm.Update expects 3 arguments");
                    }

                    var uuid  = (byte[])entry.Args[0];
                    var key   = (byte[])entry.Args[1];
                    var value = (byte[])entry.Args[2];

                    this.swarm.Update(uuid, key, value);

                    //  public static event Action<byte[], byte[], byte[]> OnUpdate;
                    break;
                }

                case "blz_delete":
                {
                    if (entry.Args.Length != 2)
                    {
                        throw new Exception($"Swarm.Delete expects 2 arguments");
                    }

                    var uuid = (byte[])entry.Args[0];
                    var key  = (byte[])entry.Args[1];

                    this.swarm.Remove(uuid, key);

                    break;
                }
                }
            }
        }