Changed type in Accept/Complete & lnwire refactor
* FundingSignAccept and FundingSingComplete had *[]btcec.Signature and instead it's now []*btcec.Signature to match other slice types. * Refactored lnwire's when doing readElement/writeElement on slices
This commit is contained in:
parent
2d3253b95d
commit
266c121510
@ -10,7 +10,7 @@ type FundingSignAccept struct {
|
|||||||
ReservationID uint64
|
ReservationID uint64
|
||||||
|
|
||||||
CommitSig *btcec.Signature //Requester's Commitment
|
CommitSig *btcec.Signature //Requester's Commitment
|
||||||
FundingTXSigs *[]btcec.Signature
|
FundingTXSigs []*btcec.Signature
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FundingSignAccept) Decode(r io.Reader, pver uint32) error {
|
func (c *FundingSignAccept) Decode(r io.Reader, pver uint32) error {
|
||||||
@ -71,9 +71,9 @@ func (c *FundingSignAccept) Validate() error {
|
|||||||
|
|
||||||
func (c *FundingSignAccept) String() string {
|
func (c *FundingSignAccept) String() string {
|
||||||
var sigs string
|
var sigs string
|
||||||
for i, in := range *c.FundingTXSigs {
|
for i, in := range c.FundingTXSigs {
|
||||||
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
|
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
|
||||||
if &in != nil && in.R != nil {
|
if in != nil {
|
||||||
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
|
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ var (
|
|||||||
fundingSignAccept = &FundingSignAccept{
|
fundingSignAccept = &FundingSignAccept{
|
||||||
ReservationID: uint64(12345678),
|
ReservationID: uint64(12345678),
|
||||||
CommitSig: commitSig,
|
CommitSig: commitSig,
|
||||||
FundingTXSigs: &fundingTXSigs,
|
FundingTXSigs: ptrFundingTXSigs,
|
||||||
}
|
}
|
||||||
fundingSignAcceptSerializedString = "0000000000bc614e4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
fundingSignAcceptSerializedString = "0000000000bc614e4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
||||||
fundingSignAcceptSerializedMessage = "0709110b000000dc000000df0000000000bc614e4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
fundingSignAcceptSerializedMessage = "0709110b000000dc000000df0000000000bc614e4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
||||||
|
@ -11,7 +11,7 @@ type FundingSignComplete struct {
|
|||||||
ReservationID uint64
|
ReservationID uint64
|
||||||
|
|
||||||
TxID *wire.ShaHash
|
TxID *wire.ShaHash
|
||||||
FundingTXSigs *[]btcec.Signature
|
FundingTXSigs []*btcec.Signature
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
||||||
@ -71,9 +71,9 @@ func (c *FundingSignComplete) Validate() error {
|
|||||||
|
|
||||||
func (c *FundingSignComplete) String() string {
|
func (c *FundingSignComplete) String() string {
|
||||||
var sigs string
|
var sigs string
|
||||||
for i, in := range *c.FundingTXSigs {
|
for i, in := range c.FundingTXSigs {
|
||||||
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
|
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
|
||||||
if &in != nil && in.R != nil {
|
if in != nil {
|
||||||
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
|
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ var (
|
|||||||
fundingSignComplete = &FundingSignComplete{
|
fundingSignComplete = &FundingSignComplete{
|
||||||
ReservationID: uint64(12345678),
|
ReservationID: uint64(12345678),
|
||||||
TxID: txid,
|
TxID: txid,
|
||||||
FundingTXSigs: &fundingTXSigs,
|
FundingTXSigs: ptrFundingTXSigs,
|
||||||
}
|
}
|
||||||
fundingSignCompleteSerializedString = "0000000000bc614efd95c6e5c9d5bcf9cfc7231b6a438e46c518c724d0b04b75cc8fddf84a254e3a02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
fundingSignCompleteSerializedString = "0000000000bc614efd95c6e5c9d5bcf9cfc7231b6a438e46c518c724d0b04b75cc8fddf84a254e3a02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
||||||
fundingSignCompleteSerializedMessage = "0709110b000000e6000000b80000000000bc614efd95c6e5c9d5bcf9cfc7231b6a438e46c518c724d0b04b75cc8fddf84a254e3a02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
fundingSignCompleteSerializedMessage = "0709110b000000e6000000b80000000000bc614efd95c6e5c9d5bcf9cfc7231b6a438e46c518c724d0b04b75cc8fddf84a254e3a02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
||||||
|
@ -66,8 +66,8 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case *[]btcec.Signature:
|
case []*btcec.Signature:
|
||||||
numSigs := len(*e)
|
numSigs := len(e)
|
||||||
if numSigs > 127 {
|
if numSigs > 127 {
|
||||||
return fmt.Errorf("Too many signatures!")
|
return fmt.Errorf("Too many signatures!")
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
}
|
}
|
||||||
//Write the data
|
//Write the data
|
||||||
for i := 0; i < numSigs; i++ {
|
for i := 0; i < numSigs; i++ {
|
||||||
err = writeElement(w, &(*e)[i])
|
err = writeElement(w, e[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -151,22 +151,29 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
//Append the actual TxIns (Size: NumOfTxins * 36)
|
//Append the actual TxIns (Size: NumOfTxins * 36)
|
||||||
//Do not include the sequence number to eliminate funny business
|
//Do not include the sequence number to eliminate funny business
|
||||||
for _, in := range e {
|
for _, in := range e {
|
||||||
//Hash
|
err = writeElement(w, in)
|
||||||
var h [32]byte
|
|
||||||
copy(h[:], in.PreviousOutPoint.Hash.Bytes())
|
|
||||||
_, err = w.Write(h[:])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
//Index
|
|
||||||
var idx [4]byte
|
|
||||||
binary.BigEndian.PutUint32(idx[:], in.PreviousOutPoint.Index)
|
|
||||||
_, err = w.Write(idx[:])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
case *wire.TxIn:
|
||||||
|
//Hash
|
||||||
|
var h [32]byte
|
||||||
|
copy(h[:], e.PreviousOutPoint.Hash.Bytes())
|
||||||
|
_, err = w.Write(h[:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
//Index
|
||||||
|
var idx [4]byte
|
||||||
|
binary.BigEndian.PutUint32(idx[:], e.PreviousOutPoint.Index)
|
||||||
|
_, err = w.Write(idx[:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown type in writeElement: %T", e)
|
return fmt.Errorf("Unknown type in writeElement: %T", e)
|
||||||
}
|
}
|
||||||
@ -239,7 +246,7 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
}
|
}
|
||||||
*e = &*x
|
*e = &*x
|
||||||
return nil
|
return nil
|
||||||
case **[]btcec.Signature:
|
case *[]*btcec.Signature:
|
||||||
var numSigs uint8
|
var numSigs uint8
|
||||||
err = readElement(r, &numSigs)
|
err = readElement(r, &numSigs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -250,16 +257,16 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Read that number of signatures
|
//Read that number of signatures
|
||||||
var sigs []btcec.Signature
|
var sigs []*btcec.Signature
|
||||||
for i := uint8(0); i < numSigs; i++ {
|
for i := uint8(0); i < numSigs; i++ {
|
||||||
sig := new(btcec.Signature)
|
sig := new(btcec.Signature)
|
||||||
err = readElement(r, &sig)
|
err = readElement(r, &sig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sigs = append(sigs, *sig)
|
sigs = append(sigs, sig)
|
||||||
}
|
}
|
||||||
*e = &sigs
|
*e = *&sigs
|
||||||
return nil
|
return nil
|
||||||
case **btcec.Signature:
|
case **btcec.Signature:
|
||||||
var sigLength uint8
|
var sigLength uint8
|
||||||
@ -337,29 +344,36 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
//Append the actual TxIns
|
//Append the actual TxIns
|
||||||
var txins []*wire.TxIn
|
var txins []*wire.TxIn
|
||||||
for i := uint8(0); i < numScripts; i++ {
|
for i := uint8(0); i < numScripts; i++ {
|
||||||
//Hash
|
outpoint := new(wire.OutPoint)
|
||||||
var h [32]byte
|
txin := wire.NewTxIn(outpoint, nil)
|
||||||
_, err = io.ReadFull(r, h[:])
|
err = readElement(r, &txin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
shaHash, err := wire.NewShaHash(h[:])
|
txins = append(txins, txin)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
//Index
|
|
||||||
var idxBytes [4]byte
|
|
||||||
_, err = io.ReadFull(r, idxBytes[:])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
index := binary.BigEndian.Uint32(idxBytes[:])
|
|
||||||
outPoint := wire.NewOutPoint(shaHash, index)
|
|
||||||
txins = append(txins, wire.NewTxIn(outPoint, nil))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*e = *&txins
|
*e = *&txins
|
||||||
return nil
|
return nil
|
||||||
|
case **wire.TxIn:
|
||||||
|
//Hash
|
||||||
|
var h [32]byte
|
||||||
|
_, err = io.ReadFull(r, h[:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hash, err := wire.NewShaHash(h[:])
|
||||||
|
(*e).PreviousOutPoint.Hash = *hash
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
//Index
|
||||||
|
var idxBytes [4]byte
|
||||||
|
_, err = io.ReadFull(r, idxBytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
(*e).PreviousOutPoint.Index = binary.BigEndian.Uint32(idxBytes[:])
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown type in readElement: %T", e)
|
return fmt.Errorf("Unknown type in readElement: %T", e)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ var (
|
|||||||
sigStr2, _ = txscript.RawTxInSignature(tx, 0, *emptybytes, txscript.SigHashAll, sig2privKey)
|
sigStr2, _ = txscript.RawTxInSignature(tx, 0, *emptybytes, txscript.SigHashAll, sig2privKey)
|
||||||
commitSig2, _ = btcec.ParseSignature(sigStr2, btcec.S256())
|
commitSig2, _ = btcec.ParseSignature(sigStr2, btcec.S256())
|
||||||
//Slice of Funding TX Sigs
|
//Slice of Funding TX Sigs
|
||||||
fundingTXSigs = append(*new([]btcec.Signature), *commitSig1, *commitSig2)
|
ptrFundingTXSigs = append(*new([]*btcec.Signature), commitSig1, commitSig2)
|
||||||
|
|
||||||
//TxID
|
//TxID
|
||||||
txid = new(wire.ShaHash)
|
txid = new(wire.ShaHash)
|
||||||
|
Loading…
Reference in New Issue
Block a user