Commit 61ccc39b authored by Bas van Kervel's avatar Bas van Kervel

initialize fields to prevent nil pointer exception

parent f9264e87
...@@ -906,6 +906,9 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { ...@@ -906,6 +906,9 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) {
} }
trans := new(types.Transaction) trans := new(types.Transaction)
trans.Amount = new(big.Int)
trans.GasLimit = new(big.Int)
trans.Price = new(big.Int)
if val, found := fields["To"]; found { if val, found := fields["To"]; found {
if strVal, ok := val.(string); ok && len(strVal) > 0 { if strVal, ok := val.(string); ok && len(strVal) > 0 {
...@@ -928,13 +931,15 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { ...@@ -928,13 +931,15 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) {
return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Nonce - %v", err)) return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Nonce - %v", err))
} }
} }
} else {
return shared.NewDecodeParamError("tx.Nonce not found")
} }
var parseOk bool var parseOk bool
if val, found := fields["Value"]; found { if val, found := fields["Value"]; found {
if strVal, ok := val.(string); ok { if strVal, ok := val.(string); ok {
tx.Value = strVal tx.Value = strVal
if trans.Amount, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { if _, parseOk = trans.Amount.SetString(strVal, 0); !parseOk {
return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Amount - %v", err)) return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.Amount - %v", err))
} }
} }
...@@ -954,7 +959,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { ...@@ -954,7 +959,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) {
if val, found := fields["GasLimit"]; found { if val, found := fields["GasLimit"]; found {
if strVal, ok := val.(string); ok { if strVal, ok := val.(string); ok {
tx.GasLimit = strVal tx.GasLimit = strVal
if trans.GasLimit, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { if _, parseOk = trans.GasLimit.SetString(strVal, 0); !parseOk {
return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasLimit - %v", err)) return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasLimit - %v", err))
} }
} }
...@@ -963,7 +968,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) { ...@@ -963,7 +968,7 @@ func (tx *tx) UnmarshalJSON(b []byte) (err error) {
if val, found := fields["GasPrice"]; found { if val, found := fields["GasPrice"]; found {
if strVal, ok := val.(string); ok { if strVal, ok := val.(string); ok {
tx.GasPrice = strVal tx.GasPrice = strVal
if trans.Price, parseOk = new(big.Int).SetString(strVal, 0); !parseOk { if _, parseOk = trans.Price.SetString(strVal, 0); !parseOk {
return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasPrice - %v", err)) return shared.NewDecodeParamError(fmt.Sprintf("Unable to decode tx.GasPrice - %v", err))
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment