From d977398bbc86a9af40eb6ba01bb8051548a8c791 Mon Sep 17 00:00:00 2001 From: manlio Date: Sat, 7 Sep 2019 15:35:38 +0200 Subject: [PATCH] Make From param optional in Transaction object --- ethrpc_test.go | 5 +---- types.go | 7 ++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ethrpc_test.go b/ethrpc_test.go index a004a0a..7c9cd43 100644 --- a/ethrpc_test.go +++ b/ethrpc_test.go @@ -526,10 +526,7 @@ func (s *EthRPCTestSuite) TestSendTransaction() { httpmock.Reset() s.registerResponse(fmt.Sprintf(`"%s"`, result), func(body []byte) { s.methodEqual(body, "eth_sendTransaction") - s.paramsEqual(body, `[{ - "from": "" - }]`) - + s.paramsEqual(body,`[{}]`) }) txid, err = s.rpc.EthSendTransaction(t) diff --git a/types.go b/types.go index b90baee..1af7d63 100644 --- a/types.go +++ b/types.go @@ -41,12 +41,13 @@ type T struct { // MarshalJSON implements the json.Unmarshaler interface. func (t T) MarshalJSON() ([]byte, error) { - params := map[string]interface{}{ - "from": t.From, - } + params := map[string]interface{}{} if t.To != "" { params["to"] = t.To } + if t.From != "" { + params["from"] = t.From + } if t.Gas > 0 { params["gas"] = IntToHex(t.Gas) }