예제 #1
0
        public static CetSigs ParseFromTLV(TLVReader reader)
        {
            CetSigs cet = new CetSigs();

            using (var r = reader.StartReadRecord())
            {
                if (r.Type != AdaptorSigsTLVType)
                {
                    throw new FormatException("Invalid TLV type, expected adaptor sigs");
                }
                List <AdaptorSignature> sigs = new List <AdaptorSignature>();
                while (!r.IsEnd)
                {
                    sigs.Add(AdaptorSignature.ParseFromTLV(reader));
                }
                cet.OutcomeSigs = sigs.ToArray();
            }
            Span <byte> buf = stackalloc byte[64];

            reader.ReadBytes(buf);
            if (!ECDSASignature.TryParseFromCompact(buf, out var sig))
            {
                throw new FormatException("Invalid DER signature");
            }
            cet.RefundSig = sig;
            return(cet);
        }
예제 #2
0
파일: Extenstions.cs 프로젝트: dgarage/NDLC
        public static Script ReadScript(this TLVReader reader)
        {
            var size = reader.ReadU16();
            var buf  = new byte[size];

            reader.ReadBytes(buf);
            return(Script.FromBytesUnsafe(buf));
        }
예제 #3
0
        public static AdaptorSignature ParseFromTLV(TLVReader reader)
        {
            Span <byte> output = stackalloc byte[65 + 97];

            reader.ReadBytes(output);
            if (!SecpECDSAAdaptorSignature.TryCreate(output.Slice(0, 65), out var sig))
            {
                throw new FormatException("Invalid adaptor signature");
            }
            if (!SecpECDSAAdaptorProof.TryCreate(output.Slice(65), out var proof))
            {
                throw new FormatException("Invalid adaptor proof");
            }
            return(new AdaptorSignature(sig, proof));
        }
예제 #4
0
        public void ReadTLV(TLVReader reader, Network network)
        {
            if (reader.ReadU16() != TLVType)
            {
                throw new FormatException("Invalid TLV type for accept");
            }
            TemporaryContractId = reader.ReadUInt256();
            TotalCollateral     = Money.Satoshis(reader.ReadU64());
            PubKeys             = new PubKeyObject();
            var pk = new byte[33];

            reader.ReadBytes(pk);
            PubKeys.FundingKey    = new PubKey(pk, true);
            PubKeys.PayoutAddress = reader.ReadScript().GetDestinationAddress(network);
            var inputLen = reader.ReadU16();

            FundingInputs = new FundingInput[inputLen];
            for (int i = 0; i < inputLen; i++)
            {
                FundingInputs[i] = FundingInput.ParseFromTLV(reader, network);
            }
            ChangeAddress = reader.ReadScript().GetDestinationAddress(network);
            CetSigs       = CetSigs.ParseFromTLV(reader);
        }
예제 #5
0
        public void ReadTLV(TLVReader reader, Network network)
        {
            if (reader.ReadU16() != TLVType)
            {
                throw new FormatException("Invalid TLV type for offer");
            }
            reader.ReadByte();             // contract_flags
            ChainHash = reader.ReadUInt256();
            if (network.GenesisHash != network.GenesisHash)
            {
                throw new FormatException("Invalid ChainHash");
            }
            Span <byte> buf = stackalloc byte[64];

            using (var ciRecord = reader.StartReadRecord())
            {
                if (ciRecord.Type != TLVContractInfoType)
                {
                    throw new FormatException("Invalid TLV type for contract info");
                }
                List <ContractInfo> cis = new List <ContractInfo>();
                while (!ciRecord.IsEnd)
                {
                    ciRecord.ReadBytes(buf.Slice(0, 32));
                    var sats = ciRecord.ReadU64();
                    cis.Add(new Messages.ContractInfo(new DiscreteOutcome(buf.Slice(0, 32).ToArray()), Money.Satoshis(sats)));
                }
                ContractInfo = cis.ToArray();
            }
            using (var oracleRecord = reader.StartReadRecord())
            {
                if (oracleRecord.Type != TLVOracleInfoType)
                {
                    throw new FormatException("Invalid TLV type for oracle info");
                }
                oracleRecord.ReadBytes(buf.Slice(0, 64));
                OracleInfo = OracleInfo.Create(buf);
            }
            PubKeys = new PubKeyObject();
            reader.ReadBytes(buf.Slice(0, 33));
            PubKeys.FundingKey    = new PubKey(buf.Slice(0, 33).ToArray());
            PubKeys.PayoutAddress = reader.ReadScript().GetDestinationAddress(network);
            if (PubKeys.PayoutAddress is null)
            {
                throw new FormatException("Invalid script");
            }
            TotalCollateral = Money.Satoshis(reader.ReadU64());
            var fiCount             = reader.ReadU16();
            List <FundingInput> fis = new List <FundingInput>();

            while (fiCount > 0)
            {
                fis.Add(FundingInput.ParseFromTLV(reader, network));
                fiCount--;
            }
            FundingInputs = fis.ToArray();
            ChangeAddress = reader.ReadScript().GetDestinationAddress(network);
            if (ChangeAddress is null)
            {
                throw new FormatException("Invalid script");
            }
            FeeRate  = new FeeRate(Money.Satoshis(reader.ReadU64()), 1);
            Timeouts = new Timeouts()
            {
                ContractMaturity = reader.ReadU32(),
                ContractTimeout  = reader.ReadU32()
            };
        }