Exemple #1
0
        private static string ConvertTxsToString(RawTxInput[] inputs)
        {
            string txInfo = "[";
            bool firstOne = true;
            foreach (RawTxInput input in inputs) {
                if (firstOne)
                    firstOne = false;
                else
                    txInfo += ",";

                if (input.txID == null || input.txID.Length == 0)
                    throw new Exception ("A txID is necessary for input for a new transaction!");
                if (input.vout == null || input.vout.Length == 0)
                    throw new Exception ("A vout needs to be specified for which part of the previous transaction's output to use as input!");
                txInfo += "{" + qt + "txid" + qt + ":" + qt + input.txID + qt + "," + qt + "vout" + qt + ":" + input.vout;

                // Optional
                if (input.scriptPubKey != null && input.scriptPubKey.Length > 0)
                    txInfo += "," + qt + "scriptPubKey" + qt + ":" + qt + input.scriptPubKey + qt;
                if (input.redeemScript != null && input.redeemScript.Length > 0)
                    txInfo += "," + qt + "redeemScript" + qt + ":" + qt + input.redeemScript + qt;

                txInfo += "}";
            }
            txInfo += "]";
            return txInfo;
        }
Exemple #2
0
 public static bool LockUnspent(bool toUnlock, RawTxInput[] lockThese = null)
 {
     string result;
     if (lockThese == null)
         result = SimpleStringRequest ("lockunspent", ConvertBoolToString (toUnlock), false);
     else {
         string txs = ConvertTxsToString (lockThese);
         result = SimpleStringRequest ("lockunspent", ConvertBoolToString (toUnlock) + ", " + txs, false);
     }
     if (result.ToLower () == "true")
         return true;
     else
         return false;
 }
Exemple #3
0
        public static string SignRawTransaction(String txHex, RawTxInput[] inputs = null, string[] privateKeys = null, SigHashType sigHashType = SigHashType.All)
        {
            if (inputs == null)
                return SimpleStringRequest ("signrawtransaction", qt + txHex + qt, false);

            string inputInfo = ConvertTxsToString (inputs);
            if (privateKeys == null)
                return SimpleStringRequest ("signrawtransaction", qt + txHex + qt + ", " + inputInfo, false);

            string privateKeysFormatted = "[";
            bool firstOne = true;
            foreach (string key in privateKeys) {
                if (firstOne)
                    firstOne = false;
                else
                    privateKeysFormatted += ",";
                privateKeysFormatted += qt + key + qt;
            }
            privateKeysFormatted += "]";
            return SimpleStringRequest ("signrawtransaction", qt + txHex + qt + ", " + inputInfo + ", " + privateKeysFormatted + ", " + qt + ConvertSigHashTypeToString(sigHashType) + qt, false);
        }
Exemple #4
0
 public static string CreateRawTransaction(RawTxInput[] inputs, PayToAddress[] payToAddresses)
 {
     string txInputInfo = ConvertTxsToString (inputs);
     string txOutputInfo = ConvertPayToAddressesToString (payToAddresses);
     return SimpleStringRequest ("createrawtransaction", txInputInfo + ", " + txOutputInfo, false);
 }