Skip to content

Commit 605dd3a

Browse files
committed
Add serpent compilation to RPC
1 parent dba4f31 commit 605dd3a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

rpc/message.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) {
201201
return args, nil
202202
}
203203

204+
func (req *RpcRequest) ToCompileArgs() (string, error) {
205+
if len(req.Params) < 1 {
206+
return "", NewErrorResponse(ErrorArguments)
207+
}
208+
209+
var args string
210+
err := json.Unmarshal(req.Params[0], &args)
211+
if err != nil {
212+
return "", NewErrorResponse(ErrorDecodeArgs)
213+
}
214+
215+
rpclogger.DebugDetailf("%T %v", args, args)
216+
return args, nil
217+
}
218+
204219
func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) {
205220
if len(req.Params) < 1 {
206221
return nil, NewErrorResponse(ErrorArguments)

rpc/packages.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
300300
return nil
301301
}
302302

303+
func (p *EthereumApi) GetCompilers(reply *interface{}) error {
304+
c := []string{"serpent"}
305+
*reply = c
306+
return nil
307+
}
308+
309+
func (p *EthereumApi) CompileSerpent(script string, reply *interface{}) error {
310+
res, err := ethutil.Compile(script, false)
311+
if err != nil {
312+
return err
313+
}
314+
*reply = res
315+
return nil
316+
}
317+
303318
func (p *EthereumApi) Sha3(args *Sha3Args, reply *interface{}) error {
304319
*reply = toHex(crypto.Sha3(fromHex(args.Data)))
305320
return nil
@@ -490,6 +505,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
490505
return err
491506
}
492507
return p.WatchTx(args, reply)
508+
case "eth_compilers":
509+
return p.GetCompilers(reply)
510+
case "eth_serpent":
511+
args, err := req.ToCompileArgs()
512+
if err != nil {
513+
return err
514+
}
515+
return p.CompileSerpent(args, reply)
493516
case "web3_sha3":
494517
args, err := req.ToSha3Args()
495518
if err != nil {

0 commit comments

Comments
 (0)