parent
bb276b53aa
commit
31a97d5c09
1 changed files with 40 additions and 30 deletions
70
rpcserver.go
70
rpcserver.go
|
@ -681,26 +681,28 @@ func handleGetRawTransaction(s *rpcServer, cmd btcjson.Cmd, walletNotification c
|
||||||
// TODO: check error code. tx is not checked before
|
// TODO: check error code. tx is not checked before
|
||||||
// this point.
|
// this point.
|
||||||
txSha, _ := btcwire.NewShaHashFromStr(c.Txid)
|
txSha, _ := btcwire.NewShaHashFromStr(c.Txid)
|
||||||
txList, err := s.server.db.FetchTxBySha(txSha)
|
var mtx *btcwire.MsgTx
|
||||||
if err != nil || len(txList) == 0 {
|
var blksha *btcwire.ShaHash
|
||||||
log.Errorf("RPCS: Error fetching tx: %v", err)
|
tx, err := s.server.txMemPool.FetchTransaction(txSha)
|
||||||
return nil, btcjson.ErrNoTxInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
lastTx := len(txList) - 1
|
|
||||||
txS := txList[lastTx].Tx
|
|
||||||
blksha := txList[lastTx].BlkSha
|
|
||||||
blk, err := s.server.db.FetchBlockBySha(blksha)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("RPCS: Error fetching sha: %v", err)
|
txList, err := s.server.db.FetchTxBySha(txSha)
|
||||||
return nil, btcjson.ErrBlockNotFound
|
if err != nil || len(txList) == 0 {
|
||||||
}
|
log.Errorf("RPCS: Error fetching tx: %v", err)
|
||||||
idx := blk.Height()
|
return nil, btcjson.ErrNoTxInfo
|
||||||
|
}
|
||||||
|
|
||||||
txOutList := txS.TxOut
|
lastTx := len(txList) - 1
|
||||||
|
mtx = txList[lastTx].Tx
|
||||||
|
|
||||||
|
blksha = txList[lastTx].BlkSha
|
||||||
|
} else {
|
||||||
|
mtx = tx.MsgTx()
|
||||||
|
}
|
||||||
|
|
||||||
|
txOutList := mtx.TxOut
|
||||||
voutList := make([]btcjson.Vout, len(txOutList))
|
voutList := make([]btcjson.Vout, len(txOutList))
|
||||||
|
|
||||||
txInList := txS.TxIn
|
txInList := mtx.TxIn
|
||||||
vinList := make([]btcjson.Vin, len(txInList))
|
vinList := make([]btcjson.Vin, len(txInList))
|
||||||
|
|
||||||
for i, v := range txInList {
|
for i, v := range txInList {
|
||||||
|
@ -730,26 +732,34 @@ func handleGetRawTransaction(s *rpcServer, cmd btcjson.Cmd, walletNotification c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, maxidx, err := s.server.db.NewestSha()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("RPCS: Cannot get newest sha: %v", err)
|
|
||||||
return nil, btcjson.ErrNoNewestBlockInfo
|
|
||||||
}
|
|
||||||
confirmations := uint64(1 + maxidx - idx)
|
|
||||||
|
|
||||||
blockHeader := &blk.MsgBlock().Header
|
|
||||||
txReply := btcjson.TxRawResult{
|
txReply := btcjson.TxRawResult{
|
||||||
Txid: c.Txid,
|
Txid: c.Txid,
|
||||||
Vout: voutList,
|
Vout: voutList,
|
||||||
Vin: vinList,
|
Vin: vinList,
|
||||||
Version: txS.Version,
|
Version: mtx.Version,
|
||||||
LockTime: txS.LockTime,
|
LockTime: mtx.LockTime,
|
||||||
|
}
|
||||||
|
if blksha != nil {
|
||||||
|
blk, err := s.server.db.FetchBlockBySha(blksha)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("RPCS: Error fetching sha: %v", err)
|
||||||
|
return nil, btcjson.ErrBlockNotFound
|
||||||
|
}
|
||||||
|
idx := blk.Height()
|
||||||
|
|
||||||
|
_, maxidx, err := s.server.db.NewestSha()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("RPCS: Cannot get newest sha: %v", err)
|
||||||
|
return nil, btcjson.ErrNoNewestBlockInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
blockHeader := &blk.MsgBlock().Header
|
||||||
// This is not a typo, they are identical in
|
// This is not a typo, they are identical in
|
||||||
// bitcoind as well.
|
// bitcoind as well.
|
||||||
Time: blockHeader.Timestamp.Unix(),
|
txReply.Time = blockHeader.Timestamp.Unix()
|
||||||
Blocktime: blockHeader.Timestamp.Unix(),
|
txReply.Blocktime = blockHeader.Timestamp.Unix()
|
||||||
BlockHash: blksha.String(),
|
txReply.BlockHash = blksha.String()
|
||||||
Confirmations: confirmations,
|
txReply.Confirmations = uint64(1 + maxidx - idx)
|
||||||
}
|
}
|
||||||
return txReply, nil
|
return txReply, nil
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue