Update for recent ScriptBuilder API change.

This commit is contained in:
Dave Collins 2015-01-29 00:11:19 -06:00
parent ee403e2abd
commit d67a0e207c
2 changed files with 28 additions and 6 deletions

View file

@ -200,7 +200,7 @@ func mergeTxStore(txStoreA btcchain.TxStore, txStoreB btcchain.TxStore) {
// signature script of the coinbase transaction of a new block. In particular, // signature script of the coinbase transaction of a new block. In particular,
// it starts with the block height that is required by version 2 blocks and adds // it starts with the block height that is required by version 2 blocks and adds
// the extra nonce as well as additional coinbase flags. // the extra nonce as well as additional coinbase flags.
func standardCoinbaseScript(nextBlockHeight int64, extraNonce uint64) []byte { func standardCoinbaseScript(nextBlockHeight int64, extraNonce uint64) ([]byte, error) {
return btcscript.NewScriptBuilder().AddInt64(nextBlockHeight). return btcscript.NewScriptBuilder().AddInt64(nextBlockHeight).
AddUint64(extraNonce).AddData([]byte(coinbaseFlags)).Script() AddUint64(extraNonce).AddData([]byte(coinbaseFlags)).Script()
} }
@ -223,8 +223,12 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int64, addr btcutil
return nil, err return nil, err
} }
} else { } else {
var err error
scriptBuilder := btcscript.NewScriptBuilder() scriptBuilder := btcscript.NewScriptBuilder()
pkScript = scriptBuilder.AddOp(btcscript.OP_TRUE).Script() pkScript, err = scriptBuilder.AddOp(btcscript.OP_TRUE).Script()
if err != nil {
return nil, err
}
} }
tx := btcwire.NewMsgTx() tx := btcwire.NewMsgTx()
@ -439,7 +443,10 @@ func NewBlockTemplate(mempool *txMemPool, payToAddress btcutil.Address) (*BlockT
// same value to the same public key address would otherwise be an // same value to the same public key address would otherwise be an
// identical transaction for block version 1). // identical transaction for block version 1).
extraNonce := uint64(0) extraNonce := uint64(0)
coinbaseScript := standardCoinbaseScript(nextBlockHeight, extraNonce) coinbaseScript, err := standardCoinbaseScript(nextBlockHeight, extraNonce)
if err != nil {
return nil, err
}
coinbaseTx, err := createCoinbaseTx(coinbaseScript, nextBlockHeight, coinbaseTx, err := createCoinbaseTx(coinbaseScript, nextBlockHeight,
payToAddress) payToAddress)
if err != nil { if err != nil {
@ -841,7 +848,10 @@ func UpdateBlockTime(msgBlock *btcwire.MsgBlock, bManager *blockManager) error {
// height. It also recalculates and updates the new merkle root that results // height. It also recalculates and updates the new merkle root that results
// from changing the coinbase script. // from changing the coinbase script.
func UpdateExtraNonce(msgBlock *btcwire.MsgBlock, blockHeight int64, extraNonce uint64) error { func UpdateExtraNonce(msgBlock *btcwire.MsgBlock, blockHeight int64, extraNonce uint64) error {
coinbaseScript := standardCoinbaseScript(blockHeight, extraNonce) coinbaseScript, err := standardCoinbaseScript(blockHeight, extraNonce)
if err != nil {
return err
}
if len(coinbaseScript) > btcchain.MaxCoinbaseScriptLen { if len(coinbaseScript) > btcchain.MaxCoinbaseScriptLen {
return fmt.Errorf("coinbase transaction script length "+ return fmt.Errorf("coinbase transaction script length "+
"of %d is out of range (min: %d, max: %d)", "of %d is out of range (min: %d, max: %d)",

View file

@ -92,8 +92,8 @@ var (
// overhead of creating a new object on every invocation for constant // overhead of creating a new object on every invocation for constant
// data. // data.
gbtCoinbaseAux = &btcjson.GetBlockTemplateResultAux{ gbtCoinbaseAux = &btcjson.GetBlockTemplateResultAux{
Flags: hex.EncodeToString(btcscript.NewScriptBuilder(). Flags: hex.EncodeToString(builderScript(btcscript.
AddData([]byte(coinbaseFlags)).Script()), NewScriptBuilder().AddData([]byte(coinbaseFlags)))),
} }
// gbtCapabilities describes additional capabilities returned with a // gbtCapabilities describes additional capabilities returned with a
@ -210,6 +210,18 @@ var rpcAskWallet = map[string]struct{}{
// Commands that are temporarily unimplemented. // Commands that are temporarily unimplemented.
var rpcUnimplemented = map[string]struct{}{} var rpcUnimplemented = map[string]struct{}{}
// builderScript is a convenience function which is used to for hard-coded
// 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 {
script, err := builder.Script()
if err != nil {
panic(err)
}
return script
}
// workStateBlockInfo houses information about how to reconstruct a block given // workStateBlockInfo houses information about how to reconstruct a block given
// its template and signature script. // its template and signature script.
type workStateBlockInfo struct { type workStateBlockInfo struct {