diff --git a/database/ldb/operational_test.go b/database/ldb/operational_test.go index ad69eff271..d76466d113 100644 --- a/database/ldb/operational_test.go +++ b/database/ldb/operational_test.go @@ -15,8 +15,8 @@ import ( "testing" "github.com/btcsuite/btcd/database" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcnet" - "github.com/btcsuite/btcscript" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwire" "golang.org/x/crypto/ripemd160" @@ -110,7 +110,7 @@ func testAddrIndexOperations(t *testing.T, db database.Db, newestBlock *btcutil. } // Extract the dest addr from the tx. - _, testAddrs, _, err := btcscript.ExtractPkScriptAddrs(testTx.MsgTx().TxOut[0].PkScript, &btcnet.MainNetParams) + _, testAddrs, _, err := txscript.ExtractPkScriptAddrs(testTx.MsgTx().TxOut[0].PkScript, &btcnet.MainNetParams) if err != nil { t.Fatalf("Unable to decode tx output, err %v", err) } @@ -527,7 +527,7 @@ func TestLimitAndSkipFetchTxsForAddr(t *testing.T) { if err != nil { t.Fatalf("Unable to decode test address: %v", err) } - outputScript, err := btcscript.PayToAddrScript(targetAddr) + outputScript, err := txscript.PayToAddrScript(targetAddr) if err != nil { t.Fatalf("Unable make test pkScript %v", err) } diff --git a/docs/README.md b/docs/README.md index 78189bff87..f3a6b4b273 100644 --- a/docs/README.md +++ b/docs/README.md @@ -199,7 +199,7 @@ information. wire protocol * [btcchain](https://github.com/btcsuite/btcchain) - Implements Bitcoin block handling and chain selection rules - * [btcscript](https://github.com/btcsuite/btcscript) - Implements the + * [txscript](https://github.com/btcsuite/btcd/txscript) - Implements the Bitcoin transaction scripting language * [btcec](https://github.com/btcsuite/btcec) - Implements support for the elliptic curve cryptographic functions needed for the Bitcoin scripts diff --git a/log.go b/log.go index d127149386..ec30a31f66 100644 --- a/log.go +++ b/log.go @@ -14,8 +14,8 @@ import ( "github.com/btcsuite/btcchain" "github.com/btcsuite/btcd/database" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btclog" - "github.com/btcsuite/btcscript" "github.com/btcsuite/btcwire" "github.com/btcsuite/seelog" ) @@ -126,7 +126,7 @@ func useLogger(subsystemID string, logger btclog.Logger) { case "SCRP": scrpLog = logger - btcscript.UseLogger(logger) + txscript.UseLogger(logger) case "SRVR": srvrLog = logger diff --git a/mempool.go b/mempool.go index eb8553040b..2929b2fef4 100644 --- a/mempool.go +++ b/mempool.go @@ -15,7 +15,7 @@ import ( "github.com/btcsuite/btcchain" "github.com/btcsuite/btcd/database" - "github.com/btcsuite/btcscript" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwire" ) @@ -172,10 +172,10 @@ func isDust(txOut *btcwire.TxOut) bool { // A standard public key script is one that is a recognized form, and for // multi-signature scripts, only contains from 1 to maxStandardMultiSigKeys // public keys. -func checkPkScriptStandard(pkScript []byte, scriptClass btcscript.ScriptClass) error { +func checkPkScriptStandard(pkScript []byte, scriptClass txscript.ScriptClass) error { switch scriptClass { - case btcscript.MultiSigTy: - numPubKeys, numSigs, err := btcscript.CalcMultiSigStats(pkScript) + case txscript.MultiSigTy: + numPubKeys, numSigs, err := txscript.CalcMultiSigStats(pkScript) if err != nil { str := fmt.Sprintf("multi-signature script parse "+ "failure: %v", err) @@ -209,7 +209,7 @@ func checkPkScriptStandard(pkScript []byte, scriptClass btcscript.ScriptClass) e return txRuleError(btcwire.RejectNonstandard, str) } - case btcscript.NonStandardTy: + case txscript.NonStandardTy: return txRuleError(btcwire.RejectNonstandard, "non-standard script form") } @@ -268,7 +268,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int64) error { // Each transaction input signature script must only contain // opcodes which push data onto the stack. - if !btcscript.IsPushOnlyScript(txIn.SignatureScript) { + if !txscript.IsPushOnlyScript(txIn.SignatureScript) { str := fmt.Sprintf("transaction input %d: signature "+ "script is not push only", i) return txRuleError(btcwire.RejectNonstandard, str) @@ -278,7 +278,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int64) error { // canonical data pushes. A canonical data push is one where // the minimum possible number of bytes is used to represent // the data push as possible. - if !btcscript.HasCanonicalPushes(txIn.SignatureScript) { + if !txscript.HasCanonicalPushes(txIn.SignatureScript) { str := fmt.Sprintf("transaction input %d: signature "+ "script has a non-canonical data push", i) return txRuleError(btcwire.RejectNonstandard, str) @@ -289,7 +289,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int64) error { // be "dust" (except when the script is a null data script). numNullDataOutputs := 0 for i, txOut := range msgTx.TxOut { - scriptClass := btcscript.GetScriptClass(txOut.PkScript) + scriptClass := txscript.GetScriptClass(txOut.PkScript) err := checkPkScriptStandard(txOut.PkScript, scriptClass) if err != nil { // Attempt to extract a reject code from the error so @@ -306,7 +306,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int64) error { // Accumulate the number of outputs which only carry data. For // all other script types, ensure the output value is not // "dust". - if scriptClass == btcscript.NullDataTy { + if scriptClass == txscript.NullDataTy { numNullDataOutputs++ } else if isDust(txOut) { str := fmt.Sprintf("transaction output %d: payment "+ @@ -346,7 +346,7 @@ func checkInputsStandard(tx *btcutil.Tx, txStore btcchain.TxStore) error { originPkScript := originTx.TxOut[prevOut.Index].PkScript // Calculate stats for the script pair. - scriptInfo, err := btcscript.CalcScriptInfo(txIn.SignatureScript, + scriptInfo, err := txscript.CalcScriptInfo(txIn.SignatureScript, originPkScript, true) if err != nil { str := fmt.Sprintf("transaction input #%d script parse "+ diff --git a/mining.go b/mining.go index 34fa0bf92d..699ab01c37 100644 --- a/mining.go +++ b/mining.go @@ -12,7 +12,7 @@ import ( "github.com/btcsuite/btcchain" "github.com/btcsuite/btcd/database" - "github.com/btcsuite/btcscript" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwire" ) @@ -46,10 +46,10 @@ const ( // allow pay-to-script hash transactions. Note these flags are // different than what is required for the consensus rules in that they // are more strict. - standardScriptVerifyFlags = btcscript.ScriptBip16 | - btcscript.ScriptCanonicalSignatures | - btcscript.ScriptStrictMultiSig | - btcscript.ScriptDiscourageUpgradableNops + standardScriptVerifyFlags = txscript.ScriptBip16 | + txscript.ScriptCanonicalSignatures | + txscript.ScriptStrictMultiSig | + txscript.ScriptDiscourageUpgradableNops ) // txPrioItem houses a transaction along with extra information that allows the @@ -202,7 +202,7 @@ func mergeTxStore(txStoreA btcchain.TxStore, txStoreB btcchain.TxStore) { // it starts with the block height that is required by version 2 blocks and adds // the extra nonce as well as additional coinbase flags. func standardCoinbaseScript(nextBlockHeight int64, extraNonce uint64) ([]byte, error) { - return btcscript.NewScriptBuilder().AddInt64(nextBlockHeight). + return txscript.NewScriptBuilder().AddInt64(nextBlockHeight). AddUint64(extraNonce).AddData([]byte(coinbaseFlags)).Script() } @@ -219,14 +219,14 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int64, addr btcutil var pkScript []byte if addr != nil { var err error - pkScript, err = btcscript.PayToAddrScript(addr) + pkScript, err = txscript.PayToAddrScript(addr) if err != nil { return nil, err } } else { var err error - scriptBuilder := btcscript.NewScriptBuilder() - pkScript, err = scriptBuilder.AddOp(btcscript.OP_TRUE).Script() + scriptBuilder := txscript.NewScriptBuilder() + pkScript, err = scriptBuilder.AddOp(txscript.OP_TRUE).Script() if err != nil { return nil, err } diff --git a/rpcserver.go b/rpcserver.go index a1a000edc7..2c2bc4cf40 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -28,10 +28,10 @@ import ( "github.com/btcsuite/btcchain" "github.com/btcsuite/btcd/database" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcec" "github.com/btcsuite/btcjson" "github.com/btcsuite/btcnet" - "github.com/btcsuite/btcscript" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwire" "github.com/btcsuite/btcws" @@ -92,7 +92,7 @@ var ( // overhead of creating a new object on every invocation for constant // data. gbtCoinbaseAux = &btcjson.GetBlockTemplateResultAux{ - Flags: hex.EncodeToString(builderScript(btcscript. + Flags: hex.EncodeToString(builderScript(txscript. NewScriptBuilder().AddData([]byte(coinbaseFlags)))), } @@ -214,7 +214,7 @@ var rpcUnimplemented = map[string]struct{}{} // scripts built with the script builder. Any errors are converted to a panic // since it is only, and must only, be used with hard-coded, and therefore, // known good, scripts. -func builderScript(builder *btcscript.ScriptBuilder) []byte { +func builderScript(builder *txscript.ScriptBuilder) []byte { script, err := builder.Script() if err != nil { panic(err) @@ -805,7 +805,7 @@ func handleCreateRawTransaction(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan } // Create a new script which pays to the provided address. - pkScript, err := btcscript.PayToAddrScript(addr) + pkScript, err := txscript.PayToAddrScript(addr) if err != nil { return nil, btcjson.Error{ Code: btcjson.ErrInternal.Code, @@ -861,7 +861,7 @@ func createVinList(mtx *btcwire.MsgTx) []btcjson.Vin { // The disassembled string will contain [error] inline // if the script doesn't fully parse, so ignore the // error here. - disbuf, _ := btcscript.DisasmString(v.SignatureScript) + disbuf, _ := txscript.DisasmString(v.SignatureScript) vinList[i].ScriptSig = new(btcjson.ScriptSig) vinList[i].ScriptSig.Asm = disbuf vinList[i].ScriptSig.Hex = hex.EncodeToString(v.SignatureScript) @@ -882,14 +882,14 @@ func createVoutList(mtx *btcwire.MsgTx, net *btcnet.Params) []btcjson.Vout { // The disassembled string will contain [error] inline if the // script doesn't fully parse, so ignore the error here. - disbuf, _ := btcscript.DisasmString(v.PkScript) + disbuf, _ := txscript.DisasmString(v.PkScript) voutList[i].ScriptPubKey.Asm = disbuf voutList[i].ScriptPubKey.Hex = hex.EncodeToString(v.PkScript) // Ignore the error here since an error means the script // couldn't parse and there is no additional information about // it anyways. - scriptClass, addrs, reqSigs, _ := btcscript.ExtractPkScriptAddrs(v.PkScript, net) + scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(v.PkScript, net) voutList[i].ScriptPubKey.Type = scriptClass.String() voutList[i].ScriptPubKey.ReqSigs = int32(reqSigs) @@ -998,13 +998,13 @@ func handleDecodeScript(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{} // The disassembled string will contain [error] inline if the script // doesn't fully parse, so ignore the error here. - disbuf, _ := btcscript.DisasmString(script) + disbuf, _ := txscript.DisasmString(script) // Get information about the script. // Ignore the error here since an error means the script couldn't parse // and there is no additinal information about it anyways. net := s.server.netParams - scriptClass, addrs, reqSigs, _ := btcscript.ExtractPkScriptAddrs(script, net) + scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script, net) addresses := make([]string, len(addrs)) for i, addr := range addrs { addresses[i] = addr.EncodeAddress() @@ -1512,7 +1512,7 @@ func (state *gbtWorkState) updateBlockTemplate(s *rpcServer, useCoinbaseValue bo // Update the block coinbase output of the template to // pay to the randomly selected payment address. - pkScript, err := btcscript.PayToAddrScript(payToAddr) + pkScript, err := txscript.PayToAddrScript(payToAddr) if err != nil { return btcjson.Error{ Code: btcjson.ErrInternal.Code, @@ -2519,13 +2519,13 @@ func handleGetTxOut(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{}) (i // The disassembled string will contain [error] inline if the script // doesn't fully parse, so ignore the error here. script := txOut.PkScript - disbuf, _ := btcscript.DisasmString(script) + disbuf, _ := txscript.DisasmString(script) // Get further info about the script. // Ignore the error here since an error means the script couldn't parse // and there is no additional information about it anyways. net := s.server.netParams - scriptClass, addrs, reqSigs, _ := btcscript.ExtractPkScriptAddrs(script, net) + scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script, net) addresses := make([]string, len(addrs)) for i, addr := range addrs { addresses[i] = addr.EncodeAddress() diff --git a/rpcwebsocket.go b/rpcwebsocket.go index f084195853..d86fe0bb98 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -20,8 +20,8 @@ import ( "golang.org/x/crypto/ripemd160" "github.com/btcsuite/btcd/database" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcjson" - "github.com/btcsuite/btcscript" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwire" "github.com/btcsuite/btcws" @@ -624,7 +624,7 @@ func (m *wsNotificationManager) notifyForTxOuts(ops map[btcwire.OutPoint]map[cha txHex := "" wscNotified := make(map[chan struct{}]struct{}) for i, txOut := range tx.MsgTx().TxOut { - _, txAddrs, _, err := btcscript.ExtractPkScriptAddrs( + _, txAddrs, _, err := txscript.ExtractPkScriptAddrs( txOut.PkScript, m.server.server.netParams) if err != nil { continue @@ -1512,7 +1512,7 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *btcutil.Block) { } for txOutIdx, txout := range tx.MsgTx().TxOut { - _, addrs, _, _ := btcscript.ExtractPkScriptAddrs( + _, addrs, _, _ := txscript.ExtractPkScriptAddrs( txout.PkScript, wsc.server.server.netParams) for _, addr := range addrs {