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); }
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() }; }