From 7c91159449c528daa099aec5a3744aa8a6b5a826 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 May 2014 11:56:25 +0200 Subject: [PATCH 1/2] Added different storage notification object --- ethchain/state_manager.go | 2 +- ethchain/state_object.go | 6 ++++++ ethpub/pub.go | 12 ++++++++++++ ethpub/types.go | 36 ++++++++++++++++++++++++++---------- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index 02d0345d75..501ec102bf 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -350,7 +350,7 @@ func (sm *StateManager) notifyChanges() { for stateObjectAddr, mappedObjects := range sm.manifest.storageChanges { for addr, value := range mappedObjects { - sm.Ethereum.Reactor().Post("storage:"+stateObjectAddr+":"+addr, value.String()) + sm.Ethereum.Reactor().Post("storage:"+stateObjectAddr+":"+addr, &StorageState{[]byte(stateObjectAddr), []byte(addr), value}) } } } diff --git a/ethchain/state_object.go b/ethchain/state_object.go index 4ec91d2e08..6176460777 100644 --- a/ethchain/state_object.go +++ b/ethchain/state_object.go @@ -186,3 +186,9 @@ type CachedStateObject struct { Nonce uint64 Object *StateObject } + +type StorageState struct { + StateAddress []byte + Address []byte + Value *big.Int +} diff --git a/ethpub/pub.go b/ethpub/pub.go index c6f177124a..5f23018f7f 100644 --- a/ethpub/pub.go +++ b/ethpub/pub.go @@ -47,6 +47,18 @@ func (lib *PEthereum) GetStateObject(address string) *PStateObject { return NewPStateObject(nil) } +func (lib *PEthereum) GetStorage(address, storageAddress string) string { + return lib.GetStateObject(address).GetStorage(storageAddress) +} + +func (lib *PEthereum) GetTxCount(address string) int { + return lib.GetStateObject(address).Nonce() +} + +func (lib *PEthereum) IsContract(address string) bool { + return lib.GetStateObject(address).IsContract() +} + func (lib *PEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (*PReceipt, error) { return lib.createTx(key, recipient, valueStr, gasStr, gasPriceStr, dataStr, "") } diff --git a/ethpub/types.go b/ethpub/types.go index bf06ce2f64..7ae476339d 100644 --- a/ethpub/types.go +++ b/ethpub/types.go @@ -59,16 +59,6 @@ func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) * } } -/* -type PKeyRing struct { - Keys []interface{} -} - -func NewPKeyRing(keys []interface{}) *PKeyRing { - return &PKeyRing{Keys: keys} -} -*/ - type PStateObject struct { object *ethchain.StateObject } @@ -105,3 +95,29 @@ func (c *PStateObject) Address() string { return "" } + +func (c *PStateObject) Nonce() int { + if c.object != nil { + return int(c.object.Nonce) + } + + return 0 +} + +func (c *PStateObject) IsContract() bool { + if c.object != nil { + return len(c.object.Script()) > 0 + } + + return false +} + +type PStorageState struct { + StateAddress string + Address string + Value string +} + +func NewPStorageState(storageObject *ethchain.StorageState) *PStorageState { + return &PStorageState{ethutil.Hex(storageObject.StateAddress), ethutil.Hex(storageObject.Address), storageObject.Value.String()} +} From 5757f5df2a5ffc4207ab2be5f1280d4f2e95d303 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 May 2014 13:09:29 +0200 Subject: [PATCH 2/2] Added secret to address method --- ethpub/pub.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ethpub/pub.go b/ethpub/pub.go index 5f23018f7f..f9d2ebc72e 100644 --- a/ethpub/pub.go +++ b/ethpub/pub.go @@ -59,6 +59,15 @@ func (lib *PEthereum) IsContract(address string) bool { return lib.GetStateObject(address).IsContract() } +func (lib *PEthereum) SecretToAddress(key string) string { + pair, err := ethchain.NewKeyPairFromSec(ethutil.FromHex(key)) + if err != nil { + return "" + } + + return ethutil.Hex(pair.Address()) +} + func (lib *PEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (*PReceipt, error) { return lib.createTx(key, recipient, valueStr, gasStr, gasPriceStr, dataStr, "") }