Commit Graph

101 Commits

Author SHA1 Message Date
bruwbird
bbb6967247
btcclient+btcjson: feeRate to BTC/kvB
defaultMaxFeeRate was set to 1e8 / 10(sat/kb) as a parameter.
But BTC/kvB is the expected value, so the units was wrong.
This commit updates defaultMaxFeeRate to BTC/kvB and sets it to 0.1,
which is the default value of Bitcoin Core.
This commit also updates the comment to reflect the change.

Because maxFeeRate sanity check has been added in
bitcoin core v27.0 or later,
sendrawtransaction cannot be executed without this change.
2024-03-27 17:58:12 +09:00
yyforyongyu
36683e0b96
rpcclient: define specific errors for chain backends
This commit adds detailed errors for all possible errors returned from
`sendrawtransaction` or `testmempoolaccept`, enabling upstream callers
to have refined control over the actions to be taken.
2024-03-18 23:08:47 +08:00
theedtron
b66f5b8379
multi: fix ioutil deprecated function
update i/o functions to use os / io package functions instead
2024-03-08 17:41:41 -08:00
yyforyongyu
34721f02c1
rpcclient: replace ErrBitcoindVersion with ErrBackendVersion 2024-02-28 03:38:48 +08:00
yyforyongyu
4cf49bd72c
multi: turn BackendVersion into an interface
This commit adds a new interface, `BackendVersion`, to support checking
versions for multiple both btcd and bitcoind. Once neutrino version is
also pinned here, it should also be checked.
2024-02-27 23:04:47 +08:00
yyforyongyu
9e6070a707
rpcclient: start tracking btcd version 2024-02-27 23:04:46 +08:00
yyforyongyu
0d52a890f2
rpcclient: handle backend versioning in one file 2024-02-27 23:04:46 +08:00
yyforyongyu
a033b0d6e7
rpcclient+integration: add new method GetTxSpendingPrevOut 2024-02-27 23:04:46 +08:00
yyforyongyu
5f71df165e
rpcclient: track bitcoind version 24.0.0
We need this for `gettxspendingprevout`.
2024-02-27 22:58:33 +08:00
ly
c4b1448212
feat: Expose newFutureError for developer friendliness 2024-01-25 19:24:23 -08:00
yyforyongyu
e8a5a55379
rpcclient: make sure batch requests are GCed
This commit makes sure the batch requests are always GCed before sending
back the responses for them. In particular,
- `removeRequest` didn't remove the item from `batchList`, which is now
  fixed.
- `Send` didn't remove the request from `requestMap`, which is now fixed
  by using `removeRequest`.
2024-01-19 18:56:22 +08:00
yyforyongyu
ef54c49df4
multi: map btcd mempool acceptance errors to bitcoind's testmempoolaccept
This commit creates a `RejectReasonMap` to map the errors returned from
`btcd` to bitcoind's `testmempoolaccept` so the `RejectReason` is
unified at the RPC level. To make sure the map keys are unique, the
error strings are modified in `btcd`.
2024-01-15 17:22:41 +08:00
yyforyongyu
c7e40280d5
rpcclient: support testmempoolaccept for bitcoind 2024-01-15 17:22:41 +08:00
yyforyongyu
889cdb4f66
multi: add more bitcoind versions to the BackendVersion
This commit adds bitcoind version 22.0 and 25.0 to our `BackendVersion`
set to handle the `testmempoolaccept` RPC calls. A unit test is added to
make sure the parser works as expected.
2024-01-15 17:22:40 +08:00
Olaoluwa Osuntokun
4ec8f016b9
rpcclient: fix race condition in doDisconnect
In this commit, we fix the following race condition:
```
==================
WARNING: DATA RACE
Write at 0x00c000216018 by goroutine 31:
  github.com/btcsuite/btcd/rpcclient.(*Client).wsReconnectHandler()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:736 +0x2aa
  github.com/btcsuite/btcd/rpcclient.New·dwrap·13()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1496 +0x39

Previous read at 0x00c000216018 by goroutine 29:
  github.com/btcsuite/btcd/rpcclient.(*Client).doDisconnect()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1079 +0x247
  github.com/btcsuite/btcd/rpcclient.(*Client).Disconnect()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1111 +0x47
  github.com/btcsuite/btcd/rpcclient.(*Client).wsInHandler()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:491 +0x1eb
  github.com/btcsuite/btcd/rpcclient.(*Client).start·dwrap·11()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1181 +0x39

Goroutine 31 (running) created at:
  github.com/btcsuite/btcd/rpcclient.New()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1496 +0xd77
  github.com/btcsuite/btcd/rpcclient.makeClient()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:268 +0x1f9
  github.com/btcsuite/btcd/rpcclient.TestClientConnectedToWSServerRunner.func2()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:164 +0x47
  testing.tRunner()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1306 +0x47

Goroutine 29 (finished) created at:
  github.com/btcsuite/btcd/rpcclient.(*Client).start()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1181 +0x2e4
  github.com/btcsuite/btcd/rpcclient.New()
      /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1493 +0xc51
  github.com/btcsuite/btcd/rpcclient.makeClient()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:268 +0x1f9
  github.com/btcsuite/btcd/rpcclient.TestClientConnectedToWSServerRunner.func2()
      /home/runner/work/btcd/btcd/rpcclient/chain_test.go:164 +0x47
  testing.tRunner()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1306 +0x47
```

This arises as in `wsReconnectHandler`, the mutex isn't held while the
`conn` pointer is modified.
2023-12-30 16:43:07 -08:00
xiaolou86
4171854739 Fix typos 2023-11-20 12:04:31 -05:00
Olaoluwa Osuntokun
f7e9fba086
Merge pull request #1918 from kcalvinalvin/2022-11-06-implement-getchaintips
blockchain, btcjson: Implement getchaintips rpc call
2023-11-14 17:16:15 -08:00
ClaytonNorthey92
d15dd71087 added tests for GetBestBlockHashAsync
now testing that GetBestBlockHashAsync sends the getbestblockhash command via websocket connection and that the channel returned can be used to send the response when it is received
2023-11-06 15:56:24 -05:00
ClaytonNorthey92
d988b86027 Added test for client.GetChainTxStatsAsync() in rpcclient. This sets up a test websocket server to run the tests. Also, ensure these are run within a timeout, since they rely on concurrency 2023-11-02 16:16:11 -04:00
ClaytonNorthey92
208800c5f4 Added tests for FutureGetBestBlockHashResult.Receive 2023-11-02 15:17:27 -04:00
yyforyongyu
3a8b851aaf
rpcclient: catch shutdown signal when sending requests 2023-09-04 12:04:32 +08:00
yyforyongyu
d62d537fb5
rpcclient: remove redundant params used in handleSendPostMessage 2023-09-04 12:04:32 +08:00
Calvin Kim
fc99e96b59 rpcclient, integration: Add test for getchaintips call
rpcclient now support calling the getchaintips rpc call.

getchaintips_test.go adds test for the getchaintips rpc call. The test
includes hard-coded blocks which the test will feed the node via rpc and
it'll check that the returned chain tips from the getchaintips call
are chaintips that we expect to be returned.
2023-07-16 16:03:50 +09:00
cui fliter
e160bb6922 multi: remove repetitive the
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-06-26 15:40:51 +08:00
Calvin Kim
ba5407615d multi: Run gofmt on the entire repository
The doc formatting changes introduced in the recent go version is
increasing the diff for all of the new commits.  Formatting it all in
this commit will help the readability of future PRs by reducing the
diff.
2023-06-21 22:31:09 +09:00
Olaoluwa Osuntokun
8fc2d707f6
Merge pull request #1862 from bhandras/rpccliet-fix2
rpcclient: fix missing return
2022-06-06 16:09:32 -07:00
Olaoluwa Osuntokun
1696c63888
Merge pull request #1844 from chappjc/getnewaddress-rpcclient-revert
rpcclient: add getnewaddresstype and revert breaking change
2022-06-06 16:08:50 -07:00
Andras Banki-Horvath
b2af7770e9
rpcclient: fix missing return 2022-06-03 14:58:20 +02:00
Andras Banki-Horvath
97313ac873
rpcclient: save the last error when retrying 2022-05-13 15:35:14 +02:00
Andras Banki-Horvath
9babf1fa08
rpcclient: fix backoff logic
This commit removes Sleep() from the rety handler so that the shutdown
request is always respected. Furthermore the maximum retry count is corrected.
2022-05-13 15:35:14 +02:00
Andras Banki-Horvath
966511246d
rpclient: fix masked error causing crash after max retries
This commit fixes the error that is masked inside the for loop's scope.
Previously after max retries the error didn't leave the for scope and
therefore httpResponse remained nil which in turn resulted in a crash.
2022-05-13 15:35:13 +02:00
Andras Banki-Horvath
ebed1927bf
rpcclient: fix formatting 2022-05-13 15:35:09 +02:00
Jonathan Chappelow
788fb8faf8 rpcclient: add getnewaddresstype and revert breaking change
This reverts the previous breaking change to the GetNewAddress and
GetRawChangeAddress rpcclient.Client methods, and adds the methods
GetNewAddressType and GetRawChangeAddressType for requesting
an address of a certain type.  This change allows the rpcclient package
to continue to work with versions of the btcwallet app that do not
recognize the address type parameter.
2022-04-14 11:25:56 -05:00
Torkel Rogstad
85b6f7ed2a rpcclient: add getzmqnotifications RPC 2022-04-09 07:46:07 -04:00
Jonathan Chappelow
7eaf360063 btcjson: add addresstype arg to getrawchangeaddress 2022-04-09 07:38:57 -04:00
Jonathan Chappelow
061aef98af btcjson: add addresstype arg to getnewaddress 2022-04-09 07:38:57 -04:00
Olaoluwa Osuntokun
caac0f821a
multi: update btcutil imports to point to new sub-module
In this commit, we update all the btcutil imports to point to the new
sub-module.

In the same commit, we also modify the recently added `btcutil/go.mod`
file as we need to continue pointing to the _old_ version of btcd, until
we merge this PR and push a new tag.
2022-01-10 18:44:58 -08:00
Matthew Bajorek
ec9ca7d782 rpcclient+rpcserver: Change getnetworkhashps return type to be a float to be in line with bitcoin core 2021-12-14 10:05:52 -05:00
3nprob
cc7327c194 rpcclient: Add retry with backoffs to HTTP POST requests
Adds behavior similar to the retries of persistent RPC connections
to HTTP request.

* Initial backoff: 500ms
* Linear increase
* Max retries: 10

Room for future improvement:
* Make configurable
* Add jitter
* Tests for retry behavior
2021-11-16 09:08:07 -05:00
JeremyRand
3e2d8464f1
rpcclient: Export symbols needed for custom commands (#1457)
* rpcclient: Export sendCmd and response

This facilitates using custom commands with rpcclient.

See https://github.com/btcsuite/btcd/issues/1083

* rpcclient: Export receiveFuture

This facilitates using custom commands with rpcclient.

See https://github.com/btcsuite/btcd/issues/1083

* rpcclient: Add customcommand example

* rpcclient: remove "Namecoin" from customcommand readme heading
2021-09-02 08:39:55 +02:00
Jake Sylvestre
540786fda6 rpcclient: fix documentation typo 2021-04-13 09:09:20 -04:00
Jake Sylvestre
d08785547a docs: update shields 2021-03-05 07:45:19 -05:00
Jake Sylvestre
2a1aa5129e Add Batch JSON-RPC support (rpc client & server) 2021-02-09 09:47:46 -05:00
10gic
610bb55ae8 rpcclient: add ExtraHeaders in ConnConfig 2020-11-24 14:15:14 -05:00
Armando Ochoa
f070f7f2be rpcclient: fix documentation typos 2020-11-04 09:56:02 -05:00
Anirudha Bose
535f25593d rpcclient: implement createwallet with functional options 2020-10-26 14:54:05 -04:00
Torkel Rogstad
1d75e0a885 rpcclient: add more wallet commands
Implement backupwallet, dumpwallet, loadwallet and unloadwallet.
2020-10-26 09:34:56 -04:00
Anirudha Bose
6519c04a6f rpcclient: implement gettxoutsetinfo command 2020-10-05 10:03:47 -04:00
Henry Fisher
584c382334 rpc: add signrawtransactionwithwallet interface
Adds interface for issuing a signrawtransactionwithwallet command.
Note that this does not add functionality for the btcd rpc server
itself, it simply assumes that the RPC client has this ability and gives
an API for interacting with the RPC client.

rpc: add signrawtransactionwithwallet interface
2020-10-05 09:56:12 -04:00
Anirudha Bose
e9a51e8dcd rpcclient: implement getwalletinfo command 2020-09-25 12:18:06 -04:00