WIP: blockchain.transaction.yyy JSON RPC implementations #78
2 changed files with 12 additions and 8 deletions
|
@ -273,12 +273,10 @@ func TestHeadersSubscribe(t *testing.T) {
|
||||||
t.Errorf("decode err: %v", err)
|
t.Errorf("decode err: %v", err)
|
||||||
}
|
}
|
||||||
note1 := headerNotification{
|
note1 := headerNotification{
|
||||||
HeightHash: internal.HeightHash{Height: 500},
|
HeightHash: internal.HeightHash{Height: 500, BlockHeader: header500},
|
||||||
blockHeader: [112]byte{},
|
|
||||||
blockHeaderElectrum: nil,
|
blockHeaderElectrum: nil,
|
||||||
blockHeaderStr: "",
|
blockHeaderStr: "",
|
||||||
}
|
}
|
||||||
copy(note1.blockHeader[:], header500)
|
|
||||||
t.Logf("sending notification")
|
t.Logf("sending notification")
|
||||||
sm.doNotify(note1)
|
sm.doNotify(note1)
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
|
|
||||||
type headerNotification struct {
|
type headerNotification struct {
|
||||||
internal.HeightHash
|
internal.HeightHash
|
||||||
blockHeader [HEADER_SIZE]byte
|
|
||||||
blockHeaderElectrum *BlockHeaderElectrum
|
blockHeaderElectrum *BlockHeaderElectrum
|
||||||
blockHeaderStr string
|
blockHeaderStr string
|
||||||
}
|
}
|
||||||
|
@ -67,7 +66,7 @@ func (s *session) doNotify(notification interface{}) {
|
||||||
if s.headersSubRaw {
|
if s.headersSubRaw {
|
||||||
header := note.blockHeaderStr
|
header := note.blockHeaderStr
|
||||||
if len(header) == 0 {
|
if len(header) == 0 {
|
||||||
header = hex.EncodeToString(note.blockHeader[:])
|
header = hex.EncodeToString(note.BlockHeader[:])
|
||||||
}
|
}
|
||||||
params = &HeadersSubscribeRawResp{
|
params = &HeadersSubscribeRawResp{
|
||||||
Hex: header,
|
Hex: header,
|
||||||
|
@ -76,7 +75,7 @@ func (s *session) doNotify(notification interface{}) {
|
||||||
} else {
|
} else {
|
||||||
header := note.blockHeaderElectrum
|
header := note.blockHeaderElectrum
|
||||||
if header == nil { // not initialized
|
if header == nil { // not initialized
|
||||||
header = newBlockHeaderElectrum(¬e.blockHeader, uint32(heightHash.Height))
|
header = newBlockHeaderElectrum((*[HEADER_SIZE]byte)(note.BlockHeader), uint32(heightHash.Height))
|
||||||
}
|
}
|
||||||
params = header
|
params = header
|
||||||
}
|
}
|
||||||
|
@ -326,6 +325,11 @@ func (sm *sessionManager) hashXSubscribe(sess *session, hashX []byte, original s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *sessionManager) doNotify(notification interface{}) {
|
func (sm *sessionManager) doNotify(notification interface{}) {
|
||||||
|
switch notification.(type) {
|
||||||
|
case internal.HeightHash:
|
||||||
|
// The HeightHash notification translates to headerNotification.
|
||||||
|
notification = &headerNotification{HeightHash: notification.(internal.HeightHash)}
|
||||||
|
}
|
||||||
sm.sessionsMut.RLock()
|
sm.sessionsMut.RLock()
|
||||||
var subsCopy sessionMap
|
var subsCopy sessionMap
|
||||||
switch notification.(type) {
|
switch notification.(type) {
|
||||||
|
@ -333,8 +337,10 @@ func (sm *sessionManager) doNotify(notification interface{}) {
|
||||||
note, _ := notification.(headerNotification)
|
note, _ := notification.(headerNotification)
|
||||||
subsCopy = sm.headerSubs
|
subsCopy = sm.headerSubs
|
||||||
if len(subsCopy) > 0 {
|
if len(subsCopy) > 0 {
|
||||||
note.blockHeaderElectrum = newBlockHeaderElectrum(¬e.blockHeader, uint32(note.Height))
|
hdr := [HEADER_SIZE]byte{}
|
||||||
note.blockHeaderStr = hex.EncodeToString(note.blockHeader[:])
|
copy(hdr[:], note.BlockHeader)
|
||||||
|
note.blockHeaderElectrum = newBlockHeaderElectrum(&hdr, uint32(note.Height))
|
||||||
|
note.blockHeaderStr = hex.EncodeToString(note.BlockHeader[:])
|
||||||
}
|
}
|
||||||
case hashXNotification:
|
case hashXNotification:
|
||||||
note, _ := notification.(hashXNotification)
|
note, _ := notification.(hashXNotification)
|
||||||
|
|
Loading…
Reference in a new issue