2020-01-13 10:21:44 +00:00
|
|
|
package result
|
2019-02-20 17:39:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core"
|
2020-01-14 12:32:07 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/block"
|
2019-02-20 17:39:32 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2019-09-16 13:08:00 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2019-02-20 17:39:32 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TransactionOutputRaw is used as a wrapper to represents
|
|
|
|
// a Transaction.
|
|
|
|
type TransactionOutputRaw struct {
|
|
|
|
*transaction.Transaction
|
|
|
|
TxHash util.Uint256 `json:"txid"`
|
|
|
|
Size int `json:"size"`
|
|
|
|
SysFee util.Fixed8 `json:"sys_fee"`
|
|
|
|
NetFee util.Fixed8 `json:"net_fee"`
|
2020-02-20 16:31:16 +00:00
|
|
|
Blockhash util.Uint256 `json:"blockhash,omitempty"`
|
|
|
|
Confirmations int `json:"confirmations,omitempty"`
|
|
|
|
Timestamp uint32 `json:"blocktime,omitempty"`
|
2019-02-20 17:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTransactionOutputRaw returns a new ransactionOutputRaw object.
|
2020-01-14 12:32:07 +00:00
|
|
|
func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, chain core.Blockchainer) TransactionOutputRaw {
|
2019-02-20 17:39:32 +00:00
|
|
|
// confirmations formula
|
2020-01-15 08:29:50 +00:00
|
|
|
confirmations := int(chain.BlockHeight() - header.Base.Index + 1)
|
2019-02-20 17:39:32 +00:00
|
|
|
// set index position
|
|
|
|
for i, o := range tx.Outputs {
|
|
|
|
o.Position = i
|
|
|
|
}
|
|
|
|
return TransactionOutputRaw{
|
|
|
|
Transaction: tx,
|
|
|
|
TxHash: tx.Hash(),
|
2019-09-16 13:08:00 +00:00
|
|
|
Size: io.GetVarSize(tx),
|
2019-02-20 17:39:32 +00:00
|
|
|
SysFee: chain.SystemFee(tx),
|
|
|
|
NetFee: chain.NetworkFee(tx),
|
|
|
|
Blockhash: header.Hash(),
|
|
|
|
Confirmations: confirmations,
|
|
|
|
Timestamp: header.Timestamp,
|
|
|
|
}
|
|
|
|
}
|