aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-06-04 21:54:39 +0800
committerMaran <maran.hidskes@gmail.com>2014-06-04 21:54:39 +0800
commita56f78af67ba2b515f396d7a150ac86f6a75335f (patch)
tree048e5b78719ab7e1a1cc96e573b5ebaf8085269e
parentd7b882977c4289bc2aabb51e1cf6b3577bc02aca (diff)
downloadgo-tangerine-a56f78af67ba2b515f396d7a150ac86f6a75335f.tar
go-tangerine-a56f78af67ba2b515f396d7a150ac86f6a75335f.tar.gz
go-tangerine-a56f78af67ba2b515f396d7a150ac86f6a75335f.tar.bz2
go-tangerine-a56f78af67ba2b515f396d7a150ac86f6a75335f.tar.lz
go-tangerine-a56f78af67ba2b515f396d7a150ac86f6a75335f.tar.xz
go-tangerine-a56f78af67ba2b515f396d7a150ac86f6a75335f.tar.zst
go-tangerine-a56f78af67ba2b515f396d7a150ac86f6a75335f.zip
Implement getStateKeyVal for JS bindings.
Gives JS the option to 'loop' over contract key/val storage
-rw-r--r--ethpub/types.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/ethpub/types.go b/ethpub/types.go
index 4967eda49..6893c7e09 100644
--- a/ethpub/types.go
+++ b/ethpub/types.go
@@ -207,6 +207,31 @@ func (c *PStateObject) IsContract() bool {
return false
}
+type KeyVal struct {
+ Key string
+ Value string
+}
+
+func (c *PStateObject) StateKeyVal(asJson bool) interface{} {
+ var values []KeyVal
+ if c.object != nil {
+ c.object.State().EachStorage(func(name string, value *ethutil.Value) {
+ values = append(values, KeyVal{name, ethutil.Hex(value.Bytes())})
+ })
+ }
+
+ if asJson {
+ valuesJson, err := json.Marshal(values)
+ if err != nil {
+ return nil
+ }
+ fmt.Println(string(valuesJson))
+ return string(valuesJson)
+ }
+
+ return values
+}
+
func (c *PStateObject) Script() string {
if c.object != nil {
return strings.Join(ethchain.Disassemble(c.object.Script()), " ")