blob: 9e12a8892004014bae71b79c7ef354693b7c5268 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
package ethui
import (
"encoding/hex"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
)
// Block interface exposed to QML
type QBlock struct {
Number int
Hash string
}
// Creates a new QML Block from a chain block
func NewQBlock(block *ethchain.Block) *QBlock {
info := block.BlockInfo()
hash := hex.EncodeToString(block.Hash())
return &QBlock{Number: int(info.Number), Hash: hash}
}
type QTx struct {
Value, Hash, Address string
Contract bool
}
func NewQTx(tx *ethchain.Transaction) *QTx {
hash := hex.EncodeToString(tx.Hash())
sender := hex.EncodeToString(tx.Recipient)
isContract := len(tx.Data) > 0
return &QTx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract}
}
type QKey struct {
Address string
}
type QKeyRing struct {
Keys []interface{}
}
func NewQKeyRing(keys []interface{}) *QKeyRing {
return &QKeyRing{Keys: keys}
}
type QStateObject struct {
object *ethchain.StateObject
}
func NewQStateObject(object *ethchain.StateObject) *QStateObject {
return &QStateObject{object: object}
}
func (c *QStateObject) GetStorage(address string) string {
// 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 ""
}
func (c *QStateObject) Value() string {
if c.object != nil {
return c.object.Amount.String()
}
return ""
}
func (c *QStateObject) Address() string {
if c.object != nil {
return ethutil.Hex(c.object.Address())
}
return ""
}
|