Skip to content

Commit

Permalink
dcrutil.Amount
Browse files Browse the repository at this point in the history
  • Loading branch information
papacarp committed Jun 1, 2018
1 parent 314827d commit 064918e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions db/dcrsqlite/apisource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"database/sql"
"encoding/hex"
"fmt"
"math"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -1136,7 +1135,7 @@ func (db *wiredDB) GetExplorerTx(txid string) *explorer.TxInfo {
for i, vin := range txraw.Vin {
var addresses []string
// ValueIn is a temporary fix until amountIn is correct from dcrd call
var ValueIn int64
var ValueIn dcrutil.Amount
if !(vin.IsCoinBase() || (vin.IsStakeBase() && i == 0)) {
var addrs []string
addrs, ValueIn, err = txhelpers.OutPointAddresses(&msgTx.TxIn[i].PreviousOutPoint, db.client, db.params)
Expand All @@ -1146,19 +1145,19 @@ func (db *wiredDB) GetExplorerTx(txid string) *explorer.TxInfo {
}
addresses = addrs
} else {
ValueIn = int64(math.Round(vin.AmountIn * 100000000.0))
ValueIn, _ = dcrutil.NewAmount(vin.AmountIn)
}
inputs = append(inputs, explorer.Vin{
Vin: &dcrjson.Vin{
Txid: vin.Txid,
Coinbase: vin.Coinbase,
Stakebase: vin.Stakebase,
Vout: vin.Vout,
AmountIn: dcrutil.Amount(ValueIn).ToCoin(),
AmountIn: ValueIn.ToCoin(),
BlockHeight: vin.BlockHeight,
},
Addresses: addresses,
FormattedAmount: humanize.Commaf(dcrutil.Amount(ValueIn).ToCoin()),
FormattedAmount: humanize.Commaf(ValueIn.ToCoin()),
})
}
tx.Vin = inputs
Expand Down
4 changes: 2 additions & 2 deletions txhelpers/txhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func BlockReceivesToAddresses(block *dcrutil.Block, addrs map[string]TxAction,

// OutPointAddresses gets the addresses paid to by a transaction output.
func OutPointAddresses(outPoint *wire.OutPoint, c RawTransactionGetter,
params *chaincfg.Params) ([]string, int64, error) {
params *chaincfg.Params) ([]string, dcrutil.Amount, error) {
// The addresses are encoded in the pkScript, so we need to get the
// raw transaction, and the TxOut that contains the pkScript.
prevTx, err := c.GetRawTransaction(&outPoint.Hash)
Expand All @@ -403,7 +403,7 @@ func OutPointAddresses(outPoint *wire.OutPoint, c RawTransactionGetter,
if err != nil {
return nil, 0, fmt.Errorf("ExtractPkScriptAddrs: %v", err.Error())
}
value := txOut.Value
value := dcrutil.Amount(txOut.Value)
addresses := make([]string, 0, len(txAddrs))
for _, txAddr := range txAddrs {
addr := txAddr.EncodeAddress()
Expand Down

0 comments on commit 064918e

Please sign in to comment.