aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ethpub/pub.go11
-rw-r--r--ethpub/types.go16
2 files changed, 14 insertions, 13 deletions
diff --git a/ethpub/pub.go b/ethpub/pub.go
index ec187e276..cd002b500 100644
--- a/ethpub/pub.go
+++ b/ethpub/pub.go
@@ -24,18 +24,9 @@ func NewPEthereum(manager ethchain.EthManager) *PEthereum {
func (lib *PEthereum) GetBlock(hexHash string) *PBlock {
hash := ethutil.FromHex(hexHash)
-
block := lib.blockChain.GetBlock(hash)
- var blockInfo *PBlock
-
- if block != nil {
- blockInfo = &PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
- } else {
- blockInfo = &PBlock{Number: -1, Hash: ""}
- }
-
- return blockInfo
+ return NewPBlock(block)
}
func (lib *PEthereum) GetKey() *PKey {
diff --git a/ethpub/types.go b/ethpub/types.go
index 77cca78b9..afec47fdc 100644
--- a/ethpub/types.go
+++ b/ethpub/types.go
@@ -8,16 +8,26 @@ import (
// Block interface exposed to QML
type PBlock struct {
+ ref *ethchain.Block
Number int `json:"number"`
Hash string `json:"hash"`
}
// Creates a new QML Block from a chain block
func NewPBlock(block *ethchain.Block) *PBlock {
- info := block.BlockInfo()
- hash := hex.EncodeToString(block.Hash())
+ if block == nil {
+ return nil
+ }
+
+ return &PBlock{ref: block, Number: int(block.Number.Uint64()), Hash: ethutil.Hex(block.Hash())}
+}
- return &PBlock{Number: int(info.Number), Hash: hash}
+func (self *PBlock) ToString() string {
+ if self.ref != nil {
+ return self.ref.String()
+ }
+
+ return ""
}
type PTx struct {