From 98d436ccc8fc53e0b0c05fe81fb7c5b98c483677 Mon Sep 17 00:00:00 2001 From: Dimitri Roche Date: Tue, 12 Dec 2017 11:50:28 -0500 Subject: [PATCH] Allow no params for the EthBytes32 adapter --- models/task.go | 9 ++++++++- web/controllers/fixtures/create_jobs.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/models/task.go b/models/task.go index 17e6f77e4cc..04fde4e79ba 100644 --- a/models/task.go +++ b/models/task.go @@ -36,7 +36,7 @@ func (self Task) Adapter() (adapters.Adapter, error) { return temp, err case "EthBytes32": temp := &adapters.EthBytes32{} - err := json.Unmarshal(self.Params, temp) + err := unmarshalOrEmpty(self.Params, temp) return temp, err case "EthSendTx": temp := &adapters.EthSendTx{} @@ -48,3 +48,10 @@ func (self Task) Adapter() (adapters.Adapter, error) { return nil, fmt.Errorf("%s is not a supported adapter type", self.Type) } + +func unmarshalOrEmpty(params json.RawMessage, dst interface{}) error { + if len(params) > 0 { + return json.Unmarshal(params, dst) + } + return nil +} diff --git a/web/controllers/fixtures/create_jobs.json b/web/controllers/fixtures/create_jobs.json index dcfa11375cb..85418beb293 100644 --- a/web/controllers/fixtures/create_jobs.json +++ b/web/controllers/fixtures/create_jobs.json @@ -2,7 +2,7 @@ "tasks": [ { "type": "HttpGet", "params": { "endpoint": "https://bitstamp.net/api/ticker/" } }, { "type": "JsonParse", "params": { "path": ["last"] } }, - { "type": "EthBytes32", "params": {} }, + { "type": "EthBytes32" }, { "type": "EthSendTx", "params": { "address": "0x356a04bce728ba4c62a30294a55e6a8600a320b3", "functionID": "12345679" } } ], "schedule": {"endAt": "2019-11-27T23:05:49Z", "runAt": ["2018-11-27T23:05:49Z"], "cron": "* 7 * * *"},