Skip to content

Commit

Permalink
[explorer] refs fibercrypto#248 - Changed from []QTransaction to []Tr…
Browse files Browse the repository at this point in the history
…ansactionDetails type of TransactionList parameter in BlockModel in explorer package. Added - TransactionTypeGeneric to transaction types in transactions package.

 - Added NewTransactionDetailFromCoreTransaction method in transaction package.
 - Added TransactionDetails UI to Explorer UI.
  • Loading branch information
hsequeda committed Jan 9, 2020
1 parent 8201feb commit 8570750
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 37 deletions.
22 changes: 11 additions & 11 deletions src/models/explorer/blocksModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package explorer
import (
skycoin "github.com/fibercrypto/fibercryptowallet/src/coin/skycoin/models"
"github.com/fibercrypto/fibercryptowallet/src/core"
"github.com/fibercrypto/fibercryptowallet/src/models"
"github.com/fibercrypto/fibercryptowallet/src/models/transactions"
"github.com/fibercrypto/fibercryptowallet/src/params"
"github.com/fibercrypto/fibercryptowallet/src/util"
"github.com/fibercrypto/fibercryptowallet/src/util/logging"
Expand Down Expand Up @@ -81,14 +81,14 @@ type BlocksModel struct {
type QBlock struct {
qtcore.QObject

_ []*models.QTransaction `property:"transactionList"`
_ qtcore.QDateTime `property:"time"`
_ string `property:"blockhash"`
_ string `property:"prevBlockhash"`
_ string `property:"totalAmount"`
_ uint64 `property:"blockNumber"`
_ uint64 `property:"size"`
_ int `property:"transactionLen"`
_ []*transactions.TransactionDetails `property:"transactionList"`
_ qtcore.QDateTime `property:"time"`
_ string `property:"blockhash"`
_ string `property:"prevBlockhash"`
_ string `property:"totalAmount"`
_ uint64 `property:"blockNumber"`
_ uint64 `property:"size"`
_ int `property:"transactionLen"`
}

func (m *BlocksModel) init() {
Expand Down Expand Up @@ -296,10 +296,10 @@ func blockToQBlock(block core.Block) *QBlock {
if err != nil {
logExplorer.WithError(err).Error("Couldn't get the transactions list of block")
}
var qTransactionsList []*models.QTransaction
var qTransactionsList []*transactions.TransactionDetails
for e := range transactionList {

qTransaction, err := models.NewQTransactionFromTransaction(transactionList[e])
qTransaction, err := transactions.NewTransactionDetailFromCoreTransaction(transactionList[e], -1)
if err != nil {
logExplorer.WithError(err).Error("Couldn't get the transactions list of block")
}
Expand Down
24 changes: 12 additions & 12 deletions src/models/explorer/explorerManager.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package explorer

// import (
// qtCore "github.com/therecipe/qt/core"
// )
//
func init() {
BlocksModel_QmlRegisterType2("ExplorerModels", 1, 0, "QBlocks")
// BlocksModel_QmlRegisterType2("ExplorerModels", 1, 0, "ExplorerManager")
}

//
// type ExploreManager struct {
// type ExplorerManager struct {
// qtCore.QObject
// Blockchain core.BlockchainStatus
// _ func() `constructor:"init"`
//
// _ func(hash string) `slot:"loadBlockByHash"`
// _ func() `constructor:"init"`

// _ func() []*transactions.TransactionDetails `slot:"loadHistoryWithFilters"`
// _ func() []*transactions.TransactionDetails `slot:"loadHistory"`
// _ func(string) `slot:"addFilter"`
// _ func(string) `slot:"removeFilter"`
// walletEnv core.WalletEnv
// }
//
// func (explorer *ExploreManager) init() {
// logExplorer.Info("Init explorerManager")
// func (em *ExplorerManager) init() {
//
// }
//
// func (em *ExplorerManager) GetTransactionDetails(txId string) *transactions.TransactionDetails {
//
// }
124 changes: 120 additions & 4 deletions src/models/transactions/transactions.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package transactions

import (
coin "github.com/fibercrypto/fibercryptowallet/src/coin/skycoin/models"
"github.com/fibercrypto/fibercryptowallet/src/coin/skycoin/params"
"github.com/fibercrypto/fibercryptowallet/src/core"
"github.com/fibercrypto/fibercryptowallet/src/models/address"
qtcore "github.com/therecipe/qt/core"
"github.com/fibercrypto/fibercryptowallet/src/util"
"github.com/fibercrypto/fibercryptowallet/src/util/logging"
qtCore "github.com/therecipe/qt/core"
"strconv"
"time"
)

var logTransactionDetails = logging.MustGetLogger("TransactionDetails")

func init() {
TransactionDetails_QmlRegisterType2("HistoryModels", 1, 0, "QTransactionDetail")
}

const (
Date = int(qtcore.Qt__UserRole) + 1<<iota
Date = int(qtCore.Qt__UserRole) + 1<<iota
Status
Type
Amount
Expand All @@ -32,11 +41,12 @@ const (
TransactionTypeSend = iota
TransactionTypeReceive
TransactionTypeInternal
TransactionTypeGeneric
)

type TransactionDetails struct {
qtcore.QObject
_ *qtcore.QDateTime `property:"date"`
qtCore.QObject
_ *qtCore.QDateTime `property:"date"`
_ int `property:"status"`
_ int `property:"type"`
_ string `property:"amount"`
Expand All @@ -47,3 +57,109 @@ type TransactionDetails struct {
_ *address.AddressList `property:"inputs"`
_ *address.AddressList `property:"outputs"`
}

func NewTransactionDetailFromCoreTransaction(transaction core.Transaction, txType int) (*TransactionDetails, error) {
txnDetails := NewTransactionDetails(nil)
t := time.Unix(int64(transaction.GetTimestamp()), 0)

txnDetails.SetDate(qtCore.NewQDateTime3(qtCore.NewQDate3(t.Year(), int(t.Month()), t.Day()),
qtCore.NewQTime3(t.Hour(), t.Minute(), 0, 0), qtCore.Qt__LocalTime))
switch transaction.GetStatus() {
case core.TXN_STATUS_CONFIRMED:
txnDetails.SetStatus(TransactionStatusConfirmed)
case core.TXN_STATUS_PENDING:
txnDetails.SetStatus(TransactionStatusPending)
default:
txnDetails.SetStatus(TransactionStatusPreview)
}

txnDetails.SetTransactionID(transaction.GetId())

if txType >= 0 {
txnDetails.SetType(txType)
} else {
txnDetails.SetType(TransactionTypeGeneric)
}

inputs := address.NewAddressList(nil)
outputs := address.NewAddressList(nil)

txnIns := transaction.GetInputs()

for e := range txnIns {

qIn := address.NewAddressDetails(nil)
qIn.SetAddress(txnIns[e].GetSpentOutput().GetAddress().String())

// TODO Do this generic for all coins
skyUint64, err := txnIns[e].GetCoins(params.SkycoinTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Skycoins balance")
continue
}
accuracy, err := util.AltcoinQuotient(params.SkycoinTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Skycoins quotient")
continue
}
skyFloat := float64(skyUint64) / float64(accuracy)
qIn.SetAddressSky(strconv.FormatFloat(skyFloat, 'f', -1, 64))
chUint64, err := txnIns[e].GetCoins(params.CoinHoursTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Coin Hours balance")
continue
}
accuracy, err = util.AltcoinQuotient(params.CoinHoursTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Coin Hours quotient")
continue
}
qIn.SetAddressCoinHours(util.FormatCoins(chUint64, accuracy))
inputs.AddAddress(qIn)
}

txnDetails.SetInputs(inputs)

for _, out := range transaction.GetOutputs() {
sky, err := out.GetCoins(params.SkycoinTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Skycoins balance")
continue
}
qOu := address.NewAddressDetails(nil)
qOu.SetAddress(out.GetAddress().String())
accuracy, err := util.AltcoinQuotient(params.SkycoinTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Skycoins quotient")
continue
}
qOu.SetAddressSky(util.FormatCoins(sky, accuracy))
val, err := out.GetCoins(params.CoinHoursTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Coin Hours balance")
continue
}
accuracy, err = util.AltcoinQuotient(coin.CoinHour)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get Coin Hours quotient")
continue
}
qOu.SetAddressCoinHours(util.FormatCoins(val, accuracy))
outputs.AddAddress(qOu)
}

txnDetails.SetOutputs(outputs)

fee, err := transaction.ComputeFee(params.CoinHoursTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't compute fee of the operation")
return nil, err
}
accuracy, err := util.AltcoinQuotient(coin.CoinHoursTicker)
if err != nil {
logTransactionDetails.WithError(err).Warn("Couldn't get " + coin.CoinHoursTicker + " coins quotient")
}
txnDetails.SetHoursBurned(util.FormatCoins(fee, accuracy))

return txnDetails, nil
}
2 changes: 1 addition & 1 deletion src/ui/BlockPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Page {
id: groupBoxBlockDetails
title: qsTr("Block Details")
clip: true
Layout.fillWidth: true
width:parent.width
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter

ColumnLayout {
Expand Down
49 changes: 42 additions & 7 deletions src/ui/Delegates/TransactionListDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12

import "../Dialogs"
Item{
id: root

Expand All @@ -13,14 +14,14 @@ Item{
readonly property real finalViewHeight: delegateHeight + 400

width: parent.width
height: itemDelegateMainButton.height+inputList.height+ 30 + outputList.height+30
height: itemDelegateTransaction.height+inputList.height+ 30 + outputList.height+30

ColumnLayout {
id: delegateColumnLayout
anchors.fill: parent

ItemDelegate {
id: itemDelegateMainButton
id: itemDelegateTransaction
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
Component.onCompleted:{
Expand All @@ -32,18 +33,31 @@ Item{
id: delegateRowLayout
anchors.fill: parent


Label {
font.bold:true
text: qsTr("Transaction ID:") // a role of the model
Layout.fillWidth: true
}

Label {
text: modelData.transactionId
text: modelData.transactionID
horizontalAlignment: Text.AlignLeft
}
} // RowLayout
onClicked:{

dialogTransactionDetails.date = modelData.date
dialogTransactionDetails.status = modelData.status
dialogTransactionDetails.type = modelData.type
dialogTransactionDetails.hoursReceived = modelData.hoursTraspassed
dialogTransactionDetails.hoursBurned = modelData.hoursBurned
dialogTransactionDetails.transactionID = modelData.transactionID
dialogTransactionDetails.modelInputs = modelData.inputs
dialogTransactionDetails.modelOutputs = modelData.outputs


dialogTransactionDetails.open()
}
} // ItemDelegate
RowLayout{
Label{
Expand Down Expand Up @@ -71,9 +85,6 @@ Item{
Behavior on opacity { NumberAnimation { duration: expanded ? 250 : 1000; easing.type: Easing.OutQuint } }

delegate: ItemDelegate {
Component.onCompleted:{
console.log("delegate: "+this.width)
}
height: delegateHeight
ColumnLayout{
Layout.fillWidth:true
Expand Down Expand Up @@ -187,4 +198,28 @@ Item{
} // ListView
} // ColumnLayout

DialogTransactionDetails {
id: dialogTransactionDetails

readonly property real maxHeight: expanded ? 590 : 370

anchors.centerIn: Overlay.overlay
width: applicationWindow.width > 640 ? 640 - 40 : applicationWindow.width - 40
height: applicationWindow.height > maxHeight ? maxHeight - 40 : applicationWindow.height - 40
Behavior on height { NumberAnimation { duration: 1000; easing.type: Easing.OutQuint } }

modal: true
focus: true

date: listTransactions.currentItem !== null ? listTransactions.currentItem.modelDate : ""
status: listTransactions.currentItem !== null ? listTransactions.currentItem.modelStatus : 0
type: listTransactions.currentItem !== null ? listTransactions.currentItem.modelType : 0
amount: modelData.amount !== null ? modelData.amount : ""
hoursReceived: listTransactions.currentItem !== null ? listTransactions.currentItem.modelHoursReceived : 1
hoursBurned: listTransactions.currentItem !== null ? listTransactions.currentItem.modelHoursBurned : 1
transactionID: modelData.transactionId !== null ? modelData.transactionId : ""
modelInputs: listTransactions.currentItem !== null ? listTransactions.currentItem.modelInputs : null
modelOutputs: listTransactions.currentItem !== null ? listTransactions.currentItem.modelOutputs : null
}

}
5 changes: 3 additions & 2 deletions src/ui/TransactionDetails.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Item {
enum Type {
Send,
Receive,
Internal
Internal,
Generic
}

implicitHeight: 80 + rowLayoutBasicDetails.height + (expanded ? rowLayoutMoreDetails.height : 0)
Expand Down Expand Up @@ -122,7 +123,7 @@ Item {
Layout.topMargin: -10
Layout.rightMargin: 20
Image {
source: "qrc:/images/resources/images/icons/send-" + (type === TransactionDetails.Type.Receive ? "blue" : "amber") + ".svg"
source: "qrc:/images/resources/images/icons/send-" + (type === TransactionDetails.Type.Receive || type === TransactionDetails.Type.Generic ? "blue" : "amber") + ".svg"
sourceSize: "72x72"
fillMode: Image.PreserveAspectFit
mirror: type === TransactionDetails.Type.Receive
Expand Down

0 comments on commit 8570750

Please sign in to comment.