Commit graph

169 commits

Author SHA1 Message Date
Calvin Kim
79752a8880 btcjson: accept null in StringOrArray.UnmarshalJSON
StringOrArray.MarshalJSON emits JSON null for a nil slice (see existing
test "nil slice marshals as null" in TestStringOrArrayMarshalJSON), but
UnmarshalJSON did not have a matching case for null and fell to the
default branch, returning "invalid string_or_array value: <nil>". A
round trip of a nil slice therefore failed.

This bit the rpcclient against btcd's own getblockchaininfo, whose
Warnings field is a StringOrArray that the server leaves as a nil slice
when there are no warnings. Every rpctest integration test that touches
GetBlockChainInfo (TestBIP0009, TestBIP0068AndBIP0112Activation,
TestBIP0113Activation, TestPrune) failed to decode the response.

Handle the nil case explicitly so null decodes back to a nil slice, and
add regression cases for "warnings: null" and an omitted warnings field
to TestGetBlockChainInfoWarnings.
2026-05-30 16:47:18 +09:00
Oliver Gugger
dccea8feba multi: use new v2 modules everywhere 2026-05-14 18:05:33 -07:00
Olaoluwa Osuntokun
62cc0a6b77 multi: appease go 1.26 vet for non-const format + goroutine Fatalf
In this commit, we fix two go vet errors that go 1.26 now treats as
hard failures during test compilation.

In btcjson/help.go, the final result row of a complex help description
was emitted via fmt.Fprintf with a non-constant format string (the
result text could contain '%' chars). Switch to fmt.Fprint, since
there are no format args here anyway.

In btcec/schnorr/musig2/musig2_test.go, the nonce-registration loop
ran inside a goroutine and called t.Fatalf on failure. Fatalf only
exits the calling goroutine, so the test goroutine would keep running
with stale state. Use t.Errorf + return so the failure is recorded
correctly and the goroutine exits cleanly.
2026-05-14 17:36:51 -07:00
Olaoluwa Osuntokun
91cf7b241e btcjson: add tests for StringOrArray and Warnings field
Add a regression test for the StringOrArray.MarshalJSON infinite-recursion
fix that exercises both the direct method call and the path through
json.Marshal. Without the fix, the test triggers a goroutine stack
overflow.

Also add a round-trip test and tests for the new Warnings field on
GetBlockChainInfoResult, covering both the legacy single-string form and
the post-bitcoin#29845 array form.
2026-05-11 17:22:00 -07:00
Eric Grill
6392419373 btcjson: add Warnings field to GetBlockChainInfoResult
Bitcoin Core added a warnings field to getblockchaininfo in PR #10858,
and recently changed it from a string to an array in PR #29845. Add
the field using StringOrArray type to handle both formats.

This allows rpcclient to properly unmarshal getblockchaininfo responses
from all Bitcoin Core versions.

Closes #2444

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-11 17:22:00 -07:00
Eric Grill
b528a35303 btcjson: fix infinite recursion in StringOrArray.MarshalJSON
The MarshalJSON method was calling json.Marshal(h) where h is of type
StringOrArray. Since StringOrArray implements json.Marshaler, this
caused json.Marshal to call MarshalJSON again, resulting in infinite
recursion and a stack overflow.

Fix by converting to the underlying []string type before marshaling,
which breaks the interface lookup cycle.

Closes #2369

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-11 17:21:14 -07:00
Olaoluwa Osuntokun
baebb836c2
Merge pull request #2366 from bhandras/submitpackage
btcjson: add stubs for SubmitPackage
2025-07-28 18:00:03 -05:00
Andras Banki-Horvath
5e4519770f
btcjson: add json parsing unit tests for SubmitPackage stubs 2025-07-23 10:38:59 +02:00
Andras Banki-Horvath
6b2a9a4a48
btcjson: add stubs for SubmitPackage 2025-07-23 10:38:32 +02:00
Olaoluwa Osuntokun
c6b2553ab8 rpcserver: expose v2 connection status in getpeerinfo
This commit adds a new boolean field, `V2Connection`, to the
`getpeerinfo` RPC result. This field indicates whether the connection
to the peer is using the v2 encrypted transport protocol.

The `peer.StatsSnap` struct is updated to include this `V2Connection`
field, which is populated based on the `UsingV2Conn` field in the peer's
configuration. The `btcjson.GetPeerInfoResult` struct is also updated
to include the corresponding JSON field `v2_connection`. Finally, the
`handleGetPeerInfo` RPC handler is modified to copy this value from the
peer's stats snapshot into the RPC response.
2025-05-26 13:46:25 -07:00
Romashka
821114285b
typo-Update register_test.go (#2291) 2025-01-09 08:32:50 -05:00
Oliver Gugger
ed879eac20
btcjson: turn warnings into StringOrArray type
Fixes #2224 and lightningnetwork/lnd#9053.

Depending on the version of Bitcoin Core, the "warnings" field in the
response to getnetworkinfo is either a single string value or an array
of strings.
We can easily parse those two variants with a custom type that
implements an UnmarshalJSON method.
2024-09-02 15:38:35 +02:00
Bruno Garcia
1a1dd2a2b3
btcjson: check if both begin and end are numbers in UnmarshalJSON 2024-08-23 12:22:54 -07:00
coderwander
11bd614171
Fix struct names (#2169)
Signed-off-by: coderwander <770732124@qq.com>
2024-06-19 11:38:54 -04:00
lilasxie
cccaa5f9b0 refactor: specify strconv.ParseFloat bitsize to 64 2024-06-03 18:28:21 +08:00
Olaoluwa Osuntokun
ae5533602c
Merge pull request #2142 from YusukeShimizu/feeRate-BTCkvB
btcclient+btcjson: defaultMaxFeeRate to BTC/kvB
2024-04-02 19:19:26 -07:00
bruwbird
80b27f5471
btcclient+btcjson: add type alias for BTC/kvB
Added type alias BTC/kvB to explicitly indicate that
it represents the fee in BTC for a transaction size of 1 kB.
Because bitcoind uses its own fee rate type
(BTC/kvB instead of sat/kWU we use in lnd),
define the type in btcjson package,
as it's the only place where we actually use BTC/kvB.
2024-03-27 17:58:12 +09:00
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
mattn
3cb9f602e8
fix typos (#2100) 2024-03-25 09:44:25 -04:00
yyforyongyu
dd31767617
btcjson: add new command GetTxSpendingPrevOutCmd 2024-02-27 22:58:33 +08:00
Nikolay Bryskin
069a0eca29
Added 'include_unsafe' option to FundRawTransaction 2024-02-05 14:55:17 +02:00
yyforyongyu
c7e40280d5
rpcclient: support testmempoolaccept for bitcoind 2024-01-15 17:22:41 +08:00
yyforyongyu
ca4261f028
btcjson: add TestMempoolAcceptCmd 2024-01-15 17:22:40 +08: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
Oliver Gugger
6f93d9f40d
Merge pull request #1969 from lindlof/rpc-address-align
Add address field (rpc client & server)
2023-08-03 08:17:30 +02:00
Calvin Kim
892ae679b3 btcjson, main: Implement the getchaintips call
getchaintips call is implemented and the behavior mimics that of Bitcoin
Core. Resolves https://github.com/btcsuite/btcd/issues/1912.
2023-07-16 16:03:48 +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
Mikael Lindlof
e4c88c3a3e rpc: Add ScriptPubKeyResult address field 2023-06-06 21:57:01 +01: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
dekokun
796f1746b3 btcjson: Update the fields of GetNetworkInfoResult
Update the fields of GetNetworkInfoResult to reflect the current number
of inbound and outbound peer connections.

* ConnectionsIn - The number of inbound peer connections
* ConnectionsOut - The number of outbound peer connections
2022-04-09 07:01:50 -04:00
James Smoot
71c844310a Default to JSONRPC 1.0 if the rpcVersion empty 2022-04-09 06:55:59 -04:00
Olaoluwa Osuntokun
0b245cca4f
btcjson+rpc: add min activation height to soft fork RPC response 2022-01-25 15:27:52 -08: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
Gabriel Nasr
505915dc3f btcjson: Update WalletCreateFundedPsbtOpts.FeeRate from *int64 to *float64 2021-06-25 15:23:44 -03:00
Aurèle Oulès
2d7825cf70 btcjson: Updated TxRawResult.Version from int32 to uint32 2021-04-13 15:21:09 -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
Steven Kreuzer
7bbd9b0284 btcjson: Update fields in GetBlockChainInfoResult
Update the fields of GetBlockChainInfoResult to reflect the current state of
the RPC returned by other full-node implementations.

 * InitialBlockDownload - Node is in Initial Block Download mode if True.
 * SizeOnDisk - The estimated size of the block and undo files on disk.
2021-01-26 09:52:38 -05:00
Vinayak Borkar
c3ece697da Fixes btcsuite/btcd#1653 2021-01-18 13:51:45 -05:00
Oliver Gugger
9e8bb3eddb
btcjson+rpcserverhelp: restore bitcoind compatibility
The PR #1594 introduced a change that made the order of parameters
relevant, if one of them is nil. This makes it harder to be backward
compatible with the same JSON message if an existing parameter in
bitcoind was re-purposed to have a different meaning.
2020-11-12 15:47:51 +01:00
Anirudha Bose
535f25593d rpcclient: implement createwallet with functional options 2020-10-26 14:54:05 -04:00
Anirudha Bose
5e56ca05e1 btcjson: add new JSON-RPC errors and document them 2020-10-26 09:35:46 -04:00
Torkel Rogstad
1d75e0a885 rpcclient: add more wallet commands
Implement backupwallet, dumpwallet, loadwallet and unloadwallet.
2020-10-26 09:34:56 -04:00
David Mazary
6adfc07d1e Unmarshal hashes/second as float in GetMiningInfoResult 2020-10-26 09:33:28 -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