Return addresses from socket.io getDetailedTransaction

This commit is contained in:
Martin Boehm 2018-02-23 14:44:14 +01:00
parent 531da09227
commit 682b0d22f1

View File

@ -264,13 +264,13 @@ type resTx struct {
BlockTimestamp int64 `json:"blockTimestamp"` BlockTimestamp int64 `json:"blockTimestamp"`
Version int `json:"version"` Version int `json:"version"`
Hash string `json:"hash"` Hash string `json:"hash"`
Locktime int `json:"locktime"` Locktime int `json:"locktime,omitempty"`
Size int `json:"size,omitempty"` Size int `json:"size,omitempty"`
Inputs []txInputs `json:"inputs"` Inputs []txInputs `json:"inputs"`
InputSatoshis int64 `json:"inputSatoshis"` InputSatoshis int64 `json:"inputSatoshis,omitempty"`
Outputs []txOutputs `json:"outputs"` Outputs []txOutputs `json:"outputs"`
OutputSatoshis int64 `json:"outputSatoshis"` OutputSatoshis int64 `json:"outputSatoshis,omitempty"`
FeeSatoshis int64 `json:"feeSatoshis"` FeeSatoshis int64 `json:"feeSatoshis,omitempty"`
} }
type addressHistoryItem struct { type addressHistoryItem struct {
@ -387,7 +387,7 @@ func (s *SocketIoServer) getAddressHistory(addr []string, rr *reqRange) (res res
} }
for _, vout := range tx.Vout { for _, vout := range tx.Vout {
ao := txOutputs{ ao := txOutputs{
Satoshis: int64(vout.Value * 10E8), Satoshis: int64(vout.Value * 1E8),
Script: vout.ScriptPubKey.Hex, Script: vout.ScriptPubKey.Hex,
ScriptAsm: vout.ScriptPubKey.Asm, ScriptAsm: vout.ScriptPubKey.Asm,
SpentIndex: int(vout.N), SpentIndex: int(vout.N),
@ -587,22 +587,36 @@ func (s *SocketIoServer) getDetailedTransaction(txid string) (res resultGetDetai
Sequence: int64(vin.Sequence), Sequence: int64(vin.Sequence),
OutputIndex: int(vin.Vout), OutputIndex: int(vin.Vout),
} }
otx, err := s.chain.GetTransaction(vin.Txid)
if err != nil {
return res, err
}
if len(otx.Vout) > int(vin.Vout) {
vout := otx.Vout[vin.Vout]
if len(vout.ScriptPubKey.Addresses) == 1 {
ai.Address = vout.ScriptPubKey.Addresses[0]
}
ai.Satoshis += int64(vout.Value * 1E8)
}
hi = append(hi, ai) hi = append(hi, ai)
} }
for _, vout := range tx.Vout { for _, vout := range tx.Vout {
ao := txOutputs{ ao := txOutputs{
Satoshis: int64(vout.Value * 10E8), Satoshis: int64(vout.Value * 1E8),
Script: vout.ScriptPubKey.Hex, Script: vout.ScriptPubKey.Hex,
ScriptAsm: vout.ScriptPubKey.Asm, ScriptAsm: vout.ScriptPubKey.Asm,
SpentIndex: int(vout.N), SpentIndex: int(vout.N),
} }
if len(vout.ScriptPubKey.Addresses) == 1 {
ao.Address = vout.ScriptPubKey.Addresses[0]
}
ho = append(ho, ao) ho = append(ho, ao)
} }
var height int var height int
if tx.Confirmations == 0 { if tx.Confirmations == 0 {
height = -1 height = -1
} else { } else {
height = int(bestheight) - int(tx.Confirmations) height = int(bestheight) - int(tx.Confirmations) + 1
} }
res.Result = txToResTx(tx, height, hi, ho) res.Result = txToResTx(tx, height, hi, ho)
return return