After Bitcoin core 23.0, bitcoind no longer returns the addresses field in RPC methods gettxout, getrawtransaction, decoderawtransaction, decodescript, gettransaction verbose=true (see bitcoin release notes for more detail).
Instead, a address field is returned, which should be decoded in a Address string field within the ScriptPubKeystruct in bitcoin's client types.
Solution
This PR contains a fix that supports both the deprecated Addresses []string field and the new Address string field, that will enable Rosetta-bitcoin implementation to be compatible with bitcoin core v23 while maintaining backward compatibility with previous bitcoin releases
Proposed code changes
func (b *Client) parseOutputAccount(
scriptPubKey *ScriptPubKey,
) *types.AccountIdentifier {
if scriptPubKey.Address == "" { // <--- new logic to handle both cases with "Addresses []string" and "Address string"
if len(scriptPubKey.Addresses) != 1 {
return &types.AccountIdentifier{Address: scriptPubKey.Hex}
}
return &types.AccountIdentifier{Address: scriptPubKey.Addresses[0]}
}
return &types.AccountIdentifier{Address: scriptPubKey.Address}
}
Unit tests for the bitcoin client have been slightly modified to take the new scenario into consideration.
A new client fixture json file has been added (get_block_responses_2_bis.json) which is a copy of the original test data (i.e. get_block_responses_2.json) but with the data fields modified as described above.
In line with the new json file added, a var with the corresponding new block (block100000_bis) has been added to the test file bitcoin/client_test.go to update unit tests accordigly
Fixes # .
Motivation
After Bitcoin core 23.0,
bitcoind
no longer returns theaddresses
field in RPC methodsgettxout
,getrawtransaction
,decoderawtransaction
,decodescript
,gettransaction verbose=true
(see bitcoin release notes for more detail). Instead, aaddress
field is returned, which should be decoded in aAddress string
field within theScriptPubKey
struct in bitcoin's client types.Solution
This PR contains a fix that supports both the deprecated
Addresses []string
field and the newAddress string
field, that will enable Rosetta-bitcoin implementation to be compatible with bitcoin core v23 while maintaining backward compatibility with previous bitcoin releases Proposed code changesbitcoin/types.go
bitcoin/client.go
Unit tests for the bitcoin client have been slightly modified to take the new scenario into consideration.
get_block_responses_2_bis.json
) which is a copy of the original test data (i.e.get_block_responses_2.json
) but with the data fields modified as described above.var
with the corresponding new block (block100000_bis
) has been added to the test filebitcoin/client_test.go
to update unit tests accordiglyOpen questions
N/A