Пример #1
0
        /// <inheritdoc />
        /// <exception cref="InvalidAddressException">Thrown if <paramref name="address"/> is invalid.</exception>
        public void Withdraw(decimal amount, string address)
        {
            this.logger.Trace("({0}:{1},{2}:'{3}')", nameof(amount), amount, nameof(address), address);

            ValidateAddressResponse validationResult = this.coinService.ValidateAddress(address);

            if (!validationResult.IsValid)
            {
                this.logger.Trace("(-)[INVALID_ADDRESS]");
                throw new InvalidAddressException();
            }

            try
            {
                this.coinService.SendFrom(AccountName, address, amount);
            }
            catch (RpcInternalServerErrorException e)
            {
                if (e.Message == "Insufficient funds")
                {
                    // This should never happen.
                    this.logger.Fatal(e.Message);
                    this.fatalNotifier.NotifySupport(e.Message);
                }

                this.logger.Error(e.ToString);
                throw;
            }

            this.logger.Trace("(-)");
        }
Пример #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
        public Dictionary <String, String> GetMyPublicAndPrivateKeyPairs()
        {
            const Int16 secondsToUnlockTheWallet = 30;
            Dictionary <String, String> keyPairs = new Dictionary <String, String>();

            WalletPassphrase(Parameters.WalletPassword, secondsToUnlockTheWallet);
            List <ListReceivedByAddressResponse> myAddresses = ListReceivedByAddress(0, true);

            foreach (ListReceivedByAddressResponse listReceivedByAddressResponse in myAddresses)
            {
                ValidateAddressResponse validateAddressResponse = ValidateAddress(listReceivedByAddressResponse.Address);

                if (validateAddressResponse.IsMine && validateAddressResponse.IsValid && !validateAddressResponse.IsScript)
                {
                    String privateKey = DumpPrivKey(listReceivedByAddressResponse.Address);
                    keyPairs.Add(validateAddressResponse.PubKey, privateKey);
                }
            }

            WalletLock();
            return(keyPairs);
        }
Пример #4
0
        //  Note: This will return funky results if the address in question along with its private key have been used to create a multisig address with unspent funds
        public Decimal GetAddressBalance(String inWalletAddress, Int32 minConf, Boolean validateAddressBeforeProcessing)
        {
            if (validateAddressBeforeProcessing)
            {
                ValidateAddressResponse validateAddressResponse = ValidateAddress(inWalletAddress);

                if (!validateAddressResponse.IsValid)
                {
                    throw new GetAddressBalanceException(String.Format("Address {0} is invalid!", inWalletAddress));
                }

                if (!validateAddressResponse.IsMine)
                {
                    throw new GetAddressBalanceException(String.Format("Address {0} is not an in-wallet address!", inWalletAddress));
                }
            }

            List <ListUnspentResponse> listUnspentResponses = ListUnspent(minConf, 9999999, new List <String>
            {
                inWalletAddress
            });

            return(listUnspentResponses.Any() ? listUnspentResponses.Sum(x => x.Amount) : 0);
        }
Пример #5
0
 public void Init()
 {
     instance = new ValidateAddressResponse();
 }