mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 02:10:46 +00:00
Enable SendTransaction over RPC.
This commit is contained in:
parent
3f900e50a2
commit
aa6b2e0323
2 changed files with 39 additions and 10 deletions
|
|
@ -133,7 +133,7 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
|
||||||
const size = 64 << 10
|
const size = 64 << 10
|
||||||
buf := make([]byte, size)
|
buf := make([]byte, size)
|
||||||
buf = buf[:runtime.Stack(buf, false)]
|
buf = buf[:runtime.Stack(buf, false)]
|
||||||
log.Error(string(buf))
|
log.Error(fmt.Sprintf("RPC serveRequest %s\n", string(buf)))
|
||||||
}
|
}
|
||||||
s.codecsMu.Lock()
|
s.codecsMu.Lock()
|
||||||
s.codecs.Remove(codec)
|
s.codecs.Remove(codec)
|
||||||
|
|
@ -190,14 +190,14 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
|
||||||
if singleShot {
|
if singleShot {
|
||||||
if batch {
|
if batch {
|
||||||
for _, req := range reqs {
|
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"}))
|
codec.Write(codec.CreateErrorResponse(&req.id, &invalidRequestError{message: "Only support send transaction with ipc"}))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.execBatch(ctx, codec, reqs)
|
s.execBatch(ctx, codec, reqs)
|
||||||
} else {
|
} 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"}))
|
codec.Write(codec.CreateErrorResponse(&reqs[0].id, &invalidRequestError{message: "Only support send transaction with ipc"}))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -344,7 +344,7 @@ func (s *Server) exec(ctx context.Context, codec ServerCodec, req *serverRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := codec.Write(response); err != nil {
|
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()
|
codec.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -371,7 +371,7 @@ func (s *Server) execBatch(ctx context.Context, codec ServerCodec, requests []*s
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := codec.Write(responses); err != nil {
|
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()
|
codec.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
39
rpc/types.go
39
rpc/types.go
|
|
@ -117,11 +117,13 @@ type ServerCodec interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlockNumber int64
|
type BlockNumber int64
|
||||||
|
type EpochNumber int64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PendingBlockNumber = BlockNumber(-2)
|
PendingBlockNumber = BlockNumber(-2)
|
||||||
LatestBlockNumber = BlockNumber(-1)
|
LatestBlockNumber = BlockNumber(-1)
|
||||||
EarliestBlockNumber = BlockNumber(0)
|
EarliestBlockNumber = BlockNumber(0)
|
||||||
|
LatestEpochNumber = EpochNumber(-1)
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
|
// 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 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
|
// - an out of range error when the given block number is either too little or too large
|
||||||
func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
||||||
input := strings.TrimSpace(string(data))
|
input := trimData(data)
|
||||||
if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
|
|
||||||
input = input[1 : len(input)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
switch input {
|
switch input {
|
||||||
case "earliest":
|
case "earliest":
|
||||||
*bn = EarliestBlockNumber
|
*bn = EarliestBlockNumber
|
||||||
|
|
@ -163,3 +161,34 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
||||||
func (bn BlockNumber) Int64() int64 {
|
func (bn BlockNumber) Int64() int64 {
|
||||||
return (int64)(bn)
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue