Merge pull request #1969 from lindlof/rpc-address-align

Add address field (rpc client & server)
This commit is contained in:
Oliver Gugger 2023-08-03 08:17:30 +02:00 committed by GitHub
commit 6f93d9f40d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 8 deletions

View file

@ -139,9 +139,10 @@ type CreateMultiSigResult struct {
// DecodeScriptResult models the data returned from the decodescript command.
type DecodeScriptResult struct {
Asm string `json:"asm"`
ReqSigs int32 `json:"reqSigs,omitempty"`
ReqSigs int32 `json:"reqSigs,omitempty"` // Deprecated: removed in Bitcoin Core
Type string `json:"type"`
Addresses []string `json:"addresses,omitempty"`
Address string `json:"address,omitempty"`
Addresses []string `json:"addresses,omitempty"` // Deprecated: removed in Bitcoin Core
P2sh string `json:"p2sh,omitempty"`
}
@ -429,9 +430,10 @@ type GetRawMempoolVerboseResult struct {
type ScriptPubKeyResult struct {
Asm string `json:"asm"`
Hex string `json:"hex,omitempty"`
ReqSigs int32 `json:"reqSigs,omitempty"`
ReqSigs int32 `json:"reqSigs,omitempty"` // Deprecated: removed in Bitcoin Core
Type string `json:"type"`
Addresses []string `json:"addresses,omitempty"`
Address string `json:"address,omitempty"`
Addresses []string `json:"addresses,omitempty"` // Deprecated: removed in Bitcoin Core
}
// GetTxOutResult models the data from the gettxout command.

View file

@ -738,6 +738,13 @@ func createVoutList(mtx *wire.MsgTx, chainParams *chaincfg.Params, filterAddrMap
vout.ScriptPubKey.Type = scriptClass.String()
vout.ScriptPubKey.ReqSigs = int32(reqSigs)
// Address is defined when there's a single well-defined
// receiver address. To spend the output a signature for this,
// and only this, address is required.
if len(encodedAddrs) == 1 && reqSigs <= 1 {
vout.ScriptPubKey.Address = encodedAddrs[0]
}
voutList = append(voutList, vout)
}
@ -857,6 +864,13 @@ func handleDecodeScript(s *rpcServer, cmd interface{}, closeChan <-chan struct{}
if scriptClass != txscript.ScriptHashTy {
reply.P2sh = p2sh.EncodeAddress()
}
// Address is defined when there's a single well-defined
// receiver address. To spend the output a signature for this,
// and only this, address is required.
if len(addresses) == 1 && reqSigs <= 1 {
reply.Address = addresses[0]
}
return reply, nil
}
@ -2725,6 +2739,7 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
var value int64
var pkScript []byte
var isCoinbase bool
var address string
includeMempool := true
if c.IncludeMempool != nil {
includeMempool = *c.IncludeMempool
@ -2798,6 +2813,13 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
addresses[i] = addr.EncodeAddress()
}
// Address is defined when there's a single well-defined
// receiver address. To spend the output a signature for this,
// and only this, address is required.
if len(addresses) == 1 && reqSigs <= 1 {
address = addresses[0]
}
txOutReply := &btcjson.GetTxOutResult{
BestBlock: bestBlockHash,
Confirmations: int64(confirmations),
@ -2807,10 +2829,12 @@ func handleGetTxOut(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
Hex: hex.EncodeToString(pkScript),
ReqSigs: int32(reqSigs),
Type: scriptClass.String(),
Address: address,
Addresses: addresses,
},
Coinbase: isCoinbase,
}
return txOutReply, nil
}

View file

@ -84,9 +84,10 @@ var helpDescsEnUS = map[string]string{
// ScriptPubKeyResult help.
"scriptpubkeyresult-asm": "Disassembly of the script",
"scriptpubkeyresult-hex": "Hex-encoded bytes of the script",
"scriptpubkeyresult-reqSigs": "The number of required signatures",
"scriptpubkeyresult-reqSigs": "(DEPRECATED) The number of required signatures",
"scriptpubkeyresult-type": "The type of the script (e.g. 'pubkeyhash')",
"scriptpubkeyresult-addresses": "The bitcoin addresses associated with this script",
"scriptpubkeyresult-address": "The bitcoin address associated with this script (only if a well-defined address exists)",
"scriptpubkeyresult-addresses": "(DEPRECATED) The bitcoin addresses associated with this script",
// Vout help.
"vout-value": "The amount in BTC",
@ -106,9 +107,10 @@ var helpDescsEnUS = map[string]string{
// DecodeScriptResult help.
"decodescriptresult-asm": "Disassembly of the script",
"decodescriptresult-reqSigs": "The number of required signatures",
"decodescriptresult-reqSigs": "(DEPRECATED) The number of required signatures",
"decodescriptresult-type": "The type of the script (e.g. 'pubkeyhash')",
"decodescriptresult-addresses": "The bitcoin addresses associated with this script",
"decodescriptresult-address": "The bitcoin address associated with this script (only if a well-defined address exists)",
"decodescriptresult-addresses": "(DEPRECATED) The bitcoin addresses associated with this script",
"decodescriptresult-p2sh": "The script hash for use in pay-to-script-hash transactions (only present if the provided redeem script is not already a pay-to-script-hash script)",
// DecodeScriptCmd help.