github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/assets/qml/views/chain.qml (about) 1 import QtQuick 2.0 2 import QtQuick.Controls 1.0; 3 import QtQuick.Layouts 1.0; 4 import QtQuick.Dialogs 1.0; 5 import QtQuick.Window 2.1; 6 import QtQuick.Controls.Styles 1.1 7 import Ethereum 1.0 8 9 Rectangle { 10 id: root 11 property var title: "Block Chain" 12 property var menuItem 13 14 objectName: "chainView" 15 visible: false 16 anchors.fill: parent 17 18 TableView { 19 id: blockTable 20 width: parent.width 21 anchors.top: parent.top 22 anchors.bottom: parent.bottom 23 TableViewColumn{ role: "number" ; title: "#" ; width: 100 } 24 TableViewColumn{ role: "hash" ; title: "Hash" ; width: 560 } 25 TableViewColumn{ role: "txAmount" ; title: "Tx amount" ; width: 100 } 26 27 model: blockModel 28 29 itemDelegate: Item { 30 Text { 31 anchors { 32 left: parent.left 33 right: parent.right 34 leftMargin: 10 35 verticalCenter: parent.verticalCenter 36 } 37 color: styleData.textColor 38 elide: styleData.elideMode 39 text: styleData.value 40 font.pixelSize: 11 41 MouseArea { 42 acceptedButtons: Qt.LeftButton | Qt.RightButton 43 propagateComposedEvents: true 44 anchors.fill: parent 45 onClicked: { 46 blockTable.selection.clear() 47 blockTable.selection.select(styleData.row) 48 49 if(mouse.button == Qt.RightButton) { 50 contextMenu.row = styleData.row; 51 contextMenu.popup() 52 } 53 } 54 55 onDoubleClicked: { 56 popup.visible = true 57 popup.setDetails(blockModel.get(styleData.row)) 58 } 59 } 60 } 61 62 } 63 64 Menu { 65 id: contextMenu 66 property var row 67 MenuItem { 68 text: "Details" 69 onTriggered: { 70 popup.visible = true 71 popup.setDetails(blockModel.get(contextMenu.row)) 72 } 73 } 74 75 MenuSeparator{} 76 77 MenuItem { 78 text: "Copy" 79 onTriggered: { 80 copyToClipboard(blockModel.get(contextMenu.row).hash) 81 } 82 } 83 84 MenuItem { 85 text: "Dump State" 86 onTriggered: { 87 generalFileDialog.show(false, function(path) { 88 var hash = blockModel.get(contextMenu.row).hash; 89 90 gui.dumpState(hash, path); 91 }); 92 } 93 } 94 } 95 } 96 97 98 99 function addBlock(block, initial) { 100 if(initial == undefined){ 101 initial = false 102 } 103 104 var amount = block.transactions.length; 105 var txs = []; 106 for(var i = 0; i < block.transactions.length; i++) { 107 var tx = JSON.parse(block.transactions.getAsJson(i)); 108 txs.push(tx); 109 } 110 111 if(initial){ 112 blockModel.append({raw: block.raw, bloom: block.bloom, size: block.size, number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)}) 113 } else { 114 blockModel.insert(0, {raw: block.raw, bloom: block.bloom, size: block.size, number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)}) 115 } 116 } 117 118 Window { 119 id: popup 120 visible: false 121 //flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint 122 property var block 123 width: root.width 124 height: 300 125 Component{ 126 id: blockDetailsDelegate 127 Rectangle { 128 color: "#252525" 129 width: popup.width 130 height: 150 131 Column { 132 anchors.leftMargin: 10 133 anchors.topMargin: 5 134 anchors.top: parent.top 135 anchors.left: parent.left 136 Text { text: '<h3>Block details</h3>'; color: "#F2F2F2"} 137 Text { text: '<b>Block number:</b> ' + number + " (Size: " + size + ")"; color: "#F2F2F2"} 138 Text { text: '<b>Hash:</b> ' + hash; color: "#F2F2F2"} 139 Text { text: '<b>Bloom:</b> ' + bloom; color: "#F2F2F2"} 140 Text { text: '<b>Coinbase:</b> <' + name + '> ' + coinbase; color: "#F2F2F2"} 141 Text { text: '<b>Block found at:</b> ' + prettyTime; color: "#F2F2F2"} 142 Text { text: '<b>Gas used:</b> ' + gasUsed + " / " + gasLimit; color: "#F2F2F2"} 143 } 144 } 145 } 146 ListView { 147 model: singleBlock 148 delegate: blockDetailsDelegate 149 anchors.top: parent.top 150 height: 100 151 anchors.leftMargin: 20 152 id: listViewThing 153 Layout.maximumHeight: 40 154 } 155 TableView { 156 id: txView 157 anchors.top: listViewThing.bottom 158 anchors.topMargin: 50 159 width: parent.width 160 161 TableViewColumn{width: 90; role: "value" ; title: "Value" } 162 TableViewColumn{width: 200; role: "hash" ; title: "Hash" } 163 TableViewColumn{width: 200; role: "sender" ; title: "Sender" } 164 TableViewColumn{width: 200;role: "address" ; title: "Receiver" } 165 TableViewColumn{width: 60; role: "gas" ; title: "Gas" } 166 TableViewColumn{width: 60; role: "gasPrice" ; title: "Gas Price" } 167 TableViewColumn{width: 60; role: "isContract" ; title: "Contract" } 168 169 model: transactionModel 170 onClicked: { 171 var tx = transactionModel.get(row) 172 if(tx.data) { 173 popup.showContractData(tx) 174 }else{ 175 popup.height = 440 176 } 177 } 178 } 179 180 function showContractData(tx) { 181 txDetailsDebugButton.tx = tx 182 if(tx.createsContract) { 183 contractData.text = tx.data 184 contractLabel.text = "<h4> Transaction created contract " + tx.address + "</h4>" 185 }else{ 186 contractLabel.text = "<h4> Transaction ran contract " + tx.address + "</h4>" 187 contractData.text = tx.rawData 188 } 189 popup.height = 540 190 } 191 192 Rectangle { 193 id: txDetails 194 width: popup.width 195 height: 300 196 anchors.left: listViewThing.left 197 anchors.top: txView.bottom 198 Label { 199 text: "<h4>Contract data</h4>" 200 anchors.top: parent.top 201 anchors.left: parent.left 202 id: contractLabel 203 anchors.leftMargin: 10 204 } 205 Button { 206 property var tx 207 id: txDetailsDebugButton 208 anchors.right: parent.right 209 anchors.rightMargin: 10 210 anchors.top: parent.top 211 anchors.topMargin: 10 212 text: "Debug contract" 213 onClicked: { 214 if(tx && tx.createsContract){ 215 eth.startDbWithCode(tx.rawData) 216 }else { 217 eth.startDbWithContractAndData(tx.address, tx.rawData) 218 } 219 } 220 } 221 TextArea { 222 id: contractData 223 text: "Contract" 224 anchors.top: contractLabel.bottom 225 anchors.left: parent.left 226 anchors.right: parent.right 227 wrapMode: Text.Wrap 228 height: 80 229 } 230 TextArea { 231 id: dumpData 232 anchors.top: contractData.bottom 233 anchors.left: parent.left 234 anchors.right: parent.right 235 anchors.bottom: parent.bottom 236 height: 300 237 } 238 } 239 property var transactionModel: ListModel { 240 id: transactionModel 241 } 242 property var singleBlock: ListModel { 243 id: singleBlock 244 } 245 function setDetails(bl){ 246 singleBlock.set(0, bl) 247 popup.height = 300 248 transactionModel.clear() 249 if(bl.txs !== undefined){ 250 for(var i = 0; i < bl.txs.count; i++) { 251 transactionModel.insert(0, bl.txs.get(i)) 252 } 253 if(bl.txs.count > 0 && bl.txs.get(0).data){ 254 popup.showContractData(bl.txs.get(0)) 255 } 256 } 257 txView.forceActiveFocus() 258 dumpData.text = bl.raw; 259 } 260 } 261 }