Update dependencies
- uses newer version of go-ethereum required for go1.11
This commit is contained in:
+1
-1
@@ -821,7 +821,7 @@ func NewEngine(scriptPubKey []byte, tx *wire.MsgTx, txIdx int, flags ScriptFlags
|
||||
}
|
||||
|
||||
// The clean stack flag (ScriptVerifyCleanStack) is not allowed without
|
||||
// either the the pay-to-script-hash (P2SH) evaluation (ScriptBip16)
|
||||
// either the pay-to-script-hash (P2SH) evaluation (ScriptBip16)
|
||||
// flag or the Segregated Witness (ScriptVerifyWitness) flag.
|
||||
//
|
||||
// Recall that evaluating a P2SH script without the flag set results in
|
||||
|
||||
+13
-2
@@ -129,9 +129,9 @@ func IsWitnessProgram(script []byte) bool {
|
||||
|
||||
// isWitnessProgram returns true if the passed script is a witness program, and
|
||||
// false otherwise. A witness program MUST adhere to the following constraints:
|
||||
// there must be excatly two pops (program version and the program itself), the
|
||||
// there must be exactly two pops (program version and the program itself), the
|
||||
// first opcode MUST be a small integer (0-16), the push data MUST be
|
||||
// cannonical, and finally the size of the push data must be between 2 and 40
|
||||
// canonical, and finally the size of the push data must be between 2 and 40
|
||||
// bytes.
|
||||
func isWitnessProgram(pops []parsedOpcode) bool {
|
||||
return len(pops) == 2 &&
|
||||
@@ -582,6 +582,17 @@ func shallowCopyTx(tx *wire.MsgTx) wire.MsgTx {
|
||||
return txCopy
|
||||
}
|
||||
|
||||
// CalcSignatureHash will, given a script and hash type for the current script
|
||||
// engine instance, calculate the signature hash to be used for signing and
|
||||
// verification.
|
||||
func CalcSignatureHash(script []byte, hashType SigHashType, tx *wire.MsgTx, idx int) ([]byte, error) {
|
||||
parsedScript, err := parseScript(script)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse output script: %v", err)
|
||||
}
|
||||
return calcSignatureHash(parsedScript, hashType, tx, idx), nil
|
||||
}
|
||||
|
||||
// calcSignatureHash will, given a script and hash type for the current script
|
||||
// engine instance, calculate the signature hash to be used for signing and
|
||||
// verification.
|
||||
|
||||
+2
-3
@@ -74,11 +74,10 @@ func WitnessSignature(tx *wire.MsgTx, sigHashes *TxSigHashes, idx int, amt int64
|
||||
func RawTxInSignature(tx *wire.MsgTx, idx int, subScript []byte,
|
||||
hashType SigHashType, key *btcec.PrivateKey) ([]byte, error) {
|
||||
|
||||
parsedScript, err := parseScript(subScript)
|
||||
hash, err := CalcSignatureHash(subScript, hashType, tx, idx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse output script: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
hash := calcSignatureHash(parsedScript, hashType, tx, idx)
|
||||
signature, err := key.Sign(hash)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot sign tx input: %s", err)
|
||||
|
||||
+38
-23
@@ -629,6 +629,7 @@ type AtomicSwapDataPushes struct {
|
||||
RecipientHash160 [20]byte
|
||||
RefundHash160 [20]byte
|
||||
SecretHash [32]byte
|
||||
SecretSize int64
|
||||
LockTime int64
|
||||
}
|
||||
|
||||
@@ -643,47 +644,61 @@ type AtomicSwapDataPushes struct {
|
||||
//
|
||||
// This function is only defined in the txscript package due to API limitations
|
||||
// which prevent callers using txscript to parse nonstandard scripts.
|
||||
func ExtractAtomicSwapDataPushes(pkScript []byte) (*AtomicSwapDataPushes, error) {
|
||||
func ExtractAtomicSwapDataPushes(version uint16, pkScript []byte) (*AtomicSwapDataPushes, error) {
|
||||
pops, err := parseScript(pkScript)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(pops) != 17 {
|
||||
if len(pops) != 20 {
|
||||
return nil, nil
|
||||
}
|
||||
isAtomicSwap := pops[0].opcode.value == OP_IF &&
|
||||
pops[1].opcode.value == OP_SHA256 &&
|
||||
pops[2].opcode.value == OP_DATA_32 &&
|
||||
pops[1].opcode.value == OP_SIZE &&
|
||||
canonicalPush(pops[2]) &&
|
||||
pops[3].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[4].opcode.value == OP_DUP &&
|
||||
pops[5].opcode.value == OP_HASH160 &&
|
||||
pops[6].opcode.value == OP_DATA_20 &&
|
||||
pops[7].opcode.value == OP_ELSE &&
|
||||
canonicalPush(pops[8]) &&
|
||||
pops[9].opcode.value == OP_CHECKLOCKTIMEVERIFY &&
|
||||
pops[10].opcode.value == OP_DROP &&
|
||||
pops[11].opcode.value == OP_DUP &&
|
||||
pops[12].opcode.value == OP_HASH160 &&
|
||||
pops[13].opcode.value == OP_DATA_20 &&
|
||||
pops[14].opcode.value == OP_ENDIF &&
|
||||
pops[15].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[16].opcode.value == OP_CHECKSIG
|
||||
pops[4].opcode.value == OP_SHA256 &&
|
||||
pops[5].opcode.value == OP_DATA_32 &&
|
||||
pops[6].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[7].opcode.value == OP_DUP &&
|
||||
pops[8].opcode.value == OP_HASH160 &&
|
||||
pops[9].opcode.value == OP_DATA_20 &&
|
||||
pops[10].opcode.value == OP_ELSE &&
|
||||
canonicalPush(pops[11]) &&
|
||||
pops[12].opcode.value == OP_CHECKLOCKTIMEVERIFY &&
|
||||
pops[13].opcode.value == OP_DROP &&
|
||||
pops[14].opcode.value == OP_DUP &&
|
||||
pops[15].opcode.value == OP_HASH160 &&
|
||||
pops[16].opcode.value == OP_DATA_20 &&
|
||||
pops[17].opcode.value == OP_ENDIF &&
|
||||
pops[18].opcode.value == OP_EQUALVERIFY &&
|
||||
pops[19].opcode.value == OP_CHECKSIG
|
||||
if !isAtomicSwap {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
pushes := new(AtomicSwapDataPushes)
|
||||
copy(pushes.SecretHash[:], pops[2].data)
|
||||
copy(pushes.RecipientHash160[:], pops[6].data)
|
||||
copy(pushes.RefundHash160[:], pops[13].data)
|
||||
if pops[8].data != nil {
|
||||
locktime, err := makeScriptNum(pops[8].data, true, 5)
|
||||
copy(pushes.SecretHash[:], pops[5].data)
|
||||
copy(pushes.RecipientHash160[:], pops[9].data)
|
||||
copy(pushes.RefundHash160[:], pops[16].data)
|
||||
if pops[2].data != nil {
|
||||
locktime, err := makeScriptNum(pops[2].data, true, 5)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
pushes.SecretSize = int64(locktime)
|
||||
} else if op := pops[2].opcode; isSmallInt(op) {
|
||||
pushes.SecretSize = int64(asSmallInt(op))
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
if pops[11].data != nil {
|
||||
locktime, err := makeScriptNum(pops[11].data, true, 5)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
pushes.LockTime = int64(locktime)
|
||||
} else if op := pops[8].opcode; isSmallInt(op) {
|
||||
} else if op := pops[11].opcode; isSmallInt(op) {
|
||||
pushes.LockTime = int64(asSmallInt(op))
|
||||
} else {
|
||||
return nil, nil
|
||||
|
||||
+3
-3
@@ -568,13 +568,13 @@ func TestCalcScriptInfo(t *testing.T) {
|
||||
// unsupported address types are handled properly.
|
||||
type bogusAddress struct{}
|
||||
|
||||
// EncodeAddress simply returns an empty string. It exists to satsify the
|
||||
// EncodeAddress simply returns an empty string. It exists to satisfy the
|
||||
// btcutil.Address interface.
|
||||
func (b *bogusAddress) EncodeAddress() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ScriptAddress simply returns an empty byte slice. It exists to satsify the
|
||||
// ScriptAddress simply returns an empty byte slice. It exists to satisfy the
|
||||
// btcutil.Address interface.
|
||||
func (b *bogusAddress) ScriptAddress() []byte {
|
||||
return nil
|
||||
@@ -585,7 +585,7 @@ func (b *bogusAddress) IsForNet(chainParams *chaincfg.Params) bool {
|
||||
return true // why not?
|
||||
}
|
||||
|
||||
// String simply returns an empty string. It exists to satsify the
|
||||
// String simply returns an empty string. It exists to satisfy the
|
||||
// btcutil.Address interface.
|
||||
func (b *bogusAddress) String() string {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user