MCPcopy Create free account
hub / github.com/copernet/copernicus / ScriptPubKeyToJSON

Function ScriptPubKeyToJSON

rpc/rawtransaction.go:214–240  ·  view source on GitHub ↗
(script *script.Script, includeHex bool)

Source from the content-addressed store, hash-verified

212}
213
214func ScriptPubKeyToJSON(script *script.Script, includeHex bool) *btcjson.ScriptPubKeyResult {
215 result := &btcjson.ScriptPubKeyResult{}
216
217 if script == nil {
218 return result
219 }
220
221 result.Asm = ScriptToAsmStr(script, false)
222 if includeHex {
223 result.Hex = hex.EncodeToString(script.GetData())
224 }
225
226 t, addresses, required, err := script.ExtractDestinations()
227 result.Type = GetTxnOutputType(t)
228
229 if err != nil {
230 return result
231 }
232
233 result.ReqSigs = int32(required)
234 result.Addresses = make([]string, 0, len(addresses))
235 for _, address := range addresses {
236 result.Addresses = append(result.Addresses, address.String())
237 }
238
239 return result
240}
241
242func GetTxnOutputType(sType int) string {
243 switch sType {

Callers 3

getVoutListFunction · 0.85
handleDecodeScriptFunction · 0.85
handleGetTxOutFunction · 0.85

Calls 5

ScriptToAsmStrFunction · 0.85
GetTxnOutputTypeFunction · 0.85
GetDataMethod · 0.80
ExtractDestinationsMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected