コード例 #1
0
        public void WriteTLV(TLVWriter writer)
        {
            Span <byte> output = stackalloc byte[65 + 97];

            Signature.WriteToSpan(output);
            Proof.WriteToSpan(output.Slice(65));
            writer.WriteBytes(output);
        }
コード例 #2
0
ファイル: Extenstions.cs プロジェクト: dgarage/NDLC
 public static void WriteScript(this TLVWriter writer, Script?script)
 {
     if (script is null)
     {
         writer.WriteU16(0);
     }
     else
     {
         writer.WriteU16((ushort)script.Length);
         writer.WriteBytes(script.ToBytes(true));
     }
 }
コード例 #3
0
        public void WriteTLV(TLVWriter writer)
        {
            if (TemporaryContractId is null)
            {
                throw new InvalidOperationException($"{nameof(TemporaryContractId)} is not set");
            }
            if (TotalCollateral is null)
            {
                throw new InvalidOperationException($"{nameof(TotalCollateral)} is not set");
            }
            if (PubKeys?.FundingKey is null)
            {
                throw new InvalidOperationException($"{nameof(PubKeys.FundingKey)} is not set");
            }
            if (PubKeys?.PayoutAddress is null)
            {
                throw new InvalidOperationException($"{nameof(PubKeys.PayoutAddress)} is not set");
            }
            if (FundingInputs is null)
            {
                throw new InvalidOperationException($"{nameof(FundingInputs)} is not set");
            }
            if (ChangeAddress is null)
            {
                throw new InvalidOperationException($"{nameof(ChangeAddress)} is not set");
            }
            if (CetSigs is null)
            {
                throw new InvalidOperationException($"{nameof(CetSigs)} is not set");
            }
            writer.WriteU16(TLVType);
            writer.WriteUInt256(TemporaryContractId);
            writer.WriteU64((ulong)TotalCollateral.Satoshi);
            Span <byte> buf = stackalloc byte[64];

            PubKeys.FundingKey.Compress().ToBytes(buf, out _);
            writer.WriteBytes(buf.Slice(0, 33));
            writer.WriteScript(PubKeys.PayoutAddress.ScriptPubKey);
            writer.WriteU16((ushort)FundingInputs.Length);
            foreach (var input in FundingInputs)
            {
                input.WriteTLV(writer);
            }
            writer.WriteScript(ChangeAddress.ScriptPubKey);
            CetSigs.WriteTLV(writer);
        }
コード例 #4
0
 public void WriteTLV(TLVWriter writer)
 {
     if (OutcomeSigs is null)
     {
         throw new InvalidOperationException("OutcomeSigs is null");
     }
     if (RefundSig is null)
     {
         throw new InvalidOperationException("RefundSig is null");
     }
     using (var record = writer.StartWriteRecord(AdaptorSigsTLVType))
     {
         foreach (var sig in OutcomeSigs)
         {
             sig.WriteTLV(record);
         }
     }
     writer.WriteBytes(RefundSig.ToCompact());
 }
コード例 #5
0
        public void WriteTLV(TLVWriter writer)
        {
            if (ChainHash is null)
            {
                throw new InvalidOperationException($"{nameof(ChainHash)} is not set");
            }
            if (ContractInfo is null)
            {
                throw new InvalidOperationException($"{nameof(ContractInfo)} is not set");
            }
            if (OracleInfo is null)
            {
                throw new InvalidOperationException($"{nameof(OracleInfo)} is not set");
            }
            if (TotalCollateral is null)
            {
                throw new InvalidOperationException($"{nameof(TotalCollateral)} is not set");
            }
            if (PubKeys?.FundingKey is null)
            {
                throw new InvalidOperationException($"{nameof(PubKeys.FundingKey)} is not set");
            }
            if (PubKeys?.PayoutAddress is null)
            {
                throw new InvalidOperationException($"{nameof(PubKeys.PayoutAddress)} is not set");
            }
            if (FundingInputs is null)
            {
                throw new InvalidOperationException($"{nameof(FundingInputs)} is not set");
            }
            if (ChangeAddress is null)
            {
                throw new InvalidOperationException($"{nameof(ChangeAddress)} is not set");
            }
            if (FeeRate is null)
            {
                throw new InvalidOperationException($"{nameof(FeeRate)} is not set");
            }
            if (Timeouts is null)
            {
                throw new InvalidOperationException($"{nameof(Timeouts)} is not set");
            }
            writer.WriteU16(TLVType);
            writer.WriteByte(0);             // contract_flags
            writer.WriteUInt256(ChainHash);
            using (var ciRecord = writer.StartWriteRecord(TLVContractInfoType))
            {
                foreach (var ci in ContractInfo)
                {
                    ciRecord.WriteBytes(ci.Outcome.Hash);
                    ciRecord.WriteU64((ulong)ci.Payout.Satoshi);
                }
            }
            Span <byte> buf = stackalloc byte[64];

            using (var oracleRecord = writer.StartWriteRecord(TLVOracleInfoType))
            {
                OracleInfo.WriteToBytes(buf);
                oracleRecord.WriteBytes(buf);
            }
            PubKeys.FundingKey.Compress().ToBytes(buf, out _);
            writer.WriteBytes(buf.Slice(0, 33));
            writer.WriteScript(PubKeys.PayoutAddress.ScriptPubKey);
            writer.WriteU64((ulong)TotalCollateral.Satoshi);
            writer.WriteU16((ushort)FundingInputs.Length);
            foreach (var input in FundingInputs)
            {
                input.WriteTLV(writer);
            }
            writer.WriteScript(ChangeAddress.ScriptPubKey);
            writer.WriteU64((ulong)FeeRate.SatoshiPerByte);
            writer.WriteU32((uint)Timeouts.ContractMaturity);
            writer.WriteU32((uint)Timeouts.ContractTimeout);
        }