Refactor in preparation for socket.io getDetailedTransaction method
parent
af0e85ce43
commit
aac52a3fcb
|
@ -142,6 +142,8 @@ var onMessageHandlers = map[string]func(*SocketIoServer, json.RawMessage) (inter
|
||||||
"\"getInfo\"": func(s *SocketIoServer, params json.RawMessage) (rv interface{}, err error) {
|
"\"getInfo\"": func(s *SocketIoServer, params json.RawMessage) (rv interface{}, err error) {
|
||||||
return s.getInfo()
|
return s.getInfo()
|
||||||
},
|
},
|
||||||
|
// getDetailedTransaction
|
||||||
|
// sendTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SocketIoServer) onMessage(c *gosocketio.Channel, req map[string]json.RawMessage) interface{} {
|
func (s *SocketIoServer) onMessage(c *gosocketio.Channel, req map[string]json.RawMessage) interface{} {
|
||||||
|
@ -223,7 +225,7 @@ type addressHistoryIndexes struct {
|
||||||
OutputIndexes []int `json:"outputIndexes"`
|
OutputIndexes []int `json:"outputIndexes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type addressHistoryInputs struct {
|
type txInputs struct {
|
||||||
PrevTxID string `json:"prevTxId"`
|
PrevTxID string `json:"prevTxId"`
|
||||||
OutputIndex int `json:"outputIndex"`
|
OutputIndex int `json:"outputIndex"`
|
||||||
Script string `json:"script"`
|
Script string `json:"script"`
|
||||||
|
@ -233,7 +235,7 @@ type addressHistoryInputs struct {
|
||||||
Satoshis int64 `json:"satoshis"`
|
Satoshis int64 `json:"satoshis"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type addressHistoryOutputs struct {
|
type txOutputs struct {
|
||||||
Satoshis int64 `json:"satoshis"`
|
Satoshis int64 `json:"satoshis"`
|
||||||
Script string `json:"script"`
|
Script string `json:"script"`
|
||||||
ScriptAsm string `json:"scriptAsm"`
|
ScriptAsm string `json:"scriptAsm"`
|
||||||
|
@ -243,25 +245,27 @@ type addressHistoryOutputs struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type resTx struct {
|
||||||
|
Hex string `json:"hex"`
|
||||||
|
BlockHash string `json:"blockHash"`
|
||||||
|
Height int `json:"height"`
|
||||||
|
BlockTimestamp int64 `json:"blockTimestamp"`
|
||||||
|
Version int `json:"version"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Locktime int `json:"locktime"`
|
||||||
|
Size int `json:"size"`
|
||||||
|
Inputs []txInputs `json:"inputs"`
|
||||||
|
InputSatoshis int64 `json:"inputSatoshis"`
|
||||||
|
Outputs []txOutputs `json:"outputs"`
|
||||||
|
OutputSatoshis int64 `json:"outputSatoshis"`
|
||||||
|
FeeSatoshis int64 `json:"feeSatoshis"`
|
||||||
|
}
|
||||||
|
|
||||||
type addressHistoryItem struct {
|
type addressHistoryItem struct {
|
||||||
Addresses map[string]addressHistoryIndexes `json:"addresses"`
|
Addresses map[string]addressHistoryIndexes `json:"addresses"`
|
||||||
Satoshis int `json:"satoshis"`
|
Satoshis int `json:"satoshis"`
|
||||||
Confirmations int `json:"confirmations"`
|
Confirmations int `json:"confirmations"`
|
||||||
Tx struct {
|
Tx resTx `json:"tx"`
|
||||||
Hex string `json:"hex"`
|
|
||||||
BlockHash string `json:"blockHash"`
|
|
||||||
Height int `json:"height"`
|
|
||||||
BlockTimestamp int64 `json:"blockTimestamp"`
|
|
||||||
Version int `json:"version"`
|
|
||||||
Hash string `json:"hash"`
|
|
||||||
Locktime int `json:"locktime"`
|
|
||||||
Size int `json:"size"`
|
|
||||||
Inputs []addressHistoryInputs `json:"inputs"`
|
|
||||||
InputSatoshis int64 `json:"inputSatoshis"`
|
|
||||||
Outputs []addressHistoryOutputs `json:"outputs"`
|
|
||||||
OutputSatoshis int64 `json:"outputSatoshis"`
|
|
||||||
FeeSatoshis int64 `json:"feeSatoshis"`
|
|
||||||
} `json:"tx"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type resultGetAddressHistory struct {
|
type resultGetAddressHistory struct {
|
||||||
|
@ -293,6 +297,23 @@ func stringInSlice(a string, list []string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func txToResTx(tx *bchain.Tx, height int, hi []txInputs, ho []txOutputs) resTx {
|
||||||
|
return resTx{
|
||||||
|
BlockHash: tx.BlockHash,
|
||||||
|
BlockTimestamp: tx.Blocktime,
|
||||||
|
// FeeSatoshis,
|
||||||
|
Hash: tx.Txid,
|
||||||
|
Height: height,
|
||||||
|
Hex: tx.Hex,
|
||||||
|
Inputs: hi,
|
||||||
|
// InputSatoshis,
|
||||||
|
Locktime: int(tx.LockTime),
|
||||||
|
Outputs: ho,
|
||||||
|
// OutputSatoshis,
|
||||||
|
Version: int(tx.Version),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SocketIoServer) getAddressHistory(addr []string, rr *reqRange) (res resultGetAddressHistory, err error) {
|
func (s *SocketIoServer) getAddressHistory(addr []string, rr *reqRange) (res resultGetAddressHistory, err error) {
|
||||||
txids, err := s.getAddressTxids(addr, rr)
|
txids, err := s.getAddressTxids(addr, rr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -313,10 +334,10 @@ func (s *SocketIoServer) getAddressHistory(addr []string, rr *reqRange) (res res
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
ads := make(map[string]addressHistoryIndexes)
|
ads := make(map[string]addressHistoryIndexes)
|
||||||
hi := make([]addressHistoryInputs, 0)
|
hi := make([]txInputs, 0)
|
||||||
ho := make([]addressHistoryOutputs, 0)
|
ho := make([]txOutputs, 0)
|
||||||
for _, vin := range tx.Vin {
|
for _, vin := range tx.Vin {
|
||||||
ai := addressHistoryInputs{
|
ai := txInputs{
|
||||||
Script: vin.ScriptSig.Hex,
|
Script: vin.ScriptSig.Hex,
|
||||||
ScriptAsm: vin.ScriptSig.Asm,
|
ScriptAsm: vin.ScriptSig.Asm,
|
||||||
Sequence: int64(vin.Sequence),
|
Sequence: int64(vin.Sequence),
|
||||||
|
@ -353,7 +374,7 @@ func (s *SocketIoServer) getAddressHistory(addr []string, rr *reqRange) (res res
|
||||||
hi = append(hi, ai)
|
hi = append(hi, ai)
|
||||||
}
|
}
|
||||||
for _, vout := range tx.Vout {
|
for _, vout := range tx.Vout {
|
||||||
ao := addressHistoryOutputs{
|
ao := txOutputs{
|
||||||
Satoshis: int64(vout.Value * 10E8),
|
Satoshis: int64(vout.Value * 10E8),
|
||||||
Script: vout.ScriptPubKey.Hex,
|
Script: vout.ScriptPubKey.Hex,
|
||||||
ScriptAsm: vout.ScriptPubKey.Asm,
|
ScriptAsm: vout.ScriptPubKey.Asm,
|
||||||
|
@ -379,18 +400,7 @@ func (s *SocketIoServer) getAddressHistory(addr []string, rr *reqRange) (res res
|
||||||
ahi := addressHistoryItem{}
|
ahi := addressHistoryItem{}
|
||||||
ahi.Addresses = ads
|
ahi.Addresses = ads
|
||||||
ahi.Confirmations = int(tx.Confirmations)
|
ahi.Confirmations = int(tx.Confirmations)
|
||||||
ahi.Tx.BlockHash = tx.BlockHash
|
ahi.Tx = txToResTx(tx, int(bestheight)-int(tx.Confirmations), hi, ho)
|
||||||
ahi.Tx.BlockTimestamp = tx.Blocktime
|
|
||||||
// ahi.Tx.FeeSatoshis
|
|
||||||
ahi.Tx.Hash = tx.Txid
|
|
||||||
ahi.Tx.Height = int(bestheight) - ahi.Confirmations
|
|
||||||
ahi.Tx.Hex = tx.Hex
|
|
||||||
ahi.Tx.Inputs = hi
|
|
||||||
// ahi.Tx.InputSatoshis
|
|
||||||
ahi.Tx.Locktime = int(tx.LockTime)
|
|
||||||
ahi.Tx.Outputs = ho
|
|
||||||
// ahi.Tx.OutputSatoshis
|
|
||||||
ahi.Tx.Version = int(tx.Version)
|
|
||||||
res.Result.Items = append(res.Result.Items, ahi)
|
res.Result.Items = append(res.Result.Items, ahi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue