WIP: blockchain.transaction.yyy JSON RPC implementations #78

Merged
moodyjon merged 12 commits from blockchain_tx_rpc1 into master 2022-12-06 22:14:28 +01:00
2 changed files with 12 additions and 8 deletions
Showing only changes of commit 6965e64a8b - Show all commits

View file

@ -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)

View file

@ -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(&note.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(&note.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)