Renamed Ethereum RPC package

This commit is contained in:
Maran 2014-05-05 13:49:59 +02:00
parent 8adad0654a
commit c496aad20b
2 changed files with 17 additions and 10 deletions

@ -7,7 +7,7 @@ import (
_ "log" _ "log"
) )
type MainPackage struct { type EthereumApi struct {
ethp *ethpub.PEthereum ethp *ethpub.PEthereum
} }
@ -65,7 +65,7 @@ func (b *GetBlockArgs) requirements() error {
return nil return nil
} }
func (p *MainPackage) GetBlock(args *GetBlockArgs, reply *string) error { func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *string) error {
err := args.requirements() err := args.requirements()
if err != nil { if err != nil {
return err return err
@ -121,7 +121,7 @@ func (a *NewTxArgs) requirementsContract() error {
return nil return nil
} }
func (p *MainPackage) Transact(args *NewTxArgs, reply *string) error { func (p *EthereumApi) Transact(args *NewTxArgs, reply *string) error {
err := args.requirements() err := args.requirements()
if err != nil { if err != nil {
return err return err
@ -131,7 +131,7 @@ func (p *MainPackage) Transact(args *NewTxArgs, reply *string) error {
return nil return nil
} }
func (p *MainPackage) Create(args *NewTxArgs, reply *string) error { func (p *EthereumApi) Create(args *NewTxArgs, reply *string) error {
err := args.requirementsContract() err := args.requirementsContract()
if err != nil { if err != nil {
return err return err
@ -141,7 +141,7 @@ func (p *MainPackage) Create(args *NewTxArgs, reply *string) error {
return nil return nil
} }
func (p *MainPackage) GetKey(args interface{}, reply *string) error { func (p *EthereumApi) GetKey(args interface{}, reply *string) error {
*reply = NewSuccessRes(p.ethp.GetKey()) *reply = NewSuccessRes(p.ethp.GetKey())
return nil return nil
} }
@ -167,14 +167,14 @@ type GetStorageAtRes struct {
Address string `json:"address"` Address string `json:"address"`
} }
func (p *MainPackage) GetStorageAt(args *GetStorageArgs, reply *string) error { func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error {
err := args.requirements() err := args.requirements()
if err != nil { if err != nil {
return err return err
} }
state := p.ethp.GetStateObject(args.Address) state := p.ethp.GetStateObject(args.Address)
value := state.GetStorage(args.Key) value := state.GetStorage(args.Key)
*reply = NewSuccessRes(&GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value}) *reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value})
return nil return nil
} }
@ -189,11 +189,18 @@ func (a *GetBalanceArgs) requirements() error {
return nil return nil
} }
func (p *MainPackage) GetBalanceAt(args *GetBalanceArgs, reply *string) error { type BalanceRes struct {
Balance string `json:"balance"`
Address string `json:"address"`
}
func (p *EthereumApi) GetBalanceAt(args *GetBalanceArgs, reply *string) error {
err := args.requirements() err := args.requirements()
if err != nil { if err != nil {
return err return err
} }
state := p.ethp.GetStateObject(args.Address)
*reply = NewSuccessRes(BalanceRes{Balance: state.Value(), Address: args.Address})
return nil return nil
} }
@ -202,7 +209,7 @@ type TestRes struct {
Answer int `json:"answer"` Answer int `json:"answer"`
} }
func (p *MainPackage) Test(args *GetBlockArgs, reply *string) error { func (p *EthereumApi) Test(args *GetBlockArgs, reply *string) error {
*reply = NewSuccessRes(TestRes{Answer: 15}) *reply = NewSuccessRes(TestRes{Answer: 15})
return nil return nil
} }

@ -34,7 +34,7 @@ func (s *JsonRpcServer) Stop() {
func (s *JsonRpcServer) Start() { func (s *JsonRpcServer) Start() {
ethutil.Config.Log.Infoln("[JSON] Starting JSON-RPC server") ethutil.Config.Log.Infoln("[JSON] Starting JSON-RPC server")
go s.exitHandler() go s.exitHandler()
rpc.Register(&MainPackage{ethp: s.ethp}) rpc.Register(&EthereumApi{ethp: s.ethp})
rpc.HandleHTTP() rpc.HandleHTTP()
for { for {