Enable SendTransaction over RPC.

This commit is contained in:
AnilChinchawale 2019-03-10 15:54:37 +05:30
parent 3f900e50a2
commit aa6b2e0323
2 changed files with 39 additions and 10 deletions

View file

@ -133,7 +133,7 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Error(string(buf))
log.Error(fmt.Sprintf("RPC serveRequest %s\n", string(buf)))
}
s.codecsMu.Lock()
s.codecs.Remove(codec)
@ -190,14 +190,14 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
if singleShot {
if batch {
for _, req := range reqs {
if req.callb != nil && req.callb.method.Name == "EnabledRPCSendTransaction" {
if req.callb != nil && req.callb.method.Name == "SendTransaction" {
codec.Write(codec.CreateErrorResponse(&req.id, &invalidRequestError{message: "Only support send transaction with ipc"}))
return nil
}
}
s.execBatch(ctx, codec, reqs)
} else {
if reqs[0].callb != nil && reqs[0].callb.method.Name == "EnabledRPCSendTransaction" {
if reqs[0].callb != nil && reqs[0].callb.method.Name == "SendTransaction" {
codec.Write(codec.CreateErrorResponse(&reqs[0].id, &invalidRequestError{message: "Only support send transaction with ipc"}))
return nil
}
@ -344,7 +344,7 @@ func (s *Server) exec(ctx context.Context, codec ServerCodec, req *serverRequest
}
if err := codec.Write(response); err != nil {
log.Error(fmt.Sprintf("%v\n", err))
log.Error(fmt.Sprintf("RPC exec %v\n", err))
codec.Close()
}
@ -371,7 +371,7 @@ func (s *Server) execBatch(ctx context.Context, codec ServerCodec, requests []*s
}
if err := codec.Write(responses); err != nil {
log.Error(fmt.Sprintf("%v\n", err))
log.Error(fmt.Sprintf("RPC execBacth %v\n", err))
codec.Close()
}

View file

@ -117,11 +117,13 @@ type ServerCodec interface {
}
type BlockNumber int64
type EpochNumber int64
const (
PendingBlockNumber = BlockNumber(-2)
LatestBlockNumber = BlockNumber(-1)
EarliestBlockNumber = BlockNumber(0)
LatestEpochNumber = EpochNumber(-1)
)
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
@ -131,11 +133,7 @@ const (
// - an invalid block number error when the given argument isn't a known strings
// - an out of range error when the given block number is either too little or too large
func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
input := strings.TrimSpace(string(data))
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
input = input[1 : len(input)-1]
}
input := trimData(data)
switch input {
case "earliest":
*bn = EarliestBlockNumber
@ -163,3 +161,34 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
func (bn BlockNumber) Int64() int64 {
return (int64)(bn)
}
func (e *EpochNumber) UnmarshalJSON(data []byte) error {
input := trimData(data)
if input == "latest" {
*e = LatestEpochNumber
return nil
}
eNum, err := hexutil.DecodeUint64(input)
if err != nil {
return err
}
if eNum > math.MaxInt64 {
return fmt.Errorf("EpochNumber too high")
}
*e = EpochNumber(eNum)
return nil
}
func (e EpochNumber) Int64() int64 {
return (int64)(e)
}
func trimData(data []byte) string {
input := strings.TrimSpace(string(data))
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
input = input[1 : len(input)-1]
}
return input
}