aboutsummaryrefslogtreecommitdiffstats
path: root/ethpipe
diff options
context:
space:
mode:
Diffstat (limited to 'ethpipe')
-rw-r--r--ethpipe/js_pipe.go49
-rw-r--r--ethpipe/js_types.go31
2 files changed, 69 insertions, 11 deletions
diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go
index 2f1f90462..a2b1a4551 100644
--- a/ethpipe/js_pipe.go
+++ b/ethpipe/js_pipe.go
@@ -17,28 +17,28 @@ func NewJSPipe(eth ethchain.EthManager) *JSPipe {
return &JSPipe{New(eth)}
}
-func (self *JSPipe) GetBlockByHash(strHash string) *JSBlock {
+func (self *JSPipe) BlockByHash(strHash string) *JSBlock {
hash := ethutil.Hex2Bytes(strHash)
block := self.obj.BlockChain().GetBlock(hash)
return NewJSBlock(block)
}
-func (self *JSPipe) GetKey() *JSKey {
+func (self *JSPipe) Key() *JSKey {
return NewJSKey(self.obj.KeyManager().KeyPair())
}
-func (self *JSPipe) GetStateObject(addr string) *JSObject {
+func (self *JSPipe) StateObject(addr string) *JSObject {
object := &Object{self.World().safeGet(ethutil.Hex2Bytes(addr))}
return NewJSObject(object)
}
-func (self *JSPipe) GetPeerCount() int {
+func (self *JSPipe) PeerCount() int {
return self.obj.PeerCount()
}
-func (self *JSPipe) GetPeers() []JSPeer {
+func (self *JSPipe) Peers() []JSPeer {
var peers []JSPeer
for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() {
p := peer.Value.(ethchain.Peer)
@@ -51,23 +51,33 @@ func (self *JSPipe) GetPeers() []JSPeer {
return peers
}
-func (self *JSPipe) GetIsMining() bool {
+func (self *JSPipe) IsMining() bool {
return self.obj.IsMining()
}
-func (self *JSPipe) GetIsListening() bool {
+func (self *JSPipe) IsListening() bool {
return self.obj.IsListening()
}
-func (self *JSPipe) GetCoinBase() string {
+func (self *JSPipe) CoinBase() string {
return ethutil.Bytes2Hex(self.obj.KeyManager().Address())
}
-func (self *JSPipe) GetStorage(addr, storageAddr string) string {
+func (self *JSPipe) BalanceAt(addr string) string {
+ return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance.String()
+}
+
+func (self *JSPipe) NumberToHuman(balance string) string {
+ b := ethutil.Big(balance)
+
+ return ethutil.CurrencyToString(b)
+}
+
+func (self *JSPipe) StorageAt(addr, storageAddr string) string {
return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)).Str()
}
-func (self *JSPipe) GetTxCountAt(address string) int {
+func (self *JSPipe) TxCountAt(address string) int {
return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce)
}
@@ -89,7 +99,7 @@ type KeyVal struct {
Value string `json:"value"`
}
-func (self *JSPipe) GetEachStorage(addr string) string {
+func (self *JSPipe) EachStorage(addr string) string {
var values []KeyVal
object := self.World().SafeGet(ethutil.Hex2Bytes(addr))
object.EachStorage(func(name string, value *ethutil.Value) {
@@ -175,3 +185,20 @@ func (self *JSPipe) CompileMutan(code string) string {
return ethutil.Bytes2Hex(data)
}
+
+func (self *JSPipe) Messages(object map[string]interface{}) string {
+ filter := ethchain.NewFilterFromMap(object, self.obj)
+
+ messages := filter.Find()
+ var msgs []JSMessage
+ for _, m := range messages {
+ msgs = append(msgs, NewJSMessage(m))
+ }
+
+ b, err := json.Marshal(msgs)
+ if err != nil {
+ return "{\"error\":" + err.Error() + "}"
+ }
+
+ return string(b)
+}
diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go
index e1743486b..0fb3a3876 100644
--- a/ethpipe/js_types.go
+++ b/ethpipe/js_types.go
@@ -7,6 +7,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethcrypto"
+ "github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
)
@@ -175,3 +176,33 @@ func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte)
ethutil.Bytes2Hex(address),
}
}
+
+type JSMessage struct {
+ To string `json:"to"`
+ From string `json:"from"`
+ Input string `json:"input"`
+ Output string `json:"output"`
+ Path int32 `json:"path"`
+ Origin string `json:"origin"`
+ Timestamp int32 `json:"timestamp"`
+ Coinbase string `json:"coinbase"`
+ Block string `json:"block"`
+ Number int32 `json:"number"`
+ Value string `json:"value"`
+}
+
+func NewJSMessage(message *ethstate.Message) JSMessage {
+ return JSMessage{
+ To: ethutil.Bytes2Hex(message.To),
+ From: ethutil.Bytes2Hex(message.From),
+ Input: ethutil.Bytes2Hex(message.Input),
+ Output: ethutil.Bytes2Hex(message.Output),
+ Path: int32(message.Path),
+ Origin: ethutil.Bytes2Hex(message.Origin),
+ Timestamp: int32(message.Timestamp),
+ Coinbase: ethutil.Bytes2Hex(message.Origin),
+ Block: ethutil.Bytes2Hex(message.Block),
+ Number: int32(message.Number.Int64()),
+ Value: message.Value.String(),
+ }
+}