aboutsummaryrefslogtreecommitdiffstats
path: root/ethpipe/config.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-04 22:25:53 +0800
committerobscuren <geffobscura@gmail.com>2014-08-04 22:25:53 +0800
commit342cc122b43f01301d0188de1e333c32ed64ae8c (patch)
treea8bfb3288a5866de2a315319124e7a6b908f7bd3 /ethpipe/config.go
parent03ce15df4c7ef51d4373233ab5c3766282b31771 (diff)
downloadgo-tangerine-342cc122b43f01301d0188de1e333c32ed64ae8c.tar.gz
go-tangerine-342cc122b43f01301d0188de1e333c32ed64ae8c.tar.zst
go-tangerine-342cc122b43f01301d0188de1e333c32ed64ae8c.zip
Added general Pipe API
Diffstat (limited to 'ethpipe/config.go')
-rw-r--r--ethpipe/config.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/ethpipe/config.go b/ethpipe/config.go
new file mode 100644
index 000000000..764f5596f
--- /dev/null
+++ b/ethpipe/config.go
@@ -0,0 +1,47 @@
+package ethpipe
+
+import (
+ "github.com/ethereum/eth-go/ethstate"
+ "github.com/ethereum/eth-go/ethutil"
+)
+
+var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f")
+
+type object struct {
+ *ethstate.StateObject
+}
+
+func (self object) StorageString(str string) *ethutil.Value {
+ if ethutil.IsHex(str) {
+ return self.Storage(ethutil.Hex2Bytes(str[2:]))
+ } else {
+ return self.Storage(ethutil.RightPadBytes([]byte(str), 32))
+ }
+}
+
+func (self object) Storage(addr []byte) *ethutil.Value {
+ return self.StateObject.GetStorage(ethutil.BigD(addr))
+}
+
+type config struct {
+ pipe *Pipe
+}
+
+func (self *config) Get(name string) object {
+ configCtrl := self.pipe.World().safeGet(cnfCtr)
+ var addr []byte
+
+ switch name {
+ case "NameReg":
+ addr = []byte{0}
+ default:
+ addr = ethutil.RightPadBytes([]byte(name), 32)
+ }
+
+ objectAddr := configCtrl.GetStorage(ethutil.BigD(addr))
+ return object{self.pipe.World().safeGet(objectAddr.Bytes())}
+}
+
+func (self *config) Exist() bool {
+ return self.pipe.World().Get(cnfCtr) != nil
+}