Exemplo n.º 1
0
 public void WriteTLV(TLVWriter writer)
 {
     if (ContractId is null)
     {
         throw new InvalidOperationException("ContractId is not set");
     }
     if (CetSigs is null)
     {
         throw new InvalidOperationException("CetSigs is not set");
     }
     if (FundingSigs is null)
     {
         throw new InvalidOperationException("FundingSigs is not set");
     }
     writer.WriteU16(TLVType);
     writer.WriteUInt256(ContractId);
     CetSigs.WriteTLV(writer);
     using (var w = writer.StartWriteRecord(FundingSignaturesTLVType))
     {
         w.WriteU16(FundingSigs.Count);
         foreach (var s in FundingSigs)
         {
             w.WriteU16(s.PushCount);
             for (int i = 0; i < s.PushCount; i++)
             {
                 var p = s.GetUnsafePush(i);
                 w.WriteU16(p.Length);
                 w.WriteBytes(p);
             }
         }
     }
 }
Exemplo n.º 2
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());
 }
Exemplo n.º 3
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);
        }