Пример #1
0
        /// <summary>
        /// XAYA: Checks to see if a name exists. Text fields show "" (an empty string) if the name does not exist,
        /// numeric fields return -1 if it does not exist, and boolean fileds return false if the name does not exist. Otherwise, regular data is returned.
        /// </summary>
        /// <param name="name">The name to check. It must be a valid name and include the namespace, e.g. "p/".</param>
        /// <returns>Returns a GetShowNameResponse object. Text fields show an empty string if the name does not exist,
        /// numeric fields return -1 if it does not exist, and boolean fileds return false if the name does not exist. Otherwise, regular data is returned.</returns>
        public GetShowNameResponse ShowName(string name)
        {
            GetShowNameResponse response = new GetShowNameResponse();

            // Initialise all fields as empty.
            response.name           = "";
            response.name_encoding  = "";
            response.name_error     = "";
            response.value          = "";
            response.value_encoding = "";
            response.txid           = "";
            response.vout           = -1;
            response.address        = "";
            response.ismine         = false;
            response.height         = -1;

            try
            {
                response = _rpcConnector.MakeRequest <GetShowNameResponse>(RpcMethods.name_show, name);
            }
            catch
            {
                // leave as is
            }

            return(response);
        }
Пример #2
0
        private void btnSendName_Click(object sender, EventArgs e)
        {
            // We should check that the name exists.
            GetShowNameResponse r = xayaCoinService.ShowName(txtSendNameName.Text);

            // We must make certain that the name exists.
            // As per the method's description, numeric fields are -1 if the name does not exist.
            // This is a simple error check.
            if (r.height < 0)
            {
                return;
            }

            // In order to update a name, it must belong to us and be in our wallet.
            // This makes the above check useless, but there are cases where you would want to only check if a name exists irrespective of whether or not the name is owned by you/the player/user.
            if (r.ismine == false)
            {
                return;
            }

            // We should verify that both the name and value are valid. We have a simple Utils class to give us some reusable checks.
            bool nameIsValid  = Utils.IsValidName(txtSendNameName.Text);
            bool valueIsValid = Utils.IsValidJson(txtSendNameValue.Text);

            if (!nameIsValid || !valueIsValid)
            {
                // One of them is invalid, so we cancel the operation.
                return;
            }

            // The destination address must be valid. Check to ensure that it is.
            ValidateAddressResponse validate = xayaCoinService.ValidateAddress(txtSendNameAddress.Text);

            if (!validate.IsValid)
            {
                // The address isn't valid, so we cancel the operation.
                return;
            }

            // Send the name to the CHI address.
            // When using RPCs, we must send the options, i.e. "destAddress", as a JSON object.
            // Here we use the Newtonsoft JObject to do that. We create the object and set its value to the address.
            JObject job = new JObject();

            job["destAddress"] = txtSendNameAddress.Text;

            // And finally perform the operation to send the name to the CHI address.
            string result = xayaCoinService.NameUpdate(txtSendNameName.Text, txtSendNameValue.Text, job);

            // The return value is a txid that we display in the results text box.
            txtSendNameResult.Text += result + "\r\n";
        }
Пример #3
0
        private void btnUpdateName_Click(object sender, EventArgs e)
        {
            // We should check that the name doesn't already exist.
            GetShowNameResponse r = xayaCoinService.ShowName(txtUpdateNameName.Text);

            // We must make certain that the name exists.
            // As per the method's description, numeric fields are -1 if the name does not exist.
            // This is a simple error check.
            if (r.height < 0)
            {
                return;
            }

            // In order to update a name, it must belong to us and be in our wallet.
            // This makes the above check useless, but there are cases where you would want to only check if a name exists irrespective of whether or not the name is owned by you/the player/user.
            if (r.ismine == false)
            {
                // return;
            }

            // We should verify that both the name and value are valid. We have a simple Utils class to give us some reusable checks.
            bool nameIsValid  = Utils.IsValidName(txtUpdateNameName.Text);
            bool valueIsValid = Utils.IsValidJson(txtUpdateNameValue.Text);

            if (!nameIsValid || !valueIsValid)
            {
                // One of them is invalid, so we cancel the operation.
                return;
            }

            // At this point, we know our input data is valid and can proceed with the call.
            string result = xayaCoinService.NameUpdate(txtUpdateNameName.Text, txtUpdateNameValue.Text, new object());

            // The return value is a txid that we display in the results text box.
            txtUpdateNameResult.Text += result + "\r\n";
        }