mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
add testing sighash folder
This commit is contained in:
parent
d8e62f6898
commit
233ec9538c
3
.gitignore
vendored
3
.gitignore
vendored
@ -33,6 +33,9 @@ cmd/cmd
|
||||
cmd/lncli/lncli
|
||||
cmd/lnshell/lnshell
|
||||
|
||||
sighash143/sighash143
|
||||
sighash143/*.hex
|
||||
|
||||
test_wal/*
|
||||
|
||||
# vim
|
||||
|
91
sighash143/sighash143.go
Normal file
91
sighash143/sighash143.go
Normal file
@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/uspv"
|
||||
)
|
||||
|
||||
const (
|
||||
inspk0 = "2103c9f4836b9a4f77fc0d81f7bcb01b7f1b35916864b9476c241ce9fc198bd25432ac"
|
||||
inamt0 = uint64(625000000)
|
||||
|
||||
inspk1 = "00141d0f172a0ecb48aee1be1f2687d2963ae33f71a1"
|
||||
inamt1 = uint64(600000000)
|
||||
)
|
||||
|
||||
func outpointBytesLil(op wire.OutPoint) []byte {
|
||||
var buf bytes.Buffer
|
||||
// ignore errors because.. whatever
|
||||
_ = binary.Write(&buf, binary.LittleEndian, op.Index)
|
||||
|
||||
b := op.Hash[:]
|
||||
return append(b, buf.Bytes()...)
|
||||
}
|
||||
|
||||
func calcSignatureHash(
|
||||
hashType txscript.SigHashType, tx *wire.MsgTx, idx int) []byte {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// if sighash_ALL, hash of all txin outpoints, sequentially.
|
||||
// if other sighash type, 0x00 * 32
|
||||
func calcHashPrevOuts(tx *wire.MsgTx) [32]byte {
|
||||
|
||||
for _, in := range tx.TxIn {
|
||||
// in.PreviousOutPoint.Hash
|
||||
}
|
||||
|
||||
return wire.DoubleSha256SH(tx.TxIn[0].SignatureScript)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("sighash 143\n")
|
||||
|
||||
// get previous pkscripts for inputs 0 and 1 from hex
|
||||
in0spk, err := hex.DecodeString(string(inspk0))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
in1spk, err := hex.DecodeString(string(inspk1))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// load tx skeleton from local file
|
||||
fmt.Printf("loading tx from file tx.hex\n")
|
||||
txhex, err := ioutil.ReadFile("tx.hex")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
txhex = []byte(strings.TrimSpace(string(txhex)))
|
||||
txbytes, err := hex.DecodeString(string(txhex))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("loaded %d byte tx %x\n", len(txbytes), txbytes)
|
||||
|
||||
// make tx
|
||||
ttx := wire.NewMsgTx()
|
||||
|
||||
// deserialize into tx
|
||||
buf := bytes.NewBuffer(txbytes)
|
||||
ttx.Deserialize(buf)
|
||||
|
||||
ttx.TxIn[0].SignatureScript = in0spk
|
||||
ttx.TxIn[1].SignatureScript = in1spk
|
||||
|
||||
fmt.Printf(uspv.TxToString(ttx))
|
||||
|
||||
}
|
@ -226,6 +226,7 @@ func (s *SPVCon) SendCoins(adr btcutil.Address, sendAmt int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SignThis isn't used anymore...
|
||||
func (t *TxStore) SignThis(tx *wire.MsgTx) error {
|
||||
fmt.Printf("-= SignThis =-\n")
|
||||
|
||||
|
@ -185,6 +185,20 @@ func outPointToBytes(op *wire.OutPoint) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
/*----- serialization for utxos ------- */
|
||||
/* Utxos serialization:
|
||||
byte length desc at offset
|
||||
|
||||
32 txid 0
|
||||
4 idx 32
|
||||
4 height 36
|
||||
4 keyidx 40
|
||||
8 amt 44
|
||||
1 flag 52
|
||||
|
||||
end len 53
|
||||
*/
|
||||
|
||||
// ToBytes turns a Utxo into some bytes.
|
||||
// note that the txid is the first 36 bytes and in our use cases will be stripped
|
||||
// off, but is left here for other applications
|
||||
@ -278,6 +292,17 @@ func UtxoFromBytes(b []byte) (Utxo, error) {
|
||||
return u, nil
|
||||
}
|
||||
|
||||
/*----- serialization for stxos ------- */
|
||||
/* Stxo serialization:
|
||||
byte length desc at offset
|
||||
|
||||
53 utxo 0
|
||||
4 sheight 53
|
||||
32 stxid 57
|
||||
|
||||
end len 89
|
||||
*/
|
||||
|
||||
// ToBytes turns an Stxo into some bytes.
|
||||
// prevUtxo serialization, then spendheight [4], spendtxid [32]
|
||||
func (s *Stxo) ToBytes() ([]byte, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user