Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add address field (rpc client & server) #1969

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions btcjson/chainsvrresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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
}

Expand Down
10 changes: 6 additions & 4 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.
Expand Down