Giter Site home page Giter Site logo

go-electrum's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

go-electrum's Issues

Implement masternode functions

Implement masternode function to support protocol v1.4.

  • masternode.announce.broadcast()
  • masternode.list()
  • protx.diff()
  • protx.info()

Batch processing ?

Hi,

Would it be possible to enable batching of calls, I am currently looking at electrs (rust implementation of electrumx) which it seems does support batching now (and previously did not).

And I believe that the original electrumx also supports batching.

This would be really handy instead of iteration of a collection and calling an rpc - X amount of times.

Thanks in advance

Unmarshaling error from response fails with: `cannot unmarshal object into Go struct field response.error of type string`

Responses unmarshaling don't work for errors returned by ElectrumX and Fulcrum servers.

I called the GetBlockHeader function with a block height that doesn't exist.

func (s *Client) GetBlockHeader(ctx context.Context, height uint32, checkpointHeight ...uint32) (*GetBlockHeaderResult, error) {

I observed the following error being returned:

Unmarshal received message failed: json: cannot unmarshal object into Go struct field response.error of type string

The reason for that is that ElectrumX, Fulcrum, and Electrs/Esplora are inconsistent when it comes to the error response format.
Please see the examples (for Bitcoin Testnet servers):

ElectrumX

echo '{"jsonrpc": "2.0", "method": "server.version", "id": 0}' | netcat 49.12.127.114 10068
{"jsonrpc":"2.0","result":["ElectrumX 1.16.0","1.4"],"id":0}

✗ echo '{"jsonrpc": "2.0", "method": "blockchain.block.header", "params": [4294967295], "id": 0}' | netcat 49.12.127.114 10068
{"jsonrpc":"2.0","error":{"code":1,"message":"height 4,294,967,295 out of range"},"id":0}

Fulcrum

echo '{"jsonrpc": "2.0", "method": "server.version", "id": 0}' | netcat 203.132.94.196 51001
{"id":0,"jsonrpc":"2.0","result":["Fulcrum 1.8.2","1.4"]}

✗ echo '{"jsonrpc": "2.0", "method": "blockchain.block.header", "params": [4294967295], "id": 0}' | netcat 203.132.94.196 51001
{"error":{"code":1,"message":"Invalid height"},"id":0,"jsonrpc":"2.0"}

Electrs/Esplora

echo '{"jsonrpc": "2.0", "method": "server.version", "id": 0}' | netcat 35.225.54.191 50001
{"id":0,"jsonrpc":"2.0","result":["electrs-esplora 0.4.1","1.4"]}

✗ echo '{"jsonrpc": "2.0", "method": "blockchain.block.header", "params": [4294967295], "id": 0}' | netcat 35.225.54.191 50001
{"error":"missing header","id":0,"jsonrpc":"2.0"}

The client handles correctly only the response returned by the Electrs/Esplora server, as only this response format can be unmarshaled to the response struct that assumes a string as an error:

type response struct {
ID uint64 `json:"id"`
Method string `json:"method"`
Error string `json:"error"`
}

Panic in listenPush

When working on testnet and mainnet integration tests in keep-network/keep-core#3599 we stumbled upon random panics when running tests:

=== FAIL: pkg/bitcoin/electrum TestGetLatestBlockHeight_Integration (unknown)
panic: assignment to entry in nil map

goroutine 511 [running]:
github.com/checksum0/go-electrum/electrum.(*Client).listenPush(0xc00036cc40, {0x120e9eb, 0x1c})
	/go/pkg/mod/github.com/keep-network/[email protected]/electrum/network.go:264 +0x74
github.com/checksum0/go-electrum/electrum.(*Client).SubscribeHeaders.func1()
	/go/pkg/mod/github.com/keep-network/[email protected]/electrum/subscribe.go:40 +0x36
created by github.com/checksum0/go-electrum/electrum.(*Client).SubscribeHeaders
	/go/pkg/mod/github.com/keep-network/[email protected]/electrum/subscribe.go:39 +0xfd

=== FAIL: pkg/bitcoin/electrum TestGetLatestBlockHeight_Integration/electrs-esplora_tcp_get (unknown)

=== FAIL: pkg/bitcoin/electrum TestGetLatestBlockHeight_Integration/electrumx_wss_get (unknown)
panic: assignment to entry in nil map

goroutine 511 [running]:
github.com/checksum0/go-electrum/electrum.(*Client).listenPush(0xc00036cc40, {0x[120](https://github.com/keep-network/keep-core/actions/runs/5215398427/jobs/9424824985?pr=3599#step:5:121)e9eb, 0x1c})
	/go/pkg/mod/github.com/keep-network/[email protected]/electrum/network.go:264 +0x74
github.com/checksum0/go-electrum/electrum.(*Client).SubscribeHeaders.func1()
	/go/pkg/mod/github.com/keep-network/[email protected]/electrum/subscribe.go:40 +0x36
created by github.com/checksum0/go-electrum/electrum.(*Client).SubscribeHeaders
	/go/pkg/mod/github.com/keep-network/[email protected]/electrum/subscribe.go:39 +0xfd

I think the problem lies in how the library handles closing the connection.

SubscribeHeaders creates a goroutine that writes to s.pushHandlers map in the listenPush function. If Shutdown() is called at the same time, unfortunate ordering of calls can lead to clearing s.pushHandlers = nil and then attempting to s.pushHandlers[method] = append(s.pushHandlers[method], c).

Separately from this issue, I think the goroutines created in SubscribeHeaders are leaking given there is no clear exit signal for them - the channel returned by listenPush is never closed and they are stuck on reading.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.