Alphabetise command handlers.
This commit is contained in:
parent
975640c6b3
commit
b96cb4317a
1 changed files with 88 additions and 86 deletions
174
rpcserver.go
174
rpcserver.go
|
@ -359,23 +359,12 @@ func jsonRead(body []byte, s *rpcServer, walletNotification chan []byte) (reply
|
||||||
|
|
||||||
// Deal with commands
|
// Deal with commands
|
||||||
switch c := cmd.(type) {
|
switch c := cmd.(type) {
|
||||||
case *btcjson.StopCmd:
|
case *btcjson.DecodeRawTransactionCmd:
|
||||||
|
// TODO: use c.HexTx and fill result with info.
|
||||||
|
txReply := btcjson.TxRawDecodeResult{}
|
||||||
reply = btcjson.Reply{
|
reply = btcjson.Reply{
|
||||||
Result: "btcd stopping.",
|
Result: txReply,
|
||||||
Id: &id,
|
Error: nil,
|
||||||
}
|
|
||||||
s.server.Stop()
|
|
||||||
|
|
||||||
case *btcjson.GetBlockCountCmd:
|
|
||||||
var maxidx int64
|
|
||||||
_, maxidx, err = s.server.db.NewestSha()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("RPCS: Error getting newest sha: %v", err)
|
|
||||||
err = btcjson.ErrBlockCount
|
|
||||||
return
|
|
||||||
}
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: maxidx,
|
|
||||||
Id: &id,
|
Id: &id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,67 +381,6 @@ func jsonRead(body []byte, s *rpcServer, walletNotification chan []byte) (reply
|
||||||
Id: &id,
|
Id: &id,
|
||||||
}
|
}
|
||||||
|
|
||||||
case *btcjson.GetConnectionCountCmd:
|
|
||||||
var count int
|
|
||||||
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: count,
|
|
||||||
Id: &id,
|
|
||||||
}
|
|
||||||
|
|
||||||
case *btcjson.GetDifficultyCmd:
|
|
||||||
var sha *btcwire.ShaHash
|
|
||||||
sha, _, err = s.server.db.NewestSha()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("RPCS: Error getting sha: %v", err)
|
|
||||||
err = btcjson.ErrDifficulty
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var blk *btcutil.Block
|
|
||||||
blk, err = s.server.db.FetchBlockBySha(sha)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("RPCS: Error getting block: %v", err)
|
|
||||||
err = btcjson.ErrDifficulty
|
|
||||||
return
|
|
||||||
}
|
|
||||||
blockHeader := &blk.MsgBlock().Header
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: getDifficultyRatio(blockHeader.Bits),
|
|
||||||
Id: &id,
|
|
||||||
}
|
|
||||||
|
|
||||||
// btcd does not do mining so we can hardcode replies here.
|
|
||||||
case *btcjson.GetGenerateCmd:
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: false,
|
|
||||||
Id: &id,
|
|
||||||
}
|
|
||||||
|
|
||||||
case *btcjson.SetGenerateCmd:
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: nil,
|
|
||||||
Id: &id,
|
|
||||||
}
|
|
||||||
|
|
||||||
case *btcjson.GetHashesPerSecCmd:
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: 0,
|
|
||||||
Id: &id,
|
|
||||||
}
|
|
||||||
|
|
||||||
case *btcjson.GetBlockHashCmd:
|
|
||||||
var sha *btcwire.ShaHash
|
|
||||||
sha, err = s.server.db.FetchBlockShaByHeight(c.Index)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("[RCPS] Error getting block: %v", err)
|
|
||||||
err = btcjson.ErrOutOfRange
|
|
||||||
return
|
|
||||||
}
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: sha.String(),
|
|
||||||
Id: &id,
|
|
||||||
}
|
|
||||||
|
|
||||||
case *btcjson.GetBlockCmd:
|
case *btcjson.GetBlockCmd:
|
||||||
var sha *btcwire.ShaHash
|
var sha *btcwire.ShaHash
|
||||||
sha, err = btcwire.NewShaHashFromStr(c.Hash)
|
sha, err = btcwire.NewShaHashFromStr(c.Hash)
|
||||||
|
@ -526,6 +454,75 @@ func jsonRead(body []byte, s *rpcServer, walletNotification chan []byte) (reply
|
||||||
Id: &id,
|
Id: &id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case *btcjson.GetBlockCountCmd:
|
||||||
|
var maxidx int64
|
||||||
|
_, maxidx, err = s.server.db.NewestSha()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("RPCS: Error getting newest sha: %v", err)
|
||||||
|
err = btcjson.ErrBlockCount
|
||||||
|
return
|
||||||
|
}
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: maxidx,
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
|
||||||
|
case *btcjson.GetBlockHashCmd:
|
||||||
|
var sha *btcwire.ShaHash
|
||||||
|
sha, err = s.server.db.FetchBlockShaByHeight(c.Index)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("[RCPS] Error getting block: %v", err)
|
||||||
|
err = btcjson.ErrOutOfRange
|
||||||
|
return
|
||||||
|
}
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: sha.String(),
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
|
||||||
|
case *btcjson.GetConnectionCountCmd:
|
||||||
|
var count int
|
||||||
|
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: count,
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
|
||||||
|
case *btcjson.GetDifficultyCmd:
|
||||||
|
var sha *btcwire.ShaHash
|
||||||
|
sha, _, err = s.server.db.NewestSha()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("RPCS: Error getting sha: %v", err)
|
||||||
|
err = btcjson.ErrDifficulty
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var blk *btcutil.Block
|
||||||
|
blk, err = s.server.db.FetchBlockBySha(sha)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("RPCS: Error getting block: %v", err)
|
||||||
|
err = btcjson.ErrDifficulty
|
||||||
|
return
|
||||||
|
}
|
||||||
|
blockHeader := &blk.MsgBlock().Header
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: getDifficultyRatio(blockHeader.Bits),
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
|
||||||
|
case *btcjson.GetGenerateCmd:
|
||||||
|
// btcd does not do mining so we can hardcode replies here.
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: false,
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
|
||||||
|
case *btcjson.GetHashesPerSecCmd:
|
||||||
|
// btcd does not do mining so we can hardcode replies here.
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: 0,
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
|
||||||
case *btcjson.GetRawMempoolCmd:
|
case *btcjson.GetRawMempoolCmd:
|
||||||
hashes := s.server.txMemPool.TxShas()
|
hashes := s.server.txMemPool.TxShas()
|
||||||
hashStrings := make([]string, len(hashes))
|
hashStrings := make([]string, len(hashes))
|
||||||
|
@ -629,15 +626,6 @@ func jsonRead(body []byte, s *rpcServer, walletNotification chan []byte) (reply
|
||||||
// not used yet
|
// not used yet
|
||||||
}
|
}
|
||||||
|
|
||||||
case *btcjson.DecodeRawTransactionCmd:
|
|
||||||
// TODO: use c.HexTx and fill result with info.
|
|
||||||
txReply := btcjson.TxRawDecodeResult{}
|
|
||||||
reply = btcjson.Reply{
|
|
||||||
Result: txReply,
|
|
||||||
Error: nil,
|
|
||||||
Id: &id,
|
|
||||||
}
|
|
||||||
|
|
||||||
case *btcjson.SendRawTransactionCmd:
|
case *btcjson.SendRawTransactionCmd:
|
||||||
|
|
||||||
// Deserialize and send off to tx relay
|
// Deserialize and send off to tx relay
|
||||||
|
@ -683,6 +671,20 @@ func jsonRead(body []byte, s *rpcServer, walletNotification chan []byte) (reply
|
||||||
Id: &id,
|
Id: &id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case *btcjson.SetGenerateCmd:
|
||||||
|
// btcd does not do mining so we can hardcode replies here.
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: nil,
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
|
||||||
|
case *btcjson.StopCmd:
|
||||||
|
reply = btcjson.Reply{
|
||||||
|
Result: "btcd stopping.",
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
s.server.Stop()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
jsonError := btcjson.Error{
|
jsonError := btcjson.Error{
|
||||||
Code: -32601,
|
Code: -32601,
|
||||||
|
|
Loading…
Reference in a new issue