github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/watchtower/serdes.go (about)

     1  package watchtower
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/mit-dci/lit/lnutil"
     7  )
     8  
     9  // IdxSigs are 74 bytes
    10  // PKHIdx 4
    11  // StateIdx 6
    12  // Sig 64
    13  
    14  // no idxSig to bytes function -- done inline in the addMsg db call
    15  
    16  func IdxSigFromBytes(b []byte) (*IdxSig, error) {
    17  	var s IdxSig
    18  	if len(b) != 74 {
    19  		return nil, fmt.Errorf("IdxSigFromBytes got %d bytes, expect 74", len(b))
    20  	}
    21  	s.PKHIdx = lnutil.BtU32(b[:4])
    22  	// kindof ugly but fast; need 8 bytes, so give invalid high 2 bytes
    23  	// then set them to 0 after we've cast to uint64
    24  	s.StateIdx = lnutil.BtU64(b[2:10])
    25  	s.StateIdx &= 0x0000ffffffffffff
    26  	copy(s.Sig[:], b[10:])
    27  	return &s, nil
    28  }
    29  
    30  //type IdxSig struct {
    31  //	PKHIdx   uint32
    32  //	StateIdx uint64
    33  //	Sig      [64]byte
    34  //}