Allow zero and negative block numbers

0 is genesis block. Xeth recognises -1 as current
pull/369/head
Taylor Gerring 10 years ago
parent dd086791ac
commit 6fd894aae0
  1. 7
      rpc/args.go
  2. 12
      rpc/packages.go

@ -22,13 +22,6 @@ func (obj *GetBlockArgs) UnmarshalJSON(b []byte) (err error) {
return NewErrorResponse(ErrorDecodeArgs) return NewErrorResponse(ErrorDecodeArgs)
} }
func (obj *GetBlockArgs) requirements() error {
if obj.BlockNumber == 0 && obj.Hash == "" {
return NewErrorResponse("GetBlock requires either a block 'number' or a block 'hash' as argument")
}
return nil
}
type NewTxArgs struct { type NewTxArgs struct {
From string `json:"from"` From string `json:"from"`
To string `json:"to"` To string `json:"to"`

@ -177,15 +177,11 @@ func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error
} }
func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error { func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
err := args.requirements() // This seems a bit precarious Maybe worth splitting to discrete functions
if err != nil { if len(args.Hash) > 0 {
return err
}
if args.BlockNumber > 0 {
*reply = p.xeth.BlockByNumber(args.BlockNumber)
} else {
*reply = p.xeth.BlockByHash(args.Hash) *reply = p.xeth.BlockByHash(args.Hash)
} else {
*reply = p.xeth.BlockByNumber(args.BlockNumber)
} }
return nil return nil
} }

Loading…
Cancel
Save