From 64c2550b3154df7f2c75dda559d91046cb559ffd Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 30 Apr 2014 01:44:02 +0200 Subject: Split off External applications from main library External applications now accept containers which function as the frontend where the ExtApplication functions as the backend. Containers execute within their own engine and have their own context and are destroyed when released. --- ethereal/ui/library.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'ethereal/ui/library.go') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 7f667f2c1..ec5f29f95 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -19,9 +19,24 @@ func NewContract(object *ethchain.StateObject) *Contract { } func (c *Contract) GetStorage(address string) string { - val := c.object.GetMem(ethutil.Big("0x" + address)) + // Because somehow, even if you return nil to QML it + // still has some magical object so we can't rely on + // undefined or null at the QML side + if c.object != nil { + val := c.object.GetMem(ethutil.Big("0x" + address)) - return val.BigInt().String() + return val.BigInt().String() + } + + return "" +} + +func (c *Contract) Value() string { + if c.object != nil { + return c.object.Amount.String() + } + + return "" } type EthLib struct { @@ -63,15 +78,23 @@ func (lib *EthLib) GetKey() string { func (lib *EthLib) GetStateObject(address string) *Contract { stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) + if stateObject != nil { + return NewContract(stateObject) + } - return NewContract(stateObject) + // See GetStorage for explanation on "nil" + return NewContract(nil) } -func (lib *EthLib) Watch(addr string) { - lib.stateManager.Watch(ethutil.FromHex(addr)) +func (lib *EthLib) Watch(addr, storageAddr string) { + // lib.stateManager.Watch(ethutil.FromHex(addr), ethutil.FromHex(storageAddr)) } func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { + return lib.Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr) +} + +func (lib *EthLib) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { var hash []byte var contractCreation bool if len(recipient) == 0 { -- cgit v1.2.3