diff options
author | obscuren <geffobscura@gmail.com> | 2014-08-18 16:17:45 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-08-18 16:17:45 +0800 |
commit | b0ae61c6521003d7861d89944e1d426e939535bb (patch) | |
tree | b3b332f939df52963341a5f05d4327b76b50009f | |
parent | 793e666f36e512bceb0d92d0a8dfe1d7c508c0e2 (diff) | |
download | dexon-b0ae61c6521003d7861d89944e1d426e939535bb.tar.gz dexon-b0ae61c6521003d7861d89944e1d426e939535bb.tar.zst dexon-b0ae61c6521003d7861d89944e1d426e939535bb.zip |
Removed the "Get" part
-rw-r--r-- | ethchain/state_transition.go | 1 | ||||
-rw-r--r-- | ethpipe/js_pipe.go | 49 | ||||
-rw-r--r-- | ethpipe/js_types.go | 31 | ||||
-rw-r--r-- | ethrpc/packages.go | 18 | ||||
-rw-r--r-- | ethstate/manifest.go | 3 | ||||
-rw-r--r-- | ethvm/vm.go | 2 |
6 files changed, 83 insertions, 21 deletions
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go index f8452cdb3..9fbc160a5 100644 --- a/ethchain/state_transition.go +++ b/ethchain/state_transition.go @@ -216,6 +216,7 @@ func (self *StateTransition) TransitionState() (err error) { Input: self.tx.Data, Origin: sender.Address(), Block: self.block.Hash(), Timestamp: self.block.Time, Coinbase: self.block.Coinbase, Number: self.block.Number, + Value: self.value, }) // Process the init code and create 'valid' contract 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(), + } +} diff --git a/ethrpc/packages.go b/ethrpc/packages.go index bd7528415..f2e57fa49 100644 --- a/ethrpc/packages.go +++ b/ethrpc/packages.go @@ -74,7 +74,7 @@ func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *string) error { return err } - block := p.pipe.GetBlockByHash(args.Hash) + block := p.pipe.BlockByHash(args.Hash) *reply = NewSuccessRes(block) return nil } @@ -129,7 +129,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *string) error { if err != nil { return err } - result, _ := p.pipe.Transact(p.pipe.GetKey().PrivateKey, args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body) + result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body) *reply = NewSuccessRes(result) return nil } @@ -140,13 +140,13 @@ func (p *EthereumApi) Create(args *NewTxArgs, reply *string) error { return err } - result, _ := p.pipe.Transact(p.pipe.GetKey().PrivateKey, "", args.Value, args.Gas, args.GasPrice, args.Body) + result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, "", args.Value, args.Gas, args.GasPrice, args.Body) *reply = NewSuccessRes(result) return nil } func (p *EthereumApi) GetKey(args interface{}, reply *string) error { - *reply = NewSuccessRes(p.pipe.GetKey()) + *reply = NewSuccessRes(p.pipe.Key()) return nil } @@ -212,7 +212,7 @@ type GetPeerCountRes struct { } func (p *EthereumApi) GetPeerCount(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetPeerCountRes{PeerCount: p.pipe.GetPeerCount()}) + *reply = NewSuccessRes(GetPeerCountRes{PeerCount: p.pipe.PeerCount()}) return nil } @@ -221,7 +221,7 @@ type GetListeningRes struct { } func (p *EthereumApi) GetIsListening(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetListeningRes{IsListening: p.pipe.GetIsListening()}) + *reply = NewSuccessRes(GetListeningRes{IsListening: p.pipe.IsListening()}) return nil } @@ -230,7 +230,7 @@ type GetCoinbaseRes struct { } func (p *EthereumApi) GetCoinbase(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetCoinbaseRes{Coinbase: p.pipe.GetCoinBase()}) + *reply = NewSuccessRes(GetCoinbaseRes{Coinbase: p.pipe.CoinBase()}) return nil } @@ -239,7 +239,7 @@ type GetMiningRes struct { } func (p *EthereumApi) GetIsMining(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetMiningRes{IsMining: p.pipe.GetIsMining()}) + *reply = NewSuccessRes(GetMiningRes{IsMining: p.pipe.IsMining()}) return nil } @@ -248,7 +248,7 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *string) error { if err != nil { return err } - state := p.pipe.GetTxCountAt(args.Address) + state := p.pipe.TxCountAt(args.Address) *reply = NewSuccessRes(GetTxCountRes{Nonce: state}) return nil } diff --git a/ethstate/manifest.go b/ethstate/manifest.go index 604f77b89..945de22ab 100644 --- a/ethstate/manifest.go +++ b/ethstate/manifest.go @@ -41,6 +41,7 @@ type Message struct { Coinbase []byte Block []byte Number *big.Int + Value *big.Int ChangedAddresses [][]byte } @@ -50,5 +51,5 @@ func (self *Message) AddStorageChange(addr []byte) { } func (self *Message) String() string { - return fmt.Sprintf("Message{to: %x from: %x input: %x output: %x origin: %x coinbase: %x block: %x number: %v timestamp: %d path: %d", self.To, self.From, self.Input, self.Output, self.Origin, self.Coinbase, self.Block, self.Number, self.Timestamp, self.Path) + return fmt.Sprintf("Message{to: %x from: %x input: %x output: %x origin: %x coinbase: %x block: %x number: %v timestamp: %d path: %d value: %v", self.To, self.From, self.Input, self.Output, self.Origin, self.Coinbase, self.Block, self.Number, self.Timestamp, self.Path, self.Value) } diff --git a/ethvm/vm.go b/ethvm/vm.go index 789697865..ddad0d366 100644 --- a/ethvm/vm.go +++ b/ethvm/vm.go @@ -700,6 +700,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { To: addr, From: closure.Address(), Origin: self.env.Origin(), Block: self.env.BlockHash(), Timestamp: self.env.Time(), Coinbase: self.env.Coinbase(), Number: self.env.BlockNumber(), + Value: value, }) // Create a new contract @@ -765,6 +766,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) { Input: args, Origin: self.env.Origin(), Block: self.env.BlockHash(), Timestamp: self.env.Time(), Coinbase: self.env.Coinbase(), Number: self.env.BlockNumber(), + Value: value, }) if closure.object.Balance.Cmp(value) < 0 { |