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,
// 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 {
func standardCoinbaseScript(nextBlockHeight int64, extraNonce uint64) ([]byte, error) {
return btcscript.NewScriptBuilder().AddInt64(nextBlockHeight).
AddUint64(extraNonce).AddData([]byte(coinbaseFlags)).Script()
}
@ -223,8 +223,12 @@ func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int64, addr btcutil
return nil, err
}
} else {
var err error
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()
@ -439,7 +443,10 @@ func NewBlockTemplate(mempool *txMemPool, payToAddress btcutil.Address) (*BlockT
// same value to the same public key address would otherwise be an
// identical transaction for block version 1).
extraNonce := uint64(0)
coinbaseScript := standardCoinbaseScript(nextBlockHeight, extraNonce)
coinbaseScript, err := standardCoinbaseScript(nextBlockHeight, extraNonce)
if err != nil {
return nil, err
}
coinbaseTx, err := createCoinbaseTx(coinbaseScript, nextBlockHeight,
payToAddress)
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
// from changing the coinbase script.
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 {
return fmt.Errorf("coinbase transaction script length "+
"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
// data.
gbtCoinbaseAux = &btcjson.GetBlockTemplateResultAux{
Flags: hex.EncodeToString(btcscript.NewScriptBuilder().
AddData([]byte(coinbaseFlags)).Script()),
Flags: hex.EncodeToString(builderScript(btcscript.
NewScriptBuilder().AddData([]byte(coinbaseFlags)))),
}
// gbtCapabilities describes additional capabilities returned with a
@ -210,6 +210,18 @@ var rpcAskWallet = map[string]struct{}{
// Commands that are temporarily unimplemented.
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
// its template and signature script.
type workStateBlockInfo struct {