diff --git a/sidecar/codec_test.go b/sidecar/codec_test.go index fc27076..5074976 100644 --- a/sidecar/codec_test.go +++ b/sidecar/codec_test.go @@ -9,15 +9,15 @@ import ( ) var ( - hardcodedTicket = "sidecarAAQgHBgUEAwIBAAIBYwMBAgp5CwgAAAAAAAADCQwIAA" + - "AAAAAAA3gNIQLVLm5gAB7Vh7eEvz8Y3CkF2DsvNuSWJj8oOxp1iSh5xw5AAA" + - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAAAAAAAAAA" + - "AAAAAAAAAAAAAAAAAAAAAAFhRGFSEC1S5uYAAe1Ye3hL8_GNwpBdg7Lzbkli" + - "Y_KDsadYkoeccWIQMZ1hb2o3OyT-XUX7KWS-pAVBloIPQe8aCTqcjiNOV89x" + - "5kHyALFiEsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACBAAAAAAAAAAA" + - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGMAAAAAAAAAAAAAAAAAAAAAAAAAAA" + - "AAAAAAAAAAAAAAISgiKSBjWE0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + - "AAAA3VE-c=" + hardcodedTicket = "sidecarAAQgHBgUEAwIBAAIBYwMBAgp_CwgAAAAAAAADCQwIAA" + + "AAAAAAA3gNBAAAB-AOIQLVLm5gAB7Vh7eEvz8Y3CkF2DsvNuSWJj8oOxp1iS" + + "h5xw9AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhRMFSEC1S5uYAAe1Ye3hL8_GNwpBd" + + "g7LzbkliY_KDsadYkoeccWIQMZ1hb2o3OyT-XUX7KWS-pAVBloIPQe8aCTqc" + + "jiNOV89xcEAAAAAB5kHyALFiEsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + + "AAACBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGMAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAISgiKSBjWE0AAAAAAAAAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAAAHcU6Y4=" ) // TestEncodeDecode tests that a ticket can be encoded and decoded from/to a @@ -29,9 +29,10 @@ func TestEncodeDecode(t *testing.T) { Version: Version(99), State: StateRegistered, Offer: Offer{ - Capacity: 777, - PushAmt: 888, - SignPubKey: testPubKey, + Capacity: 777, + PushAmt: 888, + LeaseDurationBlocks: 2016, + SignPubKey: testPubKey, SigOfferDigest: &btcec.Signature{ R: new(big.Int).SetInt64(44), S: new(big.Int).SetInt64(22), diff --git a/sidecar/interface.go b/sidecar/interface.go index 9e49ad6..e0a7f85 100644 --- a/sidecar/interface.go +++ b/sidecar/interface.go @@ -102,6 +102,10 @@ type Offer struct { // reduce the matching chances somewhat. PushAmt btcutil.Amount + // LeaseDurationBlocks is the number of blocks the offered channel in + // this offer would be leased for. + LeaseDurationBlocks uint32 + // SignPubKey is the public key for corresponding to the private key // that signed the SigOfferDigest below and, in a later state, the // SigOrderDigest of the Order struct. @@ -124,6 +128,9 @@ type Recipient struct { // multisig keys of the channel funding transaction output and is // advertised in the bid order. MultiSigPubKey *btcec.PublicKey + + // MultiSigKeyIndex is the derivation index of the MultiSigPubKey. + MultiSigKeyIndex uint32 } // Order is a struct holding the information about the sidecar bid order after @@ -189,15 +196,16 @@ type Ticket struct { // NewTicket creates a new sidecar ticket with the given version and offer // information. func NewTicket(version Version, capacity, pushAmt btcutil.Amount, - offerPubKey *btcec.PublicKey) (*Ticket, error) { + duration uint32, offerPubKey *btcec.PublicKey) (*Ticket, error) { t := &Ticket{ Version: version, State: StateOffered, Offer: Offer{ - Capacity: capacity, - PushAmt: pushAmt, - SignPubKey: offerPubKey, + Capacity: capacity, + PushAmt: pushAmt, + LeaseDurationBlocks: duration, + SignPubKey: offerPubKey, }, } diff --git a/sidecar/tlv.go b/sidecar/tlv.go index 21304ea..2724e79 100644 --- a/sidecar/tlv.go +++ b/sidecar/tlv.go @@ -19,12 +19,14 @@ const ( offerType tlv.Type = 10 capacityType tlv.Type = 11 pushAmtType tlv.Type = 12 - signPubKeyType tlv.Type = 13 - sigOfferDigestType tlv.Type = 14 + leaseDurationType tlv.Type = 13 + signPubKeyType tlv.Type = 14 + sigOfferDigestType tlv.Type = 15 - recipientType tlv.Type = 20 - nodePubKeyType tlv.Type = 21 - multiSigPubKeyType tlv.Type = 22 + recipientType tlv.Type = 20 + nodePubKeyType tlv.Type = 21 + multiSigPubKeyType tlv.Type = 22 + multiSigKeyIndexType tlv.Type = 23 orderType tlv.Type = 30 bidNonceType tlv.Type = 31 @@ -177,6 +179,9 @@ func serializeOffer(o Offer) ([]byte, error) { tlvRecords := []tlv.Record{ tlv.MakePrimitiveRecord(capacityType, &capacity), tlv.MakePrimitiveRecord(pushAmtType, &pushAmt), + tlv.MakePrimitiveRecord( + leaseDurationType, &o.LeaseDurationBlocks, + ), } if o.SignPubKey != nil { @@ -206,6 +211,9 @@ func deserializeOffer(offerBytes []byte) (Offer, error) { offerBytes, tlv.MakePrimitiveRecord(capacityType, &capacity), tlv.MakePrimitiveRecord(pushAmtType, &pushAmt), + tlv.MakePrimitiveRecord( + leaseDurationType, &o.LeaseDurationBlocks, + ), tlv.MakePrimitiveRecord(signPubKeyType, &o.SignPubKey), tlv.MakeStaticRecord( sigOfferDigestType, &o.SigOfferDigest, 64, ESig, DSig, @@ -236,6 +244,10 @@ func serializeRecipient(r Recipient) ([]byte, error) { )) } + tlvRecords = append(tlvRecords, tlv.MakePrimitiveRecord( + multiSigKeyIndexType, &r.MultiSigKeyIndex, + )) + return encodeBytes(tlvRecords...) } @@ -247,6 +259,9 @@ func deserializeRecipient(recipientBytes []byte) (Recipient, error) { recipientBytes, tlv.MakePrimitiveRecord(nodePubKeyType, &r.NodePubKey), tlv.MakePrimitiveRecord(multiSigPubKeyType, &r.MultiSigPubKey), + tlv.MakePrimitiveRecord( + multiSigKeyIndexType, &r.MultiSigKeyIndex, + ), ) }