Updates for btcutil and btcscript's btcnet conversion.

ok @davecgh
This commit is contained in:
Josh Rickmar 2014-05-27 17:44:55 -05:00
parent 4328461f36
commit 74303966c0
5 changed files with 23 additions and 20 deletions

View file

@ -524,7 +524,7 @@ func loadConfig() (*config, []string, error) {
// Check keys are valid and saved parsed versions.
cfg.miningKeys = make([]btcutil.Address, 0, len(cfg.GetWorkKeys))
for _, strAddr := range cfg.GetWorkKeys {
addr, err := btcutil.DecodeAddress(strAddr, activeNetParams.Net)
addr, err := btcutil.DecodeAddress(strAddr, activeNetParams.Params)
if err != nil {
str := "%s: the specified getworkkey '%s' failed to decode: %v"
err := fmt.Errorf(str, "loadConfig", strAddr, err)
@ -532,7 +532,7 @@ func loadConfig() (*config, []string, error) {
parser.WriteHelp(os.Stderr)
return nil, nil, err
}
if !addr.IsForNet(activeNetParams.Net) {
if !addr.IsForNet(activeNetParams.Params) {
str := "%s: the specified getworkkey '%s' is on the wrong network"
err := fmt.Errorf(str, "loadConfig", strAddr)
fmt.Fprintln(os.Stderr, err)

View file

@ -1579,7 +1579,7 @@ func newPeerBase(s *server, inbound bool) *peer {
p := peer{
server: s,
protocolVersion: maxProtocolVersion,
btcnet: s.btcnet,
btcnet: s.netParams.Net,
services: btcwire.SFNodeNetwork,
inbound: inbound,
knownAddresses: make(map[string]bool),

View file

@ -17,6 +17,7 @@ import (
"github.com/conformal/btcchain"
"github.com/conformal/btcdb"
"github.com/conformal/btcjson"
"github.com/conformal/btcnet"
"github.com/conformal/btcscript"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire"
@ -588,7 +589,7 @@ func handleCreateRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, err
// Decode the provided address.
addr, err := btcutil.DecodeAddress(encodedAddr,
activeNetParams.Net)
activeNetParams.Params)
if err != nil {
return nil, btcjson.Error{
Code: btcjson.ErrInvalidAddressOrKey.Code,
@ -606,7 +607,7 @@ func handleCreateRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, err
default:
return nil, btcjson.ErrInvalidAddressOrKey
}
if !addr.IsForNet(s.server.btcnet) {
if !addr.IsForNet(s.server.netParams) {
return nil, btcjson.Error{
Code: btcjson.ErrInvalidAddressOrKey.Code,
Message: fmt.Sprintf("%s: %q",
@ -688,7 +689,7 @@ func createVinList(mtx *btcwire.MsgTx) ([]btcjson.Vin, error) {
// createVoutList returns a slice of JSON objects for the outputs of the passed
// transaction.
func createVoutList(mtx *btcwire.MsgTx, net btcwire.BitcoinNet) ([]btcjson.Vout, error) {
func createVoutList(mtx *btcwire.MsgTx, net *btcnet.Params) ([]btcjson.Vout, error) {
voutList := make([]btcjson.Vout, len(mtx.TxOut))
for i, v := range mtx.TxOut {
voutList[i].N = i
@ -726,7 +727,10 @@ func createVoutList(mtx *btcwire.MsgTx, net btcwire.BitcoinNet) ([]btcjson.Vout,
// createTxRawResult converts the passed transaction and associated parameters
// to a raw transaction JSON object.
func createTxRawResult(net btcwire.BitcoinNet, txSha string, mtx *btcwire.MsgTx, blk *btcutil.Block, maxidx int64, blksha *btcwire.ShaHash) (*btcjson.TxRawResult, error) {
func createTxRawResult(net *btcnet.Params, txSha string, mtx *btcwire.MsgTx,
blk *btcutil.Block, maxidx int64,
blksha *btcwire.ShaHash) (*btcjson.TxRawResult, error) {
mtxHex, err := messageToHex(mtx)
if err != nil {
return nil, err
@ -795,7 +799,7 @@ func handleDecodeRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, err
if err != nil {
return nil, err
}
vout, err := createVoutList(&mtx, s.server.btcnet)
vout, err := createVoutList(&mtx, s.server.netParams)
if err != nil {
return nil, err
}
@ -832,7 +836,7 @@ func handleDecodeScript(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
// 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.btcnet
net := s.server.netParams
scriptClass, addrs, reqSigs, _ := btcscript.ExtractPkScriptAddrs(script, net)
addresses := make([]string, len(addrs))
for i, addr := range addrs {
@ -1040,8 +1044,8 @@ func handleGetBlock(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
txSha := tx.Sha().String()
mtx := tx.MsgTx()
rawTxn, err := createTxRawResult(s.server.btcnet, txSha,
mtx, blk, maxidx, sha)
rawTxn, err := createTxRawResult(s.server.netParams,
txSha, mtx, blk, maxidx, sha)
if err != nil {
rpcsLog.Errorf("Cannot create TxRawResult for "+
"transaction %s: %v", txSha, err)
@ -1096,7 +1100,7 @@ func handleGetConnectionCount(s *rpcServer, cmd btcjson.Cmd) (interface{}, error
// handleGetCurrentNet implements the getcurrentnet command.
func handleGetCurrentNet(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
return s.server.btcnet, nil
return s.server.netParams.Net, nil
}
// handleGetDifficulty implements the getdifficulty command.
@ -1422,7 +1426,8 @@ func handleGetRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, error)
}
}
rawTxn, jsonErr := createTxRawResult(s.server.btcnet, c.Txid, mtx, blk, maxidx, blksha)
rawTxn, jsonErr := createTxRawResult(s.server.netParams, c.Txid, mtx,
blk, maxidx, blksha)
if err != nil {
rpcsLog.Errorf("Cannot create TxRawResult for txSha=%s: %v", txSha, err)
return nil, jsonErr

View file

@ -485,7 +485,7 @@ func (m *wsNotificationManager) notifyForNewTx(clients map[chan bool]*wsClient,
for _, wsc := range clients {
if wsc.verboseTxUpdates {
if verboseNtfn == nil {
net := m.server.server.btcnet
net := m.server.server.netParams
rawTx, err := createTxRawResult(net, txShaStr,
mtx, nil, 0, nil)
if err != nil {
@ -620,7 +620,7 @@ func (m *wsNotificationManager) notifyForTxOuts(ops map[btcwire.OutPoint]map[cha
wscNotified := make(map[chan bool]bool)
for i, txOut := range tx.MsgTx().TxOut {
_, txAddrs, _, err := btcscript.ExtractPkScriptAddrs(
txOut.PkScript, m.server.server.btcnet)
txOut.PkScript, m.server.server.netParams)
if err != nil {
continue
}
@ -1433,7 +1433,7 @@ func handleNotifyReceived(wsc *wsClient, icmd btcjson.Cmd) (interface{}, *btcjso
}
for _, addrStr := range cmd.Addresses {
addr, err := btcutil.DecodeAddress(addrStr, activeNetParams.Net)
addr, err := btcutil.DecodeAddress(addrStr, activeNetParams.Params)
if err != nil {
e := btcjson.Error{
Code: btcjson.ErrInvalidAddressOrKey.Code,
@ -1501,7 +1501,7 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *btcutil.Block) {
for txOutIdx, txout := range tx.MsgTx().TxOut {
_, addrs, _, _ := btcscript.ExtractPkScriptAddrs(
txout.PkScript, wsc.server.server.btcnet)
txout.PkScript, wsc.server.server.netParams)
for _, addr := range addrs {
switch a := addr.(type) {
@ -1630,7 +1630,7 @@ func handleRescan(wsc *wsClient, icmd btcjson.Cmd) (interface{}, *btcjson.Error)
var compressedPubkey [33]byte
var uncompressedPubkey [65]byte
for _, addrStr := range cmd.Addresses {
addr, err := btcutil.DecodeAddress(addrStr, activeNetParams.Net)
addr, err := btcutil.DecodeAddress(addrStr, activeNetParams.Params)
if err != nil {
jsonErr := btcjson.Error{
Code: btcjson.ErrInvalidAddressOrKey.Code,

View file

@ -64,7 +64,6 @@ type server struct {
nonce uint64
listeners []net.Listener
netParams *btcnet.Params
btcnet btcwire.BitcoinNet
started int32 // atomic
shutdown int32 // atomic
shutdownSched int32 // atomic
@ -1131,7 +1130,6 @@ func newServer(listenAddrs []string, db btcdb.Db, netParams *btcnet.Params) (*se
nonce: nonce,
listeners: listeners,
netParams: netParams,
btcnet: netParams.Net,
addrManager: amgr,
newPeers: make(chan *peer, cfg.MaxPeers),
donePeers: make(chan *peer, cfg.MaxPeers),