public override string ToString()
        {
            var strWriter  = new StringWriter();
            var jsonWriter = new JsonTextWriter(strWriter);

            jsonWriter.Formatting = Formatting.Indented;
            jsonWriter.WriteStartObject();
            jsonWriter.WritePropertyName("tx");
            jsonWriter.WriteStartObject();
            var formatter = new RPC.BlockExplorerFormatter();

            formatter.WriteTransaction2(jsonWriter, tx);
            jsonWriter.WriteEndObject();

            if (TryGetFee(out var fee))
            {
                jsonWriter.WritePropertyValue("fee", $"{fee} BTC");
            }
            if (TryGetEstimatedFeeRate(out var feeRate))
            {
                jsonWriter.WritePropertyValue("feeRate", $"{feeRate}");
            }
            if (unknown.Count != 0)
            {
                jsonWriter.WritePropertyName("unknown");
                jsonWriter.WriteStartObject();
                foreach (var el in unknown)
                {
                    jsonWriter.WritePropertyValue(Encoders.Hex.EncodeData(el.Key), Encoders.Hex.EncodeData(el.Value));
                }
                jsonWriter.WriteEndObject();
            }

            jsonWriter.WritePropertyName("inputs");
            jsonWriter.WriteStartArray();
            foreach (var input in this.Inputs)
            {
                input.Write(jsonWriter);
            }
            jsonWriter.WriteEndArray();

            jsonWriter.WritePropertyName("outputs");
            jsonWriter.WriteStartArray();
            foreach (var output in this.Outputs)
            {
                output.Write(jsonWriter);
            }
            jsonWriter.WriteEndArray();

            jsonWriter.WriteEndObject();
            jsonWriter.Flush();
            return(strWriter.ToString());
        }
Exemplo n.º 2
0
        internal void Write(JsonTextWriter jsonWriter)
        {
            jsonWriter.WriteStartObject();
            jsonWriter.WritePropertyValue("index", Index);
            if (unknown.Count != 0)
            {
                jsonWriter.WritePropertyName("unknown");
                jsonWriter.WriteStartObject();
                foreach (var el in unknown)
                {
                    jsonWriter.WritePropertyValue(Encoders.Hex.EncodeData(el.Key), Encoders.Hex.EncodeData(el.Value));
                }
                jsonWriter.WriteEndObject();
            }
            jsonWriter.WritePropertyName("partial_signatures");
            jsonWriter.WriteStartObject();
            foreach (var sig in partial_sigs)
            {
                jsonWriter.WritePropertyValue(sig.Key.ToString(), Encoders.Hex.EncodeData(sig.Value.ToBytes()));
            }
            jsonWriter.WriteEndObject();
            if (SighashType is SigHash s)
            {
                jsonWriter.WritePropertyValue("sighash", GetName(s));
            }
            if (this.FinalScriptSig != null)
            {
                jsonWriter.WritePropertyValue("final_script_sig", FinalScriptSig.ToString());
            }
            if (this.FinalScriptWitness != null)
            {
                jsonWriter.WritePropertyValue("final_script_witness", FinalScriptWitness.ToString());
            }

            if (this.redeem_script != null)
            {
                jsonWriter.WritePropertyValue("redeem_script", redeem_script.ToString());
            }
            if (this.witness_script != null)
            {
                jsonWriter.WritePropertyValue("witness_script", witness_script.ToString());
            }

            if (this.NonWitnessUtxo != null)
            {
                jsonWriter.WritePropertyName("non_witness_utxo");
                jsonWriter.WriteStartObject();
                var formatter = new RPC.BlockExplorerFormatter();
                formatter.WriteTransaction2(jsonWriter, NonWitnessUtxo);
                jsonWriter.WriteEndObject();
            }
            if (this.WitnessUtxo != null)
            {
                jsonWriter.WritePropertyName("witness_utxo");
                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyValue("value", WitnessUtxo.Value.ToString(false, false));
                jsonWriter.WritePropertyValue("scriptPubKey", WitnessUtxo.ScriptPubKey.ToString());
                jsonWriter.WriteEndObject();
            }
            jsonWriter.WriteBIP32Derivations(this.hd_keypaths);

            jsonWriter.WriteEndObject();
        }