fix eth.sign. now implemented in admin jsre until web3.js has it .

pull/1048/head
zelig 10 years ago
parent b0ae84aa0d
commit 00f59f5014
  1. 25
      cmd/geth/admin.go
  2. 2
      cmd/geth/js_test.go
  3. 20
      rpc/api.go
  4. 64
      rpc/args.go

@ -35,6 +35,7 @@ func (js *jsre) adminBindings() {
eth := ethO.Object() eth := ethO.Object()
eth.Set("pendingTransactions", js.pendingTransactions) eth.Set("pendingTransactions", js.pendingTransactions)
eth.Set("resend", js.resend) eth.Set("resend", js.resend)
eth.Set("sign", js.sign)
js.re.Set("admin", struct{}{}) js.re.Set("admin", struct{}{})
t, _ := js.re.Get("admin") t, _ := js.re.Get("admin")
@ -177,6 +178,30 @@ func (js *jsre) resend(call otto.FunctionCall) otto.Value {
return otto.FalseValue() return otto.FalseValue()
} }
func (js *jsre) sign(call otto.FunctionCall) otto.Value {
if len(call.ArgumentList) != 2 {
fmt.Println("requires 2 arguments: eth.sign(signer, data)")
return otto.UndefinedValue()
}
signer, err := call.Argument(0).ToString()
if err != nil {
fmt.Println(err)
return otto.UndefinedValue()
}
data, err := call.Argument(1).ToString()
if err != nil {
fmt.Println(err)
return otto.UndefinedValue()
}
v, err := js.xeth.Sign(signer, data, false)
if err != nil {
fmt.Println(err)
return otto.UndefinedValue()
}
return js.re.ToVal(v)
}
func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value { func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value {
block, err := js.getBlock(call) block, err := js.getBlock(call)
if err != nil { if err != nil {

@ -230,7 +230,7 @@ func TestSignature(t *testing.T) {
defer ethereum.Stop() defer ethereum.Stop()
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
val, err := repl.re.Run(`eth.sign({from: "` + testAddress + `", data: "` + testHash + `"})`) val, err := repl.re.Run(`eth.sign("` + testAddress + `", "` + testHash + `")`)
// This is a very preliminary test, lacking actual signature verification // This is a very preliminary test, lacking actual signature verification
if err != nil { if err != nil {

@ -158,16 +158,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
v := api.xethAtStateNum(args.BlockNumber).CodeAtBytes(args.Address) v := api.xethAtStateNum(args.BlockNumber).CodeAtBytes(args.Address)
*reply = newHexData(v) *reply = newHexData(v)
case "eth_sign": // case "eth_sign":
args := new(NewSigArgs) // args := new(NewSigArgs)
if err := json.Unmarshal(req.Params, &args); err != nil { // if err := json.Unmarshal(req.Params, &args); err != nil {
return err // return err
} // }
v, err := api.xeth().Sign(args.From, args.Data, false) // v, err := api.xeth().Sign(args.From, args.Data, false)
if err != nil { // if err != nil {
return err // return err
} // }
*reply = v // *reply = v
case "eth_sendTransaction", "eth_transact": case "eth_sendTransaction", "eth_transact":
args := new(NewTxArgs) args := new(NewTxArgs)

@ -166,45 +166,45 @@ type NewTxArgs struct {
BlockNumber int64 BlockNumber int64
} }
type NewSigArgs struct { // type NewSigArgs struct {
From string // From string
Data string // Data string
} // }
func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { // func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) {
var obj []json.RawMessage // var obj []json.RawMessage
var ext struct { // var ext struct {
From string // From string
Data string // Data string
} // }
// Decode byte slice to array of RawMessages // // Decode byte slice to array of RawMessages
if err := json.Unmarshal(b, &obj); err != nil { // if err := json.Unmarshal(b, &obj); err != nil {
return NewDecodeParamError(err.Error()) // return NewDecodeParamError(err.Error())
} // }
// Check for sufficient params // // Check for sufficient params
if len(obj) < 1 { // if len(obj) < 1 {
return NewInsufficientParamsError(len(obj), 1) // return NewInsufficientParamsError(len(obj), 1)
} // }
// Decode 0th RawMessage to temporary struct // // Decode 0th RawMessage to temporary struct
if err := json.Unmarshal(obj[0], &ext); err != nil { // if err := json.Unmarshal(obj[0], &ext); err != nil {
return NewDecodeParamError(err.Error()) // return NewDecodeParamError(err.Error())
} // }
if len(ext.From) == 0 { // if len(ext.From) == 0 {
return NewValidationError("from", "is required") // return NewValidationError("from", "is required")
} // }
if len(ext.Data) == 0 { // if len(ext.Data) == 0 {
return NewValidationError("data", "is required") // return NewValidationError("data", "is required")
} // }
args.From = ext.From // args.From = ext.From
args.Data = ext.Data // args.Data = ext.Data
return nil // return nil
} // }
func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
var obj []json.RawMessage var obj []json.RawMessage

Loading…
Cancel
Save