aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/list.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/ethutil/list.go b/ethutil/list.go
index 9db96cf18..4fb36224f 100644
--- a/ethutil/list.go
+++ b/ethutil/list.go
@@ -9,6 +9,7 @@ import (
// for containing any slice type to use in an environment which
// does not support slice types (e.g., JavaScript, QML)
type List struct {
+ val interface{}
list reflect.Value
Length int
}
@@ -20,7 +21,7 @@ func NewList(t interface{}) *List {
panic("list container initialized with a non-slice type")
}
- return &List{list, list.Len()}
+ return &List{t, list, list.Len()}
}
func EmptyList() *List {
@@ -29,13 +30,24 @@ func EmptyList() *List {
// Get N element from the embedded slice. Returns nil if OOB.
func (self *List) Get(i int) interface{} {
+
if self.list.Len() > i {
- return self.list.Index(i).Interface()
+ i := self.list.Index(i).Interface()
+
+ return i
}
return nil
}
+func (self *List) GetAsJson(i int) interface{} {
+ e := self.Get(i)
+
+ r, _ := json.Marshal(e)
+
+ return string(r)
+}
+
// Appends value at the end of the slice. Panics when incompatible value
// is given.
func (self *List) Append(v interface{}) {